| @@ -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'); | |
| @@ -3,7 +3,7 @@ discard block | ||
| 3 | 3 | * Handles disk-cache-related operations. | 
| 4 | 4 | */ | 
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | +if (!defined('ABSPATH')) { | |
| 7 | 7 | exit; | 
| 8 | 8 | } | 
| 9 | 9 | |
| @@ -38,17 +38,17 @@ discard block | ||
| 38 | 38 | * @param string $md5 Hash. | 
| 39 | 39 | * @param string $ext Extension. | 
| 40 | 40 | */ | 
| 41 | - public function __construct( $md5, $ext = 'php' ) | |
| 41 | + public function __construct($md5, $ext = 'php') | |
| 42 | 42 |      { | 
| 43 | 43 | $this->cachedir = AUTOPTIMIZE_CACHE_DIR; | 
| 44 | 44 | $this->nogzip = AUTOPTIMIZE_CACHE_NOGZIP; | 
| 45 | -        if ( ! $this->nogzip ) { | |
| 46 | - $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . '.php'; | |
| 45 | +        if (!$this->nogzip) { | |
| 46 | + $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.'.php'; | |
| 47 | 47 |          } else { | 
| 48 | -            if ( in_array( $ext, array( 'js', 'css' ) ) ) { | |
| 49 | - $this->filename = $ext . '/' . AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . '.' . $ext; | |
| 48 | +            if (in_array($ext, array('js', 'css'))) { | |
| 49 | + $this->filename = $ext.'/'.AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.'.'.$ext; | |
| 50 | 50 |              } else { | 
| 51 | - $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . '.' . $ext; | |
| 51 | + $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.'.'.$ext; | |
| 52 | 52 | } | 
| 53 | 53 | } | 
| 54 | 54 | } | 
| @@ -60,7 +60,7 @@ discard block | ||
| 60 | 60 | */ | 
| 61 | 61 | public function check() | 
| 62 | 62 |      { | 
| 63 | - return file_exists( $this->cachedir . $this->filename ); | |
| 63 | + return file_exists($this->cachedir.$this->filename); | |
| 64 | 64 | } | 
| 65 | 65 | |
| 66 | 66 | /** | 
| @@ -70,11 +70,11 @@ discard block | ||
| 70 | 70 | */ | 
| 71 | 71 | public function retrieve() | 
| 72 | 72 |      { | 
| 73 | -        if ( $this->check() ) { | |
| 74 | -            if ( false == $this->nogzip ) { | |
| 75 | - return file_get_contents( $this->cachedir . $this->filename . '.none' ); | |
| 73 | +        if ($this->check()) { | |
| 74 | +            if (false == $this->nogzip) { | |
| 75 | + return file_get_contents($this->cachedir.$this->filename.'.none'); | |
| 76 | 76 |              } else { | 
| 77 | - return file_get_contents( $this->cachedir . $this->filename ); | |
| 77 | + return file_get_contents($this->cachedir.$this->filename); | |
| 78 | 78 | } | 
| 79 | 79 | } | 
| 80 | 80 | return false; | 
| @@ -88,22 +88,22 @@ discard block | ||
| 88 | 88 | * | 
| 89 | 89 | * @return void | 
| 90 | 90 | */ | 
| 91 | - public function cache( $data, $mime ) | |
| 91 | + public function cache($data, $mime) | |
| 92 | 92 |      { | 
| 93 | -        if ( false === $this->nogzip ) { | |
| 93 | +        if (false === $this->nogzip) { | |
| 94 | 94 | // We handle gzipping ourselves. | 
| 95 | 95 | $file = 'default.php'; | 
| 96 | - $phpcode = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $file ); | |
| 97 | - $phpcode = str_replace( array( '%%CONTENT%%', 'exit;' ), array( $mime, '' ), $phpcode ); | |
| 96 | + $phpcode = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$file); | |
| 97 | +            $phpcode = str_replace(array('%%CONTENT%%', 'exit;'), array($mime, ''), $phpcode); | |
| 98 | 98 | |
| 99 | - file_put_contents( $this->cachedir . $this->filename, $phpcode ); | |
| 100 | - file_put_contents( $this->cachedir . $this->filename . '.none', $data ); | |
| 99 | + file_put_contents($this->cachedir.$this->filename, $phpcode); | |
| 100 | + file_put_contents($this->cachedir.$this->filename.'.none', $data); | |
| 101 | 101 |          } else { | 
| 102 | 102 | // Write code to cache without doing anything else. | 
| 103 | - file_put_contents( $this->cachedir . $this->filename, $data ); | |
| 104 | -            if ( apply_filters( 'autoptimize_filter_cache_create_static_gzip', false ) ) { | |
| 103 | + file_put_contents($this->cachedir.$this->filename, $data); | |
| 104 | +            if (apply_filters('autoptimize_filter_cache_create_static_gzip', false)) { | |
| 105 | 105 | // Create an additional cached gzip file. | 
| 106 | - file_put_contents( $this->cachedir . $this->filename . '.gz', gzencode( $data, 9, FORCE_GZIP ) ); | |
| 106 | + file_put_contents($this->cachedir.$this->filename.'.gz', gzencode($data, 9, FORCE_GZIP)); | |
| 107 | 107 | } | 
| 108 | 108 | } | 
| 109 | 109 | } | 
| @@ -120,7 +120,7 @@ discard block | ||
| 120 | 120 | // The original idea here was to provide 3rd party code a hook so that | 
| 121 | 121 | // it can "listen" to all the complete autoptimized-urls that the page | 
| 122 | 122 | // will emit... Or something to that effect I think? | 
| 123 | - apply_filters( 'autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL . $this->filename ); | |
| 123 | +        apply_filters('autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL.$this->filename); | |
| 124 | 124 | |
| 125 | 125 | return $this->filename; | 
| 126 | 126 | } | 
| @@ -133,11 +133,11 @@ discard block | ||
| 133 | 133 | * @param string $file Filename. | 
| 134 | 134 | * @return bool | 
| 135 | 135 | */ | 
| 136 | - protected static function is_valid_cache_file( $dir, $file ) | |
| 136 | + protected static function is_valid_cache_file($dir, $file) | |
| 137 | 137 |      { | 
| 138 | - if ( '.' !== $file && '..' !== $file && | |
| 139 | - false !== strpos( $file, AUTOPTIMIZE_CACHEFILE_PREFIX ) && | |
| 140 | -            is_file( $dir . $file ) ) { | |
| 138 | +        if ('.' !== $file && '..' !== $file && | |
| 139 | + false !== strpos($file, AUTOPTIMIZE_CACHEFILE_PREFIX) && | |
| 140 | +            is_file($dir.$file)) { | |
| 141 | 141 | |
| 142 | 142 | // It's a valid file! | 
| 143 | 143 | return true; | 
| @@ -155,16 +155,16 @@ discard block | ||
| 155 | 155 | protected static function clear_cache_classic() | 
| 156 | 156 |      { | 
| 157 | 157 | $contents = self::get_cache_contents(); | 
| 158 | -        foreach ( $contents as $name => $files ) { | |
| 159 | - $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/'; | |
| 160 | -            foreach ( $files as $file ) { | |
| 161 | -                if ( self::is_valid_cache_file( $dir, $file ) ) { | |
| 162 | - @unlink( $dir . $file ); // @codingStandardsIgnoreLine | |
| 158 | +        foreach ($contents as $name => $files) { | |
| 159 | + $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/'; | |
| 160 | +            foreach ($files as $file) { | |
| 161 | +                if (self::is_valid_cache_file($dir, $file)) { | |
| 162 | + @unlink($dir.$file); // @codingStandardsIgnoreLine | |
| 163 | 163 | } | 
| 164 | 164 | } | 
| 165 | 165 | } | 
| 166 | 166 | |
| 167 | - @unlink( AUTOPTIMIZE_CACHE_DIR . '/.htaccess' ); // @codingStandardsIgnoreLine | |
| 167 | + @unlink(AUTOPTIMIZE_CACHE_DIR.'/.htaccess'); // @codingStandardsIgnoreLine | |
| 168 | 168 | } | 
| 169 | 169 | |
| 170 | 170 | /** | 
| @@ -175,19 +175,19 @@ discard block | ||
| 175 | 175 | * | 
| 176 | 176 | * @return bool | 
| 177 | 177 | */ | 
| 178 | - protected static function rmdir( $pathname ) | |
| 178 | + protected static function rmdir($pathname) | |
| 179 | 179 |      { | 
| 180 | - $files = self::get_dir_contents( $pathname ); | |
| 181 | -        foreach ( $files as $file ) { | |
| 182 | - $path = $pathname . '/' . $file; | |
| 183 | -            if ( is_dir( $path ) ) { | |
| 184 | - self::rmdir( $path ); | |
| 180 | + $files = self::get_dir_contents($pathname); | |
| 181 | +        foreach ($files as $file) { | |
| 182 | + $path = $pathname.'/'.$file; | |
| 183 | +            if (is_dir($path)) { | |
| 184 | + self::rmdir($path); | |
| 185 | 185 |              } else { | 
| 186 | - unlink( $path ); | |
| 186 | + unlink($path); | |
| 187 | 187 | } | 
| 188 | 188 | } | 
| 189 | 189 | |
| 190 | - return rmdir( $pathname ); | |
| 190 | + return rmdir($pathname); | |
| 191 | 191 | } | 
| 192 | 192 | |
| 193 | 193 | /** | 
| @@ -204,12 +204,12 @@ discard block | ||
| 204 | 204 | $new_name = self::get_unique_name(); | 
| 205 | 205 | |
| 206 | 206 | // Makes sure the new pathname is on the same level... | 
| 207 | - $new_pathname = dirname( $dir ) . '/' . $new_name; | |
| 208 | - $renamed = @rename( $dir, $new_pathname ); // @codingStandardsIgnoreLine | |
| 207 | + $new_pathname = dirname($dir).'/'.$new_name; | |
| 208 | + $renamed = @rename($dir, $new_pathname); // @codingStandardsIgnoreLine | |
| 209 | 209 | |
| 210 | 210 | // When renamed, re-create the default cache directory back so it's | 
| 211 | 211 | // available again... | 
| 212 | -        if ( $renamed ) { | |
| 212 | +        if ($renamed) { | |
| 213 | 213 | $ok = self::cacheavail(); | 
| 214 | 214 | } | 
| 215 | 215 | |
| @@ -223,7 +223,7 @@ discard block | ||
| 223 | 223 | */ | 
| 224 | 224 | public static function advanced_cache_clear_enabled() | 
| 225 | 225 |      { | 
| 226 | - return apply_filters( 'autoptimize_filter_cache_clear_advanced', false ); | |
| 226 | +        return apply_filters('autoptimize_filter_cache_clear_advanced', false); | |
| 227 | 227 | } | 
| 228 | 228 | |
| 229 | 229 | /** | 
| @@ -234,7 +234,7 @@ discard block | ||
| 234 | 234 | protected static function get_unique_name() | 
| 235 | 235 |      { | 
| 236 | 236 | $prefix = self::get_advanced_cache_clear_prefix(); | 
| 237 | - $new_name = uniqid( $prefix, true ); | |
| 237 | + $new_name = uniqid($prefix, true); | |
| 238 | 238 | |
| 239 | 239 | return $new_name; | 
| 240 | 240 | } | 
| @@ -247,8 +247,8 @@ discard block | ||
| 247 | 247 | protected static function get_advanced_cache_clear_prefix() | 
| 248 | 248 |      { | 
| 249 | 249 | $pathname = self::get_pathname_base(); | 
| 250 | - $basename = basename( $pathname ); | |
| 251 | - $prefix = $basename . '-'; | |
| 250 | + $basename = basename($pathname); | |
| 251 | + $prefix = $basename.'-'; | |
| 252 | 252 | |
| 253 | 253 | return $prefix; | 
| 254 | 254 | } | 
| @@ -261,9 +261,9 @@ discard block | ||
| 261 | 261 | * | 
| 262 | 262 | * @return array | 
| 263 | 263 | */ | 
| 264 | - protected static function get_dir_contents( $pathname ) | |
| 264 | + protected static function get_dir_contents($pathname) | |
| 265 | 265 |      { | 
| 266 | - return array_slice( scandir( $pathname ), 2 ); | |
| 266 | + return array_slice(scandir($pathname), 2); | |
| 267 | 267 | } | 
| 268 | 268 | |
| 269 | 269 | /** | 
| @@ -277,17 +277,17 @@ discard block | ||
| 277 | 277 |      { | 
| 278 | 278 | $dir = self::get_pathname_base(); | 
| 279 | 279 | $prefix = self::get_advanced_cache_clear_prefix(); | 
| 280 | - $parent = dirname( $dir ); | |
| 280 | + $parent = dirname($dir); | |
| 281 | 281 | $ok = false; | 
| 282 | 282 | |
| 283 | 283 | // Returns the list of files without '.' and '..' elements. | 
| 284 | - $files = self::get_dir_contents( $parent ); | |
| 285 | -        foreach ( $files as $file ) { | |
| 286 | - $path = $parent . '/' . $file; | |
| 287 | - $prefixed = ( false !== strpos( $path, $prefix ) ); | |
| 284 | + $files = self::get_dir_contents($parent); | |
| 285 | +        foreach ($files as $file) { | |
| 286 | + $path = $parent.'/'.$file; | |
| 287 | + $prefixed = (false !== strpos($path, $prefix)); | |
| 288 | 288 | // Removing only our own (prefixed) directories... | 
| 289 | -            if ( is_dir( $path ) && $prefixed ) { | |
| 290 | - $ok = self::rmdir( $path ); | |
| 289 | +            if (is_dir($path) && $prefixed) { | |
| 290 | + $ok = self::rmdir($path); | |
| 291 | 291 | } | 
| 292 | 292 | } | 
| 293 | 293 | |
| @@ -306,9 +306,9 @@ discard block | ||
| 306 | 306 |      { | 
| 307 | 307 | $pathname = self::get_pathname_base(); | 
| 308 | 308 | |
| 309 | -        if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { | |
| 309 | +        if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { | |
| 310 | 310 | $blog_id = get_current_blog_id(); | 
| 311 | - $pathname .= $blog_id . '/'; | |
| 311 | + $pathname .= $blog_id.'/'; | |
| 312 | 312 | } | 
| 313 | 313 | |
| 314 | 314 | return $pathname; | 
| @@ -321,7 +321,7 @@ discard block | ||
| 321 | 321 | */ | 
| 322 | 322 | protected static function get_pathname_base() | 
| 323 | 323 |      { | 
| 324 | - $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR; | |
| 324 | + $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR; | |
| 325 | 325 | |
| 326 | 326 | return $pathname; | 
| 327 | 327 | } | 
| @@ -333,38 +333,38 @@ discard block | ||
| 333 | 333 | * | 
| 334 | 334 | * @return bool | 
| 335 | 335 | */ | 
| 336 | - public static function clearall( $propagate = true ) | |
| 336 | + public static function clearall($propagate = true) | |
| 337 | 337 |      { | 
| 338 | -        if ( ! self::cacheavail() ) { | |
| 338 | +        if (!self::cacheavail()) { | |
| 339 | 339 | return false; | 
| 340 | 340 | } | 
| 341 | 341 | |
| 342 | 342 | // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically? | 
| 343 | -        if ( self::advanced_cache_clear_enabled() ) { | |
| 343 | +        if (self::advanced_cache_clear_enabled()) { | |
| 344 | 344 | self::clear_cache_via_rename(); | 
| 345 | 345 |          } else { | 
| 346 | 346 | self::clear_cache_classic(); | 
| 347 | 347 | } | 
| 348 | 348 | |
| 349 | 349 | // Remove the transient so it gets regenerated... | 
| 350 | - delete_transient( 'autoptimize_stats' ); | |
| 350 | +        delete_transient('autoptimize_stats'); | |
| 351 | 351 | |
| 352 | 352 | // Cache was just purged, clear page cache and allow others to hook into our purging... | 
| 353 | -        if ( true === $propagate ) { | |
| 354 | -            if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) { | |
| 353 | +        if (true === $propagate) { | |
| 354 | +            if (!function_exists('autoptimize_do_cachepurged_action')) { | |
| 355 | 355 |                  function autoptimize_do_cachepurged_action() { | 
| 356 | - do_action( 'autoptimize_action_cachepurged' ); | |
| 356 | +                    do_action('autoptimize_action_cachepurged'); | |
| 357 | 357 | } | 
| 358 | 358 | } | 
| 359 | - add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 ); | |
| 360 | - add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 ); | |
| 359 | +            add_action('shutdown', 'autoptimize_do_cachepurged_action', 11); | |
| 360 | +            add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0); | |
| 361 | 361 | } | 
| 362 | 362 | |
| 363 | 363 | // Warm cache (part of speedupper)! | 
| 364 | -        if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) { | |
| 365 | - $url = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 ); | |
| 366 | - $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine | |
| 367 | - unset( $cache ); | |
| 364 | +        if (apply_filters('autoptimize_filter_speedupper', true)) { | |
| 365 | + $url = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000); | |
| 366 | + $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine | |
| 367 | + unset($cache); | |
| 368 | 368 | } | 
| 369 | 369 | |
| 370 | 370 | return true; | 
| @@ -379,7 +379,7 @@ discard block | ||
| 379 | 379 | */ | 
| 380 | 380 | public static function clearall_actionless() | 
| 381 | 381 |      { | 
| 382 | - return self::clearall( false ); | |
| 382 | + return self::clearall(false); | |
| 383 | 383 | } | 
| 384 | 384 | |
| 385 | 385 | /** | 
| @@ -391,8 +391,8 @@ discard block | ||
| 391 | 391 |      { | 
| 392 | 392 | $contents = array(); | 
| 393 | 393 | |
| 394 | -        foreach ( array( '', 'js', 'css' ) as $dir ) { | |
| 395 | - $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir ); | |
| 394 | +        foreach (array('', 'js', 'css') as $dir) { | |
| 395 | + $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir); | |
| 396 | 396 | } | 
| 397 | 397 | |
| 398 | 398 | return $contents; | 
| @@ -405,21 +405,21 @@ discard block | ||
| 405 | 405 | */ | 
| 406 | 406 | public static function stats() | 
| 407 | 407 |      { | 
| 408 | - $stats = get_transient( 'autoptimize_stats' ); | |
| 408 | +        $stats = get_transient('autoptimize_stats'); | |
| 409 | 409 | |
| 410 | 410 | // If no transient, do the actual scan! | 
| 411 | -        if ( ! is_array( $stats ) ) { | |
| 412 | -            if ( ! self::cacheavail() ) { | |
| 411 | +        if (!is_array($stats)) { | |
| 412 | +            if (!self::cacheavail()) { | |
| 413 | 413 | return 0; | 
| 414 | 414 | } | 
| 415 | 415 | $stats = self::stats_scan(); | 
| 416 | 416 | $count = $stats[0]; | 
| 417 | -            if ( $count > 100 ) { | |
| 417 | +            if ($count > 100) { | |
| 418 | 418 | // Store results in transient. | 
| 419 | 419 | set_transient( | 
| 420 | 420 | 'autoptimize_stats', | 
| 421 | 421 | $stats, | 
| 422 | - apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS ) | |
| 422 | +                    apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS) | |
| 423 | 423 | ); | 
| 424 | 424 | } | 
| 425 | 425 | } | 
| @@ -442,30 +442,30 @@ discard block | ||
| 442 | 442 | $size = 0; | 
| 443 | 443 | |
| 444 | 444 | // Scan everything in our cache directories. | 
| 445 | -        foreach ( self::get_cache_contents() as $name => $files ) { | |
| 446 | - $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/'; | |
| 447 | -            foreach ( $files as $file ) { | |
| 448 | -                if ( self::is_valid_cache_file( $dir, $file ) ) { | |
| 449 | - if ( AUTOPTIMIZE_CACHE_NOGZIP && | |
| 445 | +        foreach (self::get_cache_contents() as $name => $files) { | |
| 446 | + $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/'; | |
| 447 | +            foreach ($files as $file) { | |
| 448 | +                if (self::is_valid_cache_file($dir, $file)) { | |
| 449 | + if (AUTOPTIMIZE_CACHE_NOGZIP && | |
| 450 | 450 | ( | 
| 451 | - false !== strpos( $file, '.js' ) || | |
| 452 | - false !== strpos( $file, '.css' ) || | |
| 453 | - false !== strpos( $file, '.img' ) || | |
| 454 | - false !== strpos( $file, '.txt' ) | |
| 451 | + false !== strpos($file, '.js') || | |
| 452 | + false !== strpos($file, '.css') || | |
| 453 | + false !== strpos($file, '.img') || | |
| 454 | + false !== strpos($file, '.txt') | |
| 455 | 455 | ) | 
| 456 | 456 |                      ) { | 
| 457 | 457 | // Web server is gzipping, we count .js|.css|.img|.txt files. | 
| 458 | 458 | $count++; | 
| 459 | -                    } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) { | |
| 459 | +                    } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) { | |
| 460 | 460 | // We are gzipping ourselves via php, counting only .none files. | 
| 461 | 461 | $count++; | 
| 462 | 462 | } | 
| 463 | - $size += filesize( $dir . $file ); | |
| 463 | + $size += filesize($dir.$file); | |
| 464 | 464 | } | 
| 465 | 465 | } | 
| 466 | 466 | } | 
| 467 | 467 | |
| 468 | - $stats = array( $count, $size, time() ); | |
| 468 | + $stats = array($count, $size, time()); | |
| 469 | 469 | |
| 470 | 470 | return $stats; | 
| 471 | 471 | } | 
| @@ -479,29 +479,29 @@ discard block | ||
| 479 | 479 | */ | 
| 480 | 480 | public static function cacheavail() | 
| 481 | 481 |      { | 
| 482 | -        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) { | |
| 482 | +        if (!defined('AUTOPTIMIZE_CACHE_DIR')) { | |
| 483 | 483 | // We didn't set a cache. | 
| 484 | 484 | return false; | 
| 485 | 485 | } | 
| 486 | 486 | |
| 487 | -        foreach ( array( '', 'js', 'css' ) as $dir ) { | |
| 488 | -            if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) { | |
| 487 | +        foreach (array('', 'js', 'css') as $dir) { | |
| 488 | +            if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) { | |
| 489 | 489 | return false; | 
| 490 | 490 | } | 
| 491 | 491 | } | 
| 492 | 492 | |
| 493 | 493 | // Using .htaccess inside our cache folder to overrule wp-super-cache. | 
| 494 | - $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess'; | |
| 495 | -        if ( ! is_file( $htaccess ) ) { | |
| 494 | + $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess'; | |
| 495 | +        if (!is_file($htaccess)) { | |
| 496 | 496 | /** | 
| 497 | 497 | * Create `wp-content/AO_htaccess_tmpl` file with | 
| 498 | 498 | * whatever htaccess rules you might need | 
| 499 | 499 | * if you want to override default AO htaccess | 
| 500 | 500 | */ | 
| 501 | - $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl'; | |
| 502 | -            if ( is_file( $htaccess_tmpl ) ) { | |
| 503 | - $content = file_get_contents( $htaccess_tmpl ); | |
| 504 | -            } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) { | |
| 501 | + $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl'; | |
| 502 | +            if (is_file($htaccess_tmpl)) { | |
| 503 | + $content = file_get_contents($htaccess_tmpl); | |
| 504 | +            } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) { | |
| 505 | 505 | $content = '<IfModule mod_expires.c> | 
| 506 | 506 | ExpiresActive On | 
| 507 | 507 | ExpiresByType text/css A30672000 | 
| @@ -554,7 +554,7 @@ discard block | ||
| 554 | 554 | </Files> | 
| 555 | 555 | </IfModule>'; | 
| 556 | 556 | } | 
| 557 | - @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine | |
| 557 | + @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine | |
| 558 | 558 | } | 
| 559 | 559 | |
| 560 | 560 | // All OK! | 
| @@ -569,25 +569,25 @@ discard block | ||
| 569 | 569 | * | 
| 570 | 570 | * @return bool | 
| 571 | 571 | */ | 
| 572 | - protected static function check_cache_dir( $dir ) | |
| 572 | + protected static function check_cache_dir($dir) | |
| 573 | 573 |      { | 
| 574 | 574 | // Try creating the dir if it doesn't exist. | 
| 575 | -        if ( ! file_exists( $dir ) ) { | |
| 576 | - @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine | |
| 577 | -            if ( ! file_exists( $dir ) ) { | |
| 575 | +        if (!file_exists($dir)) { | |
| 576 | + @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine | |
| 577 | +            if (!file_exists($dir)) { | |
| 578 | 578 | return false; | 
| 579 | 579 | } | 
| 580 | 580 | } | 
| 581 | 581 | |
| 582 | 582 | // If we still cannot write, bail. | 
| 583 | -        if ( ! is_writable( $dir ) ) { | |
| 583 | +        if (!is_writable($dir)) { | |
| 584 | 584 | return false; | 
| 585 | 585 | } | 
| 586 | 586 | |
| 587 | 587 | // Create an index.html in there to avoid prying eyes! | 
| 588 | - $idx_file = rtrim( $dir, '/\\' ) . '/index.html'; | |
| 589 | -        if ( ! is_file( $idx_file ) ) { | |
| 590 | - @file_put_contents( $idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); // @codingStandardsIgnoreLine | |
| 588 | + $idx_file = rtrim($dir, '/\\').'/index.html'; | |
| 589 | +        if (!is_file($idx_file)) { | |
| 590 | + @file_put_contents($idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>'); // @codingStandardsIgnoreLine | |
| 591 | 591 | } | 
| 592 | 592 | |
| 593 | 593 | return true; | 
| @@ -601,59 +601,59 @@ discard block | ||
| 601 | 601 | // @codingStandardsIgnoreStart | 
| 602 | 602 | public static function flushPageCache() | 
| 603 | 603 |      { | 
| 604 | -        if ( function_exists( 'wp_cache_clear_cache' ) ) { | |
| 605 | -            if ( is_multisite() ) { | |
| 604 | +        if (function_exists('wp_cache_clear_cache')) { | |
| 605 | +            if (is_multisite()) { | |
| 606 | 606 | $blog_id = get_current_blog_id(); | 
| 607 | - wp_cache_clear_cache( $blog_id ); | |
| 607 | + wp_cache_clear_cache($blog_id); | |
| 608 | 608 |              } else { | 
| 609 | 609 | wp_cache_clear_cache(); | 
| 610 | 610 | } | 
| 611 | -        } elseif ( has_action( 'cachify_flush_cache' ) ) { | |
| 612 | - do_action( 'cachify_flush_cache' ); | |
| 613 | -        } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) { | |
| 611 | +        } elseif (has_action('cachify_flush_cache')) { | |
| 612 | +            do_action('cachify_flush_cache'); | |
| 613 | +        } elseif (function_exists('w3tc_pgcache_flush')) { | |
| 614 | 614 | w3tc_pgcache_flush(); | 
| 615 | -        } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) { | |
| 615 | +        } elseif (function_exists('wp_fast_cache_bulk_delete_all')) { | |
| 616 | 616 | wp_fast_cache_bulk_delete_all(); | 
| 617 | -        } elseif ( class_exists( 'WpFastestCache' ) ) { | |
| 617 | +        } elseif (class_exists('WpFastestCache')) { | |
| 618 | 618 | $wpfc = new WpFastestCache(); | 
| 619 | 619 | $wpfc->deleteCache(); | 
| 620 | -        } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) { | |
| 620 | +        } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) { | |
| 621 | 621 | c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache | 
| 622 | -        } elseif ( class_exists( 'zencache' ) ) { | |
| 622 | +        } elseif (class_exists('zencache')) { | |
| 623 | 623 | zencache::clear(); | 
| 624 | -        } elseif ( class_exists( 'comet_cache' ) ) { | |
| 624 | +        } elseif (class_exists('comet_cache')) { | |
| 625 | 625 | comet_cache::clear(); | 
| 626 | -        } elseif ( class_exists( 'WpeCommon' ) ) { | |
| 626 | +        } elseif (class_exists('WpeCommon')) { | |
| 627 | 627 | // WPEngine cache purge/flush methods to call by default | 
| 628 | 628 | $wpe_methods = array( | 
| 629 | 629 | 'purge_varnish_cache', | 
| 630 | 630 | ); | 
| 631 | 631 | |
| 632 | 632 | // More agressive clear/flush/purge behind a filter | 
| 633 | -            if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) { | |
| 634 | - $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) ); | |
| 633 | +            if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) { | |
| 634 | +                $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache')); | |
| 635 | 635 | } | 
| 636 | 636 | |
| 637 | 637 | // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing) | 
| 638 | - $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods ); | |
| 638 | +            $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods); | |
| 639 | 639 | |
| 640 | -            foreach ( $wpe_methods as $wpe_method ) { | |
| 641 | -                if ( method_exists( 'WpeCommon', $wpe_method ) ) { | |
| 640 | +            foreach ($wpe_methods as $wpe_method) { | |
| 641 | +                if (method_exists('WpeCommon', $wpe_method)) { | |
| 642 | 642 | WpeCommon::$wpe_method(); | 
| 643 | 643 | } | 
| 644 | 644 | } | 
| 645 | -        } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) { | |
| 645 | +        } elseif (function_exists('sg_cachepress_purge_cache')) { | |
| 646 | 646 | sg_cachepress_purge_cache(); | 
| 647 | -        } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) { | |
| 647 | +        } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) { | |
| 648 | 648 | // fallback for WP-Super-Cache | 
| 649 | 649 | global $cache_path; | 
| 650 | -            if ( is_multisite() ) { | |
| 650 | +            if (is_multisite()) { | |
| 651 | 651 | $blog_id = get_current_blog_id(); | 
| 652 | - prune_super_cache( get_supercache_dir( $blog_id ), true ); | |
| 653 | - prune_super_cache( $cache_path . 'blogs/', true ); | |
| 652 | + prune_super_cache(get_supercache_dir($blog_id), true); | |
| 653 | + prune_super_cache($cache_path.'blogs/', true); | |
| 654 | 654 |              } else { | 
| 655 | - prune_super_cache( $cache_path . 'supercache/', true ); | |
| 656 | - prune_super_cache( $cache_path, true ); | |
| 655 | + prune_super_cache($cache_path.'supercache/', true); | |
| 656 | + prune_super_cache($cache_path, true); | |
| 657 | 657 | } | 
| 658 | 658 | } | 
| 659 | 659 | } | 
| @@ -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 | } | 
| @@ -3,7 +3,7 @@ discard block | ||
| 3 | 3 | * Handles version updates and should only be instantiated in autoptimize.php if/when needed. | 
| 4 | 4 | */ | 
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | +if (!defined('ABSPATH')) { | |
| 7 | 7 | exit; | 
| 8 | 8 | } | 
| 9 | 9 | |
| @@ -16,9 +16,9 @@ discard block | ||
| 16 | 16 | */ | 
| 17 | 17 | protected $current_major_version = null; | 
| 18 | 18 | |
| 19 | - public function __construct( $current_version ) | |
| 19 | + public function __construct($current_version) | |
| 20 | 20 |      { | 
| 21 | - $this->current_major_version = substr( $current_version, 0, 3 ); | |
| 21 | + $this->current_major_version = substr($current_version, 0, 3); | |
| 22 | 22 | } | 
| 23 | 23 | |
| 24 | 24 | /** | 
| @@ -29,7 +29,7 @@ discard block | ||
| 29 | 29 |      { | 
| 30 | 30 | $major_update = false; | 
| 31 | 31 | |
| 32 | -        switch ( $this->current_major_version ) { | |
| 32 | +        switch ($this->current_major_version) { | |
| 33 | 33 | case '1.6': | 
| 34 | 34 | $this->upgrade_from_1_6(); | 
| 35 | 35 | $major_update = true; | 
| @@ -48,7 +48,7 @@ discard block | ||
| 48 | 48 | // No break, intentionally, so all upgrades are ran during a single request... | 
| 49 | 49 | } | 
| 50 | 50 | |
| 51 | -        if ( true === $major_update ) { | |
| 51 | +        if (true === $major_update) { | |
| 52 | 52 | $this->on_major_version_update(); | 
| 53 | 53 | } | 
| 54 | 54 | } | 
| @@ -60,19 +60,19 @@ discard block | ||
| 60 | 60 | * | 
| 61 | 61 | * @param string $target Target version to check against (ie., the currently running one). | 
| 62 | 62 | */ | 
| 63 | - public static function check_installed_and_update( $target ) | |
| 63 | + public static function check_installed_and_update($target) | |
| 64 | 64 |      { | 
| 65 | - $db_version = get_option( 'autoptimize_version', 'none' ); | |
| 66 | -        if ( $db_version !== $target ) { | |
| 67 | -            if ( 'none' === $db_version ) { | |
| 68 | - add_action( 'admin_notices', 'autoptimizeMain::notice_installed' ); | |
| 65 | +        $db_version = get_option('autoptimize_version', 'none'); | |
| 66 | +        if ($db_version !== $target) { | |
| 67 | +            if ('none' === $db_version) { | |
| 68 | +                add_action('admin_notices', 'autoptimizeMain::notice_installed'); | |
| 69 | 69 |              } else { | 
| 70 | - $updater = new self( $db_version ); | |
| 70 | + $updater = new self($db_version); | |
| 71 | 71 | $updater->run_needed_major_upgrades(); | 
| 72 | 72 | } | 
| 73 | 73 | |
| 74 | 74 | // Versions differed, upgrades happened if needed, store the new version. | 
| 75 | - update_option( 'autoptimize_version', $target ); | |
| 75 | +            update_option('autoptimize_version', $target); | |
| 76 | 76 | } | 
| 77 | 77 | } | 
| 78 | 78 | |
| @@ -83,10 +83,10 @@ discard block | ||
| 83 | 83 | protected function on_major_version_update() | 
| 84 | 84 |      { | 
| 85 | 85 | // The transients guard here prevents stale object caches from busting the cache on every request. | 
| 86 | -        if ( false == get_transient( 'autoptimize_stale_option_buster' ) ) { | |
| 87 | - set_transient( 'autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS ); | |
| 86 | +        if (false == get_transient('autoptimize_stale_option_buster')) { | |
| 87 | +            set_transient('autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS); | |
| 88 | 88 | autoptimizeCache::clearall(); | 
| 89 | - add_action( 'admin_notices', 'autoptimizeMain::notice_updated' ); | |
| 89 | +            add_action('admin_notices', 'autoptimizeMain::notice_updated'); | |
| 90 | 90 | } | 
| 91 | 91 | } | 
| 92 | 92 | |
| @@ -96,7 +96,7 @@ discard block | ||
| 96 | 96 | private function upgrade_from_1_6() | 
| 97 | 97 |      { | 
| 98 | 98 | // If user was on version 1.6.x, force advanced options to be shown by default. | 
| 99 | - update_option( 'autoptimize_show_adv', '1' ); | |
| 99 | +        update_option('autoptimize_show_adv', '1'); | |
| 100 | 100 | |
| 101 | 101 | // And remove old options. | 
| 102 | 102 | $to_delete_options = array( | 
| @@ -108,8 +108,8 @@ discard block | ||
| 108 | 108 | 'autoptimize_cdn_img_url', | 
| 109 | 109 | 'autoptimize_css_yui', | 
| 110 | 110 | ); | 
| 111 | -        foreach ( $to_delete_options as $del_opt ) { | |
| 112 | - delete_option( $del_opt ); | |
| 111 | +        foreach ($to_delete_options as $del_opt) { | |
| 112 | + delete_option($del_opt); | |
| 113 | 113 | } | 
| 114 | 114 | } | 
| 115 | 115 | |
| @@ -120,29 +120,29 @@ discard block | ||
| 120 | 120 | */ | 
| 121 | 121 | private function upgrade_from_1_7() | 
| 122 | 122 |      { | 
| 123 | -        if ( ! is_multisite() ) { | |
| 124 | - $css_exclude = get_option( 'autoptimize_css_exclude' ); | |
| 125 | -            if ( empty( $css_exclude ) ) { | |
| 123 | +        if (!is_multisite()) { | |
| 124 | +            $css_exclude = get_option('autoptimize_css_exclude'); | |
| 125 | +            if (empty($css_exclude)) { | |
| 126 | 126 | $css_exclude = 'admin-bar.min.css, dashicons.min.css'; | 
| 127 | -            } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) { | |
| 127 | +            } elseif (false === strpos($css_exclude, 'dashicons.min.css')) { | |
| 128 | 128 | $css_exclude .= ', dashicons.min.css'; | 
| 129 | 129 | } | 
| 130 | - update_option( 'autoptimize_css_exclude', $css_exclude ); | |
| 130 | +            update_option('autoptimize_css_exclude', $css_exclude); | |
| 131 | 131 |          } else { | 
| 132 | 132 | global $wpdb; | 
| 133 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
| 133 | +            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); | |
| 134 | 134 | $original_blog_id = get_current_blog_id(); | 
| 135 | -            foreach ( $blog_ids as $blog_id ) { | |
| 136 | - switch_to_blog( $blog_id ); | |
| 137 | - $css_exclude = get_option( 'autoptimize_css_exclude' ); | |
| 138 | -                if ( empty( $css_exclude ) ) { | |
| 135 | +            foreach ($blog_ids as $blog_id) { | |
| 136 | + switch_to_blog($blog_id); | |
| 137 | +                $css_exclude = get_option('autoptimize_css_exclude'); | |
| 138 | +                if (empty($css_exclude)) { | |
| 139 | 139 | $css_exclude = 'admin-bar.min.css, dashicons.min.css'; | 
| 140 | -                } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) { | |
| 140 | +                } elseif (false === strpos($css_exclude, 'dashicons.min.css')) { | |
| 141 | 141 | $css_exclude .= ', dashicons.min.css'; | 
| 142 | 142 | } | 
| 143 | - update_option( 'autoptimize_css_exclude', $css_exclude ); | |
| 143 | +                update_option('autoptimize_css_exclude', $css_exclude); | |
| 144 | 144 | } | 
| 145 | - switch_to_blog( $original_blog_id ); | |
| 145 | + switch_to_blog($original_blog_id); | |
| 146 | 146 | } | 
| 147 | 147 | } | 
| 148 | 148 | |
| @@ -154,19 +154,19 @@ discard block | ||
| 154 | 154 | */ | 
| 155 | 155 | private function upgrade_from_1_9() | 
| 156 | 156 |      { | 
| 157 | -        if ( ! is_multisite() ) { | |
| 158 | - update_option( 'autoptimize_css_include_inline', 'on' ); | |
| 159 | - update_option( 'autoptimize_js_include_inline', 'on' ); | |
| 157 | +        if (!is_multisite()) { | |
| 158 | +            update_option('autoptimize_css_include_inline', 'on'); | |
| 159 | +            update_option('autoptimize_js_include_inline', 'on'); | |
| 160 | 160 |          } else { | 
| 161 | 161 | global $wpdb; | 
| 162 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
| 162 | +            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); | |
| 163 | 163 | $original_blog_id = get_current_blog_id(); | 
| 164 | -            foreach ( $blog_ids as $blog_id ) { | |
| 165 | - switch_to_blog( $blog_id ); | |
| 166 | - update_option( 'autoptimize_css_include_inline', 'on' ); | |
| 167 | - update_option( 'autoptimize_js_include_inline', 'on' ); | |
| 164 | +            foreach ($blog_ids as $blog_id) { | |
| 165 | + switch_to_blog($blog_id); | |
| 166 | +                update_option('autoptimize_css_include_inline', 'on'); | |
| 167 | +                update_option('autoptimize_js_include_inline', 'on'); | |
| 168 | 168 | } | 
| 169 | - switch_to_blog( $original_blog_id ); | |
| 169 | + switch_to_blog($original_blog_id); | |
| 170 | 170 | } | 
| 171 | 171 | } | 
| 172 | 172 | |
| @@ -177,17 +177,17 @@ discard block | ||
| 177 | 177 | */ | 
| 178 | 178 | private function upgrade_from_2_2() | 
| 179 | 179 |      { | 
| 180 | -        if ( ! is_multisite() ) { | |
| 180 | +        if (!is_multisite()) { | |
| 181 | 181 | $this->do_2_2_settings_update(); | 
| 182 | 182 |          } else { | 
| 183 | 183 | global $wpdb; | 
| 184 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
| 184 | +            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); | |
| 185 | 185 | $original_blog_id = get_current_blog_id(); | 
| 186 | -            foreach ( $blog_ids as $blog_id ) { | |
| 187 | - switch_to_blog( $blog_id ); | |
| 186 | +            foreach ($blog_ids as $blog_id) { | |
| 187 | + switch_to_blog($blog_id); | |
| 188 | 188 | $this->do_2_2_settings_update(); | 
| 189 | 189 | } | 
| 190 | - switch_to_blog( $original_blog_id ); | |
| 190 | + switch_to_blog($original_blog_id); | |
| 191 | 191 | } | 
| 192 | 192 | } | 
| 193 | 193 | |
| @@ -196,11 +196,11 @@ discard block | ||
| 196 | 196 | */ | 
| 197 | 197 | private function do_2_2_settings_update() | 
| 198 | 198 |      { | 
| 199 | - $nogooglefont = get_option( 'autoptimize_css_nogooglefont', '' ); | |
| 200 | - $ao_extrasetting = get_option( 'autoptimize_extra_settings', '' ); | |
| 201 | -        if ( ( $nogooglefont ) && ( empty( $ao_extrasetting ) ) ) { | |
| 202 | - update_option( 'autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options() ); | |
| 199 | +        $nogooglefont    = get_option('autoptimize_css_nogooglefont', ''); | |
| 200 | +        $ao_extrasetting = get_option('autoptimize_extra_settings', ''); | |
| 201 | +        if (($nogooglefont) && (empty($ao_extrasetting))) { | |
| 202 | +            update_option('autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options()); | |
| 203 | 203 | } | 
| 204 | - delete_option( 'autoptimize_css_nogooglefont' ); | |
| 204 | +        delete_option('autoptimize_css_nogooglefont'); | |
| 205 | 205 | } | 
| 206 | 206 | } |