@@ -16,66 +16,66 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | |
19 | -if ( ! defined( 'ABSPATH' ) ) { |
|
19 | +if (!defined('ABSPATH')) { |
|
20 | 20 | exit; |
21 | 21 | } |
22 | 22 | |
23 | -define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.7.3' ); |
|
23 | +define('AUTOPTIMIZE_PLUGIN_VERSION', '2.7.3'); |
|
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.6', '<' ) ) { |
|
30 | +if (version_compare(PHP_VERSION, '5.6', '<')) { |
|
31 | 31 | function autoptimize_incompatible_admin_notice() { |
32 | - echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.6 (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.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize').'</p></div>'; |
|
33 | + if (isset($_GET['activate'])) { |
|
34 | + unset($_GET['activate']); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | function autoptimize_deactivate_self() { |
38 | - deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) ); |
|
38 | + deactivate_plugins(plugin_basename(AUTOPTIMIZE_PLUGIN_FILE)); |
|
39 | 39 | } |
40 | - add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' ); |
|
41 | - add_action( 'admin_init', 'autoptimize_deactivate_self' ); |
|
40 | + add_action('admin_notices', 'autoptimize_incompatible_admin_notice'); |
|
41 | + add_action('admin_init', 'autoptimize_deactivate_self'); |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | -function autoptimize_autoload( $class_name ) { |
|
46 | - if ( in_array( $class_name, array( 'Minify_HTML', 'JSMin' ) ) ) { |
|
47 | - $file = strtolower( $class_name ); |
|
48 | - $file = str_replace( '_', '-', $file ); |
|
49 | - $path = dirname( __FILE__ ) . '/classes/external/php/'; |
|
50 | - $filepath = $path . $file . '.php'; |
|
51 | - } elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) { |
|
52 | - $file = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name ); |
|
53 | - $path = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/'; |
|
54 | - $filepath = $path . $file . '.php'; |
|
55 | - } elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) { |
|
45 | +function autoptimize_autoload($class_name) { |
|
46 | + if (in_array($class_name, array('Minify_HTML', 'JSMin'))) { |
|
47 | + $file = strtolower($class_name); |
|
48 | + $file = str_replace('_', '-', $file); |
|
49 | + $path = dirname(__FILE__).'/classes/external/php/'; |
|
50 | + $filepath = $path.$file.'.php'; |
|
51 | + } elseif (false !== strpos($class_name, 'Autoptimize\\tubalmartin\\CssMin')) { |
|
52 | + $file = str_replace('Autoptimize\\tubalmartin\\CssMin\\', '', $class_name); |
|
53 | + $path = dirname(__FILE__).'/classes/external/php/yui-php-cssmin-bundled/'; |
|
54 | + $filepath = $path.$file.'.php'; |
|
55 | + } elseif ('autoptimize' === substr($class_name, 0, 11)) { |
|
56 | 56 | // One of our "old" classes. |
57 | 57 | $file = $class_name; |
58 | - $path = dirname( __FILE__ ) . '/classes/'; |
|
59 | - $filepath = $path . $file . '.php'; |
|
60 | - } elseif ( 'PAnD' === $class_name ) { |
|
58 | + $path = dirname(__FILE__).'/classes/'; |
|
59 | + $filepath = $path.$file.'.php'; |
|
60 | + } elseif ('PAnD' === $class_name) { |
|
61 | 61 | $file = 'persist-admin-notices-dismissal'; |
62 | - $path = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/'; |
|
63 | - $filepath = $path . $file . '.php'; |
|
62 | + $path = dirname(__FILE__).'/classes/external/php/persist-admin-notices-dismissal/'; |
|
63 | + $filepath = $path.$file.'.php'; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // If we didn't match one of our rules, bail! |
67 | - if ( ! isset( $filepath ) ) { |
|
67 | + if (!isset($filepath)) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | 71 | require $filepath; |
72 | 72 | } |
73 | 73 | |
74 | -spl_autoload_register( 'autoptimize_autoload' ); |
|
74 | +spl_autoload_register('autoptimize_autoload'); |
|
75 | 75 | |
76 | 76 | // Load WP CLI command(s) on demand. |
77 | -if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
78 | - require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php'; |
|
77 | +if (defined('WP_CLI') && WP_CLI) { |
|
78 | + require AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php'; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | function autoptimize() { |
87 | 87 | static $plugin = null; |
88 | 88 | |
89 | - if ( null === $plugin ) { |
|
90 | - $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE ); |
|
89 | + if (null === $plugin) { |
|
90 | + $plugin = new autoptimizeMain(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $plugin; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * processes the queue, submitting jobs to criticalcss.com and retrieving generated CSS from criticalcss.com and saving rules. |
5 | 5 | */ |
6 | 6 | |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -13,23 +13,23 @@ discard block |
||
13 | 13 | { |
14 | 14 | // fetch all options at once and populate them individually explicitely as globals. |
15 | 15 | $all_options = autoptimizeCriticalCSSBase::fetch_options(); |
16 | - foreach ( $all_options as $_option => $_value ) { |
|
16 | + foreach ($all_options as $_option => $_value) { |
|
17 | 17 | global ${$_option}; |
18 | 18 | ${$_option} = $_value; |
19 | 19 | } |
20 | 20 | |
21 | 21 | // Add queue control to a registered event. |
22 | - add_action( 'ao_ccss_queue', array( $this, 'ao_ccss_queue_control' ) ); |
|
22 | + add_action('ao_ccss_queue', array($this, 'ao_ccss_queue_control')); |
|
23 | 23 | // Add cleaning job to a registered event. |
24 | - add_action( 'ao_ccss_maintenance', array( $this, 'ao_ccss_cleaning' ) ); |
|
24 | + add_action('ao_ccss_maintenance', array($this, 'ao_ccss_cleaning')); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function ao_ccss_queue_control() { |
28 | 28 | // The queue execution backend. |
29 | 29 | global $ao_ccss_key; |
30 | - if ( ! isset( $ao_ccss_key ) || empty( $ao_ccss_key ) ) { |
|
30 | + if (!isset($ao_ccss_key) || empty($ao_ccss_key)) { |
|
31 | 31 | // no key set, not processing the queue! |
32 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'No key set, so not processing queue.', 3 ); |
|
32 | + autoptimizeCriticalCSSCore::ao_ccss_log('No key set, so not processing queue.', 3); |
|
33 | 33 | return; |
34 | 34 | } |
35 | 35 | |
@@ -50,35 +50,35 @@ discard block |
||
50 | 50 | * When properly set, queue will always finish a job with the declared settings above regardless of the real API responses. |
51 | 51 | */ |
52 | 52 | $queue_debug = false; |
53 | - if ( file_exists( AO_CCSS_DEBUG ) ) { |
|
54 | - $qdobj_raw = file_get_contents( AO_CCSS_DEBUG ); |
|
55 | - $qdobj = json_decode( $qdobj_raw, true ); |
|
56 | - if ( $qdobj ) { |
|
57 | - if ( 1 === $qdobj['enable'] ) { |
|
53 | + if (file_exists(AO_CCSS_DEBUG)) { |
|
54 | + $qdobj_raw = file_get_contents(AO_CCSS_DEBUG); |
|
55 | + $qdobj = json_decode($qdobj_raw, true); |
|
56 | + if ($qdobj) { |
|
57 | + if (1 === $qdobj['enable']) { |
|
58 | 58 | $queue_debug = true; |
59 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue operating in debug mode with the following settings: <' . $qdobj_raw . '>', 3 ); |
|
59 | + autoptimizeCriticalCSSCore::ao_ccss_log('Queue operating in debug mode with the following settings: <'.$qdobj_raw.'>', 3); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | // Set some default values for $qdobj to avoid function call warnings. |
65 | - if ( ! $queue_debug ) { |
|
65 | + if (!$queue_debug) { |
|
66 | 66 | $qdobj['htcode'] = false; |
67 | 67 | } |
68 | 68 | |
69 | 69 | // Check if queue is already running. |
70 | 70 | $queue_lock = false; |
71 | - if ( file_exists( AO_CCSS_LOCK ) ) { |
|
71 | + if (file_exists(AO_CCSS_LOCK)) { |
|
72 | 72 | $queue_lock = true; |
73 | 73 | } |
74 | 74 | |
75 | 75 | // Proceed with the queue if it's not already running. |
76 | - if ( ! $queue_lock ) { |
|
76 | + if (!$queue_lock) { |
|
77 | 77 | |
78 | 78 | // Log queue start and create the lock file. |
79 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control started', 3 ); |
|
80 | - if ( touch( AO_CCSS_LOCK ) ) { |
|
81 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control locked', 3 ); |
|
79 | + autoptimizeCriticalCSSCore::ao_ccss_log('Queue control started', 3); |
|
80 | + if (touch(AO_CCSS_LOCK)) { |
|
81 | + autoptimizeCriticalCSSCore::ao_ccss_log('Queue control locked', 3); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // Attach required variables. |
@@ -88,218 +88,218 @@ discard block |
||
88 | 88 | // Initialize job counters. |
89 | 89 | $jc = 1; |
90 | 90 | $jr = 1; |
91 | - $jt = count( $ao_ccss_queue ); |
|
91 | + $jt = count($ao_ccss_queue); |
|
92 | 92 | |
93 | 93 | // Sort queue by ascending job status (e.g. ERROR, JOB_ONGOING, JOB_QUEUED, NEW...). |
94 | - array_multisort( array_column( $ao_ccss_queue, 'jqstat' ), $ao_ccss_queue ); // @codingStandardsIgnoreLine |
|
94 | + array_multisort(array_column($ao_ccss_queue, 'jqstat'), $ao_ccss_queue); // @codingStandardsIgnoreLine |
|
95 | 95 | |
96 | 96 | // Iterates over the entire queue. |
97 | - foreach ( $ao_ccss_queue as $path => $jprops ) { |
|
97 | + foreach ($ao_ccss_queue as $path => $jprops) { |
|
98 | 98 | // Prepare flags and target rule. |
99 | 99 | $update = false; |
100 | 100 | $deljob = false; |
101 | 101 | $rule_update = false; |
102 | 102 | $oldccssfile = false; |
103 | - $trule = explode( '|', $jprops['rtarget'] ); |
|
103 | + $trule = explode('|', $jprops['rtarget']); |
|
104 | 104 | |
105 | 105 | // Log job count. |
106 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Processing job ' . $jc . ' of ' . $jt . ' with id <' . $jprops['ljid'] . '> and status <' . $jprops['jqstat'] . '>', 3 ); |
|
106 | + autoptimizeCriticalCSSCore::ao_ccss_log('Processing job '.$jc.' of '.$jt.' with id <'.$jprops['ljid'].'> and status <'.$jprops['jqstat'].'>', 3); |
|
107 | 107 | |
108 | 108 | // Process NEW jobs. |
109 | - if ( 'NEW' == $jprops['jqstat'] ) { |
|
109 | + if ('NEW' == $jprops['jqstat']) { |
|
110 | 110 | |
111 | 111 | // Log the new job. |
112 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Found NEW job with local ID <' . $jprops['ljid'] . '>, starting its queue processing', 3 ); |
|
112 | + autoptimizeCriticalCSSCore::ao_ccss_log('Found NEW job with local ID <'.$jprops['ljid'].'>, starting its queue processing', 3); |
|
113 | 113 | |
114 | 114 | // Compare job and rule hashes (if any). |
115 | - $hash = $this->ao_ccss_diff_hashes( $jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget'] ); |
|
115 | + $hash = $this->ao_ccss_diff_hashes($jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget']); |
|
116 | 116 | |
117 | 117 | // If job hash is new or different of a previous one. |
118 | - if ( $hash ) { |
|
118 | + if ($hash) { |
|
119 | 119 | // Set job hash. |
120 | 120 | $jprops['hash'] = $hash; |
121 | 121 | |
122 | 122 | // If this is not the first job, wait 10 seconds before process next job due criticalcss.com API limits. |
123 | - if ( $jr > 1 ) { |
|
124 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Waiting ' . AO_CCSS_SLEEP . ' seconds due to criticalcss.com API limits', 3 ); |
|
125 | - sleep( AO_CCSS_SLEEP ); |
|
123 | + if ($jr > 1) { |
|
124 | + autoptimizeCriticalCSSCore::ao_ccss_log('Waiting '.AO_CCSS_SLEEP.' seconds due to criticalcss.com API limits', 3); |
|
125 | + sleep(AO_CCSS_SLEEP); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | // Dispatch the job generate request and increment request count. |
129 | - $apireq = $this->ao_ccss_api_generate( $path, $queue_debug, $qdobj['htcode'] ); |
|
129 | + $apireq = $this->ao_ccss_api_generate($path, $queue_debug, $qdobj['htcode']); |
|
130 | 130 | $jr++; |
131 | 131 | |
132 | 132 | // NOTE: All the following conditions maps to the ones in admin_settings_queue.js.php. |
133 | - if ( 'JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status'] ) { |
|
133 | + if ('JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status']) { |
|
134 | 134 | // SUCCESS: request has a valid result. |
135 | 135 | // Update job properties. |
136 | 136 | $jprops['jid'] = $apireq['job']['id']; |
137 | 137 | $jprops['jqstat'] = $apireq['job']['status']; |
138 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> generate request successful, remote id <' . $jprops['jid'] . '>, status now is <' . $jprops['jqstat'] . '>', 3 ); |
|
139 | - } elseif ( 'STATUS_JOB_BAD' == $apireq['job']['status'] ) { |
|
138 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> generate request successful, remote id <'.$jprops['jid'].'>, status now is <'.$jprops['jqstat'].'>', 3); |
|
139 | + } elseif ('STATUS_JOB_BAD' == $apireq['job']['status']) { |
|
140 | 140 | // ERROR: concurrent requests |
141 | 141 | // Update job properties. |
142 | 142 | $jprops['jid'] = $apireq['job']['id']; |
143 | 143 | $jprops['jqstat'] = $apireq['job']['status']; |
144 | 144 | $jprops['jrstat'] = $apireq['error']; |
145 | 145 | $jprops['jvstat'] = 'NONE'; |
146 | - $jprops['jftime'] = microtime( true ); |
|
147 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Concurrent requests when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 ); |
|
148 | - } elseif ( 'INVALID_JWT_TOKEN' == $apireq['errorCode'] ) { |
|
146 | + $jprops['jftime'] = microtime(true); |
|
147 | + autoptimizeCriticalCSSCore::ao_ccss_log('Concurrent requests when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3); |
|
148 | + } elseif ('INVALID_JWT_TOKEN' == $apireq['errorCode']) { |
|
149 | 149 | // ERROR: key validation |
150 | 150 | // Update job properties. |
151 | 151 | $jprops['jqstat'] = $apireq['errorCode']; |
152 | 152 | $jprops['jrstat'] = $apireq['error']; |
153 | 153 | $jprops['jvstat'] = 'NONE'; |
154 | - $jprops['jftime'] = microtime( true ); |
|
155 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'API key validation error when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 ); |
|
156 | - } elseif ( empty( $apireq ) ) { |
|
154 | + $jprops['jftime'] = microtime(true); |
|
155 | + autoptimizeCriticalCSSCore::ao_ccss_log('API key validation error when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3); |
|
156 | + } elseif (empty($apireq)) { |
|
157 | 157 | // ERROR: no response |
158 | 158 | // Update job properties. |
159 | 159 | $jprops['jqstat'] = 'NO_RESPONSE'; |
160 | 160 | $jprops['jrstat'] = 'NONE'; |
161 | 161 | $jprops['jvstat'] = 'NONE'; |
162 | - $jprops['jftime'] = microtime( true ); |
|
163 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 ); |
|
162 | + $jprops['jftime'] = microtime(true); |
|
163 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3); |
|
164 | 164 | } else { |
165 | 165 | // UNKNOWN: unhandled generate exception |
166 | 166 | // Update job properties. |
167 | 167 | $jprops['jqstat'] = 'JOB_UNKNOWN'; |
168 | 168 | $jprops['jrstat'] = 'NONE'; |
169 | 169 | $jprops['jvstat'] = 'NONE'; |
170 | - $jprops['jftime'] = microtime( true ); |
|
171 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> generate request has an UNKNOWN condition, status now is <' . $jprops['jqstat'] . '>, check log messages above for more information', 2 ); |
|
172 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 ); |
|
170 | + $jprops['jftime'] = microtime(true); |
|
171 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> generate request has an UNKNOWN condition, status now is <'.$jprops['jqstat'].'>, check log messages above for more information', 2); |
|
172 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3); |
|
173 | 173 | } |
174 | 174 | } else { |
175 | 175 | // SUCCESS: Job hash is equal to a previous one, so it's done |
176 | 176 | // Update job status and finish time. |
177 | 177 | $jprops['jqstat'] = 'JOB_DONE'; |
178 | - $jprops['jftime'] = microtime( true ); |
|
179 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> requires no further processing, status now is <' . $jprops['jqstat'] . '>', 3 ); |
|
178 | + $jprops['jftime'] = microtime(true); |
|
179 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> requires no further processing, status now is <'.$jprops['jqstat'].'>', 3); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Set queue update flag. |
183 | 183 | $update = true; |
184 | 184 | |
185 | - } elseif ( 'JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat'] ) { |
|
185 | + } elseif ('JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat']) { |
|
186 | 186 | // Process QUEUED and ONGOING jobs |
187 | 187 | // Log the pending job. |
188 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Found PENDING job with local ID <' . $jprops['ljid'] . '>, continuing its queue processing', 3 ); |
|
188 | + autoptimizeCriticalCSSCore::ao_ccss_log('Found PENDING job with local ID <'.$jprops['ljid'].'>, continuing its queue processing', 3); |
|
189 | 189 | |
190 | 190 | // If this is not the first job, wait before process next job due criticalcss.com API limits. |
191 | - if ( $jr > 1 ) { |
|
192 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Waiting ' . AO_CCSS_SLEEP . ' seconds due to criticalcss.com API limits', 3 ); |
|
193 | - sleep( AO_CCSS_SLEEP ); |
|
191 | + if ($jr > 1) { |
|
192 | + autoptimizeCriticalCSSCore::ao_ccss_log('Waiting '.AO_CCSS_SLEEP.' seconds due to criticalcss.com API limits', 3); |
|
193 | + sleep(AO_CCSS_SLEEP); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | // Dispatch the job result request and increment request count. |
197 | - $apireq = $this->ao_ccss_api_results( $jprops['jid'], $queue_debug, $qdobj['htcode'] ); |
|
197 | + $apireq = $this->ao_ccss_api_results($jprops['jid'], $queue_debug, $qdobj['htcode']); |
|
198 | 198 | $jr++; |
199 | 199 | |
200 | 200 | // NOTE: All the following condigitons maps to the ones in admin_settings_queue.js.php |
201 | 201 | // Replace API response values if queue debugging is enabled and some value is set. |
202 | - if ( $queue_debug ) { |
|
203 | - if ( $qdobj['status'] ) { |
|
202 | + if ($queue_debug) { |
|
203 | + if ($qdobj['status']) { |
|
204 | 204 | $apireq['status'] = $qdobj['status']; |
205 | 205 | } |
206 | - if ( $qdobj['resultStatus'] ) { |
|
206 | + if ($qdobj['resultStatus']) { |
|
207 | 207 | $apireq['resultStatus'] = $qdobj['resultStatus']; |
208 | 208 | } |
209 | - if ( $qdobj['validationStatus'] ) { |
|
209 | + if ($qdobj['validationStatus']) { |
|
210 | 210 | $apireq['validationStatus'] = $qdobj['validationStatus']; |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - if ( 'JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status'] ) { |
|
214 | + if ('JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status']) { |
|
215 | 215 | // SUCCESS: request has a valid result |
216 | 216 | // Process a PENDING job |
217 | 217 | // Update job properties. |
218 | 218 | $jprops['jqstat'] = $apireq['status']; |
219 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '> unchanged', 3 ); |
|
220 | - } elseif ( 'JOB_DONE' == $apireq['status'] ) { |
|
219 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'> unchanged', 3); |
|
220 | + } elseif ('JOB_DONE' == $apireq['status']) { |
|
221 | 221 | // Process a DONE job |
222 | 222 | // New resultStatus from ccss.com "HTML_404", consider as "GOOD" for now. |
223 | - if ( 'HTML_404' == $apireq['resultStatus'] ) { |
|
223 | + if ('HTML_404' == $apireq['resultStatus']) { |
|
224 | 224 | $apireq['resultStatus'] = 'GOOD'; |
225 | 225 | } |
226 | 226 | |
227 | - if ( 'GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus'] ) { |
|
227 | + if ('GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus']) { |
|
228 | 228 | // SUCCESS: GOOD job with GOOD validation |
229 | 229 | // Update job properties. |
230 | - $jprops['file'] = $this->ao_ccss_save_file( $apireq['css'], $trule, false ); |
|
230 | + $jprops['file'] = $this->ao_ccss_save_file($apireq['css'], $trule, false); |
|
231 | 231 | $jprops['jqstat'] = $apireq['status']; |
232 | 232 | $jprops['jrstat'] = $apireq['resultStatus']; |
233 | 233 | $jprops['jvstat'] = $apireq['validationStatus']; |
234 | - $jprops['jftime'] = microtime( true ); |
|
234 | + $jprops['jftime'] = microtime(true); |
|
235 | 235 | $rule_update = true; |
236 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '>, file saved <' . $jprops['file'] . '>', 3 ); |
|
237 | - } elseif ( 'GOOD' == $apireq['resultStatus'] && ( 'WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'] ) ) { |
|
236 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'>, file saved <'.$jprops['file'].'>', 3); |
|
237 | + } elseif ('GOOD' == $apireq['resultStatus'] && ('WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'])) { |
|
238 | 238 | // SUCCESS: GOOD job with WARN or BAD validation |
239 | 239 | // Update job properties. |
240 | - $jprops['file'] = $this->ao_ccss_save_file( $apireq['css'], $trule, true ); |
|
240 | + $jprops['file'] = $this->ao_ccss_save_file($apireq['css'], $trule, true); |
|
241 | 241 | $jprops['jqstat'] = $apireq['status']; |
242 | 242 | $jprops['jrstat'] = $apireq['resultStatus']; |
243 | 243 | $jprops['jvstat'] = $apireq['validationStatus']; |
244 | - $jprops['jftime'] = microtime( true ); |
|
244 | + $jprops['jftime'] = microtime(true); |
|
245 | 245 | $rule_update = true; |
246 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . ', file saved <' . $jprops['file'] . '> but requires REVIEW', 3 ); |
|
247 | - } elseif ( 'GOOD' != $apireq['resultStatus'] && ( 'GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'] ) ) { |
|
246 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].', file saved <'.$jprops['file'].'> but requires REVIEW', 3); |
|
247 | + } elseif ('GOOD' != $apireq['resultStatus'] && ('GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'])) { |
|
248 | 248 | // ERROR: no GOOD, WARN or BAD results |
249 | 249 | // Update job properties. |
250 | 250 | $jprops['jqstat'] = $apireq['status']; |
251 | 251 | $jprops['jrstat'] = $apireq['resultStatus']; |
252 | 252 | $jprops['jvstat'] = $apireq['validationStatus']; |
253 | - $jprops['jftime'] = microtime( true ); |
|
254 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 ); |
|
253 | + $jprops['jftime'] = microtime(true); |
|
254 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3); |
|
255 | 255 | $apireq['css'] = '/* critical css removed for DEBUG logging purposes */'; |
256 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 ); |
|
256 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3); |
|
257 | 257 | } else { |
258 | 258 | // UNKNOWN: unhandled JOB_DONE exception |
259 | 259 | // Update job properties. |
260 | 260 | $jprops['jqstat'] = 'JOB_UNKNOWN'; |
261 | 261 | $jprops['jrstat'] = $apireq['resultStatus']; |
262 | 262 | $jprops['jvstat'] = $apireq['validationStatus']; |
263 | - $jprops['jftime'] = microtime( true ); |
|
264 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job is UNKNOWN, status now is <' . $jprops['jqstat'] . '>', 2 ); |
|
263 | + $jprops['jftime'] = microtime(true); |
|
264 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job is UNKNOWN, status now is <'.$jprops['jqstat'].'>', 2); |
|
265 | 265 | $apireq['css'] = '/* critical css removed for DEBUG logging purposes */'; |
266 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 ); |
|
266 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3); |
|
267 | 267 | } |
268 | - } elseif ( 'JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status'] ) { |
|
268 | + } elseif ('JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status']) { |
|
269 | 269 | // ERROR: failed job |
270 | 270 | // Update job properties. |
271 | 271 | $jprops['jqstat'] = $apireq['job']['status']; |
272 | - if ( $apireq['error'] ) { |
|
272 | + if ($apireq['error']) { |
|
273 | 273 | $jprops['jrstat'] = $apireq['job']['error']; |
274 | 274 | } else { |
275 | 275 | } |
276 | 276 | $jprops['jvstat'] = 'NONE'; |
277 | - $jprops['jftime'] = microtime( true ); |
|
278 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 ); |
|
279 | - } elseif ( 'This css no longer exists. Please re-generate it.' == $apireq['error'] ) { |
|
277 | + $jprops['jftime'] = microtime(true); |
|
278 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3); |
|
279 | + } elseif ('This css no longer exists. Please re-generate it.' == $apireq['error']) { |
|
280 | 280 | // ERROR: CSS doesn't exist |
281 | 281 | // Update job properties. |
282 | 282 | $jprops['jqstat'] = 'NO_CSS'; |
283 | 283 | $jprops['jrstat'] = $apireq['error']; |
284 | 284 | $jprops['jvstat'] = 'NONE'; |
285 | - $jprops['jftime'] = microtime( true ); |
|
286 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 ); |
|
287 | - } elseif ( empty( $apireq ) ) { |
|
285 | + $jprops['jftime'] = microtime(true); |
|
286 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3); |
|
287 | + } elseif (empty($apireq)) { |
|
288 | 288 | // ERROR: no response |
289 | 289 | // Update job properties. |
290 | 290 | $jprops['jqstat'] = 'NO_RESPONSE'; |
291 | 291 | $jprops['jrstat'] = 'NONE'; |
292 | 292 | $jprops['jvstat'] = 'NONE'; |
293 | - $jprops['jftime'] = microtime( true ); |
|
294 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 ); |
|
293 | + $jprops['jftime'] = microtime(true); |
|
294 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3); |
|
295 | 295 | } else { |
296 | 296 | // UNKNOWN: unhandled results exception |
297 | 297 | // Update job properties. |
298 | 298 | $jprops['jqstat'] = 'JOB_UNKNOWN'; |
299 | 299 | $jprops['jrstat'] = 'NONE'; |
300 | 300 | $jprops['jvstat'] = 'NONE'; |
301 | - $jprops['jftime'] = microtime( true ); |
|
302 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request has an UNKNOWN condition, status now is <' . $jprops['jqstat'] . '>, check log messages above for more information', 2 ); |
|
301 | + $jprops['jftime'] = microtime(true); |
|
302 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request has an UNKNOWN condition, status now is <'.$jprops['jqstat'].'>, check log messages above for more information', 2); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | // Set queue update flag. |
@@ -307,40 +307,40 @@ discard block |
||
307 | 307 | } |
308 | 308 | |
309 | 309 | // Mark DONE jobs for removal. |
310 | - if ( 'JOB_DONE' == $jprops['jqstat'] ) { |
|
310 | + if ('JOB_DONE' == $jprops['jqstat']) { |
|
311 | 311 | $update = true; |
312 | 312 | $deljob = true; |
313 | 313 | } |
314 | 314 | |
315 | 315 | // Persist updated queue object. |
316 | - if ( $update ) { |
|
317 | - if ( ! $deljob ) { |
|
316 | + if ($update) { |
|
317 | + if (!$deljob) { |
|
318 | 318 | // Update properties of a NEW or PENDING job... |
319 | - $ao_ccss_queue[ $path ] = $jprops; |
|
319 | + $ao_ccss_queue[$path] = $jprops; |
|
320 | 320 | } else { |
321 | 321 | // ...or remove the DONE job. |
322 | - unset( $ao_ccss_queue[ $path ] ); |
|
323 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> is DONE and was removed from the queue', 3 ); |
|
322 | + unset($ao_ccss_queue[$path]); |
|
323 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> is DONE and was removed from the queue', 3); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | // Update queue object. |
327 | - $ao_ccss_queue_raw = json_encode( $ao_ccss_queue ); |
|
328 | - update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false ); |
|
329 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue updated by job id <' . $jprops['ljid'] . '>', 3 ); |
|
327 | + $ao_ccss_queue_raw = json_encode($ao_ccss_queue); |
|
328 | + update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false); |
|
329 | + autoptimizeCriticalCSSCore::ao_ccss_log('Queue updated by job id <'.$jprops['ljid'].'>', 3); |
|
330 | 330 | |
331 | 331 | // Update target rule. |
332 | - if ( $rule_update ) { |
|
333 | - $this->ao_ccss_rule_update( $jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash'] ); |
|
334 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> updated the target rule <' . $jprops['rtarget'] . '>', 3 ); |
|
332 | + if ($rule_update) { |
|
333 | + $this->ao_ccss_rule_update($jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash']); |
|
334 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> updated the target rule <'.$jprops['rtarget'].'>', 3); |
|
335 | 335 | } |
336 | 336 | } else { |
337 | 337 | // Or log no queue action. |
338 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Nothing to do on this job', 3 ); |
|
338 | + autoptimizeCriticalCSSCore::ao_ccss_log('Nothing to do on this job', 3); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | // Break the loop if request limit is set and was reached. |
342 | - if ( $ao_ccss_rlimit && $ao_ccss_rlimit == $jr ) { |
|
343 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'The limit of ' . $ao_ccss_rlimit . ' request(s) to criticalcss.com was reached, queue control must finish now', 3 ); |
|
342 | + if ($ao_ccss_rlimit && $ao_ccss_rlimit == $jr) { |
|
343 | + autoptimizeCriticalCSSCore::ao_ccss_log('The limit of '.$ao_ccss_rlimit.' request(s) to criticalcss.com was reached, queue control must finish now', 3); |
|
344 | 344 | break; |
345 | 345 | } |
346 | 346 | |
@@ -349,46 +349,46 @@ discard block |
||
349 | 349 | } |
350 | 350 | |
351 | 351 | // Remove the lock file and log the queue end. |
352 | - if ( file_exists( AO_CCSS_LOCK ) ) { |
|
353 | - unlink( AO_CCSS_LOCK ); |
|
354 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control unlocked', 3 ); |
|
352 | + if (file_exists(AO_CCSS_LOCK)) { |
|
353 | + unlink(AO_CCSS_LOCK); |
|
354 | + autoptimizeCriticalCSSCore::ao_ccss_log('Queue control unlocked', 3); |
|
355 | 355 | } |
356 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control finished', 3 ); |
|
356 | + autoptimizeCriticalCSSCore::ao_ccss_log('Queue control finished', 3); |
|
357 | 357 | |
358 | 358 | // Log that queue is locked. |
359 | 359 | } else { |
360 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue is already running, skipping the attempt to run it again', 3 ); |
|
360 | + autoptimizeCriticalCSSCore::ao_ccss_log('Queue is already running, skipping the attempt to run it again', 3); |
|
361 | 361 | } |
362 | 362 | } |
363 | 363 | |
364 | - public function ao_ccss_diff_hashes( $ljid, $hash, $hashes, $rule ) { |
|
364 | + public function ao_ccss_diff_hashes($ljid, $hash, $hashes, $rule) { |
|
365 | 365 | // Compare job hashes |
366 | 366 | // STEP 1: update job hashes. |
367 | - if ( 1 == count( $hashes ) ) { |
|
367 | + if (1 == count($hashes)) { |
|
368 | 368 | // Job with a single hash |
369 | 369 | // Set job hash. |
370 | 370 | $hash = $hashes[0]; |
371 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with SINGLE hash <' . $hash . '>', 3 ); |
|
371 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with SINGLE hash <'.$hash.'>', 3); |
|
372 | 372 | } else { |
373 | 373 | // Job with multiple hashes |
374 | 374 | // Loop through hashes to concatenate them. |
375 | 375 | $nhash = ''; |
376 | - foreach ( $hashes as $shash ) { |
|
376 | + foreach ($hashes as $shash) { |
|
377 | 377 | $nhash .= $shash; |
378 | 378 | } |
379 | 379 | |
380 | 380 | // Set job hash. |
381 | - $hash = md5( $nhash ); |
|
382 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with a COMPOSITE hash <' . $hash . '>', 3 ); |
|
381 | + $hash = md5($nhash); |
|
382 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with a COMPOSITE hash <'.$hash.'>', 3); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | // STEP 2: compare job to existing jobs to prevent double submission for same type+hash. |
386 | 386 | global $ao_ccss_queue; |
387 | 387 | |
388 | - foreach ( $ao_ccss_queue as $queue_item ) { |
|
389 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Comparing <' . $rule . $hash . '> with <' . $queue_item['rtarget'] . $queue_item['hash'] . '>', 3 ); |
|
390 | - if ( $queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array( $queue_item['jqstat'], array( 'JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE' ) ) ) { |
|
391 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the already pending job <' . $queue_item['ljid'] . '>', 3 ); |
|
388 | + foreach ($ao_ccss_queue as $queue_item) { |
|
389 | + autoptimizeCriticalCSSCore::ao_ccss_log('Comparing <'.$rule.$hash.'> with <'.$queue_item['rtarget'].$queue_item['hash'].'>', 3); |
|
390 | + if ($queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array($queue_item['jqstat'], array('JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE'))) { |
|
391 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the already pending job <'.$queue_item['ljid'].'>', 3); |
|
392 | 392 | return false; |
393 | 393 | } |
394 | 394 | } |
@@ -398,32 +398,32 @@ discard block |
||
398 | 398 | global $ao_ccss_rules; |
399 | 399 | |
400 | 400 | // Prepare rule variables. |
401 | - $trule = explode( '|', $rule ); |
|
402 | - $srule = $ao_ccss_rules[ $trule[0] ][ $trule[1] ]; |
|
401 | + $trule = explode('|', $rule); |
|
402 | + $srule = $ao_ccss_rules[$trule[0]][$trule[1]]; |
|
403 | 403 | |
404 | 404 | // Check if a MANUAL rule exist and return false. |
405 | - if ( ! empty( $srule ) && ( 0 == $srule['hash'] && 0 != $srule['file'] ) ) { |
|
406 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the MANUAL rule <' . $trule[0] . '|' . $trule[1] . '>', 3 ); |
|
405 | + if (!empty($srule) && (0 == $srule['hash'] && 0 != $srule['file'])) { |
|
406 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the MANUAL rule <'.$trule[0].'|'.$trule[1].'>', 3); |
|
407 | 407 | return false; |
408 | - } elseif ( ! empty( $srule ) ) { |
|
408 | + } elseif (!empty($srule)) { |
|
409 | 409 | // Check if an AUTO rule exist. |
410 | - if ( $hash === $srule['hash'] && is_file( AO_CCSS_DIR . $srule['file'] ) && 0 != filesize( AO_CCSS_DIR . $srule['file'] ) ) { |
|
410 | + if ($hash === $srule['hash'] && is_file(AO_CCSS_DIR.$srule['file']) && 0 != filesize(AO_CCSS_DIR.$srule['file'])) { |
|
411 | 411 | // Check if job hash matches rule, if the CCSS file exists said file is not empty and return FALSE is so. |
412 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> MATCH the one in rule <' . $trule[0] . '|' . $trule[1] . '>', 3 ); |
|
412 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> MATCH the one in rule <'.$trule[0].'|'.$trule[1].'>', 3); |
|
413 | 413 | return false; |
414 | 414 | } else { |
415 | 415 | // Or return the new hash if they differ. |
416 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> DOES NOT MATCH the one in rule <' . $trule[0] . '|' . $trule[1] . '> or rule\'s CCSS file was invalid.', 3 ); |
|
416 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> DOES NOT MATCH the one in rule <'.$trule[0].'|'.$trule[1].'> or rule\'s CCSS file was invalid.', 3); |
|
417 | 417 | return $hash; |
418 | 418 | } |
419 | 419 | } else { |
420 | 420 | // Or just return the hash if no rule exist yet. |
421 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> has no rule yet', 3 ); |
|
421 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> has no rule yet', 3); |
|
422 | 422 | return $hash; |
423 | 423 | } |
424 | 424 | } |
425 | 425 | |
426 | - public function ao_ccss_api_generate( $path, $debug, $dcode ) { |
|
426 | + public function ao_ccss_api_generate($path, $debug, $dcode) { |
|
427 | 427 | // POST jobs to criticalcss.com and return responses |
428 | 428 | // Get key and key status. |
429 | 429 | global $ao_ccss_key; |
@@ -435,35 +435,35 @@ discard block |
||
435 | 435 | global $ao_ccss_noptimize; |
436 | 436 | |
437 | 437 | $site_host = get_site_url(); |
438 | - $site_path = parse_url( $site_host, PHP_URL_PATH ); |
|
438 | + $site_path = parse_url($site_host, PHP_URL_PATH); |
|
439 | 439 | |
440 | - if ( ! empty( $site_path ) ) { |
|
441 | - $site_host = str_replace( $site_path, '', $site_host ); |
|
440 | + if (!empty($site_path)) { |
|
441 | + $site_host = str_replace($site_path, '', $site_host); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | // Logic to bind to one domain to avoid site clones of sites would |
445 | 445 | // automatically begin spawning requests to criticalcss.com which has |
446 | 446 | // a per domain cost. |
447 | 447 | global $ao_ccss_domain; |
448 | - if ( empty( $ao_ccss_domain ) ) { |
|
448 | + if (empty($ao_ccss_domain)) { |
|
449 | 449 | // first request being done, update option to allow future requests are only allowed if from same domain. |
450 | - update_option( 'autoptimize_ccss_domain', str_rot13( $site_host ) ); |
|
451 | - } elseif ( trim( $ao_ccss_domain, '\'"' ) !== 'none' && parse_url( $site_host, PHP_URL_HOST ) !== parse_url( $ao_ccss_domain, PHP_URL_HOST ) && apply_filters( 'autoptimize_filter_ccss_bind_domain', true ) ) { |
|
450 | + update_option('autoptimize_ccss_domain', str_rot13($site_host)); |
|
451 | + } elseif (trim($ao_ccss_domain, '\'"') !== 'none' && parse_url($site_host, PHP_URL_HOST) !== parse_url($ao_ccss_domain, PHP_URL_HOST) && apply_filters('autoptimize_filter_ccss_bind_domain', true)) { |
|
452 | 452 | // not the same domain, log as error and return without posting to criticalcss.com. |
453 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Request for domain ' . $site_host . ' does not match bound domain ' . $ao_ccss_domain . ' so not proceeding.', 2 ); |
|
453 | + autoptimizeCriticalCSSCore::ao_ccss_log('Request for domain '.$site_host.' does not match bound domain '.$ao_ccss_domain.' so not proceeding.', 2); |
|
454 | 454 | return false; |
455 | 455 | } |
456 | 456 | |
457 | - $src_url = $site_host . $path; |
|
457 | + $src_url = $site_host.$path; |
|
458 | 458 | |
459 | 459 | // Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO. |
460 | - if ( ! empty( $ao_ccss_noptimize ) ) { |
|
460 | + if (!empty($ao_ccss_noptimize)) { |
|
461 | 461 | $src_url .= '?ao_noptirocket=1'; |
462 | - } elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) { |
|
462 | + } elseif (class_exists('autoptimizeImages', false) && autoptimizeImages::should_lazyload_wrapper()) { |
|
463 | 463 | $src_url .= '?ao_nolazy=1'; |
464 | 464 | } |
465 | 465 | |
466 | - $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url ); |
|
466 | + $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url); |
|
467 | 467 | |
468 | 468 | // Initialize request body. |
469 | 469 | $body = array(); |
@@ -473,88 +473,88 @@ discard block |
||
473 | 473 | |
474 | 474 | // Prepare and add viewport size to the body if available. |
475 | 475 | $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport(); |
476 | - if ( ! empty( $viewport['w'] ) && ! empty( $viewport['h'] ) ) { |
|
476 | + if (!empty($viewport['w']) && !empty($viewport['h'])) { |
|
477 | 477 | $body['width'] = $viewport['w']; |
478 | 478 | $body['height'] = $viewport['h']; |
479 | 479 | } |
480 | 480 | |
481 | 481 | // Prepare and add forceInclude to the body if available. |
482 | 482 | global $ao_ccss_finclude; |
483 | - $finclude = $this->ao_ccss_finclude( $ao_ccss_finclude ); |
|
484 | - if ( ! empty( $finclude ) ) { |
|
483 | + $finclude = $this->ao_ccss_finclude($ao_ccss_finclude); |
|
484 | + if (!empty($finclude)) { |
|
485 | 485 | $body['forceInclude'] = $finclude; |
486 | 486 | } |
487 | 487 | |
488 | 488 | // Add filter to allow the body array to be altered (e.g. to add customPageHeaders). |
489 | - $body = apply_filters( 'autoptimize_ccss_cron_api_generate_body', $body ); |
|
489 | + $body = apply_filters('autoptimize_ccss_cron_api_generate_body', $body); |
|
490 | 490 | |
491 | 491 | // Body must be json and log it. |
492 | - $body = json_encode( $body ); |
|
493 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request body is ' . $body, 3 ); |
|
492 | + $body = json_encode($body); |
|
493 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request body is '.$body, 3); |
|
494 | 494 | |
495 | 495 | // Prepare the request. |
496 | - $url = esc_url_raw( AO_CCSS_API . 'generate?aover=' . AO_CCSS_VER ); |
|
496 | + $url = esc_url_raw(AO_CCSS_API.'generate?aover='.AO_CCSS_VER); |
|
497 | 497 | $args = array( |
498 | 498 | 'headers' => array( |
499 | - 'User-Agent' => 'Autoptimize v' . AO_CCSS_VER, |
|
499 | + 'User-Agent' => 'Autoptimize v'.AO_CCSS_VER, |
|
500 | 500 | 'Content-type' => 'application/json; charset=utf-8', |
501 | - 'Authorization' => 'JWT ' . $key, |
|
501 | + 'Authorization' => 'JWT '.$key, |
|
502 | 502 | 'Connection' => 'close', |
503 | 503 | ), |
504 | 504 | 'body' => $body, |
505 | 505 | ); |
506 | 506 | |
507 | 507 | // Dispatch the request and store its response code. |
508 | - $req = wp_safe_remote_post( $url, $args ); |
|
509 | - $code = wp_remote_retrieve_response_code( $req ); |
|
510 | - $body = json_decode( wp_remote_retrieve_body( $req ), true ); |
|
508 | + $req = wp_safe_remote_post($url, $args); |
|
509 | + $code = wp_remote_retrieve_response_code($req); |
|
510 | + $body = json_decode(wp_remote_retrieve_body($req), true); |
|
511 | 511 | |
512 | - if ( $debug && $dcode ) { |
|
512 | + if ($debug && $dcode) { |
|
513 | 513 | // If queue debug is active, change response code. |
514 | 514 | $code = $dcode; |
515 | 515 | } |
516 | 516 | |
517 | - if ( 200 == $code ) { |
|
517 | + if (200 == $code) { |
|
518 | 518 | // Response code is OK. |
519 | 519 | // Workaround criticalcss.com non-RESTful reponses. |
520 | - if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status'] ) { |
|
520 | + if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status']) { |
|
521 | 521 | // Log successful and return encoded request body. |
522 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied successfully', 3 ); |
|
522 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied successfully', 3); |
|
523 | 523 | |
524 | 524 | // This code also means the key is valid, so cache key status for 24h if not already cached. |
525 | - if ( ( ! $key_status || 2 != $key_status ) && $key ) { |
|
526 | - update_option( 'autoptimize_ccss_keyst', 2 ); |
|
527 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 ); |
|
525 | + if ((!$key_status || 2 != $key_status) && $key) { |
|
526 | + update_option('autoptimize_ccss_keyst', 2); |
|
527 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | // Return the request body. |
531 | 531 | return $body; |
532 | 532 | } else { |
533 | 533 | // Log successful requests with invalid reponses. |
534 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied with code <' . $code . '> and an UNKNOWN error condition, body follows...', 2 ); |
|
535 | - autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 ); |
|
534 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied with code <'.$code.'> and an UNKNOWN error condition, body follows...', 2); |
|
535 | + autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2); |
|
536 | 536 | return $body; |
537 | 537 | } |
538 | 538 | } else { |
539 | 539 | // Response code is anything else. |
540 | 540 | // Log failed request with a valid response code and return body. |
541 | - if ( $code ) { |
|
542 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied with error code <' . $code . '>, body follows...', 2 ); |
|
543 | - autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 ); |
|
541 | + if ($code) { |
|
542 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied with error code <'.$code.'>, body follows...', 2); |
|
543 | + autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2); |
|
544 | 544 | |
545 | - if ( 401 == $code ) { |
|
545 | + if (401 == $code) { |
|
546 | 546 | // If request is unauthorized, also clear key status. |
547 | - update_option( 'autoptimize_ccss_keyst', 1 ); |
|
548 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 ); |
|
547 | + update_option('autoptimize_ccss_keyst', 1); |
|
548 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | // Return the request body. |
552 | 552 | return $body; |
553 | 553 | } else { |
554 | 554 | // Log failed request with no response and return false. |
555 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> has no response, this could be a service timeout', 2 ); |
|
556 | - if ( is_wp_error( $req ) ) { |
|
557 | - autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 ); |
|
555 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> has no response, this could be a service timeout', 2); |
|
556 | + if (is_wp_error($req)) { |
|
557 | + autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | return false; |
@@ -562,76 +562,76 @@ discard block |
||
562 | 562 | } |
563 | 563 | } |
564 | 564 | |
565 | - public function ao_ccss_api_results( $jobid, $debug, $dcode ) { |
|
565 | + public function ao_ccss_api_results($jobid, $debug, $dcode) { |
|
566 | 566 | // GET jobs from criticalcss.com and return responses |
567 | 567 | // Get key. |
568 | 568 | global $ao_ccss_key; |
569 | 569 | $key = $ao_ccss_key; |
570 | 570 | |
571 | 571 | // Prepare the request. |
572 | - $url = AO_CCSS_API . 'results?resultId=' . $jobid; |
|
572 | + $url = AO_CCSS_API.'results?resultId='.$jobid; |
|
573 | 573 | $args = array( |
574 | 574 | 'headers' => array( |
575 | - 'User-Agent' => 'Autoptimize CriticalCSS Power-Up v' . AO_CCSS_VER, |
|
576 | - 'Authorization' => 'JWT ' . $key, |
|
575 | + 'User-Agent' => 'Autoptimize CriticalCSS Power-Up v'.AO_CCSS_VER, |
|
576 | + 'Authorization' => 'JWT '.$key, |
|
577 | 577 | 'Connection' => 'close', |
578 | 578 | ), |
579 | 579 | ); |
580 | 580 | |
581 | 581 | // Dispatch the request and store its response code. |
582 | - $req = wp_safe_remote_get( $url, $args ); |
|
583 | - $code = wp_remote_retrieve_response_code( $req ); |
|
584 | - $body = json_decode( wp_remote_retrieve_body( $req ), true ); |
|
582 | + $req = wp_safe_remote_get($url, $args); |
|
583 | + $code = wp_remote_retrieve_response_code($req); |
|
584 | + $body = json_decode(wp_remote_retrieve_body($req), true); |
|
585 | 585 | |
586 | - if ( $debug && $dcode ) { |
|
586 | + if ($debug && $dcode) { |
|
587 | 587 | // If queue debug is active, change response code. |
588 | 588 | $code = $dcode; |
589 | 589 | } |
590 | 590 | |
591 | - if ( 200 == $code ) { |
|
591 | + if (200 == $code) { |
|
592 | 592 | // Response code is OK. |
593 | - if ( is_array( $body ) && ( array_key_exists( 'status', $body ) || array_key_exists( 'job', $body ) ) && ( 'JOB_QUEUED' == $body['status'] || 'JOB_ONGOING' == $body['status'] || 'JOB_DONE' == $body['status'] || 'JOB_FAILED' == $body['status'] || 'JOB_UNKNOWN' == $body['status'] || 'STATUS_JOB_BAD' == $body['job']['status'] ) ) { |
|
593 | + if (is_array($body) && (array_key_exists('status', $body) || array_key_exists('job', $body)) && ('JOB_QUEUED' == $body['status'] || 'JOB_ONGOING' == $body['status'] || 'JOB_DONE' == $body['status'] || 'JOB_FAILED' == $body['status'] || 'JOB_UNKNOWN' == $body['status'] || 'STATUS_JOB_BAD' == $body['job']['status'])) { |
|
594 | 594 | // Workaround criticalcss.com non-RESTful reponses |
595 | 595 | // Log successful and return encoded request body. |
596 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied successfully', 3 ); |
|
596 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied successfully', 3); |
|
597 | 597 | return $body; |
598 | - } elseif ( is_array( $body ) && ( array_key_exists( 'error', $body ) && 'This css no longer exists. Please re-generate it.' == $body['error'] ) ) { |
|
598 | + } elseif (is_array($body) && (array_key_exists('error', $body) && 'This css no longer exists. Please re-generate it.' == $body['error'])) { |
|
599 | 599 | // Handle no CSS reply |
600 | 600 | // Log no CSS error and return encoded request body. |
601 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied successfully but the CSS for it does not exist anymore', 3 ); |
|
601 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied successfully but the CSS for it does not exist anymore', 3); |
|
602 | 602 | return $body; |
603 | 603 | } else { |
604 | 604 | // Log failed request and return false. |
605 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied with code <' . $code . '> and an UNKNOWN error condition, body follows...', 2 ); |
|
606 | - autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 ); |
|
605 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied with code <'.$code.'> and an UNKNOWN error condition, body follows...', 2); |
|
606 | + autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2); |
|
607 | 607 | return false; |
608 | 608 | } |
609 | 609 | } else { |
610 | 610 | // Response code is anything else |
611 | 611 | // Log failed request with a valid response code and return body. |
612 | - if ( $code ) { |
|
613 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied with error code <' . $code . '>, body follows...', 2 ); |
|
614 | - autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 ); |
|
615 | - if ( 401 == $code ) { |
|
612 | + if ($code) { |
|
613 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied with error code <'.$code.'>, body follows...', 2); |
|
614 | + autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2); |
|
615 | + if (401 == $code) { |
|
616 | 616 | // If request is unauthorized, also clear key status. |
617 | - update_option( 'autoptimize_ccss_keyst', 1 ); |
|
618 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 ); |
|
617 | + update_option('autoptimize_ccss_keyst', 1); |
|
618 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | // Return the request body. |
622 | 622 | return $body; |
623 | 623 | } else { |
624 | 624 | // Log failed request with no response and return false. |
625 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> has no response, this could be a service timeout', 2 ); |
|
625 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> has no response, this could be a service timeout', 2); |
|
626 | 626 | return false; |
627 | 627 | } |
628 | 628 | } |
629 | 629 | } |
630 | 630 | |
631 | - public function ao_ccss_save_file( $ccss, $target, $review ) { |
|
631 | + public function ao_ccss_save_file($ccss, $target, $review) { |
|
632 | 632 | // Save critical CSS into the filesystem and return its filename |
633 | 633 | // Prepare review mark. |
634 | - if ( $review ) { |
|
634 | + if ($review) { |
|
635 | 635 | $rmark = '_R'; |
636 | 636 | } else { |
637 | 637 | $rmark = ''; |
@@ -641,21 +641,21 @@ discard block |
||
641 | 641 | $filename = false; |
642 | 642 | $content = $ccss; |
643 | 643 | |
644 | - if ( autoptimizeCriticalCSSCore::ao_ccss_check_contents( $content ) ) { |
|
644 | + if (autoptimizeCriticalCSSCore::ao_ccss_check_contents($content)) { |
|
645 | 645 | // Sanitize content, set filename and try to save file. |
646 | - $file = AO_CCSS_DIR . 'ccss_' . md5( $ccss . $target[1] ) . $rmark . '.css'; |
|
647 | - $status = file_put_contents( $file, $content, LOCK_EX ); |
|
648 | - $filename = pathinfo( $file, PATHINFO_BASENAME ); |
|
649 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file for the rule <' . $target[0] . '|' . $target[1] . '> was saved as <' . $filename . '>, size in bytes is <' . $status . '>', 3 ); |
|
646 | + $file = AO_CCSS_DIR.'ccss_'.md5($ccss.$target[1]).$rmark.'.css'; |
|
647 | + $status = file_put_contents($file, $content, LOCK_EX); |
|
648 | + $filename = pathinfo($file, PATHINFO_BASENAME); |
|
649 | + autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file for the rule <'.$target[0].'|'.$target[1].'> was saved as <'.$filename.'>, size in bytes is <'.$status.'>', 3); |
|
650 | 650 | |
651 | - if ( ! $status ) { |
|
651 | + if (!$status) { |
|
652 | 652 | // If file has not been saved, reset filename. |
653 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file <' . $filename . '> could not be not saved', 2 ); |
|
653 | + autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file <'.$filename.'> could not be not saved', 2); |
|
654 | 654 | $filename = false; |
655 | 655 | return $filename; |
656 | 656 | } |
657 | 657 | } else { |
658 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not pass content check', 2 ); |
|
658 | + autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not pass content check', 2); |
|
659 | 659 | return $filename; |
660 | 660 | } |
661 | 661 | |
@@ -665,15 +665,15 @@ discard block |
||
665 | 665 | global $ao_ccss_rules; |
666 | 666 | |
667 | 667 | // Prepare rule variables. |
668 | - $srule = $ao_ccss_rules[ $target[0] ][ $target[1] ]; |
|
668 | + $srule = $ao_ccss_rules[$target[0]][$target[1]]; |
|
669 | 669 | $oldfile = $srule['file']; |
670 | 670 | |
671 | - if ( $oldfile && $oldfile !== $filename ) { |
|
672 | - $delfile = AO_CCSS_DIR . $oldfile; |
|
673 | - if ( file_exists( $delfile ) ) { |
|
674 | - $unlinkst = unlink( $delfile ); |
|
675 | - if ( $unlinkst ) { |
|
676 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'A previous critical CSS file <' . $oldfile . '> was removed for the rule <' . $target[0] . '|' . $target[1] . '>', 3 ); |
|
671 | + if ($oldfile && $oldfile !== $filename) { |
|
672 | + $delfile = AO_CCSS_DIR.$oldfile; |
|
673 | + if (file_exists($delfile)) { |
|
674 | + $unlinkst = unlink($delfile); |
|
675 | + if ($unlinkst) { |
|
676 | + autoptimizeCriticalCSSCore::ao_ccss_log('A previous critical CSS file <'.$oldfile.'> was removed for the rule <'.$target[0].'|'.$target[1].'>', 3); |
|
677 | 677 | } |
678 | 678 | } |
679 | 679 | } |
@@ -682,29 +682,29 @@ discard block |
||
682 | 682 | return $filename; |
683 | 683 | } |
684 | 684 | |
685 | - public function ao_ccss_rule_update( $ljid, $srule, $file, $hash ) { |
|
685 | + public function ao_ccss_rule_update($ljid, $srule, $file, $hash) { |
|
686 | 686 | // Update or create a rule |
687 | 687 | // Attach required arrays. |
688 | 688 | global $ao_ccss_rules; |
689 | 689 | |
690 | 690 | // Prepare rule variables. |
691 | - $trule = explode( '|', $srule ); |
|
692 | - $rule = $ao_ccss_rules[ $trule[0] ][ $trule[1] ]; |
|
691 | + $trule = explode('|', $srule); |
|
692 | + $rule = $ao_ccss_rules[$trule[0]][$trule[1]]; |
|
693 | 693 | $action = false; |
694 | 694 | $rtype = ''; |
695 | 695 | |
696 | - if ( 0 === $rule['hash'] && 0 !== $rule['file'] ) { |
|
696 | + if (0 === $rule['hash'] && 0 !== $rule['file']) { |
|
697 | 697 | // manual rule, don't ever overwrite. |
698 | 698 | $action = 'NOT UPDATED'; |
699 | 699 | $rtype = 'MANUAL'; |
700 | - } elseif ( 0 === $rule['hash'] && 0 === $rule['file'] ) { |
|
700 | + } elseif (0 === $rule['hash'] && 0 === $rule['file']) { |
|
701 | 701 | // If this is an user created AUTO rule with no hash and file yet, update its hash and filename |
702 | 702 | // Set rule hash, file and action flag. |
703 | 703 | $rule['hash'] = $hash; |
704 | 704 | $rule['file'] = $file; |
705 | 705 | $action = 'UPDATED'; |
706 | 706 | $rtype = 'AUTO'; |
707 | - } elseif ( 0 !== $rule['hash'] && ctype_alnum( $rule['hash'] ) ) { |
|
707 | + } elseif (0 !== $rule['hash'] && ctype_alnum($rule['hash'])) { |
|
708 | 708 | // If this is an genuine AUTO rule, update its hash and filename |
709 | 709 | // Set rule hash, file and action flag. |
710 | 710 | $rule['hash'] = $hash; |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | } else { |
715 | 715 | // If rule doesn't exist, create an AUTO rule |
716 | 716 | // AUTO rules were only for types, but will now also work for paths. |
717 | - if ( 'types' == $trule[0] || 'paths' == $trule[0] ) { |
|
717 | + if ('types' == $trule[0] || 'paths' == $trule[0]) { |
|
718 | 718 | // Set rule hash and file and action flag. |
719 | 719 | $rule['hash'] = $hash; |
720 | 720 | $rule['file'] = $file; |
@@ -722,47 +722,47 @@ discard block |
||
722 | 722 | $rtype = 'AUTO'; |
723 | 723 | } else { |
724 | 724 | // Log that no rule was created. |
725 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Exception, no AUTO rule created', 3 ); |
|
725 | + autoptimizeCriticalCSSCore::ao_ccss_log('Exception, no AUTO rule created', 3); |
|
726 | 726 | } |
727 | 727 | } |
728 | 728 | |
729 | - if ( $action ) { |
|
729 | + if ($action) { |
|
730 | 730 | // If a rule creation/update is required, persist updated rules object. |
731 | - $ao_ccss_rules[ $trule[0] ][ $trule[1] ] = $rule; |
|
732 | - $ao_ccss_rules_raw = json_encode( $ao_ccss_rules ); |
|
733 | - update_option( 'autoptimize_ccss_rules', $ao_ccss_rules_raw ); |
|
734 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Target rule <' . $srule . '> of type <' . $rtype . '> was ' . $action . ' for job id <' . $ljid . '>', 3 ); |
|
731 | + $ao_ccss_rules[$trule[0]][$trule[1]] = $rule; |
|
732 | + $ao_ccss_rules_raw = json_encode($ao_ccss_rules); |
|
733 | + update_option('autoptimize_ccss_rules', $ao_ccss_rules_raw); |
|
734 | + autoptimizeCriticalCSSCore::ao_ccss_log('Target rule <'.$srule.'> of type <'.$rtype.'> was '.$action.' for job id <'.$ljid.'>', 3); |
|
735 | 735 | } else { |
736 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'No rule action required', 3 ); |
|
736 | + autoptimizeCriticalCSSCore::ao_ccss_log('No rule action required', 3); |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | |
740 | - function ao_ccss_finclude( $finclude_raw ) { |
|
740 | + function ao_ccss_finclude($finclude_raw) { |
|
741 | 741 | // Prepare forceInclude object. |
742 | - if ( ! empty( $finclude_raw ) ) { |
|
742 | + if (!empty($finclude_raw)) { |
|
743 | 743 | // If there are any content |
744 | 744 | // Convert raw string into arra and initialize the returning object. |
745 | - $fincludes = explode( ',', $finclude_raw ); |
|
745 | + $fincludes = explode(',', $finclude_raw); |
|
746 | 746 | $finclude = array(); |
747 | 747 | |
748 | 748 | // Interacts over every rule. |
749 | 749 | $i = 0; |
750 | - foreach ( $fincludes as $include ) { |
|
750 | + foreach ($fincludes as $include) { |
|
751 | 751 | // Trim leading and trailing whitespaces. |
752 | - $include = trim( $include ); |
|
752 | + $include = trim($include); |
|
753 | 753 | |
754 | - if ( substr( $include, 0, 2 ) === '//' ) { |
|
754 | + if (substr($include, 0, 2) === '//') { |
|
755 | 755 | // Regex rule |
756 | 756 | // Format value as required. |
757 | - $include = str_replace( '//', '/', $include ); |
|
758 | - $include = $include . '/i'; |
|
757 | + $include = str_replace('//', '/', $include); |
|
758 | + $include = $include.'/i'; |
|
759 | 759 | |
760 | 760 | // Store regex object. |
761 | - $finclude[ $i ]['type'] = 'RegExp'; |
|
762 | - $finclude[ $i ]['value'] = $include; |
|
761 | + $finclude[$i]['type'] = 'RegExp'; |
|
762 | + $finclude[$i]['value'] = $include; |
|
763 | 763 | } else { |
764 | 764 | // Simple value rule. |
765 | - $finclude[ $i ]['value'] = $include; |
|
765 | + $finclude[$i]['value'] = $include; |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | $i++; |
@@ -779,54 +779,54 @@ discard block |
||
779 | 779 | public function ao_ccss_cleaning() { |
780 | 780 | // Perform plugin maintenance |
781 | 781 | // Truncate log file >= 1MB . |
782 | - if ( file_exists( AO_CCSS_LOG ) ) { |
|
783 | - if ( filesize( AO_CCSS_LOG ) >= 1048576 ) { |
|
784 | - $logfile = fopen( AO_CCSS_LOG, 'w' ); |
|
785 | - fclose( $logfile ); |
|
782 | + if (file_exists(AO_CCSS_LOG)) { |
|
783 | + if (filesize(AO_CCSS_LOG) >= 1048576) { |
|
784 | + $logfile = fopen(AO_CCSS_LOG, 'w'); |
|
785 | + fclose($logfile); |
|
786 | 786 | } |
787 | 787 | } |
788 | 788 | |
789 | 789 | // Remove lock file. |
790 | - if ( file_exists( AO_CCSS_LOCK ) ) { |
|
791 | - unlink( AO_CCSS_LOCK ); |
|
790 | + if (file_exists(AO_CCSS_LOCK)) { |
|
791 | + unlink(AO_CCSS_LOCK); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | // Make sure queue processing is scheduled, recreate if not. |
795 | - if ( ! wp_next_scheduled( 'ao_ccss_queue' ) ) { |
|
796 | - wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' ); |
|
795 | + if (!wp_next_scheduled('ao_ccss_queue')) { |
|
796 | + wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue'); |
|
797 | 797 | } |
798 | 798 | |
799 | 799 | // Queue cleaning. |
800 | 800 | global $ao_ccss_queue; |
801 | 801 | $queue_purge_threshold = 100; |
802 | - $queue_purge_age = 24 * 60 * 60; |
|
803 | - $queue_length = count( $ao_ccss_queue ); |
|
804 | - $timestamp_yesterday = microtime( true ) - $queue_purge_age; |
|
802 | + $queue_purge_age = 24*60*60; |
|
803 | + $queue_length = count($ao_ccss_queue); |
|
804 | + $timestamp_yesterday = microtime(true) - $queue_purge_age; |
|
805 | 805 | $remove_old_new = false; |
806 | 806 | $queue_altered = false; |
807 | 807 | |
808 | - if ( $queue_length > $queue_purge_threshold ) { |
|
808 | + if ($queue_length > $queue_purge_threshold) { |
|
809 | 809 | $remove_old_new = true; |
810 | 810 | } |
811 | 811 | |
812 | - foreach ( $ao_ccss_queue as $path => $job ) { |
|
813 | - if ( ( $remove_old_new && 'NEW' == $job['jqstat'] && $job['jctime'] < $timestamp_yesterday ) || in_array( $job['jqstat'], array( 'JOB_FAILED', 'STATUS_JOB_BAD', 'NO_CSS', 'NO_RESPONSE' ) ) ) { |
|
814 | - unset( $ao_ccss_queue[ $path ] ); |
|
812 | + foreach ($ao_ccss_queue as $path => $job) { |
|
813 | + if (($remove_old_new && 'NEW' == $job['jqstat'] && $job['jctime'] < $timestamp_yesterday) || in_array($job['jqstat'], array('JOB_FAILED', 'STATUS_JOB_BAD', 'NO_CSS', 'NO_RESPONSE'))) { |
|
814 | + unset($ao_ccss_queue[$path]); |
|
815 | 815 | $queue_altered = true; |
816 | 816 | } |
817 | 817 | } |
818 | 818 | |
819 | 819 | // save queue to options! |
820 | - if ( $queue_altered ) { |
|
821 | - $ao_ccss_queue_raw = json_encode( $ao_ccss_queue ); |
|
822 | - update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false ); |
|
823 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue cleaning done.', 3 ); |
|
820 | + if ($queue_altered) { |
|
821 | + $ao_ccss_queue_raw = json_encode($ao_ccss_queue); |
|
822 | + update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false); |
|
823 | + autoptimizeCriticalCSSCore::ao_ccss_log('Queue cleaning done.', 3); |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | // re-check key if invalid. |
827 | 827 | global $ao_ccss_keyst; |
828 | - if ( 1 == $ao_ccss_keyst ) { |
|
829 | - $this->ao_ccss_api_generate( '', '', '' ); |
|
828 | + if (1 == $ao_ccss_keyst) { |
|
829 | + $this->ao_ccss_api_generate('', '', ''); |
|
830 | 830 | } |
831 | 831 | } |
832 | 832 | } |
@@ -3,7 +3,7 @@ discard block |
||
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 | |
@@ -161,53 +161,53 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @param array $options all options. |
163 | 163 | */ |
164 | - public function read( $options ) |
|
164 | + public function read($options) |
|
165 | 165 | { |
166 | - $noptimize_css = apply_filters( 'autoptimize_filter_css_noptimize', false, $this->content ); |
|
167 | - if ( $noptimize_css ) { |
|
166 | + $noptimize_css = apply_filters('autoptimize_filter_css_noptimize', false, $this->content); |
|
167 | + if ($noptimize_css) { |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
171 | - $whitelist_css = apply_filters( 'autoptimize_filter_css_whitelist', '', $this->content ); |
|
172 | - if ( ! empty( $whitelist_css ) ) { |
|
173 | - $this->whitelist = array_filter( array_map( 'trim', explode( ',', $whitelist_css ) ) ); |
|
171 | + $whitelist_css = apply_filters('autoptimize_filter_css_whitelist', '', $this->content); |
|
172 | + if (!empty($whitelist_css)) { |
|
173 | + $this->whitelist = array_filter(array_map('trim', explode(',', $whitelist_css))); |
|
174 | 174 | } |
175 | 175 | |
176 | - $removable_css = apply_filters( 'autoptimize_filter_css_removables', '' ); |
|
177 | - if ( ! empty( $removable_css ) ) { |
|
178 | - $this->cssremovables = array_filter( array_map( 'trim', explode( ',', $removable_css ) ) ); |
|
176 | + $removable_css = apply_filters('autoptimize_filter_css_removables', ''); |
|
177 | + if (!empty($removable_css)) { |
|
178 | + $this->cssremovables = array_filter(array_map('trim', explode(',', $removable_css))); |
|
179 | 179 | } |
180 | 180 | |
181 | - $this->cssinlinesize = apply_filters( 'autoptimize_filter_css_inlinesize', 256 ); |
|
181 | + $this->cssinlinesize = apply_filters('autoptimize_filter_css_inlinesize', 256); |
|
182 | 182 | |
183 | 183 | // filter to "late inject minified CSS", default to true for now (it is faster). |
184 | - $this->inject_min_late = apply_filters( 'autoptimize_filter_css_inject_min_late', true ); |
|
184 | + $this->inject_min_late = apply_filters('autoptimize_filter_css_inject_min_late', true); |
|
185 | 185 | |
186 | 186 | // Remove everything that's not the header. |
187 | - if ( apply_filters( 'autoptimize_filter_css_justhead', $options['justhead'] ) ) { |
|
188 | - $content = explode( '</head>', $this->content, 2 ); |
|
189 | - $this->content = $content[0] . '</head>'; |
|
187 | + if (apply_filters('autoptimize_filter_css_justhead', $options['justhead'])) { |
|
188 | + $content = explode('</head>', $this->content, 2); |
|
189 | + $this->content = $content[0].'</head>'; |
|
190 | 190 | $this->restofcontent = $content[1]; |
191 | 191 | } |
192 | 192 | |
193 | 193 | // Determine whether we're doing CSS-files aggregation or not. |
194 | - if ( isset( $options['aggregate'] ) && ! $options['aggregate'] ) { |
|
194 | + if (isset($options['aggregate']) && !$options['aggregate']) { |
|
195 | 195 | $this->aggregate = false; |
196 | 196 | } |
197 | 197 | // Returning true for "dontaggregate" turns off aggregation. |
198 | - if ( $this->aggregate && apply_filters( 'autoptimize_filter_css_dontaggregate', false ) ) { |
|
198 | + if ($this->aggregate && apply_filters('autoptimize_filter_css_dontaggregate', false)) { |
|
199 | 199 | $this->aggregate = false; |
200 | 200 | } |
201 | 201 | |
202 | 202 | // include inline? |
203 | - if ( apply_filters( 'autoptimize_css_include_inline', $options['include_inline'] ) ) { |
|
203 | + if (apply_filters('autoptimize_css_include_inline', $options['include_inline'])) { |
|
204 | 204 | $this->include_inline = true; |
205 | 205 | } |
206 | 206 | |
207 | 207 | // List of CSS strings which are excluded from autoptimization. |
208 | - $exclude_css = apply_filters( 'autoptimize_filter_css_exclude', $options['css_exclude'], $this->content ); |
|
209 | - if ( '' !== $exclude_css ) { |
|
210 | - $this->dontmove = array_filter( array_map( 'trim', explode( ',', $exclude_css ) ) ); |
|
208 | + $exclude_css = apply_filters('autoptimize_filter_css_exclude', $options['css_exclude'], $this->content); |
|
209 | + if ('' !== $exclude_css) { |
|
210 | + $this->dontmove = array_filter(array_map('trim', explode(',', $exclude_css))); |
|
211 | 211 | } else { |
212 | 212 | $this->dontmove = array(); |
213 | 213 | } |
@@ -218,16 +218,16 @@ discard block |
||
218 | 218 | // Should we defer css? |
219 | 219 | // value: true / false. |
220 | 220 | $this->defer = $options['defer']; |
221 | - $this->defer = apply_filters( 'autoptimize_filter_css_defer', $this->defer, $this->content ); |
|
221 | + $this->defer = apply_filters('autoptimize_filter_css_defer', $this->defer, $this->content); |
|
222 | 222 | |
223 | 223 | // Should we inline while deferring? |
224 | 224 | // value: inlined CSS. |
225 | - $this->defer_inline = apply_filters( 'autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content ); |
|
225 | + $this->defer_inline = apply_filters('autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content); |
|
226 | 226 | |
227 | 227 | // Should we inline? |
228 | 228 | // value: true / false. |
229 | 229 | $this->inline = $options['inline']; |
230 | - $this->inline = apply_filters( 'autoptimize_filter_css_inline', $this->inline, $this->content ); |
|
230 | + $this->inline = apply_filters('autoptimize_filter_css_inline', $this->inline, $this->content); |
|
231 | 231 | |
232 | 232 | // Store cdn url. |
233 | 233 | $this->cdn_url = $options['cdn_url']; |
@@ -236,16 +236,16 @@ discard block |
||
236 | 236 | $this->datauris = $options['datauris']; |
237 | 237 | |
238 | 238 | // Determine whether excluded files should be minified if not yet so. |
239 | - if ( ! $options['minify_excluded'] && $options['aggregate'] ) { |
|
239 | + if (!$options['minify_excluded'] && $options['aggregate']) { |
|
240 | 240 | $this->minify_excluded = false; |
241 | 241 | } |
242 | - $this->minify_excluded = apply_filters( 'autoptimize_filter_css_minify_excluded', $this->minify_excluded, '' ); |
|
242 | + $this->minify_excluded = apply_filters('autoptimize_filter_css_minify_excluded', $this->minify_excluded, ''); |
|
243 | 243 | |
244 | 244 | // should we force all media-attributes to all? |
245 | - $this->media_force_all = apply_filters( 'autoptimize_filter_css_tagmedia_forceall', false ); |
|
245 | + $this->media_force_all = apply_filters('autoptimize_filter_css_tagmedia_forceall', false); |
|
246 | 246 | |
247 | 247 | // noptimize me. |
248 | - $this->content = $this->hide_noptimize( $this->content ); |
|
248 | + $this->content = $this->hide_noptimize($this->content); |
|
249 | 249 | |
250 | 250 | // Exclude (no)script, as those may contain CSS which should be left as is. |
251 | 251 | $this->content = $this->replace_contents_with_marker_if_exists( |
@@ -256,25 +256,25 @@ discard block |
||
256 | 256 | ); |
257 | 257 | |
258 | 258 | // Save IE hacks. |
259 | - $this->content = $this->hide_iehacks( $this->content ); |
|
259 | + $this->content = $this->hide_iehacks($this->content); |
|
260 | 260 | |
261 | 261 | // Hide HTML comments. |
262 | - $this->content = $this->hide_comments( $this->content ); |
|
262 | + $this->content = $this->hide_comments($this->content); |
|
263 | 263 | |
264 | 264 | // Get <style> and <link>. |
265 | - if ( preg_match_all( '#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches ) ) { |
|
265 | + if (preg_match_all('#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches)) { |
|
266 | 266 | |
267 | - foreach ( $matches[0] as $tag ) { |
|
268 | - if ( $this->isremovable( $tag, $this->cssremovables ) ) { |
|
269 | - $this->content = str_replace( $tag, '', $this->content ); |
|
270 | - } elseif ( $this->ismovable( $tag ) ) { |
|
267 | + foreach ($matches[0] as $tag) { |
|
268 | + if ($this->isremovable($tag, $this->cssremovables)) { |
|
269 | + $this->content = str_replace($tag, '', $this->content); |
|
270 | + } elseif ($this->ismovable($tag)) { |
|
271 | 271 | // Get the media. |
272 | - if ( false !== strpos( $tag, 'media=' ) ) { |
|
273 | - preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias ); |
|
274 | - $medias = explode( ',', $medias[1] ); |
|
272 | + if (false !== strpos($tag, 'media=')) { |
|
273 | + preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias); |
|
274 | + $medias = explode(',', $medias[1]); |
|
275 | 275 | $media = array(); |
276 | - foreach ( $medias as $elem ) { |
|
277 | - if ( empty( $elem ) ) { |
|
276 | + foreach ($medias as $elem) { |
|
277 | + if (empty($elem)) { |
|
278 | 278 | $elem = 'all'; |
279 | 279 | } |
280 | 280 | |
@@ -282,68 +282,68 @@ discard block |
||
282 | 282 | } |
283 | 283 | } else { |
284 | 284 | // No media specified - applies to all. |
285 | - $media = array( 'all' ); |
|
285 | + $media = array('all'); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | // forcing media attribute to all to merge all in one file. |
289 | - if ( $this->media_force_all ) { |
|
290 | - $media = array( 'all' ); |
|
289 | + if ($this->media_force_all) { |
|
290 | + $media = array('all'); |
|
291 | 291 | } |
292 | 292 | |
293 | - $media = apply_filters( 'autoptimize_filter_css_tagmedia', $media, $tag ); |
|
293 | + $media = apply_filters('autoptimize_filter_css_tagmedia', $media, $tag); |
|
294 | 294 | |
295 | - if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) { |
|
295 | + if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) { |
|
296 | 296 | // <link>. |
297 | - $url = current( explode( '?', $source[2], 2 ) ); |
|
298 | - $path = $this->getpath( $url ); |
|
297 | + $url = current(explode('?', $source[2], 2)); |
|
298 | + $path = $this->getpath($url); |
|
299 | 299 | |
300 | - if ( false !== $path && preg_match( '#\.css$#', $path ) ) { |
|
300 | + if (false !== $path && preg_match('#\.css$#', $path)) { |
|
301 | 301 | // Good link. |
302 | - $this->css[] = array( $media, $path ); |
|
302 | + $this->css[] = array($media, $path); |
|
303 | 303 | } else { |
304 | 304 | // Link is dynamic (.php etc). |
305 | - $new_tag = $this->optionally_defer_excluded( $tag, 'none' ); |
|
306 | - if ( '' !== $new_tag && $new_tag !== $tag ) { |
|
307 | - $this->content = str_replace( $tag, $new_tag, $this->content ); |
|
305 | + $new_tag = $this->optionally_defer_excluded($tag, 'none'); |
|
306 | + if ('' !== $new_tag && $new_tag !== $tag) { |
|
307 | + $this->content = str_replace($tag, $new_tag, $this->content); |
|
308 | 308 | } |
309 | 309 | $tag = ''; |
310 | 310 | } |
311 | 311 | } else { |
312 | 312 | // Inline css in style tags can be wrapped in comment tags, so restore comments. |
313 | - $tag = $this->restore_comments( $tag ); |
|
314 | - preg_match( '#<style.*>(.*)</style>#Usmi', $tag, $code ); |
|
313 | + $tag = $this->restore_comments($tag); |
|
314 | + preg_match('#<style.*>(.*)</style>#Usmi', $tag, $code); |
|
315 | 315 | |
316 | 316 | // And re-hide them to be able to to the removal based on tag. |
317 | - $tag = $this->hide_comments( $tag ); |
|
317 | + $tag = $this->hide_comments($tag); |
|
318 | 318 | |
319 | - if ( $this->include_inline ) { |
|
320 | - $code = preg_replace( '#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1] ); |
|
321 | - $this->css[] = array( $media, 'INLINE;' . $code ); |
|
319 | + if ($this->include_inline) { |
|
320 | + $code = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1]); |
|
321 | + $this->css[] = array($media, 'INLINE;'.$code); |
|
322 | 322 | } else { |
323 | 323 | $tag = ''; |
324 | 324 | } |
325 | 325 | } |
326 | 326 | |
327 | 327 | // Remove the original style tag. |
328 | - $this->content = str_replace( $tag, '', $this->content ); |
|
328 | + $this->content = str_replace($tag, '', $this->content); |
|
329 | 329 | } else { |
330 | - if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) { |
|
331 | - $exploded_url = explode( '?', $source[2], 2 ); |
|
330 | + if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) { |
|
331 | + $exploded_url = explode('?', $source[2], 2); |
|
332 | 332 | $url = $exploded_url[0]; |
333 | - $path = $this->getpath( $url ); |
|
333 | + $path = $this->getpath($url); |
|
334 | 334 | $new_tag = $tag; |
335 | 335 | |
336 | 336 | // Excluded CSS, minify that file: |
337 | 337 | // -> if aggregate is on and exclude minify is on |
338 | 338 | // -> if aggregate is off and the file is not in dontmove. |
339 | - if ( $path && $this->minify_excluded ) { |
|
340 | - $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false ); |
|
341 | - if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) { |
|
342 | - $minified_url = $this->minify_single( $path ); |
|
343 | - if ( ! empty( $minified_url ) ) { |
|
339 | + if ($path && $this->minify_excluded) { |
|
340 | + $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false); |
|
341 | + if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) { |
|
342 | + $minified_url = $this->minify_single($path); |
|
343 | + if (!empty($minified_url)) { |
|
344 | 344 | // Replace orig URL with cached minified URL. |
345 | - $new_tag = str_replace( $url, $minified_url, $tag ); |
|
346 | - } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) { |
|
345 | + $new_tag = str_replace($url, $minified_url, $tag); |
|
346 | + } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) { |
|
347 | 347 | // Remove the original style tag, because cache content is empty but only if |
348 | 348 | // filter is true-ed because $minified_url is also false if file is minified already. |
349 | 349 | $new_tag = ''; |
@@ -351,14 +351,14 @@ discard block |
||
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | - if ( '' !== $new_tag ) { |
|
354 | + if ('' !== $new_tag) { |
|
355 | 355 | // Optionally defer (preload) non-aggregated CSS. |
356 | - $new_tag = $this->optionally_defer_excluded( $new_tag, $url ); |
|
356 | + $new_tag = $this->optionally_defer_excluded($new_tag, $url); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | // And replace! |
360 | - if ( ( '' !== $new_tag && $new_tag !== $tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_css_remove_empty_files', false ) ) ) { |
|
361 | - $this->content = str_replace( $tag, $new_tag, $this->content ); |
|
360 | + if (('' !== $new_tag && $new_tag !== $tag) || ('' === $new_tag && apply_filters('autoptimize_filter_css_remove_empty_files', false))) { |
|
361 | + $this->content = str_replace($tag, $new_tag, $this->content); |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | } |
@@ -379,10 +379,10 @@ discard block |
||
379 | 379 | * |
380 | 380 | * @return string $new_tag |
381 | 381 | */ |
382 | - private function optionally_defer_excluded( $tag, $url = '' ) |
|
382 | + private function optionally_defer_excluded($tag, $url = '') |
|
383 | 383 | { |
384 | 384 | // Defer single CSS if "inline & defer" is ON and there is inline CSS. |
385 | - if ( ! empty( $tag ) && false === strpos( $tag, ' onload=' ) && $this->defer && ! empty( $this->defer_inline ) && apply_filters( 'autoptimize_filter_css_defer_excluded', true, $tag ) ) { |
|
385 | + if (!empty($tag) && false === strpos($tag, ' onload=') && $this->defer && !empty($this->defer_inline) && apply_filters('autoptimize_filter_css_defer_excluded', true, $tag)) { |
|
386 | 386 | // Get/ set (via filter) the JS to be triggers onload of the preloaded CSS. |
387 | 387 | $_preload_onload = apply_filters( |
388 | 388 | 'autoptimize_filter_css_preload_onload', |
@@ -391,12 +391,12 @@ discard block |
||
391 | 391 | ); |
392 | 392 | |
393 | 393 | // Adapt original <link> element for CSS to be preloaded and add <noscript>-version for fallback. |
394 | - $new_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>' . str_replace( |
|
394 | + $new_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>'.str_replace( |
|
395 | 395 | array( |
396 | 396 | "rel='stylesheet'", |
397 | 397 | 'rel="stylesheet"', |
398 | 398 | ), |
399 | - "rel='preload' as='style' onload=\"" . $_preload_onload . '"', |
|
399 | + "rel='preload' as='style' onload=\"".$_preload_onload.'"', |
|
400 | 400 | $tag |
401 | 401 | ); |
402 | 402 | |
@@ -414,22 +414,22 @@ discard block |
||
414 | 414 | * @param string $path image path. |
415 | 415 | * @return boolean |
416 | 416 | */ |
417 | - private function is_datauri_candidate( $path ) |
|
417 | + private function is_datauri_candidate($path) |
|
418 | 418 | { |
419 | 419 | // Call only once since it's called from a loop. |
420 | 420 | static $max_size = null; |
421 | - if ( null === $max_size ) { |
|
421 | + if (null === $max_size) { |
|
422 | 422 | $max_size = $this->get_datauri_maxsize(); |
423 | 423 | } |
424 | 424 | |
425 | - if ( $path && preg_match( '#\.(jpe?g|png|gif|webp|bmp)$#i', $path ) && |
|
426 | - file_exists( $path ) && is_readable( $path ) && filesize( $path ) <= $max_size ) { |
|
425 | + if ($path && preg_match('#\.(jpe?g|png|gif|webp|bmp)$#i', $path) && |
|
426 | + file_exists($path) && is_readable($path) && filesize($path) <= $max_size) { |
|
427 | 427 | |
428 | 428 | // Seems we have a candidate. |
429 | 429 | $is_candidate = true; |
430 | 430 | } else { |
431 | 431 | // Filter allows overriding default decision (which checks for local file existence). |
432 | - $is_candidate = apply_filters( 'autoptimize_filter_css_is_datauri_candidate', false, $path ); |
|
432 | + $is_candidate = apply_filters('autoptimize_filter_css_is_datauri_candidate', false, $path); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | return $is_candidate; |
@@ -454,29 +454,29 @@ discard block |
||
454 | 454 | * of thing you're probably better of building assets completely |
455 | 455 | * outside of WordPress anyway. |
456 | 456 | */ |
457 | - if ( null === $max_size ) { |
|
458 | - $max_size = (int) apply_filters( 'autoptimize_filter_css_datauri_maxsize', 4096 ); |
|
457 | + if (null === $max_size) { |
|
458 | + $max_size = (int) apply_filters('autoptimize_filter_css_datauri_maxsize', 4096); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | return $max_size; |
462 | 462 | } |
463 | 463 | |
464 | - private function check_datauri_exclude_list( $url ) |
|
464 | + private function check_datauri_exclude_list($url) |
|
465 | 465 | { |
466 | 466 | static $exclude_list = null; |
467 | 467 | $no_datauris = array(); |
468 | 468 | |
469 | 469 | // Again, skip doing certain stuff repeatedly when loop-called. |
470 | - if ( null === $exclude_list ) { |
|
471 | - $exclude_list = apply_filters( 'autoptimize_filter_css_datauri_exclude', '' ); |
|
472 | - $no_datauris = array_filter( array_map( 'trim', explode( ',', $exclude_list ) ) ); |
|
470 | + if (null === $exclude_list) { |
|
471 | + $exclude_list = apply_filters('autoptimize_filter_css_datauri_exclude', ''); |
|
472 | + $no_datauris = array_filter(array_map('trim', explode(',', $exclude_list))); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | $matched = false; |
476 | 476 | |
477 | - if ( ! empty( $exclude_list ) ) { |
|
478 | - foreach ( $no_datauris as $no_datauri ) { |
|
479 | - if ( false !== strpos( $url, $no_datauri ) ) { |
|
477 | + if (!empty($exclude_list)) { |
|
478 | + foreach ($no_datauris as $no_datauri) { |
|
479 | + if (false !== strpos($url, $no_datauri)) { |
|
480 | 480 | $matched = true; |
481 | 481 | break; |
482 | 482 | } |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | return $matched; |
487 | 487 | } |
488 | 488 | |
489 | - private function build_or_get_datauri_image( $path ) |
|
489 | + private function build_or_get_datauri_image($path) |
|
490 | 490 | { |
491 | 491 | /** |
492 | 492 | * TODO/FIXME: document the required return array format, or better yet, |
@@ -495,27 +495,27 @@ discard block |
||
495 | 495 | */ |
496 | 496 | |
497 | 497 | // Allows short-circuiting datauri generation for an image. |
498 | - $result = apply_filters( 'autoptimize_filter_css_datauri_image', array(), $path ); |
|
499 | - if ( ! empty( $result ) ) { |
|
500 | - if ( is_array( $result ) && isset( $result['full'] ) && isset( $result['base64data'] ) ) { |
|
498 | + $result = apply_filters('autoptimize_filter_css_datauri_image', array(), $path); |
|
499 | + if (!empty($result)) { |
|
500 | + if (is_array($result) && isset($result['full']) && isset($result['base64data'])) { |
|
501 | 501 | return $result; |
502 | 502 | } |
503 | 503 | } |
504 | 504 | |
505 | - $hash = md5( $path ); |
|
506 | - $check = new autoptimizeCache( $hash, 'img' ); |
|
507 | - if ( $check->check() ) { |
|
505 | + $hash = md5($path); |
|
506 | + $check = new autoptimizeCache($hash, 'img'); |
|
507 | + if ($check->check()) { |
|
508 | 508 | // we have the base64 image in cache. |
509 | 509 | $head_and_data = $check->retrieve(); |
510 | - $_base64data = explode( ';base64,', $head_and_data ); |
|
510 | + $_base64data = explode(';base64,', $head_and_data); |
|
511 | 511 | $base64data = $_base64data[1]; |
512 | - unset( $_base64data ); |
|
512 | + unset($_base64data); |
|
513 | 513 | } else { |
514 | 514 | // It's an image and we don't have it in cache, get the type by extension. |
515 | - $exploded_path = explode( '.', $path ); |
|
516 | - $type = end( $exploded_path ); |
|
515 | + $exploded_path = explode('.', $path); |
|
516 | + $type = end($exploded_path); |
|
517 | 517 | |
518 | - switch ( $type ) { |
|
518 | + switch ($type) { |
|
519 | 519 | case 'jpg': |
520 | 520 | case 'jpeg': |
521 | 521 | $dataurihead = 'data:image/jpeg;base64,'; |
@@ -537,13 +537,13 @@ discard block |
||
537 | 537 | } |
538 | 538 | |
539 | 539 | // Encode the data. |
540 | - $base64data = base64_encode( file_get_contents( $path ) ); |
|
541 | - $head_and_data = $dataurihead . $base64data; |
|
540 | + $base64data = base64_encode(file_get_contents($path)); |
|
541 | + $head_and_data = $dataurihead.$base64data; |
|
542 | 542 | |
543 | 543 | // Save in cache. |
544 | - $check->cache( $head_and_data, 'text/plain' ); |
|
544 | + $check->cache($head_and_data, 'text/plain'); |
|
545 | 545 | } |
546 | - unset( $check ); |
|
546 | + unset($check); |
|
547 | 547 | |
548 | 548 | return array( |
549 | 549 | 'full' => $head_and_data, |
@@ -560,13 +560,13 @@ discard block |
||
560 | 560 | * |
561 | 561 | * @return string |
562 | 562 | */ |
563 | - protected static function replace_longest_matches_first( $string, $replacements = array() ) |
|
563 | + protected static function replace_longest_matches_first($string, $replacements = array()) |
|
564 | 564 | { |
565 | - if ( ! empty( $replacements ) ) { |
|
565 | + if (!empty($replacements)) { |
|
566 | 566 | // Sort the replacements array by key length in desc order (so that the longest strings are replaced first). |
567 | - $keys = array_map( 'strlen', array_keys( $replacements ) ); |
|
568 | - array_multisort( $keys, SORT_DESC, $replacements ); |
|
569 | - $string = str_replace( array_keys( $replacements ), array_values( $replacements ), $string ); |
|
567 | + $keys = array_map('strlen', array_keys($replacements)); |
|
568 | + array_multisort($keys, SORT_DESC, $replacements); |
|
569 | + $string = str_replace(array_keys($replacements), array_values($replacements), $string); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | return $string; |
@@ -582,15 +582,15 @@ discard block |
||
582 | 582 | * |
583 | 583 | * @return string |
584 | 584 | */ |
585 | - public function replace_urls( $code = '' ) |
|
585 | + public function replace_urls($code = '') |
|
586 | 586 | { |
587 | 587 | $replacements = array(); |
588 | 588 | |
589 | - preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches ); |
|
590 | - if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) { |
|
591 | - foreach ( $url_src_matches[1] as $count => $original_url ) { |
|
589 | + preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches); |
|
590 | + if (is_array($url_src_matches) && !empty($url_src_matches)) { |
|
591 | + foreach ($url_src_matches[1] as $count => $original_url) { |
|
592 | 592 | // Removes quotes and other cruft. |
593 | - $url = trim( $original_url, " \t\n\r\0\x0B\"'" ); |
|
593 | + $url = trim($original_url, " \t\n\r\0\x0B\"'"); |
|
594 | 594 | |
595 | 595 | /** |
596 | 596 | * TODO/FIXME: Add a way for other code / callable to be called here |
@@ -608,17 +608,17 @@ discard block |
||
608 | 608 | */ |
609 | 609 | |
610 | 610 | // Do CDN replacement if needed. |
611 | - if ( ! empty( $this->cdn_url ) ) { |
|
612 | - $replacement_url = $this->url_replace_cdn( $url ); |
|
611 | + if (!empty($this->cdn_url)) { |
|
612 | + $replacement_url = $this->url_replace_cdn($url); |
|
613 | 613 | // Prepare replacements array. |
614 | - $replacements[ $url_src_matches[1][ $count ] ] = str_replace( |
|
615 | - $original_url, $replacement_url, $url_src_matches[1][ $count ] |
|
614 | + $replacements[$url_src_matches[1][$count]] = str_replace( |
|
615 | + $original_url, $replacement_url, $url_src_matches[1][$count] |
|
616 | 616 | ); |
617 | 617 | } |
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
621 | - $code = self::replace_longest_matches_first( $code, $replacements ); |
|
621 | + $code = self::replace_longest_matches_first($code, $replacements); |
|
622 | 622 | |
623 | 623 | return $code; |
624 | 624 | } |
@@ -631,26 +631,26 @@ discard block |
||
631 | 631 | * @param string $code HTML being processed to hide fonts. |
632 | 632 | * @return string |
633 | 633 | */ |
634 | - public function hide_fontface_and_maybe_cdn( $code ) |
|
634 | + public function hide_fontface_and_maybe_cdn($code) |
|
635 | 635 | { |
636 | 636 | // Proceed only if @font-face declarations exist within $code. |
637 | - preg_match_all( self::FONT_FACE_REGEX, $code, $fontfaces ); |
|
638 | - if ( isset( $fontfaces[0] ) ) { |
|
637 | + preg_match_all(self::FONT_FACE_REGEX, $code, $fontfaces); |
|
638 | + if (isset($fontfaces[0])) { |
|
639 | 639 | // Check if we need to cdn fonts or not. |
640 | - $do_font_cdn = apply_filters( 'autoptimize_filter_css_fonts_cdn', false ); |
|
640 | + $do_font_cdn = apply_filters('autoptimize_filter_css_fonts_cdn', false); |
|
641 | 641 | |
642 | - foreach ( $fontfaces[0] as $full_match ) { |
|
642 | + foreach ($fontfaces[0] as $full_match) { |
|
643 | 643 | // Keep original match so we can search/replace it. |
644 | 644 | $match_search = $full_match; |
645 | 645 | |
646 | 646 | // Do font cdn if needed. |
647 | - if ( $do_font_cdn ) { |
|
648 | - $full_match = $this->replace_urls( $full_match ); |
|
647 | + if ($do_font_cdn) { |
|
648 | + $full_match = $this->replace_urls($full_match); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | // Replace declaration with its base64 encoded string. |
652 | - $replacement = self::build_marker( 'FONTFACE', $full_match ); |
|
653 | - $code = str_replace( $match_search, $replacement, $code ); |
|
652 | + $replacement = self::build_marker('FONTFACE', $full_match); |
|
653 | + $code = str_replace($match_search, $replacement, $code); |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | * @param string $code HTML being processed to unhide fonts. |
665 | 665 | * @return string |
666 | 666 | */ |
667 | - public function restore_fontface( $code ) |
|
667 | + public function restore_fontface($code) |
|
668 | 668 | { |
669 | - return $this->restore_marked_content( 'FONTFACE', $code ); |
|
669 | + return $this->restore_marked_content('FONTFACE', $code); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
@@ -675,10 +675,10 @@ discard block |
||
675 | 675 | * @param string $code HTML being processed rewrite assets. |
676 | 676 | * @return string |
677 | 677 | */ |
678 | - public function rewrite_assets( $code ) |
|
678 | + public function rewrite_assets($code) |
|
679 | 679 | { |
680 | 680 | // Handle @font-face rules by hiding and processing them separately. |
681 | - $code = $this->hide_fontface_and_maybe_cdn( $code ); |
|
681 | + $code = $this->hide_fontface_and_maybe_cdn($code); |
|
682 | 682 | |
683 | 683 | /** |
684 | 684 | * TODO/FIXME: |
@@ -695,35 +695,35 @@ discard block |
||
695 | 695 | $imgreplace = array(); |
696 | 696 | |
697 | 697 | // Matches and captures anything specified within the literal `url()` and excludes those containing data: URIs. |
698 | - preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches ); |
|
699 | - if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) { |
|
700 | - foreach ( $url_src_matches[1] as $count => $original_url ) { |
|
698 | + preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches); |
|
699 | + if (is_array($url_src_matches) && !empty($url_src_matches)) { |
|
700 | + foreach ($url_src_matches[1] as $count => $original_url) { |
|
701 | 701 | // Removes quotes and other cruft. |
702 | - $url = trim( $original_url, " \t\n\r\0\x0B\"'" ); |
|
702 | + $url = trim($original_url, " \t\n\r\0\x0B\"'"); |
|
703 | 703 | |
704 | 704 | // If datauri inlining is turned on, do it. |
705 | 705 | $inlined = false; |
706 | - if ( $this->datauris ) { |
|
706 | + if ($this->datauris) { |
|
707 | 707 | $iurl = $url; |
708 | - if ( false !== strpos( $iurl, '?' ) ) { |
|
709 | - $iurl = strtok( $iurl, '?' ); |
|
708 | + if (false !== strpos($iurl, '?')) { |
|
709 | + $iurl = strtok($iurl, '?'); |
|
710 | 710 | } |
711 | 711 | |
712 | - $ipath = $this->getpath( $iurl ); |
|
712 | + $ipath = $this->getpath($iurl); |
|
713 | 713 | |
714 | - $excluded = $this->check_datauri_exclude_list( $ipath ); |
|
715 | - if ( ! $excluded ) { |
|
716 | - $is_datauri_candidate = $this->is_datauri_candidate( $ipath ); |
|
717 | - if ( $is_datauri_candidate ) { |
|
718 | - $datauri = $this->build_or_get_datauri_image( $ipath ); |
|
714 | + $excluded = $this->check_datauri_exclude_list($ipath); |
|
715 | + if (!$excluded) { |
|
716 | + $is_datauri_candidate = $this->is_datauri_candidate($ipath); |
|
717 | + if ($is_datauri_candidate) { |
|
718 | + $datauri = $this->build_or_get_datauri_image($ipath); |
|
719 | 719 | $base64data = $datauri['base64data']; |
720 | 720 | // Add it to the list for replacement. |
721 | - $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace( |
|
721 | + $imgreplace[$url_src_matches[1][$count]] = str_replace( |
|
722 | 722 | $original_url, |
723 | 723 | $datauri['full'], |
724 | - $url_src_matches[1][ $count ] |
|
724 | + $url_src_matches[1][$count] |
|
725 | 725 | ); |
726 | - $inlined = true; |
|
726 | + $inlined = true; |
|
727 | 727 | } |
728 | 728 | } |
729 | 729 | } |
@@ -734,20 +734,20 @@ discard block |
||
734 | 734 | * inlining isn't turned on, or if a resource is skipped from |
735 | 735 | * being inlined for whatever reason above. |
736 | 736 | */ |
737 | - if ( ! $inlined && ( ! empty( $this->cdn_url ) || has_filter( 'autoptimize_filter_base_replace_cdn' ) ) ) { |
|
737 | + if (!$inlined && (!empty($this->cdn_url) || has_filter('autoptimize_filter_base_replace_cdn'))) { |
|
738 | 738 | // Just do the "simple" CDN replacement. |
739 | - $replacement_url = $this->url_replace_cdn( $url ); |
|
740 | - $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace( |
|
741 | - $original_url, $replacement_url, $url_src_matches[1][ $count ] |
|
739 | + $replacement_url = $this->url_replace_cdn($url); |
|
740 | + $imgreplace[$url_src_matches[1][$count]] = str_replace( |
|
741 | + $original_url, $replacement_url, $url_src_matches[1][$count] |
|
742 | 742 | ); |
743 | 743 | } |
744 | 744 | } |
745 | 745 | } |
746 | 746 | |
747 | - $code = self::replace_longest_matches_first( $code, $imgreplace ); |
|
747 | + $code = self::replace_longest_matches_first($code, $imgreplace); |
|
748 | 748 | |
749 | 749 | // Replace back font-face markers with actual font-face declarations. |
750 | - $code = $this->restore_fontface( $code ); |
|
750 | + $code = $this->restore_fontface($code); |
|
751 | 751 | |
752 | 752 | return $code; |
753 | 753 | } |
@@ -757,29 +757,29 @@ discard block |
||
757 | 757 | */ |
758 | 758 | public function minify() |
759 | 759 | { |
760 | - foreach ( $this->css as $group ) { |
|
761 | - list( $media, $css ) = $group; |
|
762 | - if ( preg_match( '#^INLINE;#', $css ) ) { |
|
760 | + foreach ($this->css as $group) { |
|
761 | + list($media, $css) = $group; |
|
762 | + if (preg_match('#^INLINE;#', $css)) { |
|
763 | 763 | // <style>. |
764 | - $css = preg_replace( '#^INLINE;#', '', $css ); |
|
765 | - $css = self::fixurls( ABSPATH . 'index.php', $css ); // ABSPATH already contains a trailing slash. |
|
766 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, '' ); |
|
767 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
764 | + $css = preg_replace('#^INLINE;#', '', $css); |
|
765 | + $css = self::fixurls(ABSPATH.'index.php', $css); // ABSPATH already contains a trailing slash. |
|
766 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, ''); |
|
767 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
768 | 768 | $css = $tmpstyle; |
769 | 769 | $this->alreadyminified = true; |
770 | 770 | } |
771 | 771 | } else { |
772 | 772 | // <link> |
773 | - if ( false !== $css && file_exists( $css ) && is_readable( $css ) ) { |
|
773 | + if (false !== $css && file_exists($css) && is_readable($css)) { |
|
774 | 774 | $css_path = $css; |
775 | - $css = self::fixurls( $css_path, file_get_contents( $css_path ) ); |
|
776 | - $css = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $css ); |
|
777 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, $css_path ); |
|
778 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
775 | + $css = self::fixurls($css_path, file_get_contents($css_path)); |
|
776 | + $css = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $css); |
|
777 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, $css_path); |
|
778 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
779 | 779 | $css = $tmpstyle; |
780 | 780 | $this->alreadyminified = true; |
781 | - } elseif ( $this->can_inject_late( $css_path, $css ) ) { |
|
782 | - $css = self::build_injectlater_marker( $css_path, md5( $css ) ); |
|
781 | + } elseif ($this->can_inject_late($css_path, $css)) { |
|
782 | + $css = self::build_injectlater_marker($css_path, md5($css)); |
|
783 | 783 | } |
784 | 784 | } else { |
785 | 785 | // Couldn't read CSS. Maybe getpath isn't working? |
@@ -787,12 +787,12 @@ discard block |
||
787 | 787 | } |
788 | 788 | } |
789 | 789 | |
790 | - foreach ( $media as $elem ) { |
|
791 | - if ( ! empty( $css ) ) { |
|
792 | - if ( ! isset( $this->csscode[ $elem ] ) ) { |
|
793 | - $this->csscode[ $elem ] = ''; |
|
790 | + foreach ($media as $elem) { |
|
791 | + if (!empty($css)) { |
|
792 | + if (!isset($this->csscode[$elem])) { |
|
793 | + $this->csscode[$elem] = ''; |
|
794 | 794 | } |
795 | - $this->csscode[ $elem ] .= "\n/*FILESTART*/" . $css; |
|
795 | + $this->csscode[$elem] .= "\n/*FILESTART*/".$css; |
|
796 | 796 | } |
797 | 797 | } |
798 | 798 | } |
@@ -800,133 +800,133 @@ discard block |
||
800 | 800 | // Check for duplicate code. |
801 | 801 | $md5list = array(); |
802 | 802 | $tmpcss = $this->csscode; |
803 | - foreach ( $tmpcss as $media => $code ) { |
|
804 | - $md5sum = md5( $code ); |
|
803 | + foreach ($tmpcss as $media => $code) { |
|
804 | + $md5sum = md5($code); |
|
805 | 805 | $medianame = $media; |
806 | - foreach ( $md5list as $med => $sum ) { |
|
806 | + foreach ($md5list as $med => $sum) { |
|
807 | 807 | // If same code. |
808 | - if ( $sum === $md5sum ) { |
|
808 | + if ($sum === $md5sum) { |
|
809 | 809 | // Add the merged code. |
810 | - $medianame = $med . ', ' . $media; |
|
811 | - $this->csscode[ $medianame ] = $code; |
|
812 | - $md5list[ $medianame ] = $md5list[ $med ]; |
|
813 | - unset( $this->csscode[ $med ], $this->csscode[ $media ], $md5list[ $med ] ); |
|
810 | + $medianame = $med.', '.$media; |
|
811 | + $this->csscode[$medianame] = $code; |
|
812 | + $md5list[$medianame] = $md5list[$med]; |
|
813 | + unset($this->csscode[$med], $this->csscode[$media], $md5list[$med]); |
|
814 | 814 | } |
815 | 815 | } |
816 | - $md5list[ $medianame ] = $md5sum; |
|
816 | + $md5list[$medianame] = $md5sum; |
|
817 | 817 | } |
818 | - unset( $tmpcss ); |
|
818 | + unset($tmpcss); |
|
819 | 819 | |
820 | 820 | // Manage @imports, while is for recursive import management. |
821 | - foreach ( $this->csscode as &$thiscss ) { |
|
821 | + foreach ($this->csscode as &$thiscss) { |
|
822 | 822 | // Flag to trigger import reconstitution and var to hold external imports. |
823 | 823 | $fiximports = false; |
824 | 824 | $external_imports = ''; |
825 | 825 | |
826 | 826 | // remove comments to avoid importing commented-out imports. |
827 | - $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss ); |
|
828 | - while ( preg_match_all( '#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches ) ) { |
|
829 | - foreach ( $matches[0] as $import ) { |
|
830 | - if ( $this->isremovable( $import, $this->cssremovables ) ) { |
|
831 | - $thiscss = str_replace( $import, '', $thiscss ); |
|
827 | + $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss); |
|
828 | + while (preg_match_all('#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches)) { |
|
829 | + foreach ($matches[0] as $import) { |
|
830 | + if ($this->isremovable($import, $this->cssremovables)) { |
|
831 | + $thiscss = str_replace($import, '', $thiscss); |
|
832 | 832 | $import_ok = true; |
833 | 833 | } else { |
834 | - $url = trim( preg_replace( '#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim( $import ) ), " \t\n\r\0\x0B\"'" ); |
|
835 | - $path = $this->getpath( $url ); |
|
834 | + $url = trim(preg_replace('#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim($import)), " \t\n\r\0\x0B\"'"); |
|
835 | + $path = $this->getpath($url); |
|
836 | 836 | $import_ok = false; |
837 | - if ( file_exists( $path ) && is_readable( $path ) ) { |
|
838 | - $code = addcslashes( self::fixurls( $path, file_get_contents( $path ) ), '\\' ); |
|
839 | - $code = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $code ); |
|
840 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $code, '' ); |
|
841 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
837 | + if (file_exists($path) && is_readable($path)) { |
|
838 | + $code = addcslashes(self::fixurls($path, file_get_contents($path)), '\\'); |
|
839 | + $code = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $code); |
|
840 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $code, ''); |
|
841 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
842 | 842 | $code = $tmpstyle; |
843 | 843 | $this->alreadyminified = true; |
844 | - } elseif ( $this->can_inject_late( $path, $code ) ) { |
|
845 | - $code = self::build_injectlater_marker( $path, md5( $code ) ); |
|
844 | + } elseif ($this->can_inject_late($path, $code)) { |
|
845 | + $code = self::build_injectlater_marker($path, md5($code)); |
|
846 | 846 | } |
847 | 847 | |
848 | - if ( ! empty( $code ) ) { |
|
849 | - $tmp_thiscss = preg_replace( '#(/\*FILESTART\*/.*)' . preg_quote( $import, '#' ) . '#Us', '/*FILESTART2*/' . $code . '$1', $thiscss ); |
|
850 | - if ( ! empty( $tmp_thiscss ) ) { |
|
848 | + if (!empty($code)) { |
|
849 | + $tmp_thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import, '#').'#Us', '/*FILESTART2*/'.$code.'$1', $thiscss); |
|
850 | + if (!empty($tmp_thiscss)) { |
|
851 | 851 | $thiscss = $tmp_thiscss; |
852 | 852 | $import_ok = true; |
853 | - unset( $tmp_thiscss ); |
|
853 | + unset($tmp_thiscss); |
|
854 | 854 | } |
855 | 855 | } |
856 | - unset( $code ); |
|
856 | + unset($code); |
|
857 | 857 | } |
858 | 858 | } |
859 | - if ( ! $import_ok ) { |
|
859 | + if (!$import_ok) { |
|
860 | 860 | // External imports and general fall-back. |
861 | 861 | $external_imports .= $import; |
862 | 862 | |
863 | - $thiscss = str_replace( $import, '', $thiscss ); |
|
863 | + $thiscss = str_replace($import, '', $thiscss); |
|
864 | 864 | $fiximports = true; |
865 | 865 | } |
866 | 866 | } |
867 | - $thiscss = preg_replace( '#/\*FILESTART\*/#', '', $thiscss ); |
|
868 | - $thiscss = preg_replace( '#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss ); |
|
867 | + $thiscss = preg_replace('#/\*FILESTART\*/#', '', $thiscss); |
|
868 | + $thiscss = preg_replace('#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss); |
|
869 | 869 | |
870 | 870 | // and update $thiscss_nocomments before going into next iteration in while loop. |
871 | - $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss ); |
|
871 | + $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss); |
|
872 | 872 | } |
873 | - unset( $thiscss_nocomments ); |
|
873 | + unset($thiscss_nocomments); |
|
874 | 874 | |
875 | 875 | // Add external imports to top of aggregated CSS. |
876 | - if ( $fiximports ) { |
|
877 | - $thiscss = $external_imports . $thiscss; |
|
876 | + if ($fiximports) { |
|
877 | + $thiscss = $external_imports.$thiscss; |
|
878 | 878 | } |
879 | 879 | } |
880 | - unset( $thiscss ); |
|
880 | + unset($thiscss); |
|
881 | 881 | |
882 | 882 | // $this->csscode has all the uncompressed code now. |
883 | - foreach ( $this->csscode as &$code ) { |
|
883 | + foreach ($this->csscode as &$code) { |
|
884 | 884 | // Check for already-minified code. |
885 | - $hash = md5( $code ); |
|
886 | - do_action( 'autoptimize_action_css_hash', $hash ); |
|
887 | - $ccheck = new autoptimizeCache( $hash, 'css' ); |
|
888 | - if ( $ccheck->check() ) { |
|
885 | + $hash = md5($code); |
|
886 | + do_action('autoptimize_action_css_hash', $hash); |
|
887 | + $ccheck = new autoptimizeCache($hash, 'css'); |
|
888 | + if ($ccheck->check()) { |
|
889 | 889 | $code = $ccheck->retrieve(); |
890 | - $this->hashmap[ md5( $code ) ] = $hash; |
|
890 | + $this->hashmap[md5($code)] = $hash; |
|
891 | 891 | continue; |
892 | 892 | } |
893 | - unset( $ccheck ); |
|
893 | + unset($ccheck); |
|
894 | 894 | |
895 | 895 | // Rewrite and/or inline referenced assets. |
896 | - $code = $this->rewrite_assets( $code ); |
|
896 | + $code = $this->rewrite_assets($code); |
|
897 | 897 | |
898 | 898 | // Minify. |
899 | - $code = $this->run_minifier_on( $code ); |
|
899 | + $code = $this->run_minifier_on($code); |
|
900 | 900 | |
901 | 901 | // Bring back INJECTLATER stuff. |
902 | - $code = $this->inject_minified( $code ); |
|
902 | + $code = $this->inject_minified($code); |
|
903 | 903 | |
904 | 904 | // Filter results. |
905 | - $tmp_code = apply_filters( 'autoptimize_css_after_minify', $code ); |
|
906 | - if ( ! empty( $tmp_code ) ) { |
|
905 | + $tmp_code = apply_filters('autoptimize_css_after_minify', $code); |
|
906 | + if (!empty($tmp_code)) { |
|
907 | 907 | $code = $tmp_code; |
908 | - unset( $tmp_code ); |
|
908 | + unset($tmp_code); |
|
909 | 909 | } |
910 | 910 | |
911 | - $this->hashmap[ md5( $code ) ] = $hash; |
|
911 | + $this->hashmap[md5($code)] = $hash; |
|
912 | 912 | } |
913 | 913 | |
914 | - unset( $code ); |
|
914 | + unset($code); |
|
915 | 915 | return true; |
916 | 916 | } |
917 | 917 | |
918 | - public function run_minifier_on( $code ) |
|
918 | + public function run_minifier_on($code) |
|
919 | 919 | { |
920 | - if ( ! $this->alreadyminified ) { |
|
921 | - $do_minify = apply_filters( 'autoptimize_css_do_minify', true ); |
|
920 | + if (!$this->alreadyminified) { |
|
921 | + $do_minify = apply_filters('autoptimize_css_do_minify', true); |
|
922 | 922 | |
923 | - if ( $do_minify ) { |
|
923 | + if ($do_minify) { |
|
924 | 924 | $cssmin = new autoptimizeCSSmin(); |
925 | - $tmp_code = trim( $cssmin->run( $code ) ); |
|
925 | + $tmp_code = trim($cssmin->run($code)); |
|
926 | 926 | |
927 | - if ( ! empty( $tmp_code ) ) { |
|
927 | + if (!empty($tmp_code)) { |
|
928 | 928 | $code = $tmp_code; |
929 | - unset( $tmp_code ); |
|
929 | + unset($tmp_code); |
|
930 | 930 | } |
931 | 931 | } |
932 | 932 | } |
@@ -940,18 +940,18 @@ discard block |
||
940 | 940 | public function cache() |
941 | 941 | { |
942 | 942 | // CSS cache. |
943 | - foreach ( $this->csscode as $media => $code ) { |
|
944 | - if ( empty( $code ) ) { |
|
943 | + foreach ($this->csscode as $media => $code) { |
|
944 | + if (empty($code)) { |
|
945 | 945 | continue; |
946 | 946 | } |
947 | 947 | |
948 | - $md5 = $this->hashmap[ md5( $code ) ]; |
|
949 | - $cache = new autoptimizeCache( $md5, 'css' ); |
|
950 | - if ( ! $cache->check() ) { |
|
948 | + $md5 = $this->hashmap[md5($code)]; |
|
949 | + $cache = new autoptimizeCache($md5, 'css'); |
|
950 | + if (!$cache->check()) { |
|
951 | 951 | // Cache our code. |
952 | - $cache->cache( $code, 'text/css' ); |
|
952 | + $cache->cache($code, 'text/css'); |
|
953 | 953 | } |
954 | - $this->url[ $media ] = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
954 | + $this->url[$media] = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
955 | 955 | } |
956 | 956 | } |
957 | 957 | |
@@ -961,99 +961,99 @@ discard block |
||
961 | 961 | public function getcontent() |
962 | 962 | { |
963 | 963 | // Restore the full content (only applies when "autoptimize_filter_css_justhead" filter is true). |
964 | - if ( ! empty( $this->restofcontent ) ) { |
|
964 | + if (!empty($this->restofcontent)) { |
|
965 | 965 | $this->content .= $this->restofcontent; |
966 | 966 | $this->restofcontent = ''; |
967 | 967 | } |
968 | 968 | |
969 | 969 | // type is not added by default. |
970 | 970 | $type_css = ''; |
971 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
971 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
972 | 972 | $type_css = 'type="text/css" '; |
973 | 973 | } |
974 | 974 | |
975 | 975 | // Inject the new stylesheets. |
976 | - $replace_tag = array( '<title', 'before' ); |
|
977 | - $replace_tag = apply_filters( 'autoptimize_filter_css_replacetag', $replace_tag, $this->content ); |
|
976 | + $replace_tag = array('<title', 'before'); |
|
977 | + $replace_tag = apply_filters('autoptimize_filter_css_replacetag', $replace_tag, $this->content); |
|
978 | 978 | |
979 | - if ( $this->inline ) { |
|
980 | - foreach ( $this->csscode as $media => $code ) { |
|
981 | - $this->inject_in_html( '<style ' . $type_css . 'media="' . $media . '">' . $code . '</style>', $replace_tag ); |
|
979 | + if ($this->inline) { |
|
980 | + foreach ($this->csscode as $media => $code) { |
|
981 | + $this->inject_in_html('<style '.$type_css.'media="'.$media.'">'.$code.'</style>', $replace_tag); |
|
982 | 982 | } |
983 | 983 | } else { |
984 | - if ( $this->defer ) { |
|
984 | + if ($this->defer) { |
|
985 | 985 | $preload_css_block = ''; |
986 | 986 | $inlined_ccss_block = ''; |
987 | 987 | $noscript_css_block = '<noscript id="aonoscrcss">'; |
988 | 988 | |
989 | 989 | $defer_inline_code = $this->defer_inline; |
990 | - if ( ! empty( $defer_inline_code ) ) { |
|
991 | - if ( apply_filters( 'autoptimize_filter_css_critcss_minify', true ) ) { |
|
992 | - $icss_hash = md5( $defer_inline_code ); |
|
993 | - $icss_cache = new autoptimizeCache( $icss_hash, 'css' ); |
|
994 | - if ( $icss_cache->check() ) { |
|
990 | + if (!empty($defer_inline_code)) { |
|
991 | + if (apply_filters('autoptimize_filter_css_critcss_minify', true)) { |
|
992 | + $icss_hash = md5($defer_inline_code); |
|
993 | + $icss_cache = new autoptimizeCache($icss_hash, 'css'); |
|
994 | + if ($icss_cache->check()) { |
|
995 | 995 | // we have the optimized inline CSS in cache. |
996 | 996 | $defer_inline_code = $icss_cache->retrieve(); |
997 | 997 | } else { |
998 | 998 | $cssmin = new autoptimizeCSSmin(); |
999 | - $tmp_code = trim( $cssmin->run( $defer_inline_code ) ); |
|
999 | + $tmp_code = trim($cssmin->run($defer_inline_code)); |
|
1000 | 1000 | |
1001 | - if ( ! empty( $tmp_code ) ) { |
|
1001 | + if (!empty($tmp_code)) { |
|
1002 | 1002 | $defer_inline_code = $tmp_code; |
1003 | - $icss_cache->cache( $defer_inline_code, 'text/css' ); |
|
1004 | - unset( $tmp_code ); |
|
1003 | + $icss_cache->cache($defer_inline_code, 'text/css'); |
|
1004 | + unset($tmp_code); |
|
1005 | 1005 | } |
1006 | 1006 | } |
1007 | 1007 | } |
1008 | 1008 | // inlined critical css set here, but injected when full CSS is injected |
1009 | 1009 | // to avoid CSS containing SVG with <title tag receiving the full CSS link. |
1010 | - $inlined_ccss_block = '<style ' . $type_css . 'id="aoatfcss" media="all">' . $defer_inline_code . '</style>'; |
|
1010 | + $inlined_ccss_block = '<style '.$type_css.'id="aoatfcss" media="all">'.$defer_inline_code.'</style>'; |
|
1011 | 1011 | } |
1012 | 1012 | } |
1013 | 1013 | |
1014 | - foreach ( $this->url as $media => $url ) { |
|
1015 | - $url = $this->url_replace_cdn( $url ); |
|
1014 | + foreach ($this->url as $media => $url) { |
|
1015 | + $url = $this->url_replace_cdn($url); |
|
1016 | 1016 | |
1017 | 1017 | // Add the stylesheet either deferred (import at bottom) or normal links in head. |
1018 | - if ( $this->defer ) { |
|
1018 | + if ($this->defer) { |
|
1019 | 1019 | $preload_onload = autoptimizeConfig::get_ao_css_preload_onload(); |
1020 | 1020 | |
1021 | - $preload_css_block .= '<link rel="preload" as="style" media="' . $media . '" href="' . $url . '" onload="' . $preload_onload . '" />'; |
|
1022 | - $noscript_css_block .= '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />'; |
|
1021 | + $preload_css_block .= '<link rel="preload" as="style" media="'.$media.'" href="'.$url.'" onload="'.$preload_onload.'" />'; |
|
1022 | + $noscript_css_block .= '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />'; |
|
1023 | 1023 | } else { |
1024 | - if ( strlen( $this->csscode[ $media ] ) > $this->cssinlinesize ) { |
|
1025 | - $this->inject_in_html( '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />', $replace_tag ); |
|
1026 | - } elseif ( strlen( $this->csscode[ $media ] ) > 0 ) { |
|
1027 | - $this->inject_in_html( '<style ' . $type_css . 'media="' . $media . '">' . $this->csscode[ $media ] . '</style>', $replace_tag ); |
|
1024 | + if (strlen($this->csscode[$media]) > $this->cssinlinesize) { |
|
1025 | + $this->inject_in_html('<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />', $replace_tag); |
|
1026 | + } elseif (strlen($this->csscode[$media]) > 0) { |
|
1027 | + $this->inject_in_html('<style '.$type_css.'media="'.$media.'">'.$this->csscode[$media].'</style>', $replace_tag); |
|
1028 | 1028 | } |
1029 | 1029 | } |
1030 | 1030 | } |
1031 | 1031 | |
1032 | - if ( $this->defer ) { |
|
1032 | + if ($this->defer) { |
|
1033 | 1033 | $preload_polyfill = autoptimizeConfig::get_ao_css_preload_polyfill(); |
1034 | 1034 | $noscript_css_block .= '</noscript>'; |
1035 | 1035 | // Inject inline critical CSS, the preloaded full CSS and the noscript-CSS. |
1036 | - $this->inject_in_html( $inlined_ccss_block . $preload_css_block . $noscript_css_block, $replace_tag ); |
|
1036 | + $this->inject_in_html($inlined_ccss_block.$preload_css_block.$noscript_css_block, $replace_tag); |
|
1037 | 1037 | |
1038 | 1038 | // Adds preload polyfill at end of body tag. |
1039 | 1039 | $this->inject_in_html( |
1040 | - apply_filters( 'autoptimize_css_preload_polyfill', $preload_polyfill ), |
|
1041 | - apply_filters( 'autoptimize_css_preload_polyfill_injectat', array( '</body>', 'before' ) ) |
|
1040 | + apply_filters('autoptimize_css_preload_polyfill', $preload_polyfill), |
|
1041 | + apply_filters('autoptimize_css_preload_polyfill_injectat', array('</body>', 'before')) |
|
1042 | 1042 | ); |
1043 | 1043 | } |
1044 | 1044 | } |
1045 | 1045 | |
1046 | 1046 | // restore comments. |
1047 | - $this->content = $this->restore_comments( $this->content ); |
|
1047 | + $this->content = $this->restore_comments($this->content); |
|
1048 | 1048 | |
1049 | 1049 | // restore IE hacks. |
1050 | - $this->content = $this->restore_iehacks( $this->content ); |
|
1050 | + $this->content = $this->restore_iehacks($this->content); |
|
1051 | 1051 | |
1052 | 1052 | // restore (no)script. |
1053 | - $this->content = $this->restore_marked_content( 'SCRIPT', $this->content ); |
|
1053 | + $this->content = $this->restore_marked_content('SCRIPT', $this->content); |
|
1054 | 1054 | |
1055 | 1055 | // Restore noptimize. |
1056 | - $this->content = $this->restore_noptimize( $this->content ); |
|
1056 | + $this->content = $this->restore_noptimize($this->content); |
|
1057 | 1057 | |
1058 | 1058 | // Return the modified stylesheet. |
1059 | 1059 | return $this->content; |
@@ -1065,44 +1065,44 @@ discard block |
||
1065 | 1065 | * @param string $file filename of optimized CSS-file. |
1066 | 1066 | * @param string $code CSS-code in which to fix URL's. |
1067 | 1067 | */ |
1068 | - static function fixurls( $file, $code ) |
|
1068 | + static function fixurls($file, $code) |
|
1069 | 1069 | { |
1070 | 1070 | // Switch all imports to the url() syntax. |
1071 | - $code = preg_replace( '#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code ); |
|
1071 | + $code = preg_replace('#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code); |
|
1072 | 1072 | |
1073 | - if ( preg_match_all( self::ASSETS_REGEX, $code, $matches ) ) { |
|
1074 | - $file = str_replace( WP_ROOT_DIR, '/', $file ); |
|
1073 | + if (preg_match_all(self::ASSETS_REGEX, $code, $matches)) { |
|
1074 | + $file = str_replace(WP_ROOT_DIR, '/', $file); |
|
1075 | 1075 | /** |
1076 | 1076 | * Rollback as per https://github.com/futtta/autoptimize/issues/94 |
1077 | 1077 | * $file = str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', $file ); |
1078 | 1078 | */ |
1079 | - $dir = dirname( $file ); // Like /themes/expound/css. |
|
1079 | + $dir = dirname($file); // Like /themes/expound/css. |
|
1080 | 1080 | |
1081 | 1081 | /** |
1082 | 1082 | * $dir should not contain backslashes, since it's used to replace |
1083 | 1083 | * urls, but it can contain them when running on Windows because |
1084 | 1084 | * fixurls() is sometimes called with `ABSPATH . 'index.php'` |
1085 | 1085 | */ |
1086 | - $dir = str_replace( '\\', '/', $dir ); |
|
1087 | - unset( $file ); // not used below at all. |
|
1086 | + $dir = str_replace('\\', '/', $dir); |
|
1087 | + unset($file); // not used below at all. |
|
1088 | 1088 | |
1089 | 1089 | $replace = array(); |
1090 | - foreach ( $matches[1] as $k => $url ) { |
|
1090 | + foreach ($matches[1] as $k => $url) { |
|
1091 | 1091 | // Remove quotes. |
1092 | - $url = trim( $url, " \t\n\r\0\x0B\"'" ); |
|
1093 | - $no_q_url = trim( $url, "\"'" ); |
|
1094 | - if ( $url !== $no_q_url ) { |
|
1092 | + $url = trim($url, " \t\n\r\0\x0B\"'"); |
|
1093 | + $no_q_url = trim($url, "\"'"); |
|
1094 | + if ($url !== $no_q_url) { |
|
1095 | 1095 | $removed_quotes = true; |
1096 | 1096 | } else { |
1097 | 1097 | $removed_quotes = false; |
1098 | 1098 | } |
1099 | 1099 | |
1100 | - if ( '' === $no_q_url ) { |
|
1100 | + if ('' === $no_q_url) { |
|
1101 | 1101 | continue; |
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | $url = $no_q_url; |
1105 | - if ( '/' === $url[0] || preg_match( '#^(https?://|ftp://|data:)#i', $url ) ) { |
|
1105 | + if ('/' === $url[0] || preg_match('#^(https?://|ftp://|data:)#i', $url)) { |
|
1106 | 1106 | // URL is protocol-relative, host-relative or something we don't touch. |
1107 | 1107 | continue; |
1108 | 1108 | } else { // Relative URL. |
@@ -1111,49 +1111,49 @@ discard block |
||
1111 | 1111 | * rollback as per https://github.com/futtta/autoptimize/issues/94 |
1112 | 1112 | * $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_CONTENT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) ); |
1113 | 1113 | */ |
1114 | - $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_ROOT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) ); |
|
1115 | - $newurl = apply_filters( 'autoptimize_filter_css_fixurl_newurl', $newurl ); |
|
1114 | + $newurl = preg_replace('/https?:/', '', str_replace(' ', '%20', AUTOPTIMIZE_WP_ROOT_URL.str_replace('//', '/', $dir.'/'.$url))); |
|
1115 | + $newurl = apply_filters('autoptimize_filter_css_fixurl_newurl', $newurl); |
|
1116 | 1116 | |
1117 | 1117 | /** |
1118 | 1118 | * Hash the url + whatever was behind potentially for replacement |
1119 | 1119 | * We must do this, or different css classes referencing the same bg image (but |
1120 | 1120 | * different parts of it, say, in sprites and such) loose their stuff... |
1121 | 1121 | */ |
1122 | - $hash = md5( $url . $matches[2][ $k ] ); |
|
1123 | - $code = str_replace( $matches[0][ $k ], $hash, $code ); |
|
1122 | + $hash = md5($url.$matches[2][$k]); |
|
1123 | + $code = str_replace($matches[0][$k], $hash, $code); |
|
1124 | 1124 | |
1125 | - if ( $removed_quotes ) { |
|
1126 | - $replace[ $hash ] = "url('" . $newurl . "')" . $matches[2][ $k ]; |
|
1125 | + if ($removed_quotes) { |
|
1126 | + $replace[$hash] = "url('".$newurl."')".$matches[2][$k]; |
|
1127 | 1127 | } else { |
1128 | - $replace[ $hash ] = 'url(' . $newurl . ')' . $matches[2][ $k ]; |
|
1128 | + $replace[$hash] = 'url('.$newurl.')'.$matches[2][$k]; |
|
1129 | 1129 | } |
1130 | 1130 | } |
1131 | 1131 | } |
1132 | 1132 | |
1133 | - $code = self::replace_longest_matches_first( $code, $replace ); |
|
1133 | + $code = self::replace_longest_matches_first($code, $replace); |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | return $code; |
1137 | 1137 | } |
1138 | 1138 | |
1139 | - private function ismovable( $tag ) |
|
1139 | + private function ismovable($tag) |
|
1140 | 1140 | { |
1141 | - if ( ! $this->aggregate ) { |
|
1141 | + if (!$this->aggregate) { |
|
1142 | 1142 | return false; |
1143 | 1143 | } |
1144 | 1144 | |
1145 | - if ( ! empty( $this->whitelist ) ) { |
|
1146 | - foreach ( $this->whitelist as $match ) { |
|
1147 | - if ( false !== strpos( $tag, $match ) ) { |
|
1145 | + if (!empty($this->whitelist)) { |
|
1146 | + foreach ($this->whitelist as $match) { |
|
1147 | + if (false !== strpos($tag, $match)) { |
|
1148 | 1148 | return true; |
1149 | 1149 | } |
1150 | 1150 | } |
1151 | 1151 | // no match with whitelist. |
1152 | 1152 | return false; |
1153 | 1153 | } else { |
1154 | - if ( is_array( $this->dontmove ) && ! empty( $this->dontmove ) ) { |
|
1155 | - foreach ( $this->dontmove as $match ) { |
|
1156 | - if ( false !== strpos( $tag, $match ) ) { |
|
1154 | + if (is_array($this->dontmove) && !empty($this->dontmove)) { |
|
1155 | + foreach ($this->dontmove as $match) { |
|
1156 | + if (false !== strpos($tag, $match)) { |
|
1157 | 1157 | // Matched something. |
1158 | 1158 | return false; |
1159 | 1159 | } |
@@ -1165,22 +1165,22 @@ discard block |
||
1165 | 1165 | } |
1166 | 1166 | } |
1167 | 1167 | |
1168 | - private function can_inject_late( $css_path, $css ) |
|
1168 | + private function can_inject_late($css_path, $css) |
|
1169 | 1169 | { |
1170 | - $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false, $css_path ); |
|
1171 | - if ( true !== $this->inject_min_late ) { |
|
1170 | + $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $css_path); |
|
1171 | + if (true !== $this->inject_min_late) { |
|
1172 | 1172 | // late-inject turned off. |
1173 | 1173 | return false; |
1174 | - } elseif ( ( false === strpos( $css_path, 'min.css' ) ) && ( str_replace( $consider_minified_array, '', $css_path ) === $css_path ) ) { |
|
1174 | + } elseif ((false === strpos($css_path, 'min.css')) && (str_replace($consider_minified_array, '', $css_path) === $css_path)) { |
|
1175 | 1175 | // file not minified based on filename & filter. |
1176 | 1176 | return false; |
1177 | - } elseif ( false !== strpos( $css, '@import' ) ) { |
|
1177 | + } elseif (false !== strpos($css, '@import')) { |
|
1178 | 1178 | // can't late-inject files with imports as those need to be aggregated. |
1179 | 1179 | return false; |
1180 | - } elseif ( ( false !== strpos( $css, '@font-face' ) ) && ( apply_filters( 'autoptimize_filter_css_fonts_cdn', false ) === true ) && ( ! empty( $this->cdn_url ) ) ) { |
|
1180 | + } elseif ((false !== strpos($css, '@font-face')) && (apply_filters('autoptimize_filter_css_fonts_cdn', false) === true) && (!empty($this->cdn_url))) { |
|
1181 | 1181 | // don't late-inject CSS with font-src's if fonts are set to be CDN'ed. |
1182 | 1182 | return false; |
1183 | - } elseif ( ( ( true == $this->datauris ) || ( ! empty( $this->cdn_url ) ) ) && preg_match( '#background[^;}]*url\(#Ui', $css ) ) { |
|
1183 | + } elseif (((true == $this->datauris) || (!empty($this->cdn_url))) && preg_match('#background[^;}]*url\(#Ui', $css)) { |
|
1184 | 1184 | // don't late-inject CSS with images if CDN is set OR if image inlining is on. |
1185 | 1185 | return false; |
1186 | 1186 | } else { |
@@ -1198,41 +1198,41 @@ discard block |
||
1198 | 1198 | * |
1199 | 1199 | * @return bool|string Url pointing to the minified css file or false. |
1200 | 1200 | */ |
1201 | - public function minify_single( $filepath, $cache_miss = false ) |
|
1201 | + public function minify_single($filepath, $cache_miss = false) |
|
1202 | 1202 | { |
1203 | - $contents = $this->prepare_minify_single( $filepath ); |
|
1203 | + $contents = $this->prepare_minify_single($filepath); |
|
1204 | 1204 | |
1205 | - if ( empty( $contents ) ) { |
|
1205 | + if (empty($contents)) { |
|
1206 | 1206 | return false; |
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | // Check cache. |
1210 | - $hash = 'single_' . md5( $contents ); |
|
1211 | - $cache = new autoptimizeCache( $hash, 'css' ); |
|
1212 | - do_action( 'autoptimize_action_css_hash', $hash ); |
|
1210 | + $hash = 'single_'.md5($contents); |
|
1211 | + $cache = new autoptimizeCache($hash, 'css'); |
|
1212 | + do_action('autoptimize_action_css_hash', $hash); |
|
1213 | 1213 | |
1214 | 1214 | // If not in cache already, minify... |
1215 | - if ( ! $cache->check() || $cache_miss ) { |
|
1215 | + if (!$cache->check() || $cache_miss) { |
|
1216 | 1216 | // Fixurls... |
1217 | - $contents = self::fixurls( $filepath, $contents ); |
|
1217 | + $contents = self::fixurls($filepath, $contents); |
|
1218 | 1218 | // CDN-replace any referenced assets if needed... |
1219 | - $contents = $this->hide_fontface_and_maybe_cdn( $contents ); |
|
1220 | - $contents = $this->replace_urls( $contents ); |
|
1221 | - $contents = $this->restore_fontface( $contents ); |
|
1219 | + $contents = $this->hide_fontface_and_maybe_cdn($contents); |
|
1220 | + $contents = $this->replace_urls($contents); |
|
1221 | + $contents = $this->restore_fontface($contents); |
|
1222 | 1222 | // Now minify... |
1223 | 1223 | $cssmin = new autoptimizeCSSmin(); |
1224 | - $contents = trim( $cssmin->run( $contents ) ); |
|
1224 | + $contents = trim($cssmin->run($contents)); |
|
1225 | 1225 | |
1226 | 1226 | // Check if minified cache content is empty. |
1227 | - if ( empty( $contents ) ) { |
|
1227 | + if (empty($contents)) { |
|
1228 | 1228 | return false; |
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | // Store in cache. |
1232 | - $cache->cache( $contents, 'text/css' ); |
|
1232 | + $cache->cache($contents, 'text/css'); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | - $url = $this->build_minify_single_url( $cache ); |
|
1235 | + $url = $this->build_minify_single_url($cache); |
|
1236 | 1236 | |
1237 | 1237 | return $url; |
1238 | 1238 | } |
@@ -1252,19 +1252,19 @@ discard block |
||
1252 | 1252 | return $this->options; |
1253 | 1253 | } |
1254 | 1254 | |
1255 | - public function replaceOptions( $options ) |
|
1255 | + public function replaceOptions($options) |
|
1256 | 1256 | { |
1257 | 1257 | $this->options = $options; |
1258 | 1258 | } |
1259 | 1259 | |
1260 | - public function setOption( $name, $value ) |
|
1260 | + public function setOption($name, $value) |
|
1261 | 1261 | { |
1262 | - $this->options[ $name ] = $value; |
|
1262 | + $this->options[$name] = $value; |
|
1263 | 1263 | $this->$name = $value; |
1264 | 1264 | } |
1265 | 1265 | |
1266 | - public function getOption( $name ) |
|
1266 | + public function getOption($name) |
|
1267 | 1267 | { |
1268 | - return $this->options[ $name ]; |
|
1268 | + return $this->options[$name]; |
|
1269 | 1269 | } |
1270 | 1270 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles autoptimizeExtra frontend features + admin options page |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @param array $options Optional. Allows overriding options without having to specify them via admin options page. |
30 | 30 | */ |
31 | - public function __construct( $options = array() ) |
|
31 | + public function __construct($options = array()) |
|
32 | 32 | { |
33 | - if ( empty( $options ) ) { |
|
33 | + if (empty($options)) { |
|
34 | 34 | $options = self::fetch_options(); |
35 | 35 | } |
36 | 36 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public static function instance() |
49 | 49 | { |
50 | - if ( null === self::$instance ) { |
|
50 | + if (null === self::$instance) { |
|
51 | 51 | self::$instance = new self(); |
52 | 52 | } |
53 | 53 | |
@@ -56,19 +56,19 @@ discard block |
||
56 | 56 | |
57 | 57 | public function run() |
58 | 58 | { |
59 | - if ( is_admin() ) { |
|
60 | - if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
61 | - add_action( 'network_admin_menu', array( $this, 'admin_menu' ) ); |
|
59 | + if (is_admin()) { |
|
60 | + if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
61 | + add_action('network_admin_menu', array($this, 'admin_menu')); |
|
62 | 62 | } else { |
63 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
63 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
64 | 64 | } |
65 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_extra_tab' ) ); |
|
65 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_extra_tab')); |
|
66 | 66 | } else { |
67 | - add_action( 'wp', array( $this, 'run_on_frontend' ) ); |
|
67 | + add_action('wp', array($this, 'run_on_frontend')); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - public function set_options( array $options ) |
|
71 | + public function set_options(array $options) |
|
72 | 72 | { |
73 | 73 | $this->options = $options; |
74 | 74 | |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | |
78 | 78 | public static function fetch_options() |
79 | 79 | { |
80 | - $value = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings' ); |
|
81 | - if ( empty( $value ) ) { |
|
80 | + $value = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings'); |
|
81 | + if (empty($value)) { |
|
82 | 82 | // Fallback to returning defaults when no stored option exists yet. |
83 | 83 | $value = autoptimizeConfig::get_ao_extra_default_options(); |
84 | 84 | } |
@@ -89,55 +89,55 @@ discard block |
||
89 | 89 | public function disable_emojis() |
90 | 90 | { |
91 | 91 | // Removing all actions related to emojis! |
92 | - remove_action( 'admin_print_styles', 'print_emoji_styles' ); |
|
93 | - remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
|
94 | - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
|
95 | - remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
|
96 | - remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); |
|
97 | - remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); |
|
98 | - remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); |
|
92 | + remove_action('admin_print_styles', 'print_emoji_styles'); |
|
93 | + remove_action('wp_head', 'print_emoji_detection_script', 7); |
|
94 | + remove_action('admin_print_scripts', 'print_emoji_detection_script'); |
|
95 | + remove_action('wp_print_styles', 'print_emoji_styles'); |
|
96 | + remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); |
|
97 | + remove_filter('the_content_feed', 'wp_staticize_emoji'); |
|
98 | + remove_filter('comment_text_rss', 'wp_staticize_emoji'); |
|
99 | 99 | |
100 | 100 | // Removes TinyMCE emojis. |
101 | - add_filter( 'tiny_mce_plugins', array( $this, 'filter_disable_emojis_tinymce' ) ); |
|
101 | + add_filter('tiny_mce_plugins', array($this, 'filter_disable_emojis_tinymce')); |
|
102 | 102 | |
103 | 103 | // Removes emoji dns-preftech. |
104 | - add_filter( 'wp_resource_hints', array( $this, 'filter_remove_emoji_dns_prefetch' ), 10, 2 ); |
|
104 | + add_filter('wp_resource_hints', array($this, 'filter_remove_emoji_dns_prefetch'), 10, 2); |
|
105 | 105 | } |
106 | 106 | |
107 | - public function filter_disable_emojis_tinymce( $plugins ) |
|
107 | + public function filter_disable_emojis_tinymce($plugins) |
|
108 | 108 | { |
109 | - if ( is_array( $plugins ) ) { |
|
110 | - return array_diff( $plugins, array( 'wpemoji' ) ); |
|
109 | + if (is_array($plugins)) { |
|
110 | + return array_diff($plugins, array('wpemoji')); |
|
111 | 111 | } else { |
112 | 112 | return array(); |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - public function filter_remove_qs( $src ) |
|
116 | + public function filter_remove_qs($src) |
|
117 | 117 | { |
118 | - if ( strpos( $src, '?ver=' ) ) { |
|
119 | - $src = remove_query_arg( 'ver', $src ); |
|
118 | + if (strpos($src, '?ver=')) { |
|
119 | + $src = remove_query_arg('ver', $src); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | return $src; |
123 | 123 | } |
124 | 124 | |
125 | - public function extra_async_js( $in ) |
|
125 | + public function extra_async_js($in) |
|
126 | 126 | { |
127 | 127 | $exclusions = array(); |
128 | - if ( ! empty( $in ) ) { |
|
129 | - $exclusions = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $in ) ) ), '' ); |
|
128 | + if (!empty($in)) { |
|
129 | + $exclusions = array_fill_keys(array_filter(array_map('trim', explode(',', $in))), ''); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $settings = $this->options['autoptimize_extra_text_field_3']; |
133 | - $async = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $settings ) ) ), '' ); |
|
134 | - $attr = apply_filters( 'autoptimize_filter_extra_async', 'async' ); |
|
135 | - foreach ( $async as $k => $v ) { |
|
136 | - $async[ $k ] = $attr; |
|
133 | + $async = array_fill_keys(array_filter(array_map('trim', explode(',', $settings))), ''); |
|
134 | + $attr = apply_filters('autoptimize_filter_extra_async', 'async'); |
|
135 | + foreach ($async as $k => $v) { |
|
136 | + $async[$k] = $attr; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | // Merge exclusions & asyncs in one array and return to AO API. |
140 | - $merged = array_merge( $exclusions, $async ); |
|
140 | + $merged = array_merge($exclusions, $async); |
|
141 | 141 | |
142 | 142 | return $merged; |
143 | 143 | } |
@@ -148,68 +148,68 @@ discard block |
||
148 | 148 | // for optimizations are met, this to ensure e.g. removing querystrings |
149 | 149 | // is not done when optimizing for logged in users is off, breaking |
150 | 150 | // some pagebuilders (Divi & Elementor). |
151 | - if ( false === autoptimizeMain::should_buffer() ) { |
|
151 | + if (false === autoptimizeMain::should_buffer()) { |
|
152 | 152 | return; |
153 | 153 | } |
154 | 154 | |
155 | 155 | $options = $this->options; |
156 | 156 | |
157 | 157 | // Disable emojis if specified. |
158 | - if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) ) { |
|
158 | + if (!empty($options['autoptimize_extra_checkbox_field_1'])) { |
|
159 | 159 | $this->disable_emojis(); |
160 | 160 | } |
161 | 161 | |
162 | 162 | // Remove version query parameters. |
163 | - if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) ) { |
|
164 | - add_filter( 'script_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 ); |
|
165 | - add_filter( 'style_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 ); |
|
163 | + if (!empty($options['autoptimize_extra_checkbox_field_0'])) { |
|
164 | + add_filter('script_loader_src', array($this, 'filter_remove_qs'), 15, 1); |
|
165 | + add_filter('style_loader_src', array($this, 'filter_remove_qs'), 15, 1); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // Avoiding conflicts of interest when async-javascript plugin is active! |
169 | - $async_js_plugin_active = autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ); |
|
170 | - if ( ! empty( $options['autoptimize_extra_text_field_3'] ) && ! $async_js_plugin_active ) { |
|
171 | - add_filter( 'autoptimize_filter_js_exclude', array( $this, 'extra_async_js' ), 10, 1 ); |
|
169 | + $async_js_plugin_active = autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php'); |
|
170 | + if (!empty($options['autoptimize_extra_text_field_3']) && !$async_js_plugin_active) { |
|
171 | + add_filter('autoptimize_filter_js_exclude', array($this, 'extra_async_js'), 10, 1); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Optimize google fonts! |
175 | - if ( ! empty( $options['autoptimize_extra_radio_field_4'] ) && ( '1' !== $options['autoptimize_extra_radio_field_4'] ) ) { |
|
176 | - add_filter( 'wp_resource_hints', array( $this, 'filter_remove_gfonts_dnsprefetch' ), 10, 2 ); |
|
177 | - add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_optimize_google_fonts' ), 10, 1 ); |
|
178 | - add_filter( 'autoptimize_extra_filter_tobepreconn', array( $this, 'filter_preconnect_google_fonts' ), 10, 1 ); |
|
175 | + if (!empty($options['autoptimize_extra_radio_field_4']) && ('1' !== $options['autoptimize_extra_radio_field_4'])) { |
|
176 | + add_filter('wp_resource_hints', array($this, 'filter_remove_gfonts_dnsprefetch'), 10, 2); |
|
177 | + add_filter('autoptimize_html_after_minify', array($this, 'filter_optimize_google_fonts'), 10, 1); |
|
178 | + add_filter('autoptimize_extra_filter_tobepreconn', array($this, 'filter_preconnect_google_fonts'), 10, 1); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | // Preconnect! |
182 | - if ( ! empty( $options['autoptimize_extra_text_field_2'] ) || has_filter( 'autoptimize_extra_filter_tobepreconn' ) ) { |
|
183 | - add_filter( 'wp_resource_hints', array( $this, 'filter_preconnect' ), 10, 2 ); |
|
182 | + if (!empty($options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) { |
|
183 | + add_filter('wp_resource_hints', array($this, 'filter_preconnect'), 10, 2); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | // Preload! |
187 | - if ( ! empty( $options['autoptimize_extra_text_field_7'] ) || has_filter( 'autoptimize_filter_extra_tobepreloaded' ) ) { |
|
188 | - add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_preload' ), 10, 2 ); |
|
187 | + if (!empty($options['autoptimize_extra_text_field_7']) || has_filter('autoptimize_filter_extra_tobepreloaded')) { |
|
188 | + add_filter('autoptimize_html_after_minify', array($this, 'filter_preload'), 10, 2); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | - public function filter_remove_emoji_dns_prefetch( $urls, $relation_type ) |
|
192 | + public function filter_remove_emoji_dns_prefetch($urls, $relation_type) |
|
193 | 193 | { |
194 | - $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' ); |
|
194 | + $emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/'); |
|
195 | 195 | |
196 | - return $this->filter_remove_dns_prefetch( $urls, $relation_type, $emoji_svg_url ); |
|
196 | + return $this->filter_remove_dns_prefetch($urls, $relation_type, $emoji_svg_url); |
|
197 | 197 | } |
198 | 198 | |
199 | - public function filter_remove_gfonts_dnsprefetch( $urls, $relation_type ) |
|
199 | + public function filter_remove_gfonts_dnsprefetch($urls, $relation_type) |
|
200 | 200 | { |
201 | - return $this->filter_remove_dns_prefetch( $urls, $relation_type, 'fonts.googleapis.com' ); |
|
201 | + return $this->filter_remove_dns_prefetch($urls, $relation_type, 'fonts.googleapis.com'); |
|
202 | 202 | } |
203 | 203 | |
204 | - public function filter_remove_dns_prefetch( $urls, $relation_type, $url_to_remove ) |
|
204 | + public function filter_remove_dns_prefetch($urls, $relation_type, $url_to_remove) |
|
205 | 205 | { |
206 | 206 | $url_to_remove = (string) $url_to_remove; |
207 | 207 | |
208 | - if ( ! empty( $url_to_remove ) && 'dns-prefetch' === $relation_type ) { |
|
208 | + if (!empty($url_to_remove) && 'dns-prefetch' === $relation_type) { |
|
209 | 209 | $cnt = 0; |
210 | - foreach ( $urls as $url ) { |
|
211 | - if ( false !== strpos( $url, $url_to_remove ) ) { |
|
212 | - unset( $urls[ $cnt ] ); |
|
210 | + foreach ($urls as $url) { |
|
211 | + if (false !== strpos($url, $url_to_remove)) { |
|
212 | + unset($urls[$cnt]); |
|
213 | 213 | } |
214 | 214 | $cnt++; |
215 | 215 | } |
@@ -218,156 +218,156 @@ discard block |
||
218 | 218 | return $urls; |
219 | 219 | } |
220 | 220 | |
221 | - public function filter_optimize_google_fonts( $in ) |
|
221 | + public function filter_optimize_google_fonts($in) |
|
222 | 222 | { |
223 | 223 | // Extract fonts, partly based on wp rocket's extraction code. |
224 | - $markup = preg_replace( '/<!--(.*)-->/Uis', '', $in ); |
|
225 | - preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches ); |
|
224 | + $markup = preg_replace('/<!--(.*)-->/Uis', '', $in); |
|
225 | + preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches); |
|
226 | 226 | |
227 | 227 | $fonts_collection = array(); |
228 | - if ( ! $matches[2] ) { |
|
228 | + if (!$matches[2]) { |
|
229 | 229 | return $in; |
230 | 230 | } |
231 | 231 | |
232 | 232 | // Store them in $fonts array. |
233 | 233 | $i = 0; |
234 | - foreach ( $matches[2] as $font ) { |
|
235 | - if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) { |
|
234 | + foreach ($matches[2] as $font) { |
|
235 | + if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) { |
|
236 | 236 | // Get fonts name. |
237 | - $font = str_replace( array( '%7C', '%7c' ), '|', $font ); |
|
238 | - if ( strpos( $font, 'fonts.googleapis.com/css2' ) !== false ) { |
|
237 | + $font = str_replace(array('%7C', '%7c'), '|', $font); |
|
238 | + if (strpos($font, 'fonts.googleapis.com/css2') !== false) { |
|
239 | 239 | // (Somewhat) change Google Fonts APIv2 syntax back to v1. |
240 | - $font = str_replace( array( 'wght@', 'wght%40', ';', '%3B' ), array( '', '', ',', ',' ), $font ); |
|
240 | + $font = str_replace(array('wght@', 'wght%40', ';', '%3B'), array('', '', ',', ','), $font); |
|
241 | 241 | } |
242 | - $font = explode( 'family=', $font ); |
|
243 | - $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array(); |
|
242 | + $font = explode('family=', $font); |
|
243 | + $font = (isset($font[1])) ? explode('&', $font[1]) : array(); |
|
244 | 244 | // Add font to $fonts[$i] but make sure not to pollute with an empty family! |
245 | - $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) ); |
|
246 | - if ( ! empty( $_thisfont ) ) { |
|
247 | - $fonts_collection[ $i ]['fonts'] = $_thisfont; |
|
245 | + $_thisfont = array_values(array_filter(explode('|', reset($font)))); |
|
246 | + if (!empty($_thisfont)) { |
|
247 | + $fonts_collection[$i]['fonts'] = $_thisfont; |
|
248 | 248 | // And add subset if any! |
249 | - $subset = ( is_array( $font ) ) ? end( $font ) : ''; |
|
250 | - if ( false !== strpos( $subset, 'subset=' ) ) { |
|
251 | - $subset = str_replace( array( '%2C', '%2c' ), ',', $subset ); |
|
252 | - $subset = explode( 'subset=', $subset ); |
|
253 | - $fonts_collection[ $i ]['subsets'] = explode( ',', $subset[1] ); |
|
249 | + $subset = (is_array($font)) ? end($font) : ''; |
|
250 | + if (false !== strpos($subset, 'subset=')) { |
|
251 | + $subset = str_replace(array('%2C', '%2c'), ',', $subset); |
|
252 | + $subset = explode('subset=', $subset); |
|
253 | + $fonts_collection[$i]['subsets'] = explode(',', $subset[1]); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | // And remove Google Fonts. |
257 | - $in = str_replace( $matches[0][ $i ], '', $in ); |
|
257 | + $in = str_replace($matches[0][$i], '', $in); |
|
258 | 258 | } |
259 | 259 | $i++; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $options = $this->options; |
263 | 263 | $fonts_markup = ''; |
264 | - if ( '2' === $options['autoptimize_extra_radio_field_4'] ) { |
|
264 | + if ('2' === $options['autoptimize_extra_radio_field_4']) { |
|
265 | 265 | // Remove Google Fonts. |
266 | - unset( $fonts_collection ); |
|
266 | + unset($fonts_collection); |
|
267 | 267 | return $in; |
268 | - } elseif ( '3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4'] ) { |
|
268 | + } elseif ('3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4']) { |
|
269 | 269 | // Aggregate & link! |
270 | 270 | $fonts_string = ''; |
271 | 271 | $subset_string = ''; |
272 | - foreach ( $fonts_collection as $font ) { |
|
273 | - $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' ); |
|
274 | - if ( ! empty( $font['subsets'] ) ) { |
|
275 | - $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' ); |
|
272 | + foreach ($fonts_collection as $font) { |
|
273 | + $fonts_string .= '|'.trim(implode('|', $font['fonts']), '|'); |
|
274 | + if (!empty($font['subsets'])) { |
|
275 | + $subset_string .= ','.trim(implode(',', $font['subsets']), ','); |
|
276 | 276 | } |
277 | 277 | } |
278 | 278 | |
279 | - if ( ! empty( $subset_string ) ) { |
|
280 | - $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) ); |
|
281 | - $fonts_string = $fonts_string . '&subset=' . $subset_string; |
|
279 | + if (!empty($subset_string)) { |
|
280 | + $subset_string = str_replace(',', '%2C', ltrim($subset_string, ',')); |
|
281 | + $fonts_string = $fonts_string.'&subset='.$subset_string; |
|
282 | 282 | } |
283 | 283 | |
284 | - $fonts_string = apply_filters( 'autoptimize_filter_extra_gfont_fontstring', str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) ) ); |
|
284 | + $fonts_string = apply_filters('autoptimize_filter_extra_gfont_fontstring', str_replace('|', '%7C', ltrim($fonts_string, '|'))); |
|
285 | 285 | // only add display parameter if there is none in $fonts_string (by virtue of the filter). |
286 | - if ( strpos( $fonts_string, 'display=' ) === false ) { |
|
287 | - $fonts_string .= apply_filters( 'autoptimize_filter_extra_gfont_display', '&display=swap' ); |
|
286 | + if (strpos($fonts_string, 'display=') === false) { |
|
287 | + $fonts_string .= apply_filters('autoptimize_filter_extra_gfont_display', '&display=swap'); |
|
288 | 288 | } |
289 | 289 | |
290 | - if ( ! empty( $fonts_string ) ) { |
|
291 | - if ( '5' === $options['autoptimize_extra_radio_field_4'] ) { |
|
292 | - $rel_string = 'rel="preload" as="style" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"'; |
|
290 | + if (!empty($fonts_string)) { |
|
291 | + if ('5' === $options['autoptimize_extra_radio_field_4']) { |
|
292 | + $rel_string = 'rel="preload" as="style" onload="'.autoptimizeConfig::get_ao_css_preload_onload().'"'; |
|
293 | 293 | } else { |
294 | 294 | $rel_string = 'rel="stylesheet"'; |
295 | 295 | } |
296 | - $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />'; |
|
296 | + $fonts_markup = '<link '.$rel_string.' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$fonts_string.'" />'; |
|
297 | 297 | } |
298 | - } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) { |
|
298 | + } elseif ('4' === $options['autoptimize_extra_radio_field_4']) { |
|
299 | 299 | // Aggregate & load async (webfont.js impl.)! |
300 | 300 | $fonts_array = array(); |
301 | - foreach ( $fonts_collection as $_fonts ) { |
|
302 | - if ( ! empty( $_fonts['subsets'] ) ) { |
|
303 | - $_subset = implode( ',', $_fonts['subsets'] ); |
|
304 | - foreach ( $_fonts['fonts'] as $key => $_one_font ) { |
|
305 | - $_one_font = $_one_font . ':' . $_subset; |
|
306 | - $_fonts['fonts'][ $key ] = $_one_font; |
|
301 | + foreach ($fonts_collection as $_fonts) { |
|
302 | + if (!empty($_fonts['subsets'])) { |
|
303 | + $_subset = implode(',', $_fonts['subsets']); |
|
304 | + foreach ($_fonts['fonts'] as $key => $_one_font) { |
|
305 | + $_one_font = $_one_font.':'.$_subset; |
|
306 | + $_fonts['fonts'][$key] = $_one_font; |
|
307 | 307 | } |
308 | 308 | } |
309 | - $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] ); |
|
309 | + $fonts_array = array_merge($fonts_array, $_fonts['fonts']); |
|
310 | 310 | } |
311 | 311 | |
312 | - $fonts_array = array_map( 'urldecode', $fonts_array ); |
|
312 | + $fonts_array = array_map('urldecode', $fonts_array); |
|
313 | 313 | $fonts_array = array_map( |
314 | - function( $_f ) { |
|
315 | - return trim( $_f, ',' ); |
|
314 | + function($_f) { |
|
315 | + return trim($_f, ','); |
|
316 | 316 | }, |
317 | 317 | $fonts_array |
318 | 318 | ); |
319 | 319 | |
320 | 320 | // type attrib on <script not added by default. |
321 | 321 | $type_js = ''; |
322 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
322 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
323 | 323 | $type_js = 'type="text/javascript" '; |
324 | 324 | } |
325 | 325 | |
326 | - $fonts_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array ) . ' },classes:false, events:false, timeout:1500};</script>'; |
|
327 | - $fonts_library_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>'; |
|
328 | - $in = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) ); |
|
326 | + $fonts_markup = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:'.wp_json_encode($fonts_array).' },classes:false, events:false, timeout:1500};</script>'; |
|
327 | + $fonts_library_markup = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>'; |
|
328 | + $in = substr_replace($in, $fonts_library_markup.'</head>', strpos($in, '</head>'), strlen('</head>')); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // Replace back in markup. |
332 | - $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' ); |
|
333 | - $out = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) ); |
|
334 | - unset( $fonts_collection ); |
|
332 | + $inject_point = apply_filters('autoptimize_filter_extra_gfont_injectpoint', '<link'); |
|
333 | + $out = substr_replace($in, $fonts_markup.$inject_point, strpos($in, $inject_point), strlen($inject_point)); |
|
334 | + unset($fonts_collection); |
|
335 | 335 | |
336 | 336 | // and insert preload polyfill if "link preload" and if the polyfill isn't there yet (courtesy of inline&defer). |
337 | 337 | $preload_polyfill = autoptimizeConfig::get_ao_css_preload_polyfill(); |
338 | - if ( '5' === $options['autoptimize_extra_radio_field_4'] && strpos( $out, $preload_polyfill ) === false ) { |
|
339 | - $out = str_replace( '</body>', $preload_polyfill . '</body>', $out ); |
|
338 | + if ('5' === $options['autoptimize_extra_radio_field_4'] && strpos($out, $preload_polyfill) === false) { |
|
339 | + $out = str_replace('</body>', $preload_polyfill.'</body>', $out); |
|
340 | 340 | } |
341 | 341 | return $out; |
342 | 342 | } |
343 | 343 | |
344 | - public function filter_preconnect( $hints, $relation_type ) |
|
344 | + public function filter_preconnect($hints, $relation_type) |
|
345 | 345 | { |
346 | 346 | $options = $this->options; |
347 | 347 | $preconns = array(); |
348 | 348 | |
349 | 349 | // Get settings and store in array. |
350 | - if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { |
|
351 | - $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) ); |
|
350 | + if (array_key_exists('autoptimize_extra_text_field_2', $options)) { |
|
351 | + $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2']))); |
|
352 | 352 | } |
353 | - $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns ); |
|
353 | + $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns); |
|
354 | 354 | |
355 | 355 | // Walk array, extract domain and add to new array with crossorigin attribute. |
356 | - foreach ( $preconns as $preconn ) { |
|
356 | + foreach ($preconns as $preconn) { |
|
357 | 357 | $domain = ''; |
358 | - $parsed = parse_url( $preconn ); |
|
359 | - if ( is_array( $parsed ) && ! empty( $parsed['host'] ) && empty( $parsed['scheme'] ) ) { |
|
360 | - $domain = '//' . $parsed['host']; |
|
361 | - } elseif ( is_array( $parsed ) && ! empty( $parsed['host'] ) ) { |
|
362 | - $domain = $parsed['scheme'] . '://' . $parsed['host']; |
|
358 | + $parsed = parse_url($preconn); |
|
359 | + if (is_array($parsed) && !empty($parsed['host']) && empty($parsed['scheme'])) { |
|
360 | + $domain = '//'.$parsed['host']; |
|
361 | + } elseif (is_array($parsed) && !empty($parsed['host'])) { |
|
362 | + $domain = $parsed['scheme'].'://'.$parsed['host']; |
|
363 | 363 | } |
364 | 364 | |
365 | - if ( ! empty( $domain ) ) { |
|
366 | - $hint = array( 'href' => $domain ); |
|
365 | + if (!empty($domain)) { |
|
366 | + $hint = array('href' => $domain); |
|
367 | 367 | // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set |
368 | 368 | // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed. |
369 | - $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) ); |
|
370 | - if ( in_array( $domain, $crossorigins ) ) { |
|
369 | + $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com')); |
|
370 | + if (in_array($domain, $crossorigins)) { |
|
371 | 371 | $hint['crossorigin'] = 'anonymous'; |
372 | 372 | } |
373 | 373 | $new_hints[] = $hint; |
@@ -375,21 +375,21 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | // Merge in WP's preconnect hints. |
378 | - if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) { |
|
379 | - $hints = array_merge( $hints, $new_hints ); |
|
378 | + if ('preconnect' === $relation_type && !empty($new_hints)) { |
|
379 | + $hints = array_merge($hints, $new_hints); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | return $hints; |
383 | 383 | } |
384 | 384 | |
385 | - public function filter_preconnect_google_fonts( $in ) |
|
385 | + public function filter_preconnect_google_fonts($in) |
|
386 | 386 | { |
387 | - if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) { |
|
387 | + if ('2' !== $this->options['autoptimize_extra_radio_field_4']) { |
|
388 | 388 | // Preconnect to fonts.gstatic.com unless we remove gfonts. |
389 | 389 | $in[] = 'https://fonts.gstatic.com'; |
390 | 390 | } |
391 | 391 | |
392 | - if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) { |
|
392 | + if ('4' === $this->options['autoptimize_extra_radio_field_4']) { |
|
393 | 393 | // Preconnect even more hosts for webfont.js! |
394 | 394 | $in[] = 'https://ajax.googleapis.com'; |
395 | 395 | $in[] = 'https://fonts.googleapis.com'; |
@@ -398,76 +398,76 @@ discard block |
||
398 | 398 | return $in; |
399 | 399 | } |
400 | 400 | |
401 | - public function filter_preload( $in ) { |
|
401 | + public function filter_preload($in) { |
|
402 | 402 | // make array from comma separated list. |
403 | 403 | $options = $this->options; |
404 | 404 | $preloads = array(); |
405 | - if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { |
|
406 | - $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) ); |
|
405 | + if (array_key_exists('autoptimize_extra_text_field_7', $options)) { |
|
406 | + $preloads = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_7']))); |
|
407 | 407 | } |
408 | - $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads ); |
|
408 | + $preloads = apply_filters('autoptimize_filter_extra_tobepreloaded', $preloads); |
|
409 | 409 | |
410 | 410 | // immediately return if nothing to be preloaded. |
411 | - if ( empty( $preloads ) ) { |
|
411 | + if (empty($preloads)) { |
|
412 | 412 | return $in; |
413 | 413 | } |
414 | 414 | |
415 | 415 | // iterate through array and add preload link to tmp string. |
416 | 416 | $preload_output = ''; |
417 | - foreach ( $preloads as $preload ) { |
|
417 | + foreach ($preloads as $preload) { |
|
418 | 418 | $crossorigin = ''; |
419 | 419 | $preload_as = ''; |
420 | 420 | $mime_type = ''; |
421 | - $_preload = strtok( $preload, '?' ); |
|
421 | + $_preload = strtok($preload, '?'); |
|
422 | 422 | |
423 | - if ( autoptimizeUtils::str_ends_in( $_preload, '.css' ) ) { |
|
423 | + if (autoptimizeUtils::str_ends_in($_preload, '.css')) { |
|
424 | 424 | $preload_as = 'style'; |
425 | - } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.js' ) ) { |
|
425 | + } elseif (autoptimizeUtils::str_ends_in($_preload, '.js')) { |
|
426 | 426 | $preload_as = 'script'; |
427 | - } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.woff' ) || autoptimizeUtils::str_ends_in( $_preload, '.woff2' ) || autoptimizeUtils::str_ends_in( $_preload, '.ttf' ) || autoptimizeUtils::str_ends_in( $_preload, '.eot' ) ) { |
|
427 | + } elseif (autoptimizeUtils::str_ends_in($_preload, '.woff') || autoptimizeUtils::str_ends_in($_preload, '.woff2') || autoptimizeUtils::str_ends_in($_preload, '.ttf') || autoptimizeUtils::str_ends_in($_preload, '.eot')) { |
|
428 | 428 | $preload_as = 'font'; |
429 | 429 | $crossorigin = ' crossorigin'; |
430 | - $mime_type = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"'; |
|
431 | - if ( ' type="font/eot"' === $mime_type ) { |
|
430 | + $mime_type = ' type="font/'.pathinfo($_preload, PATHINFO_EXTENSION).'"'; |
|
431 | + if (' type="font/eot"' === $mime_type) { |
|
432 | 432 | $mime_type = 'application/vnd.ms-fontobject'; |
433 | 433 | } |
434 | - } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.jpeg' ) || autoptimizeUtils::str_ends_in( $_preload, '.jpg' ) || autoptimizeUtils::str_ends_in( $_preload, '.webp' ) || autoptimizeUtils::str_ends_in( $_preload, '.png' ) || autoptimizeUtils::str_ends_in( $_preload, '.gif' ) ) { |
|
434 | + } elseif (autoptimizeUtils::str_ends_in($_preload, '.jpeg') || autoptimizeUtils::str_ends_in($_preload, '.jpg') || autoptimizeUtils::str_ends_in($_preload, '.webp') || autoptimizeUtils::str_ends_in($_preload, '.png') || autoptimizeUtils::str_ends_in($_preload, '.gif')) { |
|
435 | 435 | $preload_as = 'image'; |
436 | 436 | } else { |
437 | 437 | $preload_as = 'other'; |
438 | 438 | } |
439 | 439 | |
440 | - $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>'; |
|
440 | + $preload_output .= '<link rel="preload" href="'.$preload.'" as="'.$preload_as.'"'.$mime_type.$crossorigin.'>'; |
|
441 | 441 | } |
442 | - $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output ); |
|
442 | + $preload_output = apply_filters('autoptimize_filter_extra_preload_output', $preload_output); |
|
443 | 443 | |
444 | 444 | // add string to head (before first link node by default). |
445 | - $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' ); |
|
446 | - $position = autoptimizeUtils::strpos( $in, $preload_inject ); |
|
445 | + $preload_inject = apply_filters('autoptimize_filter_extra_preload_inject', '<link'); |
|
446 | + $position = autoptimizeUtils::strpos($in, $preload_inject); |
|
447 | 447 | |
448 | - return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) ); |
|
448 | + return autoptimizeUtils::substr_replace($in, $preload_output.$preload_inject, $position, strlen($preload_inject)); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | public function admin_menu() |
452 | 452 | { |
453 | 453 | // no acces if multisite and not network admin and no site config allowed. |
454 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
454 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
455 | 455 | add_submenu_page( |
456 | 456 | null, |
457 | 457 | 'autoptimize_extra', |
458 | 458 | 'autoptimize_extra', |
459 | 459 | 'manage_options', |
460 | 460 | 'autoptimize_extra', |
461 | - array( $this, 'options_page' ) |
|
461 | + array($this, 'options_page') |
|
462 | 462 | ); |
463 | 463 | } |
464 | - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
464 | + register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings'); |
|
465 | 465 | } |
466 | 466 | |
467 | - public function add_extra_tab( $in ) |
|
467 | + public function add_extra_tab($in) |
|
468 | 468 | { |
469 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
470 | - $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) ); |
|
469 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
470 | + $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize'))); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | return $in; |
@@ -487,97 +487,97 @@ discard block |
||
487 | 487 | #ao_settings_form .form-table th {font-weight: normal;} |
488 | 488 | #autoptimize_extra_descr{font-size: 120%;} |
489 | 489 | </style> |
490 | - <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script> |
|
490 | + <script>document.title = "Autoptimize: <?php _e('Extra', 'autoptimize'); ?> " + document.title;</script> |
|
491 | 491 | <div class="wrap"> |
492 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
492 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
493 | 493 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
494 | - <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?> |
|
494 | + <?php if ('on' !== autoptimizeOptionWrapper::get_option('autoptimize_js') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_css') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?> |
|
495 | 495 | <div class="notice-warning notice"><p> |
496 | - <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?> |
|
496 | + <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?> |
|
497 | 497 | </p></div> |
498 | 498 | <?php } ?> |
499 | 499 | |
500 | - <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'> |
|
501 | - <?php settings_fields( 'autoptimize_extra_settings' ); ?> |
|
502 | - <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2> |
|
503 | - <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span> |
|
500 | + <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'> |
|
501 | + <?php settings_fields('autoptimize_extra_settings'); ?> |
|
502 | + <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2> |
|
503 | + <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span> |
|
504 | 504 | <table class="form-table"> |
505 | 505 | <tr> |
506 | - <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th> |
|
506 | + <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th> |
|
507 | 507 | <td> |
508 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if ( ! in_array( $gfonts, array( 2, 3, 4, 5 ) ) ) { echo 'checked'; } ?> ><?php _e( 'Leave as is', 'autoptimize' ); ?><br/> |
|
509 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked( 2, $gfonts, true ); ?> ><?php _e( 'Remove Google Fonts', 'autoptimize' ); ?><br/> |
|
508 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if (!in_array($gfonts, array(2, 3, 4, 5))) { echo 'checked'; } ?> ><?php _e('Leave as is', 'autoptimize'); ?><br/> |
|
509 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $gfonts, true); ?> ><?php _e('Remove Google Fonts', 'autoptimize'); ?><br/> |
|
510 | 510 | <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?> |
511 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked( 3, $gfonts, true ); ?> ><?php echo __( 'Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/> |
|
511 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $gfonts, true); ?> ><?php echo __('Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/> |
|
512 | 512 | <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?> |
513 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php echo __( 'Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/> |
|
514 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php _e( 'Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize' ); ?><br/> |
|
513 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked(5, $gfonts, true); ?> ><?php echo __('Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/> |
|
514 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $gfonts, true); ?> ><?php _e('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize'); ?><br/> |
|
515 | 515 | </td> |
516 | 516 | </tr> |
517 | 517 | <tr> |
518 | - <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th> |
|
518 | + <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th> |
|
519 | 519 | <td> |
520 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) && '1' === $options['autoptimize_extra_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize' ); ?></label> |
|
520 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($options['autoptimize_extra_checkbox_field_1']) && '1' === $options['autoptimize_extra_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize'); ?></label> |
|
521 | 521 | </td> |
522 | 522 | </tr> |
523 | 523 | <tr> |
524 | - <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th> |
|
524 | + <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th> |
|
525 | 525 | <td> |
526 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) && '1' === $options['autoptimize_extra_checkbox_field_0'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize' ); ?></label> |
|
526 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty($options['autoptimize_extra_checkbox_field_0']) && '1' === $options['autoptimize_extra_checkbox_field_0']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize'); ?></label> |
|
527 | 527 | </td> |
528 | 528 | </tr> |
529 | 529 | <tr> |
530 | - <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
530 | + <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
531 | 531 | <td> |
532 | - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_2'] ); } ?>'><br /><?php _e( 'Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize' ); ?></label> |
|
532 | + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if (array_key_exists('autoptimize_extra_text_field_2', $options)) { echo esc_attr($options['autoptimize_extra_text_field_2']); } ?>'><br /><?php _e('Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize'); ?></label> |
|
533 | 533 | </td> |
534 | 534 | </tr> |
535 | 535 | <tr> |
536 | - <th scope="row"><?php _e( 'Preload specific requests <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
536 | + <th scope="row"><?php _e('Preload specific requests <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
537 | 537 | <td> |
538 | - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_7'] ); } ?>'><br /><?php _e( 'Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize' ); ?></label> |
|
538 | + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if (array_key_exists('autoptimize_extra_text_field_7', $options)) { echo esc_attr($options['autoptimize_extra_text_field_7']); } ?>'><br /><?php _e('Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize'); ?></label> |
|
539 | 539 | </td> |
540 | 540 | </tr> |
541 | 541 | <tr> |
542 | - <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
542 | + <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
543 | 543 | <td> |
544 | 544 | <?php |
545 | - if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) { |
|
545 | + if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) { |
|
546 | 546 | // translators: link points Async Javascript settings page. |
547 | - printf( __( 'You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize' ), '<a href="' . 'options-general.php?page=async-javascript' . '">', '</a>' ); |
|
547 | + printf(__('You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize'), '<a href="'.'options-general.php?page=async-javascript'.'">', '</a>'); |
|
548 | 548 | } else { |
549 | 549 | ?> |
550 | - <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_3', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_3'] ); } ?>'> |
|
550 | + <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if (array_key_exists('autoptimize_extra_text_field_3', $options)) { echo esc_attr($options['autoptimize_extra_text_field_3']); } ?>'> |
|
551 | 551 | <br /> |
552 | 552 | <?php |
553 | - _e( 'Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize' ); |
|
553 | + _e('Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize'); |
|
554 | 554 | // translators: %s will be replaced by a link to the "async javascript" plugin. |
555 | - echo sprintf( __( 'Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize' ), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"' ); |
|
556 | - $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
557 | - echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
555 | + echo sprintf(__('Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize'), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"'); |
|
556 | + $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
557 | + echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
558 | 558 | } |
559 | 559 | ?> |
560 | 560 | </td> |
561 | 561 | </tr> |
562 | 562 | <tr> |
563 | - <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th> |
|
563 | + <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th> |
|
564 | 564 | <td> |
565 | 565 | <?php |
566 | - if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) { |
|
567 | - _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' ); |
|
566 | + if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) { |
|
567 | + _e('Great, you have WP YouTube Lyte installed.', 'autoptimize'); |
|
568 | 568 | $lyte_config_url = 'options-general.php?page=lyte_settings_page'; |
569 | - echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) ); |
|
569 | + echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize')); |
|
570 | 570 | } else { |
571 | 571 | // translators: %s will be replaced by a link to "wp youtube lyte" plugin. |
572 | - echo sprintf( __( '%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize' ), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>' ); |
|
573 | - $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term'; |
|
574 | - echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
572 | + echo sprintf(__('%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize'), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>'); |
|
573 | + $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term'; |
|
574 | + echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
575 | 575 | } |
576 | 576 | ?> |
577 | 577 | </td> |
578 | 578 | </tr> |
579 | 579 | </table> |
580 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p> |
|
580 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p> |
|
581 | 581 | </form> |
582 | 582 | <?php |
583 | 583 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Main configuration logic. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -35,32 +35,32 @@ discard block |
||
35 | 35 | */ |
36 | 36 | private function __construct() |
37 | 37 | { |
38 | - if ( is_admin() ) { |
|
38 | + if (is_admin()) { |
|
39 | 39 | // Add the admin page and settings. |
40 | - if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
41 | - add_action( 'network_admin_menu', array( $this, 'addmenu' ) ); |
|
40 | + if (autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
41 | + add_action('network_admin_menu', array($this, 'addmenu')); |
|
42 | 42 | } |
43 | 43 | |
44 | - add_action( 'admin_menu', array( $this, 'addmenu' ) ); |
|
45 | - add_action( 'admin_init', array( $this, 'registersettings' ) ); |
|
44 | + add_action('admin_menu', array($this, 'addmenu')); |
|
45 | + add_action('admin_init', array($this, 'registersettings')); |
|
46 | 46 | |
47 | 47 | // Set meta info. |
48 | - if ( function_exists( 'plugin_row_meta' ) ) { |
|
48 | + if (function_exists('plugin_row_meta')) { |
|
49 | 49 | // 2.8 and higher. |
50 | - add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 ); |
|
51 | - } elseif ( function_exists( 'post_class' ) ) { |
|
50 | + add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2); |
|
51 | + } elseif (function_exists('post_class')) { |
|
52 | 52 | // 2.7 and lower. |
53 | - $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' ); |
|
54 | - add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) ); |
|
53 | + $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php'); |
|
54 | + add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | // Clean cache? |
58 | - if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) { |
|
58 | + if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) { |
|
59 | 59 | autoptimizeCache::clearall(); |
60 | - autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 ); |
|
60 | + autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0); |
|
61 | 61 | } |
62 | 62 | |
63 | - $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http ); |
|
63 | + $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // Adds the Autoptimize Toolbar to the Admin bar. |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | static public function instance() |
77 | 77 | { |
78 | 78 | // Only one instance. |
79 | - if ( null === self::$instance ) { |
|
79 | + if (null === self::$instance) { |
|
80 | 80 | self::$instance = new autoptimizeConfig(); |
81 | 81 | } |
82 | 82 | |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | public function show_network_message() { |
87 | 87 | ?> |
88 | 88 | <div class="wrap"> |
89 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
89 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
90 | 90 | <?php echo $this->ao_admin_tabs(); ?> |
91 | - <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p> |
|
91 | + <p style="font-size:120%;"><?php echo apply_filters('autoptimize_filter_settingsscreen_multisite_network_message', __('Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize')); ?></p> |
|
92 | 92 | </div> |
93 | 93 | <?php |
94 | 94 | } |
@@ -181,32 +181,32 @@ discard block |
||
181 | 181 | <div class="wrap"> |
182 | 182 | |
183 | 183 | <!-- Temporary nudge to disable aoccss power-up. --> |
184 | -<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?> |
|
184 | +<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?> |
|
185 | 185 | <div class="notice-info notice"><p> |
186 | - <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?> |
|
186 | + <?php _e('Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize'); ?> |
|
187 | 187 | </p></div> |
188 | 188 | <?php } ?> |
189 | 189 | |
190 | 190 | <div id="autoptimize_main"> |
191 | - <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
191 | + <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
192 | 192 | <?php echo $this->ao_admin_tabs(); ?> |
193 | 193 | |
194 | -<form method="post" action="<?php echo admin_url( 'options.php' ); ?>"> |
|
195 | -<?php settings_fields( 'autoptimize' ); ?> |
|
194 | +<form method="post" action="<?php echo admin_url('options.php'); ?>"> |
|
195 | +<?php settings_fields('autoptimize'); ?> |
|
196 | 196 | |
197 | 197 | <ul> |
198 | 198 | |
199 | 199 | <?php |
200 | 200 | // Only show enable site configuration in network site option. |
201 | -if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
201 | +if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
202 | 202 | ?> |
203 | 203 | <li class="itemDetail multiSite"> |
204 | - <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2> |
|
204 | + <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2> |
|
205 | 205 | <table class="form-table"> |
206 | 206 | <tr valign="top"> |
207 | - <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th> |
|
208 | - <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/> |
|
209 | - <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td> |
|
207 | + <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th> |
|
208 | + <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config') ? 'checked="checked" ' : ''; ?>/> |
|
209 | + <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td> |
|
210 | 210 | </tr> |
211 | 211 | </table> |
212 | 212 | </li> |
@@ -215,115 +215,115 @@ discard block |
||
215 | 215 | <?php } ?> |
216 | 216 | |
217 | 217 | <li class="itemDetail"> |
218 | -<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2> |
|
218 | +<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2> |
|
219 | 219 | <table class="form-table"> |
220 | 220 | <tr valign="top"> |
221 | -<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th> |
|
222 | -<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td> |
|
221 | +<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th> |
|
222 | +<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td> |
|
223 | 223 | </tr> |
224 | 224 | <tr valign="top" class="js_sub"> |
225 | -<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th> |
|
226 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/> |
|
227 | -<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td> |
|
225 | +<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th> |
|
226 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get('autoptimize_js_aggregate') ? 'checked="checked" ' : ''; ?>/> |
|
227 | +<?php _e('Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td> |
|
228 | 228 | </tr> |
229 | 229 | <tr valign="top" class="js_sub js_aggregate"> |
230 | -<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th> |
|
231 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/> |
|
232 | -<?php _e( 'Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize' ); ?></label></td> |
|
230 | +<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th> |
|
231 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/> |
|
232 | +<?php _e('Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize'); ?></label></td> |
|
233 | 233 | </tr> |
234 | 234 | <tr valign="top" class="js_sub js_aggregate"> |
235 | -<th scope="row"><?php _e( 'Force JavaScript in <head>?', 'autoptimize' ); ?></th> |
|
236 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/> |
|
237 | -<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td> |
|
235 | +<th scope="row"><?php _e('Force JavaScript in <head>?', 'autoptimize'); ?></th> |
|
236 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/> |
|
237 | +<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td> |
|
238 | 238 | </tr> |
239 | -<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?> |
|
239 | +<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?> |
|
240 | 240 | <tr valign="top" class="js_sub js_aggregate"> |
241 | 241 | <th scope="row"> |
242 | 242 | <?php |
243 | - _e( 'Look for scripts only in <head>?', 'autoptimize' ); |
|
244 | - echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>'; |
|
243 | + _e('Look for scripts only in <head>?', 'autoptimize'); |
|
244 | + echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>'; |
|
245 | 245 | ?> |
246 | 246 | </th> |
247 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/> |
|
248 | -<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td> |
|
247 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/> |
|
248 | +<?php _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize'); ?></label></td> |
|
249 | 249 | </tr> |
250 | 250 | <?php } ?> |
251 | 251 | <tr valign="top" class="js_sub"> |
252 | -<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th> |
|
253 | -<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js' ); ?>"/><br /> |
|
252 | +<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th> |
|
253 | +<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js'); ?>"/><br /> |
|
254 | 254 | <?php |
255 | -echo __( 'A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' ); |
|
255 | +echo __('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize'); |
|
256 | 256 | ?> |
257 | 257 | </label></td> |
258 | 258 | </tr> |
259 | 259 | <tr valign="top" class="js_sub js_aggregate"> |
260 | -<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th> |
|
261 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/> |
|
262 | -<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td> |
|
260 | +<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th> |
|
261 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/> |
|
262 | +<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td> |
|
263 | 263 | </tr> |
264 | 264 | </table> |
265 | 265 | </li> |
266 | 266 | |
267 | 267 | <li class="itemDetail"> |
268 | -<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2> |
|
268 | +<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2> |
|
269 | 269 | <table class="form-table"> |
270 | 270 | <tr valign="top"> |
271 | -<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th> |
|
272 | -<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td> |
|
271 | +<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th> |
|
272 | +<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td> |
|
273 | 273 | </tr> |
274 | 274 | <tr class="css_sub" valign="top"> |
275 | -<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th> |
|
276 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/> |
|
277 | -<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td> |
|
275 | +<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th> |
|
276 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get('autoptimize_css_aggregate') ? 'checked="checked" ' : ''; ?>/> |
|
277 | +<?php _e('Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td> |
|
278 | 278 | </tr> |
279 | 279 | <tr valign="top" class="css_sub css_aggregate"> |
280 | -<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th> |
|
281 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
282 | -<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td> |
|
280 | +<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th> |
|
281 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_include_inline', '1') ? 'checked="checked" ' : ''; ?>/> |
|
282 | +<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td> |
|
283 | 283 | </tr> |
284 | 284 | <tr class="css_sub css_aggregate" valign="top"> |
285 | -<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th> |
|
286 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/> |
|
287 | -<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td> |
|
285 | +<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th> |
|
286 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/> |
|
287 | +<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td> |
|
288 | 288 | </tr> |
289 | -<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?> |
|
289 | +<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?> |
|
290 | 290 | <tr valign="top" class="css_sub css_aggregate"> |
291 | 291 | <th scope="row"> |
292 | 292 | <?php |
293 | -_e( 'Look for styles only in <head>?', 'autoptimize' ); |
|
294 | -echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>'; |
|
293 | +_e('Look for styles only in <head>?', 'autoptimize'); |
|
294 | +echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>'; |
|
295 | 295 | ?> |
296 | 296 | </th> |
297 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/> |
|
298 | -<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td> |
|
297 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/> |
|
298 | +<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td> |
|
299 | 299 | </tr> |
300 | 300 | <?php } ?> |
301 | 301 | <tr valign="top" class="css_sub"> |
302 | -<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th> |
|
303 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/> |
|
302 | +<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th> |
|
303 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer') ? 'checked="checked" ' : ''; ?>/> |
|
304 | 304 | <?php |
305 | -_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' ); |
|
305 | +_e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize'); |
|
306 | 306 | echo ' '; |
307 | -$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' ); |
|
307 | +$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss'); |
|
308 | 308 | // translators: links "autoptimize critical CSS" tab. |
309 | -echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' ); |
|
309 | +echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>'); |
|
310 | 310 | ?> |
311 | 311 | </label></td> |
312 | 312 | </tr> |
313 | 313 | <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline"> |
314 | 314 | <th scope="row"></th> |
315 | -<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ); ?></textarea></label></td> |
|
315 | +<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline'); ?></textarea></label></td> |
|
316 | 316 | </tr> |
317 | 317 | <tr valign="top" class="css_sub css_aggregate"> |
318 | -<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th> |
|
319 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/> |
|
320 | -<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td> |
|
318 | +<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th> |
|
319 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_inline') ? 'checked="checked" ' : ''; ?>/> |
|
320 | +<?php _e('Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize'); ?></label></td> |
|
321 | 321 | </tr> |
322 | 322 | <tr valign="top" class="css_sub"> |
323 | -<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th> |
|
324 | -<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ); ?>"/><br /> |
|
323 | +<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th> |
|
324 | +<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css'); ?>"/><br /> |
|
325 | 325 | <?php |
326 | -echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' ); |
|
326 | +echo __('A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize'); |
|
327 | 327 | ?> |
328 | 328 | </label></td> |
329 | 329 | </tr> |
@@ -331,55 +331,55 @@ discard block |
||
331 | 331 | </li> |
332 | 332 | |
333 | 333 | <li class="itemDetail"> |
334 | -<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2> |
|
334 | +<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2> |
|
335 | 335 | <table class="form-table"> |
336 | 336 | <tr valign="top"> |
337 | -<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th> |
|
338 | -<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td> |
|
337 | +<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th> |
|
338 | +<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td> |
|
339 | 339 | </tr> |
340 | 340 | <tr class="html_sub" valign="top"> |
341 | -<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th> |
|
342 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/> |
|
343 | -<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td> |
|
341 | +<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th> |
|
342 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/> |
|
343 | +<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td> |
|
344 | 344 | </tr> |
345 | 345 | </table> |
346 | 346 | </li> |
347 | 347 | |
348 | 348 | <li class="itemDetail"> |
349 | -<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2> |
|
349 | +<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2> |
|
350 | 350 | <table class="form-table"> |
351 | 351 | <tr valign="top"> |
352 | -<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th> |
|
353 | -<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br /> |
|
354 | -<?php _e( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize' ); ?></label></td> |
|
352 | +<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th> |
|
353 | +<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url(autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', ''), array('http', 'https')); ?>" /><br /> |
|
354 | +<?php _e('Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize'); ?></label></td> |
|
355 | 355 | </tr> |
356 | 356 | </table> |
357 | 357 | </li> |
358 | 358 | |
359 | 359 | <li class="itemDetail"> |
360 | -<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2> |
|
360 | +<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2> |
|
361 | 361 | <table class="form-table" > |
362 | 362 | <tr valign="top" > |
363 | -<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th> |
|
364 | -<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td> |
|
363 | +<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th> |
|
364 | +<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td> |
|
365 | 365 | </tr> |
366 | 366 | <tr valign="top" > |
367 | -<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th> |
|
368 | -<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td> |
|
367 | +<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th> |
|
368 | +<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td> |
|
369 | 369 | </tr> |
370 | 370 | <tr valign="top" > |
371 | -<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th> |
|
371 | +<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th> |
|
372 | 372 | <td> |
373 | 373 | <?php |
374 | 374 | $ao_stat_arr = autoptimizeCache::stats(); |
375 | - if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) { |
|
376 | - $ao_cache_size = size_format( $ao_stat_arr[1], 2 ); |
|
375 | + if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) { |
|
376 | + $ao_cache_size = size_format($ao_stat_arr[1], 2); |
|
377 | 377 | $details = ''; |
378 | - if ( $ao_cache_size > 0 ) { |
|
379 | - $details = ', ~' . $ao_cache_size . ' total'; |
|
378 | + if ($ao_cache_size > 0) { |
|
379 | + $details = ', ~'.$ao_cache_size.' total'; |
|
380 | 380 | } |
381 | 381 | // translators: Kilobytes + timestamp shown. |
382 | - printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) ); |
|
382 | + printf(__('%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize'), $ao_stat_arr[0], $ao_cache_size, date('H:i e', $ao_stat_arr[2])); |
|
383 | 383 | } |
384 | 384 | ?> |
385 | 385 | </td> |
@@ -388,41 +388,41 @@ discard block |
||
388 | 388 | </li> |
389 | 389 | |
390 | 390 | <li class="itemDetail"> |
391 | -<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2> |
|
391 | +<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2> |
|
392 | 392 | <table class="form-table"> |
393 | 393 | <tr valign="top" > |
394 | - <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th> |
|
395 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
396 | - <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td> |
|
394 | + <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th> |
|
395 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/> |
|
396 | + <?php _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize'); ?></label></td> |
|
397 | 397 | </tr> |
398 | 398 | <?php |
399 | 399 | $_min_excl_class = ''; |
400 | - if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) { |
|
400 | + if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) { |
|
401 | 401 | $_min_excl_class = 'hidden'; |
402 | 402 | } |
403 | 403 | ?> |
404 | 404 | <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>"> |
405 | - <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th> |
|
406 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
407 | - <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td> |
|
405 | + <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th> |
|
406 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/> |
|
407 | + <?php _e('When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize'); ?></label></td> |
|
408 | 408 | </tr> |
409 | 409 | <tr valign="top"> |
410 | - <th scope="row"><?php _e( 'Experimental: enable 404 fallbacks.', 'autoptimize' ); ?></th> |
|
411 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '' ) ? 'checked="checked" ' : ''; ?>/> |
|
412 | - <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. This experimental feature tries to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td> |
|
410 | + <th scope="row"><?php _e('Experimental: enable 404 fallbacks.', 'autoptimize'); ?></th> |
|
411 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '') ? 'checked="checked" ' : ''; ?>/> |
|
412 | + <?php _e('Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. This experimental feature tries to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize'); ?></label></td> |
|
413 | 413 | </tr> |
414 | 414 | <tr valign="top"> |
415 | - <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th> |
|
416 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
417 | - <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td> |
|
415 | + <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th> |
|
416 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/> |
|
417 | + <?php _e('By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize'); ?></label></td> |
|
418 | 418 | </tr> |
419 | 419 | <?php |
420 | - if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) { |
|
420 | + if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) { |
|
421 | 421 | ?> |
422 | 422 | <tr valign="top" > |
423 | - <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th> |
|
424 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/> |
|
425 | - <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label> |
|
423 | + <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th> |
|
424 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/> |
|
425 | + <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label> |
|
426 | 426 | </td> |
427 | 427 | </tr> |
428 | 428 | <?php } ?> |
@@ -432,8 +432,8 @@ discard block |
||
432 | 432 | </ul> |
433 | 433 | |
434 | 434 | <p class="submit"> |
435 | -<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /> |
|
436 | -<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" /> |
|
435 | +<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /> |
|
436 | +<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" /> |
|
437 | 437 | </p> |
438 | 438 | |
439 | 439 | </form> |
@@ -442,46 +442,46 @@ discard block |
||
442 | 442 | <div class="autoptimize_banner hidden"> |
443 | 443 | <ul> |
444 | 444 | <?php |
445 | - if ( $this->settings_screen_do_remote_http ) { |
|
446 | - $ao_banner = get_transient( 'autoptimize_banner' ); |
|
447 | - if ( empty( $ao_banner ) ) { |
|
448 | - $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION ); |
|
449 | - if ( ! is_wp_error( $banner_resp ) ) { |
|
450 | - if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) { |
|
451 | - $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) ); |
|
452 | - set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS ); |
|
445 | + if ($this->settings_screen_do_remote_http) { |
|
446 | + $ao_banner = get_transient('autoptimize_banner'); |
|
447 | + if (empty($ao_banner)) { |
|
448 | + $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION); |
|
449 | + if (!is_wp_error($banner_resp)) { |
|
450 | + if ('200' == wp_remote_retrieve_response_code($banner_resp)) { |
|
451 | + $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp)); |
|
452 | + set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS); |
|
453 | 453 | } |
454 | 454 | } |
455 | 455 | } |
456 | 456 | echo $ao_banner; |
457 | 457 | } |
458 | 458 | ?> |
459 | - <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li> |
|
460 | - <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li> |
|
459 | + <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li> |
|
460 | + <li><?php _e('Happy with Autoptimize?', 'autoptimize'); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e('Try my other plugins!', 'autoptimize'); ?></a></li> |
|
461 | 461 | </ul> |
462 | 462 | </div> |
463 | 463 | <div style="margin-left:10px;margin-top:-5px;"> |
464 | 464 | <h2> |
465 | - <?php _e( 'futtta about', 'autoptimize' ); ?> |
|
465 | + <?php _e('futtta about', 'autoptimize'); ?> |
|
466 | 466 | <select id="feed_dropdown" > |
467 | - <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option> |
|
468 | - <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option> |
|
469 | - <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option> |
|
467 | + <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option> |
|
468 | + <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option> |
|
469 | + <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option> |
|
470 | 470 | </select> |
471 | 471 | </h2> |
472 | 472 | <div id="futtta_feed"> |
473 | 473 | <div id="autoptimizefeed"> |
474 | - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?> |
|
474 | + <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?> |
|
475 | 475 | </div> |
476 | 476 | <div id="wordpressfeed"> |
477 | - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?> |
|
477 | + <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?> |
|
478 | 478 | </div> |
479 | 479 | <div id="webtechfeed"> |
480 | - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?> |
|
480 | + <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?> |
|
481 | 481 | </div> |
482 | 482 | </div> |
483 | 483 | </div> |
484 | - <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div> |
|
484 | + <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e('Do not donate for this plugin!', 'autoptimize'); ?>"></a></div> |
|
485 | 485 | </div> |
486 | 486 | |
487 | 487 | <script type="text/javascript"> |
@@ -630,81 +630,81 @@ discard block |
||
630 | 630 | |
631 | 631 | public function addmenu() |
632 | 632 | { |
633 | - if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
633 | + if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
634 | 634 | // multisite, network admin, ao network activated: add normal settings page at network level. |
635 | - $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) ); |
|
636 | - } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) { |
|
635 | + $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config')); |
|
636 | + } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) { |
|
637 | 637 | // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options. |
638 | - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) ); |
|
638 | + $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message')); |
|
639 | 639 | } else { |
640 | 640 | // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on. |
641 | - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) ); |
|
641 | + $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config')); |
|
642 | 642 | } |
643 | 643 | |
644 | - add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) ); |
|
645 | - add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) ); |
|
644 | + add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts')); |
|
645 | + add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles')); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | public function autoptimize_admin_scripts() |
649 | 649 | { |
650 | - wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
651 | - wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
650 | + wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true); |
|
651 | + wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | public function autoptimize_admin_styles() |
655 | 655 | { |
656 | - wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) ); |
|
657 | - wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) ); |
|
656 | + wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__)); |
|
657 | + wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__)); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | public function registersettings() { |
661 | - register_setting( 'autoptimize', 'autoptimize_html' ); |
|
662 | - register_setting( 'autoptimize', 'autoptimize_html_keepcomments' ); |
|
663 | - register_setting( 'autoptimize', 'autoptimize_enable_site_config' ); |
|
664 | - register_setting( 'autoptimize', 'autoptimize_js' ); |
|
665 | - register_setting( 'autoptimize', 'autoptimize_js_aggregate' ); |
|
666 | - register_setting( 'autoptimize', 'autoptimize_js_exclude' ); |
|
667 | - register_setting( 'autoptimize', 'autoptimize_js_trycatch' ); |
|
668 | - register_setting( 'autoptimize', 'autoptimize_js_justhead' ); |
|
669 | - register_setting( 'autoptimize', 'autoptimize_js_forcehead' ); |
|
670 | - register_setting( 'autoptimize', 'autoptimize_js_include_inline' ); |
|
671 | - register_setting( 'autoptimize', 'autoptimize_css' ); |
|
672 | - register_setting( 'autoptimize', 'autoptimize_css_aggregate' ); |
|
673 | - register_setting( 'autoptimize', 'autoptimize_css_exclude' ); |
|
674 | - register_setting( 'autoptimize', 'autoptimize_css_justhead' ); |
|
675 | - register_setting( 'autoptimize', 'autoptimize_css_datauris' ); |
|
676 | - register_setting( 'autoptimize', 'autoptimize_css_defer' ); |
|
677 | - register_setting( 'autoptimize', 'autoptimize_css_defer_inline' ); |
|
678 | - register_setting( 'autoptimize', 'autoptimize_css_inline' ); |
|
679 | - register_setting( 'autoptimize', 'autoptimize_css_include_inline' ); |
|
680 | - register_setting( 'autoptimize', 'autoptimize_cdn_url' ); |
|
681 | - register_setting( 'autoptimize', 'autoptimize_cache_clean' ); |
|
682 | - register_setting( 'autoptimize', 'autoptimize_cache_nogzip' ); |
|
683 | - register_setting( 'autoptimize', 'autoptimize_optimize_logged' ); |
|
684 | - register_setting( 'autoptimize', 'autoptimize_optimize_checkout' ); |
|
685 | - register_setting( 'autoptimize', 'autoptimize_minify_excluded' ); |
|
686 | - register_setting( 'autoptimize', 'autoptimize_cache_fallback' ); |
|
661 | + register_setting('autoptimize', 'autoptimize_html'); |
|
662 | + register_setting('autoptimize', 'autoptimize_html_keepcomments'); |
|
663 | + register_setting('autoptimize', 'autoptimize_enable_site_config'); |
|
664 | + register_setting('autoptimize', 'autoptimize_js'); |
|
665 | + register_setting('autoptimize', 'autoptimize_js_aggregate'); |
|
666 | + register_setting('autoptimize', 'autoptimize_js_exclude'); |
|
667 | + register_setting('autoptimize', 'autoptimize_js_trycatch'); |
|
668 | + register_setting('autoptimize', 'autoptimize_js_justhead'); |
|
669 | + register_setting('autoptimize', 'autoptimize_js_forcehead'); |
|
670 | + register_setting('autoptimize', 'autoptimize_js_include_inline'); |
|
671 | + register_setting('autoptimize', 'autoptimize_css'); |
|
672 | + register_setting('autoptimize', 'autoptimize_css_aggregate'); |
|
673 | + register_setting('autoptimize', 'autoptimize_css_exclude'); |
|
674 | + register_setting('autoptimize', 'autoptimize_css_justhead'); |
|
675 | + register_setting('autoptimize', 'autoptimize_css_datauris'); |
|
676 | + register_setting('autoptimize', 'autoptimize_css_defer'); |
|
677 | + register_setting('autoptimize', 'autoptimize_css_defer_inline'); |
|
678 | + register_setting('autoptimize', 'autoptimize_css_inline'); |
|
679 | + register_setting('autoptimize', 'autoptimize_css_include_inline'); |
|
680 | + register_setting('autoptimize', 'autoptimize_cdn_url'); |
|
681 | + register_setting('autoptimize', 'autoptimize_cache_clean'); |
|
682 | + register_setting('autoptimize', 'autoptimize_cache_nogzip'); |
|
683 | + register_setting('autoptimize', 'autoptimize_optimize_logged'); |
|
684 | + register_setting('autoptimize', 'autoptimize_optimize_checkout'); |
|
685 | + register_setting('autoptimize', 'autoptimize_minify_excluded'); |
|
686 | + register_setting('autoptimize', 'autoptimize_cache_fallback'); |
|
687 | 687 | } |
688 | 688 | |
689 | - public function setmeta( $links, $file = null ) |
|
689 | + public function setmeta($links, $file = null) |
|
690 | 690 | { |
691 | 691 | // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/. |
692 | 692 | // Do it only once - saves time. |
693 | 693 | static $plugin; |
694 | - if ( empty( $plugin ) ) { |
|
695 | - $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' ); |
|
694 | + if (empty($plugin)) { |
|
695 | + $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php'); |
|
696 | 696 | } |
697 | 697 | |
698 | - if ( null === $file ) { |
|
698 | + if (null === $file) { |
|
699 | 699 | // 2.7 and lower. |
700 | - $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ); |
|
701 | - array_unshift( $links, $settings_link ); |
|
700 | + $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')); |
|
701 | + array_unshift($links, $settings_link); |
|
702 | 702 | } else { |
703 | 703 | // 2.8 and higher. |
704 | 704 | // If it's us, add the link. |
705 | - if ( $file === $plugin ) { |
|
706 | - $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) ); |
|
707 | - $links = array_merge( $links, $newlink ); |
|
705 | + if ($file === $plugin) { |
|
706 | + $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'))); |
|
707 | + $links = array_merge($links, $newlink); |
|
708 | 708 | } |
709 | 709 | } |
710 | 710 | |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | 'autoptimize_imgopt_select_field_2' => '2', // quality glossy. |
781 | 781 | 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off. |
782 | 782 | 'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed). |
783 | - 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty. |
|
783 | + 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty. |
|
784 | 784 | ); |
785 | 785 | return $defaults; |
786 | 786 | } |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | */ |
793 | 793 | public static function get_ao_css_preload_polyfill() |
794 | 794 | { |
795 | - $preload_poly = apply_filters( 'autoptimize_css_preload_polyfill', '<script data-cfasync=\'false\'>!function(t){"use strict";t.loadCSS||(t.loadCSS=function(){});var e=loadCSS.relpreload={};if(e.support=function(){var e;try{e=t.document.createElement("link").relList.supports("preload")}catch(t){e=!1}return function(){return e}}(),e.bindMediaToggle=function(t){function e(){t.media=a}var a=t.media||"all";t.addEventListener?t.addEventListener("load",e):t.attachEvent&&t.attachEvent("onload",e),setTimeout(function(){t.rel="stylesheet",t.media="only x"}),setTimeout(e,3e3)},e.poly=function(){if(!e.support())for(var a=t.document.getElementsByTagName("link"),n=0;n<a.length;n++){var o=a[n];"preload"!==o.rel||"style"!==o.getAttribute("as")||o.getAttribute("data-loadcss")||(o.setAttribute("data-loadcss",!0),e.bindMediaToggle(o))}},!e.support()){e.poly();var a=t.setInterval(e.poly,500);t.addEventListener?t.addEventListener("load",function(){e.poly(),t.clearInterval(a)}):t.attachEvent&&t.attachEvent("onload",function(){e.poly(),t.clearInterval(a)})}"undefined"!=typeof exports?exports.loadCSS=loadCSS:t.loadCSS=loadCSS}("undefined"!=typeof global?global:this);</script>' ); |
|
795 | + $preload_poly = apply_filters('autoptimize_css_preload_polyfill', '<script data-cfasync=\'false\'>!function(t){"use strict";t.loadCSS||(t.loadCSS=function(){});var e=loadCSS.relpreload={};if(e.support=function(){var e;try{e=t.document.createElement("link").relList.supports("preload")}catch(t){e=!1}return function(){return e}}(),e.bindMediaToggle=function(t){function e(){t.media=a}var a=t.media||"all";t.addEventListener?t.addEventListener("load",e):t.attachEvent&&t.attachEvent("onload",e),setTimeout(function(){t.rel="stylesheet",t.media="only x"}),setTimeout(e,3e3)},e.poly=function(){if(!e.support())for(var a=t.document.getElementsByTagName("link"),n=0;n<a.length;n++){var o=a[n];"preload"!==o.rel||"style"!==o.getAttribute("as")||o.getAttribute("data-loadcss")||(o.setAttribute("data-loadcss",!0),e.bindMediaToggle(o))}},!e.support()){e.poly();var a=t.setInterval(e.poly,500);t.addEventListener?t.addEventListener("load",function(){e.poly(),t.clearInterval(a)}):t.attachEvent&&t.attachEvent("onload",function(){e.poly(),t.clearInterval(a)})}"undefined"!=typeof exports?exports.loadCSS=loadCSS:t.loadCSS=loadCSS}("undefined"!=typeof global?global:this);</script>'); |
|
796 | 796 | return $preload_poly; |
797 | 797 | } |
798 | 798 | |
@@ -803,56 +803,56 @@ discard block |
||
803 | 803 | */ |
804 | 804 | public static function get_ao_css_preload_onload() |
805 | 805 | { |
806 | - $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.rel='stylesheet'" ); |
|
806 | + $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.rel='stylesheet'"); |
|
807 | 807 | return $preload_onload; |
808 | 808 | } |
809 | 809 | |
810 | - public function get( $key ) |
|
810 | + public function get($key) |
|
811 | 811 | { |
812 | - if ( ! is_array( $this->config ) ) { |
|
812 | + if (!is_array($this->config)) { |
|
813 | 813 | // Default config. |
814 | 814 | $config = self::get_defaults(); |
815 | 815 | |
816 | 816 | // Override with user settings. |
817 | - foreach ( array_keys( $config ) as $name ) { |
|
818 | - $conf = autoptimizeOptionWrapper::get_option( $name ); |
|
819 | - if ( false !== $conf ) { |
|
817 | + foreach (array_keys($config) as $name) { |
|
818 | + $conf = autoptimizeOptionWrapper::get_option($name); |
|
819 | + if (false !== $conf) { |
|
820 | 820 | // It was set before! |
821 | - $config[ $name ] = $conf; |
|
821 | + $config[$name] = $conf; |
|
822 | 822 | } |
823 | 823 | } |
824 | 824 | |
825 | 825 | // Save for next call. |
826 | - $this->config = apply_filters( 'autoptimize_filter_get_config', $config ); |
|
826 | + $this->config = apply_filters('autoptimize_filter_get_config', $config); |
|
827 | 827 | } |
828 | 828 | |
829 | - if ( isset( $this->config[ $key ] ) ) { |
|
830 | - return $this->config[ $key ]; |
|
829 | + if (isset($this->config[$key])) { |
|
830 | + return $this->config[$key]; |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | return false; |
834 | 834 | } |
835 | 835 | |
836 | - private function get_futtta_feeds( $url ) { |
|
837 | - if ( $this->settings_screen_do_remote_http ) { |
|
838 | - $rss = fetch_feed( $url ); |
|
836 | + private function get_futtta_feeds($url) { |
|
837 | + if ($this->settings_screen_do_remote_http) { |
|
838 | + $rss = fetch_feed($url); |
|
839 | 839 | $maxitems = 0; |
840 | 840 | |
841 | - if ( ! is_wp_error( $rss ) ) { |
|
842 | - $maxitems = $rss->get_item_quantity( 7 ); |
|
843 | - $rss_items = $rss->get_items( 0, $maxitems ); |
|
841 | + if (!is_wp_error($rss)) { |
|
842 | + $maxitems = $rss->get_item_quantity(7); |
|
843 | + $rss_items = $rss->get_items(0, $maxitems); |
|
844 | 844 | } |
845 | 845 | ?> |
846 | 846 | <ul> |
847 | - <?php if ( 0 == $maxitems ) : ?> |
|
848 | - <li><?php _e( 'No items', 'autoptimize' ); ?></li> |
|
847 | + <?php if (0 == $maxitems) : ?> |
|
848 | + <li><?php _e('No items', 'autoptimize'); ?></li> |
|
849 | 849 | <?php else : ?> |
850 | - <?php foreach ( $rss_items as $item ) : ?> |
|
850 | + <?php foreach ($rss_items as $item) : ?> |
|
851 | 851 | <li> |
852 | - <a href="<?php echo esc_url( $item->get_permalink() ); ?>" |
|
852 | + <a href="<?php echo esc_url($item->get_permalink()); ?>" |
|
853 | 853 | <?php // translators: the variable contains a date. ?> |
854 | - title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>"> |
|
855 | - <?php echo esc_html( $item->get_title() ); ?> |
|
854 | + title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>"> |
|
855 | + <?php echo esc_html($item->get_title()); ?> |
|
856 | 856 | </a> |
857 | 857 | </li> |
858 | 858 | <?php endforeach; ?> |
@@ -865,23 +865,23 @@ discard block |
||
865 | 865 | static function ao_admin_tabs() |
866 | 866 | { |
867 | 867 | // based on http://wordpress.stackexchange.com/a/58826 . |
868 | - $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS & HTML', 'autoptimize' ) ) ); |
|
868 | + $tabs = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS & HTML', 'autoptimize'))); |
|
869 | 869 | $tab_content = ''; |
870 | - $tabs_count = count( $tabs ); |
|
871 | - if ( $tabs_count > 1 ) { |
|
872 | - if ( isset( $_GET['page'] ) ) { |
|
870 | + $tabs_count = count($tabs); |
|
871 | + if ($tabs_count > 1) { |
|
872 | + if (isset($_GET['page'])) { |
|
873 | 873 | $current_id = $_GET['page']; |
874 | 874 | } else { |
875 | 875 | $current_id = 'autoptimize'; |
876 | 876 | } |
877 | 877 | $tab_content .= '<h2 class="nav-tab-wrapper">'; |
878 | - foreach ( $tabs as $tab_id => $tab_name ) { |
|
879 | - if ( $current_id == $tab_id ) { |
|
878 | + foreach ($tabs as $tab_id => $tab_name) { |
|
879 | + if ($current_id == $tab_id) { |
|
880 | 880 | $class = ' nav-tab-active'; |
881 | 881 | } else { |
882 | 882 | $class = ''; |
883 | 883 | } |
884 | - $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>'; |
|
884 | + $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>'; |
|
885 | 885 | } |
886 | 886 | $tab_content .= '</h2>'; |
887 | 887 | } else { |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | */ |
899 | 899 | public static function is_admin_and_not_ajax() |
900 | 900 | { |
901 | - return ( is_admin() && ! self::doing_ajax() ); |
|
901 | + return (is_admin() && !self::doing_ajax()); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | /** |
@@ -908,10 +908,10 @@ discard block |
||
908 | 908 | */ |
909 | 909 | protected static function doing_ajax() |
910 | 910 | { |
911 | - if ( function_exists( 'wp_doing_ajax' ) ) { |
|
911 | + if (function_exists('wp_doing_ajax')) { |
|
912 | 912 | return wp_doing_ajax(); |
913 | 913 | } |
914 | - return ( defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
914 | + return (defined('DOING_AJAX') && DOING_AJAX); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | /** |
@@ -920,7 +920,7 @@ discard block |
||
920 | 920 | * @return bool |
921 | 921 | */ |
922 | 922 | public static function should_show_menu_tabs() { |
923 | - if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) { |
|
923 | + if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) { |
|
924 | 924 | return true; |
925 | 925 | } else { |
926 | 926 | return false; |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Critical CSS base file (initializes all ccss files). |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -19,28 +19,28 @@ discard block |
||
19 | 19 | public function __construct() |
20 | 20 | { |
21 | 21 | // define constant, but only once. |
22 | - if ( ! defined( 'AO_CCSS_DIR' ) ) { |
|
22 | + if (!defined('AO_CCSS_DIR')) { |
|
23 | 23 | // Define plugin version. |
24 | - define( 'AO_CCSS_VER', 'AO_' . AUTOPTIMIZE_PLUGIN_VERSION ); |
|
24 | + define('AO_CCSS_VER', 'AO_'.AUTOPTIMIZE_PLUGIN_VERSION); |
|
25 | 25 | |
26 | 26 | // Define a constant with the directory to store critical CSS in. |
27 | - if ( is_multisite() ) { |
|
27 | + if (is_multisite()) { |
|
28 | 28 | $blog_id = get_current_blog_id(); |
29 | - define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' . $blog_id . '/' ); |
|
29 | + define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/'.$blog_id.'/'); |
|
30 | 30 | } else { |
31 | - define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' ); |
|
31 | + define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | // Define support files locations. |
35 | - define( 'AO_CCSS_LOCK', AO_CCSS_DIR . 'queue.lock' ); |
|
36 | - define( 'AO_CCSS_LOG', AO_CCSS_DIR . 'queuelog.html' ); |
|
37 | - define( 'AO_CCSS_DEBUG', AO_CCSS_DIR . 'queue.json' ); |
|
35 | + define('AO_CCSS_LOCK', AO_CCSS_DIR.'queue.lock'); |
|
36 | + define('AO_CCSS_LOG', AO_CCSS_DIR.'queuelog.html'); |
|
37 | + define('AO_CCSS_DEBUG', AO_CCSS_DIR.'queue.json'); |
|
38 | 38 | |
39 | 39 | // Define constants for criticalcss.com base path and API endpoints. |
40 | 40 | // fixme: AO_CCSS_URL should be read from the autoptimize availability json stored as option. |
41 | - define( 'AO_CCSS_URL', 'https://criticalcss.com' ); |
|
42 | - define( 'AO_CCSS_API', AO_CCSS_URL . '/api/premium/' ); |
|
43 | - define( 'AO_CCSS_SLEEP', 10 ); |
|
41 | + define('AO_CCSS_URL', 'https://criticalcss.com'); |
|
42 | + define('AO_CCSS_API', AO_CCSS_URL.'/api/premium/'); |
|
43 | + define('AO_CCSS_SLEEP', 10); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | $this->filepath = __FILE__; |
@@ -53,19 +53,19 @@ discard block |
||
53 | 53 | { |
54 | 54 | // get all options. |
55 | 55 | $all_options = $this->fetch_options(); |
56 | - foreach ( $all_options as $option => $value ) { |
|
56 | + foreach ($all_options as $option => $value) { |
|
57 | 57 | ${$option} = $value; |
58 | 58 | } |
59 | 59 | |
60 | 60 | // make sure the 10 minutes cron schedule is added. |
61 | - add_filter( 'cron_schedules', array( $this, 'ao_ccss_interval' ) ); |
|
61 | + add_filter('cron_schedules', array($this, 'ao_ccss_interval')); |
|
62 | 62 | |
63 | 63 | // check if we need to upgrade. |
64 | 64 | $this->check_upgrade(); |
65 | 65 | |
66 | 66 | // make sure ao_ccss_queue is scheduled OK if an API key is set. |
67 | - if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) { |
|
68 | - wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' ); |
|
67 | + if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) { |
|
68 | + wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue'); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | // Required libs, core is always needed. |
74 | 74 | $criticalcss_core = new autoptimizeCriticalCSSCore(); |
75 | 75 | |
76 | - if ( defined( 'DOING_CRON' ) || is_admin() ) { |
|
76 | + if (defined('DOING_CRON') || is_admin()) { |
|
77 | 77 | // TODO: also include if overridden somehow to force queue processing to be executed? |
78 | 78 | $criticalcss_cron = new autoptimizeCriticalCSSCron(); |
79 | 79 | } |
80 | 80 | |
81 | - if ( is_admin() ) { |
|
81 | + if (is_admin()) { |
|
82 | 82 | $criticalcss_settings = new autoptimizeCriticalCSSSettings(); |
83 | 83 | } else { |
84 | 84 | // enqueuing only done when not wp-admin. |
@@ -89,50 +89,50 @@ discard block |
||
89 | 89 | public static function fetch_options() { |
90 | 90 | static $autoptimize_ccss_options = null; |
91 | 91 | |
92 | - if ( null === $autoptimize_ccss_options ) { |
|
92 | + if (null === $autoptimize_ccss_options) { |
|
93 | 93 | // not cached yet, fetching from WordPress options. |
94 | - $autoptimize_ccss_options['ao_css_defer'] = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ); |
|
95 | - $autoptimize_ccss_options['ao_css_defer_inline'] = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ); |
|
96 | - $autoptimize_ccss_options['ao_ccss_rules_raw'] = get_option( 'autoptimize_ccss_rules', false ); |
|
97 | - $autoptimize_ccss_options['ao_ccss_additional'] = get_option( 'autoptimize_ccss_additional' ); |
|
98 | - $autoptimize_ccss_options['ao_ccss_queue_raw'] = get_option( 'autoptimize_ccss_queue', false ); |
|
99 | - $autoptimize_ccss_options['ao_ccss_viewport'] = get_option( 'autoptimize_ccss_viewport', false ); |
|
100 | - $autoptimize_ccss_options['ao_ccss_finclude'] = get_option( 'autoptimize_ccss_finclude', false ); |
|
101 | - $autoptimize_ccss_options['ao_ccss_rlimit'] = get_option( 'autoptimize_ccss_rlimit', '5' ); |
|
102 | - $autoptimize_ccss_options['ao_ccss_noptimize'] = get_option( 'autoptimize_ccss_noptimize', false ); |
|
103 | - $autoptimize_ccss_options['ao_ccss_debug'] = get_option( 'autoptimize_ccss_debug', false ); |
|
104 | - $autoptimize_ccss_options['ao_ccss_key'] = get_option( 'autoptimize_ccss_key' ); |
|
105 | - $autoptimize_ccss_options['ao_ccss_keyst'] = get_option( 'autoptimize_ccss_keyst' ); |
|
106 | - $autoptimize_ccss_options['ao_ccss_loggedin'] = get_option( 'autoptimize_ccss_loggedin', '1' ); |
|
107 | - $autoptimize_ccss_options['ao_ccss_forcepath'] = get_option( 'autoptimize_ccss_forcepath', '1' ); |
|
108 | - $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option( 'autoptimize_service_availablity' ); |
|
109 | - $autoptimize_ccss_options['ao_ccss_deferjquery'] = get_option( 'autoptimize_ccss_deferjquery', false ); |
|
110 | - $autoptimize_ccss_options['ao_ccss_domain'] = get_option( 'autoptimize_ccss_domain' ); |
|
111 | - |
|
112 | - if ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) === false && strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'uggc' ) === 0 ) { |
|
113 | - $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ); |
|
114 | - } elseif ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) !== false ) { |
|
94 | + $autoptimize_ccss_options['ao_css_defer'] = autoptimizeOptionWrapper::get_option('autoptimize_css_defer'); |
|
95 | + $autoptimize_ccss_options['ao_css_defer_inline'] = autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline'); |
|
96 | + $autoptimize_ccss_options['ao_ccss_rules_raw'] = get_option('autoptimize_ccss_rules', false); |
|
97 | + $autoptimize_ccss_options['ao_ccss_additional'] = get_option('autoptimize_ccss_additional'); |
|
98 | + $autoptimize_ccss_options['ao_ccss_queue_raw'] = get_option('autoptimize_ccss_queue', false); |
|
99 | + $autoptimize_ccss_options['ao_ccss_viewport'] = get_option('autoptimize_ccss_viewport', false); |
|
100 | + $autoptimize_ccss_options['ao_ccss_finclude'] = get_option('autoptimize_ccss_finclude', false); |
|
101 | + $autoptimize_ccss_options['ao_ccss_rlimit'] = get_option('autoptimize_ccss_rlimit', '5'); |
|
102 | + $autoptimize_ccss_options['ao_ccss_noptimize'] = get_option('autoptimize_ccss_noptimize', false); |
|
103 | + $autoptimize_ccss_options['ao_ccss_debug'] = get_option('autoptimize_ccss_debug', false); |
|
104 | + $autoptimize_ccss_options['ao_ccss_key'] = get_option('autoptimize_ccss_key'); |
|
105 | + $autoptimize_ccss_options['ao_ccss_keyst'] = get_option('autoptimize_ccss_keyst'); |
|
106 | + $autoptimize_ccss_options['ao_ccss_loggedin'] = get_option('autoptimize_ccss_loggedin', '1'); |
|
107 | + $autoptimize_ccss_options['ao_ccss_forcepath'] = get_option('autoptimize_ccss_forcepath', '1'); |
|
108 | + $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option('autoptimize_service_availablity'); |
|
109 | + $autoptimize_ccss_options['ao_ccss_deferjquery'] = get_option('autoptimize_ccss_deferjquery', false); |
|
110 | + $autoptimize_ccss_options['ao_ccss_domain'] = get_option('autoptimize_ccss_domain'); |
|
111 | + |
|
112 | + if (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') === false && strpos($autoptimize_ccss_options['ao_ccss_domain'], 'uggc') === 0) { |
|
113 | + $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13($autoptimize_ccss_options['ao_ccss_domain']); |
|
114 | + } elseif (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') !== false) { |
|
115 | 115 | // not rot13'ed yet, do so now (goal; avoid migration plugins change the bound domain). |
116 | - update_option( 'autoptimize_ccss_domain', str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ) ); |
|
116 | + update_option('autoptimize_ccss_domain', str_rot13($autoptimize_ccss_options['ao_ccss_domain'])); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Setup the rules array. |
120 | - if ( empty( $autoptimize_ccss_options['ao_ccss_rules_raw'] ) ) { |
|
120 | + if (empty($autoptimize_ccss_options['ao_ccss_rules_raw'])) { |
|
121 | 121 | $autoptimize_ccss_options['ao_ccss_rules']['paths'] = array(); |
122 | 122 | $autoptimize_ccss_options['ao_ccss_rules']['types'] = array(); |
123 | 123 | } else { |
124 | - $autoptimize_ccss_options['ao_ccss_rules'] = json_decode( $autoptimize_ccss_options['ao_ccss_rules_raw'], true ); |
|
124 | + $autoptimize_ccss_options['ao_ccss_rules'] = json_decode($autoptimize_ccss_options['ao_ccss_rules_raw'], true); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | // Setup the queue array. |
128 | - if ( empty( $autoptimize_ccss_options['ao_ccss_queue_raw'] ) ) { |
|
128 | + if (empty($autoptimize_ccss_options['ao_ccss_queue_raw'])) { |
|
129 | 129 | $autoptimize_ccss_options['ao_ccss_queue'] = array(); |
130 | 130 | } else { |
131 | - $autoptimize_ccss_options['ao_ccss_queue'] = json_decode( $autoptimize_ccss_options['ao_ccss_queue_raw'], true ); |
|
131 | + $autoptimize_ccss_options['ao_ccss_queue'] = json_decode($autoptimize_ccss_options['ao_ccss_queue_raw'], true); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // Override API key if constant is defined. |
135 | - if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) { |
|
135 | + if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) { |
|
136 | 136 | $autoptimize_ccss_options['ao_ccss_key'] = AUTOPTIMIZE_CRITICALCSS_API_KEY; |
137 | 137 | } |
138 | 138 | } |
@@ -144,49 +144,49 @@ discard block |
||
144 | 144 | global $ao_ccss_key; |
145 | 145 | |
146 | 146 | // Create the cache directory if it doesn't exist already. |
147 | - if ( ! file_exists( AO_CCSS_DIR ) ) { |
|
148 | - mkdir( AO_CCSS_DIR, 0755, true ); |
|
147 | + if (!file_exists(AO_CCSS_DIR)) { |
|
148 | + mkdir(AO_CCSS_DIR, 0755, true); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | // Create a scheduled event for the queue. |
152 | - if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) { |
|
153 | - wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' ); |
|
152 | + if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) { |
|
153 | + wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // Create a scheduled event for log maintenance. |
157 | - if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_maintenance' ) ) { |
|
158 | - wp_schedule_event( time(), 'twicedaily', 'ao_ccss_maintenance' ); |
|
157 | + if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_maintenance')) { |
|
158 | + wp_schedule_event(time(), 'twicedaily', 'ao_ccss_maintenance'); |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
162 | 162 | public function check_upgrade() { |
163 | - $db_version = get_option( 'autoptimize_ccss_version', '' ); |
|
164 | - if ( AO_CCSS_VER !== $db_version ) { |
|
163 | + $db_version = get_option('autoptimize_ccss_version', ''); |
|
164 | + if (AO_CCSS_VER !== $db_version) { |
|
165 | 165 | // check schedules & re-schedule if needed. |
166 | 166 | $this->on_upgrade(); |
167 | 167 | // and update db_version. |
168 | - update_option( 'autoptimize_ccss_version', AO_CCSS_VER ); |
|
168 | + update_option('autoptimize_ccss_version', AO_CCSS_VER); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - public function ao_ccss_interval( $schedules ) { |
|
172 | + public function ao_ccss_interval($schedules) { |
|
173 | 173 | // Let interval be configurable. |
174 | - if ( ! defined( 'AO_CCSS_DEBUG_INTERVAL' ) ) { |
|
174 | + if (!defined('AO_CCSS_DEBUG_INTERVAL')) { |
|
175 | 175 | $intsec = 600; |
176 | 176 | } else { |
177 | 177 | $intsec = AO_CCSS_DEBUG_INTERVAL; |
178 | - if ( $intsec >= 120 ) { |
|
179 | - $inttxt = $intsec / 60 . ' minutes'; |
|
178 | + if ($intsec >= 120) { |
|
179 | + $inttxt = $intsec/60.' minutes'; |
|
180 | 180 | } else { |
181 | - $inttxt = $intsec . ' second(s)'; |
|
181 | + $inttxt = $intsec.' second(s)'; |
|
182 | 182 | } |
183 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Using custom WP-Cron interval of ' . $inttxt, 3 ); |
|
183 | + autoptimizeCriticalCSSCore::ao_ccss_log('Using custom WP-Cron interval of '.$inttxt, 3); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | // Attach interval to schedule. |
187 | 187 | $schedules['ao_ccss'] = array( |
188 | 188 | 'interval' => $intsec, |
189 | - 'display' => __( 'Autoptimize CriticalCSS' ), |
|
189 | + 'display' => __('Autoptimize CriticalCSS'), |
|
190 | 190 | ); |
191 | 191 | return $schedules; |
192 | 192 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles disk-cache-related operations. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | * @param string $md5 Hash. |
39 | 39 | * @param string $ext Extension. |
40 | 40 | */ |
41 | - public function __construct( $md5, $ext = 'php' ) |
|
41 | + public function __construct($md5, $ext = 'php') |
|
42 | 42 | { |
43 | 43 | $_min_ext = ''; |
44 | - if ( apply_filters( 'autoptimize_filter_cache_url_add_min_ext', false ) ) { |
|
44 | + if (apply_filters('autoptimize_filter_cache_url_add_min_ext', false)) { |
|
45 | 45 | $_min_ext = '.min'; |
46 | 46 | } |
47 | 47 | |
48 | 48 | $this->cachedir = AUTOPTIMIZE_CACHE_DIR; |
49 | 49 | $this->nogzip = AUTOPTIMIZE_CACHE_NOGZIP; |
50 | - if ( ! $this->nogzip ) { |
|
51 | - $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.php'; |
|
50 | + if (!$this->nogzip) { |
|
51 | + $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.php'; |
|
52 | 52 | } else { |
53 | - if ( in_array( $ext, array( 'js', 'css' ) ) ) { |
|
54 | - $this->filename = $ext . '/' . AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext; |
|
53 | + if (in_array($ext, array('js', 'css'))) { |
|
54 | + $this->filename = $ext.'/'.AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext; |
|
55 | 55 | } else { |
56 | - $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext; |
|
56 | + $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext; |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function check() |
67 | 67 | { |
68 | - return file_exists( $this->cachedir . $this->filename ); |
|
68 | + return file_exists($this->cachedir.$this->filename); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function retrieve() |
77 | 77 | { |
78 | - if ( $this->check() ) { |
|
79 | - if ( false == $this->nogzip ) { |
|
80 | - return file_get_contents( $this->cachedir . $this->filename . '.none' ); |
|
78 | + if ($this->check()) { |
|
79 | + if (false == $this->nogzip) { |
|
80 | + return file_get_contents($this->cachedir.$this->filename.'.none'); |
|
81 | 81 | } else { |
82 | - return file_get_contents( $this->cachedir . $this->filename ); |
|
82 | + return file_get_contents($this->cachedir.$this->filename); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | return false; |
@@ -93,50 +93,50 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return void |
95 | 95 | */ |
96 | - public function cache( $data, $mime ) |
|
96 | + public function cache($data, $mime) |
|
97 | 97 | { |
98 | 98 | // off by default; check if cachedirs exist every time before caching |
99 | 99 | // |
100 | 100 | // to be activated for users that experience these ugly errors; |
101 | 101 | // PHP Warning: file_put_contents failed to open stream: No such file or directory. |
102 | - if ( apply_filters( 'autoptimize_filter_cache_checkdirs_on_write', false ) ) { |
|
102 | + if (apply_filters('autoptimize_filter_cache_checkdirs_on_write', false)) { |
|
103 | 103 | $this->check_and_create_dirs(); |
104 | 104 | } |
105 | 105 | |
106 | - if ( false === $this->nogzip ) { |
|
106 | + if (false === $this->nogzip) { |
|
107 | 107 | // We handle gzipping ourselves. |
108 | 108 | $file = 'default.php'; |
109 | - $phpcode = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $file ); |
|
110 | - $phpcode = str_replace( array( '%%CONTENT%%', 'exit;' ), array( $mime, '' ), $phpcode ); |
|
109 | + $phpcode = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$file); |
|
110 | + $phpcode = str_replace(array('%%CONTENT%%', 'exit;'), array($mime, ''), $phpcode); |
|
111 | 111 | |
112 | - file_put_contents( $this->cachedir . $this->filename, $phpcode ); |
|
113 | - file_put_contents( $this->cachedir . $this->filename . '.none', $data ); |
|
112 | + file_put_contents($this->cachedir.$this->filename, $phpcode); |
|
113 | + file_put_contents($this->cachedir.$this->filename.'.none', $data); |
|
114 | 114 | } else { |
115 | 115 | // Write code to cache without doing anything else. |
116 | - file_put_contents( $this->cachedir . $this->filename, $data ); |
|
116 | + file_put_contents($this->cachedir.$this->filename, $data); |
|
117 | 117 | |
118 | 118 | // save fallback .js or .css file if filter true (to be false by default) but not if snippet or single. |
119 | - if ( self::do_fallback() && strpos( $this->filename, '_snippet_' ) === false && strpos( $this->filename, '_single_' ) === false ) { |
|
120 | - $_extension = pathinfo( $this->filename, PATHINFO_EXTENSION ); |
|
121 | - $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX . 'fallback.' . $_extension; |
|
122 | - if ( ( 'css' === $_extension || 'js' === $_extension ) && ! file_exists( $this->cachedir . $_extension . '/' . $_fallback_file ) ) { |
|
123 | - file_put_contents( $this->cachedir . $_extension . '/' . $_fallback_file, $data ); |
|
119 | + if (self::do_fallback() && strpos($this->filename, '_snippet_') === false && strpos($this->filename, '_single_') === false) { |
|
120 | + $_extension = pathinfo($this->filename, PATHINFO_EXTENSION); |
|
121 | + $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX.'fallback.'.$_extension; |
|
122 | + if (('css' === $_extension || 'js' === $_extension) && !file_exists($this->cachedir.$_extension.'/'.$_fallback_file)) { |
|
123 | + file_put_contents($this->cachedir.$_extension.'/'.$_fallback_file, $data); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - if ( apply_filters( 'autoptimize_filter_cache_create_static_gzip', false ) ) { |
|
127 | + if (apply_filters('autoptimize_filter_cache_create_static_gzip', false)) { |
|
128 | 128 | // Create an additional cached gzip file. |
129 | - file_put_contents( $this->cachedir . $this->filename . '.gz', gzencode( $data, 9, FORCE_GZIP ) ); |
|
129 | + file_put_contents($this->cachedir.$this->filename.'.gz', gzencode($data, 9, FORCE_GZIP)); |
|
130 | 130 | // If PHP Brotli extension is installed, create an additional cached Brotli file. |
131 | - if ( function_exists( 'brotli_compress' ) ) { |
|
132 | - file_put_contents( $this->cachedir . $this->filename . '.br', brotli_compress( $data, 11, BROTLI_GENERIC ) ); |
|
131 | + if (function_exists('brotli_compress')) { |
|
132 | + file_put_contents($this->cachedir.$this->filename.'.br', brotli_compress($data, 11, BROTLI_GENERIC)); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | 137 | // Provide 3rd party action hook for every cache file that is created. |
138 | 138 | // This hook can for example be used to inject a copy of the created cache file to a other domain. |
139 | - do_action( 'autoptimize_action_cache_file_created', $this->cachedir . $this->filename ); |
|
139 | + do_action('autoptimize_action_cache_file_created', $this->cachedir.$this->filename); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | // The original idea here was to provide 3rd party code a hook so that |
152 | 152 | // it can "listen" to all the complete autoptimized-urls that the page |
153 | 153 | // will emit... Or something to that effect I think? |
154 | - apply_filters( 'autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL . $this->filename ); |
|
154 | + apply_filters('autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL.$this->filename); |
|
155 | 155 | |
156 | 156 | return $this->filename; |
157 | 157 | } |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | * @param string $file Filename. |
165 | 165 | * @return bool |
166 | 166 | */ |
167 | - protected static function is_valid_cache_file( $dir, $file ) |
|
167 | + protected static function is_valid_cache_file($dir, $file) |
|
168 | 168 | { |
169 | - if ( '.' !== $file && '..' !== $file && |
|
170 | - false !== strpos( $file, AUTOPTIMIZE_CACHEFILE_PREFIX ) && |
|
171 | - is_file( $dir . $file ) ) { |
|
169 | + if ('.' !== $file && '..' !== $file && |
|
170 | + false !== strpos($file, AUTOPTIMIZE_CACHEFILE_PREFIX) && |
|
171 | + is_file($dir.$file)) { |
|
172 | 172 | |
173 | 173 | // It's a valid file! |
174 | 174 | return true; |
@@ -186,16 +186,16 @@ discard block |
||
186 | 186 | protected static function clear_cache_classic() |
187 | 187 | { |
188 | 188 | $contents = self::get_cache_contents(); |
189 | - foreach ( $contents as $name => $files ) { |
|
190 | - $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/'; |
|
191 | - foreach ( $files as $file ) { |
|
192 | - if ( self::is_valid_cache_file( $dir, $file ) ) { |
|
193 | - @unlink( $dir . $file ); // @codingStandardsIgnoreLine |
|
189 | + foreach ($contents as $name => $files) { |
|
190 | + $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/'; |
|
191 | + foreach ($files as $file) { |
|
192 | + if (self::is_valid_cache_file($dir, $file)) { |
|
193 | + @unlink($dir.$file); // @codingStandardsIgnoreLine |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
198 | - @unlink( AUTOPTIMIZE_CACHE_DIR . '/.htaccess' ); // @codingStandardsIgnoreLine |
|
198 | + @unlink(AUTOPTIMIZE_CACHE_DIR.'/.htaccess'); // @codingStandardsIgnoreLine |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -206,19 +206,19 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return bool |
208 | 208 | */ |
209 | - protected static function rmdir( $pathname ) |
|
209 | + protected static function rmdir($pathname) |
|
210 | 210 | { |
211 | - $files = self::get_dir_contents( $pathname ); |
|
212 | - foreach ( $files as $file ) { |
|
213 | - $path = $pathname . '/' . $file; |
|
214 | - if ( is_dir( $path ) ) { |
|
215 | - self::rmdir( $path ); |
|
211 | + $files = self::get_dir_contents($pathname); |
|
212 | + foreach ($files as $file) { |
|
213 | + $path = $pathname.'/'.$file; |
|
214 | + if (is_dir($path)) { |
|
215 | + self::rmdir($path); |
|
216 | 216 | } else { |
217 | - unlink( $path ); |
|
217 | + unlink($path); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - return rmdir( $pathname ); |
|
221 | + return rmdir($pathname); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | $new_name = self::get_unique_name(); |
240 | 240 | |
241 | 241 | // Makes sure the new pathname is on the same level... |
242 | - $new_pathname = dirname( $dir ) . '/' . $new_name; |
|
243 | - $renamed = @rename( $dir, $new_pathname ); // @codingStandardsIgnoreLine |
|
242 | + $new_pathname = dirname($dir).'/'.$new_name; |
|
243 | + $renamed = @rename($dir, $new_pathname); // @codingStandardsIgnoreLine |
|
244 | 244 | |
245 | 245 | // When renamed, re-create the default cache directory back so it's |
246 | 246 | // available again... |
247 | - if ( $renamed ) { |
|
247 | + if ($renamed) { |
|
248 | 248 | $ok = self::cacheavail(); |
249 | 249 | } |
250 | 250 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public static function advanced_cache_clear_enabled() |
260 | 260 | { |
261 | - return apply_filters( 'autoptimize_filter_cache_clear_advanced', false ); |
|
261 | + return apply_filters('autoptimize_filter_cache_clear_advanced', false); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | protected static function get_unique_name() |
270 | 270 | { |
271 | 271 | $prefix = self::get_advanced_cache_clear_prefix(); |
272 | - $new_name = uniqid( $prefix, true ); |
|
272 | + $new_name = uniqid($prefix, true); |
|
273 | 273 | |
274 | 274 | return $new_name; |
275 | 275 | } |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | protected static function get_advanced_cache_clear_prefix() |
283 | 283 | { |
284 | 284 | $pathname = self::get_pathname_base(); |
285 | - $basename = basename( $pathname ); |
|
286 | - $prefix = $basename . '-artifact-'; |
|
285 | + $basename = basename($pathname); |
|
286 | + $prefix = $basename.'-artifact-'; |
|
287 | 287 | |
288 | 288 | return $prefix; |
289 | 289 | } |
@@ -296,9 +296,9 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @return array |
298 | 298 | */ |
299 | - protected static function get_dir_contents( $pathname ) |
|
299 | + protected static function get_dir_contents($pathname) |
|
300 | 300 | { |
301 | - return array_slice( scandir( $pathname ), 2 ); |
|
301 | + return array_slice(scandir($pathname), 2); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -311,24 +311,24 @@ discard block |
||
311 | 311 | public static function delete_advanced_cache_clear_artifacts() |
312 | 312 | { |
313 | 313 | // Don't go through these motions (called from the cachechecker) if advanced cache clear isn't even active. |
314 | - if ( ! self::advanced_cache_clear_enabled() ) { |
|
314 | + if (!self::advanced_cache_clear_enabled()) { |
|
315 | 315 | return false; |
316 | 316 | } |
317 | 317 | |
318 | 318 | $dir = self::get_pathname_base(); |
319 | 319 | $prefix = self::get_advanced_cache_clear_prefix(); |
320 | - $parent = dirname( $dir ); |
|
320 | + $parent = dirname($dir); |
|
321 | 321 | $ok = false; |
322 | 322 | |
323 | 323 | // Returns the list of files without '.' and '..' elements. |
324 | - $files = self::get_dir_contents( $parent ); |
|
325 | - if ( is_array( $files ) && ! empty( $files ) ) { |
|
326 | - foreach ( $files as $file ) { |
|
327 | - $path = $parent . '/' . $file; |
|
328 | - $prefixed = ( false !== strpos( $path, $prefix ) ); |
|
324 | + $files = self::get_dir_contents($parent); |
|
325 | + if (is_array($files) && !empty($files)) { |
|
326 | + foreach ($files as $file) { |
|
327 | + $path = $parent.'/'.$file; |
|
328 | + $prefixed = (false !== strpos($path, $prefix)); |
|
329 | 329 | // Removing only our own (prefixed) directories... |
330 | - if ( is_dir( $path ) && $prefixed ) { |
|
331 | - $ok = self::rmdir( $path ); |
|
330 | + if (is_dir($path) && $prefixed) { |
|
331 | + $ok = self::rmdir($path); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | } |
@@ -348,9 +348,9 @@ discard block |
||
348 | 348 | { |
349 | 349 | $pathname = self::get_pathname_base(); |
350 | 350 | |
351 | - if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { |
|
351 | + if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
352 | 352 | $blog_id = get_current_blog_id(); |
353 | - $pathname .= $blog_id . '/'; |
|
353 | + $pathname .= $blog_id.'/'; |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | return $pathname; |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | */ |
364 | 364 | protected static function get_pathname_base() |
365 | 365 | { |
366 | - $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR; |
|
366 | + $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR; |
|
367 | 367 | |
368 | 368 | return $pathname; |
369 | 369 | } |
@@ -375,46 +375,46 @@ discard block |
||
375 | 375 | * |
376 | 376 | * @return bool |
377 | 377 | */ |
378 | - public static function clearall( $propagate = true ) |
|
378 | + public static function clearall($propagate = true) |
|
379 | 379 | { |
380 | - if ( ! self::cacheavail() ) { |
|
380 | + if (!self::cacheavail()) { |
|
381 | 381 | return false; |
382 | 382 | } |
383 | 383 | |
384 | 384 | // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically? |
385 | - if ( self::advanced_cache_clear_enabled() ) { |
|
385 | + if (self::advanced_cache_clear_enabled()) { |
|
386 | 386 | self::clear_cache_via_rename(); |
387 | 387 | } else { |
388 | 388 | self::clear_cache_classic(); |
389 | 389 | } |
390 | 390 | |
391 | 391 | // Remove 404 handler if required. |
392 | - if ( self::do_fallback() ) { |
|
393 | - $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . 'autoptimize_404_handler.php'; |
|
394 | - @unlink( $_fallback_php ); // @codingStandardsIgnoreLine |
|
392 | + if (self::do_fallback()) { |
|
393 | + $_fallback_php = trailingslashit(WP_CONTENT_DIR).'autoptimize_404_handler.php'; |
|
394 | + @unlink($_fallback_php); // @codingStandardsIgnoreLine |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | // Remove the transient so it gets regenerated... |
398 | - delete_transient( 'autoptimize_stats' ); |
|
398 | + delete_transient('autoptimize_stats'); |
|
399 | 399 | |
400 | 400 | // Cache was just purged, clear page cache and allow others to hook into our purging... |
401 | - if ( true === $propagate ) { |
|
402 | - if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) { |
|
401 | + if (true === $propagate) { |
|
402 | + if (!function_exists('autoptimize_do_cachepurged_action')) { |
|
403 | 403 | function autoptimize_do_cachepurged_action() { |
404 | - do_action( 'autoptimize_action_cachepurged' ); |
|
404 | + do_action('autoptimize_action_cachepurged'); |
|
405 | 405 | } |
406 | 406 | } |
407 | - add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 ); |
|
408 | - add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 ); |
|
407 | + add_action('shutdown', 'autoptimize_do_cachepurged_action', 11); |
|
408 | + add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | // Warm cache (part of speedupper)! |
412 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) && false == get_transient( 'autoptimize_cache_warmer_protector' ) ) { |
|
413 | - set_transient( 'autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60 * 10 ); |
|
414 | - $url = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 ); |
|
415 | - $url = apply_filters( 'autoptimize_filter_cache_warmer_url', $url ); |
|
416 | - $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine |
|
417 | - unset( $cache ); |
|
412 | + if (apply_filters('autoptimize_filter_speedupper', true) && false == get_transient('autoptimize_cache_warmer_protector')) { |
|
413 | + set_transient('autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60*10); |
|
414 | + $url = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000); |
|
415 | + $url = apply_filters('autoptimize_filter_cache_warmer_url', $url); |
|
416 | + $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine |
|
417 | + unset($cache); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | return true; |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | */ |
430 | 430 | public static function clearall_actionless() |
431 | 431 | { |
432 | - return self::clearall( false ); |
|
432 | + return self::clearall(false); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | { |
442 | 442 | $contents = array(); |
443 | 443 | |
444 | - foreach ( array( '', 'js', 'css' ) as $dir ) { |
|
445 | - $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir ); |
|
444 | + foreach (array('', 'js', 'css') as $dir) { |
|
445 | + $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | return $contents; |
@@ -455,21 +455,21 @@ discard block |
||
455 | 455 | */ |
456 | 456 | public static function stats() |
457 | 457 | { |
458 | - $stats = get_transient( 'autoptimize_stats' ); |
|
458 | + $stats = get_transient('autoptimize_stats'); |
|
459 | 459 | |
460 | 460 | // If no transient, do the actual scan! |
461 | - if ( ! is_array( $stats ) ) { |
|
462 | - if ( ! self::cacheavail() ) { |
|
461 | + if (!is_array($stats)) { |
|
462 | + if (!self::cacheavail()) { |
|
463 | 463 | return 0; |
464 | 464 | } |
465 | 465 | $stats = self::stats_scan(); |
466 | 466 | $count = $stats[0]; |
467 | - if ( $count > 100 ) { |
|
467 | + if ($count > 100) { |
|
468 | 468 | // Store results in transient. |
469 | 469 | set_transient( |
470 | 470 | 'autoptimize_stats', |
471 | 471 | $stats, |
472 | - apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS ) |
|
472 | + apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS) |
|
473 | 473 | ); |
474 | 474 | } |
475 | 475 | } |
@@ -492,30 +492,30 @@ discard block |
||
492 | 492 | $size = 0; |
493 | 493 | |
494 | 494 | // Scan everything in our cache directories. |
495 | - foreach ( self::get_cache_contents() as $name => $files ) { |
|
496 | - $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/'; |
|
497 | - foreach ( $files as $file ) { |
|
498 | - if ( self::is_valid_cache_file( $dir, $file ) ) { |
|
499 | - if ( AUTOPTIMIZE_CACHE_NOGZIP && |
|
495 | + foreach (self::get_cache_contents() as $name => $files) { |
|
496 | + $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/'; |
|
497 | + foreach ($files as $file) { |
|
498 | + if (self::is_valid_cache_file($dir, $file)) { |
|
499 | + if (AUTOPTIMIZE_CACHE_NOGZIP && |
|
500 | 500 | ( |
501 | - false !== strpos( $file, '.js' ) || |
|
502 | - false !== strpos( $file, '.css' ) || |
|
503 | - false !== strpos( $file, '.img' ) || |
|
504 | - false !== strpos( $file, '.txt' ) |
|
501 | + false !== strpos($file, '.js') || |
|
502 | + false !== strpos($file, '.css') || |
|
503 | + false !== strpos($file, '.img') || |
|
504 | + false !== strpos($file, '.txt') |
|
505 | 505 | ) |
506 | 506 | ) { |
507 | 507 | // Web server is gzipping, we count .js|.css|.img|.txt files. |
508 | 508 | $count++; |
509 | - } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) { |
|
509 | + } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) { |
|
510 | 510 | // We are gzipping ourselves via php, counting only .none files. |
511 | 511 | $count++; |
512 | 512 | } |
513 | - $size += filesize( $dir . $file ); |
|
513 | + $size += filesize($dir.$file); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | } |
517 | 517 | |
518 | - $stats = array( $count, $size, time() ); |
|
518 | + $stats = array($count, $size, time()); |
|
519 | 519 | |
520 | 520 | return $stats; |
521 | 521 | } |
@@ -529,22 +529,22 @@ discard block |
||
529 | 529 | */ |
530 | 530 | public static function cacheavail() |
531 | 531 | { |
532 | - if ( false === autoptimizeCache::check_and_create_dirs() ) { |
|
532 | + if (false === autoptimizeCache::check_and_create_dirs()) { |
|
533 | 533 | return false; |
534 | 534 | } |
535 | 535 | |
536 | 536 | // Using .htaccess inside our cache folder to overrule wp-super-cache. |
537 | - $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess'; |
|
538 | - if ( ! is_file( $htaccess ) ) { |
|
537 | + $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess'; |
|
538 | + if (!is_file($htaccess)) { |
|
539 | 539 | /** |
540 | 540 | * Create `wp-content/AO_htaccess_tmpl` file with |
541 | 541 | * whatever htaccess rules you might need |
542 | 542 | * if you want to override default AO htaccess |
543 | 543 | */ |
544 | - $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl'; |
|
545 | - if ( is_file( $htaccess_tmpl ) ) { |
|
546 | - $content = file_get_contents( $htaccess_tmpl ); |
|
547 | - } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) { |
|
544 | + $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl'; |
|
545 | + if (is_file($htaccess_tmpl)) { |
|
546 | + $content = file_get_contents($htaccess_tmpl); |
|
547 | + } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) { |
|
548 | 548 | $content = '<IfModule mod_expires.c> |
549 | 549 | ExpiresActive On |
550 | 550 | ExpiresByType text/css A30672000 |
@@ -598,13 +598,13 @@ discard block |
||
598 | 598 | </IfModule>'; |
599 | 599 | } |
600 | 600 | |
601 | - if ( self::do_fallback() === true ) { |
|
602 | - $content .= "\nErrorDocument 404 " . trailingslashit( parse_url( content_url(), PHP_URL_PATH ) ) . 'autoptimize_404_handler.php'; |
|
601 | + if (self::do_fallback() === true) { |
|
602 | + $content .= "\nErrorDocument 404 ".trailingslashit(parse_url(content_url(), PHP_URL_PATH)).'autoptimize_404_handler.php'; |
|
603 | 603 | } |
604 | - @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine |
|
604 | + @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine |
|
605 | 605 | } |
606 | 606 | |
607 | - if ( self::do_fallback() ) { |
|
607 | + if (self::do_fallback()) { |
|
608 | 608 | self::check_fallback_php(); |
609 | 609 | } |
610 | 610 | |
@@ -619,17 +619,17 @@ discard block |
||
619 | 619 | */ |
620 | 620 | public static function check_fallback_php() { |
621 | 621 | $_fallback_filename = 'autoptimize_404_handler.php'; |
622 | - $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . $_fallback_filename; |
|
622 | + $_fallback_php = trailingslashit(WP_CONTENT_DIR).$_fallback_filename; |
|
623 | 623 | $_fallback_status = true; |
624 | 624 | |
625 | - if ( ! file_exists( $_fallback_php ) ) { |
|
626 | - $_fallback_php_contents = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $_fallback_filename ); |
|
627 | - $_fallback_php_contents = str_replace( '<?php exit;', '<?php', $_fallback_php_contents ); |
|
628 | - $_fallback_php_contents = str_replace( '<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents ); |
|
629 | - if ( apply_filters( 'autoptimize_filter_cache_fallback_log_errors', false ) ) { |
|
630 | - $_fallback_php_contents = str_replace( '// error_log', 'error_log', $_fallback_php_contents ); |
|
625 | + if (!file_exists($_fallback_php)) { |
|
626 | + $_fallback_php_contents = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$_fallback_filename); |
|
627 | + $_fallback_php_contents = str_replace('<?php exit;', '<?php', $_fallback_php_contents); |
|
628 | + $_fallback_php_contents = str_replace('<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents); |
|
629 | + if (apply_filters('autoptimize_filter_cache_fallback_log_errors', false)) { |
|
630 | + $_fallback_php_contents = str_replace('// error_log', 'error_log', $_fallback_php_contents); |
|
631 | 631 | } |
632 | - $_fallback_status = file_put_contents( $_fallback_php, $_fallback_php_contents ); |
|
632 | + $_fallback_status = file_put_contents($_fallback_php, $_fallback_php_contents); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | return $_fallback_status; |
@@ -646,8 +646,8 @@ discard block |
||
646 | 646 | public static function do_fallback() { |
647 | 647 | static $_do_fallback = null; |
648 | 648 | |
649 | - if ( null === $_do_fallback ) { |
|
650 | - $_do_fallback = (bool) apply_filters( 'autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '' ) ); |
|
649 | + if (null === $_do_fallback) { |
|
650 | + $_do_fallback = (bool) apply_filters('autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '')); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | return $_do_fallback; |
@@ -659,26 +659,26 @@ discard block |
||
659 | 659 | * and 410'ing ("Gone") if fallback not available. |
660 | 660 | */ |
661 | 661 | public static function wordpress_notfound_fallback() { |
662 | - $original_request = strtok( $_SERVER['REQUEST_URI'], '?' ); |
|
663 | - if ( strpos( $original_request, wp_basename( WP_CONTENT_DIR ) . AUTOPTIMIZE_CACHE_CHILD_DIR ) !== false && is_404() ) { |
|
662 | + $original_request = strtok($_SERVER['REQUEST_URI'], '?'); |
|
663 | + if (strpos($original_request, wp_basename(WP_CONTENT_DIR).AUTOPTIMIZE_CACHE_CHILD_DIR) !== false && is_404()) { |
|
664 | 664 | // make sure this is not considered a 404. |
665 | 665 | global $wp_query; |
666 | 666 | $wp_query->is_404 = false; |
667 | 667 | |
668 | 668 | // set fallback path. |
669 | - $js_or_css = pathinfo( $original_request, PATHINFO_EXTENSION ); |
|
670 | - $fallback_path = AUTOPTIMIZE_CACHE_DIR . $js_or_css . '/autoptimize_fallback.' . $js_or_css; |
|
669 | + $js_or_css = pathinfo($original_request, PATHINFO_EXTENSION); |
|
670 | + $fallback_path = AUTOPTIMIZE_CACHE_DIR.$js_or_css.'/autoptimize_fallback.'.$js_or_css; |
|
671 | 671 | |
672 | 672 | // set fallback URL. |
673 | - $fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request ); |
|
673 | + $fallback_target = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request); |
|
674 | 674 | |
675 | 675 | // redirect to fallback if possible. |
676 | - if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) { |
|
676 | + if ($original_request !== $fallback_target && file_exists($fallback_path)) { |
|
677 | 677 | // redirect to fallback. |
678 | - wp_redirect( $fallback_target, 302 ); |
|
678 | + wp_redirect($fallback_target, 302); |
|
679 | 679 | } else { |
680 | 680 | // return HTTP 410 (gone) reponse. |
681 | - status_header( 410 ); |
|
681 | + status_header(410); |
|
682 | 682 | } |
683 | 683 | } |
684 | 684 | } |
@@ -690,13 +690,13 @@ discard block |
||
690 | 690 | * @return bool |
691 | 691 | */ |
692 | 692 | public static function check_and_create_dirs() { |
693 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) { |
|
693 | + if (!defined('AUTOPTIMIZE_CACHE_DIR')) { |
|
694 | 694 | // We didn't set a cache. |
695 | 695 | return false; |
696 | 696 | } |
697 | 697 | |
698 | - foreach ( array( '', 'js', 'css' ) as $dir ) { |
|
699 | - if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) { |
|
698 | + foreach (array('', 'js', 'css') as $dir) { |
|
699 | + if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) { |
|
700 | 700 | return false; |
701 | 701 | } |
702 | 702 | } |
@@ -711,25 +711,25 @@ discard block |
||
711 | 711 | * |
712 | 712 | * @return bool |
713 | 713 | */ |
714 | - protected static function check_cache_dir( $dir ) |
|
714 | + protected static function check_cache_dir($dir) |
|
715 | 715 | { |
716 | 716 | // Try creating the dir if it doesn't exist. |
717 | - if ( ! file_exists( $dir ) ) { |
|
718 | - @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine |
|
719 | - if ( ! file_exists( $dir ) ) { |
|
717 | + if (!file_exists($dir)) { |
|
718 | + @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine |
|
719 | + if (!file_exists($dir)) { |
|
720 | 720 | return false; |
721 | 721 | } |
722 | 722 | } |
723 | 723 | |
724 | 724 | // If we still cannot write, bail. |
725 | - if ( ! is_writable( $dir ) ) { |
|
725 | + if (!is_writable($dir)) { |
|
726 | 726 | return false; |
727 | 727 | } |
728 | 728 | |
729 | 729 | // Create an index.html in there to avoid prying eyes! |
730 | - $idx_file = rtrim( $dir, '/\\' ) . '/index.html'; |
|
731 | - if ( ! is_file( $idx_file ) ) { |
|
732 | - @file_put_contents( $idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); // @codingStandardsIgnoreLine |
|
730 | + $idx_file = rtrim($dir, '/\\').'/index.html'; |
|
731 | + if (!is_file($idx_file)) { |
|
732 | + @file_put_contents($idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>'); // @codingStandardsIgnoreLine |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | return true; |
@@ -743,50 +743,50 @@ discard block |
||
743 | 743 | // @codingStandardsIgnoreStart |
744 | 744 | public static function flushPageCache() |
745 | 745 | { |
746 | - if ( function_exists( 'wp_cache_clear_cache' ) ) { |
|
747 | - if ( is_multisite() ) { |
|
746 | + if (function_exists('wp_cache_clear_cache')) { |
|
747 | + if (is_multisite()) { |
|
748 | 748 | $blog_id = get_current_blog_id(); |
749 | - wp_cache_clear_cache( $blog_id ); |
|
749 | + wp_cache_clear_cache($blog_id); |
|
750 | 750 | } else { |
751 | 751 | wp_cache_clear_cache(); |
752 | 752 | } |
753 | - } elseif ( has_action( 'cachify_flush_cache' ) ) { |
|
754 | - do_action( 'cachify_flush_cache' ); |
|
755 | - } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) { |
|
753 | + } elseif (has_action('cachify_flush_cache')) { |
|
754 | + do_action('cachify_flush_cache'); |
|
755 | + } elseif (function_exists('w3tc_pgcache_flush')) { |
|
756 | 756 | w3tc_pgcache_flush(); |
757 | - } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) { |
|
757 | + } elseif (function_exists('wp_fast_cache_bulk_delete_all')) { |
|
758 | 758 | wp_fast_cache_bulk_delete_all(); |
759 | - } elseif ( class_exists( 'WpFastestCache' ) ) { |
|
759 | + } elseif (class_exists('WpFastestCache')) { |
|
760 | 760 | $wpfc = new WpFastestCache(); |
761 | 761 | $wpfc->deleteCache(); |
762 | - } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) { |
|
762 | + } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) { |
|
763 | 763 | c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache |
764 | - } elseif ( class_exists( 'zencache' ) ) { |
|
764 | + } elseif (class_exists('zencache')) { |
|
765 | 765 | zencache::clear(); |
766 | - } elseif ( class_exists( 'comet_cache' ) ) { |
|
766 | + } elseif (class_exists('comet_cache')) { |
|
767 | 767 | comet_cache::clear(); |
768 | - } elseif ( class_exists( 'WpeCommon' ) ) { |
|
768 | + } elseif (class_exists('WpeCommon')) { |
|
769 | 769 | // WPEngine cache purge/flush methods to call by default |
770 | 770 | $wpe_methods = array( |
771 | 771 | 'purge_varnish_cache', |
772 | 772 | ); |
773 | 773 | |
774 | 774 | // More agressive clear/flush/purge behind a filter |
775 | - if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) { |
|
776 | - $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) ); |
|
775 | + if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) { |
|
776 | + $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache')); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing) |
780 | - $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods ); |
|
780 | + $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods); |
|
781 | 781 | |
782 | - foreach ( $wpe_methods as $wpe_method ) { |
|
783 | - if ( method_exists( 'WpeCommon', $wpe_method ) ) { |
|
782 | + foreach ($wpe_methods as $wpe_method) { |
|
783 | + if (method_exists('WpeCommon', $wpe_method)) { |
|
784 | 784 | WpeCommon::$wpe_method(); |
785 | 785 | } |
786 | 786 | } |
787 | - } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) { |
|
787 | + } elseif (function_exists('sg_cachepress_purge_cache')) { |
|
788 | 788 | sg_cachepress_purge_cache(); |
789 | - } elseif ( array_key_exists( 'KINSTA_CACHE_ZONE', $_SERVER ) ) { |
|
789 | + } elseif (array_key_exists('KINSTA_CACHE_ZONE', $_SERVER)) { |
|
790 | 790 | $_kinsta_clear_cache_url = 'https://localhost/kinsta-clear-cache-all'; |
791 | 791 | $_kinsta_response = wp_remote_get( |
792 | 792 | $_kinsta_clear_cache_url, |
@@ -795,18 +795,18 @@ discard block |
||
795 | 795 | 'timeout' => 5, |
796 | 796 | ) |
797 | 797 | ); |
798 | - } elseif ( defined('NGINX_HELPER_BASENAME') ) { |
|
799 | - do_action( 'rt_nginx_helper_purge_all' ); |
|
800 | - } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) { |
|
798 | + } elseif (defined('NGINX_HELPER_BASENAME')) { |
|
799 | + do_action('rt_nginx_helper_purge_all'); |
|
800 | + } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) { |
|
801 | 801 | // fallback for WP-Super-Cache |
802 | 802 | global $cache_path; |
803 | - if ( is_multisite() ) { |
|
803 | + if (is_multisite()) { |
|
804 | 804 | $blog_id = get_current_blog_id(); |
805 | - prune_super_cache( get_supercache_dir( $blog_id ), true ); |
|
806 | - prune_super_cache( $cache_path . 'blogs/', true ); |
|
805 | + prune_super_cache(get_supercache_dir($blog_id), true); |
|
806 | + prune_super_cache($cache_path.'blogs/', true); |
|
807 | 807 | } else { |
808 | - prune_super_cache( $cache_path . 'supercache/', true ); |
|
809 | - prune_super_cache( $cache_path, true ); |
|
808 | + prune_super_cache($cache_path.'supercache/', true); |
|
809 | + prune_super_cache($cache_path, true); |
|
810 | 810 | } |
811 | 811 | } |
812 | 812 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Class for JS optimization. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -198,127 +198,127 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @param array $options all options. |
200 | 200 | */ |
201 | - public function read( $options ) |
|
201 | + public function read($options) |
|
202 | 202 | { |
203 | - $noptimize_js = apply_filters( 'autoptimize_filter_js_noptimize', false, $this->content ); |
|
204 | - if ( $noptimize_js ) { |
|
203 | + $noptimize_js = apply_filters('autoptimize_filter_js_noptimize', false, $this->content); |
|
204 | + if ($noptimize_js) { |
|
205 | 205 | return false; |
206 | 206 | } |
207 | 207 | |
208 | 208 | // only optimize known good JS? |
209 | - $whitelist_js = apply_filters( 'autoptimize_filter_js_whitelist', '', $this->content ); |
|
210 | - if ( ! empty( $whitelist_js ) ) { |
|
211 | - $this->whitelist = array_filter( array_map( 'trim', explode( ',', $whitelist_js ) ) ); |
|
209 | + $whitelist_js = apply_filters('autoptimize_filter_js_whitelist', '', $this->content); |
|
210 | + if (!empty($whitelist_js)) { |
|
211 | + $this->whitelist = array_filter(array_map('trim', explode(',', $whitelist_js))); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | // is there JS we should simply remove? |
215 | - $removable_js = apply_filters( 'autoptimize_filter_js_removables', '', $this->content ); |
|
216 | - if ( ! empty( $removable_js ) ) { |
|
217 | - $this->jsremovables = array_filter( array_map( 'trim', explode( ',', $removable_js ) ) ); |
|
215 | + $removable_js = apply_filters('autoptimize_filter_js_removables', '', $this->content); |
|
216 | + if (!empty($removable_js)) { |
|
217 | + $this->jsremovables = array_filter(array_map('trim', explode(',', $removable_js))); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | // only header? |
221 | - if ( apply_filters( 'autoptimize_filter_js_justhead', $options['justhead'] ) ) { |
|
222 | - $content = explode( '</head>', $this->content, 2 ); |
|
223 | - $this->content = $content[0] . '</head>'; |
|
221 | + if (apply_filters('autoptimize_filter_js_justhead', $options['justhead'])) { |
|
222 | + $content = explode('</head>', $this->content, 2); |
|
223 | + $this->content = $content[0].'</head>'; |
|
224 | 224 | $this->restofcontent = $content[1]; |
225 | 225 | } |
226 | 226 | |
227 | 227 | // Determine whether we're doing JS-files aggregation or not. |
228 | - if ( ! $options['aggregate'] ) { |
|
228 | + if (!$options['aggregate']) { |
|
229 | 229 | $this->aggregate = false; |
230 | 230 | } |
231 | 231 | // Returning true for "dontaggregate" turns off aggregation. |
232 | - if ( $this->aggregate && apply_filters( 'autoptimize_filter_js_dontaggregate', false ) ) { |
|
232 | + if ($this->aggregate && apply_filters('autoptimize_filter_js_dontaggregate', false)) { |
|
233 | 233 | $this->aggregate = false; |
234 | 234 | } |
235 | 235 | |
236 | 236 | // include inline? |
237 | - if ( apply_filters( 'autoptimize_js_include_inline', $options['include_inline'] ) ) { |
|
237 | + if (apply_filters('autoptimize_js_include_inline', $options['include_inline'])) { |
|
238 | 238 | $this->include_inline = true; |
239 | 239 | } |
240 | 240 | |
241 | 241 | // filter to "late inject minified JS", default to true for now (it is faster). |
242 | - $this->inject_min_late = apply_filters( 'autoptimize_filter_js_inject_min_late', true ); |
|
242 | + $this->inject_min_late = apply_filters('autoptimize_filter_js_inject_min_late', true); |
|
243 | 243 | |
244 | 244 | // filters to override hardcoded do(nt)move(last) array contents (array in, array out!). |
245 | - $this->dontmove = apply_filters( 'autoptimize_filter_js_dontmove', $this->dontmove ); |
|
246 | - $this->domovelast = apply_filters( 'autoptimize_filter_js_movelast', $this->domovelast ); |
|
247 | - $this->domove = apply_filters( 'autoptimize_filter_js_domove', $this->domove ); |
|
245 | + $this->dontmove = apply_filters('autoptimize_filter_js_dontmove', $this->dontmove); |
|
246 | + $this->domovelast = apply_filters('autoptimize_filter_js_movelast', $this->domovelast); |
|
247 | + $this->domove = apply_filters('autoptimize_filter_js_domove', $this->domove); |
|
248 | 248 | |
249 | 249 | // Determine whether excluded files should be minified if not yet so. |
250 | - if ( ! $options['minify_excluded'] && $options['aggregate'] ) { |
|
250 | + if (!$options['minify_excluded'] && $options['aggregate']) { |
|
251 | 251 | $this->minify_excluded = false; |
252 | 252 | } |
253 | - $this->minify_excluded = apply_filters( 'autoptimize_filter_js_minify_excluded', $this->minify_excluded, '' ); |
|
253 | + $this->minify_excluded = apply_filters('autoptimize_filter_js_minify_excluded', $this->minify_excluded, ''); |
|
254 | 254 | |
255 | 255 | // get extra exclusions settings or filter. |
256 | 256 | $exclude_js = $options['js_exclude']; |
257 | - $exclude_js = apply_filters( 'autoptimize_filter_js_exclude', $exclude_js, $this->content ); |
|
258 | - |
|
259 | - if ( '' !== $exclude_js ) { |
|
260 | - if ( is_array( $exclude_js ) ) { |
|
261 | - $remove_keys = array_keys( $exclude_js, 'remove' ); |
|
262 | - if ( false !== $remove_keys ) { |
|
263 | - foreach ( $remove_keys as $remove_key ) { |
|
264 | - unset( $exclude_js[ $remove_key ] ); |
|
257 | + $exclude_js = apply_filters('autoptimize_filter_js_exclude', $exclude_js, $this->content); |
|
258 | + |
|
259 | + if ('' !== $exclude_js) { |
|
260 | + if (is_array($exclude_js)) { |
|
261 | + $remove_keys = array_keys($exclude_js, 'remove'); |
|
262 | + if (false !== $remove_keys) { |
|
263 | + foreach ($remove_keys as $remove_key) { |
|
264 | + unset($exclude_js[$remove_key]); |
|
265 | 265 | $this->jsremovables[] = $remove_key; |
266 | 266 | } |
267 | 267 | } |
268 | - $excl_js_arr = array_keys( $exclude_js ); |
|
268 | + $excl_js_arr = array_keys($exclude_js); |
|
269 | 269 | } else { |
270 | - $excl_js_arr = array_filter( array_map( 'trim', explode( ',', $exclude_js ) ) ); |
|
270 | + $excl_js_arr = array_filter(array_map('trim', explode(',', $exclude_js))); |
|
271 | 271 | } |
272 | - $this->dontmove = array_merge( $excl_js_arr, $this->dontmove ); |
|
272 | + $this->dontmove = array_merge($excl_js_arr, $this->dontmove); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | // Should we add try-catch? |
276 | - if ( $options['trycatch'] ) { |
|
276 | + if ($options['trycatch']) { |
|
277 | 277 | $this->trycatch = true; |
278 | 278 | } |
279 | 279 | |
280 | 280 | // force js in head? |
281 | - if ( $options['forcehead'] ) { |
|
281 | + if ($options['forcehead']) { |
|
282 | 282 | $this->forcehead = true; |
283 | 283 | } else { |
284 | 284 | $this->forcehead = false; |
285 | 285 | } |
286 | 286 | |
287 | - $this->forcehead = apply_filters( 'autoptimize_filter_js_forcehead', $this->forcehead ); |
|
287 | + $this->forcehead = apply_filters('autoptimize_filter_js_forcehead', $this->forcehead); |
|
288 | 288 | |
289 | 289 | // get cdn url. |
290 | 290 | $this->cdn_url = $options['cdn_url']; |
291 | 291 | |
292 | 292 | // noptimize me. |
293 | - $this->content = $this->hide_noptimize( $this->content ); |
|
293 | + $this->content = $this->hide_noptimize($this->content); |
|
294 | 294 | |
295 | 295 | // Save IE hacks. |
296 | - $this->content = $this->hide_iehacks( $this->content ); |
|
296 | + $this->content = $this->hide_iehacks($this->content); |
|
297 | 297 | |
298 | 298 | // comments. |
299 | - $this->content = $this->hide_comments( $this->content ); |
|
299 | + $this->content = $this->hide_comments($this->content); |
|
300 | 300 | |
301 | 301 | // Get script files. |
302 | - if ( preg_match_all( '#<script.*</script>#Usmi', $this->content, $matches ) ) { |
|
303 | - foreach ( $matches[0] as $tag ) { |
|
302 | + if (preg_match_all('#<script.*</script>#Usmi', $this->content, $matches)) { |
|
303 | + foreach ($matches[0] as $tag) { |
|
304 | 304 | // only consider script aggregation for types whitelisted in should_aggregate-function. |
305 | - $should_aggregate = $this->should_aggregate( $tag ); |
|
306 | - if ( ! $should_aggregate ) { |
|
305 | + $should_aggregate = $this->should_aggregate($tag); |
|
306 | + if (!$should_aggregate) { |
|
307 | 307 | $tag = ''; |
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | - if ( preg_match( '#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source ) ) { |
|
311 | + if (preg_match('#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source)) { |
|
312 | 312 | // non-inline script. |
313 | - if ( $this->isremovable( $tag, $this->jsremovables ) ) { |
|
314 | - $this->content = str_replace( $tag, '', $this->content ); |
|
313 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
314 | + $this->content = str_replace($tag, '', $this->content); |
|
315 | 315 | continue; |
316 | 316 | } |
317 | 317 | |
318 | 318 | $orig_tag = null; |
319 | - $url = current( explode( '?', $source[2], 2 ) ); |
|
320 | - $path = $this->getpath( $url ); |
|
321 | - if ( false !== $path && preg_match( '#\.js$#', $path ) && $this->ismergeable( $tag ) ) { |
|
319 | + $url = current(explode('?', $source[2], 2)); |
|
320 | + $path = $this->getpath($url); |
|
321 | + if (false !== $path && preg_match('#\.js$#', $path) && $this->ismergeable($tag)) { |
|
322 | 322 | // ok to optimize, add to array. |
323 | 323 | $this->scripts[] = $path; |
324 | 324 | } else { |
@@ -326,11 +326,11 @@ discard block |
||
326 | 326 | $new_tag = $tag; |
327 | 327 | |
328 | 328 | // non-mergeable script (excluded or dynamic or external). |
329 | - if ( is_array( $exclude_js ) ) { |
|
329 | + if (is_array($exclude_js)) { |
|
330 | 330 | // should we add flags? |
331 | - foreach ( $exclude_js as $excl_tag => $excl_flags ) { |
|
332 | - if ( false !== strpos( $orig_tag, $excl_tag ) && in_array( $excl_flags, array( 'async', 'defer' ) ) ) { |
|
333 | - $new_tag = str_replace( '<script ', '<script ' . $excl_flags . ' ', $new_tag ); |
|
331 | + foreach ($exclude_js as $excl_tag => $excl_flags) { |
|
332 | + if (false !== strpos($orig_tag, $excl_tag) && in_array($excl_flags, array('async', 'defer'))) { |
|
333 | + $new_tag = str_replace('<script ', '<script '.$excl_flags.' ', $new_tag); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | } |
@@ -338,14 +338,14 @@ discard block |
||
338 | 338 | // Should we minify the non-aggregated script? |
339 | 339 | // -> if aggregate is on and exclude minify is on |
340 | 340 | // -> if aggregate is off and the file is not in dontmove. |
341 | - if ( $path && $this->minify_excluded ) { |
|
342 | - $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false ); |
|
343 | - if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) { |
|
344 | - $minified_url = $this->minify_single( $path ); |
|
345 | - if ( ! empty( $minified_url ) ) { |
|
341 | + if ($path && $this->minify_excluded) { |
|
342 | + $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false); |
|
343 | + if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) { |
|
344 | + $minified_url = $this->minify_single($path); |
|
345 | + if (!empty($minified_url)) { |
|
346 | 346 | // Replace original URL with minified URL from cache. |
347 | - $new_tag = str_replace( $url, $minified_url, $new_tag ); |
|
348 | - } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) { |
|
347 | + $new_tag = str_replace($url, $minified_url, $new_tag); |
|
348 | + } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) { |
|
349 | 349 | // Remove the original script tag, because cache content is empty but only if filter |
350 | 350 | // is trued because $minified_url is also false if original JS is minified already. |
351 | 351 | $new_tag = ''; |
@@ -353,17 +353,17 @@ discard block |
||
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | - if ( $this->ismovable( $new_tag ) ) { |
|
356 | + if ($this->ismovable($new_tag)) { |
|
357 | 357 | // can be moved, flags and all. |
358 | - if ( $this->movetolast( $new_tag ) ) { |
|
358 | + if ($this->movetolast($new_tag)) { |
|
359 | 359 | $this->move['last'][] = $new_tag; |
360 | 360 | } else { |
361 | 361 | $this->move['first'][] = $new_tag; |
362 | 362 | } |
363 | 363 | } else { |
364 | 364 | // cannot be moved, so if flag was added re-inject altered tag immediately. |
365 | - if ( ( '' !== $new_tag && $orig_tag !== $new_tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_js_remove_empty_files', false ) ) ) { |
|
366 | - $this->content = str_replace( $orig_tag, $new_tag, $this->content ); |
|
365 | + if (('' !== $new_tag && $orig_tag !== $new_tag) || ('' === $new_tag && apply_filters('autoptimize_filter_js_remove_empty_files', false))) { |
|
366 | + $this->content = str_replace($orig_tag, $new_tag, $this->content); |
|
367 | 367 | $orig_tag = ''; |
368 | 368 | } |
369 | 369 | // and forget about the $tag (not to be touched any more). |
@@ -372,23 +372,23 @@ discard block |
||
372 | 372 | } |
373 | 373 | } else { |
374 | 374 | // Inline script. |
375 | - if ( $this->isremovable( $tag, $this->jsremovables ) ) { |
|
376 | - $this->content = str_replace( $tag, '', $this->content ); |
|
375 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
376 | + $this->content = str_replace($tag, '', $this->content); |
|
377 | 377 | continue; |
378 | 378 | } |
379 | 379 | |
380 | 380 | // unhide comments, as javascript may be wrapped in comment-tags for old times' sake. |
381 | - $tag = $this->restore_comments( $tag ); |
|
382 | - if ( $this->ismergeable( $tag ) && $this->include_inline ) { |
|
383 | - preg_match( '#<script.*>(.*)</script>#Usmi', $tag, $code ); |
|
384 | - $code = preg_replace( '#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1] ); |
|
385 | - $code = preg_replace( '/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code ); |
|
386 | - $this->scripts[] = 'INLINE;' . $code; |
|
381 | + $tag = $this->restore_comments($tag); |
|
382 | + if ($this->ismergeable($tag) && $this->include_inline) { |
|
383 | + preg_match('#<script.*>(.*)</script>#Usmi', $tag, $code); |
|
384 | + $code = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1]); |
|
385 | + $code = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code); |
|
386 | + $this->scripts[] = 'INLINE;'.$code; |
|
387 | 387 | } else { |
388 | 388 | // Can we move this? |
389 | - $autoptimize_js_moveable = apply_filters( 'autoptimize_js_moveable', '', $tag ); |
|
390 | - if ( $this->ismovable( $tag ) || '' !== $autoptimize_js_moveable ) { |
|
391 | - if ( $this->movetolast( $tag ) || 'last' === $autoptimize_js_moveable ) { |
|
389 | + $autoptimize_js_moveable = apply_filters('autoptimize_js_moveable', '', $tag); |
|
390 | + if ($this->ismovable($tag) || '' !== $autoptimize_js_moveable) { |
|
391 | + if ($this->movetolast($tag) || 'last' === $autoptimize_js_moveable) { |
|
392 | 392 | $this->move['last'][] = $tag; |
393 | 393 | } else { |
394 | 394 | $this->move['first'][] = $tag; |
@@ -399,11 +399,11 @@ discard block |
||
399 | 399 | } |
400 | 400 | } |
401 | 401 | // Re-hide comments to be able to do the removal based on tag from $this->content. |
402 | - $tag = $this->hide_comments( $tag ); |
|
402 | + $tag = $this->hide_comments($tag); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | // Remove the original script tag. |
406 | - $this->content = str_replace( $tag, '', $this->content ); |
|
406 | + $this->content = str_replace($tag, '', $this->content); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | return true; |
@@ -428,30 +428,30 @@ discard block |
||
428 | 428 | * @param string $tag Script node & child(ren). |
429 | 429 | * @return bool |
430 | 430 | */ |
431 | - public function should_aggregate( $tag ) |
|
431 | + public function should_aggregate($tag) |
|
432 | 432 | { |
433 | - if ( empty( $tag ) ) { |
|
433 | + if (empty($tag)) { |
|
434 | 434 | return false; |
435 | 435 | } |
436 | 436 | |
437 | 437 | // We're only interested in the type attribute of the <script> tag itself, not any possible |
438 | 438 | // inline code that might just contain the 'type=' string... |
439 | 439 | $tag_parts = array(); |
440 | - preg_match( '#<(script[^>]*)>#i', $tag, $tag_parts ); |
|
440 | + preg_match('#<(script[^>]*)>#i', $tag, $tag_parts); |
|
441 | 441 | $tag_without_contents = null; |
442 | - if ( ! empty( $tag_parts[1] ) ) { |
|
442 | + if (!empty($tag_parts[1])) { |
|
443 | 443 | $tag_without_contents = $tag_parts[1]; |
444 | 444 | } |
445 | 445 | |
446 | - $has_type = ( strpos( $tag_without_contents, 'type' ) !== false ); |
|
446 | + $has_type = (strpos($tag_without_contents, 'type') !== false); |
|
447 | 447 | |
448 | 448 | $type_valid = false; |
449 | - if ( $has_type ) { |
|
450 | - $type_valid = (bool) preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents ); |
|
449 | + if ($has_type) { |
|
450 | + $type_valid = (bool) preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | $should_aggregate = false; |
454 | - if ( ! $has_type || $type_valid ) { |
|
454 | + if (!$has_type || $type_valid) { |
|
455 | 455 | $should_aggregate = true; |
456 | 456 | } |
457 | 457 | |
@@ -463,75 +463,75 @@ discard block |
||
463 | 463 | */ |
464 | 464 | public function minify() |
465 | 465 | { |
466 | - foreach ( $this->scripts as $script ) { |
|
467 | - if ( empty( $script ) ) { |
|
466 | + foreach ($this->scripts as $script) { |
|
467 | + if (empty($script)) { |
|
468 | 468 | continue; |
469 | 469 | } |
470 | 470 | |
471 | 471 | // TODO/FIXME: some duplicate code here, can be reduced/simplified. |
472 | - if ( preg_match( '#^INLINE;#', $script ) ) { |
|
472 | + if (preg_match('#^INLINE;#', $script)) { |
|
473 | 473 | // Inline script. |
474 | - $script = preg_replace( '#^INLINE;#', '', $script ); |
|
475 | - $script = rtrim( $script, ";\n\t\r" ) . ';'; |
|
474 | + $script = preg_replace('#^INLINE;#', '', $script); |
|
475 | + $script = rtrim($script, ";\n\t\r").';'; |
|
476 | 476 | // Add try-catch? |
477 | - if ( $this->trycatch ) { |
|
478 | - $script = 'try{' . $script . '}catch(e){}'; |
|
477 | + if ($this->trycatch) { |
|
478 | + $script = 'try{'.$script.'}catch(e){}'; |
|
479 | 479 | } |
480 | - $tmpscript = apply_filters( 'autoptimize_js_individual_script', $script, '' ); |
|
481 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscript ) ) { |
|
480 | + $tmpscript = apply_filters('autoptimize_js_individual_script', $script, ''); |
|
481 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscript)) { |
|
482 | 482 | $script = $tmpscript; |
483 | 483 | $this->alreadyminified = true; |
484 | 484 | } |
485 | - $this->jscode .= "\n" . $script; |
|
485 | + $this->jscode .= "\n".$script; |
|
486 | 486 | } else { |
487 | 487 | // External script. |
488 | - if ( false !== $script && file_exists( $script ) && is_readable( $script ) ) { |
|
489 | - $scriptsrc = file_get_contents( $script ); |
|
490 | - $scriptsrc = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc ); |
|
491 | - $scriptsrc = rtrim( $scriptsrc, ";\n\t\r" ) . ';'; |
|
488 | + if (false !== $script && file_exists($script) && is_readable($script)) { |
|
489 | + $scriptsrc = file_get_contents($script); |
|
490 | + $scriptsrc = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc); |
|
491 | + $scriptsrc = rtrim($scriptsrc, ";\n\t\r").';'; |
|
492 | 492 | // Add try-catch? |
493 | - if ( $this->trycatch ) { |
|
494 | - $scriptsrc = 'try{' . $scriptsrc . '}catch(e){}'; |
|
493 | + if ($this->trycatch) { |
|
494 | + $scriptsrc = 'try{'.$scriptsrc.'}catch(e){}'; |
|
495 | 495 | } |
496 | - $tmpscriptsrc = apply_filters( 'autoptimize_js_individual_script', $scriptsrc, $script ); |
|
497 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscriptsrc ) ) { |
|
496 | + $tmpscriptsrc = apply_filters('autoptimize_js_individual_script', $scriptsrc, $script); |
|
497 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscriptsrc)) { |
|
498 | 498 | $scriptsrc = $tmpscriptsrc; |
499 | 499 | $this->alreadyminified = true; |
500 | - } elseif ( $this->can_inject_late( $script ) ) { |
|
501 | - $scriptsrc = self::build_injectlater_marker( $script, md5( $scriptsrc ) ); |
|
500 | + } elseif ($this->can_inject_late($script)) { |
|
501 | + $scriptsrc = self::build_injectlater_marker($script, md5($scriptsrc)); |
|
502 | 502 | } |
503 | - $this->jscode .= "\n" . $scriptsrc; |
|
503 | + $this->jscode .= "\n".$scriptsrc; |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | } |
507 | 507 | |
508 | 508 | // Check for already-minified code. |
509 | - $this->md5hash = md5( $this->jscode ); |
|
510 | - $ccheck = new autoptimizeCache( $this->md5hash, 'js' ); |
|
511 | - if ( $ccheck->check() ) { |
|
509 | + $this->md5hash = md5($this->jscode); |
|
510 | + $ccheck = new autoptimizeCache($this->md5hash, 'js'); |
|
511 | + if ($ccheck->check()) { |
|
512 | 512 | $this->jscode = $ccheck->retrieve(); |
513 | 513 | return true; |
514 | 514 | } |
515 | - unset( $ccheck ); |
|
515 | + unset($ccheck); |
|
516 | 516 | |
517 | 517 | // $this->jscode has all the uncompressed code now. |
518 | - if ( true !== $this->alreadyminified ) { |
|
519 | - if ( apply_filters( 'autoptimize_js_do_minify', true ) ) { |
|
520 | - $tmp_jscode = trim( JSMin::minify( $this->jscode ) ); |
|
521 | - if ( ! empty( $tmp_jscode ) ) { |
|
518 | + if (true !== $this->alreadyminified) { |
|
519 | + if (apply_filters('autoptimize_js_do_minify', true)) { |
|
520 | + $tmp_jscode = trim(JSMin::minify($this->jscode)); |
|
521 | + if (!empty($tmp_jscode)) { |
|
522 | 522 | $this->jscode = $tmp_jscode; |
523 | - unset( $tmp_jscode ); |
|
523 | + unset($tmp_jscode); |
|
524 | 524 | } |
525 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
526 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
525 | + $this->jscode = $this->inject_minified($this->jscode); |
|
526 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
527 | 527 | return true; |
528 | 528 | } else { |
529 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
529 | + $this->jscode = $this->inject_minified($this->jscode); |
|
530 | 530 | return false; |
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
534 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
534 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
535 | 535 | return true; |
536 | 536 | } |
537 | 537 | |
@@ -540,13 +540,13 @@ discard block |
||
540 | 540 | */ |
541 | 541 | public function cache() |
542 | 542 | { |
543 | - $cache = new autoptimizeCache( $this->md5hash, 'js' ); |
|
544 | - if ( ! $cache->check() ) { |
|
543 | + $cache = new autoptimizeCache($this->md5hash, 'js'); |
|
544 | + if (!$cache->check()) { |
|
545 | 545 | // Cache our code. |
546 | - $cache->cache( $this->jscode, 'text/javascript' ); |
|
546 | + $cache->cache($this->jscode, 'text/javascript'); |
|
547 | 547 | } |
548 | - $this->url = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
549 | - $this->url = $this->url_replace_cdn( $this->url ); |
|
548 | + $this->url = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
549 | + $this->url = $this->url_replace_cdn($this->url); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -555,47 +555,47 @@ discard block |
||
555 | 555 | public function getcontent() |
556 | 556 | { |
557 | 557 | // Restore the full content. |
558 | - if ( ! empty( $this->restofcontent ) ) { |
|
558 | + if (!empty($this->restofcontent)) { |
|
559 | 559 | $this->content .= $this->restofcontent; |
560 | 560 | $this->restofcontent = ''; |
561 | 561 | } |
562 | 562 | |
563 | 563 | // Add the scripts taking forcehead/ deferred (default) into account. |
564 | - if ( $this->forcehead ) { |
|
565 | - $replace_tag = array( '</head>', 'before' ); |
|
564 | + if ($this->forcehead) { |
|
565 | + $replace_tag = array('</head>', 'before'); |
|
566 | 566 | $defer = ''; |
567 | 567 | } else { |
568 | - $replace_tag = array( '</body>', 'before' ); |
|
568 | + $replace_tag = array('</body>', 'before'); |
|
569 | 569 | $defer = 'defer '; |
570 | 570 | } |
571 | 571 | |
572 | - $defer = apply_filters( 'autoptimize_filter_js_defer', $defer ); |
|
572 | + $defer = apply_filters('autoptimize_filter_js_defer', $defer); |
|
573 | 573 | $type_js = ''; |
574 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
574 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
575 | 575 | $type_js = 'type="text/javascript" '; |
576 | 576 | } |
577 | 577 | |
578 | - $bodyreplacementpayload = '<script ' . $type_js . $defer . 'src="' . $this->url . '"></script>'; |
|
579 | - $bodyreplacementpayload = apply_filters( 'autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload ); |
|
578 | + $bodyreplacementpayload = '<script '.$type_js.$defer.'src="'.$this->url.'"></script>'; |
|
579 | + $bodyreplacementpayload = apply_filters('autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload); |
|
580 | 580 | |
581 | - $bodyreplacement = implode( '', $this->move['first'] ); |
|
581 | + $bodyreplacement = implode('', $this->move['first']); |
|
582 | 582 | $bodyreplacement .= $bodyreplacementpayload; |
583 | - $bodyreplacement .= implode( '', $this->move['last'] ); |
|
583 | + $bodyreplacement .= implode('', $this->move['last']); |
|
584 | 584 | |
585 | - $replace_tag = apply_filters( 'autoptimize_filter_js_replacetag', $replace_tag ); |
|
585 | + $replace_tag = apply_filters('autoptimize_filter_js_replacetag', $replace_tag); |
|
586 | 586 | |
587 | - if ( strlen( $this->jscode ) > 0 ) { |
|
588 | - $this->inject_in_html( $bodyreplacement, $replace_tag ); |
|
587 | + if (strlen($this->jscode) > 0) { |
|
588 | + $this->inject_in_html($bodyreplacement, $replace_tag); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | // Restore comments. |
592 | - $this->content = $this->restore_comments( $this->content ); |
|
592 | + $this->content = $this->restore_comments($this->content); |
|
593 | 593 | |
594 | 594 | // Restore IE hacks. |
595 | - $this->content = $this->restore_iehacks( $this->content ); |
|
595 | + $this->content = $this->restore_iehacks($this->content); |
|
596 | 596 | |
597 | 597 | // Restore noptimize. |
598 | - $this->content = $this->restore_noptimize( $this->content ); |
|
598 | + $this->content = $this->restore_noptimize($this->content); |
|
599 | 599 | |
600 | 600 | // Return the modified HTML. |
601 | 601 | return $this->content; |
@@ -606,34 +606,34 @@ discard block |
||
606 | 606 | * |
607 | 607 | * @param string $tag JS tag. |
608 | 608 | */ |
609 | - private function ismergeable( $tag ) |
|
609 | + private function ismergeable($tag) |
|
610 | 610 | { |
611 | - if ( empty( $tag ) || ! $this->aggregate ) { |
|
611 | + if (empty($tag) || !$this->aggregate) { |
|
612 | 612 | return false; |
613 | 613 | } |
614 | 614 | |
615 | - if ( ! empty( $this->whitelist ) ) { |
|
616 | - foreach ( $this->whitelist as $match ) { |
|
617 | - if ( false !== strpos( $tag, $match ) ) { |
|
615 | + if (!empty($this->whitelist)) { |
|
616 | + foreach ($this->whitelist as $match) { |
|
617 | + if (false !== strpos($tag, $match)) { |
|
618 | 618 | return true; |
619 | 619 | } |
620 | 620 | } |
621 | 621 | // No match with whitelist. |
622 | 622 | return false; |
623 | 623 | } else { |
624 | - foreach ( $this->domove as $match ) { |
|
625 | - if ( false !== strpos( $tag, $match ) ) { |
|
624 | + foreach ($this->domove as $match) { |
|
625 | + if (false !== strpos($tag, $match)) { |
|
626 | 626 | // Matched something. |
627 | 627 | return false; |
628 | 628 | } |
629 | 629 | } |
630 | 630 | |
631 | - if ( $this->movetolast( $tag ) ) { |
|
631 | + if ($this->movetolast($tag)) { |
|
632 | 632 | return false; |
633 | 633 | } |
634 | 634 | |
635 | - foreach ( $this->dontmove as $match ) { |
|
636 | - if ( false !== strpos( $tag, $match ) ) { |
|
635 | + foreach ($this->dontmove as $match) { |
|
636 | + if (false !== strpos($tag, $match)) { |
|
637 | 637 | // Matched something. |
638 | 638 | return false; |
639 | 639 | } |
@@ -649,25 +649,25 @@ discard block |
||
649 | 649 | * |
650 | 650 | * @param string $tag tag to check for blacklist (exclusions). |
651 | 651 | */ |
652 | - private function ismovable( $tag ) |
|
652 | + private function ismovable($tag) |
|
653 | 653 | { |
654 | - if ( empty( $tag ) || true !== $this->include_inline || apply_filters( 'autoptimize_filter_js_unmovable', true ) ) { |
|
654 | + if (empty($tag) || true !== $this->include_inline || apply_filters('autoptimize_filter_js_unmovable', true)) { |
|
655 | 655 | return false; |
656 | 656 | } |
657 | 657 | |
658 | - foreach ( $this->domove as $match ) { |
|
659 | - if ( false !== strpos( $tag, $match ) ) { |
|
658 | + foreach ($this->domove as $match) { |
|
659 | + if (false !== strpos($tag, $match)) { |
|
660 | 660 | // Matched something. |
661 | 661 | return true; |
662 | 662 | } |
663 | 663 | } |
664 | 664 | |
665 | - if ( $this->movetolast( $tag ) ) { |
|
665 | + if ($this->movetolast($tag)) { |
|
666 | 666 | return true; |
667 | 667 | } |
668 | 668 | |
669 | - foreach ( $this->dontmove as $match ) { |
|
670 | - if ( false !== strpos( $tag, $match ) ) { |
|
669 | + foreach ($this->dontmove as $match) { |
|
670 | + if (false !== strpos($tag, $match)) { |
|
671 | 671 | // Matched something. |
672 | 672 | return false; |
673 | 673 | } |
@@ -677,14 +677,14 @@ discard block |
||
677 | 677 | return true; |
678 | 678 | } |
679 | 679 | |
680 | - private function movetolast( $tag ) |
|
680 | + private function movetolast($tag) |
|
681 | 681 | { |
682 | - if ( empty( $tag ) ) { |
|
682 | + if (empty($tag)) { |
|
683 | 683 | return false; |
684 | 684 | } |
685 | 685 | |
686 | - foreach ( $this->domovelast as $match ) { |
|
687 | - if ( false !== strpos( $tag, $match ) ) { |
|
686 | + foreach ($this->domovelast as $match) { |
|
687 | + if (false !== strpos($tag, $match)) { |
|
688 | 688 | // Matched, return true. |
689 | 689 | return true; |
690 | 690 | } |
@@ -704,12 +704,12 @@ discard block |
||
704 | 704 | * @param string $js_path Path to JS file. |
705 | 705 | * @return bool |
706 | 706 | */ |
707 | - private function can_inject_late( $js_path ) { |
|
708 | - $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false ); |
|
709 | - if ( true !== $this->inject_min_late ) { |
|
707 | + private function can_inject_late($js_path) { |
|
708 | + $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false); |
|
709 | + if (true !== $this->inject_min_late) { |
|
710 | 710 | // late-inject turned off. |
711 | 711 | return false; |
712 | - } elseif ( ( false === strpos( $js_path, 'min.js' ) ) && ( false === strpos( $js_path, 'wp-includes/js/jquery/jquery.js' ) ) && ( str_replace( $consider_minified_array, '', $js_path ) === $js_path ) ) { |
|
712 | + } elseif ((false === strpos($js_path, 'min.js')) && (false === strpos($js_path, 'wp-includes/js/jquery/jquery.js')) && (str_replace($consider_minified_array, '', $js_path) === $js_path)) { |
|
713 | 713 | // file not minified based on filename & filter. |
714 | 714 | return false; |
715 | 715 | } else { |
@@ -736,32 +736,32 @@ discard block |
||
736 | 736 | * |
737 | 737 | * @return bool|string Url pointing to the minified js file or false. |
738 | 738 | */ |
739 | - public function minify_single( $filepath, $cache_miss = false ) |
|
739 | + public function minify_single($filepath, $cache_miss = false) |
|
740 | 740 | { |
741 | - $contents = $this->prepare_minify_single( $filepath ); |
|
741 | + $contents = $this->prepare_minify_single($filepath); |
|
742 | 742 | |
743 | - if ( empty( $contents ) ) { |
|
743 | + if (empty($contents)) { |
|
744 | 744 | return false; |
745 | 745 | } |
746 | 746 | |
747 | 747 | // Check cache. |
748 | - $hash = 'single_' . md5( $contents ); |
|
749 | - $cache = new autoptimizeCache( $hash, 'js' ); |
|
748 | + $hash = 'single_'.md5($contents); |
|
749 | + $cache = new autoptimizeCache($hash, 'js'); |
|
750 | 750 | |
751 | 751 | // If not in cache already, minify... |
752 | - if ( ! $cache->check() || $cache_miss ) { |
|
753 | - $contents = trim( JSMin::minify( $contents ) ); |
|
752 | + if (!$cache->check() || $cache_miss) { |
|
753 | + $contents = trim(JSMin::minify($contents)); |
|
754 | 754 | |
755 | 755 | // Check if minified cache content is empty. |
756 | - if ( empty( $contents ) ) { |
|
756 | + if (empty($contents)) { |
|
757 | 757 | return false; |
758 | 758 | } |
759 | 759 | |
760 | 760 | // Store in cache. |
761 | - $cache->cache( $contents, 'text/javascript' ); |
|
761 | + $cache->cache($contents, 'text/javascript'); |
|
762 | 762 | } |
763 | 763 | |
764 | - $url = $this->build_minify_single_url( $cache ); |
|
764 | + $url = $this->build_minify_single_url($cache); |
|
765 | 765 | |
766 | 766 | return $url; |
767 | 767 | } |
@@ -12,29 +12,29 @@ |
||
12 | 12 | .ao_settings_div {background: white;border: 1px solid #ccc;padding: 1px 15px;margin: 15px 10px 10px 0;} |
13 | 13 | .ao_settings_div .form-table th {font-weight: normal;} |
14 | 14 | </style> |
15 | - <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script> |
|
15 | + <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script> |
|
16 | 16 | <ul id="explain-panel"> |
17 | 17 | <div class="ao_settings_div"> |
18 | 18 | <?php |
19 | 19 | $ccss_explanation = ''; |
20 | 20 | |
21 | 21 | // get the HTML with the explanation of what critical CSS is. |
22 | - if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) { |
|
23 | - $ccss_explanation = get_transient( 'ao_ccss_explain' ); |
|
24 | - if ( empty( $ccss_explanation ) ) { |
|
25 | - $ccss_expl_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_ccss_explain_i18n.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION ); |
|
26 | - if ( ! is_wp_error( $ccss_expl_resp ) ) { |
|
27 | - if ( '200' == wp_remote_retrieve_response_code( $ccss_expl_resp ) ) { |
|
28 | - $ccss_explanation = wp_kses_post( wp_remote_retrieve_body( $ccss_expl_resp ) ); |
|
29 | - set_transient( 'ao_ccss_explain', $ccss_explanation, WEEK_IN_SECONDS ); |
|
22 | + if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) { |
|
23 | + $ccss_explanation = get_transient('ao_ccss_explain'); |
|
24 | + if (empty($ccss_explanation)) { |
|
25 | + $ccss_expl_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_ccss_explain_i18n.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION); |
|
26 | + if (!is_wp_error($ccss_expl_resp)) { |
|
27 | + if ('200' == wp_remote_retrieve_response_code($ccss_expl_resp)) { |
|
28 | + $ccss_explanation = wp_kses_post(wp_remote_retrieve_body($ccss_expl_resp)); |
|
29 | + set_transient('ao_ccss_explain', $ccss_explanation, WEEK_IN_SECONDS); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | 35 | // placeholder text in case HTML is empty. |
36 | - if ( empty( $ccss_explanation ) ) { |
|
37 | - $ccss_explanation = __( '<h2>Fix render-blocking CSS!</h2><p>Significantly improve your first-paint times by making CSS non-render-blocking.</p><p>The next step is to sign up at <a href="https://criticalcss.com/?aff=1" target="_blank">https://criticalcss.com</a> (this is a premium service, priced 2 GBP/month for membership and 5 GBP/month per domain) <strong>and get the API key, which you can copy from <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">the API-keys page</a></strong> and paste below.</p><p>If you have any questions or need support, head on over to <a href="https://wordpress.org/support/plugin/autoptimize" target="_blank">our support forum</a> and we\'ll help you get up and running in no time!</p>', 'autoptimize' ); |
|
36 | + if (empty($ccss_explanation)) { |
|
37 | + $ccss_explanation = __('<h2>Fix render-blocking CSS!</h2><p>Significantly improve your first-paint times by making CSS non-render-blocking.</p><p>The next step is to sign up at <a href="https://criticalcss.com/?aff=1" target="_blank">https://criticalcss.com</a> (this is a premium service, priced 2 GBP/month for membership and 5 GBP/month per domain) <strong>and get the API key, which you can copy from <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">the API-keys page</a></strong> and paste below.</p><p>If you have any questions or need support, head on over to <a href="https://wordpress.org/support/plugin/autoptimize" target="_blank">our support forum</a> and we\'ll help you get up and running in no time!</p>', 'autoptimize'); |
|
38 | 38 | } else { |
39 | 39 | // we were able to fetch the explenation, so add the JS to show correct language. |
40 | 40 | $ccss_explanation .= "<script>jQuery('.ao_i18n').hide();d=document;lang=d.getElementsByTagName('html')[0].getAttribute('lang').substring(0,2);if(d.getElementById(lang)!= null){jQuery('#'+lang).show();}else{jQuery('#default').show();}</script>"; |