@@ -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 |
@@ -52,36 +52,36 @@ discard block |
||
| 52 | 52 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); |
| 53 | 53 | |
| 54 | 54 | if (($modTimeMatch)||($eTagMatch)) { |
| 55 | - header('HTTP/1.1 304 Not Modified'); |
|
| 56 | - header('Connection: close'); |
|
| 55 | + header('HTTP/1.1 304 Not Modified'); |
|
| 56 | + header('Connection: close'); |
|
| 57 | 57 | } else { |
| 58 | - // send all sorts of headers |
|
| 59 | - $expireTime=60*60*24*355; // 1y max according to RFC |
|
| 60 | - if ($encoding != 'none') { |
|
| 61 | - header('Content-Encoding: '.$encoding); |
|
| 62 | - } |
|
| 63 | - header('Vary: Accept-Encoding'); |
|
| 64 | - header('Content-Length: '.strlen($contents)); |
|
| 65 | - header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
| 66 | - header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); |
|
| 67 | - header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
| 68 | - header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
| 69 | - header('ETag: ' . $eTag); |
|
| 70 | - header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
| 58 | + // send all sorts of headers |
|
| 59 | + $expireTime=60*60*24*355; // 1y max according to RFC |
|
| 60 | + if ($encoding != 'none') { |
|
| 61 | + header('Content-Encoding: '.$encoding); |
|
| 62 | + } |
|
| 63 | + header('Vary: Accept-Encoding'); |
|
| 64 | + header('Content-Length: '.strlen($contents)); |
|
| 65 | + header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
| 66 | + header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); |
|
| 67 | + header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
| 68 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
| 69 | + header('ETag: ' . $eTag); |
|
| 70 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
| 71 | 71 | |
| 72 | - // send output |
|
| 73 | - echo $contents; |
|
| 72 | + // send output |
|
| 73 | + echo $contents; |
|
| 74 | 74 | |
| 75 | - //And write to filesystem cache if not done yet |
|
| 76 | - if($encoding != 'none' && $iscompressed == false) |
|
| 77 | - { |
|
| 78 | - //Write the content we sent |
|
| 79 | - file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
| 75 | + //And write to filesystem cache if not done yet |
|
| 76 | + if($encoding != 'none' && $iscompressed == false) |
|
| 77 | + { |
|
| 78 | + //Write the content we sent |
|
| 79 | + file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
| 80 | 80 | |
| 81 | - //And write the new content |
|
| 82 | - $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
| 83 | - $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
| 84 | - $contents = gzencode($code,9,$flag); |
|
| 85 | - file_put_contents(__FILE__.'.'.$ext,$contents); |
|
| 86 | - } |
|
| 81 | + //And write the new content |
|
| 82 | + $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
| 83 | + $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
| 84 | + $contents = gzencode($code,9,$flag); |
|
| 85 | + file_put_contents(__FILE__.'.'.$ext,$contents); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -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 | } |
@@ -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); |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | { |
| 71 | 71 | $this->_html = str_replace("\r\n", "\n", trim($html)); |
| 72 | 72 | if (isset($options['xhtml'])) { |
| 73 | - $this->_isXhtml = (bool)$options['xhtml']; |
|
| 73 | + $this->_isXhtml = (bool) $options['xhtml']; |
|
| 74 | 74 | } |
| 75 | 75 | if (isset($options['cssMinifier'])) { |
| 76 | 76 | $this->_cssMinifier = $options['cssMinifier']; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML')); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']); |
|
| 98 | + $this->_replacementHash = 'MINIFYHTML'.md5($_SERVER['REQUEST_TIME']); |
|
| 99 | 99 | $this->_placeholders = array(); |
| 100 | 100 | |
| 101 | 101 | // replace SCRIPTs (and minify) with placeholders |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | ,$this->_html); |
| 112 | 112 | |
| 113 | 113 | // remove HTML comments (not containing IE conditional comments). |
| 114 | - if ($this->_keepComments == false) { |
|
| 114 | + if ($this->_keepComments == false) { |
|
| 115 | 115 | $this->_html = preg_replace_callback( |
| 116 | 116 | '/<!--([\\s\\S]*?)-->/' |
| 117 | 117 | ,array($this, '_commentCB') |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | protected function _reservePlace($content) |
| 175 | 175 | { |
| 176 | - $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%'; |
|
| 176 | + $placeholder = '%'.$this->_replacementHash.count($this->_placeholders).'%'; |
|
| 177 | 177 | $this->_placeholders[$placeholder] = $content; |
| 178 | 178 | return $placeholder; |
| 179 | 179 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | |
| 188 | 188 | protected function _outsideTagCB($m) |
| 189 | 189 | { |
| 190 | - return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<'; |
|
| 190 | + return '>'.preg_replace('/^\\s+|\\s+$/', ' ', $m[1]).'<'; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | protected function _removePreCB($m) |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | protected function _removeCdata($str) |
| 260 | 260 | { |
| 261 | 261 | return (false !== strpos($str, '<![CDATA[')) |
| 262 | - ? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str) |
|
| 262 | + ? str_replace(array('/* <![CDATA[ */', '/* ]]> */', '/*<![CDATA[*/', '/*]]>*/', '<![CDATA[', ']]>'), '', $str) |
|
| 263 | 263 | : $str; |
| 264 | 264 | } |
| 265 | 265 | |
@@ -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'); |
|
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * addons and/or affiliate services. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 7 | +if (!defined('ABSPATH')) { |
|
| 8 | 8 | exit; |
| 9 | 9 | } |
| 10 | 10 | |
@@ -17,64 +17,64 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function run() |
| 19 | 19 | { |
| 20 | - if ( $this->enabled() ) { |
|
| 21 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_partner_tabs' ), 10, 1 ); |
|
| 20 | + if ($this->enabled()) { |
|
| 21 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_partner_tabs'), 10, 1); |
|
| 22 | 22 | } |
| 23 | - add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); |
|
| 23 | + add_action('admin_menu', array($this, 'add_admin_menu')); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | protected function enabled() |
| 27 | 27 | { |
| 28 | - return apply_filters( 'autoptimize_filter_show_partner_tabs', true ); |
|
| 28 | + return apply_filters('autoptimize_filter_show_partner_tabs', true); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function add_partner_tabs( $in ) |
|
| 31 | + public function add_partner_tabs($in) |
|
| 32 | 32 | { |
| 33 | - $in = array_merge( $in, array( |
|
| 34 | - 'ao_partners' => __( 'Optimize More!', 'autoptimize' ), |
|
| 35 | - ) ); |
|
| 33 | + $in = array_merge($in, array( |
|
| 34 | + 'ao_partners' => __('Optimize More!', 'autoptimize'), |
|
| 35 | + )); |
|
| 36 | 36 | |
| 37 | 37 | return $in; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public function add_admin_menu() |
| 41 | 41 | { |
| 42 | - if ( $this->enabled() ) { |
|
| 43 | - add_submenu_page( null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array( $this, 'ao_partners_page' ) ); |
|
| 42 | + if ($this->enabled()) { |
|
| 43 | + add_submenu_page(null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array($this, 'ao_partners_page')); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | protected function get_ao_partner_feed_markup() |
| 48 | 48 | { |
| 49 | - $no_feed_text = __( 'Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize' ); |
|
| 49 | + $no_feed_text = __('Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize'); |
|
| 50 | 50 | $output = ''; |
| 51 | - if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) { |
|
| 52 | - $rss = fetch_feed( 'http://feeds.feedburner.com/OptimizingMattersDownloads' ); |
|
| 51 | + if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) { |
|
| 52 | + $rss = fetch_feed('http://feeds.feedburner.com/OptimizingMattersDownloads'); |
|
| 53 | 53 | $maxitems = 0; |
| 54 | 54 | |
| 55 | - if ( ! is_wp_error( $rss ) ) { |
|
| 56 | - $maxitems = $rss->get_item_quantity( 20 ); |
|
| 57 | - $rss_items = $rss->get_items( 0, $maxitems ); |
|
| 55 | + if (!is_wp_error($rss)) { |
|
| 56 | + $maxitems = $rss->get_item_quantity(20); |
|
| 57 | + $rss_items = $rss->get_items(0, $maxitems); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if ( 0 == $maxitems ) { |
|
| 60 | + if (0 == $maxitems) { |
|
| 61 | 61 | $output .= $no_feed_text; |
| 62 | 62 | } else { |
| 63 | 63 | $output .= '<ul>'; |
| 64 | - foreach ( $rss_items as $item ) { |
|
| 65 | - $item_url = esc_url( $item->get_permalink() ); |
|
| 64 | + foreach ($rss_items as $item) { |
|
| 65 | + $item_url = esc_url($item->get_permalink()); |
|
| 66 | 66 | $enclosure = $item->get_enclosure(); |
| 67 | 67 | |
| 68 | 68 | $output .= '<li class="itemDetail">'; |
| 69 | - $output .= '<h3 class="itemTitle"><a href="' . $item_url . '" target="_blank">' . esc_html( $item->get_title() ) . '</a></h3>'; |
|
| 69 | + $output .= '<h3 class="itemTitle"><a href="'.$item_url.'" target="_blank">'.esc_html($item->get_title()).'</a></h3>'; |
|
| 70 | 70 | |
| 71 | - if ( $enclosure && ( false !== strpos( $enclosure->get_type(), 'image' ) ) ) { |
|
| 72 | - $img_url = esc_url( $enclosure->get_link() ); |
|
| 73 | - $output .= '<div class="itemImage"><a href="' . $item_url . '" target="_blank"><img src="' . $img_url . '"></a></div>'; |
|
| 71 | + if ($enclosure && (false !== strpos($enclosure->get_type(), 'image'))) { |
|
| 72 | + $img_url = esc_url($enclosure->get_link()); |
|
| 73 | + $output .= '<div class="itemImage"><a href="'.$item_url.'" target="_blank"><img src="'.$img_url.'"></a></div>'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $output .= '<div class="itemDescription">' . wp_kses_post( $item->get_description() ) . '</div>'; |
|
| 77 | - $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="' . $item_url . '" target="_blank">' . __( 'More info', 'autoptimize' ) . '</a></div></div>'; |
|
| 76 | + $output .= '<div class="itemDescription">'.wp_kses_post($item->get_description()).'</div>'; |
|
| 77 | + $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="'.$item_url.'" target="_blank">'.__('More info', 'autoptimize').'</a></div></div>'; |
|
| 78 | 78 | $output .= '</li>'; |
| 79 | 79 | } |
| 80 | 80 | $output .= '</ul>'; |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | </style> |
| 135 | 135 | <div class="wrap"> |
| 136 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
| 136 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
| 137 | 137 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
| 138 | - <?php echo '<h2>' . __( "These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize' ) . '</h2>'; ?> |
|
| 138 | + <?php echo '<h2>'.__("These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize').'</h2>'; ?> |
|
| 139 | 139 | <div> |
| 140 | 140 | <?php echo $this->get_ao_partner_feed_markup(); ?> |
| 141 | 141 | </div> |
@@ -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 | } |
@@ -412,7 +412,7 @@ |
||
| 412 | 412 | * First element is the filepath, second is the md5 hash of contents |
| 413 | 413 | * the filepath had when it was being processed. |
| 414 | 414 | * If we don't have those, we'll bail out early. |
| 415 | - */ |
|
| 415 | + */ |
|
| 416 | 416 | $filepath = null; |
| 417 | 417 | $filehash = null; |
| 418 | 418 | |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Base class other (more-specific) classes inherit from. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 6 | +if (!defined('ABSPATH')) { |
|
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public $debug_log = false; |
| 25 | 25 | |
| 26 | - public function __construct( $content ) |
|
| 26 | + public function __construct($content) |
|
| 27 | 27 | { |
| 28 | 28 | $this->content = $content; |
| 29 | 29 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return bool |
| 37 | 37 | */ |
| 38 | - abstract public function read( $options ); |
|
| 38 | + abstract public function read($options); |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Joins and optimizes collected things. |
@@ -66,40 +66,40 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return bool|string |
| 68 | 68 | */ |
| 69 | - public function getpath( $url ) |
|
| 69 | + public function getpath($url) |
|
| 70 | 70 | { |
| 71 | - $url = apply_filters( 'autoptimize_filter_cssjs_alter_url', $url ); |
|
| 71 | + $url = apply_filters('autoptimize_filter_cssjs_alter_url', $url); |
|
| 72 | 72 | |
| 73 | - if ( false !== strpos( $url, '%' ) ) { |
|
| 74 | - $url = urldecode( $url ); |
|
| 73 | + if (false !== strpos($url, '%')) { |
|
| 74 | + $url = urldecode($url); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $site_host = parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ); |
|
| 78 | - $content_host = parse_url( AUTOPTIMIZE_WP_ROOT_URL, PHP_URL_HOST ); |
|
| 77 | + $site_host = parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST); |
|
| 78 | + $content_host = parse_url(AUTOPTIMIZE_WP_ROOT_URL, PHP_URL_HOST); |
|
| 79 | 79 | |
| 80 | 80 | // Normalizing attempts... |
| 81 | - $double_slash_position = strpos( $url, '//' ); |
|
| 82 | - if ( 0 === $double_slash_position ) { |
|
| 83 | - if ( is_ssl() ) { |
|
| 84 | - $url = 'https:' . $url; |
|
| 81 | + $double_slash_position = strpos($url, '//'); |
|
| 82 | + if (0 === $double_slash_position) { |
|
| 83 | + if (is_ssl()) { |
|
| 84 | + $url = 'https:'.$url; |
|
| 85 | 85 | } else { |
| 86 | - $url = 'http:' . $url; |
|
| 86 | + $url = 'http:'.$url; |
|
| 87 | 87 | } |
| 88 | - } elseif ( ( false === $double_slash_position ) && ( false === strpos( $url, $site_host ) ) ) { |
|
| 89 | - if ( AUTOPTIMIZE_WP_SITE_URL === $site_host ) { |
|
| 90 | - $url = AUTOPTIMIZE_WP_SITE_URL . $url; |
|
| 88 | + } elseif ((false === $double_slash_position) && (false === strpos($url, $site_host))) { |
|
| 89 | + if (AUTOPTIMIZE_WP_SITE_URL === $site_host) { |
|
| 90 | + $url = AUTOPTIMIZE_WP_SITE_URL.$url; |
|
| 91 | 91 | } else { |
| 92 | - $url = AUTOPTIMIZE_WP_SITE_URL . autoptimizeUtils::path_canonicalize( $url ); |
|
| 92 | + $url = AUTOPTIMIZE_WP_SITE_URL.autoptimizeUtils::path_canonicalize($url); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if ( $site_host !== $content_host ) { |
|
| 97 | - $url = str_replace( AUTOPTIMIZE_WP_CONTENT_URL, AUTOPTIMIZE_WP_SITE_URL . AUTOPTIMIZE_WP_CONTENT_NAME, $url ); |
|
| 96 | + if ($site_host !== $content_host) { |
|
| 97 | + $url = str_replace(AUTOPTIMIZE_WP_CONTENT_URL, AUTOPTIMIZE_WP_SITE_URL.AUTOPTIMIZE_WP_CONTENT_NAME, $url); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // First check; hostname wp site should be hostname of url! |
| 101 | - $url_host = @parse_url( $url, PHP_URL_HOST ); // @codingStandardsIgnoreLine |
|
| 102 | - if ( $url_host !== $site_host ) { |
|
| 101 | + $url_host = @parse_url($url, PHP_URL_HOST); // @codingStandardsIgnoreLine |
|
| 102 | + if ($url_host !== $site_host) { |
|
| 103 | 103 | /** |
| 104 | 104 | * First try to get all domains from WPML (if available) |
| 105 | 105 | * then explicitely declare $this->cdn_url as OK as well |
@@ -108,20 +108,20 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | $multidomains = array(); |
| 110 | 110 | |
| 111 | - $multidomains_wpml = apply_filters( 'wpml_setting', array(), 'language_domains' ); |
|
| 112 | - if ( ! empty( $multidomains_wpml ) ) { |
|
| 113 | - $multidomains = array_map( array( $this, 'get_url_hostname' ), $multidomains_wpml ); |
|
| 111 | + $multidomains_wpml = apply_filters('wpml_setting', array(), 'language_domains'); |
|
| 112 | + if (!empty($multidomains_wpml)) { |
|
| 113 | + $multidomains = array_map(array($this, 'get_url_hostname'), $multidomains_wpml); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( ! empty( $this->cdn_url ) ) { |
|
| 117 | - $multidomains[] = parse_url( $this->cdn_url, PHP_URL_HOST ); |
|
| 116 | + if (!empty($this->cdn_url)) { |
|
| 117 | + $multidomains[] = parse_url($this->cdn_url, PHP_URL_HOST); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $multidomains = apply_filters( 'autoptimize_filter_cssjs_multidomain', $multidomains ); |
|
| 120 | + $multidomains = apply_filters('autoptimize_filter_cssjs_multidomain', $multidomains); |
|
| 121 | 121 | |
| 122 | - if ( ! empty( $multidomains ) ) { |
|
| 123 | - if ( in_array( $url_host, $multidomains ) ) { |
|
| 124 | - $url = str_replace( $url_host, $site_host, $url ); |
|
| 122 | + if (!empty($multidomains)) { |
|
| 123 | + if (in_array($url_host, $multidomains)) { |
|
| 124 | + $url = str_replace($url_host, $site_host, $url); |
|
| 125 | 125 | } else { |
| 126 | 126 | return false; |
| 127 | 127 | } |
@@ -131,28 +131,28 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // Try to remove "wp root url" from url while not minding http<>https. |
| 134 | - $tmp_ao_root = preg_replace( '/https?:/', '', AUTOPTIMIZE_WP_ROOT_URL ); |
|
| 134 | + $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_ROOT_URL); |
|
| 135 | 135 | |
| 136 | - if ( $site_host !== $content_host ) { |
|
| 136 | + if ($site_host !== $content_host) { |
|
| 137 | 137 | // As we replaced the content-domain with the site-domain, we should match against that. |
| 138 | - $tmp_ao_root = preg_replace( '/https?:/', '', AUTOPTIMIZE_WP_SITE_URL ); |
|
| 138 | + $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_SITE_URL); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $tmp_url = preg_replace( '/https?:/', '', $url ); |
|
| 142 | - $path = str_replace( $tmp_ao_root, '', $tmp_url ); |
|
| 141 | + $tmp_url = preg_replace('/https?:/', '', $url); |
|
| 142 | + $path = str_replace($tmp_ao_root, '', $tmp_url); |
|
| 143 | 143 | |
| 144 | 144 | // If path starts with :// or //, this is not a URL in the WP context and |
| 145 | 145 | // we have to assume we can't aggregate. |
| 146 | - if ( preg_match( '#^:?//#', $path ) ) { |
|
| 146 | + if (preg_match('#^:?//#', $path)) { |
|
| 147 | 147 | // External script/css (adsense, etc). |
| 148 | 148 | return false; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Prepend with WP_ROOT_DIR to have full path to file. |
| 152 | - $path = str_replace( '//', '/', WP_ROOT_DIR . $path ); |
|
| 152 | + $path = str_replace('//', '/', WP_ROOT_DIR.$path); |
|
| 153 | 153 | |
| 154 | 154 | // Final check: does file exist and is it readable? |
| 155 | - if ( file_exists( $path ) && is_file( $path ) && is_readable( $path ) ) { |
|
| 155 | + if (file_exists($path) && is_file($path) && is_readable($path)) { |
|
| 156 | 156 | return $path; |
| 157 | 157 | } else { |
| 158 | 158 | return false; |
@@ -169,18 +169,18 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @return string |
| 171 | 171 | */ |
| 172 | - protected function get_url_hostname( $url ) |
|
| 172 | + protected function get_url_hostname($url) |
|
| 173 | 173 | { |
| 174 | 174 | // Checking that the url starts with something vaguely resembling a protocol. |
| 175 | - if ( ( 0 !== strpos( $url, 'http' ) ) && ( 0 !== strpos( $url, '//' ) ) ) { |
|
| 176 | - $url = 'http://' . $url; |
|
| 175 | + if ((0 !== strpos($url, 'http')) && (0 !== strpos($url, '//'))) { |
|
| 176 | + $url = 'http://'.$url; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // Grab the hostname. |
| 180 | - $hostname = parse_url( $url, PHP_URL_HOST ); |
|
| 180 | + $hostname = parse_url($url, PHP_URL_HOST); |
|
| 181 | 181 | |
| 182 | 182 | // Fallback when parse_url() fails. |
| 183 | - if ( empty( $hostname ) ) { |
|
| 183 | + if (empty($hostname)) { |
|
| 184 | 184 | $hostname = $url; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | - protected function hide_noptimize( $markup ) |
|
| 197 | + protected function hide_noptimize($markup) |
|
| 198 | 198 | { |
| 199 | 199 | return $this->replace_contents_with_marker_if_exists( |
| 200 | 200 | 'NOPTIMIZE', |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | - protected function restore_noptimize( $markup ) |
|
| 214 | + protected function restore_noptimize($markup) |
|
| 215 | 215 | { |
| 216 | - return $this->restore_marked_content( 'NOPTIMIZE', $markup ); |
|
| 216 | + return $this->restore_marked_content('NOPTIMIZE', $markup); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - protected function hide_iehacks( $markup ) |
|
| 226 | + protected function hide_iehacks($markup) |
|
| 227 | 227 | { |
| 228 | 228 | return $this->replace_contents_with_marker_if_exists( |
| 229 | 229 | 'IEHACK', // Marker name... |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | - protected function restore_iehacks( $markup ) |
|
| 243 | + protected function restore_iehacks($markup) |
|
| 244 | 244 | { |
| 245 | - return $this->restore_marked_content( 'IEHACK', $markup ); |
|
| 245 | + return $this->restore_marked_content('IEHACK', $markup); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * |
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | - protected function hide_comments( $markup ) |
|
| 257 | + protected function hide_comments($markup) |
|
| 258 | 258 | { |
| 259 | 259 | return $this->replace_contents_with_marker_if_exists( |
| 260 | 260 | 'COMMENTS', |
@@ -272,9 +272,9 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return string |
| 274 | 274 | */ |
| 275 | - protected function restore_comments( $markup ) |
|
| 275 | + protected function restore_comments($markup) |
|
| 276 | 276 | { |
| 277 | - return $this->restore_marked_content( 'COMMENTS', $markup ); |
|
| 277 | + return $this->restore_marked_content('COMMENTS', $markup); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -285,44 +285,44 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @return string |
| 287 | 287 | */ |
| 288 | - public function url_replace_cdn( $url ) |
|
| 288 | + public function url_replace_cdn($url) |
|
| 289 | 289 | { |
| 290 | 290 | // For 2.3 back-compat in which cdn-ing appeared to be automatically |
| 291 | 291 | // including WP subfolder/subdirectory into account as part of cdn-ing, |
| 292 | 292 | // even though it might've caused serious troubles in certain edge-cases. |
| 293 | - $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $this->cdn_url ); |
|
| 293 | + $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($this->cdn_url); |
|
| 294 | 294 | |
| 295 | 295 | // Allows API/filter to further tweak the cdn url... |
| 296 | - $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url ); |
|
| 297 | - if ( ! empty( $cdn_url ) ) { |
|
| 298 | - $this->debug_log( 'before=' . $url ); |
|
| 296 | + $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url); |
|
| 297 | + if (!empty($cdn_url)) { |
|
| 298 | + $this->debug_log('before='.$url); |
|
| 299 | 299 | |
| 300 | 300 | // Simple str_replace-based approach fails when $url is protocol-or-host-relative. |
| 301 | - $is_protocol_relative = autoptimizeUtils::is_protocol_relative( $url ); |
|
| 302 | - $is_host_relative = ( ! $is_protocol_relative && ( '/' === $url{0} ) ); |
|
| 303 | - $cdn_url = rtrim( $cdn_url, '/' ); |
|
| 301 | + $is_protocol_relative = autoptimizeUtils::is_protocol_relative($url); |
|
| 302 | + $is_host_relative = (!$is_protocol_relative && ('/' === $url{0} )); |
|
| 303 | + $cdn_url = rtrim($cdn_url, '/'); |
|
| 304 | 304 | |
| 305 | - if ( $is_host_relative ) { |
|
| 305 | + if ($is_host_relative) { |
|
| 306 | 306 | // Prepending host-relative urls with the cdn url. |
| 307 | - $url = $cdn_url . $url; |
|
| 307 | + $url = $cdn_url.$url; |
|
| 308 | 308 | } else { |
| 309 | 309 | // Either a protocol-relative or "regular" url, replacing it either way. |
| 310 | - if ( $is_protocol_relative ) { |
|
| 310 | + if ($is_protocol_relative) { |
|
| 311 | 311 | // Massage $site_url so that simple str_replace() still "works" by |
| 312 | 312 | // searching for the protocol-relative version of AUTOPTIMIZE_WP_SITE_URL. |
| 313 | - $site_url = str_replace( array( 'http:', 'https:' ), '', AUTOPTIMIZE_WP_SITE_URL ); |
|
| 313 | + $site_url = str_replace(array('http:', 'https:'), '', AUTOPTIMIZE_WP_SITE_URL); |
|
| 314 | 314 | } else { |
| 315 | 315 | $site_url = AUTOPTIMIZE_WP_SITE_URL; |
| 316 | 316 | } |
| 317 | - $this->debug_log( '`' . $site_url . '` -> `' . $cdn_url . '` in `' . $url . '`' ); |
|
| 318 | - $url = str_replace( $site_url, $cdn_url, $url ); |
|
| 317 | + $this->debug_log('`'.$site_url.'` -> `'.$cdn_url.'` in `'.$url.'`'); |
|
| 318 | + $url = str_replace($site_url, $cdn_url, $url); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - $this->debug_log( 'after=' . $url ); |
|
| 321 | + $this->debug_log('after='.$url); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | // Allow API filter to take further care of CDN replacement. |
| 325 | - $url = apply_filters( 'autoptimize_filter_base_replace_cdn', $url ); |
|
| 325 | + $url = apply_filters('autoptimize_filter_base_replace_cdn', $url); |
|
| 326 | 326 | |
| 327 | 327 | return $url; |
| 328 | 328 | } |
@@ -340,18 +340,18 @@ discard block |
||
| 340 | 340 | * |
| 341 | 341 | * @return void |
| 342 | 342 | */ |
| 343 | - protected function inject_in_html( $payload, $where ) |
|
| 343 | + protected function inject_in_html($payload, $where) |
|
| 344 | 344 | { |
| 345 | 345 | $warned = false; |
| 346 | - $position = autoptimizeUtils::strpos( $this->content, $where[0] ); |
|
| 347 | - if ( false !== $position ) { |
|
| 346 | + $position = autoptimizeUtils::strpos($this->content, $where[0]); |
|
| 347 | + if (false !== $position) { |
|
| 348 | 348 | // Found the tag, setup content/injection as specified. |
| 349 | - if ( 'after' === $where[1] ) { |
|
| 350 | - $content = $where[0] . $payload; |
|
| 351 | - } elseif ( 'replace' === $where[1] ) { |
|
| 349 | + if ('after' === $where[1]) { |
|
| 350 | + $content = $where[0].$payload; |
|
| 351 | + } elseif ('replace' === $where[1]) { |
|
| 352 | 352 | $content = $payload; |
| 353 | 353 | } else { |
| 354 | - $content = $payload . $where[0]; |
|
| 354 | + $content = $payload.$where[0]; |
|
| 355 | 355 | } |
| 356 | 356 | // Place where specified. |
| 357 | 357 | $this->content = autoptimizeUtils::substr_replace( |
@@ -360,14 +360,14 @@ discard block |
||
| 360 | 360 | $position, |
| 361 | 361 | // Using plain strlen() should be safe here for now, since |
| 362 | 362 | // we're not searching for multibyte chars here still... |
| 363 | - strlen( $where[0] ) |
|
| 363 | + strlen($where[0]) |
|
| 364 | 364 | ); |
| 365 | 365 | } else { |
| 366 | 366 | // Couldn't find what was specified, just append and add a warning. |
| 367 | 367 | $this->content .= $payload; |
| 368 | - if ( ! $warned ) { |
|
| 369 | - $tag_display = str_replace( array( '<', '>' ), '', $where[0] ); |
|
| 370 | - $this->content .= '<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag `' . $tag_display . '` missing --><!--/noptimize-->'; |
|
| 368 | + if (!$warned) { |
|
| 369 | + $tag_display = str_replace(array('<', '>'), '', $where[0]); |
|
| 370 | + $this->content .= '<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag `'.$tag_display.'` missing --><!--/noptimize-->'; |
|
| 371 | 371 | $warned = true; |
| 372 | 372 | } |
| 373 | 373 | } |
@@ -381,10 +381,10 @@ discard block |
||
| 381 | 381 | * |
| 382 | 382 | * @return bool |
| 383 | 383 | */ |
| 384 | - protected function isremovable( $tag, $removables ) |
|
| 384 | + protected function isremovable($tag, $removables) |
|
| 385 | 385 | { |
| 386 | - foreach ( $removables as $match ) { |
|
| 387 | - if ( false !== strpos( $tag, $match ) ) { |
|
| 386 | + foreach ($removables as $match) { |
|
| 387 | + if (false !== strpos($tag, $match)) { |
|
| 388 | 388 | return true; |
| 389 | 389 | } |
| 390 | 390 | } |
@@ -399,10 +399,10 @@ discard block |
||
| 399 | 399 | * |
| 400 | 400 | * @return string |
| 401 | 401 | */ |
| 402 | - public function inject_minified_callback( $matches ) |
|
| 402 | + public function inject_minified_callback($matches) |
|
| 403 | 403 | { |
| 404 | 404 | static $conf = null; |
| 405 | - if ( null === $conf ) { |
|
| 405 | + if (null === $conf) { |
|
| 406 | 406 | $conf = autoptimizeConfig::instance(); |
| 407 | 407 | } |
| 408 | 408 | |
@@ -417,62 +417,62 @@ discard block |
||
| 417 | 417 | $filehash = null; |
| 418 | 418 | |
| 419 | 419 | // Grab the parts we need. |
| 420 | - $parts = explode( '|', $matches[1] ); |
|
| 421 | - if ( ! empty( $parts ) ) { |
|
| 422 | - $filepath = isset( $parts[0] ) ? base64_decode($parts[0]) : null; |
|
| 423 | - $filehash = isset( $parts[1] ) ? $parts[1] : null; |
|
| 420 | + $parts = explode('|', $matches[1]); |
|
| 421 | + if (!empty($parts)) { |
|
| 422 | + $filepath = isset($parts[0]) ? base64_decode($parts[0]) : null; |
|
| 423 | + $filehash = isset($parts[1]) ? $parts[1] : null; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | // Bail early if something's not right... |
| 427 | - if ( ! $filepath || ! $filehash ) { |
|
| 427 | + if (!$filepath || !$filehash) { |
|
| 428 | 428 | return "\n"; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - $filecontent = file_get_contents( $filepath ); |
|
| 431 | + $filecontent = file_get_contents($filepath); |
|
| 432 | 432 | |
| 433 | 433 | // Some things are differently handled for css/js... |
| 434 | - $is_js_file = ( '.js' === substr( $filepath, -3, 3 ) ); |
|
| 434 | + $is_js_file = ('.js' === substr($filepath, -3, 3)); |
|
| 435 | 435 | |
| 436 | 436 | $is_css_file = false; |
| 437 | - if ( ! $is_js_file ) { |
|
| 438 | - $is_css_file = ( '.css' === substr( $filepath, -4, 4 ) ); |
|
| 437 | + if (!$is_js_file) { |
|
| 438 | + $is_css_file = ('.css' === substr($filepath, -4, 4)); |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | // BOMs being nuked here unconditionally (regardless of where they are)! |
| 442 | - $filecontent = preg_replace( "#\x{EF}\x{BB}\x{BF}#", '', $filecontent ); |
|
| 442 | + $filecontent = preg_replace("#\x{EF}\x{BB}\x{BF}#", '', $filecontent); |
|
| 443 | 443 | |
| 444 | 444 | // Remove comments and blank lines. |
| 445 | - if ( $is_js_file ) { |
|
| 446 | - $filecontent = preg_replace( '#^\s*\/\/.*$#Um', '', $filecontent ); |
|
| 445 | + if ($is_js_file) { |
|
| 446 | + $filecontent = preg_replace('#^\s*\/\/.*$#Um', '', $filecontent); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | // Nuke un-important comments. |
| 450 | - $filecontent = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Um', '', $filecontent ); |
|
| 450 | + $filecontent = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Um', '', $filecontent); |
|
| 451 | 451 | |
| 452 | 452 | // Normalize newlines. |
| 453 | - $filecontent = preg_replace( '#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#', "\n", $filecontent ); |
|
| 453 | + $filecontent = preg_replace('#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#', "\n", $filecontent); |
|
| 454 | 454 | |
| 455 | 455 | // JS specifics. |
| 456 | - if ( $is_js_file ) { |
|
| 456 | + if ($is_js_file) { |
|
| 457 | 457 | // Append a semicolon at the end of js files if it's missing. |
| 458 | - $last_char = substr( $filecontent, -1, 1 ); |
|
| 459 | - if ( ';' !== $last_char && '}' !== $last_char ) { |
|
| 458 | + $last_char = substr($filecontent, -1, 1); |
|
| 459 | + if (';' !== $last_char && '}' !== $last_char) { |
|
| 460 | 460 | $filecontent .= ';'; |
| 461 | 461 | } |
| 462 | 462 | // Check if try/catch should be used. |
| 463 | - $opt_js_try_catch = $conf->get( 'autoptimize_js_trycatch' ); |
|
| 464 | - if ( 'on' === $opt_js_try_catch ) { |
|
| 463 | + $opt_js_try_catch = $conf->get('autoptimize_js_trycatch'); |
|
| 464 | + if ('on' === $opt_js_try_catch) { |
|
| 465 | 465 | // It should, wrap in try/catch. |
| 466 | - $filecontent = 'try{' . $filecontent . '}catch(e){}'; |
|
| 466 | + $filecontent = 'try{'.$filecontent.'}catch(e){}'; |
|
| 467 | 467 | } |
| 468 | - } elseif ( $is_css_file ) { |
|
| 469 | - $filecontent = autoptimizeStyles::fixurls( $filepath, $filecontent ); |
|
| 468 | + } elseif ($is_css_file) { |
|
| 469 | + $filecontent = autoptimizeStyles::fixurls($filepath, $filecontent); |
|
| 470 | 470 | } else { |
| 471 | 471 | $filecontent = ''; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | // Return modified (or empty!) code/content. |
| 475 | - return "\n" . $filecontent; |
|
| 475 | + return "\n".$filecontent; |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -482,13 +482,13 @@ discard block |
||
| 482 | 482 | * |
| 483 | 483 | * @return string |
| 484 | 484 | */ |
| 485 | - protected function inject_minified( $in ) |
|
| 485 | + protected function inject_minified($in) |
|
| 486 | 486 | { |
| 487 | 487 | $out = $in; |
| 488 | - if ( false !== strpos( $in, '%%INJECTLATER%%' ) ) { |
|
| 488 | + if (false !== strpos($in, '%%INJECTLATER%%')) { |
|
| 489 | 489 | $out = preg_replace_callback( |
| 490 | - '#\/\*\!%%INJECTLATER' . AUTOPTIMIZE_HASH . '%%(.*?)%%INJECTLATER%%\*\/#is', |
|
| 491 | - array( $this, 'inject_minified_callback' ), |
|
| 490 | + '#\/\*\!%%INJECTLATER'.AUTOPTIMIZE_HASH.'%%(.*?)%%INJECTLATER%%\*\/#is', |
|
| 491 | + array($this, 'inject_minified_callback'), |
|
| 492 | 492 | $in |
| 493 | 493 | ); |
| 494 | 494 | } |
@@ -508,9 +508,9 @@ discard block |
||
| 508 | 508 | * |
| 509 | 509 | * @return string |
| 510 | 510 | */ |
| 511 | - public static function build_injectlater_marker( $filepath, $hash ) |
|
| 511 | + public static function build_injectlater_marker($filepath, $hash) |
|
| 512 | 512 | { |
| 513 | - $contents = '/*!' . self::build_marker( 'INJECTLATER', $filepath, $hash ) . '*/'; |
|
| 513 | + $contents = '/*!'.self::build_marker('INJECTLATER', $filepath, $hash).'*/'; |
|
| 514 | 514 | |
| 515 | 515 | return $contents; |
| 516 | 516 | } |
@@ -528,18 +528,18 @@ discard block |
||
| 528 | 528 | * |
| 529 | 529 | * @return string |
| 530 | 530 | */ |
| 531 | - public static function build_marker( $name, $data, $hash = null ) |
|
| 531 | + public static function build_marker($name, $data, $hash = null) |
|
| 532 | 532 | { |
| 533 | 533 | // Start the marker, add the data. |
| 534 | - $marker = '%%' . $name . AUTOPTIMIZE_HASH . '%%' . base64_encode( $data ); |
|
| 534 | + $marker = '%%'.$name.AUTOPTIMIZE_HASH.'%%'.base64_encode($data); |
|
| 535 | 535 | |
| 536 | 536 | // Add the hash if provided. |
| 537 | - if ( null !== $hash ) { |
|
| 538 | - $marker .= '|' . $hash; |
|
| 537 | + if (null !== $hash) { |
|
| 538 | + $marker .= '|'.$hash; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | // Close the marker. |
| 542 | - $marker .= '%%' . $name . '%%'; |
|
| 542 | + $marker .= '%%'.$name.'%%'; |
|
| 543 | 543 | |
| 544 | 544 | return $marker; |
| 545 | 545 | } |
@@ -559,22 +559,22 @@ discard block |
||
| 559 | 559 | * |
| 560 | 560 | * @return string |
| 561 | 561 | */ |
| 562 | - protected function replace_contents_with_marker_if_exists( $marker, $search, $re_replace_pattern, $content ) |
|
| 562 | + protected function replace_contents_with_marker_if_exists($marker, $search, $re_replace_pattern, $content) |
|
| 563 | 563 | { |
| 564 | 564 | $found = false; |
| 565 | 565 | |
| 566 | - $is_regex = autoptimizeUtils::str_is_valid_regex( $search ); |
|
| 567 | - if ( $is_regex ) { |
|
| 568 | - $found = preg_match( $search, $content ); |
|
| 566 | + $is_regex = autoptimizeUtils::str_is_valid_regex($search); |
|
| 567 | + if ($is_regex) { |
|
| 568 | + $found = preg_match($search, $content); |
|
| 569 | 569 | } else { |
| 570 | - $found = ( false !== strpos( $content, $search ) ); |
|
| 570 | + $found = (false !== strpos($content, $search)); |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - if ( $found ) { |
|
| 573 | + if ($found) { |
|
| 574 | 574 | $content = preg_replace_callback( |
| 575 | 575 | $re_replace_pattern, |
| 576 | - function( $matches ) use ( $marker ) { |
|
| 577 | - return autoptimizeBase::build_marker( $marker, $matches[0] ); |
|
| 576 | + function($matches) use ($marker) { |
|
| 577 | + return autoptimizeBase::build_marker($marker, $matches[0]); |
|
| 578 | 578 | }, |
| 579 | 579 | $content |
| 580 | 580 | ); |
@@ -591,13 +591,13 @@ discard block |
||
| 591 | 591 | * |
| 592 | 592 | * @return string |
| 593 | 593 | */ |
| 594 | - protected function restore_marked_content( $marker, $content ) |
|
| 594 | + protected function restore_marked_content($marker, $content) |
|
| 595 | 595 | { |
| 596 | - if ( false !== strpos( $content, $marker ) ) { |
|
| 596 | + if (false !== strpos($content, $marker)) { |
|
| 597 | 597 | $content = preg_replace_callback( |
| 598 | - '#%%' . $marker . AUTOPTIMIZE_HASH . '%%(.*?)%%' . $marker . '%%#is', |
|
| 599 | - function ( $matches ) { |
|
| 600 | - return base64_decode( $matches[1] ); |
|
| 598 | + '#%%'.$marker.AUTOPTIMIZE_HASH.'%%(.*?)%%'.$marker.'%%#is', |
|
| 599 | + function($matches) { |
|
| 600 | + return base64_decode($matches[1]); |
|
| 601 | 601 | }, |
| 602 | 602 | $content |
| 603 | 603 | ); |
@@ -613,17 +613,17 @@ discard block |
||
| 613 | 613 | * |
| 614 | 614 | * @return void |
| 615 | 615 | */ |
| 616 | - protected function debug_log( $data ) |
|
| 616 | + protected function debug_log($data) |
|
| 617 | 617 | { |
| 618 | - if ( ! isset( $this->debug_log ) || ! $this->debug_log ) { |
|
| 618 | + if (!isset($this->debug_log) || !$this->debug_log) { |
|
| 619 | 619 | return; |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | - if ( ! is_string( $data ) && ! is_resource( $data ) ) { |
|
| 623 | - $data = var_export( $data, true ); |
|
| 622 | + if (!is_string($data) && !is_resource($data)) { |
|
| 623 | + $data = var_export($data, true); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | - error_log( $data ); |
|
| 626 | + error_log($data); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | /** |
@@ -633,12 +633,12 @@ discard block |
||
| 633 | 633 | * |
| 634 | 634 | * @return bool|string to be minified code or false. |
| 635 | 635 | */ |
| 636 | - protected function prepare_minify_single( $filepath ) |
|
| 636 | + protected function prepare_minify_single($filepath) |
|
| 637 | 637 | { |
| 638 | 638 | // Decide what we're dealing with, return false if we don't know. |
| 639 | - if ( $this->str_ends_in( $filepath, '.js' ) ) { |
|
| 639 | + if ($this->str_ends_in($filepath, '.js')) { |
|
| 640 | 640 | $type = 'js'; |
| 641 | - } elseif ( $this->str_ends_in( $filepath, '.css' ) ) { |
|
| 641 | + } elseif ($this->str_ends_in($filepath, '.css')) { |
|
| 642 | 642 | $type = 'css'; |
| 643 | 643 | } else { |
| 644 | 644 | return false; |
@@ -647,18 +647,18 @@ discard block |
||
| 647 | 647 | // Bail if it looks like its already minifed (by having -min or .min |
| 648 | 648 | // in filename) or if it looks like WP jquery.js (which is minified). |
| 649 | 649 | $minified_variants = array( |
| 650 | - '-min.' . $type, |
|
| 651 | - '.min.' . $type, |
|
| 650 | + '-min.'.$type, |
|
| 651 | + '.min.'.$type, |
|
| 652 | 652 | 'js/jquery/jquery.js', |
| 653 | 653 | ); |
| 654 | - foreach ( $minified_variants as $ending ) { |
|
| 655 | - if ( $this->str_ends_in( $filepath, $ending ) ) { |
|
| 654 | + foreach ($minified_variants as $ending) { |
|
| 655 | + if ($this->str_ends_in($filepath, $ending)) { |
|
| 656 | 656 | return false; |
| 657 | 657 | } |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | // Get file contents, bail if empty. |
| 661 | - $contents = file_get_contents( $filepath ); |
|
| 661 | + $contents = file_get_contents($filepath); |
|
| 662 | 662 | |
| 663 | 663 | return $contents; |
| 664 | 664 | } |
@@ -671,12 +671,12 @@ discard block |
||
| 671 | 671 | * |
| 672 | 672 | * @return string |
| 673 | 673 | */ |
| 674 | - protected function build_minify_single_url( autoptimizeCache $cache ) |
|
| 674 | + protected function build_minify_single_url(autoptimizeCache $cache) |
|
| 675 | 675 | { |
| 676 | - $url = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
| 676 | + $url = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
| 677 | 677 | |
| 678 | 678 | // CDN-replace the resulting URL if needed... |
| 679 | - $url = $this->url_replace_cdn( $url ); |
|
| 679 | + $url = $this->url_replace_cdn($url); |
|
| 680 | 680 | |
| 681 | 681 | return $url; |
| 682 | 682 | } |
@@ -689,15 +689,15 @@ discard block |
||
| 689 | 689 | * |
| 690 | 690 | * @return bool |
| 691 | 691 | */ |
| 692 | - protected function str_ends_in( $str, $test ) |
|
| 692 | + protected function str_ends_in($str, $test) |
|
| 693 | 693 | { |
| 694 | 694 | // @codingStandardsIgnoreStart |
| 695 | 695 | // substr_compare() is bugged on 5.5.11: https://3v4l.org/qGYBH |
| 696 | 696 | // return ( 0 === substr_compare( $str, $test, -strlen( $test ) ) ); |
| 697 | 697 | // @codingStandardsIgnoreEnd |
| 698 | 698 | |
| 699 | - $length = strlen( $test ); |
|
| 699 | + $length = strlen($test); |
|
| 700 | 700 | |
| 701 | - return ( substr( $str, -$length, $length ) === $test ); |
|
| 701 | + return (substr($str, -$length, $length) === $test); |
|
| 702 | 702 | } |
| 703 | 703 | } |
@@ -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 | } |