Version Description
[2021.01.06] = * Added support for WP AMP by custom4web * Fix for code and pre tags being minified * Better HTML document detection for minification
Download this release
Release Info
Developer | Alignak |
Plugin | Fast Velocity Minify |
Version | 3.1.0 |
Comparing to | |
See all releases |
Code changes from version 3.0.9 to 3.1.0
- fvm.php +1 -1
- inc/admin.php +10 -2
- inc/common.php +81 -7
- inc/frontend.php +1 -5
- libs/raisermin/minify.php +46 -3
- readme.txt +6 -1
fvm.php
CHANGED
@@ -6,7 +6,7 @@ Description: Improve your speed score on GTmetrix, Pingdom Tools and Google Page
|
|
6 |
Author: Raul Peixoto
|
7 |
Author URI: http://fastvelocity.com
|
8 |
Text Domain: fast-velocity-minify
|
9 |
-
Version: 3.0
|
10 |
License: GPL2
|
11 |
|
12 |
------------------------------------------------------------------------
|
6 |
Author: Raul Peixoto
|
7 |
Author URI: http://fastvelocity.com
|
8 |
Text Domain: fast-velocity-minify
|
9 |
+
Version: 3.1.0
|
10 |
License: GPL2
|
11 |
|
12 |
------------------------------------------------------------------------
|
inc/admin.php
CHANGED
@@ -146,7 +146,7 @@ add_filter("plugin_action_links_".$fvm_var_basename, 'fvm_min_settings_link' );
|
|
146 |
function fvm_min_settings_link($links) {
|
147 |
global $fvm_var_basename;
|
148 |
if (is_plugin_active($fvm_var_basename)) {
|
149 |
-
$settings_link = '<a href="'.admin_url('
|
150 |
array_unshift($links, $settings_link);
|
151 |
}
|
152 |
return $links;
|
@@ -188,8 +188,16 @@ function fvm_show_admin_notice_from_transient() {
|
|
188 |
if($inf != false && !empty($inf)) {
|
189 |
$jsonarr = json_decode($inf, true);
|
190 |
if(!is_null($jsonarr) && is_array($jsonarr)){
|
|
|
|
|
|
|
191 |
foreach ($jsonarr as $notice) {
|
192 |
-
add_settings_error( 'fvm_admin_notice', 'fvm_admin_notice',
|
|
|
|
|
|
|
|
|
|
|
193 |
}
|
194 |
}
|
195 |
|
146 |
function fvm_min_settings_link($links) {
|
147 |
global $fvm_var_basename;
|
148 |
if (is_plugin_active($fvm_var_basename)) {
|
149 |
+
$settings_link = '<a href="'.admin_url('admin.php?page=fvm').'">Settings</a>';
|
150 |
array_unshift($links, $settings_link);
|
151 |
}
|
152 |
return $links;
|
188 |
if($inf != false && !empty($inf)) {
|
189 |
$jsonarr = json_decode($inf, true);
|
190 |
if(!is_null($jsonarr) && is_array($jsonarr)){
|
191 |
+
|
192 |
+
# add all
|
193 |
+
$jsonarr = array_unique($jsonarr);
|
194 |
foreach ($jsonarr as $notice) {
|
195 |
+
add_settings_error( 'fvm_admin_notice', 'fvm_admin_notice', 'FVM: '.$notice, 'info' );
|
196 |
+
}
|
197 |
+
|
198 |
+
# output on other pages
|
199 |
+
if(!isset($_GET['page']) || (isset($_GET['page']) && $_GET['page'] != 'fvm')) {
|
200 |
+
settings_errors( 'fvm_admin_notice' );
|
201 |
}
|
202 |
}
|
203 |
|
inc/common.php
CHANGED
@@ -30,7 +30,7 @@ function fvm_admintoolbar() {
|
|
30 |
'id' => 'fvm_submenu_settings',
|
31 |
'parent' => 'fvm_menu',
|
32 |
'title' => __("FVM Settings", 'fvm'),
|
33 |
-
'href' => admin_url('
|
34 |
));
|
35 |
|
36 |
/*
|
@@ -39,7 +39,7 @@ function fvm_admintoolbar() {
|
|
39 |
'id' => 'fvm_submenu_upgrade',
|
40 |
'parent' => 'fvm_menu',
|
41 |
'title' => __("Upgrade", 'fvm'),
|
42 |
-
'href' => admin_url('
|
43 |
));
|
44 |
*/
|
45 |
|
@@ -48,7 +48,7 @@ function fvm_admintoolbar() {
|
|
48 |
'id' => 'fvm_submenu_help',
|
49 |
'parent' => 'fvm_menu',
|
50 |
'title' => __("Help", 'fvm'),
|
51 |
-
'href' => admin_url('
|
52 |
));
|
53 |
|
54 |
}
|
@@ -85,7 +85,7 @@ function fvm_process_cache_purge_request(){
|
|
85 |
if(is_string($others)) { $notices[] = $others; }
|
86 |
|
87 |
# save transient for after the redirect
|
88 |
-
if(count($notices) == 0) { $notices[] = __( '
|
89 |
set_transient( 'fvm_admin_notice', json_encode($notices), 10);
|
90 |
|
91 |
}
|
@@ -424,14 +424,39 @@ function fvm_can_minify() {
|
|
424 |
|
425 |
global $fvm_urls;
|
426 |
|
|
|
|
|
|
|
|
|
|
|
427 |
# only GET requests allowed
|
428 |
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
429 |
return false;
|
430 |
}
|
431 |
|
432 |
# disable on nocache query string
|
433 |
-
if(
|
434 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
}
|
436 |
|
437 |
# compatibility with DONOTCACHEPAGE
|
@@ -472,9 +497,10 @@ function fvm_can_minify() {
|
|
472 |
if(function_exists('is_ajax') && is_ajax()){ return false; }
|
473 |
if(function_exists('is_wc_endpoint_url') && is_wc_endpoint_url()){ return false; }
|
474 |
|
475 |
-
# don't minify amp pages by
|
476 |
if(function_exists('is_amp_endpoint') && is_amp_endpoint()){ return false; }
|
477 |
if(function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint()){ return false; }
|
|
|
478 |
|
479 |
# get requested hostname
|
480 |
$host = fvm_get_domain();
|
@@ -1031,6 +1057,53 @@ function fvm_not_php_html($code) {
|
|
1031 |
}
|
1032 |
|
1033 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1034 |
# remove UTF8 BOM
|
1035 |
function fvm_remove_utf8_bom($text) {
|
1036 |
$bom = pack('H*','EFBBBF');
|
@@ -1394,6 +1467,7 @@ function fvm_get_domain() {
|
|
1394 |
}
|
1395 |
}
|
1396 |
|
|
|
1397 |
# get the settings file path, current domain name, and uri path without query strings
|
1398 |
function fvm_get_uripath() {
|
1399 |
if (isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI'])) {
|
30 |
'id' => 'fvm_submenu_settings',
|
31 |
'parent' => 'fvm_menu',
|
32 |
'title' => __("FVM Settings", 'fvm'),
|
33 |
+
'href' => admin_url('admin.php?page=fvm')
|
34 |
));
|
35 |
|
36 |
/*
|
39 |
'id' => 'fvm_submenu_upgrade',
|
40 |
'parent' => 'fvm_menu',
|
41 |
'title' => __("Upgrade", 'fvm'),
|
42 |
+
'href' => admin_url('admin.php?page=fvm&tab=upgrade')
|
43 |
));
|
44 |
*/
|
45 |
|
48 |
'id' => 'fvm_submenu_help',
|
49 |
'parent' => 'fvm_menu',
|
50 |
'title' => __("Help", 'fvm'),
|
51 |
+
'href' => admin_url('admin.php?page=fvm&tab=help')
|
52 |
));
|
53 |
|
54 |
}
|
85 |
if(is_string($others)) { $notices[] = $others; }
|
86 |
|
87 |
# save transient for after the redirect
|
88 |
+
if(count($notices) == 0) { $notices[] = __( 'All supported caches have been purged ', 'fast-velocity-minify' ) . ' ('.date("D, d M Y @ H:i:s e").')'; }
|
89 |
set_transient( 'fvm_admin_notice', json_encode($notices), 10);
|
90 |
|
91 |
}
|
424 |
|
425 |
global $fvm_urls;
|
426 |
|
427 |
+
# must have
|
428 |
+
if(!isset($_SERVER['REQUEST_URI']) || !isset($_SERVER['REQUEST_METHOD'])){
|
429 |
+
return false;
|
430 |
+
}
|
431 |
+
|
432 |
# only GET requests allowed
|
433 |
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
434 |
return false;
|
435 |
}
|
436 |
|
437 |
# disable on nocache query string
|
438 |
+
if (!empty($_SERVER['REQUEST_URI'])) {
|
439 |
+
|
440 |
+
$parseurl = parse_url($_SERVER['REQUEST_URI']);
|
441 |
+
if(isset($parseurl["query"]) && !empty($parseurl["query"])) {
|
442 |
+
|
443 |
+
# parse query string to array
|
444 |
+
$query_string_arr = array();
|
445 |
+
parse_str($parseurl["query"], $query_string_arr);
|
446 |
+
|
447 |
+
# specifically allowed query strings
|
448 |
+
$allowed = array('_ga', 'age-verified', 'ao_noptimize', 'cn-reloaded', 'fb_action_ids', 'fb_action_types', 'fb_source', 'fbclid', 'gclid', 'usqp', 'utm_campaign', 'utm_content', 'utm_expid', 'utm_medium', 'utm_source', 'utm_term');
|
449 |
+
|
450 |
+
foreach ( $allowed as $qs) {
|
451 |
+
if(isset($query_string_arr[$qs])) { unset($query_string_arr[$qs]); }
|
452 |
+
}
|
453 |
+
|
454 |
+
# return false if there are any query strings left
|
455 |
+
if(count($query_string_arr) > 0) {
|
456 |
+
return false;
|
457 |
+
}
|
458 |
+
}
|
459 |
+
|
460 |
}
|
461 |
|
462 |
# compatibility with DONOTCACHEPAGE
|
497 |
if(function_exists('is_ajax') && is_ajax()){ return false; }
|
498 |
if(function_exists('is_wc_endpoint_url') && is_wc_endpoint_url()){ return false; }
|
499 |
|
500 |
+
# don't minify amp pages by known amp plugins
|
501 |
if(function_exists('is_amp_endpoint') && is_amp_endpoint()){ return false; }
|
502 |
if(function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint()){ return false; }
|
503 |
+
if(function_exists('is_wp_amp') && is_wp_amp()){ return false; }
|
504 |
|
505 |
# get requested hostname
|
506 |
$host = fvm_get_domain();
|
1057 |
}
|
1058 |
|
1059 |
|
1060 |
+
# find if a string looks like HTML content
|
1061 |
+
function fvm_is_html($html) {
|
1062 |
+
|
1063 |
+
# return early if it's html
|
1064 |
+
$html = trim($html);
|
1065 |
+
$a = '<!doctype';
|
1066 |
+
$b = '<html';
|
1067 |
+
if ( strcasecmp(substr($html, 0, strlen($a)), $a) == 0 || strcasecmp(substr($html, 0, strlen($b)), $b) == 0 ) {
|
1068 |
+
return true;
|
1069 |
+
}
|
1070 |
+
|
1071 |
+
# must have html
|
1072 |
+
$hfound = array(); preg_match_all('/<\s?(html)+(.*)>(.*)<\s?\/\s?html\s?>/Uuis', $html, $hfound);
|
1073 |
+
if(!isset($hfound[0][0])) { return false; }
|
1074 |
+
|
1075 |
+
# must have head
|
1076 |
+
$hfound = array(); preg_match_all('/<\s?(head)+(.*)>(.*)<\s?\/\s?head\s?>/Uuis', $html, $hfound);
|
1077 |
+
if(!isset($hfound[0][0])) { return false; }
|
1078 |
+
|
1079 |
+
# must have body
|
1080 |
+
$hfound = array(); preg_match_all('/<\s?(body)+(.*)>(.*)<\s?\/\s?body\s?>/Uuis', $html, $hfound);
|
1081 |
+
if(!isset($hfound[0][0])) { return false; }
|
1082 |
+
|
1083 |
+
# must have at least one of these
|
1084 |
+
$count = 0;
|
1085 |
+
|
1086 |
+
# css link
|
1087 |
+
$hfound = array(); preg_match_all('/<\s?(link)+(.*)(rel|href)+(.*)>/Uuis', $html, $hfound);
|
1088 |
+
if(!isset($hfound[0][0])) { $count++; }
|
1089 |
+
|
1090 |
+
# style
|
1091 |
+
$hfound = array(); preg_match_all('/<\s?(style)+(.*)(src)+(.*)>(.*)<\s?\/\s?style\s?>/Uuis', $html, $hfound);
|
1092 |
+
if(!isset($hfound[0][0])) { $count++; }
|
1093 |
+
|
1094 |
+
# script
|
1095 |
+
$hfound = array(); preg_match_all('/<\s?(script)+(.*)(src)+(.*)>(.*)<\s?\/\s?script\s?>/Uuis', $html, $hfound);
|
1096 |
+
if(!isset($hfound[0][0])) { $count++; }
|
1097 |
+
|
1098 |
+
# return if not
|
1099 |
+
if($count == 0) { return false; }
|
1100 |
+
|
1101 |
+
# else, it's likely html
|
1102 |
+
return true;
|
1103 |
+
|
1104 |
+
}
|
1105 |
+
|
1106 |
+
|
1107 |
# remove UTF8 BOM
|
1108 |
function fvm_remove_utf8_bom($text) {
|
1109 |
$bom = pack('H*','EFBBBF');
|
1467 |
}
|
1468 |
}
|
1469 |
|
1470 |
+
|
1471 |
# get the settings file path, current domain name, and uri path without query strings
|
1472 |
function fvm_get_uripath() {
|
1473 |
if (isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI'])) {
|
inc/frontend.php
CHANGED
@@ -49,11 +49,7 @@ function fvm_process_page($html) {
|
|
49 |
if(fvm_can_minify()) {
|
50 |
|
51 |
# return early if not html
|
52 |
-
$html
|
53 |
-
$a = '<!doctype';
|
54 |
-
$b = '<html';
|
55 |
-
|
56 |
-
if ( strcasecmp(substr($html, 0, strlen($a)), $a) != 0 && strcasecmp(substr($html, 0, strlen($b)), $b) != 0 ) {
|
57 |
return $html;
|
58 |
}
|
59 |
|
49 |
if(fvm_can_minify()) {
|
50 |
|
51 |
# return early if not html
|
52 |
+
if(fvm_is_html($html) !== true) {
|
|
|
|
|
|
|
|
|
53 |
return $html;
|
54 |
}
|
55 |
|
libs/raisermin/minify.php
CHANGED
@@ -74,12 +74,34 @@ function fvm_raisermin_html($html, $xtra) {
|
|
74 |
$allscripts = array();
|
75 |
preg_match_all('/\<script(.*?)\<(\s*)\/script(\s*)\>/uis', $html, $allscripts);
|
76 |
|
77 |
-
# replace all
|
78 |
if(is_array($allscripts) && isset($allscripts[0]) && count($allscripts[0]) > 0) {
|
79 |
foreach ($allscripts[0] as $k=>$v) {
|
80 |
$content = str_replace($v, '<!-- SCRIPT '.$k.' -->', $content);
|
81 |
}
|
82 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
# remove line breaks, and colapse two or more white spaces into one
|
85 |
$content = preg_replace('/\s+/u', " ", $content);
|
@@ -131,7 +153,7 @@ function fvm_raisermin_html($html, $xtra) {
|
|
131 |
|
132 |
}
|
133 |
|
134 |
-
# replace markers
|
135 |
if(is_array($allscripts) && isset($allscripts[0]) && count($allscripts[0]) > 0) {
|
136 |
foreach ($allscripts[0] as $k=>$v) {
|
137 |
if($xtra === true) {
|
@@ -142,9 +164,30 @@ function fvm_raisermin_html($html, $xtra) {
|
|
142 |
}
|
143 |
}
|
144 |
|
145 |
-
|
146 |
# no more than 1 linebreak
|
147 |
$content = preg_replace('/\v{2,}/u', PHP_EOL, $content);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
# save as html, if not empty
|
150 |
if(!empty($content)) {
|
74 |
$allscripts = array();
|
75 |
preg_match_all('/\<script(.*?)\<(\s*)\/script(\s*)\>/uis', $html, $allscripts);
|
76 |
|
77 |
+
# replace all with a marker
|
78 |
if(is_array($allscripts) && isset($allscripts[0]) && count($allscripts[0]) > 0) {
|
79 |
foreach ($allscripts[0] as $k=>$v) {
|
80 |
$content = str_replace($v, '<!-- SCRIPT '.$k.' -->', $content);
|
81 |
}
|
82 |
}
|
83 |
+
|
84 |
+
# get all <code> sections
|
85 |
+
$allcodes = array();
|
86 |
+
preg_match_all('/\<code(.*?)\<(\s*)\/code(\s*)\>/uis', $html, $allcodes);
|
87 |
+
|
88 |
+
# replace all with a marker
|
89 |
+
if(is_array($allcodes) && isset($allcodes[0]) && count($allcodes[0]) > 0) {
|
90 |
+
foreach ($allcodes[0] as $k=>$v) {
|
91 |
+
$content = str_replace($v, '<!-- CODE '.$k.' -->', $content);
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
# get all <pre> sections
|
96 |
+
$allpres = array();
|
97 |
+
preg_match_all('/\<pre(.*?)\<(\s*)\/pre(\s*)\>/uis', $html, $allpres);
|
98 |
+
|
99 |
+
# replace all with a marker
|
100 |
+
if(is_array($allpres) && isset($allpres[0]) && count($allpres[0]) > 0) {
|
101 |
+
foreach ($allpres[0] as $k=>$v) {
|
102 |
+
$content = str_replace($v, '<!-- PRE '.$k.' -->', $content);
|
103 |
+
}
|
104 |
+
}
|
105 |
|
106 |
# remove line breaks, and colapse two or more white spaces into one
|
107 |
$content = preg_replace('/\s+/u', " ", $content);
|
153 |
|
154 |
}
|
155 |
|
156 |
+
# replace markers for scripts
|
157 |
if(is_array($allscripts) && isset($allscripts[0]) && count($allscripts[0]) > 0) {
|
158 |
foreach ($allscripts[0] as $k=>$v) {
|
159 |
if($xtra === true) {
|
164 |
}
|
165 |
}
|
166 |
|
|
|
167 |
# no more than 1 linebreak
|
168 |
$content = preg_replace('/\v{2,}/u', PHP_EOL, $content);
|
169 |
+
|
170 |
+
# replace markers for <code>
|
171 |
+
if(is_array($allcodes) && isset($allcodes[0]) && count($allcodes[0]) > 0) {
|
172 |
+
foreach ($allcodes[0] as $k=>$v) {
|
173 |
+
if($xtra === true) {
|
174 |
+
$content = str_replace('<!-- CODE '.$k.' -->', PHP_EOL . $v . PHP_EOL, $content);
|
175 |
+
} else {
|
176 |
+
$content = str_replace('<!-- CODE '.$k.' -->', $v, $content);
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
180 |
+
|
181 |
+
# replace markers for <pre>
|
182 |
+
if(is_array($allpres) && isset($allpres[0]) && count($allpres[0]) > 0) {
|
183 |
+
foreach ($allpres[0] as $k=>$v) {
|
184 |
+
if($xtra === true) {
|
185 |
+
$content = str_replace('<!-- PRE '.$k.' -->', PHP_EOL . $v . PHP_EOL, $content);
|
186 |
+
} else {
|
187 |
+
$content = str_replace('<!-- PRE '.$k.' -->', $v, $content);
|
188 |
+
}
|
189 |
+
}
|
190 |
+
}
|
191 |
|
192 |
# save as html, if not empty
|
193 |
if(!empty($content)) {
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: Alignak
|
|
3 |
Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM
|
4 |
Requires at least: 4.7
|
5 |
Requires PHP: 5.6
|
6 |
-
Stable tag: 3.0
|
7 |
Tested up to: 5.6
|
8 |
Text Domain: fast-velocity-minify
|
9 |
License: GPLv3 or later
|
@@ -55,6 +55,11 @@ Version 3.0 is a major code rewrite to improve JS and CSS merging, but it requir
|
|
55 |
|
56 |
== Changelog ==
|
57 |
|
|
|
|
|
|
|
|
|
|
|
58 |
= 3.0.9 [2021.01.04] =
|
59 |
* Added page caching purging support for Hummingbird and WP-Optimize from FVM
|
60 |
|
3 |
Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM
|
4 |
Requires at least: 4.7
|
5 |
Requires PHP: 5.6
|
6 |
+
Stable tag: 3.1.0
|
7 |
Tested up to: 5.6
|
8 |
Text Domain: fast-velocity-minify
|
9 |
License: GPLv3 or later
|
55 |
|
56 |
== Changelog ==
|
57 |
|
58 |
+
= 3.1.0 [2021.01.06] =
|
59 |
+
* Added support for WP AMP by custom4web
|
60 |
+
* Fix for code and pre tags being minified
|
61 |
+
* Better HTML document detection for minification
|
62 |
+
|
63 |
= 3.0.9 [2021.01.04] =
|
64 |
* Added page caching purging support for Hummingbird and WP-Optimize from FVM
|
65 |
|