@@ -2,9 +2,9 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | //Check everything exists before using it |
| 4 | 4 | if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
| 5 | - $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
| 5 | + $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
| 6 | 6 | if(!isset($_SERVER['HTTP_USER_AGENT'])) |
| 7 | - $_SERVER['HTTP_USER_AGENT'] = ''; |
|
| 7 | + $_SERVER['HTTP_USER_AGENT'] = ''; |
|
| 8 | 8 | |
| 9 | 9 | // Determine supported compression method |
| 10 | 10 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); |
@@ -15,30 +15,30 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | // Check for buggy versions of Internet Explorer |
| 17 | 17 | if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && |
| 18 | - preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
| 18 | + preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
| 19 | 19 | { |
| 20 | - $version = floatval($matches[1]); |
|
| 20 | + $version = floatval($matches[1]); |
|
| 21 | 21 | |
| 22 | - if ($version < 6) |
|
| 23 | - $encoding = 'none'; |
|
| 22 | + if ($version < 6) |
|
| 23 | + $encoding = 'none'; |
|
| 24 | 24 | |
| 25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
| 26 | - $encoding = 'none'; |
|
| 25 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
| 26 | + $encoding = 'none'; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | //Some servers compress the output of PHP - Don't break in those cases |
| 30 | 30 | if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
| 31 | - $encoding = 'none'; |
|
| 31 | + $encoding = 'none'; |
|
| 32 | 32 | |
| 33 | 33 | $iscompressed = file_exists(__FILE__.'.'.$encoding); |
| 34 | 34 | if($encoding != 'none' && $iscompressed == false) |
| 35 | 35 | { |
| 36 | - $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
|
| 37 | - $code = file_get_contents(__FILE__.'.none'); |
|
| 38 | - $contents = gzencode($code,9,$flag); |
|
| 36 | + $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
|
| 37 | + $code = file_get_contents(__FILE__.'.none'); |
|
| 38 | + $contents = gzencode($code,9,$flag); |
|
| 39 | 39 | }else{ |
| 40 | - //Get data |
|
| 41 | - $contents = file_get_contents(__FILE__.'.'.$encoding); |
|
| 40 | + //Get data |
|
| 41 | + $contents = file_get_contents(__FILE__.'.'.$encoding); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | // first check if we have to send 304 |
@@ -51,35 +51,35 @@ discard block |
||
| 51 | 51 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); |
| 52 | 52 | |
| 53 | 53 | if (($modTimeMatch)||($eTagMatch)) { |
| 54 | - header('HTTP/1.1 304 Not Modified'); |
|
| 55 | - header('Connection: close'); |
|
| 54 | + header('HTTP/1.1 304 Not Modified'); |
|
| 55 | + header('Connection: close'); |
|
| 56 | 56 | } else { |
| 57 | - // send all sorts of headers |
|
| 58 | - $expireTime=60*60*24*355; // 1y max according to RFC |
|
| 59 | - if ($encoding != 'none') { |
|
| 60 | - header('Content-Encoding: '.$encoding); |
|
| 61 | - } |
|
| 62 | - header('Vary: Accept-Encoding'); |
|
| 63 | - header('Content-Length: '.strlen($contents)); |
|
| 64 | - header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
| 65 | - header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
| 66 | - header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
| 67 | - header('ETag: ' . $eTag); |
|
| 68 | - header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
| 57 | + // send all sorts of headers |
|
| 58 | + $expireTime=60*60*24*355; // 1y max according to RFC |
|
| 59 | + if ($encoding != 'none') { |
|
| 60 | + header('Content-Encoding: '.$encoding); |
|
| 61 | + } |
|
| 62 | + header('Vary: Accept-Encoding'); |
|
| 63 | + header('Content-Length: '.strlen($contents)); |
|
| 64 | + header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
| 65 | + header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
| 66 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
| 67 | + header('ETag: ' . $eTag); |
|
| 68 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
| 69 | 69 | |
| 70 | - // send output |
|
| 71 | - echo $contents; |
|
| 70 | + // send output |
|
| 71 | + echo $contents; |
|
| 72 | 72 | |
| 73 | - //And write to filesystem cache if not done yet |
|
| 74 | - if($encoding != 'none' && $iscompressed == false) |
|
| 75 | - { |
|
| 76 | - //Write the content we sent |
|
| 77 | - file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
| 73 | + //And write to filesystem cache if not done yet |
|
| 74 | + if($encoding != 'none' && $iscompressed == false) |
|
| 75 | + { |
|
| 76 | + //Write the content we sent |
|
| 77 | + file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
| 78 | 78 | |
| 79 | - //And write the new content |
|
| 80 | - $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
| 81 | - $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
| 82 | - $contents = gzencode($code,9,$flag); |
|
| 83 | - file_put_contents(__FILE__.'.'.$ext,$contents); |
|
| 84 | - } |
|
| 79 | + //And write the new content |
|
| 80 | + $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
| 81 | + $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
| 82 | + $contents = gzencode($code,9,$flag); |
|
| 83 | + file_put_contents(__FILE__.'.'.$ext,$contents); |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -88,13 +88,13 @@ |
||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function ao_css_speedup_cleanup($cssin) { |
| 91 | - // speedupper results in aggregated CSS not being minified, so the filestart-marker AO adds when aggregating need to be removed |
|
| 92 | - return trim(str_replace(array('/*FILESTART*/','/*FILESTART2*/'),'',$cssin)); |
|
| 91 | + // speedupper results in aggregated CSS not being minified, so the filestart-marker AO adds when aggregating need to be removed |
|
| 92 | + return trim(str_replace(array('/*FILESTART*/','/*FILESTART2*/'),'',$cssin)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | function ao_js_speedup_cleanup($jsin) { |
| 96 | - // cleanup |
|
| 97 | - return trim($jsin); |
|
| 96 | + // cleanup |
|
| 97 | + return trim($jsin); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | add_filter('autoptimize_css_individual_style','ao_css_snippetcacher',10,2); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | // WP CLI |
| 52 | 52 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 53 | - require_once AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php'; |
|
| 53 | + require_once AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php'; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Initialize the cache at least once |
@@ -137,21 +137,21 @@ discard block |
||
| 137 | 137 | $ao_noptimize = true; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - // if setting says not to optimize logged in user and user is logged in |
|
| 141 | - if ( get_option('autoptimize_optimize_logged','on') !== 'on' && is_user_logged_in() && current_user_can('edit_posts') ) { |
|
| 142 | - $ao_noptimize = true; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // if setting says not to optimize cart/ checkout |
|
| 146 | - if ( get_option('autoptimize_optimize_checkout','on') !== 'on' ) { |
|
| 147 | - // checking for woocommerce, easy digital downloads and wp ecommerce |
|
| 148 | - foreach ( array("is_checkout","is_cart","edd_is_checkout","wpsc_is_cart","wpsc_is_checkout") as $shopCond ) { |
|
| 149 | - if ( function_exists($shopCond) && $shopCond() ) { |
|
| 150 | - $ao_noptimize = true; |
|
| 151 | - break; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 140 | + // if setting says not to optimize logged in user and user is logged in |
|
| 141 | + if ( get_option('autoptimize_optimize_logged','on') !== 'on' && is_user_logged_in() && current_user_can('edit_posts') ) { |
|
| 142 | + $ao_noptimize = true; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // if setting says not to optimize cart/ checkout |
|
| 146 | + if ( get_option('autoptimize_optimize_checkout','on') !== 'on' ) { |
|
| 147 | + // checking for woocommerce, easy digital downloads and wp ecommerce |
|
| 148 | + foreach ( array("is_checkout","is_cart","edd_is_checkout","wpsc_is_cart","wpsc_is_checkout") as $shopCond ) { |
|
| 149 | + if ( function_exists($shopCond) && $shopCond() ) { |
|
| 150 | + $ao_noptimize = true; |
|
| 151 | + break; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | // filter you can use to block autoptimization on your own terms |
| 157 | 157 | $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize ); |
@@ -1,41 +1,41 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; |
|
| 4 | + exit; |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | class autoptimizeCLI extends WP_CLI_Command { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Clears the cache. |
|
| 11 | - * |
|
| 12 | - * @subcommand clear |
|
| 13 | - * @synopsis [--type=<css|js>] |
|
| 14 | - */ |
|
| 15 | - public function clear( $args, $args_assoc ) { |
|
| 16 | - $clear = ''; |
|
| 17 | - if ( ! empty( $args_assoc ) ) { |
|
| 18 | - $clear = $args_assoc['type']; |
|
| 19 | - if ( ! in_array( $clear, array( 'css', 'js' ), true ) ) { |
|
| 20 | - WP_CLI::error( esc_html__( 'Please choose `css` or `js`.', 'autoptimize' ) ); |
|
| 21 | - } |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - if ( empty( $clear ) ) { |
|
| 25 | - WP_CLI::line( esc_html__( 'Flushing the cache...', 'autoptimize' ) ); |
|
| 26 | - autoptimizeCache::clearall(); |
|
| 27 | - WP_CLI::success( esc_html__( 'Cache flushed.', 'autoptimize' ) ); |
|
| 28 | - return; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - WP_CLI::line( esc_html__( 'Clearing the cache...', 'autoptimize' ) ); |
|
| 32 | - |
|
| 33 | - WP_Filesystem(); |
|
| 34 | - global $wp_filesystem; |
|
| 35 | - $wp_filesystem->rmdir( AUTOPTIMIZE_CACHE_DIR . $clear, true ); |
|
| 36 | - |
|
| 37 | - WP_CLI::success( esc_html__( sprintf( '%s cache cleared.', strtoupper( $clear ) ), 'autoptimize' ) ); |
|
| 38 | - } |
|
| 9 | + /** |
|
| 10 | + * Clears the cache. |
|
| 11 | + * |
|
| 12 | + * @subcommand clear |
|
| 13 | + * @synopsis [--type=<css|js>] |
|
| 14 | + */ |
|
| 15 | + public function clear( $args, $args_assoc ) { |
|
| 16 | + $clear = ''; |
|
| 17 | + if ( ! empty( $args_assoc ) ) { |
|
| 18 | + $clear = $args_assoc['type']; |
|
| 19 | + if ( ! in_array( $clear, array( 'css', 'js' ), true ) ) { |
|
| 20 | + WP_CLI::error( esc_html__( 'Please choose `css` or `js`.', 'autoptimize' ) ); |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + if ( empty( $clear ) ) { |
|
| 25 | + WP_CLI::line( esc_html__( 'Flushing the cache...', 'autoptimize' ) ); |
|
| 26 | + autoptimizeCache::clearall(); |
|
| 27 | + WP_CLI::success( esc_html__( 'Cache flushed.', 'autoptimize' ) ); |
|
| 28 | + return; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + WP_CLI::line( esc_html__( 'Clearing the cache...', 'autoptimize' ) ); |
|
| 32 | + |
|
| 33 | + WP_Filesystem(); |
|
| 34 | + global $wp_filesystem; |
|
| 35 | + $wp_filesystem->rmdir( AUTOPTIMIZE_CACHE_DIR . $clear, true ); |
|
| 36 | + |
|
| 37 | + WP_CLI::success( esc_html__( sprintf( '%s cache cleared.', strtoupper( $clear ) ), 'autoptimize' ) ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | } |
| 41 | 41 | |