Completed
Push — master ( 8e7dca...6ec0d0 )
by frank
01:41
created
autoptimize.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -16,66 +16,66 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
config/default.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
php/persist-admin-notices-dismissal/persist-admin-notices-dismissal.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
classes/external/php/yui-php-cssmin-bundled/Utils.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -38,18 +38,18 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
classes/external/php/yui-php-cssmin-bundled/Minifier.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
     public function __construct($raisePhpLimits = true)
70 70
     {
71 71
         $this->raisePhpLimits = (bool) $raisePhpLimits;
72
-        $this->memoryLimit = 128 * 1048576; // 128MB in bytes
73
-        $this->pcreBacktrackLimit = 1000 * 1000;
74
-        $this->pcreRecursionLimit = 500 * 1000;
72
+        $this->memoryLimit = 128*1048576; // 128MB in bytes
73
+        $this->pcreBacktrackLimit = 1000*1000;
74
+        $this->pcreRecursionLimit = 500*1000;
75 75
         $this->hexToNamedColorsMap = Colors::getHexToNamedMap();
76 76
         $this->namedToHexColorsMap = Colors::getNamedToHexMap();
77 77
         $this->namedToHexColorsRegex = sprintf(
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
      */
174 174
     private function setShortenZeroValuesRegexes()
175 175
     {
176
-        $zeroRegex = '0'. $this->unitsGroupRegex;
177
-        $numOrPosRegex = '('. $this->numRegex .'|top|left|bottom|right|center) ';
176
+        $zeroRegex = '0'.$this->unitsGroupRegex;
177
+        $numOrPosRegex = '('.$this->numRegex.'|top|left|bottom|right|center) ';
178 178
         $oneZeroSafeProperties = array(
179 179
             '(?:line-)?height',
180 180
             '(?:(?:min|max)-)?width',
@@ -192,14 +192,14 @@  discard block
 block discarded – undo
192 192
         );
193 193
 
194 194
         // First zero regex
195
-        $regex = '/(^|;)('. implode('|', $oneZeroSafeProperties) .'):%s/Si';
195
+        $regex = '/(^|;)('.implode('|', $oneZeroSafeProperties).'):%s/Si';
196 196
         $this->shortenOneZeroesRegex = sprintf($regex, $zeroRegex);
197 197
 
198 198
         // Multiple zeroes regexes
199 199
         $regex = '/(^|;)(margin|padding|border-(?:width|radius)|background-position):%s/Si';
200
-        $this->shortenTwoZeroesRegex = sprintf($regex, $numOrPosRegex . $zeroRegex);
201
-        $this->shortenThreeZeroesRegex = sprintf($regex, $numOrPosRegex . $numOrPosRegex . $zeroRegex);
202
-        $this->shortenFourZeroesRegex = sprintf($regex, $numOrPosRegex . $numOrPosRegex . $numOrPosRegex . $zeroRegex);
200
+        $this->shortenTwoZeroesRegex = sprintf($regex, $numOrPosRegex.$zeroRegex);
201
+        $this->shortenThreeZeroesRegex = sprintf($regex, $numOrPosRegex.$numOrPosRegex.$zeroRegex);
202
+        $this->shortenFourZeroesRegex = sprintf($regex, $numOrPosRegex.$numOrPosRegex.$numOrPosRegex.$zeroRegex);
203 203
     }
204 204
 
205 205
     /**
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
             $dataStartIndex = $matchStartIndex + 4; // url( length
376 376
             $searchOffset = $matchStartIndex + strlen($m[0][0]);
377 377
             $terminator = $m[1][0]; // ', " or empty (not quoted)
378
-            $terminatorRegex = '/(?<!\\\\)'. (strlen($terminator) === 0 ? '' : $terminator.'\s*') .'(\))/S';
378
+            $terminatorRegex = '/(?<!\\\\)'.(strlen($terminator) === 0 ? '' : $terminator.'\s*').'(\))/S';
379 379
 
380 380
             $ret .= substr($css, $substrOffset, $matchStartIndex - $substrOffset);
381 381
 
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
                     $token = preg_replace('/\s+/S', '', $token);
391 391
                 }
392 392
 
393
-                $ret .= 'url('. $this->registerPreservedToken(trim($token)) .')';
393
+                $ret .= 'url('.$this->registerPreservedToken(trim($token)).')';
394 394
             // No end terminator found, re-add the whole match. Should we throw/warn here?
395 395
             } else {
396 396
                 $ret .= substr($css, $matchStartIndex, $searchOffset - $matchStartIndex);
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
      */
412 412
     private function processCommentsCallback($matches)
413 413
     {
414
-        return '/*'. $this->registerCommentToken($matches[1]) .'*/';
414
+        return '/*'.$this->registerCommentToken($matches[1]).'*/';
415 415
     }
416 416
 
417 417
     /**
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
      */
422 422
     private function processOldIeSpecificMatrixDefinitionCallback($matches)
423 423
     {
424
-        return 'filter:progid:DXImageTransform.Microsoft.Matrix('. $this->registerPreservedToken($matches[1]) .')';
424
+        return 'filter:progid:DXImageTransform.Microsoft.Matrix('.$this->registerPreservedToken($matches[1]).')';
425 425
     }
426 426
 
427 427
     /**
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
         // minify alpha opacity in filter strings
445 445
         $match = str_ireplace('progid:DXImageTransform.Microsoft.Alpha(Opacity=', 'alpha(opacity=', $match);
446 446
 
447
-        return $quote . $this->registerPreservedToken($match) . $quote;
447
+        return $quote.$this->registerPreservedToken($match).$quote;
448 448
     }
449 449
 
450 450
     /**
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
      */
456 456
     private function processImportUnquotedUrlAtRulesCallback($matches)
457 457
     {
458
-        return '@import url('. $this->registerPreservedToken($matches[1]) .')'. $matches[2];
458
+        return '@import url('.$this->registerPreservedToken($matches[1]).')'.$matches[2];
459 459
     }
460 460
 
461 461
     /**
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
     private function processComments($css)
467 467
     {
468 468
         foreach ($this->comments as $commentId => $comment) {
469
-            $commentIdString = '/*'. $commentId .'*/';
469
+            $commentIdString = '/*'.$commentId.'*/';
470 470
 
471 471
             // ! in the first position of the comment means preserve
472 472
             // so push to the preserved tokens keeping the !
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
             } else {
525 525
                 $ruleBody = substr($css, $blockStartPos + 1, $blockEndPos - $blockStartPos - 1);
526 526
                 $ruleBodyToken = $this->registerRuleBodyToken($this->processRuleBody($ruleBody));
527
-                $ret .= '{'. $ruleBodyToken .'}';
527
+                $ret .= '{'.$ruleBodyToken.'}';
528 528
                 $searchOffset = $blockEndPos + 1;
529 529
             }
530 530
 
@@ -613,8 +613,8 @@  discard block
 block discarded – undo
613 613
         $body = preg_replace('/([ :,(])\+(\.?\d+)/S', '$1$2', $body);
614 614
 
615 615
         // shorten ms to s
616
-        $body = preg_replace_callback('/([ :,(])(-?)(\d{3,})ms/Si', function ($matches) {
617
-            return $matches[1] . $matches[2] . ((int) $matches[3] / 1000) .'s';
616
+        $body = preg_replace_callback('/([ :,(])(-?)(\d{3,})ms/Si', function($matches) {
617
+            return $matches[1].$matches[2].((int) $matches[3]/1000).'s';
618 618
         }, $body);
619 619
 
620 620
         // Remove leading zeros from integer and float numbers.
@@ -716,13 +716,13 @@  discard block
 block discarded – undo
716 716
         $css = preg_replace('/::(before|after|first-(?:line|letter))(\{|,)/Si', ':$1$2', $css);
717 717
 
718 718
         // Retain space for special IE6 cases
719
-        $css = preg_replace_callback('/:first-(line|letter)(\{|,)/Si', function ($matches) {
720
-            return ':first-'. strtolower($matches[1]) .' '. $matches[2];
719
+        $css = preg_replace_callback('/:first-(line|letter)(\{|,)/Si', function($matches) {
720
+            return ':first-'.strtolower($matches[1]).' '.$matches[2];
721 721
         }, $css);
722 722
 
723 723
         // Find a fraction that may used in some @media queries such as: (min-aspect-ratio: 1/1)
724 724
         // Add token to add the "/" back in later
725
-        $css = preg_replace('/\(([a-z-]+):([0-9]+)\/([0-9]+)\)/Si', '($1:$2'. self::QUERY_FRACTION .'$3)', $css);
725
+        $css = preg_replace('/\(([a-z-]+):([0-9]+)\/([0-9]+)\)/Si', '($1:$2'.self::QUERY_FRACTION.'$3)', $css);
726 726
 
727 727
         // Remove empty rule blocks up to 2 levels deep.
728 728
         $css = preg_replace(array_fill(0, 2, '/(\{)[^{};\/\n]+\{\}/S'), '$1', $css);
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
         }
771 771
 
772 772
         // @import handling
773
-        $css = preg_replace_callback($this->importRegex, function ($matches) use (&$imports) {
773
+        $css = preg_replace_callback($this->importRegex, function($matches) use (&$imports) {
774 774
             // Keep all @import at-rules found for later
775 775
             $imports .= $matches[0];
776 776
             // Delete all @import at-rules
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
         }, $css);
779 779
 
780 780
         // @namespace handling
781
-        $css = preg_replace_callback($this->namespaceRegex, function ($matches) use (&$namespaces) {
781
+        $css = preg_replace_callback($this->namespaceRegex, function($matches) use (&$namespaces) {
782 782
             // Keep all @namespace at-rules found for later
783 783
             $namespaces .= $matches[0];
784 784
             // Delete all @namespace at-rules
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
         // 1. @charset first
790 790
         // 2. @imports below @charset
791 791
         // 3. @namespaces below @imports
792
-        $css = $charset . $imports . $namespaces . $css;
792
+        $css = $charset.$imports.$namespaces.$css;
793 793
 
794 794
         return $css;
795 795
     }
@@ -843,10 +843,10 @@  discard block
 block discarded – undo
843 843
         // Restore space after rgb() or hsl() function in some cases such as:
844 844
         // background-image: linear-gradient(to bottom, rgb(210,180,140) 10%, rgb(255,0,0) 90%);
845 845
         if (!empty($terminator) && !preg_match('/[ ,);]/S', $terminator)) {
846
-            $terminator = ' '. $terminator;
846
+            $terminator = ' '.$terminator;
847 847
         }
848 848
 
849
-        return '#'. implode('', $hexColors) . $terminator;
849
+        return '#'.implode('', $hexColors).$terminator;
850 850
     }
851 851
 
852 852
     /**
@@ -860,16 +860,16 @@  discard block
 block discarded – undo
860 860
 
861 861
         // Shorten suitable 6 chars HEX colors
862 862
         if (strlen($hex) === 6 && preg_match('/^([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3$/Si', $hex, $m)) {
863
-            $hex = $m[1] . $m[2] . $m[3];
863
+            $hex = $m[1].$m[2].$m[3];
864 864
         }
865 865
 
866 866
         // Lowercase
867
-        $hex = '#'. strtolower($hex);
867
+        $hex = '#'.strtolower($hex);
868 868
 
869 869
         // Replace Hex colors with shorter color names
870 870
         $color = array_key_exists($hex, $this->hexToNamedColorsMap) ? $this->hexToNamedColorsMap[$hex] : $hex;
871 871
 
872
-        return $color . $matches[2];
872
+        return $color.$matches[2];
873 873
     }
874 874
 
875 875
     /**
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
      */
881 881
     private function shortenNamedColorsCallback($matches)
882 882
     {
883
-        return $matches[1] . $this->namedToHexColorsMap[strtolower($matches[2])] . $matches[3];
883
+        return $matches[1].$this->namedToHexColorsMap[strtolower($matches[2])].$matches[3];
884 884
     }
885 885
 
886 886
     /**
Please login to merge, or discard this patch.
classes/external/php/jsmin.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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}*/";
Please login to merge, or discard this patch.
classes/external/php/minify-html.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
classes/autoptimizeScripts.php 1 patch
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
classes/autoptimizeStyles.php 1 patch
Spacing   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Class for CSS optimization.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -48,53 +48,53 @@  discard block
 block discarded – undo
48 48
     // public $cdn_url; // Used all over the place implicitly, so will have to be either public or protected :/ .
49 49
 
50 50
     // Reads the page and collects style tags.
51
-    public function read( $options )
51
+    public function read($options)
52 52
     {
53
-        $noptimizeCSS = apply_filters( 'autoptimize_filter_css_noptimize', false, $this->content );
54
-        if ( $noptimizeCSS ) {
53
+        $noptimizeCSS = apply_filters('autoptimize_filter_css_noptimize', false, $this->content);
54
+        if ($noptimizeCSS) {
55 55
             return false;
56 56
         }
57 57
 
58
-        $whitelistCSS = apply_filters( 'autoptimize_filter_css_whitelist', '', $this->content );
59
-        if ( ! empty( $whitelistCSS ) ) {
60
-            $this->whitelist = array_filter( array_map( 'trim', explode( ',', $whitelistCSS ) ) );
58
+        $whitelistCSS = apply_filters('autoptimize_filter_css_whitelist', '', $this->content);
59
+        if (!empty($whitelistCSS)) {
60
+            $this->whitelist = array_filter(array_map('trim', explode(',', $whitelistCSS)));
61 61
         }
62 62
 
63
-        $removableCSS = apply_filters( 'autoptimize_filter_css_removables', '' );
64
-        if ( ! empty( $removableCSS ) ) {
65
-            $this->cssremovables = array_filter( array_map( 'trim', explode( ',', $removableCSS ) ) );
63
+        $removableCSS = apply_filters('autoptimize_filter_css_removables', '');
64
+        if (!empty($removableCSS)) {
65
+            $this->cssremovables = array_filter(array_map('trim', explode(',', $removableCSS)));
66 66
         }
67 67
 
68
-        $this->cssinlinesize = apply_filters( 'autoptimize_filter_css_inlinesize', 256 );
68
+        $this->cssinlinesize = apply_filters('autoptimize_filter_css_inlinesize', 256);
69 69
 
70 70
         // filter to "late inject minified CSS", default to true for now (it is faster).
71
-        $this->inject_min_late = apply_filters( 'autoptimize_filter_css_inject_min_late', true );
71
+        $this->inject_min_late = apply_filters('autoptimize_filter_css_inject_min_late', true);
72 72
 
73 73
         // Remove everything that's not the header.
74
-        if ( apply_filters( 'autoptimize_filter_css_justhead', $options['justhead'] ) ) {
75
-            $content             = explode( '</head>', $this->content, 2 );
76
-            $this->content       = $content[0] . '</head>';
74
+        if (apply_filters('autoptimize_filter_css_justhead', $options['justhead'])) {
75
+            $content             = explode('</head>', $this->content, 2);
76
+            $this->content       = $content[0].'</head>';
77 77
             $this->restofcontent = $content[1];
78 78
         }
79 79
 
80 80
         // Determine whether we're doing CSS-files aggregation or not.
81
-        if ( isset( $options['aggregate'] ) && ! $options['aggregate'] ) {
81
+        if (isset($options['aggregate']) && !$options['aggregate']) {
82 82
             $this->aggregate = false;
83 83
         }
84 84
         // Returning true for "dontaggregate" turns off aggregation.
85
-        if ( $this->aggregate && apply_filters( 'autoptimize_filter_css_dontaggregate', false ) ) {
85
+        if ($this->aggregate && apply_filters('autoptimize_filter_css_dontaggregate', false)) {
86 86
             $this->aggregate = false;
87 87
         }
88 88
 
89 89
         // include inline?
90
-        if ( apply_filters( 'autoptimize_css_include_inline', $options['include_inline'] ) ) {
90
+        if (apply_filters('autoptimize_css_include_inline', $options['include_inline'])) {
91 91
             $this->include_inline = true;
92 92
         }
93 93
 
94 94
         // List of CSS strings which are excluded from autoptimization.
95
-        $excludeCSS = apply_filters( 'autoptimize_filter_css_exclude', $options['css_exclude'], $this->content );
96
-        if ( '' !== $excludeCSS ) {
97
-            $this->dontmove = array_filter( array_map( 'trim', explode( ',', $excludeCSS ) ) );
95
+        $excludeCSS = apply_filters('autoptimize_filter_css_exclude', $options['css_exclude'], $this->content);
96
+        if ('' !== $excludeCSS) {
97
+            $this->dontmove = array_filter(array_map('trim', explode(',', $excludeCSS)));
98 98
         } else {
99 99
             $this->dontmove = array();
100 100
         }
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
         // Should we defer css?
106 106
         // value: true / false.
107 107
         $this->defer = $options['defer'];
108
-        $this->defer = apply_filters( 'autoptimize_filter_css_defer', $this->defer, $this->content );
108
+        $this->defer = apply_filters('autoptimize_filter_css_defer', $this->defer, $this->content);
109 109
 
110 110
         // Should we inline while deferring?
111 111
         // value: inlined CSS.
112
-        $this->defer_inline = apply_filters( 'autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content );
112
+        $this->defer_inline = apply_filters('autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content);
113 113
 
114 114
         // Should we inline?
115 115
         // value: true / false.
116 116
         $this->inline = $options['inline'];
117
-        $this->inline = apply_filters( 'autoptimize_filter_css_inline', $this->inline, $this->content );
117
+        $this->inline = apply_filters('autoptimize_filter_css_inline', $this->inline, $this->content);
118 118
 
119 119
         // Store cdn url.
120 120
         $this->cdn_url = $options['cdn_url'];
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         $this->datauris = $options['datauris'];
124 124
 
125 125
         // noptimize me.
126
-        $this->content = $this->hide_noptimize( $this->content );
126
+        $this->content = $this->hide_noptimize($this->content);
127 127
 
128 128
         // Exclude (no)script, as those may contain CSS which should be left as is.
129 129
         $this->content = $this->replace_contents_with_marker_if_exists(
@@ -134,26 +134,26 @@  discard block
 block discarded – undo
134 134
         );
135 135
 
136 136
         // Save IE hacks.
137
-        $this->content = $this->hide_iehacks( $this->content );
137
+        $this->content = $this->hide_iehacks($this->content);
138 138
 
139 139
         // Hide HTML comments.
140
-        $this->content = $this->hide_comments( $this->content );
140
+        $this->content = $this->hide_comments($this->content);
141 141
 
142 142
         // Get <style> and <link>.
143
-        if ( preg_match_all( '#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches ) ) {
143
+        if (preg_match_all('#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches)) {
144 144
 
145
-            foreach ( $matches[0] as $tag ) {
146
-                if ( $this->isremovable( $tag, $this->cssremovables ) ) {
147
-                    $this->content = str_replace( $tag, '', $this->content );
148
-                } elseif ( $this->ismovable( $tag ) ) {
145
+            foreach ($matches[0] as $tag) {
146
+                if ($this->isremovable($tag, $this->cssremovables)) {
147
+                    $this->content = str_replace($tag, '', $this->content);
148
+                } elseif ($this->ismovable($tag)) {
149 149
                     // Get the media.
150
-                    if ( false !== strpos( $tag, 'media=' ) ) {
151
-                        preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias );
152
-                        $medias = explode( ',', $medias[1] );
150
+                    if (false !== strpos($tag, 'media=')) {
151
+                        preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias);
152
+                        $medias = explode(',', $medias[1]);
153 153
                         $media = array();
154
-                        foreach ( $medias as $elem ) {
154
+                        foreach ($medias as $elem) {
155 155
                             /* $media[] = current(explode(' ',trim($elem),2)); */
156
-                            if ( empty( $elem ) ) {
156
+                            if (empty($elem)) {
157 157
                                 $elem = 'all';
158 158
                             }
159 159
 
@@ -161,64 +161,64 @@  discard block
 block discarded – undo
161 161
                         }
162 162
                     } else {
163 163
                         // No media specified - applies to all.
164
-                        $media = array( 'all' );
164
+                        $media = array('all');
165 165
                     }
166 166
 
167
-                    $media = apply_filters( 'autoptimize_filter_css_tagmedia', $media, $tag );
167
+                    $media = apply_filters('autoptimize_filter_css_tagmedia', $media, $tag);
168 168
 
169
-                    if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) {
169
+                    if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) {
170 170
                         // <link>.
171
-                        $url  = current( explode( '?', $source[2], 2 ) );
172
-                        $path = $this->getpath( $url );
171
+                        $url  = current(explode('?', $source[2], 2));
172
+                        $path = $this->getpath($url);
173 173
 
174
-                        if ( false !== $path && preg_match( '#\.css$#', $path ) ) {
174
+                        if (false !== $path && preg_match('#\.css$#', $path)) {
175 175
                             // Good link.
176
-                            $this->css[] = array( $media, $path );
176
+                            $this->css[] = array($media, $path);
177 177
                         } else {
178 178
                             // Link is dynamic (.php etc).
179 179
                             $tag = '';
180 180
                         }
181 181
                     } else {
182 182
                         // Inline css in style tags can be wrapped in comment tags, so restore comments.
183
-                        $tag = $this->restore_comments( $tag );
184
-                        preg_match( '#<style.*>(.*)</style>#Usmi', $tag, $code );
183
+                        $tag = $this->restore_comments($tag);
184
+                        preg_match('#<style.*>(.*)</style>#Usmi', $tag, $code);
185 185
 
186 186
                         // And re-hide them to be able to to the removal based on tag.
187
-                        $tag = $this->hide_comments( $tag );
187
+                        $tag = $this->hide_comments($tag);
188 188
 
189
-                        if ( $this->include_inline ) {
190
-                            $code = preg_replace( '#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1] );
191
-                            $this->css[] = array( $media, 'INLINE;' . $code );
189
+                        if ($this->include_inline) {
190
+                            $code = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1]);
191
+                            $this->css[] = array($media, 'INLINE;'.$code);
192 192
                         } else {
193 193
                             $tag = '';
194 194
                         }
195 195
                     }
196 196
 
197 197
                     // Remove the original style tag.
198
-                    $this->content = str_replace( $tag, '', $this->content );
198
+                    $this->content = str_replace($tag, '', $this->content);
199 199
                 } else {
200 200
                     // Excluded CSS, minify if getpath and filter says so...
201
-                    if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) {
202
-                        $exploded_url = explode( '?', $source[2], 2 );
201
+                    if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) {
202
+                        $exploded_url = explode('?', $source[2], 2);
203 203
                         $url          = $exploded_url[0];
204
-                        $path         = $this->getpath( $url );
204
+                        $path         = $this->getpath($url);
205 205
 
206
-                        if ( $path && apply_filters( 'autoptimize_filter_css_minify_excluded', true, $url ) ) {
207
-                            $minified_url = $this->minify_single( $path );
208
-                            if ( ! empty( $minified_url ) ) {
206
+                        if ($path && apply_filters('autoptimize_filter_css_minify_excluded', true, $url)) {
207
+                            $minified_url = $this->minify_single($path);
208
+                            if (!empty($minified_url)) {
209 209
                                 // Replace orig URL with cached minified URL.
210
-                                $new_tag = str_replace( $url, $minified_url, $tag );
210
+                                $new_tag = str_replace($url, $minified_url, $tag);
211 211
                             } else {
212 212
                                 $new_tag = $tag;
213 213
                             }
214 214
 
215 215
                             // Removes querystring from URL.
216
-                            if ( ! empty( $exploded_url[1] ) ) {
217
-                                $new_tag = str_replace( '?' . $exploded_url[1], '', $new_tag );
216
+                            if (!empty($exploded_url[1])) {
217
+                                $new_tag = str_replace('?'.$exploded_url[1], '', $new_tag);
218 218
                             }
219 219
 
220 220
                             // Defer single CSS if "inline & defer" is ON and there is inline CSS.
221
-                            if ( $this->defer && ! empty( $this->defer_inline ) ) {
221
+                            if ($this->defer && !empty($this->defer_inline)) {
222 222
                                 // Get/ set (via filter) the JS to be triggers onload of the preloaded CSS.
223 223
                                 $_preload_onload = apply_filters(
224 224
                                     'autoptimize_filter_css_preload_onload',
@@ -226,18 +226,18 @@  discard block
 block discarded – undo
226 226
                                     $url
227 227
                                 );
228 228
                                 // Adapt original <link> element for CSS to be preloaded and add <noscript>-version for fallback.
229
-                                $new_tag = '<noscript>' . $new_tag . '</noscript>' . str_replace(
229
+                                $new_tag = '<noscript>'.$new_tag.'</noscript>'.str_replace(
230 230
                                     array(
231 231
                                         "rel='stylesheet'",
232 232
                                         'rel="stylesheet"',
233 233
                                     ),
234
-                                    "rel='preload' as='style' onload=\"" . $_preload_onload . "\"",
234
+                                    "rel='preload' as='style' onload=\"".$_preload_onload."\"",
235 235
                                     $new_tag
236 236
                                 );
237 237
                             }
238 238
 
239 239
                             // And replace!
240
-                            $this->content = str_replace( $tag, $new_tag, $this->content );
240
+                            $this->content = str_replace($tag, $new_tag, $this->content);
241 241
                         }
242 242
                     }
243 243
                 }
@@ -256,22 +256,22 @@  discard block
 block discarded – undo
256 256
      * @param string $path
257 257
      * @return boolean
258 258
      */
259
-    private function is_datauri_candidate( $path )
259
+    private function is_datauri_candidate($path)
260 260
     {
261 261
         // Call only once since it's called from a loop.
262 262
         static $max_size = null;
263
-        if ( null === $max_size ) {
263
+        if (null === $max_size) {
264 264
             $max_size = $this->get_datauri_maxsize();
265 265
         }
266 266
 
267
-        if ( $path && preg_match( '#\.(jpe?g|png|gif|webp|bmp)$#i', $path ) &&
268
-            file_exists( $path ) && is_readable( $path ) && filesize( $path ) <= $max_size ) {
267
+        if ($path && preg_match('#\.(jpe?g|png|gif|webp|bmp)$#i', $path) &&
268
+            file_exists($path) && is_readable($path) && filesize($path) <= $max_size) {
269 269
 
270 270
             // Seems we have a candidate.
271 271
             $is_candidate = true;
272 272
         } else {
273 273
             // Filter allows overriding default decision (which checks for local file existence).
274
-            $is_candidate = apply_filters( 'autoptimize_filter_css_is_datauri_candidate', false, $path );
274
+            $is_candidate = apply_filters('autoptimize_filter_css_is_datauri_candidate', false, $path);
275 275
         }
276 276
 
277 277
         return $is_candidate;
@@ -296,29 +296,29 @@  discard block
 block discarded – undo
296 296
          * of thing you're probably better of building assets completely
297 297
          * outside of WordPress anyway.
298 298
          */
299
-        if ( null === $max_size ) {
300
-            $max_size = (int) apply_filters( 'autoptimize_filter_css_datauri_maxsize', 4096 );
299
+        if (null === $max_size) {
300
+            $max_size = (int) apply_filters('autoptimize_filter_css_datauri_maxsize', 4096);
301 301
         }
302 302
 
303 303
         return $max_size;
304 304
     }
305 305
 
306
-    private function check_datauri_exclude_list( $url )
306
+    private function check_datauri_exclude_list($url)
307 307
     {
308 308
         static $exclude_list = null;
309 309
         $no_datauris         = array();
310 310
 
311 311
         // Again, skip doing certain stuff repeatedly when loop-called.
312
-        if ( null === $exclude_list ) {
313
-            $exclude_list = apply_filters( 'autoptimize_filter_css_datauri_exclude', '' );
314
-            $no_datauris = array_filter( array_map( 'trim', explode( ',', $exclude_list ) ) );
312
+        if (null === $exclude_list) {
313
+            $exclude_list = apply_filters('autoptimize_filter_css_datauri_exclude', '');
314
+            $no_datauris = array_filter(array_map('trim', explode(',', $exclude_list)));
315 315
         }
316 316
 
317 317
         $matched = false;
318 318
 
319
-        if ( ! empty( $exclude_list ) ) {
320
-            foreach ( $no_datauris as $no_datauri ) {
321
-                if ( false !== strpos( $url, $no_datauri ) ) {
319
+        if (!empty($exclude_list)) {
320
+            foreach ($no_datauris as $no_datauri) {
321
+                if (false !== strpos($url, $no_datauri)) {
322 322
                     $matched = true;
323 323
                     break;
324 324
                 }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
         return $matched;
329 329
     }
330 330
 
331
-    private function build_or_get_datauri_image( $path )
331
+    private function build_or_get_datauri_image($path)
332 332
     {
333 333
         /**
334 334
          * TODO/FIXME: document the required return array format, or better yet,
@@ -337,27 +337,27 @@  discard block
 block discarded – undo
337 337
          */
338 338
 
339 339
         // Allows short-circuiting datauri generation for an image.
340
-        $result = apply_filters( 'autoptimize_filter_css_datauri_image', array(), $path );
341
-        if ( ! empty( $result ) ) {
342
-            if ( is_array( $result ) && isset( $result['full'] ) && isset( $result['base64data'] ) ) {
340
+        $result = apply_filters('autoptimize_filter_css_datauri_image', array(), $path);
341
+        if (!empty($result)) {
342
+            if (is_array($result) && isset($result['full']) && isset($result['base64data'])) {
343 343
                 return $result;
344 344
             }
345 345
         }
346 346
 
347
-        $hash = md5( $path );
348
-        $check = new autoptimizeCache( $hash, 'img' );
349
-        if ( $check->check() ) {
347
+        $hash = md5($path);
348
+        $check = new autoptimizeCache($hash, 'img');
349
+        if ($check->check()) {
350 350
             // we have the base64 image in cache.
351 351
             $headAndData = $check->retrieve();
352
-            $_base64data = explode( ';base64,', $headAndData );
352
+            $_base64data = explode(';base64,', $headAndData);
353 353
             $base64data  = $_base64data[1];
354
-            unset( $_base64data );
354
+            unset($_base64data);
355 355
         } else {
356 356
             // It's an image and we don't have it in cache, get the type by extension.
357
-            $exploded_path = explode( '.', $path );
358
-            $type = end( $exploded_path );
357
+            $exploded_path = explode('.', $path);
358
+            $type = end($exploded_path);
359 359
 
360
-            switch ( $type ) {
360
+            switch ($type) {
361 361
                 case 'jpg':
362 362
                 case 'jpeg':
363 363
                     $dataurihead = 'data:image/jpeg;base64,';
@@ -379,15 +379,15 @@  discard block
 block discarded – undo
379 379
             }
380 380
 
381 381
             // Encode the data.
382
-            $base64data  = base64_encode( file_get_contents( $path ) );
383
-            $headAndData = $dataurihead . $base64data;
382
+            $base64data  = base64_encode(file_get_contents($path));
383
+            $headAndData = $dataurihead.$base64data;
384 384
 
385 385
             // Save in cache.
386
-            $check->cache( $headAndData, 'text/plain' );
386
+            $check->cache($headAndData, 'text/plain');
387 387
         }
388
-        unset( $check );
388
+        unset($check);
389 389
 
390
-        return array( 'full' => $headAndData, 'base64data' => $base64data );
390
+        return array('full' => $headAndData, 'base64data' => $base64data);
391 391
     }
392 392
 
393 393
     /**
@@ -399,13 +399,13 @@  discard block
 block discarded – undo
399 399
      *
400 400
      * @return string
401 401
      */
402
-    protected static function replace_longest_matches_first( $string, $replacements = array() )
402
+    protected static function replace_longest_matches_first($string, $replacements = array())
403 403
     {
404
-        if ( ! empty( $replacements ) ) {
404
+        if (!empty($replacements)) {
405 405
             // Sort the replacements array by key length in desc order (so that the longest strings are replaced first).
406
-            $keys = array_map( 'strlen', array_keys( $replacements ) );
407
-            array_multisort( $keys, SORT_DESC, $replacements );
408
-            $string = str_replace( array_keys( $replacements ), array_values( $replacements ), $string );
406
+            $keys = array_map('strlen', array_keys($replacements));
407
+            array_multisort($keys, SORT_DESC, $replacements);
408
+            $string = str_replace(array_keys($replacements), array_values($replacements), $string);
409 409
         }
410 410
 
411 411
         return $string;
@@ -421,15 +421,15 @@  discard block
 block discarded – undo
421 421
      *
422 422
      * @return string
423 423
      */
424
-    public function replace_urls( $code = '' )
424
+    public function replace_urls($code = '')
425 425
     {
426 426
         $replacements = array();
427 427
 
428
-        preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches );
429
-        if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) {
430
-            foreach ( $url_src_matches[1] as $count => $original_url ) {
428
+        preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches);
429
+        if (is_array($url_src_matches) && !empty($url_src_matches)) {
430
+            foreach ($url_src_matches[1] as $count => $original_url) {
431 431
                 // Removes quotes and other cruft.
432
-                $url = trim( $original_url, " \t\n\r\0\x0B\"'" );
432
+                $url = trim($original_url, " \t\n\r\0\x0B\"'");
433 433
 
434 434
                 /**
435 435
                  * TODO/FIXME: Add a way for other code / callable to be called here
@@ -447,17 +447,17 @@  discard block
 block discarded – undo
447 447
                  */
448 448
 
449 449
                 // Do CDN replacement if needed.
450
-                if ( ! empty( $this->cdn_url ) ) {
451
-                    $replacement_url = $this->url_replace_cdn( $url );
450
+                if (!empty($this->cdn_url)) {
451
+                    $replacement_url = $this->url_replace_cdn($url);
452 452
                     // Prepare replacements array.
453
-                    $replacements[ $url_src_matches[1][ $count ] ] = str_replace(
453
+                    $replacements[$url_src_matches[1][$count]] = str_replace(
454 454
                         $original_url, $replacement_url, $url_src_matches[1][$count]
455 455
                     );
456 456
                 }
457 457
             }
458 458
         }
459 459
 
460
-        $code = self::replace_longest_matches_first( $code, $replacements );
460
+        $code = self::replace_longest_matches_first($code, $replacements);
461 461
 
462 462
         return $code;
463 463
     }
@@ -470,26 +470,26 @@  discard block
 block discarded – undo
470 470
      * @param string $code
471 471
      * @return string
472 472
      */
473
-    public function hide_fontface_and_maybe_cdn( $code )
473
+    public function hide_fontface_and_maybe_cdn($code)
474 474
     {
475 475
         // Proceed only if @font-face declarations exist within $code.
476
-        preg_match_all( self::FONT_FACE_REGEX, $code, $fontfaces );
477
-        if ( isset( $fontfaces[0] ) ) {
476
+        preg_match_all(self::FONT_FACE_REGEX, $code, $fontfaces);
477
+        if (isset($fontfaces[0])) {
478 478
             // Check if we need to cdn fonts or not.
479
-            $do_font_cdn = apply_filters( 'autoptimize_filter_css_fonts_cdn', false );
479
+            $do_font_cdn = apply_filters('autoptimize_filter_css_fonts_cdn', false);
480 480
 
481
-            foreach ( $fontfaces[0] as $full_match ) {
481
+            foreach ($fontfaces[0] as $full_match) {
482 482
                 // Keep original match so we can search/replace it.
483 483
                 $match_search = $full_match;
484 484
 
485 485
                 // Do font cdn if needed.
486
-                if ( $do_font_cdn ) {
487
-                    $full_match = $this->replace_urls( $full_match );
486
+                if ($do_font_cdn) {
487
+                    $full_match = $this->replace_urls($full_match);
488 488
                 }
489 489
 
490 490
                 // Replace declaration with its base64 encoded string.
491
-                $replacement = self::build_marker( 'FONTFACE', $full_match );
492
-                $code = str_replace( $match_search, $replacement, $code );
491
+                $replacement = self::build_marker('FONTFACE', $full_match);
492
+                $code = str_replace($match_search, $replacement, $code);
493 493
             }
494 494
         }
495 495
 
@@ -503,16 +503,16 @@  discard block
 block discarded – undo
503 503
      * @param string $code
504 504
      * @return string
505 505
      */
506
-    public function restore_fontface( $code )
506
+    public function restore_fontface($code)
507 507
     {
508
-        return $this->restore_marked_content( 'FONTFACE', $code );
508
+        return $this->restore_marked_content('FONTFACE', $code);
509 509
     }
510 510
 
511 511
     // Re-write (and/or inline) referenced assets.
512
-    public function rewrite_assets( $code )
512
+    public function rewrite_assets($code)
513 513
     {
514 514
         // Handle @font-face rules by hiding and processing them separately.
515
-        $code = $this->hide_fontface_and_maybe_cdn( $code );
515
+        $code = $this->hide_fontface_and_maybe_cdn($code);
516 516
 
517 517
         /**
518 518
          * TODO/FIXME:
@@ -528,30 +528,30 @@  discard block
 block discarded – undo
528 528
         $url_src_matches = array();
529 529
         $imgreplace = array();
530 530
         // Matches and captures anything specified within the literal `url()` and excludes those containing data: URIs.
531
-        preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches );
532
-        if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) {
533
-            foreach ( $url_src_matches[1] as $count => $original_url ) {
531
+        preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches);
532
+        if (is_array($url_src_matches) && !empty($url_src_matches)) {
533
+            foreach ($url_src_matches[1] as $count => $original_url) {
534 534
                 // Removes quotes and other cruft.
535
-                $url = trim( $original_url, " \t\n\r\0\x0B\"'" );
535
+                $url = trim($original_url, " \t\n\r\0\x0B\"'");
536 536
 
537 537
                 // If datauri inlining is turned on, do it.
538 538
                 $inlined = false;
539
-                if ( $this->datauris ) {
539
+                if ($this->datauris) {
540 540
                     $iurl = $url;
541
-                    if ( false !== strpos( $iurl, '?' ) ) {
542
-                        $iurl = strtok( $iurl, '?' );
541
+                    if (false !== strpos($iurl, '?')) {
542
+                        $iurl = strtok($iurl, '?');
543 543
                     }
544 544
 
545
-                    $ipath = $this->getpath( $iurl );
545
+                    $ipath = $this->getpath($iurl);
546 546
 
547
-                    $excluded = $this->check_datauri_exclude_list( $ipath );
548
-                    if ( ! $excluded ) {
549
-                        $is_datauri_candidate = $this->is_datauri_candidate( $ipath );
550
-                        if ( $is_datauri_candidate ) {
551
-                            $datauri     = $this->build_or_get_datauri_image( $ipath );
547
+                    $excluded = $this->check_datauri_exclude_list($ipath);
548
+                    if (!$excluded) {
549
+                        $is_datauri_candidate = $this->is_datauri_candidate($ipath);
550
+                        if ($is_datauri_candidate) {
551
+                            $datauri     = $this->build_or_get_datauri_image($ipath);
552 552
                             $base64data  = $datauri['base64data'];
553 553
                             // Add it to the list for replacement.
554
-                            $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace(
554
+                            $imgreplace[$url_src_matches[1][$count]] = str_replace(
555 555
                                     $original_url,
556 556
                                     $datauri['full'],
557 557
                                     $url_src_matches[1][$count]
@@ -567,20 +567,20 @@  discard block
 block discarded – undo
567 567
                  * inlining isn't turned on, or if a resource is skipped from
568 568
                  * being inlined for whatever reason above.
569 569
                  */
570
-                if ( ! $inlined && ( ! empty( $this->cdn_url ) || has_filter( 'autoptimize_filter_base_replace_cdn' ) ) ) {
570
+                if (!$inlined && (!empty($this->cdn_url) || has_filter('autoptimize_filter_base_replace_cdn'))) {
571 571
                     // Just do the "simple" CDN replacement.
572
-                    $replacement_url = $this->url_replace_cdn( $url );
573
-                    $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace(
572
+                    $replacement_url = $this->url_replace_cdn($url);
573
+                    $imgreplace[$url_src_matches[1][$count]] = str_replace(
574 574
                         $original_url, $replacement_url, $url_src_matches[1][$count]
575 575
                     );
576 576
                 }
577 577
             }
578 578
         }
579 579
 
580
-        $code = self::replace_longest_matches_first( $code, $imgreplace );
580
+        $code = self::replace_longest_matches_first($code, $imgreplace);
581 581
 
582 582
         // Replace back font-face markers with actual font-face declarations.
583
-        $code = $this->restore_fontface( $code );
583
+        $code = $this->restore_fontface($code);
584 584
 
585 585
         return $code;
586 586
     }
@@ -588,29 +588,29 @@  discard block
 block discarded – undo
588 588
     // Joins and optimizes CSS.
589 589
     public function minify()
590 590
     {
591
-        foreach ( $this->css as $group ) {
592
-            list( $media, $css ) = $group;
593
-            if ( preg_match( '#^INLINE;#', $css ) ) {
591
+        foreach ($this->css as $group) {
592
+            list($media, $css) = $group;
593
+            if (preg_match('#^INLINE;#', $css)) {
594 594
                 // <style>.
595
-                $css = preg_replace( '#^INLINE;#', '', $css );
596
-                $css = self::fixurls( ABSPATH . 'index.php', $css ); // ABSPATH already contains a trailing slash.
597
-                $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, '' );
598
-                if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) {
595
+                $css = preg_replace('#^INLINE;#', '', $css);
596
+                $css = self::fixurls(ABSPATH.'index.php', $css); // ABSPATH already contains a trailing slash.
597
+                $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, '');
598
+                if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
599 599
                     $css = $tmpstyle;
600 600
                     $this->alreadyminified = true;
601 601
                 }
602 602
             } else {
603 603
                 // <link>
604
-                if ( false !== $css && file_exists( $css ) && is_readable( $css ) ) {
604
+                if (false !== $css && file_exists($css) && is_readable($css)) {
605 605
                     $cssPath = $css;
606
-                    $css = self::fixurls( $cssPath, file_get_contents( $cssPath ) );
607
-                    $css = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $css );
608
-                    $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, $cssPath );
609
-                    if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) {
606
+                    $css = self::fixurls($cssPath, file_get_contents($cssPath));
607
+                    $css = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $css);
608
+                    $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, $cssPath);
609
+                    if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
610 610
                         $css = $tmpstyle;
611 611
                         $this->alreadyminified = true;
612
-                    } elseif ( $this->can_inject_late( $cssPath, $css ) ) {
613
-                        $css = self::build_injectlater_marker( $cssPath, md5( $css ) );
612
+                    } elseif ($this->can_inject_late($cssPath, $css)) {
613
+                        $css = self::build_injectlater_marker($cssPath, md5($css));
614 614
                     }
615 615
                 } else {
616 616
                     // Couldn't read CSS. Maybe getpath isn't working?
@@ -618,12 +618,12 @@  discard block
 block discarded – undo
618 618
                 }
619 619
             }
620 620
 
621
-            foreach ( $media as $elem ) {
622
-                if ( ! empty( $css ) ) {
623
-                    if ( ! isset( $this->csscode[$elem] ) ) {
621
+            foreach ($media as $elem) {
622
+                if (!empty($css)) {
623
+                    if (!isset($this->csscode[$elem])) {
624 624
                         $this->csscode[$elem] = '';
625 625
                     }
626
-                    $this->csscode[$elem] .= "\n/*FILESTART*/" . $css;
626
+                    $this->csscode[$elem] .= "\n/*FILESTART*/".$css;
627 627
                 }
628 628
             }
629 629
         }
@@ -631,133 +631,133 @@  discard block
 block discarded – undo
631 631
         // Check for duplicate code.
632 632
         $md5list = array();
633 633
         $tmpcss  = $this->csscode;
634
-        foreach ( $tmpcss as $media => $code ) {
635
-            $md5sum    = md5( $code );
634
+        foreach ($tmpcss as $media => $code) {
635
+            $md5sum    = md5($code);
636 636
             $medianame = $media;
637
-            foreach ( $md5list as $med => $sum ) {
637
+            foreach ($md5list as $med => $sum) {
638 638
                 // If same code.
639
-                if ( $sum === $md5sum ) {
639
+                if ($sum === $md5sum) {
640 640
                     // Add the merged code.
641
-                    $medianame                 = $med . ', ' . $media;
641
+                    $medianame                 = $med.', '.$media;
642 642
                     $this->csscode[$medianame] = $code;
643 643
                     $md5list[$medianame]       = $md5list[$med];
644
-                    unset( $this->csscode[$med], $this->csscode[$media], $med5list[$med] );
644
+                    unset($this->csscode[$med], $this->csscode[$media], $med5list[$med]);
645 645
                 }
646 646
             }
647 647
             $md5list[$medianame] = $md5sum;
648 648
         }
649
-        unset( $tmpcss );
649
+        unset($tmpcss);
650 650
 
651 651
         // Manage @imports, while is for recursive import management.
652
-        foreach ( $this->csscode as &$thiscss ) {
652
+        foreach ($this->csscode as &$thiscss) {
653 653
             // Flag to trigger import reconstitution and var to hold external imports.
654 654
             $fiximports       = false;
655 655
             $external_imports = '';
656 656
 
657 657
             // remove comments to avoid importing commented-out imports.
658
-            $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss );
659
-            while ( preg_match_all( '#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches ) ) {
660
-                foreach ( $matches[0] as $import ) {
661
-                    if ( $this->isremovable( $import, $this->cssremovables ) ) {
662
-                        $thiscss = str_replace( $import, '', $thiscss );
658
+            $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss);
659
+            while (preg_match_all('#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches)) {
660
+                foreach ($matches[0] as $import) {
661
+                    if ($this->isremovable($import, $this->cssremovables)) {
662
+                        $thiscss = str_replace($import, '', $thiscss);
663 663
                         $import_ok = true;
664 664
                     } else {
665
-                        $url = trim( preg_replace( '#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim( $import ) ), " \t\n\r\0\x0B\"'" );
666
-                        $path = $this->getpath( $url );
665
+                        $url = trim(preg_replace('#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim($import)), " \t\n\r\0\x0B\"'");
666
+                        $path = $this->getpath($url);
667 667
                         $import_ok = false;
668
-                        if ( file_exists( $path ) && is_readable( $path ) ) {
669
-                            $code = addcslashes( self::fixurls( $path, file_get_contents( $path ) ), "\\" );
670
-                            $code = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $code );
671
-                            $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $code, '' );
672
-                            if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) {
668
+                        if (file_exists($path) && is_readable($path)) {
669
+                            $code = addcslashes(self::fixurls($path, file_get_contents($path)), "\\");
670
+                            $code = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $code);
671
+                            $tmpstyle = apply_filters('autoptimize_css_individual_style', $code, '');
672
+                            if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
673 673
                                 $code = $tmpstyle;
674 674
                                 $this->alreadyminified = true;
675
-                            } elseif ( $this->can_inject_late( $path, $code ) ) {
676
-                                $code = self::build_injectlater_marker( $path, md5( $code ) );
675
+                            } elseif ($this->can_inject_late($path, $code)) {
676
+                                $code = self::build_injectlater_marker($path, md5($code));
677 677
                             }
678 678
 
679
-                            if ( ! empty( $code ) ) {
680
-                                $tmp_thiscss = preg_replace( '#(/\*FILESTART\*/.*)' . preg_quote( $import, '#' ) . '#Us', '/*FILESTART2*/' . $code . '$1', $thiscss );
681
-                                if ( ! empty( $tmp_thiscss ) ) {
679
+                            if (!empty($code)) {
680
+                                $tmp_thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import, '#').'#Us', '/*FILESTART2*/'.$code.'$1', $thiscss);
681
+                                if (!empty($tmp_thiscss)) {
682 682
                                     $thiscss = $tmp_thiscss;
683 683
                                     $import_ok = true;
684
-                                    unset( $tmp_thiscss );
684
+                                    unset($tmp_thiscss);
685 685
                                 }
686 686
                             }
687
-                            unset( $code );
687
+                            unset($code);
688 688
                         }
689 689
                     }
690
-                    if ( ! $import_ok ) {
690
+                    if (!$import_ok) {
691 691
                         // External imports and general fall-back.
692 692
                         $external_imports .= $import;
693 693
 
694
-                        $thiscss    = str_replace( $import, '', $thiscss );
694
+                        $thiscss    = str_replace($import, '', $thiscss);
695 695
                         $fiximports = true;
696 696
                     }
697 697
                 }
698
-                $thiscss = preg_replace( '#/\*FILESTART\*/#', '', $thiscss );
699
-                $thiscss = preg_replace( '#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss );
698
+                $thiscss = preg_replace('#/\*FILESTART\*/#', '', $thiscss);
699
+                $thiscss = preg_replace('#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss);
700 700
 
701 701
                 // and update $thiscss_nocomments before going into next iteration in while loop.
702
-                $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss );
702
+                $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss);
703 703
             }
704
-            unset( $thiscss_nocomments );
704
+            unset($thiscss_nocomments);
705 705
 
706 706
             // Add external imports to top of aggregated CSS.
707
-            if ( $fiximports ) {
708
-                $thiscss = $external_imports . $thiscss;
707
+            if ($fiximports) {
708
+                $thiscss = $external_imports.$thiscss;
709 709
             }
710 710
         }
711
-        unset( $thiscss );
711
+        unset($thiscss);
712 712
 
713 713
         // $this->csscode has all the uncompressed code now.
714
-        foreach ( $this->csscode as &$code ) {
714
+        foreach ($this->csscode as &$code) {
715 715
             // Check for already-minified code.
716
-            $hash = md5( $code );
717
-            do_action( 'autoptimize_action_css_hash', $hash );
718
-            $ccheck = new autoptimizeCache( $hash, 'css' );
719
-            if ( $ccheck->check() ) {
716
+            $hash = md5($code);
717
+            do_action('autoptimize_action_css_hash', $hash);
718
+            $ccheck = new autoptimizeCache($hash, 'css');
719
+            if ($ccheck->check()) {
720 720
                 $code = $ccheck->retrieve();
721
-                $this->hashmap[md5( $code )] = $hash;
721
+                $this->hashmap[md5($code)] = $hash;
722 722
                 continue;
723 723
             }
724
-            unset( $ccheck );
724
+            unset($ccheck);
725 725
 
726 726
             // Rewrite and/or inline referenced assets.
727
-            $code = $this->rewrite_assets( $code );
727
+            $code = $this->rewrite_assets($code);
728 728
 
729 729
             // Minify.
730
-            $code = $this->run_minifier_on( $code );
730
+            $code = $this->run_minifier_on($code);
731 731
 
732 732
             // Bring back INJECTLATER stuff.
733
-            $code = $this->inject_minified( $code );
733
+            $code = $this->inject_minified($code);
734 734
 
735 735
             // Filter results.
736
-            $tmp_code = apply_filters( 'autoptimize_css_after_minify', $code );
737
-            if ( ! empty( $tmp_code ) ) {
736
+            $tmp_code = apply_filters('autoptimize_css_after_minify', $code);
737
+            if (!empty($tmp_code)) {
738 738
                 $code = $tmp_code;
739
-                unset( $tmp_code );
739
+                unset($tmp_code);
740 740
             }
741 741
 
742
-            $this->hashmap[md5( $code )] = $hash;
742
+            $this->hashmap[md5($code)] = $hash;
743 743
         }
744 744
 
745
-        unset( $code );
745
+        unset($code);
746 746
         return true;
747 747
     }
748 748
 
749
-    public function run_minifier_on( $code )
749
+    public function run_minifier_on($code)
750 750
     {
751
-        if ( ! $this->alreadyminified ) {
752
-            $do_minify = apply_filters( 'autoptimize_css_do_minify', true );
751
+        if (!$this->alreadyminified) {
752
+            $do_minify = apply_filters('autoptimize_css_do_minify', true);
753 753
 
754
-            if ( $do_minify ) {
754
+            if ($do_minify) {
755 755
                 $cssmin   = new autoptimizeCSSmin();
756
-                $tmp_code = trim( $cssmin->run( $code ) );
756
+                $tmp_code = trim($cssmin->run($code));
757 757
 
758
-                if ( ! empty( $tmp_code ) ) {
758
+                if (!empty($tmp_code)) {
759 759
                     $code = $tmp_code;
760
-                    unset( $tmp_code );
760
+                    unset($tmp_code);
761 761
                 }
762 762
             }
763 763
         }
@@ -769,14 +769,14 @@  discard block
 block discarded – undo
769 769
     public function cache()
770 770
     {
771 771
         // CSS cache.
772
-        foreach ( $this->csscode as $media => $code ) {
773
-            $md5 = $this->hashmap[md5( $code )];
774
-            $cache = new autoptimizeCache( $md5, 'css' );
775
-            if ( ! $cache->check() ) {
772
+        foreach ($this->csscode as $media => $code) {
773
+            $md5 = $this->hashmap[md5($code)];
774
+            $cache = new autoptimizeCache($md5, 'css');
775
+            if (!$cache->check()) {
776 776
                 // Cache our code.
777
-                $cache->cache( $code, 'text/css' );
777
+                $cache->cache($code, 'text/css');
778 778
             }
779
-            $this->url[$media] = AUTOPTIMIZE_CACHE_URL . $cache->getname();
779
+            $this->url[$media] = AUTOPTIMIZE_CACHE_URL.$cache->getname();
780 780
         }
781 781
     }
782 782
 
@@ -784,88 +784,88 @@  discard block
 block discarded – undo
784 784
     public function getcontent()
785 785
     {
786 786
         // restore comments.
787
-        $this->content = $this->restore_comments( $this->content );
787
+        $this->content = $this->restore_comments($this->content);
788 788
 
789 789
         // restore IE hacks.
790
-        $this->content = $this->restore_iehacks( $this->content );
790
+        $this->content = $this->restore_iehacks($this->content);
791 791
 
792 792
         // restore (no)script.
793
-        $this->content = $this->restore_marked_content( 'SCRIPT', $this->content );
793
+        $this->content = $this->restore_marked_content('SCRIPT', $this->content);
794 794
 
795 795
         // Restore noptimize.
796
-        $this->content = $this->restore_noptimize( $this->content );
796
+        $this->content = $this->restore_noptimize($this->content);
797 797
 
798 798
         // Restore the full content.
799
-        if ( ! empty( $this->restofcontent ) ) {
799
+        if (!empty($this->restofcontent)) {
800 800
             $this->content .= $this->restofcontent;
801 801
             $this->restofcontent = '';
802 802
         }
803 803
 
804 804
         // Inject the new stylesheets.
805
-        $replaceTag = array( '<title', 'before' );
806
-        $replaceTag = apply_filters( 'autoptimize_filter_css_replacetag', $replaceTag, $this->content );
805
+        $replaceTag = array('<title', 'before');
806
+        $replaceTag = apply_filters('autoptimize_filter_css_replacetag', $replaceTag, $this->content);
807 807
 
808
-        if ( $this->inline ) {
809
-            foreach ( $this->csscode as $media => $code ) {
810
-                $this->inject_in_html( '<style type="text/css" media="' . $media . '">' . $code . '</style>', $replaceTag );
808
+        if ($this->inline) {
809
+            foreach ($this->csscode as $media => $code) {
810
+                $this->inject_in_html('<style type="text/css" media="'.$media.'">'.$code.'</style>', $replaceTag);
811 811
             }
812 812
         } else {
813
-            if ( $this->defer ) {
813
+            if ($this->defer) {
814 814
                 $preloadCssBlock = '';
815 815
                 $noScriptCssBlock = "<noscript id=\"aonoscrcss\">";
816 816
 
817 817
                 $defer_inline_code = $this->defer_inline;
818
-                if ( ! empty( $defer_inline_code ) ) {
819
-                    if ( apply_filters( 'autoptimize_filter_css_critcss_minify', true ) ) {
820
-                        $iCssHash = md5( $defer_inline_code );
821
-                        $iCssCache = new autoptimizeCache( $iCssHash, 'css' );
822
-                        if ( $iCssCache->check() ) {
818
+                if (!empty($defer_inline_code)) {
819
+                    if (apply_filters('autoptimize_filter_css_critcss_minify', true)) {
820
+                        $iCssHash = md5($defer_inline_code);
821
+                        $iCssCache = new autoptimizeCache($iCssHash, 'css');
822
+                        if ($iCssCache->check()) {
823 823
                             // we have the optimized inline CSS in cache.
824 824
                             $defer_inline_code = $iCssCache->retrieve();
825 825
                         } else {
826 826
                             $cssmin   = new autoptimizeCSSmin();
827
-                            $tmp_code = trim( $cssmin->run( $defer_inline_code ) );
827
+                            $tmp_code = trim($cssmin->run($defer_inline_code));
828 828
 
829
-                            if ( ! empty( $tmp_code ) ) {
829
+                            if (!empty($tmp_code)) {
830 830
                                 $defer_inline_code = $tmp_code;
831
-                                $iCssCache->cache( $defer_inline_code, 'text/css' );
832
-                                unset( $tmp_code );
831
+                                $iCssCache->cache($defer_inline_code, 'text/css');
832
+                                unset($tmp_code);
833 833
                             }
834 834
                         }
835 835
                     }
836
-                    $code_out = '<style type="text/css" id="aoatfcss" media="all">' . $defer_inline_code . '</style>';
837
-                    $this->inject_in_html( $code_out, $replaceTag );
836
+                    $code_out = '<style type="text/css" id="aoatfcss" media="all">'.$defer_inline_code.'</style>';
837
+                    $this->inject_in_html($code_out, $replaceTag);
838 838
                 }
839 839
             }
840 840
 
841
-            foreach ( $this->url as $media => $url ) {
842
-                $url = $this->url_replace_cdn( $url );
841
+            foreach ($this->url as $media => $url) {
842
+                $url = $this->url_replace_cdn($url);
843 843
 
844 844
                 // Add the stylesheet either deferred (import at bottom) or normal links in head.
845
-                if ( $this->defer ) {
845
+                if ($this->defer) {
846 846
                     $preloadOnLoad = autoptimizeConfig::get_ao_css_preload_onload();
847 847
 
848
-                    $preloadCssBlock .= '<link rel="preload" as="style" media="' . $media . '" href="' . $url . '" onload="' . $preloadOnLoad . '" />';
849
-                    $noScriptCssBlock .= '<link type="text/css" media="' . $media . '" href="' . $url . '" rel="stylesheet" />';
848
+                    $preloadCssBlock .= '<link rel="preload" as="style" media="'.$media.'" href="'.$url.'" onload="'.$preloadOnLoad.'" />';
849
+                    $noScriptCssBlock .= '<link type="text/css" media="'.$media.'" href="'.$url.'" rel="stylesheet" />';
850 850
                 } else {
851 851
                     // $this->inject_in_html('<link type="text/css" media="' . $media . '" href="' . $url . '" rel="stylesheet" />', $replaceTag);
852
-                    if ( strlen( $this->csscode[$media] ) > $this->cssinlinesize ) {
853
-                        $this->inject_in_html( '<link type="text/css" media="' . $media . '" href="' . $url . '" rel="stylesheet" />', $replaceTag );
854
-                    } elseif ( strlen( $this->csscode[$media] ) > 0 ) {
855
-                        $this->inject_in_html( '<style type="text/css" media="' . $media . '">' . $this->csscode[$media] . '</style>', $replaceTag );
852
+                    if (strlen($this->csscode[$media]) > $this->cssinlinesize) {
853
+                        $this->inject_in_html('<link type="text/css" media="'.$media.'" href="'.$url.'" rel="stylesheet" />', $replaceTag);
854
+                    } elseif (strlen($this->csscode[$media]) > 0) {
855
+                        $this->inject_in_html('<style type="text/css" media="'.$media.'">'.$this->csscode[$media].'</style>', $replaceTag);
856 856
                     }
857 857
                 }
858 858
             }
859 859
 
860
-            if ( $this->defer ) {
860
+            if ($this->defer) {
861 861
                 $preload_polyfill = autoptimizeConfig::get_ao_css_preload_polyfill();
862 862
                 $noScriptCssBlock .= '</noscript>';
863
-                $this->inject_in_html( $preloadCssBlock . $noScriptCssBlock, $replaceTag );
863
+                $this->inject_in_html($preloadCssBlock.$noScriptCssBlock, $replaceTag);
864 864
 
865 865
                 // Adds preload polyfill at end of body tag.
866 866
                 $this->inject_in_html(
867
-                    apply_filters( 'autoptimize_css_preload_polyfill', $preload_polyfill ),
868
-                    array( '</body>', 'before' )
867
+                    apply_filters('autoptimize_css_preload_polyfill', $preload_polyfill),
868
+                    array('</body>', 'before')
869 869
                 );
870 870
             }
871 871
         }
@@ -874,44 +874,44 @@  discard block
 block discarded – undo
874 874
         return $this->content;
875 875
     }
876 876
 
877
-    static function fixurls( $file, $code )
877
+    static function fixurls($file, $code)
878 878
     {
879 879
         // Switch all imports to the url() syntax.
880
-        $code = preg_replace( '#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code );
880
+        $code = preg_replace('#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code);
881 881
 
882
-        if ( preg_match_all( self::ASSETS_REGEX, $code, $matches ) ) {
883
-            $file = str_replace( WP_ROOT_DIR, '/', $file );
882
+        if (preg_match_all(self::ASSETS_REGEX, $code, $matches)) {
883
+            $file = str_replace(WP_ROOT_DIR, '/', $file);
884 884
             /**
885 885
              * rollback as per https://github.com/futtta/autoptimize/issues/94
886 886
              * $file = str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', $file );
887 887
              */
888
-            $dir = dirname( $file ); // Like /themes/expound/css.
888
+            $dir = dirname($file); // Like /themes/expound/css.
889 889
 
890 890
             /**
891 891
              * $dir should not contain backslashes, since it's used to replace
892 892
              * urls, but it can contain them when running on Windows because
893 893
              * fixurls() is sometimes called with `ABSPATH . 'index.php'`
894 894
              */
895
-            $dir = str_replace( '\\', '/', $dir );
896
-            unset( $file ); // not used below at all.
895
+            $dir = str_replace('\\', '/', $dir);
896
+            unset($file); // not used below at all.
897 897
 
898 898
             $replace = array();
899
-            foreach ( $matches[1] as $k => $url ) {
899
+            foreach ($matches[1] as $k => $url) {
900 900
                 // Remove quotes.
901
-                $url    = trim( $url, " \t\n\r\0\x0B\"'" );
902
-                $noQurl = trim( $url, "\"'" );
903
-                if ( $url !== $noQurl ) {
901
+                $url    = trim($url, " \t\n\r\0\x0B\"'");
902
+                $noQurl = trim($url, "\"'");
903
+                if ($url !== $noQurl) {
904 904
                     $removedQuotes = true;
905 905
                 } else {
906 906
                     $removedQuotes = false;
907 907
                 }
908 908
 
909
-                if ( '' === $noQurl ) {
909
+                if ('' === $noQurl) {
910 910
                     continue;
911 911
                 }
912 912
 
913 913
                 $url = $noQurl;
914
-                if ( '/' === $url{0} || preg_match( '#^(https?://|ftp://|data:)#i', $url ) ) {
914
+                if ('/' === $url{0} || preg_match('#^(https?://|ftp://|data:)#i', $url)) {
915 915
                     // URL is protocol-relative, host-relative or something we don't touch.
916 916
                     continue;
917 917
                 } else {
@@ -920,49 +920,49 @@  discard block
 block discarded – undo
920 920
                      * rollback as per https://github.com/futtta/autoptimize/issues/94
921 921
                      * $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_CONTENT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) );
922 922
                      */
923
-                    $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_ROOT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) );
924
-                    $newurl = apply_filters( 'autoptimize_filter_css_fixurl_newurl', $newurl );
923
+                    $newurl = preg_replace('/https?:/', '', str_replace(' ', '%20', AUTOPTIMIZE_WP_ROOT_URL.str_replace('//', '/', $dir.'/'.$url)));
924
+                    $newurl = apply_filters('autoptimize_filter_css_fixurl_newurl', $newurl);
925 925
 
926 926
                     /**
927 927
                      * Hash the url + whatever was behind potentially for replacement
928 928
                      * We must do this, or different css classes referencing the same bg image (but
929 929
                      * different parts of it, say, in sprites and such) loose their stuff...
930 930
                      */
931
-                    $hash = md5( $url . $matches[2][$k] );
932
-                    $code = str_replace( $matches[0][$k], $hash, $code );
931
+                    $hash = md5($url.$matches[2][$k]);
932
+                    $code = str_replace($matches[0][$k], $hash, $code);
933 933
 
934
-                    if ( $removedQuotes ) {
935
-                        $replace[$hash] = "url('" . $newurl . "')" . $matches[2][$k];
934
+                    if ($removedQuotes) {
935
+                        $replace[$hash] = "url('".$newurl."')".$matches[2][$k];
936 936
                     } else {
937
-                        $replace[$hash] = 'url(' . $newurl . ')' . $matches[2][$k];
937
+                        $replace[$hash] = 'url('.$newurl.')'.$matches[2][$k];
938 938
                     }
939 939
                 }
940 940
             }
941 941
 
942
-            $code = self::replace_longest_matches_first( $code, $replace );
942
+            $code = self::replace_longest_matches_first($code, $replace);
943 943
         }
944 944
 
945 945
         return $code;
946 946
     }
947 947
 
948
-    private function ismovable( $tag )
948
+    private function ismovable($tag)
949 949
     {
950
-        if ( ! $this->aggregate ) {
950
+        if (!$this->aggregate) {
951 951
             return false;
952 952
         }
953 953
 
954
-        if ( ! empty( $this->whitelist ) ) {
955
-            foreach ( $this->whitelist as $match ) {
956
-                if ( false !== strpos( $tag, $match ) ) {
954
+        if (!empty($this->whitelist)) {
955
+            foreach ($this->whitelist as $match) {
956
+                if (false !== strpos($tag, $match)) {
957 957
                     return true;
958 958
                 }
959 959
             }
960 960
             // no match with whitelist.
961 961
             return false;
962 962
         } else {
963
-            if ( is_array( $this->dontmove ) && ! empty( $this->dontmove ) ) {
964
-                foreach ( $this->dontmove as $match ) {
965
-                    if ( false !== strpos( $tag, $match ) ) {
963
+            if (is_array($this->dontmove) && !empty($this->dontmove)) {
964
+                foreach ($this->dontmove as $match) {
965
+                    if (false !== strpos($tag, $match)) {
966 966
                         // Matched something.
967 967
                         return false;
968 968
                     }
@@ -974,22 +974,22 @@  discard block
 block discarded – undo
974 974
         }
975 975
     }
976 976
 
977
-    private function can_inject_late( $cssPath, $css )
977
+    private function can_inject_late($cssPath, $css)
978 978
     {
979
-        $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false, $cssPath );
980
-        if ( true !== $this->inject_min_late ) {
979
+        $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $cssPath);
980
+        if (true !== $this->inject_min_late) {
981 981
             // late-inject turned off.
982 982
             return false;
983
-        } elseif ( ( false === strpos( $cssPath, 'min.css' ) ) && ( str_replace( $consider_minified_array, '', $cssPath ) === $cssPath ) ) {
983
+        } elseif ((false === strpos($cssPath, 'min.css')) && (str_replace($consider_minified_array, '', $cssPath) === $cssPath)) {
984 984
             // file not minified based on filename & filter.
985 985
             return false;
986
-        } elseif ( false !== strpos( $css, '@import' ) ) {
986
+        } elseif (false !== strpos($css, '@import')) {
987 987
             // can't late-inject files with imports as those need to be aggregated.
988 988
             return false;
989
-        } elseif ( ( false !== strpos( $css, '@font-face' ) ) && ( apply_filters( 'autoptimize_filter_css_fonts_cdn', false ) === true ) && ( ! empty( $this->cdn_url ) ) ) {
989
+        } elseif ((false !== strpos($css, '@font-face')) && (apply_filters('autoptimize_filter_css_fonts_cdn', false) === true) && (!empty($this->cdn_url))) {
990 990
             // don't late-inject CSS with font-src's if fonts are set to be CDN'ed.
991 991
             return false;
992
-        } elseif ( ( ( $this->datauris == true ) || ( ! empty( $this->cdn_url ) ) ) && preg_match( '#background[^;}]*url\(#Ui', $css ) ) {
992
+        } elseif ((($this->datauris == true) || (!empty($this->cdn_url))) && preg_match('#background[^;}]*url\(#Ui', $css)) {
993 993
             // don't late-inject CSS with images if CDN is set OR if image inlining is on.
994 994
             return false;
995 995
         } else {
@@ -1007,32 +1007,32 @@  discard block
 block discarded – undo
1007 1007
      *
1008 1008
      * @return bool|string Url pointing to the minified css file or false.
1009 1009
      */
1010
-    public function minify_single( $filepath, $cache_miss = false )
1010
+    public function minify_single($filepath, $cache_miss = false)
1011 1011
     {
1012
-        $contents = $this->prepare_minify_single( $filepath );
1012
+        $contents = $this->prepare_minify_single($filepath);
1013 1013
 
1014
-        if ( empty( $contents ) ) {
1014
+        if (empty($contents)) {
1015 1015
             return false;
1016 1016
         }
1017 1017
 
1018 1018
         // Check cache.
1019
-        $hash  = 'single_' . md5( $contents );
1020
-        $cache = new autoptimizeCache( $hash, 'css' );
1019
+        $hash  = 'single_'.md5($contents);
1020
+        $cache = new autoptimizeCache($hash, 'css');
1021 1021
 
1022 1022
         // If not in cache already, minify...
1023
-        if ( ! $cache->check() || $cache_miss ) {
1023
+        if (!$cache->check() || $cache_miss) {
1024 1024
             // Fixurls...
1025
-            $contents = self::fixurls( $filepath, $contents );
1025
+            $contents = self::fixurls($filepath, $contents);
1026 1026
             // CDN-replace any referenced assets if needed...
1027
-            $contents = $this->replace_urls( $contents );
1027
+            $contents = $this->replace_urls($contents);
1028 1028
             // Now minify...
1029 1029
             $cssmin   = new autoptimizeCSSmin();
1030
-            $contents = trim( $cssmin->run( $contents ) );
1030
+            $contents = trim($cssmin->run($contents));
1031 1031
             // Store in cache.
1032
-            $cache->cache( $contents, 'text/css' );
1032
+            $cache->cache($contents, 'text/css');
1033 1033
         }
1034 1034
 
1035
-        $url = $this->build_minify_single_url( $cache );
1035
+        $url = $this->build_minify_single_url($cache);
1036 1036
 
1037 1037
         return $url;
1038 1038
     }
@@ -1052,18 +1052,18 @@  discard block
 block discarded – undo
1052 1052
         return $this->options;
1053 1053
     }
1054 1054
 
1055
-    public function replaceOptions( $options )
1055
+    public function replaceOptions($options)
1056 1056
     {
1057 1057
         $this->options = $options;
1058 1058
     }
1059 1059
 
1060
-    public function setOption( $name, $value )
1060
+    public function setOption($name, $value)
1061 1061
     {
1062 1062
         $this->options[$name] = $value;
1063 1063
         $this->$name = $value;
1064 1064
     }
1065 1065
 
1066
-    public function getOption( $name )
1066
+    public function getOption($name)
1067 1067
     {
1068 1068
         return $this->options[$name];
1069 1069
     }
Please login to merge, or discard this patch.