1000 ) { return false; } foreach ( (array) $zc['exclude'] as $ex ) { if ( '' !== $ex && false !== stripos( $path, $ex ) ) { return false; } } $lang = ''; $cur = ''; foreach ( $cookie as $k => $v ) { if ( preg_match( '/^(wordpress_logged_in_|wp-postpass_|comment_author_|woocommerce_|wp_woocommerce_session_|edd_|wpsc_)/', $k ) ) { return false; } // Only a language the site really has (Polylang, WPML): made-up values must not each grow a copy. if ( ( 'pll_language' === $k || 'wp-wpml_current_language' === $k ) && in_array( (string) $v, isset( $zc['langs'] ) ? (array) $zc['langs'] : array(), true ) ) { $lang = '-' . preg_replace( '/[^a-z0-9_]/i', '', (string) $v ); } // Multi-currency shops (Aelia, WCML, CURCY, WOOCS, YITH): a page priced in EUR must never reach // a visitor who chose USD, so the chosen currency is part of the key, like the language. // A three-letter currency code only (ISO 4217), so the number of copies stays bounded. if ( preg_match( '/^(aelia_cs_selected_currency|wcml_client_currency|wmc_current_currency|woocs_current_currency|yith_wcmcs_currency)$/', $k ) && preg_match( '/^[A-Za-z]{3}$/', (string) $v ) ) { $cur = '-' . strtolower( (string) $v ); } } $lang .= $cur; $host = isset( $server['HTTP_HOST'] ) ? strtolower( (string) $server['HTTP_HOST'] ) : 'default'; $host = preg_replace( '/[^a-z0-9.\-]/', '', $host ); // Only this site's own address picks the folder. A forged Host must not: ".." would write and read // outside the cache directory, and every made-up name would grow another full copy of the site. if ( ! preg_match( '/^[a-z0-9](?:[a-z0-9\-]|\.(?!\.))*$/', $host ) || ( ! empty( $zc['hosts'] ) && ! in_array( $host, (array) $zc['hosts'], true ) ) ) { return false; } $ua = isset( $server['HTTP_USER_AGENT'] ) ? (string) $server['HTTP_USER_AGENT'] : ''; $dev = preg_match( '/Mobile|Android|iPhone|iPad|iPod|Opera Mini|IEMobile/i', $ua ) ? 'm' : 'd'; $rel = trim( $path, '/' ); return $dir . '/' . $host . ( '' !== $rel ? '/' . $rel : '' ) . '/index-' . $dev . $lang . '.html'; } }