Fast Velocity Minify - Version 3.0.7

Version Description

[2021.01.02] = * Fixed incorrect paths on subdirectory sites (inside merged CSS files)

Download this release

Release Info

Developer Alignak
Plugin Icon 128x128 Fast Velocity Minify
Version 3.0.7
Comparing to
See all releases

Code changes from version 3.0.6 to 3.0.7

Files changed (5) hide show
  1. fvm.php +2 -2
  2. inc/common.php +34 -18
  3. inc/frontend.php +6 -6
  4. inc/updates.php +3 -3
  5. readme.txt +6 -3
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.6
10
  License: GPL2
11
 
12
  ------------------------------------------------------------------------
@@ -58,7 +58,7 @@ $fvm_settings = fvm_get_settings();
58
  $fvm_cache_paths = fvm_cachepath();
59
 
60
  # site url, domain name
61
- $fvm_urls = array('wp_home'=>site_url(), 'wp_domain'=>fvm_get_domain());
62
 
63
 
64
  # only on backend
6
  Author: Raul Peixoto
7
  Author URI: http://fastvelocity.com
8
  Text Domain: fast-velocity-minify
9
+ Version: 3.0.7
10
  License: GPL2
11
 
12
  ------------------------------------------------------------------------
58
  $fvm_cache_paths = fvm_cachepath();
59
 
60
  # site url, domain name
61
+ $fvm_urls = array('wp_site_url'=>site_url(), 'wp_domain'=>fvm_get_domain());
62
 
63
 
64
  # only on backend
inc/common.php CHANGED
@@ -418,6 +418,11 @@ function fvm_can_minify() {
418
  if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
419
  return false;
420
  }
 
 
 
 
 
421
 
422
  # compatibility with DONOTCACHEPAGE
423
  if( defined('DONOTCACHEPAGE') && DONOTCACHEPAGE ){ return false; }
@@ -472,11 +477,9 @@ function fvm_can_minify() {
472
  }
473
 
474
  # if there is an url, avoid known static files
475
- if(isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI'])) {
476
-
477
- # parse url (path, query)
478
- $ruri = str_replace('//', '/', str_replace('..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', strtok($_SERVER['REQUEST_URI'], '?'))));
479
-
480
  # avoid robots.txt and other situations
481
  $noext = array('.txt', '.xml', '.map', '.css', '.js', '.png', '.jpeg', '.jpg', '.gif', '.webp', '.ico', '.php', '.htaccess', '.json', '.pdf', '.mp4', '.webm', '.zip', '.sql', '.gz');
482
  foreach ($noext as $ext) {
@@ -768,7 +771,7 @@ function fvm_maybe_download($url) {
768
  if (stripos($url, $fvm_urls['wp_domain']) !== false && defined('ABSPATH') && !empty('ABSPATH')) {
769
 
770
  # file path + windows compatibility
771
- $f = str_replace('/', DIRECTORY_SEPARATOR, str_replace(rtrim($fvm_urls['wp_home'], '/'), ABSPATH, $url));
772
 
773
  # did it work?
774
  if (file_exists($f)) {
@@ -1079,19 +1082,32 @@ function fvm_maybe_minify_css_file($css, $url, $min) {
1079
 
1080
  # make relative urls when possible
1081
  global $fvm_urls;
1082
- $bgimgs = array();
1083
- preg_match_all ('/url\s*\((\s*[\'"]?(http)(s|:).+[\'"]?\s*)\)/Uui', $css, $bgimgs);
1084
- if(isset($bgimgs[1]) && is_array($bgimgs[1])) {
1085
- foreach($bgimgs[1] as $img) {
1086
- if(substr($img, 0, strlen($fvm_urls['wp_home'])) == $fvm_urls['wp_home']) {
1087
- $pos = strpos($img, $fvm_urls['wp_home']);
1088
- if ($pos !== false) {
1089
- $relimg = substr_replace($img, '', $pos, strlen($fvm_urls['wp_home']));
1090
- $css = str_replace($img, $relimg, $css);
 
 
 
 
 
 
 
 
 
 
 
 
 
1091
  }
1092
  }
1093
  }
1094
- }
1095
 
1096
  # return css
1097
  return trim($css);
@@ -1267,7 +1283,7 @@ function fvm_replace_css_imports($css, $rq=null) {
1267
  if(!empty($url)) {
1268
 
1269
  # make sure we have a complete url
1270
- $href = fvm_normalize_url($url, $fvm_urls['wp_domain'], $fvm_urls['wp_home']);
1271
 
1272
  # download, minify, cache (no ver query string)
1273
  $tkey = hash('sha1', $href);
@@ -1314,7 +1330,7 @@ function fvm_replace_css_imports($css, $rq=null) {
1314
 
1315
  # size in bytes
1316
  $fs = strlen($subcss);
1317
- $ur = str_replace($fvm_urls['wp_home'], '', $href);
1318
  $tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur), 'mt'=>$media);
1319
 
1320
  # save
418
  if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
419
  return false;
420
  }
421
+
422
+ # disable on nocache query string
423
+ if(isset($_GET["nocache"])) {
424
+ return false;
425
+ }
426
 
427
  # compatibility with DONOTCACHEPAGE
428
  if( defined('DONOTCACHEPAGE') && DONOTCACHEPAGE ){ return false; }
477
  }
478
 
479
  # if there is an url, avoid known static files
480
+ $ruri = fvm_get_uripath();
481
+ if($ruri !== false && !empty($ruri)) {
482
+
 
 
483
  # avoid robots.txt and other situations
484
  $noext = array('.txt', '.xml', '.map', '.css', '.js', '.png', '.jpeg', '.jpg', '.gif', '.webp', '.ico', '.php', '.htaccess', '.json', '.pdf', '.mp4', '.webm', '.zip', '.sql', '.gz');
485
  foreach ($noext as $ext) {
771
  if (stripos($url, $fvm_urls['wp_domain']) !== false && defined('ABSPATH') && !empty('ABSPATH')) {
772
 
773
  # file path + windows compatibility
774
+ $f = str_replace('/', DIRECTORY_SEPARATOR, str_replace(rtrim($fvm_urls['wp_site_url'], '/'), ABSPATH, $url));
775
 
776
  # did it work?
777
  if (file_exists($f)) {
1082
 
1083
  # make relative urls when possible
1084
  global $fvm_urls;
1085
+
1086
+ # get root url, preserve subdirectories
1087
+ if(isset($fvm_urls['wp_site_url']) && !empty($fvm_urls['wp_site_url'])) {
1088
+
1089
+ # parse url and extract domain without uri path
1090
+ $use_url = $fvm_urls['wp_site_url'];
1091
+ $parse = parse_url($use_url);
1092
+ if(isset($parse['path']) && !empty($parse['path']) && $parse['path'] != '/') {
1093
+ $use_url = str_replace(str_replace($use_url, $parse['path'], $use_url), '', $use_url);
1094
+ }
1095
+
1096
+ # adjust paths
1097
+ $bgimgs = array();
1098
+ preg_match_all ('/url\s*\((\s*[\'"]?(http)(s|:).+[\'"]?\s*)\)/Uui', $css, $bgimgs);
1099
+ if(isset($bgimgs[1]) && is_array($bgimgs[1])) {
1100
+ foreach($bgimgs[1] as $img) {
1101
+ if(substr($img, 0, strlen($use_url)) == $use_url) {
1102
+ $pos = strpos($img, $use_url);
1103
+ if ($pos !== false) {
1104
+ $relimg = substr_replace($img, '', $pos, strlen($use_url));
1105
+ $css = str_replace($img, $relimg, $css);
1106
+ }
1107
  }
1108
  }
1109
  }
1110
+ }
1111
 
1112
  # return css
1113
  return trim($css);
1283
  if(!empty($url)) {
1284
 
1285
  # make sure we have a complete url
1286
+ $href = fvm_normalize_url($url, $fvm_urls['wp_domain'], $fvm_urls['wp_site_url']);
1287
 
1288
  # download, minify, cache (no ver query string)
1289
  $tkey = hash('sha1', $href);
1330
 
1331
  # size in bytes
1332
  $fs = strlen($subcss);
1333
+ $ur = str_replace($fvm_urls['wp_site_url'], '', $href);
1334
  $tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur), 'mt'=>$media);
1335
 
1336
  # save
inc/frontend.php CHANGED
@@ -165,7 +165,7 @@ function fvm_process_page($html) {
165
  $css = '';
166
 
167
  # make sure we have a complete url
168
- $href = fvm_normalize_url($tag->href, $fvm_urls['wp_domain'], $fvm_urls['wp_home']);
169
 
170
  # get minification settings for files
171
  if(isset($fvm_settings['css']['min_disable']) && $fvm_settings['css']['min_disable'] == '1') {
@@ -206,7 +206,7 @@ function fvm_process_page($html) {
206
 
207
  # execution time in ms, size in bytes
208
  $fs = strlen($css);
209
- $ur = str_replace($fvm_urls['wp_home'], '', $href);
210
  $tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur), 'mt'=>$media);
211
 
212
  # save
@@ -278,7 +278,7 @@ function fvm_process_page($html) {
278
  if(isset($fvm_settings['cdn']['cssok']) && $fvm_settings['cdn']['cssok'] == true) {
279
 
280
  # scheme + site url
281
- $fcdn = str_replace($fvm_urls['wp_domain'], $fvm_settings['cdn']['domain'], $fvm_urls['wp_home']);
282
 
283
  # replacements
284
  $css = str_ireplace('url(/wp-content/', 'url('.$fcdn.'/wp-content/', $css);
@@ -546,7 +546,7 @@ function fvm_process_page($html) {
546
  if(isset($tag->src)) {
547
 
548
  # make sure we have a complete url
549
- $href = fvm_normalize_url($tag->src, $fvm_urls['wp_domain'], $fvm_urls['wp_home']);
550
 
551
  # upgrade jQuery library and jQuery migrate to version 3
552
  if(isset($fvm_settings['js']['jqupgrade']) && $fvm_settings['js']['jqupgrade'] == true) {
@@ -647,7 +647,7 @@ function fvm_process_page($html) {
647
 
648
  # execution time in ms, size in bytes
649
  $fs = strlen($js);
650
- $ur = str_replace($fvm_urls['wp_home'], '', $href);
651
  $tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur));
652
 
653
  # save
@@ -713,7 +713,7 @@ function fvm_process_page($html) {
713
 
714
  # execution time in ms, size in bytes
715
  $fs = strlen($js);
716
- $ur = str_replace($fvm_urls['wp_home'], '', $href);
717
  $tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur));
718
 
719
  # save
165
  $css = '';
166
 
167
  # make sure we have a complete url
168
+ $href = fvm_normalize_url($tag->href, $fvm_urls['wp_domain'], $fvm_urls['wp_site_url']);
169
 
170
  # get minification settings for files
171
  if(isset($fvm_settings['css']['min_disable']) && $fvm_settings['css']['min_disable'] == '1') {
206
 
207
  # execution time in ms, size in bytes
208
  $fs = strlen($css);
209
+ $ur = str_replace($fvm_urls['wp_site_url'], '', $href);
210
  $tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur), 'mt'=>$media);
211
 
212
  # save
278
  if(isset($fvm_settings['cdn']['cssok']) && $fvm_settings['cdn']['cssok'] == true) {
279
 
280
  # scheme + site url
281
+ $fcdn = str_replace($fvm_urls['wp_domain'], $fvm_settings['cdn']['domain'], $fvm_urls['wp_site_url']);
282
 
283
  # replacements
284
  $css = str_ireplace('url(/wp-content/', 'url('.$fcdn.'/wp-content/', $css);
546
  if(isset($tag->src)) {
547
 
548
  # make sure we have a complete url
549
+ $href = fvm_normalize_url($tag->src, $fvm_urls['wp_domain'], $fvm_urls['wp_site_url']);
550
 
551
  # upgrade jQuery library and jQuery migrate to version 3
552
  if(isset($fvm_settings['js']['jqupgrade']) && $fvm_settings['js']['jqupgrade'] == true) {
647
 
648
  # execution time in ms, size in bytes
649
  $fs = strlen($js);
650
+ $ur = str_replace($fvm_urls['wp_site_url'], '', $href);
651
  $tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur));
652
 
653
  # save
713
 
714
  # execution time in ms, size in bytes
715
  $fs = strlen($js);
716
+ $ur = str_replace($fvm_urls['wp_site_url'], '', $href);
717
  $tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur));
718
 
719
  # save
inc/updates.php CHANGED
@@ -146,9 +146,9 @@ function fvm_get_updated_field_routines($fvm_settings) {
146
  }
147
  # Version 3.0 routines end
148
 
149
- # Version 3.1 routines start
150
  if (get_option("fastvelocity_plugin_version") !== false) {
151
- if (version_compare($fvm_var_plugin_version, '3.1.0', '>=' )) {
152
 
153
  # cleanup
154
  delete_option('fastvelocity_upgraded');
@@ -194,7 +194,7 @@ function fvm_get_updated_field_routines($fvm_settings) {
194
 
195
  }
196
  }
197
- # Version 3.1 routines end
198
 
199
  # return settings array
200
  return $fvm_settings;
146
  }
147
  # Version 3.0 routines end
148
 
149
+ # Version 3.2 routines start
150
  if (get_option("fastvelocity_plugin_version") !== false) {
151
+ if (version_compare($fvm_var_plugin_version, '3.2.0', '>=' )) {
152
 
153
  # cleanup
154
  delete_option('fastvelocity_upgraded');
194
 
195
  }
196
  }
197
+ # Version 3.2 routines end
198
 
199
  # return settings array
200
  return $fvm_settings;
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.6
7
  Tested up to: 5.6
8
  Text Domain: fast-velocity-minify
9
  License: GPLv3 or later
@@ -55,13 +55,16 @@ Version 3.0 is a major code rewrite to improve JS and CSS merging, but it requir
55
 
56
  == Changelog ==
57
 
 
 
 
58
  = 3.0.6 [2021.01.01] =
59
  * Adjusted the HELP tab settings
60
  * Improved compatibility with CSS merging on WP Bakery
61
 
62
  = 3.0.5 [2021.01.01] =
63
  * Fixed the cache paths on Windows Servers
64
- * Fixed incorrect paths on subdirectory sites
65
  * Fixed the CDN integration not replacing the domain name
66
  * Fixed CSS font-display replacements
67
 
@@ -80,7 +83,7 @@ Version 3.0 is a major code rewrite to improve JS and CSS merging, but it requir
80
  * Added option to force HTTPS on the generated cache file urls
81
  * Added an ignore list to the JS section (also imported from FVM 2 settings)
82
  * Improved compatibility with FVM 2 (you still need to specify what JS paths you want to merge)
83
- * Preserve the old FVM 2 settings on the database (will be removed on version 3.1)
84
 
85
  = 3.0.1 [2020.12.27] =
86
  * Added initial translation support under the "fast-velocity-minify" text domain.
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
7
  Tested up to: 5.6
8
  Text Domain: fast-velocity-minify
9
  License: GPLv3 or later
55
 
56
  == Changelog ==
57
 
58
+ = 3.0.7 [2021.01.02] =
59
+ * Fixed incorrect paths on subdirectory sites (inside merged CSS files)
60
+
61
  = 3.0.6 [2021.01.01] =
62
  * Adjusted the HELP tab settings
63
  * Improved compatibility with CSS merging on WP Bakery
64
 
65
  = 3.0.5 [2021.01.01] =
66
  * Fixed the cache paths on Windows Servers
67
+ * Fixed incorrect file paths on subdirectory sites
68
  * Fixed the CDN integration not replacing the domain name
69
  * Fixed CSS font-display replacements
70
 
83
  * Added option to force HTTPS on the generated cache file urls
84
  * Added an ignore list to the JS section (also imported from FVM 2 settings)
85
  * Improved compatibility with FVM 2 (you still need to specify what JS paths you want to merge)
86
+ * Preserve the old FVM 2 settings on the database (will be removed on version 3.2)
87
 
88
  = 3.0.1 [2020.12.27] =
89
  * Added initial translation support under the "fast-velocity-minify" text domain.