@@ -16,66 +16,66 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | |
19 | -if ( ! defined( 'ABSPATH' ) ) { |
|
19 | +if (!defined('ABSPATH')) { |
|
20 | 20 | exit; |
21 | 21 | } |
22 | 22 | |
23 | -define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.4.0' ); |
|
23 | +define('AUTOPTIMIZE_PLUGIN_VERSION', '2.4.0'); |
|
24 | 24 | |
25 | 25 | // plugin_dir_path() returns the trailing slash! |
26 | -define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
|
27 | -define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ ); |
|
26 | +define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__)); |
|
27 | +define('AUTOPTIMIZE_PLUGIN_FILE', __FILE__); |
|
28 | 28 | |
29 | 29 | // Bail early if attempting to run on non-supported php versions. |
30 | -if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
|
30 | +if (version_compare(PHP_VERSION, '5.3', '<')) { |
|
31 | 31 | function autoptimize_incompatible_admin_notice() { |
32 | - echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.3 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize' ) . '</p></div>'; |
|
33 | - if ( isset( $_GET['activate'] ) ) { |
|
34 | - unset( $_GET['activate'] ); |
|
32 | + echo '<div class="error"><p>'.__('Autoptimize requires PHP 5.3 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize').'</p></div>'; |
|
33 | + if (isset($_GET['activate'])) { |
|
34 | + unset($_GET['activate']); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | function autoptimize_deactivate_self() { |
38 | - deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) ); |
|
38 | + deactivate_plugins(plugin_basename(AUTOPTIMIZE_PLUGIN_FILE)); |
|
39 | 39 | } |
40 | - add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' ); |
|
41 | - add_action( 'admin_init', 'autoptimize_deactivate_self' ); |
|
40 | + add_action('admin_notices', 'autoptimize_incompatible_admin_notice'); |
|
41 | + add_action('admin_init', 'autoptimize_deactivate_self'); |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | -function autoptimize_autoload( $class_name ) { |
|
46 | - if ( in_array( $class_name, array( 'Minify_HTML', 'JSMin' ) ) ) { |
|
47 | - $file = strtolower( $class_name ); |
|
48 | - $file = str_replace( '_', '-', $file ); |
|
49 | - $path = dirname( __FILE__ ) . '/classes/external/php/'; |
|
50 | - $filepath = $path . $file . '.php'; |
|
51 | - } elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) { |
|
52 | - $file = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name ); |
|
53 | - $path = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/'; |
|
54 | - $filepath = $path . $file . '.php'; |
|
55 | - } elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) { |
|
45 | +function autoptimize_autoload($class_name) { |
|
46 | + if (in_array($class_name, array('Minify_HTML', 'JSMin'))) { |
|
47 | + $file = strtolower($class_name); |
|
48 | + $file = str_replace('_', '-', $file); |
|
49 | + $path = dirname(__FILE__).'/classes/external/php/'; |
|
50 | + $filepath = $path.$file.'.php'; |
|
51 | + } elseif (false !== strpos($class_name, 'Autoptimize\\tubalmartin\\CssMin')) { |
|
52 | + $file = str_replace('Autoptimize\\tubalmartin\\CssMin\\', '', $class_name); |
|
53 | + $path = dirname(__FILE__).'/classes/external/php/yui-php-cssmin-bundled/'; |
|
54 | + $filepath = $path.$file.'.php'; |
|
55 | + } elseif ('autoptimize' === substr($class_name, 0, 11)) { |
|
56 | 56 | // One of our "old" classes. |
57 | 57 | $file = $class_name; |
58 | - $path = dirname( __FILE__ ) . '/classes/'; |
|
59 | - $filepath = $path . $file . '.php'; |
|
60 | - } elseif ( 'PAnD' === $class_name ) { |
|
58 | + $path = dirname(__FILE__).'/classes/'; |
|
59 | + $filepath = $path.$file.'.php'; |
|
60 | + } elseif ('PAnD' === $class_name) { |
|
61 | 61 | $file = 'persist-admin-notices-dismissal'; |
62 | - $path = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/'; |
|
63 | - $filepath = $path . $file . '.php'; |
|
62 | + $path = dirname(__FILE__).'/classes/external/php/persist-admin-notices-dismissal/'; |
|
63 | + $filepath = $path.$file.'.php'; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // If we didn't match one of our rules, bail! |
67 | - if ( ! isset( $filepath ) ) { |
|
67 | + if (!isset($filepath)) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | 71 | require $filepath; |
72 | 72 | } |
73 | 73 | |
74 | -spl_autoload_register( 'autoptimize_autoload' ); |
|
74 | +spl_autoload_register('autoptimize_autoload'); |
|
75 | 75 | |
76 | 76 | // Load WP CLI command(s) on demand. |
77 | -if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
78 | - require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php'; |
|
77 | +if (defined('WP_CLI') && WP_CLI) { |
|
78 | + require AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php'; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | function autoptimize() { |
87 | 87 | static $plugin = null; |
88 | 88 | |
89 | - if ( null === $plugin ) { |
|
90 | - $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE ); |
|
89 | + if (null === $plugin) { |
|
90 | + $plugin = new autoptimizeMain(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $plugin; |
@@ -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 | } |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * Exit if called directly. |
30 | 30 | */ |
31 | -if ( ! defined( 'ABSPATH' ) ) { |
|
31 | +if (!defined('ABSPATH')) { |
|
32 | 32 | die; |
33 | 33 | } |
34 | 34 | |
35 | -if ( ! class_exists( 'PAnD' ) ) { |
|
35 | +if (!class_exists('PAnD')) { |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Class PAnD |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * Init hooks. |
44 | 44 | */ |
45 | 45 | public static function init() { |
46 | - add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) ); |
|
47 | - add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) ); |
|
46 | + add_action('admin_enqueue_scripts', array(__CLASS__, 'load_script')); |
|
47 | + add_action('wp_ajax_dismiss_admin_notice', array(__CLASS__, 'dismiss_admin_notice')); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public static function load_script() { |
54 | 54 | |
55 | - if(is_customize_preview()) return; |
|
55 | + if (is_customize_preview()) return; |
|
56 | 56 | |
57 | 57 | wp_enqueue_script( |
58 | 58 | 'dismissible-notices', |
59 | - plugins_url( 'dismiss-notice.js', __FILE__ ), |
|
60 | - array( 'jquery', 'common' ), |
|
59 | + plugins_url('dismiss-notice.js', __FILE__), |
|
60 | + array('jquery', 'common'), |
|
61 | 61 | false, |
62 | 62 | true |
63 | 63 | ); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | 'dismissible-notices', |
67 | 67 | 'dismissible_notice', |
68 | 68 | array( |
69 | - 'nonce' => wp_create_nonce( 'dismissible-notice' ), |
|
69 | + 'nonce' => wp_create_nonce('dismissible-notice'), |
|
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | } |
@@ -76,19 +76,19 @@ discard block |
||
76 | 76 | * Uses check_ajax_referer to verify nonce. |
77 | 77 | */ |
78 | 78 | public static function dismiss_admin_notice() { |
79 | - $option_name = sanitize_text_field( $_POST['option_name'] ); |
|
80 | - $dismissible_length = sanitize_text_field( $_POST['dismissible_length'] ); |
|
79 | + $option_name = sanitize_text_field($_POST['option_name']); |
|
80 | + $dismissible_length = sanitize_text_field($_POST['dismissible_length']); |
|
81 | 81 | $transient = 0; |
82 | 82 | |
83 | - if ( 'forever' != $dismissible_length ) { |
|
83 | + if ('forever' != $dismissible_length) { |
|
84 | 84 | // If $dismissible_length is not an integer default to 1 |
85 | - $dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length; |
|
86 | - $transient = absint( $dismissible_length ) * DAY_IN_SECONDS; |
|
87 | - $dismissible_length = strtotime( absint( $dismissible_length ) . ' days' ); |
|
85 | + $dismissible_length = (0 == absint($dismissible_length)) ? 1 : $dismissible_length; |
|
86 | + $transient = absint($dismissible_length)*DAY_IN_SECONDS; |
|
87 | + $dismissible_length = strtotime(absint($dismissible_length).' days'); |
|
88 | 88 | } |
89 | 89 | |
90 | - check_ajax_referer( 'dismissible-notice', 'nonce' ); |
|
91 | - set_site_transient( $option_name, $dismissible_length, $transient ); |
|
90 | + check_ajax_referer('dismissible-notice', 'nonce'); |
|
91 | + set_site_transient($option_name, $dismissible_length, $transient); |
|
92 | 92 | wp_die(); |
93 | 93 | } |
94 | 94 | |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return bool |
101 | 101 | */ |
102 | - public static function is_admin_notice_active( $arg ) { |
|
103 | - $array = explode( '-', $arg ); |
|
104 | - $length = array_pop( $array ); |
|
105 | - $option_name = implode( '-', $array ); |
|
106 | - $db_record = get_site_transient( $option_name ); |
|
102 | + public static function is_admin_notice_active($arg) { |
|
103 | + $array = explode('-', $arg); |
|
104 | + $length = array_pop($array); |
|
105 | + $option_name = implode('-', $array); |
|
106 | + $db_record = get_site_transient($option_name); |
|
107 | 107 | |
108 | - if ( 'forever' == $db_record ) { |
|
108 | + if ('forever' == $db_record) { |
|
109 | 109 | return false; |
110 | - } elseif ( absint( $db_record ) >= time() ) { |
|
110 | + } elseif (absint($db_record) >= time()) { |
|
111 | 111 | return false; |
112 | 112 | } else { |
113 | 113 | return true; |
@@ -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 | protected $inputLength = 0; |
71 | 71 | protected $lookAhead = null; |
72 | 72 | protected $output = ''; |
73 | - protected $lastByteOut = ''; |
|
73 | + protected $lastByteOut = ''; |
|
74 | 74 | protected $keptComment = ''; |
75 | 75 | |
76 | 76 | /** |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | $mbIntEnc = null; |
109 | - if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { |
|
109 | + if (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload') & 2)) { |
|
110 | 110 | $mbIntEnc = mb_internal_encoding(); |
111 | 111 | mb_internal_encoding('8bit'); |
112 | 112 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | && ($this->b === $this->lastByteOut)) { |
129 | 129 | // Don't delete this space. If we do, the addition/subtraction |
130 | 130 | // could be parsed as a post-increment |
131 | - } elseif (! $this->isAlphaNum($this->b)) { |
|
131 | + } elseif (!$this->isAlphaNum($this->b)) { |
|
132 | 132 | $command = self::ACTION_DELETE_A; |
133 | 133 | } |
134 | 134 | } elseif ($this->a === "\n") { |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | // otherwise mb_strpos will give WARNING |
140 | 140 | } elseif ($this->b === null |
141 | 141 | || (false === strpos('{[(+-!~', $this->b) |
142 | - && ! $this->isAlphaNum($this->b))) { |
|
142 | + && !$this->isAlphaNum($this->b))) { |
|
143 | 143 | $command = self::ACTION_DELETE_A; |
144 | 144 | } |
145 | - } elseif (! $this->isAlphaNum($this->a)) { |
|
145 | + } elseif (!$this->isAlphaNum($this->a)) { |
|
146 | 146 | if ($this->b === ' ' |
147 | 147 | || ($this->b === "\n" |
148 | 148 | && (false === strpos('}])+-"\'', $this->a)))) { |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $this->a = $this->b; |
199 | 199 | if ($this->a === "'" || $this->a === '"') { // string literal |
200 | 200 | $str = $this->a; // in case needed for exception |
201 | - for(;;) { |
|
201 | + for (;;) { |
|
202 | 202 | $this->output .= $this->a; |
203 | 203 | $this->lastByteOut = $this->a; |
204 | 204 | |
@@ -226,13 +226,13 @@ discard block |
||
226 | 226 | case self::ACTION_DELETE_A_B: // 3 |
227 | 227 | $this->b = $this->next(); |
228 | 228 | if ($this->b === '/' && $this->isRegexpLiteral()) { |
229 | - $this->output .= $this->a . $this->b; |
|
229 | + $this->output .= $this->a.$this->b; |
|
230 | 230 | $pattern = '/'; // keep entire pattern in case we need to report it in the exception |
231 | - for(;;) { |
|
231 | + for (;;) { |
|
232 | 232 | $this->a = $this->get(); |
233 | 233 | $pattern .= $this->a; |
234 | 234 | if ($this->a === '[') { |
235 | - for(;;) { |
|
235 | + for (;;) { |
|
236 | 236 | $this->output .= $this->a; |
237 | 237 | $this->a = $this->get(); |
238 | 238 | $pattern .= $this->a; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | if ($this->isEOF($this->a)) { |
248 | 248 | throw new JSMin_UnterminatedRegExpException( |
249 | 249 | "JSMin: Unterminated set in RegExp at byte " |
250 | - . $this->inputIndex .": {$pattern}"); |
|
250 | + . $this->inputIndex.": {$pattern}"); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | |
293 | 293 | // if the "/" follows a keyword, it must be a regexp, otherwise it's best to assume division |
294 | 294 | |
295 | - $subject = $this->output . trim($this->a); |
|
295 | + $subject = $this->output.trim($this->a); |
|
296 | 296 | if (!preg_match('/(?:case|else|in|return|typeof)$/', $subject, $m)) { |
297 | 297 | // not a keyword |
298 | 298 | return false; |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | { |
404 | 404 | $this->get(); |
405 | 405 | $comment = ''; |
406 | - for(;;) { |
|
406 | + for (;;) { |
|
407 | 407 | $get = $this->get(); |
408 | 408 | if ($get === '*') { |
409 | 409 | if ($this->peek() === '/') { // end of comment reached |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | // don't prepend a newline if two comments right after one another |
415 | 415 | $this->keptComment = "\n"; |
416 | 416 | } |
417 | - $this->keptComment .= "/*!" . substr($comment, 1) . "*/\n"; |
|
417 | + $this->keptComment .= "/*!".substr($comment, 1)."*/\n"; |
|
418 | 418 | } else if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) { |
419 | 419 | // IE conditional |
420 | 420 | $this->keptComment .= "/*{$comment}*/"; |
@@ -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 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
@@ -13,18 +13,18 @@ discard block |
||
13 | 13 | ); |
14 | 14 | |
15 | 15 | private $dontmove = array( |
16 | - 'document.write','html5.js','show_ads.js','google_ad','histats.com/js','statcounter.com/counter/counter.js', |
|
17 | - 'ws.amazon.com/widgets','media.fastclick.net','/ads/','comment-form-quicktags/quicktags.php','edToolbar', |
|
18 | - 'intensedebate.com','scripts.chitika.net/','_gaq.push','jotform.com/','admin-bar.min.js','GoogleAnalyticsObject', |
|
19 | - 'plupload.full.min.js','syntaxhighlighter','adsbygoogle','gist.github.com','_stq','nonce','post_id','data-noptimize' |
|
16 | + 'document.write', 'html5.js', 'show_ads.js', 'google_ad', 'histats.com/js', 'statcounter.com/counter/counter.js', |
|
17 | + 'ws.amazon.com/widgets', 'media.fastclick.net', '/ads/', 'comment-form-quicktags/quicktags.php', 'edToolbar', |
|
18 | + 'intensedebate.com', 'scripts.chitika.net/', '_gaq.push', 'jotform.com/', 'admin-bar.min.js', 'GoogleAnalyticsObject', |
|
19 | + 'plupload.full.min.js', 'syntaxhighlighter', 'adsbygoogle', 'gist.github.com', '_stq', 'nonce', 'post_id', 'data-noptimize' |
|
20 | 20 | ,'logHuman' |
21 | 21 | ); |
22 | 22 | private $domove = array( |
23 | - 'gaJsHost','load_cmc','jd.gallery.transitions.js','swfobject.embedSWF(','tiny_mce.js','tinyMCEPreInit.go' |
|
23 | + 'gaJsHost', 'load_cmc', 'jd.gallery.transitions.js', 'swfobject.embedSWF(', 'tiny_mce.js', 'tinyMCEPreInit.go' |
|
24 | 24 | ); |
25 | 25 | private $domovelast = array( |
26 | - 'addthis.com','/afsonline/show_afs_search.js','disqus.js','networkedblogs.com/getnetworkwidget','infolinks.com/js/', |
|
27 | - 'jd.gallery.js.php','jd.gallery.transitions.js','swfobject.embedSWF(','linkwithin.com/widget.js','tiny_mce.js','tinyMCEPreInit.go' |
|
26 | + 'addthis.com', '/afsonline/show_afs_search.js', 'disqus.js', 'networkedblogs.com/getnetworkwidget', 'infolinks.com/js/', |
|
27 | + 'jd.gallery.js.php', 'jd.gallery.transitions.js', 'swfobject.embedSWF(', 'linkwithin.com/widget.js', 'tiny_mce.js', 'tinyMCEPreInit.go' |
|
28 | 28 | ); |
29 | 29 | |
30 | 30 | private $aggregate = true; |
@@ -43,84 +43,84 @@ discard block |
||
43 | 43 | // Reads the page and collects script tags |
44 | 44 | public function read($options) |
45 | 45 | { |
46 | - $noptimizeJS = apply_filters( 'autoptimize_filter_js_noptimize', false, $this->content ); |
|
47 | - if ( $noptimizeJS ) { |
|
46 | + $noptimizeJS = apply_filters('autoptimize_filter_js_noptimize', false, $this->content); |
|
47 | + if ($noptimizeJS) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
51 | 51 | // only optimize known good JS? |
52 | - $whitelistJS = apply_filters( 'autoptimize_filter_js_whitelist', '', $this->content ); |
|
53 | - if ( ! empty( $whitelistJS ) ) { |
|
54 | - $this->whitelist = array_filter( array_map( 'trim', explode( ',', $whitelistJS ) ) ); |
|
52 | + $whitelistJS = apply_filters('autoptimize_filter_js_whitelist', '', $this->content); |
|
53 | + if (!empty($whitelistJS)) { |
|
54 | + $this->whitelist = array_filter(array_map('trim', explode(',', $whitelistJS))); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | // is there JS we should simply remove |
58 | - $removableJS = apply_filters( 'autoptimize_filter_js_removables', '', $this->content ); |
|
58 | + $removableJS = apply_filters('autoptimize_filter_js_removables', '', $this->content); |
|
59 | 59 | if (!empty($removableJS)) { |
60 | - $this->jsremovables = array_filter( array_map( 'trim', explode( ',', $removableJS ) ) ); |
|
60 | + $this->jsremovables = array_filter(array_map('trim', explode(',', $removableJS))); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // only header? |
64 | - if ( apply_filters( 'autoptimize_filter_js_justhead', $options['justhead'] ) ) { |
|
65 | - $content = explode( '</head>', $this->content, 2 ); |
|
66 | - $this->content = $content[0] . '</head>'; |
|
64 | + if (apply_filters('autoptimize_filter_js_justhead', $options['justhead'])) { |
|
65 | + $content = explode('</head>', $this->content, 2); |
|
66 | + $this->content = $content[0].'</head>'; |
|
67 | 67 | $this->restofcontent = $content[1]; |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Determine whether we're doing JS-files aggregation or not. |
71 | - if ( ! $options['aggregate'] ) { |
|
71 | + if (!$options['aggregate']) { |
|
72 | 72 | $this->aggregate = false; |
73 | 73 | } |
74 | 74 | // Returning true for "dontaggregate" turns off aggregation. |
75 | - if ( $this->aggregate && apply_filters( 'autoptimize_filter_js_dontaggregate', false ) ) { |
|
75 | + if ($this->aggregate && apply_filters('autoptimize_filter_js_dontaggregate', false)) { |
|
76 | 76 | $this->aggregate = false; |
77 | 77 | } |
78 | 78 | |
79 | 79 | // include inline? |
80 | - if ( apply_filters( 'autoptimize_js_include_inline', $options['include_inline'] ) ) { |
|
80 | + if (apply_filters('autoptimize_js_include_inline', $options['include_inline'])) { |
|
81 | 81 | $this->include_inline = true; |
82 | 82 | } |
83 | 83 | |
84 | 84 | // filter to "late inject minified JS", default to true for now (it is faster) |
85 | - $this->inject_min_late = apply_filters( 'autoptimize_filter_js_inject_min_late', true ); |
|
85 | + $this->inject_min_late = apply_filters('autoptimize_filter_js_inject_min_late', true); |
|
86 | 86 | |
87 | 87 | // filters to override hardcoded do(nt)move(last) array contents (array in, array out!) |
88 | - $this->dontmove = apply_filters( 'autoptimize_filter_js_dontmove', $this->dontmove ); |
|
89 | - $this->domovelast = apply_filters( 'autoptimize_filter_js_movelast', $this->domovelast ); |
|
90 | - $this->domove = apply_filters( 'autoptimize_filter_js_domove', $this->domove ); |
|
88 | + $this->dontmove = apply_filters('autoptimize_filter_js_dontmove', $this->dontmove); |
|
89 | + $this->domovelast = apply_filters('autoptimize_filter_js_movelast', $this->domovelast); |
|
90 | + $this->domove = apply_filters('autoptimize_filter_js_domove', $this->domove); |
|
91 | 91 | |
92 | 92 | // get extra exclusions settings or filter |
93 | 93 | $excludeJS = $options['js_exclude']; |
94 | - $excludeJS = apply_filters( 'autoptimize_filter_js_exclude', $excludeJS, $this->content ); |
|
94 | + $excludeJS = apply_filters('autoptimize_filter_js_exclude', $excludeJS, $this->content); |
|
95 | 95 | |
96 | - if ( '' !== $excludeJS ) { |
|
97 | - if ( is_array( $excludeJS ) ) { |
|
98 | - if ( ( $removeKeys = array_keys( $excludeJS, 'remove' ) ) !== false ) { |
|
99 | - foreach ( $removeKeys as $removeKey ) { |
|
100 | - unset( $excludeJS[$removeKey] ); |
|
96 | + if ('' !== $excludeJS) { |
|
97 | + if (is_array($excludeJS)) { |
|
98 | + if (($removeKeys = array_keys($excludeJS, 'remove')) !== false) { |
|
99 | + foreach ($removeKeys as $removeKey) { |
|
100 | + unset($excludeJS[$removeKey]); |
|
101 | 101 | $this->jsremovables[] = $removeKey; |
102 | 102 | } |
103 | 103 | } |
104 | - $exclJSArr = array_keys( $excludeJS ); |
|
104 | + $exclJSArr = array_keys($excludeJS); |
|
105 | 105 | } else { |
106 | - $exclJSArr = array_filter( array_map( 'trim', explode( ',', $excludeJS ) ) ); |
|
106 | + $exclJSArr = array_filter(array_map('trim', explode(',', $excludeJS))); |
|
107 | 107 | } |
108 | - $this->dontmove = array_merge( $exclJSArr, $this->dontmove ); |
|
108 | + $this->dontmove = array_merge($exclJSArr, $this->dontmove); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Should we add try-catch? |
112 | - if ( $options['trycatch'] ) { |
|
112 | + if ($options['trycatch']) { |
|
113 | 113 | $this->trycatch = true; |
114 | 114 | } |
115 | 115 | |
116 | 116 | // force js in head? |
117 | - if ( $options['forcehead'] ) { |
|
117 | + if ($options['forcehead']) { |
|
118 | 118 | $this->forcehead = true; |
119 | 119 | } else { |
120 | 120 | $this->forcehead = false; |
121 | 121 | } |
122 | 122 | |
123 | - $this->forcehead = apply_filters( 'autoptimize_filter_js_forcehead', $this->forcehead ); |
|
123 | + $this->forcehead = apply_filters('autoptimize_filter_js_forcehead', $this->forcehead); |
|
124 | 124 | |
125 | 125 | // get cdn url |
126 | 126 | $this->cdn_url = $options['cdn_url']; |
@@ -135,26 +135,26 @@ discard block |
||
135 | 135 | $this->content = $this->hide_comments($this->content); |
136 | 136 | |
137 | 137 | // Get script files |
138 | - if ( preg_match_all( '#<script.*</script>#Usmi', $this->content, $matches ) ) { |
|
139 | - foreach( $matches[0] as $tag ) { |
|
138 | + if (preg_match_all('#<script.*</script>#Usmi', $this->content, $matches)) { |
|
139 | + foreach ($matches[0] as $tag) { |
|
140 | 140 | // only consider script aggregation for types whitelisted in should_aggregate-function |
141 | 141 | $should_aggregate = $this->should_aggregate($tag); |
142 | - if ( ! $should_aggregate ) { |
|
142 | + if (!$should_aggregate) { |
|
143 | 143 | $tag = ''; |
144 | 144 | continue; |
145 | 145 | } |
146 | 146 | |
147 | - if ( preg_match( '#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source ) ) { |
|
147 | + if (preg_match('#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source)) { |
|
148 | 148 | // non-inline script |
149 | - if ( $this->isremovable($tag, $this->jsremovables) ) { |
|
150 | - $this->content = str_replace( $tag, '', $this->content ); |
|
149 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
150 | + $this->content = str_replace($tag, '', $this->content); |
|
151 | 151 | continue; |
152 | 152 | } |
153 | 153 | |
154 | 154 | $origTag = null; |
155 | - $url = current( explode( '?', $source[2], 2 ) ); |
|
155 | + $url = current(explode('?', $source[2], 2)); |
|
156 | 156 | $path = $this->getpath($url); |
157 | - if ( false !== $path && preg_match( '#\.js$#', $path ) && $this->ismergeable($tag) ) { |
|
157 | + if (false !== $path && preg_match('#\.js$#', $path) && $this->ismergeable($tag)) { |
|
158 | 158 | // ok to optimize, add to array |
159 | 159 | $this->scripts[] = $path; |
160 | 160 | } else { |
@@ -162,40 +162,40 @@ discard block |
||
162 | 162 | $newTag = $tag; |
163 | 163 | |
164 | 164 | // non-mergeable script (excluded or dynamic or external) |
165 | - if ( is_array( $excludeJS ) ) { |
|
165 | + if (is_array($excludeJS)) { |
|
166 | 166 | // should we add flags? |
167 | - foreach ( $excludeJS as $exclTag => $exclFlags) { |
|
168 | - if ( false !== strpos( $origTag, $exclTag ) && in_array( $exclFlags, array( 'async', 'defer' ) ) ) { |
|
169 | - $newTag = str_replace( '<script ', '<script ' . $exclFlags . ' ', $newTag ); |
|
167 | + foreach ($excludeJS as $exclTag => $exclFlags) { |
|
168 | + if (false !== strpos($origTag, $exclTag) && in_array($exclFlags, array('async', 'defer'))) { |
|
169 | + $newTag = str_replace('<script ', '<script '.$exclFlags.' ', $newTag); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | 174 | // Should we minify the non-aggregated script? |
175 | - if ( $path && apply_filters( 'autoptimize_filter_js_minify_excluded', true, $url ) ) { |
|
176 | - $minified_url = $this->minify_single( $path ); |
|
175 | + if ($path && apply_filters('autoptimize_filter_js_minify_excluded', true, $url)) { |
|
176 | + $minified_url = $this->minify_single($path); |
|
177 | 177 | // replace orig URL with minified URL from cache if so |
178 | - if ( ! empty( $minified_url ) ) { |
|
179 | - $newTag = str_replace( $url, $minified_url, $newTag ); |
|
178 | + if (!empty($minified_url)) { |
|
179 | + $newTag = str_replace($url, $minified_url, $newTag); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // remove querystring from URL in newTag |
183 | - if ( ! empty( $explUrl[1] ) ) { |
|
184 | - $newTag = str_replace( '?' . $explUrl[1], '', $newTag ); |
|
183 | + if (!empty($explUrl[1])) { |
|
184 | + $newTag = str_replace('?'.$explUrl[1], '', $newTag); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - if ( $this->ismovable($newTag) ) { |
|
188 | + if ($this->ismovable($newTag)) { |
|
189 | 189 | // can be moved, flags and all |
190 | - if ( $this->movetolast($newTag) ) { |
|
190 | + if ($this->movetolast($newTag)) { |
|
191 | 191 | $this->move['last'][] = $newTag; |
192 | 192 | } else { |
193 | 193 | $this->move['first'][] = $newTag; |
194 | 194 | } |
195 | 195 | } else { |
196 | 196 | // cannot be moved, so if flag was added re-inject altered tag immediately |
197 | - if ( $origTag !== $newTag ) { |
|
198 | - $this->content = str_replace( $origTag, $newTag, $this->content ); |
|
197 | + if ($origTag !== $newTag) { |
|
198 | + $this->content = str_replace($origTag, $newTag, $this->content); |
|
199 | 199 | $origTag = ''; |
200 | 200 | } |
201 | 201 | // and forget about the $tag (not to be touched any more) |
@@ -204,23 +204,23 @@ discard block |
||
204 | 204 | } |
205 | 205 | } else { |
206 | 206 | // Inline script |
207 | - if ( $this->isremovable($tag, $this->jsremovables) ) { |
|
208 | - $this->content = str_replace( $tag, '', $this->content ); |
|
207 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
208 | + $this->content = str_replace($tag, '', $this->content); |
|
209 | 209 | continue; |
210 | 210 | } |
211 | 211 | |
212 | 212 | // unhide comments, as javascript may be wrapped in comment-tags for old times' sake |
213 | 213 | $tag = $this->restore_comments($tag); |
214 | - if ( $this->ismergeable($tag) && $this->include_inline ) { |
|
215 | - preg_match( '#<script.*>(.*)</script>#Usmi', $tag , $code ); |
|
216 | - $code = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1] ); |
|
217 | - $code = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code ); |
|
218 | - $this->scripts[] = 'INLINE;' . $code; |
|
214 | + if ($this->ismergeable($tag) && $this->include_inline) { |
|
215 | + preg_match('#<script.*>(.*)</script>#Usmi', $tag, $code); |
|
216 | + $code = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1]); |
|
217 | + $code = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code); |
|
218 | + $this->scripts[] = 'INLINE;'.$code; |
|
219 | 219 | } else { |
220 | 220 | // Can we move this? |
221 | - $autoptimize_js_moveable = apply_filters( 'autoptimize_js_moveable', '', $tag ); |
|
222 | - if ( $this->ismovable($tag) || '' !== $autoptimize_js_moveable ) { |
|
223 | - if ( $this->movetolast($tag) || 'last' === $autoptimize_js_moveable ) { |
|
221 | + $autoptimize_js_moveable = apply_filters('autoptimize_js_moveable', '', $tag); |
|
222 | + if ($this->ismovable($tag) || '' !== $autoptimize_js_moveable) { |
|
223 | + if ($this->movetolast($tag) || 'last' === $autoptimize_js_moveable) { |
|
224 | 224 | $this->move['last'][] = $tag; |
225 | 225 | } else { |
226 | 226 | $this->move['first'][] = $tag; |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | //Remove the original script tag |
238 | - $this->content = str_replace( $tag, '', $this->content ); |
|
238 | + $this->content = str_replace($tag, '', $this->content); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | return true; |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | // We're only interested in the type attribute of the <script> tag itself, not any possible |
266 | 266 | // inline code that might just contain the 'type=' string... |
267 | 267 | $tag_parts = array(); |
268 | - preg_match( '#<(script[^>]*)>#i', $tag, $tag_parts); |
|
268 | + preg_match('#<(script[^>]*)>#i', $tag, $tag_parts); |
|
269 | 269 | $tag_without_contents = null; |
270 | - if ( ! empty( $tag_parts[1] ) ) { |
|
270 | + if (!empty($tag_parts[1])) { |
|
271 | 271 | $tag_without_contents = $tag_parts[1]; |
272 | 272 | } |
273 | 273 | |
274 | - $has_type = ( strpos( $tag_without_contents, 'type' ) !== false ); |
|
274 | + $has_type = (strpos($tag_without_contents, 'type') !== false); |
|
275 | 275 | |
276 | 276 | $type_valid = false; |
277 | - if ( $has_type ) { |
|
278 | - $type_valid = (bool) preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents ); |
|
277 | + if ($has_type) { |
|
278 | + $type_valid = (bool) preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | $should_aggregate = false; |
282 | - if ( ! $has_type || $type_valid ) { |
|
282 | + if (!$has_type || $type_valid) { |
|
283 | 283 | $should_aggregate = true; |
284 | 284 | } |
285 | 285 | |
@@ -289,40 +289,40 @@ discard block |
||
289 | 289 | //Joins and optimizes JS |
290 | 290 | public function minify() |
291 | 291 | { |
292 | - foreach ( $this->scripts as $script ) { |
|
292 | + foreach ($this->scripts as $script) { |
|
293 | 293 | // TODO/FIXME: some duplicate code here, can be reduced/simplified |
294 | - if ( preg_match( '#^INLINE;#', $script ) ) { |
|
294 | + if (preg_match('#^INLINE;#', $script)) { |
|
295 | 295 | // Inline script |
296 | - $script = preg_replace( '#^INLINE;#', '', $script ); |
|
297 | - $script = rtrim( $script, ";\n\t\r" ) . ';'; |
|
296 | + $script = preg_replace('#^INLINE;#', '', $script); |
|
297 | + $script = rtrim($script, ";\n\t\r").';'; |
|
298 | 298 | // Add try-catch? |
299 | - if ( $this->trycatch ) { |
|
300 | - $script = 'try{' . $script . '}catch(e){}'; |
|
299 | + if ($this->trycatch) { |
|
300 | + $script = 'try{'.$script.'}catch(e){}'; |
|
301 | 301 | } |
302 | - $tmpscript = apply_filters( 'autoptimize_js_individual_script', $script, '' ); |
|
303 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscript ) ) { |
|
302 | + $tmpscript = apply_filters('autoptimize_js_individual_script', $script, ''); |
|
303 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscript)) { |
|
304 | 304 | $script = $tmpscript; |
305 | 305 | $this->alreadyminified = true; |
306 | 306 | } |
307 | - $this->jscode .= "\n" . $script; |
|
307 | + $this->jscode .= "\n".$script; |
|
308 | 308 | } else { |
309 | 309 | // External script |
310 | - if ( false !== $script && file_exists( $script ) && is_readable( $script ) ) { |
|
311 | - $scriptsrc = file_get_contents( $script ); |
|
312 | - $scriptsrc = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc ); |
|
313 | - $scriptsrc = rtrim( $scriptsrc, ";\n\t\r" ) . ';'; |
|
310 | + if (false !== $script && file_exists($script) && is_readable($script)) { |
|
311 | + $scriptsrc = file_get_contents($script); |
|
312 | + $scriptsrc = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc); |
|
313 | + $scriptsrc = rtrim($scriptsrc, ";\n\t\r").';'; |
|
314 | 314 | // Add try-catch? |
315 | - if ( $this->trycatch ) { |
|
316 | - $scriptsrc = 'try{' . $scriptsrc . '}catch(e){}'; |
|
315 | + if ($this->trycatch) { |
|
316 | + $scriptsrc = 'try{'.$scriptsrc.'}catch(e){}'; |
|
317 | 317 | } |
318 | - $tmpscriptsrc = apply_filters( 'autoptimize_js_individual_script', $scriptsrc, $script ); |
|
319 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscriptsrc ) ) { |
|
318 | + $tmpscriptsrc = apply_filters('autoptimize_js_individual_script', $scriptsrc, $script); |
|
319 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscriptsrc)) { |
|
320 | 320 | $scriptsrc = $tmpscriptsrc; |
321 | 321 | $this->alreadyminified = true; |
322 | - } else if ( $this->can_inject_late($script) ) { |
|
322 | + } else if ($this->can_inject_late($script)) { |
|
323 | 323 | $scriptsrc = self::build_injectlater_marker($script, md5($scriptsrc)); |
324 | 324 | } |
325 | - $this->jscode .= "\n" . $scriptsrc; |
|
325 | + $this->jscode .= "\n".$scriptsrc; |
|
326 | 326 | }/*else{ |
327 | 327 | //Couldn't read JS. Maybe getpath isn't working? |
328 | 328 | }*/ |
@@ -330,32 +330,32 @@ discard block |
||
330 | 330 | } |
331 | 331 | |
332 | 332 | // Check for already-minified code |
333 | - $this->md5hash = md5( $this->jscode ); |
|
333 | + $this->md5hash = md5($this->jscode); |
|
334 | 334 | $ccheck = new autoptimizeCache($this->md5hash, 'js'); |
335 | - if ( $ccheck->check() ) { |
|
335 | + if ($ccheck->check()) { |
|
336 | 336 | $this->jscode = $ccheck->retrieve(); |
337 | 337 | return true; |
338 | 338 | } |
339 | - unset( $ccheck ); |
|
339 | + unset($ccheck); |
|
340 | 340 | |
341 | 341 | // $this->jscode has all the uncompressed code now. |
342 | - if ( true !== $this->alreadyminified ) { |
|
343 | - if ( apply_filters( 'autoptimize_js_do_minify', true ) ) { |
|
344 | - $tmp_jscode = trim( JSMin::minify( $this->jscode ) ); |
|
345 | - if ( ! empty( $tmp_jscode ) ) { |
|
342 | + if (true !== $this->alreadyminified) { |
|
343 | + if (apply_filters('autoptimize_js_do_minify', true)) { |
|
344 | + $tmp_jscode = trim(JSMin::minify($this->jscode)); |
|
345 | + if (!empty($tmp_jscode)) { |
|
346 | 346 | $this->jscode = $tmp_jscode; |
347 | - unset( $tmp_jscode ); |
|
347 | + unset($tmp_jscode); |
|
348 | 348 | } |
349 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
350 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
349 | + $this->jscode = $this->inject_minified($this->jscode); |
|
350 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
351 | 351 | return true; |
352 | 352 | } else { |
353 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
353 | + $this->jscode = $this->inject_minified($this->jscode); |
|
354 | 354 | return false; |
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
358 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
358 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
359 | 359 | return true; |
360 | 360 | } |
361 | 361 | |
@@ -363,11 +363,11 @@ discard block |
||
363 | 363 | public function cache() |
364 | 364 | { |
365 | 365 | $cache = new autoptimizeCache($this->md5hash, 'js'); |
366 | - if ( ! $cache->check() ) { |
|
366 | + if (!$cache->check()) { |
|
367 | 367 | // Cache our code |
368 | 368 | $cache->cache($this->jscode, 'text/javascript'); |
369 | 369 | } |
370 | - $this->url = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
370 | + $this->url = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
371 | 371 | $this->url = $this->url_replace_cdn($this->url); |
372 | 372 | } |
373 | 373 | |
@@ -375,43 +375,43 @@ discard block |
||
375 | 375 | public function getcontent() |
376 | 376 | { |
377 | 377 | // Restore the full content |
378 | - if ( ! empty( $this->restofcontent ) ) { |
|
378 | + if (!empty($this->restofcontent)) { |
|
379 | 379 | $this->content .= $this->restofcontent; |
380 | 380 | $this->restofcontent = ''; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // Add the scripts taking forcehead/ deferred (default) into account |
384 | - if ( $this->forcehead ) { |
|
385 | - $replaceTag = array( '</head>', 'before' ); |
|
384 | + if ($this->forcehead) { |
|
385 | + $replaceTag = array('</head>', 'before'); |
|
386 | 386 | $defer = ''; |
387 | 387 | } else { |
388 | - $replaceTag = array( '</body>', 'before' ); |
|
388 | + $replaceTag = array('</body>', 'before'); |
|
389 | 389 | $defer = 'defer '; |
390 | 390 | } |
391 | 391 | |
392 | - $defer = apply_filters( 'autoptimize_filter_js_defer', $defer ); |
|
392 | + $defer = apply_filters('autoptimize_filter_js_defer', $defer); |
|
393 | 393 | |
394 | - $bodyreplacementpayload = '<script type="text/javascript" ' . $defer . 'src="' . $this->url . '"></script>'; |
|
395 | - $bodyreplacementpayload = apply_filters( 'autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload ); |
|
394 | + $bodyreplacementpayload = '<script type="text/javascript" '.$defer.'src="'.$this->url.'"></script>'; |
|
395 | + $bodyreplacementpayload = apply_filters('autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload); |
|
396 | 396 | |
397 | - $bodyreplacement = implode( '', $this->move['first'] ); |
|
397 | + $bodyreplacement = implode('', $this->move['first']); |
|
398 | 398 | $bodyreplacement .= $bodyreplacementpayload; |
399 | - $bodyreplacement .= implode( '', $this->move['last'] ); |
|
399 | + $bodyreplacement .= implode('', $this->move['last']); |
|
400 | 400 | |
401 | - $replaceTag = apply_filters( 'autoptimize_filter_js_replacetag', $replaceTag ); |
|
401 | + $replaceTag = apply_filters('autoptimize_filter_js_replacetag', $replaceTag); |
|
402 | 402 | |
403 | - if ( strlen( $this->jscode ) > 0 ) { |
|
404 | - $this->inject_in_html( $bodyreplacement, $replaceTag ); |
|
403 | + if (strlen($this->jscode) > 0) { |
|
404 | + $this->inject_in_html($bodyreplacement, $replaceTag); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | // Restore comments. |
408 | - $this->content = $this->restore_comments( $this->content ); |
|
408 | + $this->content = $this->restore_comments($this->content); |
|
409 | 409 | |
410 | 410 | // Restore IE hacks. |
411 | - $this->content = $this->restore_iehacks( $this->content ); |
|
411 | + $this->content = $this->restore_iehacks($this->content); |
|
412 | 412 | |
413 | 413 | // Restore noptimize. |
414 | - $this->content = $this->restore_noptimize( $this->content ); |
|
414 | + $this->content = $this->restore_noptimize($this->content); |
|
415 | 415 | |
416 | 416 | // Return the modified HTML. |
417 | 417 | return $this->content; |
@@ -420,32 +420,32 @@ discard block |
||
420 | 420 | // Checks against the white- and blacklists |
421 | 421 | private function ismergeable($tag) |
422 | 422 | { |
423 | - if ( ! $this->aggregate ) { |
|
423 | + if (!$this->aggregate) { |
|
424 | 424 | return false; |
425 | 425 | } |
426 | 426 | |
427 | - if ( ! empty( $this->whitelist ) ) { |
|
428 | - foreach ( $this->whitelist as $match ) { |
|
429 | - if (false !== strpos( $tag, $match ) ) { |
|
427 | + if (!empty($this->whitelist)) { |
|
428 | + foreach ($this->whitelist as $match) { |
|
429 | + if (false !== strpos($tag, $match)) { |
|
430 | 430 | return true; |
431 | 431 | } |
432 | 432 | } |
433 | 433 | // no match with whitelist |
434 | 434 | return false; |
435 | 435 | } else { |
436 | - foreach($this->domove as $match) { |
|
437 | - if ( false !== strpos( $tag, $match ) ) { |
|
436 | + foreach ($this->domove as $match) { |
|
437 | + if (false !== strpos($tag, $match)) { |
|
438 | 438 | // Matched something |
439 | 439 | return false; |
440 | 440 | } |
441 | 441 | } |
442 | 442 | |
443 | - if ( $this->movetolast($tag) ) { |
|
443 | + if ($this->movetolast($tag)) { |
|
444 | 444 | return false; |
445 | 445 | } |
446 | 446 | |
447 | - foreach( $this->dontmove as $match ) { |
|
448 | - if ( false !== strpos( $tag, $match ) ) { |
|
447 | + foreach ($this->dontmove as $match) { |
|
448 | + if (false !== strpos($tag, $match)) { |
|
449 | 449 | // Matched something |
450 | 450 | return false; |
451 | 451 | } |
@@ -459,23 +459,23 @@ discard block |
||
459 | 459 | // Checks agains the blacklist |
460 | 460 | private function ismovable($tag) |
461 | 461 | { |
462 | - if ( true !== $this->include_inline || apply_filters( 'autoptimize_filter_js_unmovable', true ) ) { |
|
462 | + if (true !== $this->include_inline || apply_filters('autoptimize_filter_js_unmovable', true)) { |
|
463 | 463 | return false; |
464 | 464 | } |
465 | 465 | |
466 | - foreach ( $this->domove as $match ) { |
|
467 | - if ( false !== strpos( $tag, $match ) ) { |
|
466 | + foreach ($this->domove as $match) { |
|
467 | + if (false !== strpos($tag, $match)) { |
|
468 | 468 | // Matched something |
469 | 469 | return true; |
470 | 470 | } |
471 | 471 | } |
472 | 472 | |
473 | - if ( $this->movetolast($tag) ) { |
|
473 | + if ($this->movetolast($tag)) { |
|
474 | 474 | return true; |
475 | 475 | } |
476 | 476 | |
477 | - foreach ( $this->dontmove as $match ) { |
|
478 | - if ( false !== strpos( $tag, $match ) ) { |
|
477 | + foreach ($this->dontmove as $match) { |
|
478 | + if (false !== strpos($tag, $match)) { |
|
479 | 479 | // Matched something |
480 | 480 | return false; |
481 | 481 | } |
@@ -487,8 +487,8 @@ discard block |
||
487 | 487 | |
488 | 488 | private function movetolast($tag) |
489 | 489 | { |
490 | - foreach ( $this->domovelast as $match ) { |
|
491 | - if ( false !== strpos( $tag, $match ) ) { |
|
490 | + foreach ($this->domovelast as $match) { |
|
491 | + if (false !== strpos($tag, $match)) { |
|
492 | 492 | // Matched, return true |
493 | 493 | return true; |
494 | 494 | } |
@@ -509,11 +509,11 @@ discard block |
||
509 | 509 | * @return bool |
510 | 510 | */ |
511 | 511 | private function can_inject_late($jsPath) { |
512 | - $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false ); |
|
513 | - if ( true !== $this->inject_min_late ) { |
|
512 | + $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false); |
|
513 | + if (true !== $this->inject_min_late) { |
|
514 | 514 | // late-inject turned off |
515 | 515 | return false; |
516 | - } else if ( ( false === strpos( $jsPath, 'min.js' ) ) && ( false === strpos( $jsPath, 'wp-includes/js/jquery/jquery.js' ) ) && ( str_replace( $consider_minified_array, '', $jsPath ) === $jsPath ) ) { |
|
516 | + } else if ((false === strpos($jsPath, 'min.js')) && (false === strpos($jsPath, 'wp-includes/js/jquery/jquery.js')) && (str_replace($consider_minified_array, '', $jsPath) === $jsPath)) { |
|
517 | 517 | // file not minified based on filename & filter |
518 | 518 | return false; |
519 | 519 | } else { |
@@ -540,26 +540,26 @@ discard block |
||
540 | 540 | * |
541 | 541 | * @return bool|string Url pointing to the minified js file or false. |
542 | 542 | */ |
543 | - public function minify_single( $filepath, $cache_miss = false ) |
|
543 | + public function minify_single($filepath, $cache_miss = false) |
|
544 | 544 | { |
545 | - $contents = $this->prepare_minify_single( $filepath ); |
|
545 | + $contents = $this->prepare_minify_single($filepath); |
|
546 | 546 | |
547 | - if ( empty( $contents ) ) { |
|
547 | + if (empty($contents)) { |
|
548 | 548 | return false; |
549 | 549 | } |
550 | 550 | |
551 | 551 | // Check cache. |
552 | - $hash = 'single_' . md5( $contents ); |
|
553 | - $cache = new autoptimizeCache( $hash, 'js' ); |
|
552 | + $hash = 'single_'.md5($contents); |
|
553 | + $cache = new autoptimizeCache($hash, 'js'); |
|
554 | 554 | |
555 | 555 | // If not in cache already, minify... |
556 | - if ( ! $cache->check() || $cache_miss ) { |
|
557 | - $contents = trim( JSMin::minify( $contents ) ); |
|
556 | + if (!$cache->check() || $cache_miss) { |
|
557 | + $contents = trim(JSMin::minify($contents)); |
|
558 | 558 | // Store in cache. |
559 | - $cache->cache( $contents, 'text/javascript' ); |
|
559 | + $cache->cache($contents, 'text/javascript'); |
|
560 | 560 | } |
561 | 561 | |
562 | - $url = $this->build_minify_single_url( $cache ); |
|
562 | + $url = $this->build_minify_single_url($cache); |
|
563 | 563 | |
564 | 564 | return $url; |
565 | 565 | } |
@@ -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'); |