09b52d43 by Jeff Balicki

ddd

1 parent 4c19e6fe
...@@ -6,7 +6,7 @@ Description: Improve your speed score on GTmetrix, Pingdom Tools and Google Page ...@@ -6,7 +6,7 @@ Description: Improve your speed score on GTmetrix, Pingdom Tools and Google Page
6 Author: Raul Peixoto 6 Author: Raul Peixoto
7 Author URI: http://fastvelocity.com 7 Author URI: http://fastvelocity.com
8 Text Domain: fast-velocity-minify 8 Text Domain: fast-velocity-minify
9 Version: 3.2.2 9 Version: 3.2.6
10 License: GPL2 10 License: GPL2
11 11
12 ------------------------------------------------------------------------ 12 ------------------------------------------------------------------------
......
...@@ -84,6 +84,49 @@ function fvm_check_misconfiguration() { ...@@ -84,6 +84,49 @@ function fvm_check_misconfiguration() {
84 84
85 } 85 }
86 86
87 # check if our tables exist, and do maintenance once a day
88 $fvm_table_checker = get_transient('fvm_table_checker');
89 $fvm_table_checker = false;
90 if ($fvm_table_checker === false) {
91
92 # test if at least one table exists
93 global $wpdb;
94 if(!is_null($wpdb)) {
95 $sqla_table_name = $wpdb->prefix . 'fvm_cache';
96 if (!$wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $sqla_table_name)) === $sqla_table_name) {
97 fvm_plugin_activate();
98 }
99 }
100
101 # daily maintenance
102 try {
103
104 if(!is_null($wpdb)) {
105
106 # limit cache table to 20k records
107 $lim = 20000;
108 $res = $wpdb->get_row("SELECT MAX(id) as maxid FROM ".$wpdb->prefix."fvm_cache");
109 if(isset($res->maxid) && intval($res->maxid) > $lim) {
110 $wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."fvm_cache WHERE id < %d LIMIT 1", (intval($res->maxid) - $lim)));
111 }
112
113 # limit logs table to 500 records
114 $lim = 500;
115 $res = $wpdb->get_row("SELECT MAX(id) as maxid FROM ".$wpdb->prefix."fvm_logs");
116 if(isset($res->maxid) && intval($res->maxid) > $lim) {
117 $wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."fvm_logs WHERE id < %d LIMIT 1", (intval($res->maxid) - $lim)));
118 }
119
120 }
121
122 } catch (Exception $e) {
123 error_log('Error: '.$e->getMessage(), 0);
124 }
125
126
127 }
128
129
87 } catch (Exception $e) { 130 } catch (Exception $e) {
88 error_log('Caught exception (fvm_initialize_database): '.$e->getMessage(), 0); 131 error_log('Caught exception (fvm_initialize_database): '.$e->getMessage(), 0);
89 } 132 }
...@@ -207,25 +250,30 @@ function fvm_add_admin_menu() { ...@@ -207,25 +250,30 @@ function fvm_add_admin_menu() {
207 # print admin notices when needed (json) 250 # print admin notices when needed (json)
208 function fvm_show_admin_notice_from_transient() { 251 function fvm_show_admin_notice_from_transient() {
209 if(current_user_can('manage_options')) { 252 if(current_user_can('manage_options')) {
210 $inf = get_transient('fvm_admin_notice'); 253 $inf = get_transient('fvm_admin_notice_'.get_current_user_id());
211 if($inf != false && !empty($inf)) {
212 $jsonarr = json_decode($inf, true);
213 if(!is_null($jsonarr) && is_array($jsonarr)){
214 254
215 # add all 255 # show transient after the redirect
216 $jsonarr = array_unique($jsonarr); 256 if($inf != false && !empty($inf)) {
217 foreach ($jsonarr as $notice) { 257 $notices = json_decode($inf, true);
218 add_settings_error( 'fvm_admin_notice', 'fvm_admin_notice', 'FVM: '.$notice, 'info' ); 258 if(!is_null($notices) && is_array($notices)){
259
260 # consolidate messages
261 $notices = array_unique($notices);
262 if(count($notices) > 1) {
263 $msg = '<div class="fvm-info-list"><h3>FVM</h3><ul>';
264 foreach ($notices as $notice) { $msg.= "<li>$notice</li>"; }
265 $msg.= '</ul></div>';
266 add_settings_error( 'fvm_admin_notice', 'fvm_admin_notice', $msg, 'info' );
267 } else {
268 $msg = 'FVM: '.implode(PHP_EOL, $notices);
269 add_settings_error( 'fvm_admin_notice', 'fvm_admin_notice', $msg, 'info' );
219 } 270 }
220 271
221 # output on other pages
222 if(!isset($_GET['page']) || (isset($_GET['page']) && $_GET['page'] != 'fvm')) {
223 settings_errors( 'fvm_admin_notice' );
224 }
225 } 272 }
226 273
227 # remove 274 # delete
228 delete_transient('fvm_admin_notice'); 275 delete_transient('fvm_admin_notice_'.get_current_user_id());
276
229 } 277 }
230 } 278 }
231 } 279 }
...@@ -301,47 +349,66 @@ function fvm_get_logs_callback() { ...@@ -301,47 +349,66 @@ function fvm_get_logs_callback() {
301 register_activation_hook($fvm_var_file, 'fvm_plugin_activate'); 349 register_activation_hook($fvm_var_file, 'fvm_plugin_activate');
302 function fvm_plugin_activate() { 350 function fvm_plugin_activate() {
303 351
352 # defauls
304 global $wpdb; 353 global $wpdb;
305 if(is_null($wpdb)) { return false; } 354 if(is_null($wpdb)) { return false; }
306 355 $charset_collate = $wpdb->get_charset_collate();
307 # defauls 356 $sqla_table_name = $wpdb->prefix . 'fvm_cache';
308 $sql = array(); 357 $sqlb_table_name = $wpdb->prefix . 'fvm_logs';
309 $wpdb_collate = $wpdb->collate;
310 358
311 # create cache table 359 # create cache table
312 $sqla_table_name = $wpdb->prefix . 'fvm_cache'; 360 $sqla = "CREATE TABLE {$sqla_table_name} (
313 $sqla = "CREATE TABLE IF NOT EXISTS {$sqla_table_name} ( 361 id bigint(20) unsigned NOT NULL auto_increment ,
314 `id` bigint(20) unsigned NOT NULL auto_increment , 362 uid varchar(64) NOT NULL,
315 `uid` varchar(64) NOT NULL, 363 date bigint(10) unsigned NOT NULL,
316 `date` bigint(10) unsigned NOT NULL, 364 type varchar(3) NOT NULL,
317 `type` varchar(3) NOT NULL, 365 content mediumtext NOT NULL,
318 `content` mediumtext NOT NULL, 366 meta mediumtext NOT NULL,
319 `meta` mediumtext NOT NULL,
320 PRIMARY KEY (id), 367 PRIMARY KEY (id),
321 UNIQUE KEY uid (uid), 368 UNIQUE KEY uid (uid),
322 KEY date (date), KEY type (type) 369 KEY date (date), KEY type (type)
323 ) 370 ) $charset_collate;";
324 COLLATE {$wpdb_collate}";
325 371
326 # create logs table 372 # create logs table
327 $sqlb_table_name = $wpdb->prefix . 'fvm_logs'; 373 $sqlb = "CREATE TABLE {$sqlb_table_name} (
328 $sqlb = "CREATE TABLE IF NOT EXISTS {$sqlb_table_name} ( 374 id bigint(20) unsigned NOT NULL auto_increment,
329 `id` bigint(20) unsigned NOT NULL auto_increment, 375 uid varchar(64) NOT NULL,
330 `uid` varchar(64) NOT NULL, 376 date bigint(10) unsigned NOT NULL,
331 `date` bigint(10) unsigned NOT NULL, 377 type varchar(10) NOT NULL,
332 `type` varchar(10) NOT NULL, 378 msg mediumtext NOT NULL,
333 `msg` mediumtext NOT NULL, 379 meta mediumtext NOT NULL,
334 `meta` mediumtext NOT NULL,
335 PRIMARY KEY (id), 380 PRIMARY KEY (id),
336 UNIQUE KEY uid (uid), 381 UNIQUE KEY uid (uid),
337 KEY date (date), 382 KEY date (date),
338 KEY type (type) 383 KEY type (type)
339 ) 384 ) $charset_collate;";
340 COLLATE {$wpdb_collate}";
341 385
342 # run sql 386 # run sql
343 $wpdb->query($sqla); 387 # https://developer.wordpress.org/reference/functions/dbdelta/
344 $wpdb->query($sqlb); 388 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
389 dbDelta( $sqla );
390 dbDelta( $sqlb );
391
392 # test if at least one table exists
393 if (!$wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $sqla_table_name)) === $sqla_table_name) {
394
395 # log
396 $err = 'An error occurred when trying to create the database tables';
397 error_log($err);
398
399 # alert
400 if(is_admin()) {
401 $notices = array($err);
402 set_transient('fvm_admin_notice_'.get_current_user_id(), json_encode($notices), 10);
403 }
404
405 # try again in 1 hour
406 set_transient('fvm_table_checker', true, HOUR_IN_SECONDS);
407
408 } else {
409 # success, but check again tomorrow
410 set_transient('fvm_table_checker', true, DAY_IN_SECONDS);
411 }
345 412
346 } 413 }
347 414
...@@ -350,6 +417,9 @@ function fvm_plugin_activate() { ...@@ -350,6 +417,9 @@ function fvm_plugin_activate() {
350 register_deactivation_hook($fvm_var_file, 'fvm_plugin_deactivate'); 417 register_deactivation_hook($fvm_var_file, 'fvm_plugin_deactivate');
351 function fvm_plugin_deactivate() { 418 function fvm_plugin_deactivate() {
352 419
420 # process cache settings
421 fvm_purge_static_files();
422
353 global $wpdb; 423 global $wpdb;
354 if(is_null($wpdb)) { return false; } 424 if(is_null($wpdb)) { return false; }
355 425
...@@ -358,14 +428,15 @@ function fvm_plugin_deactivate() { ...@@ -358,14 +428,15 @@ function fvm_plugin_deactivate() {
358 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}fvm_cache"); 428 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}fvm_cache");
359 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}fvm_logs"); 429 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}fvm_logs");
360 430
361 # process cache settings
362 fvm_purge_static_files();
363
364 } 431 }
365 432
366 # run during uninstall 433 # run during uninstall
367 register_uninstall_hook($fvm_var_file, 'fvm_plugin_uninstall'); 434 register_uninstall_hook($fvm_var_file, 'fvm_plugin_uninstall');
368 function fvm_plugin_uninstall() { 435 function fvm_plugin_uninstall() {
436
437 # process cache settings
438 fvm_purge_static_files();
439
369 global $wpdb; 440 global $wpdb;
370 if(is_null($wpdb)) { return false; } 441 if(is_null($wpdb)) { return false; }
371 442
...@@ -375,9 +446,6 @@ function fvm_plugin_uninstall() { ...@@ -375,9 +446,6 @@ function fvm_plugin_uninstall() {
375 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}fvm_cache"); 446 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}fvm_cache");
376 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}fvm_logs"); 447 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}fvm_logs");
377 448
378 # process cache settings
379 fvm_purge_static_files();
380
381 } 449 }
382 450
383 451
......
...@@ -47,12 +47,13 @@ function fvm_process_page($html) { ...@@ -47,12 +47,13 @@ function fvm_process_page($html) {
47 47
48 # get html into an object 48 # get html into an object
49 # https://simplehtmldom.sourceforge.io/manual.htm 49 # https://simplehtmldom.sourceforge.io/manual.htm
50 $html_object = str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 50 $html_object = fvm_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
51 51
52 # return early if html is not an object, or overwrite html into an object for processing 52 # return early if html is not an object, or overwrite html into an object for processing
53 if (!is_object($html_object)) { 53 if (!is_object($html_object)) {
54 return $html . '<!-- simplehtmldom failed to process the html -->'; 54 return $html . '<!-- simplehtmldom failed to process the html -->';
55 } else { 55 } else {
56 $html_src = $html;
56 $html = $html_object; 57 $html = $html_object;
57 } 58 }
58 59
...@@ -66,13 +67,16 @@ function fvm_process_page($html) { ...@@ -66,13 +67,16 @@ function fvm_process_page($html) {
66 $htmljsheader = array(); 67 $htmljsheader = array();
67 $htmljsdefer = array(); 68 $htmljsdefer = array();
68 69
70 # only error possible for now
71 $fvm_error = PHP_EOL . '<!-- ['.date('r').'] FVM has no write access for CSS / JS cache files under '. fvm_get_cache_location()['ch_url'] . ' -->'. PHP_EOL;
72
69 73
70 # collect all link preload headers, skip amp 74 # collect all link preload headers, skip amp
71 if(fvm_is_amp_page() !== true) { 75 if(fvm_is_amp_page() !== true) {
72 76
73 # skip on web stories 77 # skip on web stories
74 if(count($html->find('script[src*=cdn.ampproject.org]')) > 0) { 78 if(count($html->find('script[src*=cdn.ampproject.org]')) > 0) {
75 return $html . '<!-- FVM does not support AMP -->'; 79 return $html_src . DIRECTORY_SEPARATOR . '<!-- FVM ['.date('r').'] does not support AMP -->';
76 } 80 }
77 81
78 # add other preloads 82 # add other preloads
...@@ -188,7 +192,7 @@ function fvm_process_page($html) { ...@@ -188,7 +192,7 @@ function fvm_process_page($html) {
188 192
189 # extract fonts and icons 193 # extract fonts and icons
190 if(isset($fvm_settings['css']['fonts']) && $fvm_settings['css']['fonts'] == true) { 194 if(isset($fvm_settings['css']['fonts']) && $fvm_settings['css']['fonts'] == true) {
191 $extract_fonts_arr = fvm_extract_fonts($css['code']); 195 $extract_fonts_arr = fvm_extract_fonts($css['code'], $href);
192 $css_lowpriority_code.= '/* '.$href.' */'. PHP_EOL . $extract_fonts_arr['fonts']; 196 $css_lowpriority_code.= '/* '.$href.' */'. PHP_EOL . $extract_fonts_arr['fonts'];
193 $css_code = $extract_fonts_arr['code']; 197 $css_code = $extract_fonts_arr['code'];
194 } else { 198 } else {
...@@ -259,7 +263,7 @@ function fvm_process_page($html) { ...@@ -259,7 +263,7 @@ function fvm_process_page($html) {
259 263
260 # extract fonts and icons 264 # extract fonts and icons
261 if(isset($fvm_settings['css']['fonts']) && $fvm_settings['css']['fonts'] == true) { 265 if(isset($fvm_settings['css']['fonts']) && $fvm_settings['css']['fonts'] == true) {
262 $extract_fonts_arr = fvm_extract_fonts($css['code']); 266 $extract_fonts_arr = fvm_extract_fonts($css['code'], $href);
263 $css_lowpriority_code.= '/* '.$href.' */'. PHP_EOL . $extract_fonts_arr['fonts']; 267 $css_lowpriority_code.= '/* '.$href.' */'. PHP_EOL . $extract_fonts_arr['fonts'];
264 $css_code = $extract_fonts_arr['code']; 268 $css_code = $extract_fonts_arr['code'];
265 } else { 269 } else {
...@@ -277,6 +281,9 @@ function fvm_process_page($html) { ...@@ -277,6 +281,9 @@ function fvm_process_page($html) {
277 281
278 # generate url 282 # generate url
279 $ind_css_url = fvm_generate_min_url($href, $css['tkey'], 'css', $css_code); 283 $ind_css_url = fvm_generate_min_url($href, $css['tkey'], 'css', $css_code);
284 if($ind_css_url === false) {
285 return $html_src . $fvm_error;
286 }
280 287
281 # cdn 288 # cdn
282 if(isset($fvm_settings['cdn']['cssok']) && $fvm_settings['cdn']['cssok'] == true) { 289 if(isset($fvm_settings['cdn']['cssok']) && $fvm_settings['cdn']['cssok'] == true) {
...@@ -402,6 +409,9 @@ function fvm_process_page($html) { ...@@ -402,6 +409,9 @@ function fvm_process_page($html) {
402 409
403 # generate url 410 # generate url
404 $css_fonts_url = fvm_generate_min_url('fonts', $tkey, 'css', $css_lowpriority_code); 411 $css_fonts_url = fvm_generate_min_url('fonts', $tkey, 'css', $css_lowpriority_code);
412 if($css_fonts_url === false) {
413 return $html_src . $fvm_error;
414 }
405 415
406 # cdn 416 # cdn
407 if(isset($fvm_settings['cdn']['cssok']) && $fvm_settings['cdn']['cssok'] == true) { 417 if(isset($fvm_settings['cdn']['cssok']) && $fvm_settings['cdn']['cssok'] == true) {
...@@ -435,6 +445,9 @@ function fvm_process_page($html) { ...@@ -435,6 +445,9 @@ function fvm_process_page($html) {
435 445
436 # url, preload, add 446 # url, preload, add
437 $merged_css_url = fvm_generate_min_url('combined', $tkey, 'css', $merged_css); 447 $merged_css_url = fvm_generate_min_url('combined', $tkey, 'css', $merged_css);
448 if($merged_css_url === false) {
449 return $html_src . $fvm_error;
450 }
438 451
439 # cdn 452 # cdn
440 if(isset($fvm_settings['cdn']['cssok']) && $fvm_settings['cdn']['cssok'] == true) { 453 if(isset($fvm_settings['cdn']['cssok']) && $fvm_settings['cdn']['cssok'] == true) {
...@@ -708,6 +721,9 @@ function fvm_process_page($html) { ...@@ -708,6 +721,9 @@ function fvm_process_page($html) {
708 721
709 # generate url 722 # generate url
710 $ind_js_url = fvm_generate_min_url($tag->src, $js['tkey'], 'js', $js['code']); 723 $ind_js_url = fvm_generate_min_url($tag->src, $js['tkey'], 'js', $js['code']);
724 if($ind_js_url === false) {
725 return $html_src . $fvm_error;
726 }
711 727
712 # cdn 728 # cdn
713 if(isset($fvm_settings['cdn']['jsok']) && $fvm_settings['cdn']['jsok'] == true) { 729 if(isset($fvm_settings['cdn']['jsok']) && $fvm_settings['cdn']['jsok'] == true) {
...@@ -759,6 +775,9 @@ function fvm_process_page($html) { ...@@ -759,6 +775,9 @@ function fvm_process_page($html) {
759 775
760 # generate url 776 # generate url
761 $ind_js_url = fvm_generate_min_url($tag->src, $js['tkey'], 'js', $js['code']); 777 $ind_js_url = fvm_generate_min_url($tag->src, $js['tkey'], 'js', $js['code']);
778 if($ind_js_url === false) {
779 return $html_src . $fvm_error;
780 }
762 781
763 # cdn 782 # cdn
764 if(isset($fvm_settings['cdn']['jsok']) && $fvm_settings['cdn']['jsok'] == true) { 783 if(isset($fvm_settings['cdn']['jsok']) && $fvm_settings['cdn']['jsok'] == true) {
...@@ -885,6 +904,9 @@ function fvm_process_page($html) { ...@@ -885,6 +904,9 @@ function fvm_process_page($html) {
885 904
886 # generate url 905 # generate url
887 $merged_js_url = fvm_generate_min_url('combined', $tkey, 'js', $merged_js); 906 $merged_js_url = fvm_generate_min_url('combined', $tkey, 'js', $merged_js);
907 if($merged_js_url === false) {
908 return $html_src . $fvm_error;
909 }
888 910
889 # cdn 911 # cdn
890 if(isset($fvm_settings['cdn']['jsok']) && $fvm_settings['cdn']['jsok'] == true) { 912 if(isset($fvm_settings['cdn']['jsok']) && $fvm_settings['cdn']['jsok'] == true) {
...@@ -910,6 +932,9 @@ function fvm_process_page($html) { ...@@ -910,6 +932,9 @@ function fvm_process_page($html) {
910 932
911 # generate url 933 # generate url
912 $merged_js_url = fvm_generate_min_url('combined', $tkey, 'js', $merged_js); 934 $merged_js_url = fvm_generate_min_url('combined', $tkey, 'js', $merged_js);
935 if($merged_js_url === false) {
936 return $html_src . $fvm_error;
937 }
913 938
914 # cdn 939 # cdn
915 if(isset($fvm_settings['cdn']['jsok']) && $fvm_settings['cdn']['jsok'] == true) { 940 if(isset($fvm_settings['cdn']['jsok']) && $fvm_settings['cdn']['jsok'] == true) {
......
...@@ -286,6 +286,21 @@ ...@@ -286,6 +286,21 @@
286 </div> 286 </div>
287 287
288 <div style="height: 20px;"></div> 288 <div style="height: 20px;"></div>
289 <h2 class="title">Query String Settings</h2>
290
291 <div class="accordion">
292 <h3>Allowed Query Strings</h3>
293 <div>
294 <p><strong>Notes:</strong></p>
295 <p>This allows processing of CSS, HTML and JS when the url contains certain query strings, but note that if there are other query strings found on the same url not on the list of allowed query strings, it will still not process the url.</p>
296 <p><strong>Example Settings:</strong></p>
297 <p class="fvm-code-full">
298 utm_source<br />utm_campaign<br />utm_medium<br />utm_expid<br />utm_term<br />utm_content<br />fb_action_ids<br />fb_action_types<br />fb_source<br />fbclid<br />_ga<br />gclid<br />age-verified<br />usqp<br />cn-reloaded<br />lang<br />s<br />permalink_name<br />lp-variation-id<br />author<br />author_name<br />cat<br />category_name<br />order<br />orderby<br />p<br />page_id<br />page<br />paged<br />post_type<br />posts<br />s<br />search<br />taxonomy<br />tag<br />tag_id<br />term
299 </p>
300 </div>
301 </div>
302
303 <div style="height: 20px;"></div>
289 <h2 class="title">User Settings</h2> 304 <h2 class="title">User Settings</h2>
290 305
291 <div class="accordion"> 306 <div class="accordion">
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
22 <fieldset> 22 <fieldset>
23 <label for="fvm_settings_cache_min_instant_purge"> 23 <label for="fvm_settings_cache_min_instant_purge">
24 <input name="fvm_settings[cache][min_instant_purge]" type="checkbox" id="fvm_settings_cache_min_instant_purge" value="1" <?php echo fvm_get_settings_checkbox(fvm_get_settings_value($fvm_settings, 'cache', 'min_instant_purge')); ?>> 24 <input name="fvm_settings[cache][min_instant_purge]" type="checkbox" id="fvm_settings_cache_min_instant_purge" value="1" <?php echo fvm_get_settings_checkbox(fvm_get_settings_value($fvm_settings, 'cache', 'min_instant_purge')); ?>>
25 <?php _e( 'Purge Minified CSS/JS files instantly', 'fast-velocity-minify' ); ?> <span class="note-info">[ <?php _e( 'Cache files are only deleted if older than 24h by default, for compatibility with certain hosting providers.', 'fast-velocity-minify' ); ?> ]</span></label> 25 <?php _e( 'Purge Minified CSS/JS files instantly', 'fast-velocity-minify' ); ?> <span class="note-info">[ <?php _e( 'CSS & JS cache files are preserved for 7 days by default, for better compatibility with certain hosting providers.', 'fast-velocity-minify' ); ?> ]</span></label>
26 <br /> 26 <br />
27 27
28 </fieldset></td> 28 </fieldset></td>
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
160 <td><fieldset> 160 <td><fieldset>
161 <label for="fvm_settings_css_remove"><span class="fvm-bold-green fvm-rowintro"><?php _e( 'Remove the following CSS files', 'fast-velocity-minify' ); ?></span></label> 161 <label for="fvm_settings_css_remove"><span class="fvm-bold-green fvm-rowintro"><?php _e( 'Remove the following CSS files', 'fast-velocity-minify' ); ?></span></label>
162 <p><textarea name="fvm_settings[css][remove]" rows="7" cols="50" id="fvm_settings_css_remove" class="large-text code" placeholder="ex: fonts.googleapis.com"><?php echo fvm_get_settings_value($fvm_settings, 'css', 'remove'); ?></textarea></p> 162 <p><textarea name="fvm_settings[css][remove]" rows="7" cols="50" id="fvm_settings_css_remove" class="large-text code" placeholder="ex: fonts.googleapis.com"><?php echo fvm_get_settings_value($fvm_settings, 'css', 'remove'); ?></textarea></p>
163 <p class="description">[ <?php _e( 'This will allow you to remove unwanted CSS files by URL path from the frontend', 'fast-velocity-minify' ); ?> ]</p> 163 <p class="description">[ <?php _e( 'This will allow you to remove unwanted CSS files by URI path from the frontend', 'fast-velocity-minify' ); ?> ]</p>
164 <p class="description">[ <?php _e( 'Will match using <code>PHP stripos</code> against the <code>href attribute</code> on the <code>link tag</code>', 'fast-velocity-minify' ); ?> ]</p> 164 <p class="description">[ <?php _e( 'Will match using <code>PHP stripos</code> against the <code>href attribute</code> on the <code>link tag</code>', 'fast-velocity-minify' ); ?> ]</p>
165 </fieldset></td> 165 </fieldset></td>
166 </tr> 166 </tr>
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
170 <td><fieldset> 170 <td><fieldset>
171 <label for="fvm_settings_css_async"><span class="fvm-bold-green fvm-rowintro"><?php _e( 'Async the following CSS files', 'fast-velocity-minify' ); ?></span></label> 171 <label for="fvm_settings_css_async"><span class="fvm-bold-green fvm-rowintro"><?php _e( 'Async the following CSS files', 'fast-velocity-minify' ); ?></span></label>
172 <p><textarea name="fvm_settings[css][async]" rows="7" cols="50" id="fvm_settings_css_async" class="large-text code" placeholder="ex: /plugins/something/assets/low-priority.css"><?php echo fvm_get_settings_value($fvm_settings, 'css', 'async'); ?></textarea></p> 172 <p><textarea name="fvm_settings[css][async]" rows="7" cols="50" id="fvm_settings_css_async" class="large-text code" placeholder="ex: /plugins/something/assets/low-priority.css"><?php echo fvm_get_settings_value($fvm_settings, 'css', 'async'); ?></textarea></p>
173 <p class="description">[ <?php _e( 'This will allow you to remove unwanted CSS files by URL path from the frontend', 'fast-velocity-minify' ); ?> ]</p> 173 <p class="description">[ <?php _e( 'This will allow you to Async CSS files by URI path from the frontend', 'fast-velocity-minify' ); ?> ]</p>
174 <p class="description">[ <?php _e( 'Will match using <code>PHP stripos</code> against the <code>href attribute</code> on the <code>link tag</code>', 'fast-velocity-minify' ); ?> ]</p> 174 <p class="description">[ <?php _e( 'Will match using <code>PHP stripos</code> against the <code>href attribute</code> on the <code>link tag</code>', 'fast-velocity-minify' ); ?> ]</p>
175 </fieldset></td> 175 </fieldset></td>
176 </tr> 176 </tr>
...@@ -364,6 +364,22 @@ www.googletagmanager.com/gtm.js"><?php echo fvm_get_settings_value($fvm_settings ...@@ -364,6 +364,22 @@ www.googletagmanager.com/gtm.js"><?php echo fvm_get_settings_value($fvm_settings
364 364
365 365
366 <div style="height: 60px;"></div> 366 <div style="height: 60px;"></div>
367 <h2 class="title"><?php _e( 'Query Strings', 'fast-velocity-minify' ); ?></h2>
368 <h3 class="fvm-bold-green"><?php _e( 'Allow processing of CSS, JS & HTML on specific query strings', 'fast-velocity-minify' ); ?></h3>
369 <table class="form-table fvm-settings">
370 <tbody>
371 <tr>
372 <th scope="row"><?php _e( 'Allowed Query Strings', 'fast-velocity-minify' ); ?></th>
373 <td><fieldset>
374 <label for="fvm_settings_settings_qs"><span class="fvm-bold-green fvm-rowintro"><?php _e( 'One query string key per line', 'fast-velocity-minify' ); ?></span></label>
375 <p><textarea name="fvm_settings[settings][qs]" rows="7" cols="50" id="fvm_settings_settings_qs" class="large-text code" placeholder="--- check the help section for suggestions ---"><?php echo fvm_get_settings_value($fvm_settings, 'settings', 'qs'); ?></textarea></p>
376 <p class="description">[ <?php _e( 'Additional query strings, keys only', 'fast-velocity-minify' ); ?> ]</p>
377 </fieldset></td>
378 </tr>
379 </tbody></table>
380
381
382 <div style="height: 60px;"></div>
367 <h2 class="title"><?php _e( 'User Settings', 'fast-velocity-minify' ); ?></h2> 383 <h2 class="title"><?php _e( 'User Settings', 'fast-velocity-minify' ); ?></h2>
368 <h3 class="fvm-bold-green"><?php _e( 'For compatibility reasons, only anonymous users should be optimized by default.', 'fast-velocity-minify' ); ?></h3> 384 <h3 class="fvm-bold-green"><?php _e( 'For compatibility reasons, only anonymous users should be optimized by default.', 'fast-velocity-minify' ); ?></h3>
369 <table class="form-table fvm-settings"> 385 <table class="form-table fvm-settings">
......
...@@ -563,47 +563,7 @@ class CSS extends Minify ...@@ -563,47 +563,7 @@ class CSS extends Minify
563 */ 563 */
564 protected function shortenZeroes($content) 564 protected function shortenZeroes($content)
565 { 565 {
566 // we don't want to strip units in `calc()` expressions: 566 // removed
567 // `5px - 0px` is valid, but `5px - 0` is not
568 // `10px * 0` is valid (equates to 0), and so is `10 * 0px`, but
569 // `10 * 0` is invalid
570 // we've extracted calcs earlier, so we don't need to worry about this
571
572 // reusable bits of code throughout these regexes:
573 // before & after are used to make sure we don't match lose unintended
574 // 0-like values (e.g. in #000, or in http://url/1.0)
575 // units can be stripped from 0 values, or used to recognize non 0
576 // values (where wa may be able to strip a .0 suffix)
577 $before = '(?<=[:(, ])';
578 $after = '(?=[ ,);}])';
579 $units = '(em|ex|%|px|cm|mm|in|pt|pc|ch|rem|vh|vw|vmin|vmax|vm)';
580
581 // strip units after zeroes (0px -> 0)
582 // NOTE: it should be safe to remove all units for a 0 value, but in
583 // practice, Webkit (especially Safari) seems to stumble over at least
584 // 0%, potentially other units as well. Only stripping 'px' for now.
585 // @see https://github.com/matthiasmullie/minify/issues/60
586 $content = preg_replace('/'.$before.'(-?0*(\.0+)?)(?<=0)px'.$after.'/', '\\1', $content);
587
588 // strip 0-digits (.0 -> 0)
589 $content = preg_replace('/'.$before.'\.0+'.$units.'?'.$after.'/', '0\\1', $content);
590 // strip trailing 0: 50.10 -> 50.1, 50.10px -> 50.1px
591 $content = preg_replace('/'.$before.'(-?[0-9]+\.[0-9]+)0+'.$units.'?'.$after.'/', '\\1\\2', $content);
592 // strip trailing 0: 50.00 -> 50, 50.00px -> 50px
593 $content = preg_replace('/'.$before.'(-?[0-9]+)\.0+'.$units.'?'.$after.'/', '\\1\\2', $content);
594 // strip leading 0: 0.1 -> .1, 01.1 -> 1.1
595 $content = preg_replace('/'.$before.'(-?)0+([0-9]*\.[0-9]+)'.$units.'?'.$after.'/', '\\1\\2\\3', $content);
596
597 // strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0)
598 $content = preg_replace('/'.$before.'-?0+'.$units.'?'.$after.'/', '0\\1', $content);
599
600 // IE doesn't seem to understand a unitless flex-basis value (correct -
601 // it goes against the spec), so let's add it in again (make it `%`,
602 // which is only 1 char: 0%, 0px, 0 anything, it's all just the same)
603 // @see https://developer.mozilla.org/nl/docs/Web/CSS/flex
604 $content = preg_replace('/flex:([0-9]+\s[0-9]+\s)0([;\}])/', 'flex:${1}0%${2}', $content);
605 $content = preg_replace('/flex-basis:0([;\}])/', 'flex-basis:0%${1}', $content);
606
607 return $content; 567 return $content;
608 } 568 }
609 569
......
...@@ -3,13 +3,13 @@ Contributors: Alignak ...@@ -3,13 +3,13 @@ Contributors: Alignak
3 Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM 3 Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM
4 Requires at least: 4.9 4 Requires at least: 4.9
5 Requires PHP: 5.6 5 Requires PHP: 5.6
6 Stable tag: 3.2.2 6 Stable tag: 3.2.6
7 Tested up to: 5.7.1 7 Tested up to: 5.9.1
8 Text Domain: fast-velocity-minify 8 Text Domain: fast-velocity-minify
9 License: GPLv3 or later 9 License: GPLv3 or later
10 License URI: http://www.gnu.org/licenses/gpl-3.0.html 10 License URI: http://www.gnu.org/licenses/gpl-3.0.html
11 11
12 Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by adjusting your CSS and JS files (defer, async, minify, combine, etc), compressing HTML, simplifying fonts and a few more speed optimization options. 12 Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by adjusting CSS and JS files (defer, async, minify, combine, etc), compressing HTML, simplifying fonts and a few more speed optimization options.
13 13
14 14
15 == Description == 15 == Description ==
...@@ -49,8 +49,26 @@ You need a public directory to store and serve minified cache files. If you need ...@@ -49,8 +49,26 @@ You need a public directory to store and serve minified cache files. If you need
49 49
50 == Changelog == 50 == Changelog ==
51 51
52 = 3.2.2 [2021.05.09] = 52 = 3.2.6 [2022.02.06] =
53 * cache purging fixes
54
55 = 3.2.5 [2022.02.01] =
56 * changed writing the css/js files to WP_Filesystem_Direct with a secondary fallback method
57 * fixed a bug when merging css/js can break the site layout if the plugin failed to write the cache file (there will be an html comment on the footer if this happens)
58 * renamed a common name class to avoid conflicts with other plugins
59
60 = 3.2.4 [2022.01.31] =
61 * WP 5.9 / PHP 8 maintenance release
62 * changed deferred css/js cache clearing from 24h to 7 days
63 * added cache purging support for nginx helper plugin
64 * added option to allow processing on specific query strings
65 * other bug fixes
66
67 = 3.2.3 [2021.05.15] =
53 * added auto varnish cache purge for Cloudways 68 * added auto varnish cache purge for Cloudways
69 * switched from WP_Filesystem_Direct() to WP_Filesystem()
70
71 = 3.2.2 [2021.05.09] =
54 * fixed some JS files not being minified 72 * fixed some JS files not being minified
55 73
56 = 3.2.1 [2021.05.07] = 74 = 3.2.1 [2021.05.07] =
......