diff --git a/BrowserCache_Environment.php b/BrowserCache_Environment.php index 11993a4..f77e8dc 100644 --- a/BrowserCache_Environment.php +++ b/BrowserCache_Environment.php @@ -527,18 +527,18 @@ private function _rules_cache_generate_apache_for_type( $config, $mime_types, } else { if ( $compatibility ) { $rules .= " FileETag None\n"; - $headers_rules .= " Header unset ETag\n"; + $headers_rules .= " Header unset ETag\n"; } } if ( $unset_setcookie ) - $headers_rules .= " Header unset Set-Cookie\n"; + $headers_rules .= " Header unset Set-Cookie\n"; if ( !$set_last_modified ) - $headers_rules .= " Header unset Last-Modified\n"; + $headers_rules .= " Header unset Last-Modified\n"; if ( $w3tc ) - $headers_rules .= " Header set X-Powered-By \"" . + $headers_rules .= " Header set X-Powered-By \"" . Util_Environment::w3tc_header() . "\"\n"; if ( strlen( $headers_rules ) > 0 ) { diff --git a/Minify_Page.php b/Minify_Page.php index af8d1dc..0adf3d8 100644 --- a/Minify_Page.php +++ b/Minify_Page.php @@ -635,7 +635,20 @@ function get_recommendations_js( $content ) { $files = array_map( array( '\W3TC\Util_Environment', 'normalize_file_minify' ), $files ); $files = array_unique( $files ); $ignore_files = $this->_config->get_array( 'minify.reject.files.js' ); - $files = array_diff( $files, $ignore_files ); + + $ignore_files = str_replace( "~", "\~", $ignore_files ); + Util_Rule::array_trim( $ignore_files ); + + if ( !empty( $ignore_files ) ) { + $diff = array(); + foreach( $files as $file ) { + if ( !@preg_match( '~' . implode( "|", $ignore_files ) . '~i', $file ) ) { + $diff[] = $file; + } + } + $files = $diff; + } + return $files; } @@ -654,7 +667,19 @@ function get_recommendations_css( $content ) { $files = array_map( array( '\W3TC\Util_Environment', 'normalize_file_minify' ), $files ); $files = array_unique( $files ); $ignore_files = $this->_config->get_array( 'minify.reject.files.css' ); - $files = array_diff( $files, $ignore_files ); + + $ignore_files = str_replace( "~", "\~", $ignore_files ); + Util_Rule::array_trim( $ignore_files ); + + if ( !empty( $ignore_files ) ) { + $diff = array(); + foreach( $files as $file ) { + if ( !@preg_match( '~' . implode( "|", $ignore_files ) . '~i', $file ) ) { + $diff[] = $file; + } + } + $files = $diff; + } return $files; } diff --git a/Minify_Plugin.php b/Minify_Plugin.php index b799451..c30bd48 100644 --- a/Minify_Plugin.php +++ b/Minify_Plugin.php @@ -196,7 +196,6 @@ function ob_callback( $buffer ) { $embed_pos = 0; } - $ignore_css_files = array_map( array( '\W3TC\Util_Environment', 'normalize_file' ), $ignore_css_files ); $handled_styles = array(); $style_tags = Minify_Extract::extract_css( $buffer ); $previous_file_was_ignored = false; @@ -228,7 +227,11 @@ function ob_callback( $buffer ) { $handled_styles[] = $file; $this->replaced_styles[] = $file; - if ( in_array( $file, $ignore_css_files ) ) { + + $ignore_css_files = str_replace( "~", "\~", $ignore_css_files ); + Util_Rule::array_trim( $ignore_css_files ); + + if ( !empty( $ignore_css_files ) && @preg_match( '~' . implode("|", $ignore_css_files ) . '~i', $file ) ) { if ( $tag_pos > $embed_pos ) { if ( $files_to_minify ) { $data = array( @@ -1040,17 +1043,18 @@ function can_minify2( $buffer ) { * @return boolean */ function check_ua() { - $uas = array_merge( $this->_config->get_array( 'minify.reject.ua' ), array( - W3TC_POWERED_BY - ) ); + if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { + $uas = array_merge( $this->_config->get_array( 'minify.reject.ua' ), array( + W3TC_POWERED_BY + ) ); - foreach ( $uas as $ua ) { - if ( !empty( $ua ) ) { - if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && stristr( $_SERVER['HTTP_USER_AGENT'], $ua ) !== false ) { - return false; - } - } - } + $uas = str_replace( "~", "\~", $uas ); + Util_Rule::array_trim( $uas ); + + if ( !empty( $uas ) && @preg_match( '~' . implode( "|", $uas ) . '~i', $_SERVER['HTTP_USER_AGENT'] ) ) { + return false; + } + } return true; } @@ -1404,7 +1408,9 @@ function __construct( $config, $buffer, $minify_helpers ) { // ignored files $this->ignore_js_files = $this->config->get_array( 'minify.reject.files.js' ); - $this->ignore_js_files = array_map( array( '\W3TC\Util_Environment', 'normalize_file' ), $this->ignore_js_files ); + + $this->ignore_js_files = str_replace( "~", "\~", $this->ignore_js_files ); + Util_Rule::array_trim( $this->ignore_js_files ); // define embed type $this->embed_type = array( @@ -1522,7 +1528,7 @@ private function process_script_tag( $script_tag, $script_tag_number ) { $step1_result = $this->minify_helpers->is_file_for_minification( $script_src, $file ); $step1 = !empty( $step1_result ); - $step2 = !in_array( $file, $this->ignore_js_files ); + $step2 = empty( $this->ignore_js_files ) || !@preg_match( '~' . implode( "|", $this->ignore_js_files ) . '~i', $file ); $do_tag_minification = $step1 && $step2; $do_tag_minification = apply_filters( 'w3tc_minify_js_do_tag_minification', diff --git a/PgCache_ContentGrabber.php b/PgCache_ContentGrabber.php index 3a6a118..e60985d 100644 --- a/PgCache_ContentGrabber.php +++ b/PgCache_ContentGrabber.php @@ -783,8 +783,9 @@ function _check_cache_exception() { $accept_uri = $this->_config->get_array( 'pgcache.accept.files' ); $accept_uri = array_map( array( '\W3TC\Util_Environment', 'parse_path' ), $accept_uri ); - foreach ( $accept_uri as &$val ) $val = trim( str_replace( "~", "\~", $val ) ); - $accept_uri = array_filter( $accept_uri, function( $val ){ return $val != ""; } ); + $accept_uri = str_replace( "~", "\~", $accept_uri ); + Util_Rule::array_trim( $accept_uri ); + if ( !empty( $accept_uri ) && @preg_match( '~' . implode( "|", $accept_uri ) . '~i', $this->_request_uri ) ) { return true; } @@ -863,9 +864,9 @@ function _check_authors() { */ function _check_custom_fields() { $reject_custom = $this->_config->get_array( 'pgcache.reject.custom' ); - foreach ( $reject_custom as &$val ) { - $val = preg_quote( trim( $val ), '~' ); - } + + Util_Rule::array_trim( $reject_custom ); + $reject_custom = array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_custom ); $reject_custom = implode( "|",array_filter( $reject_custom ) ); @@ -948,17 +949,21 @@ function _check_cookies() { } } - foreach ( $this->_config->get_array( 'pgcache.reject.cookie' ) as $reject_cookie ) { - if ( !empty( $reject_cookie ) ) { - foreach ( array_keys( $_COOKIE ) as $cookie_name ) { - if ( strstr( $cookie_name, $reject_cookie ) !== false ) { - return false; - } - } - } - } + $reject_cookies = $this->_config->get_array( 'pgcache.reject.cookie' ); + Util_Rule::array_trim( $reject_cookies ); - return true; + $reject_cookies = str_replace( "+", " ", $reject_cookies ); + $reject_cookies = array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_cookies ); + + $reject_cookies = implode( '|', $reject_cookies ); + + foreach ( $_COOKIE as $key => $value ) { + if ( @preg_match( '~' . $reject_cookies . '~i', $key . "=$value" ) ) { + return false; + } + } + + return true; } /** @@ -1757,10 +1762,10 @@ private function _is_cacheable_content_type() { */ private function _check_query_string() { $accept_qs = $this->_config->get_array( 'pgcache.accept.qs' ); - $accept_qs = array_filter( $accept_qs, function( $val ) { return $val != ""; } ); + Util_Rule::array_trim( $accept_qs ); foreach ( $accept_qs as &$val ) { - $val = preg_quote( trim( str_replace( "+", " ", $val ) ), "~" ); + $val = Util_Environment::preg_quote( str_replace( "+", " ", $val ) ); $val .= ( strpos( $val, '=' ) === false ? '.*?' : '' ); } diff --git a/PgCache_Environment.php b/PgCache_Environment.php index e6f5873..34b51e9 100644 --- a/PgCache_Environment.php +++ b/PgCache_Environment.php @@ -595,12 +595,12 @@ private function rules_core_generate_apache( $config ) { /** * Set accept query strings */ - $w3tc_query_strings = array_filter( $config->get_array( 'pgcache.accept.qs' ), function( $val ) { return $val != ""; } ); + $w3tc_query_strings = $config->get_array( 'pgcache.accept.qs' ); + Util_Rule::array_trim( $w3tc_query_strings ); if ( !empty( $w3tc_query_strings ) ) { - foreach ( $w3tc_query_strings as &$val ) { - $val = trim( str_replace( " ", "\+", preg_quote( $val ) ) ); - } + $w3tc_query_strings = str_replace( ' ', '+', $w3tc_query_strings ); + $w3tc_query_strings = array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $w3tc_query_strings ); $rules .= " RewriteRule ^ - [E=W3TC_QUERY_STRING:%{QUERY_STRING}]\n"; @@ -735,8 +735,11 @@ private function rules_core_generate_apache( $config ) { /** * Check for rejected cookies */ - $use_cache_rules .= " RewriteCond %{HTTP_COOKIE} !(" . implode( '|', - array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_cookies ) ) . ") [NC]\n"; + if ( !empty( $reject_cookies ) ) { + $reject_cookies = str_replace( ' ', '+', $reject_cookies ); + $use_cache_rules .= " RewriteCond %{HTTP_COOKIE} !(" . implode( '|', + array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_cookies ) ) . ") [NC]\n"; + } /** * Check for rejected user agents @@ -764,7 +767,7 @@ private function rules_core_generate_apache( $config ) { $rules .= " RewriteRule .* \"" . $uri_prefix . $ext . $env_W3TC_ENC . "\" [L]\n"; - if ($config->get_boolean('pgcache.cache.apache_handle_xml')) { + if ($config->get_boolean( 'pgcache.cache.apache_handle_xml' ) ) { $ext = '.xml'; $rules .= " RewriteCond \"" . $document_root . $uri_prefix . $ext . $env_W3TC_ENC . "\"" . $switch . "\n"; @@ -852,12 +855,12 @@ private function rules_core_generate_nginx( $config ) { /** * Set accept query strings */ - $w3tc_query_strings = array_filter( $config->get_array( 'pgcache.accept.qs' ), function( $val ) { return $val != ""; } ); + $w3tc_query_strings = $config->get_array( 'pgcache.accept.qs' ); + Util_Rule::array_trim( $w3tc_query_strings ); if ( !empty( $w3tc_query_strings ) ) { - foreach ( $w3tc_query_strings as &$val ) { - $val = trim( str_replace( " ", "\+", preg_quote( $val ) ) ); - } + $w3tc_query_strings = str_replace( ' ', '+', $w3tc_query_strings ); + $w3tc_query_strings = array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $w3tc_query_strings ); $rules .= "set \$w3tc_query_string \$query_string;\n"; @@ -947,11 +950,13 @@ private function rules_core_generate_nginx( $config ) { /** * Check for rejected cookies */ - $rules .= "if (\$http_cookie ~* \"(" . implode( '|', - array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_cookies ) ) . ")\") {\n"; - $rules .= " set \$w3tc_rewrite 0;\n"; - $rules .= "}\n"; - + if ( !empty( $reject_cookies ) ) { + $reject_cookies = str_replace( ' ', '+', $reject_cookies ); + $rules .= "if (\$http_cookie ~* \"(" . implode( '|', + array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_cookies ) ) . ")\") {\n"; + $rules .= " set \$w3tc_rewrite 0;\n"; + $rules .= "}\n"; + } /** * Check for rejected user agents */ diff --git a/Util_Rule.php b/Util_Rule.php index 04701a1..5e0a979 100644 --- a/Util_Rule.php +++ b/Util_Rule.php @@ -22,10 +22,8 @@ static public function is_permalink_rules() { * Removes empty elements */ static public function array_trim( &$a ) { - for ( $n = count( $a ) - 1; $n >= 0; $n-- ) { - if ( empty( $a[$n] ) ) - array_splice( $a, $n, 1 ); - } + $a = array_map( 'trim', $a ); + $a = array_filter( $a, function( $val ) { return $val != ""; } ); } /** diff --git a/inc/options/minify.php b/inc/options/minify.php index 95868c2..fcdabb9 100644 --- a/inc/options/minify.php +++ b/inc/options/minify.php @@ -486,7 +486,7 @@
- + @@ -494,7 +494,7 @@
- JS files. Use relative paths. Omit: protocol, hostname, leading forward slash and query strings.', 'w3-total-cache' ); ?> + JS files. Use relative paths. Supports regular expressions. Omit: protocol, hostname, leading forward slash and query strings.', 'w3-total-cache' ); ?> @@ -502,7 +502,7 @@
- CSS files. Use relative paths. Omit: protocol, hostname, leading forward slash and query strings.', 'w3-total-cache' ); ?> + CSS files. Use relative paths. Supports regular expressions. Omit: protocol, hostname, leading forward slash and query strings.', 'w3-total-cache' ); ?> @@ -511,7 +511,7 @@
- + diff --git a/inc/options/pgcache.php b/inc/options/pgcache.php index 06d7a24..cecf562 100644 --- a/inc/options/pgcache.php +++ b/inc/options/pgcache.php @@ -354,7 +354,7 @@
- + @@ -366,7 +366,7 @@ FAQ)', 'w3-total-cache' ), network_admin_url( 'admin.php?page=w3tc_faq#q82' ) + __( 'Always ignore the specified pages / directories. Use relative paths. Supports regular expressions (See FAQ)', 'w3-total-cache' ), network_admin_url( 'admin.php?page=w3tc_faq#q82' ) ); ?> @@ -413,7 +413,7 @@
- FAQ)', 'w3-total-cache' ), network_admin_url( 'admin.php?page=w3tc_faq#q82' ) ); ?> + FAQ)', 'w3-total-cache' ), network_admin_url( 'admin.php?page=w3tc_faq#q82' ) ); ?> diff --git a/pub/css/widget.css b/pub/css/widget.css index 8340cea..eb13189 100644 --- a/pub/css/widget.css +++ b/pub/css/widget.css @@ -145,3 +145,7 @@ .maxcdn-netdna-widget-base.sign-up p span.desc { color:#8F8F8F; } + +#purge_urls { + width: 100%; +} \ No newline at end of file