Fast Velocity Minify - Version 2.4.8

Version Description

[2018.12.07] = * changed the file permissions for the generated cache directory and files, to match the uploads directory * added some extra checks for when PHP is running in safe mode

Download this release

Release Info

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

Code changes from version 2.4.7 to 2.4.8

Files changed (4) hide show
  1. fvm.php +33 -23
  2. inc/functions-serverinfo.php +10 -8
  3. inc/functions.php +84 -18
  4. readme.txt +5 -1
fvm.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://fastvelocity.com
5
  Description: Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by merging and minifying CSS and JavaScript files into groups, compressing HTML and other speed optimizations.
6
  Author: Raul Peixoto
7
  Author URI: http://fastvelocity.com
8
- Version: 2.4.7
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
@@ -367,8 +367,7 @@ function fastvelocity_min_register_settings() {
367
  register_setting('fvm-group', 'fastvelocity_min_fvm_cdn_force');
368
  register_setting('fvm-group', 'fastvelocity_min_change_cache_base_url');
369
  register_setting('fvm-group', 'fastvelocity_min_change_cache_path');
370
- register_setting('fvm-group', 'fastvelocity_force_chmodmax');
371
-
372
  # pro tab
373
  register_setting('fvm-group-pro', 'fastvelocity_min_ignore');
374
  register_setting('fvm-group-pro', 'fastvelocity_min_ignorelist');
@@ -851,18 +850,6 @@ I know what I'm doing... <span class="note-info">[ Load my JS files from the CDN
851
  </label>
852
  </fieldset></td>
853
  </tr>
854
-
855
- <tr>
856
- <th scope="row">File Permissions</th>
857
- <td>
858
- <p class="fvm-bold-green fvm-rowintro">You should never need to tick this box, unless your server is misconfigured and FVM files are not being generated.</p>
859
- <fieldset>
860
- <label for="fastvelocity_force_chmodmax">
861
- <input name="fastvelocity_force_chmodmax" type="checkbox" id="fastvelocity_force_chmodmax" value="1" <?php echo checked(1 == get_option('fastvelocity_force_chmodmax'), true, false); ?>>
862
- Use chmod 0777 <span class="note-info">[ Some servers, need higher file permissions instead of the default chmod 0755 ]</span></label>
863
- </fieldset></td>
864
- </tr>
865
-
866
  </tbody></table>
867
 
868
 
@@ -1279,7 +1266,6 @@ $is_footer = 0; if (isset($wp_scripts->registered[$handle]->extra["group"]) || i
1279
  }
1280
  endforeach;
1281
 
1282
-
1283
  # loop through header scripts and merge
1284
  for($i=0,$l=count($header);$i<$l;$i++) {
1285
  if(!isset($header[$i]['handle'])) {
@@ -1333,14 +1319,10 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1333
  # Add extra data from wp_add_inline_script before
1334
  if (!empty( $wp_scripts->registered[$handle]->extra)) {
1335
  if (!empty( $wp_scripts->registered[$handle]->extra['before'])){
1336
- $code.= PHP_EOL.implode(PHP_EOL, $wp_scripts->registered[$handle]->extra['before']);
1337
  }
1338
  }
1339
-
1340
-
1341
-
1342
-
1343
-
1344
  # consider dependencies on handles with an empty src
1345
  } else {
1346
  wp_dequeue_script($handle); wp_enqueue_script($handle);
@@ -1355,9 +1337,15 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1355
  file_put_contents($file, $code);
1356
  file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1357
 
 
 
 
 
 
1358
  # brotli static support
1359
  if(function_exists('brotli_compress')) {
1360
  file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
 
1361
  }
1362
  }
1363
 
@@ -1531,9 +1519,15 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
1531
  file_put_contents($file, $code);
1532
  file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1533
 
 
 
 
 
 
1534
  # brotli static support
1535
  if(function_exists('brotli_compress')) {
1536
  file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
 
1537
  }
1538
  }
1539
 
@@ -1960,9 +1954,15 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1960
  file_put_contents($file, $code);
1961
  file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1962
 
 
 
 
 
 
1963
  # brotli static support
1964
  if(function_exists('brotli_compress')) {
1965
  file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
 
1966
  }
1967
  }
1968
 
@@ -2323,9 +2323,15 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
2323
  file_put_contents($file, $code); # preserve style tags
2324
  file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
2325
 
 
 
 
 
 
2326
  # brotli static support
2327
  if(function_exists('brotli_compress')) {
2328
  file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
 
2329
  }
2330
  }
2331
 
@@ -2887,13 +2893,17 @@ function fastvelocity_generate_preload_headers(){
2887
 
2888
  # if there are no query strings
2889
  if($b == $a) {
2890
- if(!file_exists($a)) { file_put_contents($a, $headers); }
 
 
 
2891
  return false;
2892
  }
2893
 
2894
  # b fallback
2895
  if($b != $a && !file_exists($b)) {
2896
  file_put_contents($b, $headers);
 
2897
  }
2898
 
2899
  return false;
5
  Description: Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by merging and minifying CSS and JavaScript files into groups, compressing HTML and other speed optimizations.
6
  Author: Raul Peixoto
7
  Author URI: http://fastvelocity.com
8
+ Version: 2.4.8
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
367
  register_setting('fvm-group', 'fastvelocity_min_fvm_cdn_force');
368
  register_setting('fvm-group', 'fastvelocity_min_change_cache_base_url');
369
  register_setting('fvm-group', 'fastvelocity_min_change_cache_path');
370
+
 
371
  # pro tab
372
  register_setting('fvm-group-pro', 'fastvelocity_min_ignore');
373
  register_setting('fvm-group-pro', 'fastvelocity_min_ignorelist');
850
  </label>
851
  </fieldset></td>
852
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
853
  </tbody></table>
854
 
855
 
1266
  }
1267
  endforeach;
1268
 
 
1269
  # loop through header scripts and merge
1270
  for($i=0,$l=count($header);$i<$l;$i++) {
1271
  if(!isset($header[$i]['handle'])) {
1319
  # Add extra data from wp_add_inline_script before
1320
  if (!empty( $wp_scripts->registered[$handle]->extra)) {
1321
  if (!empty( $wp_scripts->registered[$handle]->extra['before'])){
1322
+ $code.= PHP_EOL . implode(PHP_EOL, $wp_scripts->registered[$handle]->extra['before']);
1323
  }
1324
  }
1325
+
 
 
 
 
1326
  # consider dependencies on handles with an empty src
1327
  } else {
1328
  wp_dequeue_script($handle); wp_enqueue_script($handle);
1337
  file_put_contents($file, $code);
1338
  file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1339
 
1340
+ # permissions
1341
+ fastvelocity_fix_permission_bits($file.'.txt');
1342
+ fastvelocity_fix_permission_bits($file);
1343
+ fastvelocity_fix_permission_bits($file.'.gz');
1344
+
1345
  # brotli static support
1346
  if(function_exists('brotli_compress')) {
1347
  file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
1348
+ fastvelocity_fix_permission_bits($file.'.br');
1349
  }
1350
  }
1351
 
1519
  file_put_contents($file, $code);
1520
  file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1521
 
1522
+ # permissions
1523
+ fastvelocity_fix_permission_bits($file.'.txt');
1524
+ fastvelocity_fix_permission_bits($file);
1525
+ fastvelocity_fix_permission_bits($file.'.gz');
1526
+
1527
  # brotli static support
1528
  if(function_exists('brotli_compress')) {
1529
  file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
1530
+ fastvelocity_fix_permission_bits($file.'.br');
1531
  }
1532
  }
1533
 
1954
  file_put_contents($file, $code);
1955
  file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1956
 
1957
+ # permissions
1958
+ fastvelocity_fix_permission_bits($file.'.txt');
1959
+ fastvelocity_fix_permission_bits($file);
1960
+ fastvelocity_fix_permission_bits($file.'.gz');
1961
+
1962
  # brotli static support
1963
  if(function_exists('brotli_compress')) {
1964
  file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
1965
+ fastvelocity_fix_permission_bits($file.'.br');
1966
  }
1967
  }
1968
 
2323
  file_put_contents($file, $code); # preserve style tags
2324
  file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
2325
 
2326
+ # permissions
2327
+ fastvelocity_fix_permission_bits($file.'.txt');
2328
+ fastvelocity_fix_permission_bits($file);
2329
+ fastvelocity_fix_permission_bits($file.'.gz');
2330
+
2331
  # brotli static support
2332
  if(function_exists('brotli_compress')) {
2333
  file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
2334
+ fastvelocity_fix_permission_bits($file.'.br');
2335
  }
2336
  }
2337
 
2893
 
2894
  # if there are no query strings
2895
  if($b == $a) {
2896
+ if(!file_exists($a)) {
2897
+ file_put_contents($a, $headers);
2898
+ fastvelocity_fix_permission_bits($a);
2899
+ }
2900
  return false;
2901
  }
2902
 
2903
  # b fallback
2904
  if($b != $a && !file_exists($b)) {
2905
  file_put_contents($b, $headers);
2906
+ fastvelocity_fix_permission_bits($b);
2907
  }
2908
 
2909
  return false;
inc/functions-serverinfo.php CHANGED
@@ -1,7 +1,5 @@
1
  <?php
2
 
3
-
4
-
5
  ### Get General Information
6
  function fvm_get_generalinfo() {
7
  global $is_IIS;
@@ -318,14 +316,14 @@ if(!function_exists('fvm_get_serverload')) {
318
  $load_avg = explode( " ", $data );
319
  $server_load = trim($load_avg[0]);
320
  }
321
- } else if ('WIN' == strtoupper(substr(PHP_OS, 0, 3))) {
322
  $process = @popen('wmic cpu get NumberOfCores', 'rb');
323
  if (false !== $process && null !== $process) {
324
  fgets($process);
325
  $numCpus = intval(fgets($process));
326
  pclose($process);
327
  }
328
- } else {
329
  $data = @system('uptime');
330
  preg_match('/(.*):{1}(.*)/', $data, $matches);
331
  if(isset($matches[2])) {
@@ -334,7 +332,9 @@ if(!function_exists('fvm_get_serverload')) {
334
  } else {
335
  $server_load = __('N/A', 'fvm-serverinfo');
336
  }
337
- }
 
 
338
  }
339
  if(empty($server_load)) {
340
  $server_load = __('N/A', 'fvm-serverinfo');
@@ -354,7 +354,7 @@ if(!function_exists('fvm_get_servercpu')) {
354
  $cpuinfo = file_get_contents('/proc/cpuinfo');
355
  preg_match_all('/^processor/m', $cpuinfo, $matches);
356
  $numCpus = count($matches[0]);
357
- } else {
358
  $process = @popen('sysctl -a', 'rb');
359
  if (false !== $process && null !== $process) {
360
  $output = stream_get_contents($process);
@@ -362,8 +362,10 @@ if(!function_exists('fvm_get_servercpu')) {
362
  if ($matches) { $numCpus = intval($matches[1][0]); }
363
  pclose($process);
364
  }
365
- }
366
- }
 
 
367
  if(empty($numCpus)) {
368
  $numCpus = __('N/A', 'fvm-serverinfo');
369
  }
1
  <?php
2
 
 
 
3
  ### Get General Information
4
  function fvm_get_generalinfo() {
5
  global $is_IIS;
316
  $load_avg = explode( " ", $data );
317
  $server_load = trim($load_avg[0]);
318
  }
319
+ } else if ('WIN' == strtoupper(substr(PHP_OS, 0, 3)) && function_exists('popen') && fvm_function_available('popen')) {
320
  $process = @popen('wmic cpu get NumberOfCores', 'rb');
321
  if (false !== $process && null !== $process) {
322
  fgets($process);
323
  $numCpus = intval(fgets($process));
324
  pclose($process);
325
  }
326
+ } else if (function_exists('system') && fvm_function_available('system')){
327
  $data = @system('uptime');
328
  preg_match('/(.*):{1}(.*)/', $data, $matches);
329
  if(isset($matches[2])) {
332
  } else {
333
  $server_load = __('N/A', 'fvm-serverinfo');
334
  }
335
+ } else {
336
+ $server_load = __('N/A', 'fvm-serverinfo');
337
+ }
338
  }
339
  if(empty($server_load)) {
340
  $server_load = __('N/A', 'fvm-serverinfo');
354
  $cpuinfo = file_get_contents('/proc/cpuinfo');
355
  preg_match_all('/^processor/m', $cpuinfo, $matches);
356
  $numCpus = count($matches[0]);
357
+ } else if (function_exists('popen') && fvm_function_available('popen')) {
358
  $process = @popen('sysctl -a', 'rb');
359
  if (false !== $process && null !== $process) {
360
  $output = stream_get_contents($process);
362
  if ($matches) { $numCpus = intval($matches[1][0]); }
363
  pclose($process);
364
  }
365
+ } else {
366
+ $numCpus = __('N/A', 'fvm-serverinfo');
367
+ }
368
+ }
369
  if(empty($numCpus)) {
370
  $numCpus = __('N/A', 'fvm-serverinfo');
371
  }
inc/functions.php CHANGED
@@ -23,6 +23,50 @@ use MatthiasMullie\Minify;
23
  # use HTML minification
24
  require_once ($plugindir . 'libs/mrclay/HTML.php');
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # get cache directories and urls
27
  function fvm_cachepath() {
28
 
@@ -38,20 +82,35 @@ if($fvm_change_cache_path !== false && $fvm_change_cache_base !== false && strle
38
  }
39
 
40
  # create
41
- $cachebase = rtrim($upload['basedir'], '/').'/fvm';
42
- $cachedir = rtrim($upload['basedir'], '/').'/fvm/out';
43
- $tmpdir = rtrim($upload['basedir'], '/').'/fvm/tmp';
44
- $cachedirurl = rtrim($upload['baseurl'], '/').'/fvm/out';
45
- $headerdir = rtrim($upload['basedir'], '/').'/fvm/header';
46
-
47
- # chmod level
48
- if(get_option('fastvelocity_force_chmodmax') != false) { $chmod = 0777; } else { $chmod = 0755; }
 
 
 
 
 
49
 
50
- # create and chmod accordingly
51
- if(!is_dir($cachebase)) { mkdir($cachebase, $chmod, true); }
52
- if(!is_dir($cachedir)) { mkdir($cachedir, $chmod, true); }
53
- if(!is_dir($tmpdir)) { mkdir($tmpdir, $chmod, true); }
54
- if(!is_dir($headerdir)) { mkdir($headerdir, $chmod, true); }
 
 
 
 
 
 
 
 
 
 
55
 
56
  # return
57
  return array('cachebase'=>$cachebase,'tmpdir'=>$tmpdir, 'cachedir'=>$cachedir, 'cachedirurl'=>$cachedirurl, 'headerdir'=>$headerdir);
@@ -362,12 +421,18 @@ function fastvelocity_format_filesize($bytes, $decimals = 2) {
362
  # get cache size and count
363
  function fastvelocity_get_cachestats() {
364
  clearstatcache();
365
- $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(fvm_cachepath()['cachebase'], FilesystemIterator::SKIP_DOTS));
366
- $size = 0;
367
- foreach ($dir as $file) {
368
- $size += $file->getSize();
 
 
 
 
 
 
 
369
  }
370
- return fastvelocity_format_filesize($size);
371
  }
372
 
373
  # remove default HTTP headers
@@ -844,6 +909,7 @@ function fvm_set_transient($key, $code) {
844
  $tmpdir = $cachepath['tmpdir'];
845
  $f = $tmpdir.'/'.$key.'.transient';
846
  file_put_contents($f, $code);
 
847
  return true;
848
  }
849
 
23
  # use HTML minification
24
  require_once ($plugindir . 'libs/mrclay/HTML.php');
25
 
26
+
27
+ # check if php has disabled some functions by default
28
+ function fvm_function_available($func) {
29
+ if (ini_get('safe_mode')) return false;
30
+ $disabled = ini_get('disable_functions');
31
+ if ($disabled) {
32
+ $disabled = explode(',', $disabled);
33
+ $disabled = array_map('trim', $disabled);
34
+ return !in_array($func, $disabled);
35
+ }
36
+ return true;
37
+ }
38
+
39
+ # Fix the permission bits on generated files
40
+ function fastvelocity_fix_permission_bits($file){
41
+ if(function_exists('stat') && fvm_function_available('stat')) {
42
+ if ($stat = @stat(dirname($file))) {
43
+ $perms = $stat['mode'] & 0007777;
44
+ @chmod($file, $perms);
45
+ clearstatcache();
46
+ return true;
47
+ }
48
+ }
49
+
50
+
51
+ # get permissions from parent directory
52
+ $perms = 0777;
53
+ if(function_exists('stat') && fvm_function_available('stat')) {
54
+ if ($stat = @stat(dirname($file))) { $perms = $stat['mode'] & 0007777; }
55
+ }
56
+
57
+ if (file_exists($file)){
58
+ if ($perms != ($perms & ~umask())){
59
+ $folder_parts = explode( '/', substr( $file, strlen(dirname($file)) + 1 ) );
60
+ for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
61
+ @chmod(dirname($file) . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $perms );
62
+ }
63
+ }
64
+ }
65
+
66
+ return true;
67
+ }
68
+
69
+
70
  # get cache directories and urls
71
  function fvm_cachepath() {
72
 
82
  }
83
 
84
  # create
85
+ $uploadsdir = rtrim($upload['basedir'], '/');
86
+ $uploadsurl = rtrim($upload['baseurl'], '/');
87
+ $cachebase = $uploadsdir.'/fvm';
88
+ $cachedir = $uploadsdir.'/fvm/out';
89
+ $tmpdir = $uploadsdir.'/fvm/tmp';
90
+ $cachedirurl = $uploadsurl.'/fvm/out';
91
+ $headerdir = $uploadsdir.'/fvm/header';
92
+
93
+ # get permissions from uploads directory
94
+ $dir_perms = 0777;
95
+ if(function_exists('stat') && fvm_function_available('stat')) {
96
+ if ($stat = @stat($uploadsdir)) { $dir_perms = $stat['mode'] & 0007777; }
97
+ }
98
 
99
+ # mkdir and check if umask requires chmod
100
+ $dirs = array($cachebase, $cachedir, $tmpdir, $headerdir);
101
+ foreach ($dirs as $target) {
102
+ if (@mkdir($target, $dir_perms, true)){
103
+ if ($dir_perms != ($dir_perms & ~umask())){
104
+ $folder_parts = explode( '/', substr( $target, strlen(dirname($target)) + 1 ) );
105
+ for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
106
+ @chmod(dirname($target) . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
107
+ }
108
+ }
109
+ } else {
110
+ # fallback
111
+ if(!is_dir($target)) { wp_mkdir_p($target); }
112
+ }
113
+ }
114
 
115
  # return
116
  return array('cachebase'=>$cachebase,'tmpdir'=>$tmpdir, 'cachedir'=>$cachedir, 'cachedirurl'=>$cachedirurl, 'headerdir'=>$headerdir);
421
  # get cache size and count
422
  function fastvelocity_get_cachestats() {
423
  clearstatcache();
424
+ $cachepath = fvm_cachepath();
425
+ $cachebase = $cachepath['cachebase'];
426
+ if(is_dir($cachebase)) {
427
+ $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cachebase, FilesystemIterator::SKIP_DOTS));
428
+ $size = 0;
429
+ foreach ($dir as $file) {
430
+ $size += $file->getSize();
431
+ }
432
+ return fastvelocity_format_filesize($size);
433
+ } else {
434
+ return 'Error: '.$cachebase. ' is not a directory!';
435
  }
 
436
  }
437
 
438
  # remove default HTTP headers
909
  $tmpdir = $cachepath['tmpdir'];
910
  $f = $tmpdir.'/'.$key.'.transient';
911
  file_put_contents($f, $code);
912
+ fastvelocity_fix_permission_bits($f);
913
  return true;
914
  }
915
 
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: Alignak
3
  Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, CSS Merging, JS Merging, CSS Minification, JS Minification, Speed Optimization, HTML Minification, Performance, Optimization, Speed, Fast
4
  Requires at least: 4.5
5
- Stable tag: 2.4.7
6
  Tested up to: 5.0
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -202,6 +202,10 @@ If you would like to donate any amount to the plugin author (thank you in advanc
202
 
203
  == Changelog ==
204
 
 
 
 
 
205
  = 2.4.7 [2018.12.06] =
206
  * added better default options after new install
207
  * added option to preserve FVM settings on deactivation
2
  Contributors: Alignak
3
  Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, CSS Merging, JS Merging, CSS Minification, JS Minification, Speed Optimization, HTML Minification, Performance, Optimization, Speed, Fast
4
  Requires at least: 4.5
5
+ Stable tag: 2.4.8
6
  Tested up to: 5.0
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
202
 
203
  == Changelog ==
204
 
205
+ = 2.4.8 [2018.12.07] =
206
+ * changed the file permissions for the generated cache directory and files, to match the uploads directory
207
+ * added some extra checks for when PHP is running in safe mode
208
+
209
  = 2.4.7 [2018.12.06] =
210
  * added better default options after new install
211
  * added option to preserve FVM settings on deactivation