| @@ -1,9 +1,9 @@ discard block | ||
| 1 | 1 | <?php exit; | 
| 2 | 2 | |
| 3 | 3 | //Check everything exists before using it | 
| 4 | -if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) | |
| 4 | +if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) | |
| 5 | 5 | $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; | 
| 6 | -if(!isset($_SERVER['HTTP_USER_AGENT'])) | |
| 6 | +if (!isset($_SERVER['HTTP_USER_AGENT'])) | |
| 7 | 7 | $_SERVER['HTTP_USER_AGENT'] = ''; | 
| 8 | 8 | |
| 9 | 9 | // Determine supported compression method | 
| @@ -27,16 +27,16 @@ discard block | ||
| 27 | 27 | } | 
| 28 | 28 | |
| 29 | 29 | //Some servers compress the output of PHP - Don't break in those cases | 
| 30 | -if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) | |
| 30 | +if (ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) | |
| 31 | 31 | $encoding = 'none'; | 
| 32 | 32 | |
| 33 | 33 | $iscompressed = file_exists(__FILE__.'.'.$encoding); | 
| 34 | -if($encoding != 'none' && $iscompressed == false) | |
| 34 | +if ($encoding != 'none' && $iscompressed == false) | |
| 35 | 35 |  { | 
| 36 | 36 | $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); | 
| 37 | 37 | $code = file_get_contents(__FILE__.'.none'); | 
| 38 | - $contents = gzencode($code,9,$flag); | |
| 39 | -}else{ | |
| 38 | + $contents = gzencode($code, 9, $flag); | |
| 39 | +} else { | |
| 40 | 40 | //Get data | 
| 41 | 41 | $contents = file_get_contents(__FILE__.'.'.$encoding); | 
| 42 | 42 | } | 
| @@ -44,19 +44,19 @@ discard block | ||
| 44 | 44 | // first check if we have to send 304 | 
| 45 | 45 | // inspired by http://www.jonasjohn.de/snippets/php/caching.htm | 
| 46 | 46 | |
| 47 | -$eTag=md5($contents); | |
| 48 | -$modTime=filemtime(__FILE__.'.none'); | |
| 47 | +$eTag = md5($contents); | |
| 48 | +$modTime = filemtime(__FILE__.'.none'); | |
| 49 | 49 | |
| 50 | 50 |  date_default_timezone_set("UTC"); | 
| 51 | -$eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'],$eTag)); | |
| 51 | +$eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'], $eTag)); | |
| 52 | 52 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); | 
| 53 | 53 | |
| 54 | -if (($modTimeMatch)||($eTagMatch)) { | |
| 54 | +if (($modTimeMatch) || ($eTagMatch)) { | |
| 55 | 55 |  	header('HTTP/1.1 304 Not Modified'); | 
| 56 | 56 |  	header('Connection: close'); | 
| 57 | 57 |  } else { | 
| 58 | 58 | // send all sorts of headers | 
| 59 | - $expireTime=60*60*24*355; // 1y max according to RFC | |
| 59 | + $expireTime = 60*60*24*355; // 1y max according to RFC | |
| 60 | 60 |  	if ($encoding != 'none') { | 
| 61 | 61 |  		header('Content-Encoding: '.$encoding); | 
| 62 | 62 | } | 
| @@ -66,22 +66,22 @@ discard block | ||
| 66 | 66 |  	header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); | 
| 67 | 67 |  	header('Cache-Control: max-age='.$expireTime.', public, immutable'); | 
| 68 | 68 |  	header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); | 
| 69 | -	header('ETag: ' . $eTag); | |
| 69 | +	header('ETag: '.$eTag); | |
| 70 | 70 |  	header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); | 
| 71 | 71 | |
| 72 | 72 | // send output | 
| 73 | 73 | echo $contents; | 
| 74 | 74 | |
| 75 | 75 | //And write to filesystem cache if not done yet | 
| 76 | - if($encoding != 'none' && $iscompressed == false) | |
| 76 | + if ($encoding != 'none' && $iscompressed == false) | |
| 77 | 77 |  	{ | 
| 78 | 78 | //Write the content we sent | 
| 79 | - file_put_contents(__FILE__.'.'.$encoding,$contents); | |
| 79 | + file_put_contents(__FILE__.'.'.$encoding, $contents); | |
| 80 | 80 | |
| 81 | 81 | //And write the new content | 
| 82 | 82 | $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); | 
| 83 | 83 | $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); | 
| 84 | - $contents = gzencode($code,9,$flag); | |
| 85 | - file_put_contents(__FILE__.'.'.$ext,$contents); | |
| 84 | + $contents = gzencode($code, 9, $flag); | |
| 85 | + file_put_contents(__FILE__.'.'.$ext, $contents); | |
| 86 | 86 | } | 
| 87 | 87 | } | 
| @@ -1,10 +1,12 @@ discard block | ||
| 1 | 1 | <?php exit; | 
| 2 | 2 | |
| 3 | 3 | //Check everything exists before using it | 
| 4 | -if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) | |
| 4 | +if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { | |
| 5 | 5 | $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; | 
| 6 | -if(!isset($_SERVER['HTTP_USER_AGENT'])) | |
| 6 | +} | |
| 7 | +if(!isset($_SERVER['HTTP_USER_AGENT'])) { | |
| 7 | 8 | $_SERVER['HTTP_USER_AGENT'] = ''; | 
| 9 | +} | |
| 8 | 10 | |
| 9 | 11 | // Determine supported compression method | 
| 10 | 12 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); | 
| @@ -19,16 +21,19 @@ discard block | ||
| 19 | 21 |  { | 
| 20 | 22 | $version = floatval($matches[1]); | 
| 21 | 23 | |
| 22 | - if ($version < 6) | |
| 23 | - $encoding = 'none'; | |
| 24 | +	if ($version < 6) { | |
| 25 | + $encoding = 'none'; | |
| 26 | + } | |
| 24 | 27 | |
| 25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) | |
| 26 | - $encoding = 'none'; | |
| 27 | -} | |
| 28 | +	if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) { | |
| 29 | + $encoding = 'none'; | |
| 30 | + } | |
| 31 | + } | |
| 28 | 32 | |
| 29 | 33 | //Some servers compress the output of PHP - Don't break in those cases | 
| 30 | -if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) | |
| 34 | +if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) { | |
| 31 | 35 | $encoding = 'none'; | 
| 36 | +} | |
| 32 | 37 | |
| 33 | 38 | $iscompressed = file_exists(__FILE__.'.'.$encoding); | 
| 34 | 39 | if($encoding != 'none' && $iscompressed == false) | 
| @@ -36,7 +41,7 @@ discard block | ||
| 36 | 41 | $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); | 
| 37 | 42 | $code = file_get_contents(__FILE__.'.none'); | 
| 38 | 43 | $contents = gzencode($code,9,$flag); | 
| 39 | -}else{ | |
| 44 | +} else{ | |
| 40 | 45 | //Get data | 
| 41 | 46 | $contents = file_get_contents(__FILE__.'.'.$encoding); | 
| 42 | 47 | } | 
| @@ -38,18 +38,18 @@ discard block | ||
| 38 | 38 |          $l = floatval(str_replace('%', '', $hslValues[2])); | 
| 39 | 39 | |
| 40 | 40 | // Wrap and clamp, then fraction! | 
| 41 | - $h = ((($h % 360) + 360) % 360) / 360; | |
| 42 | - $s = self::clampNumber($s, 0, 100) / 100; | |
| 43 | - $l = self::clampNumber($l, 0, 100) / 100; | |
| 41 | + $h = ((($h%360) + 360)%360)/360; | |
| 42 | + $s = self::clampNumber($s, 0, 100)/100; | |
| 43 | + $l = self::clampNumber($l, 0, 100)/100; | |
| 44 | 44 | |
| 45 | 45 |          if ($s == 0) { | 
| 46 | - $r = $g = $b = self::roundNumber(255 * $l); | |
| 46 | + $r = $g = $b = self::roundNumber(255*$l); | |
| 47 | 47 |          } else { | 
| 48 | - $v2 = $l < 0.5 ? $l * (1 + $s) : ($l + $s) - ($s * $l); | |
| 49 | - $v1 = (2 * $l) - $v2; | |
| 50 | - $r = self::roundNumber(255 * self::hueToRgb($v1, $v2, $h + (1/3))); | |
| 51 | - $g = self::roundNumber(255 * self::hueToRgb($v1, $v2, $h)); | |
| 52 | - $b = self::roundNumber(255 * self::hueToRgb($v1, $v2, $h - (1/3))); | |
| 48 | + $v2 = $l < 0.5 ? $l*(1 + $s) : ($l + $s) - ($s*$l); | |
| 49 | + $v1 = (2*$l) - $v2; | |
| 50 | + $r = self::roundNumber(255*self::hueToRgb($v1, $v2, $h + (1/3))); | |
| 51 | + $g = self::roundNumber(255*self::hueToRgb($v1, $v2, $h)); | |
| 52 | + $b = self::roundNumber(255*self::hueToRgb($v1, $v2, $h - (1/3))); | |
| 53 | 53 | } | 
| 54 | 54 | |
| 55 | 55 | return array($r, $g, $b); | 
| @@ -66,16 +66,16 @@ discard block | ||
| 66 | 66 |      { | 
| 67 | 67 | $vh = $vh < 0 ? $vh + 1 : ($vh > 1 ? $vh - 1 : $vh); | 
| 68 | 68 | |
| 69 | -        if ($vh * 6 < 1) { | |
| 70 | - return $v1 + ($v2 - $v1) * 6 * $vh; | |
| 69 | +        if ($vh*6 < 1) { | |
| 70 | + return $v1 + ($v2 - $v1)*6*$vh; | |
| 71 | 71 | } | 
| 72 | 72 | |
| 73 | -        if ($vh * 2 < 1) { | |
| 73 | +        if ($vh*2 < 1) { | |
| 74 | 74 | return $v2; | 
| 75 | 75 | } | 
| 76 | 76 | |
| 77 | -        if ($vh * 3 < 2) { | |
| 78 | - return $v1 + ($v2 - $v1) * ((2 / 3) - $vh) * 6; | |
| 77 | +        if ($vh*3 < 2) { | |
| 78 | + return $v1 + ($v2 - $v1)*((2/3) - $vh)*6; | |
| 79 | 79 | } | 
| 80 | 80 | |
| 81 | 81 | return $v1; | 
| @@ -94,13 +94,13 @@ discard block | ||
| 94 | 94 |              switch ($letter) { | 
| 95 | 95 | case 'M': | 
| 96 | 96 | case 'm': | 
| 97 | - return (int) $size * 1048576; | |
| 97 | + return (int) $size*1048576; | |
| 98 | 98 | case 'K': | 
| 99 | 99 | case 'k': | 
| 100 | - return (int) $size * 1024; | |
| 100 | + return (int) $size*1024; | |
| 101 | 101 | case 'G': | 
| 102 | 102 | case 'g': | 
| 103 | - return (int) $size * 1073741824; | |
| 103 | + return (int) $size*1073741824; | |
| 104 | 104 | } | 
| 105 | 105 | } | 
| 106 | 106 | return (int) $size; | 
| @@ -114,7 +114,7 @@ discard block | ||
| 114 | 114 | public static function rgbPercentageToRgbInteger($rgbPercentage) | 
| 115 | 115 |      { | 
| 116 | 116 |          if (strpos($rgbPercentage, '%') !== false) { | 
| 117 | -            $rgbPercentage = self::roundNumber(floatval(str_replace('%', '', $rgbPercentage)) * 2.55); | |
| 117 | +            $rgbPercentage = self::roundNumber(floatval(str_replace('%', '', $rgbPercentage))*2.55); | |
| 118 | 118 | } | 
| 119 | 119 | |
| 120 | 120 | return intval($rgbPercentage, 10); | 
| @@ -3,7 +3,7 @@ discard block | ||
| 3 | 3 | * Handles minifying HTML markup. | 
| 4 | 4 | */ | 
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | +if (!defined('ABSPATH')) { | |
| 7 | 7 | exit; | 
| 8 | 8 | } | 
| 9 | 9 | |
| @@ -27,19 +27,19 @@ discard block | ||
| 27 | 27 | '<!--/noindex-->', | 
| 28 | 28 | ); | 
| 29 | 29 | |
| 30 | - public function read( $options ) | |
| 30 | + public function read($options) | |
| 31 | 31 |      { | 
| 32 | 32 | // Remove the HTML comments? | 
| 33 | 33 | $this->keepcomments = (bool) $options['keepcomments']; | 
| 34 | 34 | |
| 35 | 35 | // Filter to force xhtml. | 
| 36 | - $this->forcexhtml = (bool) apply_filters( 'autoptimize_filter_html_forcexhtml', false ); | |
| 36 | +        $this->forcexhtml = (bool) apply_filters('autoptimize_filter_html_forcexhtml', false); | |
| 37 | 37 | |
| 38 | 38 | // Filterable strings to be excluded from HTML minification. | 
| 39 | - $exclude = apply_filters( 'autoptimize_filter_html_exclude', '' ); | |
| 40 | -        if ( '' !== $exclude ) { | |
| 41 | - $exclude_arr = array_filter( array_map( 'trim', explode( ',', $exclude ) ) ); | |
| 42 | - $this->exclude = array_merge( $exclude_arr, $this->exclude ); | |
| 39 | +        $exclude = apply_filters('autoptimize_filter_html_exclude', ''); | |
| 40 | +        if ('' !== $exclude) { | |
| 41 | +            $exclude_arr   = array_filter(array_map('trim', explode(',', $exclude))); | |
| 42 | + $this->exclude = array_merge($exclude_arr, $this->exclude); | |
| 43 | 43 | } | 
| 44 | 44 | |
| 45 | 45 | // Nothing else for HTML! | 
| @@ -53,49 +53,49 @@ discard block | ||
| 53 | 53 | */ | 
| 54 | 54 | public function minify() | 
| 55 | 55 |      { | 
| 56 | - $noptimize = apply_filters( 'autoptimize_filter_html_noptimize', false, $this->content ); | |
| 57 | -        if ( $noptimize ) { | |
| 56 | +        $noptimize = apply_filters('autoptimize_filter_html_noptimize', false, $this->content); | |
| 57 | +        if ($noptimize) { | |
| 58 | 58 | return false; | 
| 59 | 59 | } | 
| 60 | 60 | |
| 61 | 61 | // Wrap the to-be-excluded strings in noptimize tags. | 
| 62 | -        foreach ( $this->exclude as $str ) { | |
| 63 | -            if ( false !== strpos( $this->content, $str ) ) { | |
| 64 | - $replacement = '<!--noptimize-->' . $str . '<!--/noptimize-->'; | |
| 65 | - $this->content = str_replace( $str, $replacement, $this->content ); | |
| 62 | +        foreach ($this->exclude as $str) { | |
| 63 | +            if (false !== strpos($this->content, $str)) { | |
| 64 | + $replacement = '<!--noptimize-->'.$str.'<!--/noptimize-->'; | |
| 65 | + $this->content = str_replace($str, $replacement, $this->content); | |
| 66 | 66 | } | 
| 67 | 67 | } | 
| 68 | 68 | |
| 69 | 69 | // Noptimize. | 
| 70 | - $this->content = $this->hide_noptimize( $this->content ); | |
| 70 | + $this->content = $this->hide_noptimize($this->content); | |
| 71 | 71 | |
| 72 | 72 | // Preparing options for Minify_HTML. | 
| 73 | - $options = array( 'keepComments' => $this->keepcomments ); | |
| 74 | -        if ( $this->forcexhtml ) { | |
| 73 | +        $options = array('keepComments' => $this->keepcomments); | |
| 74 | +        if ($this->forcexhtml) { | |
| 75 | 75 | $options['xhtml'] = true; | 
| 76 | 76 | } | 
| 77 | 77 | |
| 78 | - $tmp_content = Minify_HTML::minify( $this->content, $options ); | |
| 79 | -        if ( ! empty( $tmp_content ) ) { | |
| 78 | + $tmp_content = Minify_HTML::minify($this->content, $options); | |
| 79 | +        if (!empty($tmp_content)) { | |
| 80 | 80 | $this->content = $tmp_content; | 
| 81 | - unset( $tmp_content ); | |
| 81 | + unset($tmp_content); | |
| 82 | 82 | } | 
| 83 | 83 | |
| 84 | 84 | // Restore noptimize. | 
| 85 | - $this->content = $this->restore_noptimize( $this->content ); | |
| 85 | + $this->content = $this->restore_noptimize($this->content); | |
| 86 | 86 | |
| 87 | 87 | // Remove the noptimize-wrapper from around the excluded strings. | 
| 88 | -        foreach ( $this->exclude as $str ) { | |
| 89 | - $replacement = '<!--noptimize-->' . $str . '<!--/noptimize-->'; | |
| 90 | -            if ( false !== strpos( $this->content, $replacement ) ) { | |
| 91 | - $this->content = str_replace( $replacement, $str, $this->content ); | |
| 88 | +        foreach ($this->exclude as $str) { | |
| 89 | + $replacement = '<!--noptimize-->'.$str.'<!--/noptimize-->'; | |
| 90 | +            if (false !== strpos($this->content, $replacement)) { | |
| 91 | + $this->content = str_replace($replacement, $str, $this->content); | |
| 92 | 92 | } | 
| 93 | 93 | } | 
| 94 | 94 | |
| 95 | 95 | // Revslider data attribs somehow suffer from HTML optimization, this fixes that! | 
| 96 | -        if ( class_exists( 'RevSlider' ) && apply_filters( 'autoptimize_filter_html_dataattrib_cleanup', false ) ) { | |
| 97 | - $this->content = preg_replace( '#\n(data-.*$)\n#Um', ' $1 ', $this->content ); | |
| 98 | - $this->content = preg_replace( '#<[^>]*(=\"[^"\'<>\s]*\")(\w)#', '$1 $2', $this->content ); | |
| 96 | +        if (class_exists('RevSlider') && apply_filters('autoptimize_filter_html_dataattrib_cleanup', false)) { | |
| 97 | +            $this->content = preg_replace('#\n(data-.*$)\n#Um', ' $1 ', $this->content); | |
| 98 | +            $this->content = preg_replace('#<[^>]*(=\"[^"\'<>\s]*\")(\w)#', '$1 $2', $this->content); | |
| 99 | 99 | } | 
| 100 | 100 | |
| 101 | 101 | return true; | 
| @@ -3,12 +3,12 @@ discard block | ||
| 3 | 3 | * WP-CLI commands for Autoptimize. | 
| 4 | 4 | */ | 
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | +if (!defined('ABSPATH')) { | |
| 7 | 7 | exit; | 
| 8 | 8 | } | 
| 9 | 9 | |
| 10 | 10 | // This is a WP-CLI command, so bail if it's not available. | 
| 11 | -if ( ! defined( 'WP_CLI' ) ) { | |
| 11 | +if (!defined('WP_CLI')) { | |
| 12 | 12 | return; | 
| 13 | 13 | } | 
| 14 | 14 | |
| @@ -24,11 +24,11 @@ discard block | ||
| 24 | 24 | * | 
| 25 | 25 | * @return void | 
| 26 | 26 | */ | 
| 27 | -    public function clear( $args, $args_assoc ) { | |
| 28 | - WP_CLI::line( esc_html__( 'Flushing the cache...', 'autoptimize' ) ); | |
| 27 | +    public function clear($args, $args_assoc) { | |
| 28 | +        WP_CLI::line(esc_html__('Flushing the cache...', 'autoptimize')); | |
| 29 | 29 | autoptimizeCache::clearall(); | 
| 30 | - WP_CLI::success( esc_html__( 'Cache flushed.', 'autoptimize' ) ); | |
| 30 | +        WP_CLI::success(esc_html__('Cache flushed.', 'autoptimize')); | |
| 31 | 31 | } | 
| 32 | 32 | } | 
| 33 | 33 | |
| 34 | -WP_CLI::add_command( 'autoptimize', 'autoptimizeCLI' ); | |
| 34 | +WP_CLI::add_command('autoptimize', 'autoptimizeCLI'); | |
| @@ -3,7 +3,7 @@ discard block | ||
| 3 | 3 | * Thin wrapper around css minifiers to avoid rewriting a bunch of existing code. | 
| 4 | 4 | */ | 
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | +if (!defined('ABSPATH')) { | |
| 7 | 7 | exit; | 
| 8 | 8 | } | 
| 9 | 9 | |
| @@ -21,9 +21,9 @@ discard block | ||
| 21 | 21 | * | 
| 22 | 22 | * @param bool $raise_limits Whether to raise memory limits or not. Default true. | 
| 23 | 23 | */ | 
| 24 | - public function __construct( $raise_limits = true ) | |
| 24 | + public function __construct($raise_limits = true) | |
| 25 | 25 |      { | 
| 26 | - $this->minifier = new Autoptimize\tubalmartin\CssMin\Minifier( $raise_limits ); | |
| 26 | + $this->minifier = new Autoptimize\tubalmartin\CssMin\Minifier($raise_limits); | |
| 27 | 27 | } | 
| 28 | 28 | |
| 29 | 29 | /** | 
| @@ -34,9 +34,9 @@ discard block | ||
| 34 | 34 | * | 
| 35 | 35 | * @return string | 
| 36 | 36 | */ | 
| 37 | - public function run( $css ) | |
| 37 | + public function run($css) | |
| 38 | 38 |      { | 
| 39 | - $result = $this->minifier->run( $css ); | |
| 39 | + $result = $this->minifier->run($css); | |
| 40 | 40 | |
| 41 | 41 | return $result; | 
| 42 | 42 | } | 
| @@ -48,10 +48,10 @@ discard block | ||
| 48 | 48 | * | 
| 49 | 49 | * @return string | 
| 50 | 50 | */ | 
| 51 | - public static function minify( $css ) | |
| 51 | + public static function minify($css) | |
| 52 | 52 |      { | 
| 53 | 53 | $minifier = new self(); | 
| 54 | 54 | |
| 55 | - return $minifier->run( $css ); | |
| 55 | + return $minifier->run($css); | |
| 56 | 56 | } | 
| 57 | 57 | } | 
| @@ -4,7 +4,7 @@ discard block | ||
| 4 | 4 | * new in Autoptimize 2.2 | 
| 5 | 5 | */ | 
| 6 | 6 | |
| 7 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 7 | +if (!defined('ABSPATH')) { | |
| 8 | 8 | exit; | 
| 9 | 9 | } | 
| 10 | 10 | |
| @@ -17,94 +17,94 @@ discard block | ||
| 17 | 17 | |
| 18 | 18 | public function add_hooks() | 
| 19 | 19 |      { | 
| 20 | -        if ( apply_filters( 'autoptimize_js_do_minify', true ) ) { | |
| 21 | - add_filter( 'autoptimize_js_individual_script', array( $this, 'js_snippetcacher' ), 10, 2 ); | |
| 22 | - add_filter( 'autoptimize_js_after_minify', array( $this, 'js_cleanup' ), 10, 1 ); | |
| 20 | +        if (apply_filters('autoptimize_js_do_minify', true)) { | |
| 21 | +            add_filter('autoptimize_js_individual_script', array($this, 'js_snippetcacher'), 10, 2); | |
| 22 | +            add_filter('autoptimize_js_after_minify', array($this, 'js_cleanup'), 10, 1); | |
| 23 | 23 | } | 
| 24 | -        if ( apply_filters( 'autoptimize_css_do_minify', true ) ) { | |
| 25 | - add_filter( 'autoptimize_css_individual_style', array( $this, 'css_snippetcacher' ), 10, 2 ); | |
| 26 | - add_filter( 'autoptimize_css_after_minify', array( $this, 'css_cleanup' ), 10, 1 ); | |
| 24 | +        if (apply_filters('autoptimize_css_do_minify', true)) { | |
| 25 | +            add_filter('autoptimize_css_individual_style', array($this, 'css_snippetcacher'), 10, 2); | |
| 26 | +            add_filter('autoptimize_css_after_minify', array($this, 'css_cleanup'), 10, 1); | |
| 27 | 27 | } | 
| 28 | 28 | } | 
| 29 | 29 | |
| 30 | - public function js_snippetcacher( $jsin, $jsfilename ) | |
| 30 | + public function js_snippetcacher($jsin, $jsfilename) | |
| 31 | 31 |      { | 
| 32 | - $md5hash = 'snippet_' . md5( $jsin ); | |
| 33 | - $ccheck = new autoptimizeCache( $md5hash, 'js' ); | |
| 34 | -        if ( $ccheck->check() ) { | |
| 32 | + $md5hash = 'snippet_'.md5($jsin); | |
| 33 | + $ccheck = new autoptimizeCache($md5hash, 'js'); | |
| 34 | +        if ($ccheck->check()) { | |
| 35 | 35 | $scriptsrc = $ccheck->retrieve(); | 
| 36 | 36 |          } else { | 
| 37 | -            if ( false === ( strpos( $jsfilename, 'min.js' ) ) && ( false === strpos( $jsfilename, 'js/jquery/jquery.js' ) ) && ( str_replace( apply_filters( 'autoptimize_filter_js_consider_minified', false ), '', $jsfilename ) === $jsfilename ) ) { | |
| 38 | - $tmp_jscode = trim( JSMin::minify( $jsin ) ); | |
| 39 | -                if ( ! empty( $tmp_jscode ) ) { | |
| 37 | +            if (false === (strpos($jsfilename, 'min.js')) && (false === strpos($jsfilename, 'js/jquery/jquery.js')) && (str_replace(apply_filters('autoptimize_filter_js_consider_minified', false), '', $jsfilename) === $jsfilename)) { | |
| 38 | + $tmp_jscode = trim(JSMin::minify($jsin)); | |
| 39 | +                if (!empty($tmp_jscode)) { | |
| 40 | 40 | $scriptsrc = $tmp_jscode; | 
| 41 | - unset( $tmp_jscode ); | |
| 41 | + unset($tmp_jscode); | |
| 42 | 42 |                  } else { | 
| 43 | 43 | $scriptsrc = $jsin; | 
| 44 | 44 | } | 
| 45 | 45 |              } else { | 
| 46 | 46 | // Removing comments, linebreaks and stuff! | 
| 47 | - $scriptsrc = preg_replace( '#^\s*\/\/.*$#Um', '', $jsin ); | |
| 48 | - $scriptsrc = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Us', '', $scriptsrc ); | |
| 49 | - $scriptsrc = preg_replace( "#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc ); | |
| 47 | +                $scriptsrc = preg_replace('#^\s*\/\/.*$#Um', '', $jsin); | |
| 48 | +                $scriptsrc = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Us', '', $scriptsrc); | |
| 49 | +                $scriptsrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc); | |
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | - $last_char = substr( $scriptsrc, -1, 1 ); | |
| 53 | -            if ( ';' !== $last_char && '}' !== $last_char ) { | |
| 52 | + $last_char = substr($scriptsrc, -1, 1); | |
| 53 | +            if (';' !== $last_char && '}' !== $last_char) { | |
| 54 | 54 | $scriptsrc .= ';'; | 
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | -            if ( ! empty( $jsfilename ) && str_replace( apply_filters( 'autoptimize_filter_js_speedup_cache', false ), '', $jsfilename ) === $jsfilename ) { | |
| 57 | +            if (!empty($jsfilename) && str_replace(apply_filters('autoptimize_filter_js_speedup_cache', false), '', $jsfilename) === $jsfilename) { | |
| 58 | 58 | // Don't cache inline CSS or if filter says no! | 
| 59 | - $ccheck->cache( $scriptsrc, 'text/javascript' ); | |
| 59 | + $ccheck->cache($scriptsrc, 'text/javascript'); | |
| 60 | 60 | } | 
| 61 | 61 | } | 
| 62 | - unset( $ccheck ); | |
| 62 | + unset($ccheck); | |
| 63 | 63 | |
| 64 | 64 | return $scriptsrc; | 
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | - public function css_snippetcacher( $cssin, $cssfilename ) | |
| 67 | + public function css_snippetcacher($cssin, $cssfilename) | |
| 68 | 68 |      { | 
| 69 | - $md5hash = 'snippet_' . md5( $cssin ); | |
| 70 | - $ccheck = new autoptimizeCache( $md5hash, 'css' ); | |
| 71 | -        if ( $ccheck->check() ) { | |
| 69 | + $md5hash = 'snippet_'.md5($cssin); | |
| 70 | + $ccheck = new autoptimizeCache($md5hash, 'css'); | |
| 71 | +        if ($ccheck->check()) { | |
| 72 | 72 | $stylesrc = $ccheck->retrieve(); | 
| 73 | 73 |          } else { | 
| 74 | -            if ( ( false === strpos( $cssfilename, 'min.css' ) ) && ( str_replace( apply_filters( 'autoptimize_filter_css_consider_minified', false ), '', $cssfilename ) === $cssfilename ) ) { | |
| 74 | +            if ((false === strpos($cssfilename, 'min.css')) && (str_replace(apply_filters('autoptimize_filter_css_consider_minified', false), '', $cssfilename) === $cssfilename)) { | |
| 75 | 75 | $cssmin = new autoptimizeCSSmin(); | 
| 76 | - $tmp_code = trim( $cssmin->run( $cssin ) ); | |
| 76 | + $tmp_code = trim($cssmin->run($cssin)); | |
| 77 | 77 | |
| 78 | -                if ( ! empty( $tmp_code ) ) { | |
| 78 | +                if (!empty($tmp_code)) { | |
| 79 | 79 | $stylesrc = $tmp_code; | 
| 80 | - unset( $tmp_code ); | |
| 80 | + unset($tmp_code); | |
| 81 | 81 |                  } else { | 
| 82 | 82 | $stylesrc = $cssin; | 
| 83 | 83 | } | 
| 84 | 84 |              } else { | 
| 85 | 85 | // .min.css -> no heavy-lifting, just some cleanup! | 
| 86 | - $stylesrc = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Us', '', $cssin ); | |
| 87 | - $stylesrc = preg_replace( "#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc ); | |
| 88 | - $stylesrc = autoptimizeStyles::fixurls( $cssfilename, $stylesrc ); | |
| 86 | +                $stylesrc = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Us', '', $cssin); | |
| 87 | +                $stylesrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc); | |
| 88 | + $stylesrc = autoptimizeStyles::fixurls($cssfilename, $stylesrc); | |
| 89 | 89 | } | 
| 90 | -            if ( ! empty( $cssfilename ) && ( str_replace( apply_filters( 'autoptimize_filter_css_speedup_cache', false ), '', $cssfilename ) === $cssfilename ) ) { | |
| 90 | +            if (!empty($cssfilename) && (str_replace(apply_filters('autoptimize_filter_css_speedup_cache', false), '', $cssfilename) === $cssfilename)) { | |
| 91 | 91 | // Only caching CSS if it's not inline and is allowed by filter! | 
| 92 | - $ccheck->cache( $stylesrc, 'text/css' ); | |
| 92 | + $ccheck->cache($stylesrc, 'text/css'); | |
| 93 | 93 | } | 
| 94 | 94 | } | 
| 95 | - unset( $ccheck ); | |
| 95 | + unset($ccheck); | |
| 96 | 96 | |
| 97 | 97 | return $stylesrc; | 
| 98 | 98 | } | 
| 99 | 99 | |
| 100 | - public function css_cleanup( $cssin ) | |
| 100 | + public function css_cleanup($cssin) | |
| 101 | 101 |      { | 
| 102 | 102 | // Speedupper results in aggregated CSS not being minified, so the filestart-marker AO adds when aggregating needs to be removed. | 
| 103 | - return trim( str_replace( array( '/*FILESTART*/', '/*FILESTART2*/' ), '', $cssin ) ); | |
| 103 | +        return trim(str_replace(array('/*FILESTART*/', '/*FILESTART2*/'), '', $cssin)); | |
| 104 | 104 | } | 
| 105 | 105 | |
| 106 | - public function js_cleanup( $jsin ) | |
| 106 | + public function js_cleanup($jsin) | |
| 107 | 107 |      { | 
| 108 | - return trim( $jsin ); | |
| 108 | + return trim($jsin); | |
| 109 | 109 | } | 
| 110 | 110 | } | 
| @@ -72,9 +72,9 @@ discard block | ||
| 72 | 72 | public function __construct($raisePhpLimits = true) | 
| 73 | 73 |      { | 
| 74 | 74 | $this->raisePhpLimits = (bool) $raisePhpLimits; | 
| 75 | - $this->memoryLimit = 128 * 1048576; // 128MB in bytes | |
| 76 | - $this->pcreBacktrackLimit = 1000 * 1000; | |
| 77 | - $this->pcreRecursionLimit = 500 * 1000; | |
| 75 | + $this->memoryLimit = 128*1048576; // 128MB in bytes | |
| 76 | + $this->pcreBacktrackLimit = 1000*1000; | |
| 77 | + $this->pcreRecursionLimit = 500*1000; | |
| 78 | 78 | $this->hexToNamedColorsMap = Colors::getHexToNamedMap(); | 
| 79 | 79 | $this->namedToHexColorsMap = Colors::getNamedToHexMap(); | 
| 80 | 80 | $this->namedToHexColorsRegex = sprintf( | 
| @@ -176,8 +176,8 @@ discard block | ||
| 176 | 176 | */ | 
| 177 | 177 | private function setShortenZeroValuesRegexes() | 
| 178 | 178 |      { | 
| 179 | - $zeroRegex = '0'. $this->unitsGroupRegex; | |
| 180 | -        $numOrPosRegex = '('. $this->numRegex .'|top|left|bottom|right|center) '; | |
| 179 | + $zeroRegex = '0'.$this->unitsGroupRegex; | |
| 180 | +        $numOrPosRegex = '('.$this->numRegex.'|top|left|bottom|right|center) '; | |
| 181 | 181 | $oneZeroSafeProperties = array( | 
| 182 | 182 | '(?:line-)?height', | 
| 183 | 183 | '(?:(?:min|max)-)?width', | 
| @@ -195,14 +195,14 @@ discard block | ||
| 195 | 195 | ); | 
| 196 | 196 | |
| 197 | 197 | // First zero regex | 
| 198 | -        $regex = '/(^|;)('. implode('|', $oneZeroSafeProperties) .'):%s/Si'; | |
| 198 | +        $regex = '/(^|;)('.implode('|', $oneZeroSafeProperties).'):%s/Si'; | |
| 199 | 199 | $this->shortenOneZeroesRegex = sprintf($regex, $zeroRegex); | 
| 200 | 200 | |
| 201 | 201 | // Multiple zeroes regexes | 
| 202 | 202 | $regex = '/(^|;)(margin|padding|border-(?:width|radius)|background-position):%s/Si'; | 
| 203 | - $this->shortenTwoZeroesRegex = sprintf($regex, $numOrPosRegex . $zeroRegex); | |
| 204 | - $this->shortenThreeZeroesRegex = sprintf($regex, $numOrPosRegex . $numOrPosRegex . $zeroRegex); | |
| 205 | - $this->shortenFourZeroesRegex = sprintf($regex, $numOrPosRegex . $numOrPosRegex . $numOrPosRegex . $zeroRegex); | |
| 203 | + $this->shortenTwoZeroesRegex = sprintf($regex, $numOrPosRegex.$zeroRegex); | |
| 204 | + $this->shortenThreeZeroesRegex = sprintf($regex, $numOrPosRegex.$numOrPosRegex.$zeroRegex); | |
| 205 | + $this->shortenFourZeroesRegex = sprintf($regex, $numOrPosRegex.$numOrPosRegex.$numOrPosRegex.$zeroRegex); | |
| 206 | 206 | } | 
| 207 | 207 | |
| 208 | 208 | /** | 
| @@ -389,7 +389,7 @@ discard block | ||
| 389 | 389 | $dataStartIndex = $matchStartIndex + 4; // url( length | 
| 390 | 390 | $searchOffset = $matchStartIndex + strlen($m[0][0]); | 
| 391 | 391 | $terminator = $m[1][0]; // ', " or empty (not quoted) | 
| 392 | - $terminatorRegex = '/(?<!\\\\)'. (strlen($terminator) === 0 ? '' : $terminator.'\s*') .'(\))/S'; | |
| 392 | + $terminatorRegex = '/(?<!\\\\)'.(strlen($terminator) === 0 ? '' : $terminator.'\s*').'(\))/S'; | |
| 393 | 393 | |
| 394 | 394 | $ret .= substr($css, $substrOffset, $matchStartIndex - $substrOffset); | 
| 395 | 395 | |
| @@ -404,7 +404,7 @@ discard block | ||
| 404 | 404 |                      $token = preg_replace('/\s+/S', '', $token); | 
| 405 | 405 | } | 
| 406 | 406 | |
| 407 | -                $ret .= 'url('. $this->registerPreservedToken(trim($token)) .')'; | |
| 407 | +                $ret .= 'url('.$this->registerPreservedToken(trim($token)).')'; | |
| 408 | 408 | // No end terminator found, re-add the whole match. Should we throw/warn here? | 
| 409 | 409 |              } else { | 
| 410 | 410 | $ret .= substr($css, $matchStartIndex, $searchOffset - $matchStartIndex); | 
| @@ -425,7 +425,7 @@ discard block | ||
| 425 | 425 | */ | 
| 426 | 426 | private function processCommentsCallback($matches) | 
| 427 | 427 |      { | 
| 428 | - return '/*'. $this->registerCommentToken($matches[1]) .'*/'; | |
| 428 | + return '/*'.$this->registerCommentToken($matches[1]).'*/'; | |
| 429 | 429 | } | 
| 430 | 430 | |
| 431 | 431 | /** | 
| @@ -435,7 +435,7 @@ discard block | ||
| 435 | 435 | */ | 
| 436 | 436 | private function processOldIeSpecificMatrixDefinitionCallback($matches) | 
| 437 | 437 |      { | 
| 438 | -        return 'filter:progid:DXImageTransform.Microsoft.Matrix('. $this->registerPreservedToken($matches[1]) .')'; | |
| 438 | +        return 'filter:progid:DXImageTransform.Microsoft.Matrix('.$this->registerPreservedToken($matches[1]).')'; | |
| 439 | 439 | } | 
| 440 | 440 | |
| 441 | 441 | /** | 
| @@ -458,7 +458,7 @@ discard block | ||
| 458 | 458 | // minify alpha opacity in filter strings | 
| 459 | 459 |          $match = str_ireplace('progid:DXImageTransform.Microsoft.Alpha(Opacity=', 'alpha(opacity=', $match); | 
| 460 | 460 | |
| 461 | - return $quote . $this->registerPreservedToken($match) . $quote; | |
| 461 | + return $quote.$this->registerPreservedToken($match).$quote; | |
| 462 | 462 | } | 
| 463 | 463 | |
| 464 | 464 | /** | 
| @@ -469,7 +469,7 @@ discard block | ||
| 469 | 469 | */ | 
| 470 | 470 | private function processImportUnquotedUrlAtRulesCallback($matches) | 
| 471 | 471 |      { | 
| 472 | -        return '@import url('. $this->registerPreservedToken($matches[1]) .')'. $matches[2]; | |
| 472 | +        return '@import url('.$this->registerPreservedToken($matches[1]).')'.$matches[2]; | |
| 473 | 473 | } | 
| 474 | 474 | |
| 475 | 475 | /** | 
| @@ -480,7 +480,7 @@ discard block | ||
| 480 | 480 | private function processComments($css) | 
| 481 | 481 |      { | 
| 482 | 482 |          foreach ($this->comments as $commentId => $comment) { | 
| 483 | - $commentIdString = '/*'. $commentId .'*/'; | |
| 483 | + $commentIdString = '/*'.$commentId.'*/'; | |
| 484 | 484 | |
| 485 | 485 | // ! in the first position of the comment means preserve | 
| 486 | 486 | // so push to the preserved tokens keeping the ! | 
| @@ -531,7 +531,7 @@ discard block | ||
| 531 | 531 | $blockEndPos = strpos($css, '}', $blockStartPos); | 
| 532 | 532 | // When ending curly brace is missing, let's | 
| 533 | 533 | // behave like there was one at the end of the block... | 
| 534 | -            if ( false === $blockEndPos ) { | |
| 534 | +            if (false === $blockEndPos) { | |
| 535 | 535 | $blockEndPos = strlen($css) - 1; | 
| 536 | 536 | } | 
| 537 | 537 |              $nextBlockStartPos = strpos($css, '{', $blockStartPos + 1); | 
| @@ -543,7 +543,7 @@ discard block | ||
| 543 | 543 |              } else { | 
| 544 | 544 | $ruleBody = substr($css, $blockStartPos + 1, $blockEndPos - $blockStartPos - 1); | 
| 545 | 545 | $ruleBodyToken = $this->registerRuleBodyToken($this->processRuleBody($ruleBody)); | 
| 546 | -                $ret .= '{'. $ruleBodyToken .'}'; | |
| 546 | +                $ret .= '{'.$ruleBodyToken.'}'; | |
| 547 | 547 | $searchOffset = $blockEndPos + 1; | 
| 548 | 548 | } | 
| 549 | 549 | |
| @@ -643,8 +643,8 @@ discard block | ||
| 643 | 643 |          $body = preg_replace('/([ :,(])\+(\.?\d+)/S', '$1$2', $body); | 
| 644 | 644 | |
| 645 | 645 | // shorten ms to s | 
| 646 | -        $body = preg_replace_callback('/([ :,(])(-?)(\d{3,})ms/Si', function ($matches) { | |
| 647 | - return $matches[1] . $matches[2] . ((int) $matches[3] / 1000) .'s'; | |
| 646 | +        $body = preg_replace_callback('/([ :,(])(-?)(\d{3,})ms/Si', function($matches) { | |
| 647 | + return $matches[1].$matches[2].((int) $matches[3]/1000).'s'; | |
| 648 | 648 | }, $body); | 
| 649 | 649 | |
| 650 | 650 | // Remove leading zeros from integer and float numbers. | 
| @@ -756,13 +756,13 @@ discard block | ||
| 756 | 756 |          $css = preg_replace('/::(before|after|first-(?:line|letter))(\{|,)/Si', ':$1$2', $css); | 
| 757 | 757 | |
| 758 | 758 | // Retain space for special IE6 cases | 
| 759 | -        $css = preg_replace_callback('/:first-(line|letter)(\{|,)/Si', function ($matches) { | |
| 760 | - return ':first-'. strtolower($matches[1]) .' '. $matches[2]; | |
| 759 | +        $css = preg_replace_callback('/:first-(line|letter)(\{|,)/Si', function($matches) { | |
| 760 | + return ':first-'.strtolower($matches[1]).' '.$matches[2]; | |
| 761 | 761 | }, $css); | 
| 762 | 762 | |
| 763 | 763 | // Find a fraction that may used in some @media queries such as: (min-aspect-ratio: 1/1) | 
| 764 | 764 | // Add token to add the "/" back in later | 
| 765 | -        $css = preg_replace('/\(([a-z-]+):([0-9]+)\/([0-9]+)\)/Si', '($1:$2'. self::QUERY_FRACTION .'$3)', $css); | |
| 765 | +        $css = preg_replace('/\(([a-z-]+):([0-9]+)\/([0-9]+)\)/Si', '($1:$2'.self::QUERY_FRACTION.'$3)', $css); | |
| 766 | 766 | |
| 767 | 767 | // Remove empty rule blocks up to 2 levels deep. | 
| 768 | 768 |          $css = preg_replace(array_fill(0, 2, '/(\{)[^{};\/\n]+\{\}/S'), '$1', $css); | 
| @@ -810,7 +810,7 @@ discard block | ||
| 810 | 810 | } | 
| 811 | 811 | |
| 812 | 812 | // @import handling | 
| 813 | -        $css = preg_replace_callback($this->importRegex, function ($matches) use (&$imports) { | |
| 813 | +        $css = preg_replace_callback($this->importRegex, function($matches) use (&$imports) { | |
| 814 | 814 | // Keep all @import at-rules found for later | 
| 815 | 815 | $imports .= $matches[0]; | 
| 816 | 816 | // Delete all @import at-rules | 
| @@ -818,7 +818,7 @@ discard block | ||
| 818 | 818 | }, $css); | 
| 819 | 819 | |
| 820 | 820 | // @namespace handling | 
| 821 | -        $css = preg_replace_callback($this->namespaceRegex, function ($matches) use (&$namespaces) { | |
| 821 | +        $css = preg_replace_callback($this->namespaceRegex, function($matches) use (&$namespaces) { | |
| 822 | 822 | // Keep all @namespace at-rules found for later | 
| 823 | 823 | $namespaces .= $matches[0]; | 
| 824 | 824 | // Delete all @namespace at-rules | 
| @@ -829,7 +829,7 @@ discard block | ||
| 829 | 829 | // 1. @charset first | 
| 830 | 830 | // 2. @imports below @charset | 
| 831 | 831 | // 3. @namespaces below @imports | 
| 832 | - $css = $charset . $imports . $namespaces . $css; | |
| 832 | + $css = $charset.$imports.$namespaces.$css; | |
| 833 | 833 | |
| 834 | 834 | return $css; | 
| 835 | 835 | } | 
| @@ -883,10 +883,10 @@ discard block | ||
| 883 | 883 | // Restore space after rgb() or hsl() function in some cases such as: | 
| 884 | 884 | // background-image: linear-gradient(to bottom, rgb(210,180,140) 10%, rgb(255,0,0) 90%); | 
| 885 | 885 |          if (!empty($terminator) && !preg_match('/[ ,);]/S', $terminator)) { | 
| 886 | - $terminator = ' '. $terminator; | |
| 886 | + $terminator = ' '.$terminator; | |
| 887 | 887 | } | 
| 888 | 888 | |
| 889 | -        return '#'. implode('', $hexColors) . $terminator; | |
| 889 | +        return '#'.implode('', $hexColors).$terminator; | |
| 890 | 890 | } | 
| 891 | 891 | |
| 892 | 892 | /** | 
| @@ -900,16 +900,16 @@ discard block | ||
| 900 | 900 | |
| 901 | 901 | // Shorten suitable 6 chars HEX colors | 
| 902 | 902 |          if (strlen($hex) === 6 && preg_match('/^([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3$/Si', $hex, $m)) { | 
| 903 | - $hex = $m[1] . $m[2] . $m[3]; | |
| 903 | + $hex = $m[1].$m[2].$m[3]; | |
| 904 | 904 | } | 
| 905 | 905 | |
| 906 | 906 | // Lowercase | 
| 907 | - $hex = '#'. strtolower($hex); | |
| 907 | + $hex = '#'.strtolower($hex); | |
| 908 | 908 | |
| 909 | 909 | // Replace Hex colors with shorter color names | 
| 910 | 910 | $color = array_key_exists($hex, $this->hexToNamedColorsMap) ? $this->hexToNamedColorsMap[$hex] : $hex; | 
| 911 | 911 | |
| 912 | - return $color . $matches[2]; | |
| 912 | + return $color.$matches[2]; | |
| 913 | 913 | } | 
| 914 | 914 | |
| 915 | 915 | /** | 
| @@ -920,7 +920,7 @@ discard block | ||
| 920 | 920 | */ | 
| 921 | 921 | private function shortenNamedColorsCallback($matches) | 
| 922 | 922 |      { | 
| 923 | - return $matches[1] . $this->namedToHexColorsMap[strtolower($matches[2])] . $matches[3]; | |
| 923 | + return $matches[1].$this->namedToHexColorsMap[strtolower($matches[2])].$matches[3]; | |
| 924 | 924 | } | 
| 925 | 925 | |
| 926 | 926 | /** | 
| @@ -3,50 +3,50 @@ discard block | ||
| 3 | 3 | * WP tests bootstrap. | 
| 4 | 4 | */ | 
| 5 | 5 | |
| 6 | -$_tests_dir = getenv( 'WP_TESTS_DIR' ); | |
| 7 | -if ( ! $_tests_dir ) { | |
| 8 | - $tmp_dir = getenv( 'TMPDIR' ); | |
| 9 | -    if ( ! empty( $tmp_dir ) ) { | |
| 10 | - $_tests_dir = rtrim( $tmp_dir, '/' ) . '/wordpress-tests-lib'; | |
| 11 | -        if ( ! is_dir( $_tests_dir ) ) { | |
| 6 | +$_tests_dir = getenv('WP_TESTS_DIR'); | |
| 7 | +if (!$_tests_dir) { | |
| 8 | +    $tmp_dir = getenv('TMPDIR'); | |
| 9 | +    if (!empty($tmp_dir)) { | |
| 10 | + $_tests_dir = rtrim($tmp_dir, '/').'/wordpress-tests-lib'; | |
| 11 | +        if (!is_dir($_tests_dir)) { | |
| 12 | 12 | $_tests_dir = null; | 
| 13 | 13 | } | 
| 14 | 14 | } | 
| 15 | 15 | } | 
| 16 | 16 | |
| 17 | -if ( ! $_tests_dir ) { | |
| 17 | +if (!$_tests_dir) { | |
| 18 | 18 | $_tests_dir = '/tmp/wordpress-tests-lib'; | 
| 19 | 19 | } | 
| 20 | 20 | |
| 21 | -require_once $_tests_dir . '/includes/functions.php'; | |
| 21 | +require_once $_tests_dir.'/includes/functions.php'; | |
| 22 | 22 | |
| 23 | 23 |  function _manually_load_plugin() { | 
| 24 | - define( 'AUTOPTIMIZE_INIT_EARLIER', true ); | |
| 24 | +    define('AUTOPTIMIZE_INIT_EARLIER', true); | |
| 25 | 25 | |
| 26 | 26 | // For overriding cache dirs and whatnot. Kinda works if you keep a few things in mind. | 
| 27 | -    if ( getenv('CUSTOM_CONSTANTS' ) ) { | |
| 28 | - define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/c/ao/' ); | |
| 29 | - $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR; | |
| 30 | -        if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { | |
| 27 | +    if (getenv('CUSTOM_CONSTANTS')) { | |
| 28 | +        define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/c/ao/'); | |
| 29 | + $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR; | |
| 30 | +        if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { | |
| 31 | 31 | $blog_id = get_current_blog_id(); | 
| 32 | - $pathname .= $blog_id . '/'; | |
| 32 | + $pathname .= $blog_id.'/'; | |
| 33 | 33 | } | 
| 34 | - define( 'AUTOPTIMIZE_CACHE_DIR', $pathname ); | |
| 34 | +        define('AUTOPTIMIZE_CACHE_DIR', $pathname); | |
| 35 | 35 | |
| 36 | 36 | $custom_site_url = 'http://localhost/wordpress'; | 
| 37 | - define( 'AUTOPTIMIZE_WP_SITE_URL', $custom_site_url ); | |
| 38 | -        add_filter( 'site_url', function( $url, $path, $scheme, $blog_id ) use ( $custom_site_url ) { | |
| 37 | +        define('AUTOPTIMIZE_WP_SITE_URL', $custom_site_url); | |
| 38 | +        add_filter('site_url', function($url, $path, $scheme, $blog_id) use ($custom_site_url) { | |
| 39 | 39 | return $custom_site_url; | 
| 40 | - }, 10, 4 ); | |
| 41 | -        add_filter( 'content_url', function( $url, $path ) use ( $custom_site_url ) { | |
| 42 | - return $custom_site_url . '/wp-content'; | |
| 43 | - }, 10, 2 ); | |
| 44 | - define( 'AO_TEST_SUBFOLDER_INSTALL', true ); | |
| 40 | + }, 10, 4); | |
| 41 | +        add_filter('content_url', function($url, $path) use ($custom_site_url) { | |
| 42 | + return $custom_site_url.'/wp-content'; | |
| 43 | + }, 10, 2); | |
| 44 | +        define('AO_TEST_SUBFOLDER_INSTALL', true); | |
| 45 | 45 | |
| 46 | - define( 'CUSTOM_CONSTANTS_USED', true ); | |
| 46 | +        define('CUSTOM_CONSTANTS_USED', true); | |
| 47 | 47 |      } else { | 
| 48 | - define( 'CUSTOM_CONSTANTS_USED', false ); | |
| 49 | - define( 'AO_TEST_SUBFOLDER_INSTALL', false ); | |
| 48 | +        define('CUSTOM_CONSTANTS_USED', false); | |
| 49 | +        define('AO_TEST_SUBFOLDER_INSTALL', false); | |
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | 52 | /* | 
| @@ -54,18 +54,18 @@ discard block | ||
| 54 | 54 | update_option( 'active_plugins', $active_plugins ); | 
| 55 | 55 | */ | 
| 56 | 56 | |
| 57 | - update_option( 'autoptimize_js', 1 ); | |
| 58 | - update_option( 'autoptimize_css', 1 ); | |
| 59 | - update_option( 'autoptimize_html', 0 ); | |
| 60 | - update_option( 'autoptimize_cdn_url', 'http://cdn.example.org' ); | |
| 61 | - update_option( 'autoptimize_cache_nogzip', 1 ); | |
| 57 | +    update_option('autoptimize_js', 1); | |
| 58 | +    update_option('autoptimize_css', 1); | |
| 59 | +    update_option('autoptimize_html', 0); | |
| 60 | +    update_option('autoptimize_cdn_url', 'http://cdn.example.org'); | |
| 61 | +    update_option('autoptimize_cache_nogzip', 1); | |
| 62 | 62 | |
| 63 | -    add_filter( 'autoptimize_css_include_inline', function( $include_inline ) { | |
| 63 | +    add_filter('autoptimize_css_include_inline', function($include_inline) { | |
| 64 | 64 | return true; | 
| 65 | 65 | }); | 
| 66 | 66 | |
| 67 | - require dirname( dirname( __FILE__ ) ) . '/autoptimize.php'; | |
| 67 | + require dirname(dirname(__FILE__)).'/autoptimize.php'; | |
| 68 | 68 | } | 
| 69 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); | |
| 69 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); | |
| 70 | 70 | |
| 71 | -require $_tests_dir . '/includes/bootstrap.php'; | |
| 71 | +require $_tests_dir.'/includes/bootstrap.php'; | |
| @@ -28,11 +28,11 @@ discard block | ||
| 28 | 28 | /** | 
| 29 | 29 | * Exit if called directly. | 
| 30 | 30 | */ | 
| 31 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 31 | +if (!defined('ABSPATH')) { | |
| 32 | 32 | die; | 
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | -if ( ! class_exists( 'PAnD' ) ) { | |
| 35 | +if (!class_exists('PAnD')) { | |
| 36 | 36 | |
| 37 | 37 | /** | 
| 38 | 38 | * Class PAnD | 
| @@ -43,8 +43,8 @@ discard block | ||
| 43 | 43 | * Init hooks. | 
| 44 | 44 | */ | 
| 45 | 45 |  		public static function init() { | 
| 46 | - add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) ); | |
| 47 | - add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) ); | |
| 46 | +			add_action('admin_enqueue_scripts', array(__CLASS__, 'load_script')); | |
| 47 | +			add_action('wp_ajax_dismiss_admin_notice', array(__CLASS__, 'dismiss_admin_notice')); | |
| 48 | 48 | } | 
| 49 | 49 | |
| 50 | 50 | /** | 
| @@ -52,14 +52,14 @@ discard block | ||
| 52 | 52 | */ | 
| 53 | 53 |  		public static function load_script() { | 
| 54 | 54 | |
| 55 | -			if ( is_customize_preview() ) { | |
| 55 | +			if (is_customize_preview()) { | |
| 56 | 56 | return; | 
| 57 | 57 | } | 
| 58 | 58 | |
| 59 | 59 | wp_enqueue_script( | 
| 60 | 60 | 'dismissible-notices', | 
| 61 | - plugins_url( 'dismiss-notice.js', __FILE__ ), | |
| 62 | - array( 'jquery', 'common' ), | |
| 61 | +				plugins_url('dismiss-notice.js', __FILE__), | |
| 62 | +				array('jquery', 'common'), | |
| 63 | 63 | false, | 
| 64 | 64 | true | 
| 65 | 65 | ); | 
| @@ -68,7 +68,7 @@ discard block | ||
| 68 | 68 | 'dismissible-notices', | 
| 69 | 69 | 'dismissible_notice', | 
| 70 | 70 | array( | 
| 71 | - 'nonce' => wp_create_nonce( 'dismissible-notice' ), | |
| 71 | +					'nonce' => wp_create_nonce('dismissible-notice'), | |
| 72 | 72 | ) | 
| 73 | 73 | ); | 
| 74 | 74 | } | 
| @@ -78,17 +78,17 @@ discard block | ||
| 78 | 78 | * Uses check_ajax_referer to verify nonce. | 
| 79 | 79 | */ | 
| 80 | 80 |  		public static function dismiss_admin_notice() { | 
| 81 | - $option_name = sanitize_text_field( $_POST['option_name'] ); | |
| 82 | - $dismissible_length = sanitize_text_field( $_POST['dismissible_length'] ); | |
| 81 | + $option_name = sanitize_text_field($_POST['option_name']); | |
| 82 | + $dismissible_length = sanitize_text_field($_POST['dismissible_length']); | |
| 83 | 83 | |
| 84 | -			if ( 'forever' != $dismissible_length ) { | |
| 84 | +			if ('forever' != $dismissible_length) { | |
| 85 | 85 | // If $dismissible_length is not an integer default to 1 | 
| 86 | - $dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length; | |
| 87 | - $dismissible_length = strtotime( absint( $dismissible_length ) . ' days' ); | |
| 86 | + $dismissible_length = (0 == absint($dismissible_length)) ? 1 : $dismissible_length; | |
| 87 | + $dismissible_length = strtotime(absint($dismissible_length).' days'); | |
| 88 | 88 | } | 
| 89 | 89 | |
| 90 | - check_ajax_referer( 'dismissible-notice', 'nonce' ); | |
| 91 | - self::set_admin_notice_cache( $option_name, $dismissible_length ); | |
| 90 | +			check_ajax_referer('dismissible-notice', 'nonce'); | |
| 91 | + self::set_admin_notice_cache($option_name, $dismissible_length); | |
| 92 | 92 | wp_die(); | 
| 93 | 93 | } | 
| 94 | 94 | |
| @@ -99,14 +99,14 @@ discard block | ||
| 99 | 99 | * | 
| 100 | 100 | * @return bool | 
| 101 | 101 | */ | 
| 102 | -		public static function is_admin_notice_active( $arg ) { | |
| 103 | - $array = explode( '-', $arg ); | |
| 104 | - $length = array_pop( $array ); | |
| 105 | - $option_name = implode( '-', $array ); | |
| 106 | - $db_record = self::get_admin_notice_cache( $option_name ); | |
| 107 | -			if ( 'forever' == $db_record ) { | |
| 102 | +		public static function is_admin_notice_active($arg) { | |
| 103 | +			$array       = explode('-', $arg); | |
| 104 | + $length = array_pop($array); | |
| 105 | +			$option_name = implode('-', $array); | |
| 106 | + $db_record = self::get_admin_notice_cache($option_name); | |
| 107 | +			if ('forever' == $db_record) { | |
| 108 | 108 | return false; | 
| 109 | -			} elseif ( absint( $db_record ) >= time() ) { | |
| 109 | +			} elseif (absint($db_record) >= time()) { | |
| 110 | 110 | return false; | 
| 111 | 111 |  			} else { | 
| 112 | 112 | return true; | 
| @@ -122,15 +122,15 @@ discard block | ||
| 122 | 122 | * | 
| 123 | 123 | * @return array|bool The timeout. False if expired. | 
| 124 | 124 | */ | 
| 125 | -		public static function get_admin_notice_cache( $id = false ) { | |
| 126 | -			if ( ! $id ) { | |
| 125 | +		public static function get_admin_notice_cache($id = false) { | |
| 126 | +			if (!$id) { | |
| 127 | 127 | return false; | 
| 128 | 128 | } | 
| 129 | - $cache_key = 'pand-' . md5( $id ); | |
| 130 | - $timeout = get_site_option( $cache_key ); | |
| 129 | + $cache_key = 'pand-'.md5($id); | |
| 130 | + $timeout = get_site_option($cache_key); | |
| 131 | 131 | $timeout = 'forever' === $timeout ? time() + 60 : $timeout; | 
| 132 | 132 | |
| 133 | -			if ( empty( $timeout ) || time() > $timeout ) { | |
| 133 | +			if (empty($timeout) || time() > $timeout) { | |
| 134 | 134 | return false; | 
| 135 | 135 | } | 
| 136 | 136 | |
| @@ -147,9 +147,9 @@ discard block | ||
| 147 | 147 | * | 
| 148 | 148 | * @return bool | 
| 149 | 149 | */ | 
| 150 | -		public static function set_admin_notice_cache( $id, $timeout ) { | |
| 151 | - $cache_key = 'pand-' . md5( $id ); | |
| 152 | - update_site_option( $cache_key, $timeout ); | |
| 150 | +		public static function set_admin_notice_cache($id, $timeout) { | |
| 151 | + $cache_key = 'pand-'.md5($id); | |
| 152 | + update_site_option($cache_key, $timeout); | |
| 153 | 153 | |
| 154 | 154 | return true; | 
| 155 | 155 | } |