@@ -123,6 +123,10 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // hide everything between noptimize-comment tags |
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param string $noptimize_in |
|
| 129 | + */ |
|
| 126 | 130 | protected function hide_noptimize($noptimize_in) { |
| 127 | 131 | if ( preg_match( '/<!--\s?noptimize\s?-->/', $noptimize_in ) ) { |
| 128 | 132 | $noptimize_out = preg_replace_callback( |
@@ -251,6 +255,9 @@ discard block |
||
| 251 | 255 | return $url; |
| 252 | 256 | } |
| 253 | 257 | |
| 258 | + /** |
|
| 259 | + * @param string $payload |
|
| 260 | + */ |
|
| 254 | 261 | protected function inject_in_html($payload,$replaceTag) { |
| 255 | 262 | if (strpos($this->content,$replaceTag[0])!== false) { |
| 256 | 263 | if ($replaceTag[1]==="after") { |
@@ -270,6 +277,9 @@ discard block |
||
| 270 | 277 | } |
| 271 | 278 | } |
| 272 | 279 | |
| 280 | + /** |
|
| 281 | + * @param string $tag |
|
| 282 | + */ |
|
| 273 | 283 | protected function isremovable($tag, $removables) { |
| 274 | 284 | foreach ($removables as $match) { |
| 275 | 285 | if (strpos($tag,$match)!==false) { |
@@ -280,6 +290,10 @@ discard block |
||
| 280 | 290 | } |
| 281 | 291 | |
| 282 | 292 | // inject already minified code in optimized JS/CSS |
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @return string |
|
| 296 | + */ |
|
| 283 | 297 | protected function inject_minified($in) { |
| 284 | 298 | if ( strpos( $in, '%%INJECTLATER%%' ) !== false ) { |
| 285 | 299 | $out = preg_replace_callback( |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | abstract class autoptimizeBase { |
| 5 | 8 | protected $content = ''; |
@@ -106,7 +109,9 @@ discard block |
||
| 106 | 109 | $out = parse_url($in,PHP_URL_HOST); |
| 107 | 110 | |
| 108 | 111 | // fallback if parse_url does not understand the url is in fact a url |
| 109 | - if (empty($out)) $out=$in; |
|
| 112 | + if (empty($out)) { |
|
| 113 | + $out=$in; |
|
| 114 | + } |
|
| 110 | 115 | |
| 111 | 116 | return $out; |
| 112 | 117 | } |
@@ -42,6 +42,9 @@ discard block |
||
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | + /** |
|
| 46 | + * @param string $mime |
|
| 47 | + */ |
|
| 45 | 48 | public function cache($code,$mime) { |
| 46 | 49 | if($this->nogzip == false) { |
| 47 | 50 | $file = ($this->delayed ? 'delayed.php' : 'default.php'); |
@@ -240,6 +243,9 @@ discard block |
||
| 240 | 243 | return true; |
| 241 | 244 | } |
| 242 | 245 | |
| 246 | + /** |
|
| 247 | + * @param string $dir |
|
| 248 | + */ |
|
| 243 | 249 | static function checkCacheDir($dir) { |
| 244 | 250 | // Check and create if not exists |
| 245 | 251 | if(!file_exists($dir)) { |
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | class autoptimizeCache { |
| 5 | 8 | private $filename; |
@@ -625,6 +625,9 @@ |
||
| 625 | 625 | return false; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | + /** |
|
| 629 | + * @param string $url |
|
| 630 | + */ |
|
| 628 | 631 | private function getFutttaFeeds($url) { |
| 629 | 632 | if (apply_filters('autoptimize_settingsscreen_remotehttp',true)) { |
| 630 | 633 | $rss = fetch_feed( $url ); |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | class autoptimizeConfig { |
| 5 | 8 | private $config = null; |
@@ -562,8 +565,9 @@ discard block |
||
| 562 | 565 | //Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/ |
| 563 | 566 | //Do it only once - saves time |
| 564 | 567 | static $plugin; |
| 565 | - if(empty($plugin)) |
|
| 566 | - $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php'); |
|
| 568 | + if(empty($plugin)) { |
|
| 569 | + $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php'); |
|
| 570 | + } |
|
| 567 | 571 | |
| 568 | 572 | if($file===null) { |
| 569 | 573 | //2.7 |
@@ -619,8 +623,9 @@ discard block |
||
| 619 | 623 | $this->config = $config; |
| 620 | 624 | } |
| 621 | 625 | |
| 622 | - if(isset($this->config[$key])) |
|
| 623 | - return $this->config[$key]; |
|
| 626 | + if(isset($this->config[$key])) { |
|
| 627 | + return $this->config[$key]; |
|
| 628 | + } |
|
| 624 | 629 | |
| 625 | 630 | return false; |
| 626 | 631 | } |
@@ -638,10 +643,13 @@ discard block |
||
| 638 | 643 | <ul> |
| 639 | 644 | <?php if ( $maxitems == 0 ) : ?> |
| 640 | 645 | <li><?php _e( 'No items', 'autoptimize' ); ?></li> |
| 641 | - <?php else : ?> |
|
| 646 | + <?php else { |
|
| 647 | + : ?> |
|
| 642 | 648 | <?php foreach ( $rss_items as $item ) : ?> |
| 643 | 649 | <li> |
| 644 | - <a href="<?php echo esc_url( $item->get_permalink() ); ?>" |
|
| 650 | + <a href="<?php echo esc_url( $item->get_permalink() ); |
|
| 651 | +} |
|
| 652 | +?>" |
|
| 645 | 653 | title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date('j F Y | g:i a') ); ?>"> |
| 646 | 654 | <?php echo esc_html( $item->get_title() ); ?> |
| 647 | 655 | </a> |
@@ -617,6 +617,9 @@ |
||
| 617 | 617 | return $code; |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | + /** |
|
| 621 | + * @param string $tag |
|
| 622 | + */ |
|
| 620 | 623 | private function ismovable($tag) {
|
| 621 | 624 | if (!empty($this->whitelist)) {
|
| 622 | 625 | foreach ($this->whitelist as $match) {
|
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | class autoptimizeStyles extends autoptimizeBase {
|
| 5 | 8 | private $css = array(); |
@@ -22,7 +25,9 @@ discard block |
||
| 22 | 25 | //Reads the page and collects style tags |
| 23 | 26 | public function read($options) {
|
| 24 | 27 | $noptimizeCSS = apply_filters( 'autoptimize_filter_css_noptimize', false, $this->content ); |
| 25 | - if ($noptimizeCSS) return false; |
|
| 28 | + if ($noptimizeCSS) { |
|
| 29 | + return false; |
|
| 30 | + } |
|
| 26 | 31 | |
| 27 | 32 | $whitelistCSS = apply_filters( 'autoptimize_filter_css_whitelist', '' ); |
| 28 | 33 | if (!empty($whitelistCSS)) {
|
@@ -136,7 +141,7 @@ discard block |
||
| 136 | 141 | if($path!==false && preg_match('#\.css$#',$path)) {
|
| 137 | 142 | // Good link |
| 138 | 143 | $this->css[] = array($media,$path); |
| 139 | - }else{
|
|
| 144 | + } else{
|
|
| 140 | 145 | // Link is dynamic (.php etc) |
| 141 | 146 | $tag = ''; |
| 142 | 147 | } |
@@ -199,8 +204,9 @@ discard block |
||
| 199 | 204 | } |
| 200 | 205 | |
| 201 | 206 | foreach($media as $elem) {
|
| 202 | - if(!isset($this->csscode[$elem])) |
|
| 203 | - $this->csscode[$elem] = ''; |
|
| 207 | + if(!isset($this->csscode[$elem])) { |
|
| 208 | + $this->csscode[$elem] = ''; |
|
| 209 | + } |
|
| 204 | 210 | $this->csscode[$elem] .= "\n/*FILESTART*/".$css; |
| 205 | 211 | } |
| 206 | 212 | } |
@@ -59,6 +59,9 @@ |
||
| 59 | 59 | |
| 60 | 60 | // -- Public Static Methods -------------------------------------------------- |
| 61 | 61 | |
| 62 | + /** |
|
| 63 | + * @param string $js |
|
| 64 | + */ |
|
| 62 | 65 | public static function minify($js) {
|
| 63 | 66 | $jsmin = new JSMin($js); |
| 64 | 67 | return $jsmin->min(); |
@@ -191,8 +191,7 @@ discard block |
||
| 191 | 191 | default: |
| 192 | 192 | if ($this->isAlphaNum($this->b)) {
|
| 193 | 193 | $this->action(1); |
| 194 | - } |
|
| 195 | - else {
|
|
| 194 | + } else {
|
|
| 196 | 195 | $this->action(2); |
| 197 | 196 | } |
| 198 | 197 | } |
@@ -224,8 +223,7 @@ discard block |
||
| 224 | 223 | default: |
| 225 | 224 | if ($this->isAlphaNum($this->a)) {
|
| 226 | 225 | $this->action(1); |
| 227 | - } |
|
| 228 | - else {
|
|
| 226 | + } else {
|
|
| 229 | 227 | $this->action(3); |
| 230 | 228 | } |
| 231 | 229 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | * |
| 54 | 54 | * @param array $options (currently ignored) |
| 55 | 55 | * |
| 56 | - * @return null |
|
| 56 | + * @return string |
|
| 57 | 57 | */ |
| 58 | 58 | private function __construct($options) { |
| 59 | 59 | $this->_options = $options; |
@@ -698,6 +698,11 @@ discard block |
||
| 698 | 698 | * --------------------------------------------------------------------------------------------- |
| 699 | 699 | */ |
| 700 | 700 | |
| 701 | + /** |
|
| 702 | + * @param double $v1 |
|
| 703 | + * @param double $v2 |
|
| 704 | + * @param integer $vh |
|
| 705 | + */ |
|
| 701 | 706 | private function hue_to_rgb($v1, $v2, $vh) |
| 702 | 707 | { |
| 703 | 708 | $vh = $vh < 0 ? $vh + 1 : ($vh > 1 ? $vh - 1 : $vh); |
@@ -712,6 +717,10 @@ discard block |
||
| 712 | 717 | return intval(floor(floatval($n) + 0.5), 10); |
| 713 | 718 | } |
| 714 | 719 | |
| 720 | + /** |
|
| 721 | + * @param integer $min |
|
| 722 | + * @param integer $max |
|
| 723 | + */ |
|
| 715 | 724 | private function clamp_number($n, $min, $max) |
| 716 | 725 | { |
| 717 | 726 | return min(max($n, $min), $max); |
@@ -740,7 +749,7 @@ discard block |
||
| 740 | 749 | * |
| 741 | 750 | * @param string $str |
| 742 | 751 | * @param int $start index |
| 743 | - * @param int|bool $end index (optional) |
|
| 752 | + * @param integer $end index (optional) |
|
| 744 | 753 | * @return string |
| 745 | 754 | */ |
| 746 | 755 | private function str_slice($str, $start = 0, $end = FALSE) |
@@ -689,9 +689,15 @@ |
||
| 689 | 689 | private function hue_to_rgb($v1, $v2, $vh) |
| 690 | 690 | { |
| 691 | 691 | $vh = $vh < 0 ? $vh + 1 : ($vh > 1 ? $vh - 1 : $vh); |
| 692 | - if ($vh * 6 < 1) return $v1 + ($v2 - $v1) * 6 * $vh; |
|
| 693 | - if ($vh * 2 < 1) return $v2; |
|
| 694 | - if ($vh * 3 < 2) return $v1 + ($v2 - $v1) * ((2/3) - $vh) * 6; |
|
| 692 | + if ($vh * 6 < 1) { |
|
| 693 | + return $v1 + ($v2 - $v1) * 6 * $vh; |
|
| 694 | + } |
|
| 695 | + if ($vh * 2 < 1) { |
|
| 696 | + return $v2; |
|
| 697 | + } |
|
| 698 | + if ($vh * 3 < 2) { |
|
| 699 | + return $v1 + ($v2 - $v1) * ((2/3) - $vh) * 6; |
|
| 700 | + } |
|
| 695 | 701 | return $v1; |
| 696 | 702 | } |
| 697 | 703 | |
@@ -1,10 +1,12 @@ discard block |
||
| 1 | 1 | <?php exit; |
| 2 | 2 | |
| 3 | 3 | //Check everything exists before using it |
| 4 | -if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
| 4 | +if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { |
|
| 5 | 5 | $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
| 6 | -if(!isset($_SERVER['HTTP_USER_AGENT'])) |
|
| 6 | +} |
|
| 7 | +if(!isset($_SERVER['HTTP_USER_AGENT'])) { |
|
| 7 | 8 | $_SERVER['HTTP_USER_AGENT'] = ''; |
| 9 | +} |
|
| 8 | 10 | |
| 9 | 11 | // Determine supported compression method |
| 10 | 12 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); |
@@ -19,16 +21,19 @@ discard block |
||
| 19 | 21 | { |
| 20 | 22 | $version = floatval($matches[1]); |
| 21 | 23 | |
| 22 | - if ($version < 6) |
|
| 23 | - $encoding = 'none'; |
|
| 24 | + if ($version < 6) { |
|
| 25 | + $encoding = 'none'; |
|
| 26 | + } |
|
| 24 | 27 | |
| 25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
| 26 | - $encoding = 'none'; |
|
| 27 | -} |
|
| 28 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) { |
|
| 29 | + $encoding = 'none'; |
|
| 30 | + } |
|
| 31 | + } |
|
| 28 | 32 | |
| 29 | 33 | //Some servers compress the output of PHP - Don't break in those cases |
| 30 | -if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
|
| 34 | +if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) { |
|
| 31 | 35 | $encoding = 'none'; |
| 36 | +} |
|
| 32 | 37 | |
| 33 | 38 | //Get data |
| 34 | 39 | $contents = file_get_contents(__FILE__.'.'.$encoding); |
@@ -1,10 +1,12 @@ discard block |
||
| 1 | 1 | <?php exit; |
| 2 | 2 | |
| 3 | 3 | //Check everything exists before using it |
| 4 | -if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
| 4 | +if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { |
|
| 5 | 5 | $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
| 6 | -if(!isset($_SERVER['HTTP_USER_AGENT'])) |
|
| 6 | +} |
|
| 7 | +if(!isset($_SERVER['HTTP_USER_AGENT'])) { |
|
| 7 | 8 | $_SERVER['HTTP_USER_AGENT'] = ''; |
| 9 | +} |
|
| 8 | 10 | |
| 9 | 11 | // Determine supported compression method |
| 10 | 12 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); |
@@ -19,16 +21,19 @@ discard block |
||
| 19 | 21 | { |
| 20 | 22 | $version = floatval($matches[1]); |
| 21 | 23 | |
| 22 | - if ($version < 6) |
|
| 23 | - $encoding = 'none'; |
|
| 24 | + if ($version < 6) { |
|
| 25 | + $encoding = 'none'; |
|
| 26 | + } |
|
| 24 | 27 | |
| 25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
| 26 | - $encoding = 'none'; |
|
| 27 | -} |
|
| 28 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) { |
|
| 29 | + $encoding = 'none'; |
|
| 30 | + } |
|
| 31 | + } |
|
| 28 | 32 | |
| 29 | 33 | //Some servers compress the output of PHP - Don't break in those cases |
| 30 | -if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
|
| 34 | +if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) { |
|
| 31 | 35 | $encoding = 'none'; |
| 36 | +} |
|
| 32 | 37 | |
| 33 | 38 | $iscompressed = file_exists(__FILE__.'.'.$encoding); |
| 34 | 39 | if($encoding != 'none' && $iscompressed == false) |
@@ -36,7 +41,7 @@ discard block |
||
| 36 | 41 | $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
| 37 | 42 | $code = file_get_contents(__FILE__.'.none'); |
| 38 | 43 | $contents = gzencode($code,9,$flag); |
| 39 | -}else{ |
|
| 44 | +} else{ |
|
| 40 | 45 | //Get data |
| 41 | 46 | $contents = file_get_contents(__FILE__.'.'.$encoding); |
| 42 | 47 | } |