Fast Velocity Minify - Version 2.4.9

Version Description

[2018.12.14] = * improved the google fonts merging to only allow existing google fonts (no more google fonts 404 errors due to the merging of the fonts) * downgraded PHP Minify to version 1.3.60 due to someone reporting a server error with the new version

Download this release

Release Info

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

Code changes from version 2.4.8 to 2.4.9

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.8
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
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.9
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
inc/functions.php CHANGED
@@ -23,6 +23,11 @@ use MatthiasMullie\Minify;
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) {
@@ -650,6 +655,23 @@ $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $
650
  }
651
 
652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
653
 
654
  # Concatenate Google Fonts tags (http://fonts.googleapis.com/css?...)
655
  function fastvelocity_min_concatenate_google_fonts($array) {
@@ -667,19 +689,29 @@ function fastvelocity_min_concatenate_google_fonts($array) {
667
  $font = trim(trim(trim(current($a)), ','));
668
 
669
  # reprocess if fonts are already concatenated in this url
670
- if(stristr($font, '|') !== FALSE) {
671
  $multiple = explode('|', $font);
672
  if (count($multiple) > 0) {
673
- foreach ($multiple as $f) {
674
- $families[] = trim($f);
 
 
 
675
  }
676
  }
677
  } else {
678
- $families[] = $font;
 
 
679
  }
680
  }
681
  }
682
 
 
 
 
 
 
683
  # process names, types, subsets
684
  $fonts = array();
685
  $subsets = array();
23
  # use HTML minification
24
  require_once ($plugindir . 'libs/mrclay/HTML.php');
25
 
26
+ # get list of allowed google fonts from the API (847 fonts on 2018-12-13)
27
+ # https://www.googleapis.com/webfonts/v1/webfonts?sort=alpha
28
+ # https://www.xcartmods.co.uk/google-fonts-list.php
29
+ $gfontswhitelist = array('ABeeZee','Abel','Abhaya Libre','Abril Fatface','Aclonica','Acme','Actor','Adamina','Advent Pro','Aguafina Script','Akronim','Aladin','Aldrich','Alef','Alegreya','Alegreya SC','Alegreya Sans','Alegreya Sans SC','Alex Brush','Alfa Slab One','Alice','Alike','Alike Angular','Allan','Allerta','Allerta Stencil','Allura','Almendra','Almendra Display','Almendra SC','Amarante','Amaranth','Amatic SC','Amatica SC','Amethysta','Amiko','Amiri','Amita','Anaheim','Andada','Andika','Angkor','Annie Use Your Telescope','Anonymous Pro','Antic','Antic Didone','Antic Slab','Anton','Arapey','Arbutus','Arbutus Slab','Architects Daughter','Archivo','Archivo Black','Archivo Narrow','Aref Ruqaa','Arima Madurai','Arimo','Arizonia','Armata','Arsenal','Artifika','Arvo','Arya','Asap','Asap Condensed','Asar','Asset','Assistant','Astloch','Asul','Athiti','Atma','Atomic Age','Aubrey','Audiowide','Autour One','Average','Average Sans','Averia Gruesa Libre','Averia Libre','Averia Sans Libre','Averia Serif Libre','Bad Script','Bahiana','Baloo','Baloo Bhai','Baloo Bhaijaan','Baloo Bhaina','Baloo Chettan','Baloo Da','Baloo Paaji','Baloo Tamma','Baloo Tammudu','Baloo Thambi','Balthazar','Bangers','Barrio','Basic','Battambang','Baumans','Bayon','Belgrano','Bellefair','Belleza','BenchNine','Bentham','Berkshire Swash','Bevan','Bigelow Rules','Bigshot One','Bilbo','Bilbo Swash Caps','BioRhyme','BioRhyme Expanded','Biryani','Bitter','Black Ops One','Bokor','Bonbon','Boogaloo','Bowlby One','Bowlby One SC','Brawler','Bree Serif','Bubblegum Sans','Bubbler One','Buda','Buenard','Bungee','Bungee Hairline','Bungee Inline','Bungee Outline','Bungee Shade','Butcherman','Butterfly Kids','Cabin','Cabin Condensed','Cabin Sketch','Caesar Dressing','Cagliostro','Cairo','Calligraffitti','Cambay','Cambo','Candal','Cantarell','Cantata One','Cantora One','Capriola','Cardo','Carme','Carrois Gothic','Carrois Gothic SC','Carter One','Catamaran','Caudex','Caveat','Caveat Brush','Cedarville Cursive','Ceviche One','Changa','Changa One','Chango','Chathura','Chau Philomene One','Chela One','Chelsea Market','Chenla','Cherry Cream Soda','Cherry Swash','Chewy','Chicle','Chivo','Chonburi','Cinzel','Cinzel Decorative','Clicker Script','Coda','Coda Caption','Codystar','Coiny','Combo','Comfortaa','Coming Soon','Concert One','Condiment','Content','Contrail One','Convergence','Cookie','Copse','Corben','Cormorant','Cormorant Garamond','Cormorant Infant','Cormorant SC','Cormorant Unicase','Cormorant Upright','Courgette','Cousine','Coustard','Covered By Your Grace','Crafty Girls','Creepster','Crete Round','Crimson Text','Croissant One','Crushed','Cuprum','Cutive','Cutive Mono','Damion','Dancing Script','Dangrek','David Libre','Dawning of a New Day','Days One','Dekko','Delius','Delius Swash Caps','Delius Unicase','Della Respira','Denk One','Devonshire','Dhurjati','Didact Gothic','Diplomata','Diplomata SC','Domine','Donegal One','Doppio One','Dorsa','Dosis','Dr Sugiyama','Droid Sans','Droid Sans Mono','Droid Serif','Duru Sans','Dynalight','EB Garamond','Eagle Lake','Eater','Economica','Eczar','El Messiri','Electrolize','Elsie','Elsie Swash Caps','Emblema One','Emilys Candy','Encode Sans','Encode Sans Condensed','Encode Sans Expanded','Encode Sans Semi Condensed','Encode Sans Semi Expanded','Engagement','Englebert','Enriqueta','Erica One','Esteban','Euphoria Script','Ewert','Exo','Exo 2','Expletus Sans','Fanwood Text','Farsan','Fascinate','Fascinate Inline','Faster One','Fasthand','Fauna One','Faustina','Federant','Federo','Felipa','Fenix','Finger Paint','Fira Mono','Fira Sans','Fira Sans Condensed','Fira Sans Extra Condensed','Fjalla One','Fjord One','Flamenco','Flavors','Fondamento','Fontdiner Swanky','Forum','Francois One','Frank Ruhl Libre','Freckle Face','Fredericka the Great','Fredoka One','Freehand','Fresca','Frijole','Fruktur','Fugaz One','GFS Didot','GFS Neohellenic','Gabriela','Gafata','Galada','Galdeano','Galindo','Gentium Basic','Gentium Book Basic','Geo','Geostar','Geostar Fill','Germania One','Gidugu','Gilda Display','Give You Glory','Glass Antiqua','Glegoo','Gloria Hallelujah','Goblin One','Gochi Hand','Gorditas','Goudy Bookletter 1911','Graduate','Grand Hotel','Gravitas One','Great Vibes','Griffy','Gruppo','Gudea','Gurajada','Habibi','Halant','Hammersmith One','Hanalei','Hanalei Fill','Handlee','Hanuman','Happy Monkey','Harmattan','Headland One','Heebo','Henny Penny','Herr Von Muellerhoff','Hind','Hind Guntur','Hind Madurai','Hind Siliguri','Hind Vadodara','Holtwood One SC','Homemade Apple','Homenaje','IM Fell DW Pica','IM Fell DW Pica SC','IM Fell Double Pica','IM Fell Double Pica SC','IM Fell English','IM Fell English SC','IM Fell French Canon','IM Fell French Canon SC','IM Fell Great Primer','IM Fell Great Primer SC','Iceberg','Iceland','Imprima','Inconsolata','Inder','Indie Flower','Inika','Inknut Antiqua','Irish Grover','Istok Web','Italiana','Italianno','Itim','Jacques Francois','Jacques Francois Shadow','Jaldi','Jim Nightshade','Jockey One','Jolly Lodger','Jomhuria','Josefin Sans','Josefin Slab','Joti One','Judson','Julee','Julius Sans One','Junge','Jura','Just Another Hand','Just Me Again Down Here','Kadwa','Kalam','Kameron','Kanit','Kantumruy','Karla','Karma','Katibeh','Kaushan Script','Kavivanar','Kavoon','Kdam Thmor','Keania One','Kelly Slab','Kenia','Khand','Khmer','Khula','Kite One','Knewave','Kotta One','Koulen','Kranky','Kreon','Kristi','Krona One','Kumar One','Kumar One Outline','Kurale','La Belle Aurore','Laila','Lakki Reddy','Lalezar','Lancelot','Lateef','Lato','League Script','Leckerli One','Ledger','Lekton','Lemon','Lemonada','Libre Barcode 128','Libre Barcode 128 Text','Libre Barcode 39','Libre Barcode 39 Extended','Libre Barcode 39 Extended Text','Libre Barcode 39 Text','Libre Baskerville','Libre Franklin','Life Savers','Lilita One','Lily Script One','Limelight','Linden Hill','Lobster','Lobster Two','Londrina Outline','Londrina Shadow','Londrina Sketch','Londrina Solid','Lora','Love Ya Like A Sister','Loved by the King','Lovers Quarrel','Luckiest Guy','Lusitana','Lustria','Macondo','Macondo Swash Caps','Mada','Magra','Maiden Orange','Maitree','Mako','Mallanna','Mandali','Manuale','Marcellus','Marcellus SC','Marck Script','Margarine','Marko One','Marmelad','Martel','Martel Sans','Marvel','Mate','Mate SC','Maven Pro','McLaren','Meddon','MedievalSharp','Medula One','Meera Inimai','Megrim','Meie Script','Merienda','Merienda One','Merriweather','Merriweather Sans','Metal','Metal Mania','Metamorphous','Metrophobic','Michroma','Milonga','Miltonian','Miltonian Tattoo','Miniver','Miriam Libre','Mirza','Miss Fajardose','Mitr','Modak','Modern Antiqua','Mogra','Molengo','Molle','Monda','Monofett','Monoton','Monsieur La Doulaise','Montaga','Montez','Montserrat','Montserrat Alternates','Montserrat Subrayada','Moul','Moulpali','Mountains of Christmas','Mouse Memoirs','Mr Bedfort','Mr Dafoe','Mr De Haviland','Mrs Saint Delafield','Mrs Sheppards','Mukta','Mukta Mahee','Mukta Malar','Mukta Vaani','Muli','Mystery Quest','NTR','Neucha','Neuton','New Rocker','News Cycle','Niconne','Nixie One','Nobile','Nokora','Norican','Nosifer','Nothing You Could Do','Noticia Text','Noto Sans','Noto Serif','Nova Cut','Nova Flat','Nova Mono','Nova Oval','Nova Round','Nova Script','Nova Slim','Nova Square','Numans','Nunito','Nunito Sans','Odor Mean Chey','Offside','Old Standard TT','Oldenburg','Oleo Script','Oleo Script Swash Caps','Open Sans','Open Sans Condensed','Oranienbaum','Orbitron','Oregano','Orienta','Original Surfer','Oswald','Over the Rainbow','Overlock','Overlock SC','Overpass','Overpass Mono','Ovo','Oxygen','Oxygen Mono','PT Mono','PT Sans','PT Sans Caption','PT Sans Narrow','PT Serif','PT Serif Caption','Pacifico','Padauk','Palanquin','Palanquin Dark','Pangolin','Paprika','Parisienne','Passero One','Passion One','Pathway Gothic One','Patrick Hand','Patrick Hand SC','Pattaya','Patua One','Pavanam','Paytone One','Peddana','Peralta','Permanent Marker','Petit Formal Script','Petrona','Philosopher','Piedra','Pinyon Script','Pirata One','Plaster','Play','Playball','Playfair Display','Playfair Display SC','Podkova','Poiret One','Poller One','Poly','Pompiere','Pontano Sans','Poppins','Port Lligat Sans','Port Lligat Slab','Pragati Narrow','Prata','Preahvihear','Press Start 2P','Pridi','Princess Sofia','Prociono','Prompt','Prosto One','Proza Libre','Puritan','Purple Purse','Quando','Quantico','Quattrocento','Quattrocento Sans','Questrial','Quicksand','Quintessential','Qwigley','Racing Sans One','Radley','Rajdhani','Rakkas','Raleway','Raleway Dots','Ramabhadra','Ramaraja','Rambla','Rammetto One','Ranchers','Rancho','Ranga','Rasa','Rationale','Ravi Prakash','Redressed','Reem Kufi','Reenie Beanie','Revalia','Rhodium Libre','Ribeye','Ribeye Marrow','Righteous','Risque','Roboto','Roboto Condensed','Roboto Mono','Roboto Slab','Rochester','Rock Salt','Rokkitt','Romanesco','Ropa Sans','Rosario','Rosarivo','Rouge Script','Rozha One','Rubik','Rubik Mono One','Ruda','Rufina','Ruge Boogie','Ruluko','Rum Raisin','Ruslan Display','Russo One','Ruthie','Rye','Sacramento','Sahitya','Sail','Saira','Saira Condensed','Saira Extra Condensed','Saira Semi Condensed','Salsa','Sanchez','Sancreek','Sansita','Sarala','Sarina','Sarpanch','Satisfy','Scada','Scheherazade','Schoolbell','Scope One','Seaweed Script','Secular One','Sedgwick Ave','Sedgwick Ave Display','Sevillana','Seymour One','Shadows Into Light','Shadows Into Light Two','Shanti','Share','Share Tech','Share Tech Mono','Shojumaru','Short Stack','Shrikhand','Siemreap','Sigmar One','Signika','Signika Negative','Simonetta','Sintony','Sirin Stencil','Six Caps','Skranji','Slabo 13px','Slabo 27px','Slackey','Smokum','Smythe','Sniglet','Snippet','Snowburst One','Sofadi One','Sofia','Sonsie One','Sorts Mill Goudy','Source Code Pro','Source Sans Pro','Source Serif Pro','Space Mono','Special Elite','Spectral','Spicy Rice','Spinnaker','Spirax','Squada One','Sree Krushnadevaraya','Sriracha','Stalemate','Stalinist One','Stardos Stencil','Stint Ultra Condensed','Stint Ultra Expanded','Stoke','Strait','Sue Ellen Francisco','Suez One','Sumana','Sunshiney','Supermercado One','Sura','Suranna','Suravaram','Suwannaphum','Swanky and Moo Moo','Syncopate','Tangerine','Taprom','Tauri','Taviraj','Teko','Telex','Tenali Ramakrishna','Tenor Sans','Text Me One','The Girl Next Door','Tienne','Tillana','Timmana','Tinos','Titan One','Titillium Web','Trade Winds','Trirong','Trocchi','Trochut','Trykker','Tulpen One','Ubuntu','Ubuntu Condensed','Ubuntu Mono','Ultra','Uncial Antiqua','Underdog','Unica One','UnifrakturCook','UnifrakturMaguntia','Unkempt','Unlock','Unna','VT323','Vampiro One','Varela','Varela Round','Vast Shadow','Vesper Libre','Vibur','Vidaloka','Viga','Voces','Volkhov','Vollkorn','Voltaire','Waiting for the Sunrise','Wallpoet','Walter Turncoat','Warnes','Wellfleet','Wendy One','Wire One','Work Sans','Yanone Kaffeesatz','Yantramanav','Yatra One','Yellowtail','Yeseva One','Yesteryear','Yrsa','Zeyada','Zilla Slab','Zilla Slab Highlight');
30
+
31
 
32
  # check if php has disabled some functions by default
33
  function fvm_function_available($func) {
655
  }
656
 
657
 
658
+ # check if the google font exist or not
659
+ function fastvelocity_min_concatenate_google_fonts_allowed($font) {
660
+ global $gfontswhitelist;
661
+
662
+ #normalize
663
+ $gfontswhitelist = array_map('strtolower', $gfontswhitelist);
664
+ $font = strtolower($font);
665
+
666
+ # check
667
+ if(in_array($font, $gfontswhitelist)) {
668
+ return true;
669
+ }
670
+
671
+ # fallback
672
+ return false;
673
+ }
674
+
675
 
676
  # Concatenate Google Fonts tags (http://fonts.googleapis.com/css?...)
677
  function fastvelocity_min_concatenate_google_fonts($array) {
689
  $font = trim(trim(trim(current($a)), ','));
690
 
691
  # reprocess if fonts are already concatenated in this url
692
+ if(stristr($font, '|') !== false) {
693
  $multiple = explode('|', $font);
694
  if (count($multiple) > 0) {
695
+ foreach ($multiple as $f) {
696
+ $f = trim($f);
697
+ if(fastvelocity_min_concatenate_google_fonts_allowed($font) == true) {
698
+ $families[] = trim($f);
699
+ }
700
  }
701
  }
702
  } else {
703
+ if(fastvelocity_min_concatenate_google_fonts_allowed($font) == true) {
704
+ $families[] = $font;
705
+ }
706
  }
707
  }
708
  }
709
 
710
+ # return if empty
711
+ if(count($families) == 0) {
712
+ return false;
713
+ }
714
+
715
  # process names, types, subsets
716
  $fonts = array();
717
  $subsets = array();
libs/matthiasmullie/minify/src/CSS.php CHANGED
@@ -217,8 +217,6 @@ class CSS extends Minify
217
  // grab referenced file & minify it (which may include importing
218
  // yet other @import statements recursively)
219
  $minifier = new static($importPath);
220
- $minifier->setMaxImportSize($this->maxImportSize);
221
- $minifier->setImportExtensions($this->importExtensions);
222
  $importContent = $minifier->execute($source, $parents);
223
 
224
  // check if this is only valid for certain media
@@ -307,11 +305,10 @@ class CSS extends Minify
307
  */
308
  $this->extractStrings();
309
  $this->stripComments();
310
- $this->extractCalcs();
311
  $css = $this->replace($css);
312
 
313
  $css = $this->stripWhitespace($css);
314
- $css = $this->shortenColors($css);
315
  $css = $this->shortenZeroes($css);
316
  $css = $this->shortenFontWeights($css);
317
  $css = $this->stripEmptyTags($css);
@@ -482,16 +479,12 @@ class CSS extends Minify
482
  *
483
  * @return string
484
  */
485
- protected function shortenColors($content)
486
  {
487
- $content = preg_replace('/(?<=[: ])#([0-9a-z])\\1([0-9a-z])\\2([0-9a-z])\\3(?:([0-9a-z])\\4)?(?=[; }])/i', '#$1$2$3$4', $content);
488
-
489
- // remove alpha channel if it's pointless...
490
- $content = preg_replace('/(?<=[: ])#([0-9a-z]{6})ff?(?=[; }])/i', '#$1', $content);
491
- $content = preg_replace('/(?<=[: ])#([0-9a-z]{3})f?(?=[; }])/i', '#$1', $content);
492
 
 
493
  $colors = array(
494
- // we can shorten some even more by replacing them with their color name
495
  '#F0FFFF' => 'azure',
496
  '#F5F5DC' => 'beige',
497
  '#A52A2A' => 'brown',
@@ -519,9 +512,6 @@ class CSS extends Minify
519
  '#FF6347' => 'tomato',
520
  '#EE82EE' => 'violet',
521
  '#F5DEB3' => 'wheat',
522
- // or the other way around
523
- 'WHITE' => '#fff',
524
- 'BLACK' => '#000',
525
  );
526
 
527
  return preg_replace_callback(
@@ -567,7 +557,11 @@ class CSS extends Minify
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
@@ -604,6 +598,9 @@ class CSS extends Minify
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;
608
  }
609
 
@@ -627,17 +624,6 @@ class CSS extends Minify
627
  */
628
  protected function stripComments()
629
  {
630
- // PHP only supports $this inside anonymous functions since 5.4
631
- $minifier = $this;
632
- $callback = function ($match) use ($minifier) {
633
- $count = count($minifier->extracted);
634
- $placeholder = '/*'.$count.'*/';
635
- $minifier->extracted[$placeholder] = $match[0];
636
-
637
- return $placeholder;
638
- };
639
- $this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
640
-
641
  $this->registerPattern('/\/\*.*?\*\//s', '');
642
  }
643
 
@@ -660,8 +646,8 @@ class CSS extends Minify
660
  // remove whitespace around meta characters
661
  // inspired by stackoverflow.com/questions/15195750/minify-compress-css-with-regex
662
  $content = preg_replace('/\s*([\*$~^|]?+=|[{};,>~]|!important\b)\s*/', '$1', $content);
663
- $content = preg_replace('/([\[(:>\+])\s+/', '$1', $content);
664
- $content = preg_replace('/\s+([\]\)>\+])/', '$1', $content);
665
  $content = preg_replace('/\s+(:)(?![^\}]*\{)/', '$1', $content);
666
 
667
  // whitespace around + and - can only be stripped inside some pseudo-
@@ -678,13 +664,18 @@ class CSS extends Minify
678
  }
679
 
680
  /**
681
- * Replace all `calc()` occurrences.
 
 
 
 
682
  */
683
- protected function extractCalcs()
684
  {
685
- // PHP only supports $this inside anonymous functions since 5.4
686
- $minifier = $this;
687
- $callback = function ($match) use ($minifier) {
 
688
  $length = strlen($match[1]);
689
  $expr = '';
690
  $opened = 0;
@@ -698,17 +689,11 @@ class CSS extends Minify
698
  break;
699
  }
700
  }
701
- $rest = str_replace($expr, '', $match[1]);
702
- $expr = trim(substr($expr, 1, -1));
703
-
704
- $count = count($minifier->extracted);
705
- $placeholder = 'calc('.$count.')';
706
- $minifier->extracted[$placeholder] = 'calc('.$expr.')';
707
 
708
- return $placeholder.$rest;
709
- };
710
 
711
- $this->registerPattern('/calc(\(.+?)(?=$|;|calc\()/', $callback);
712
  }
713
 
714
  /**
217
  // grab referenced file & minify it (which may include importing
218
  // yet other @import statements recursively)
219
  $minifier = new static($importPath);
 
 
220
  $importContent = $minifier->execute($source, $parents);
221
 
222
  // check if this is only valid for certain media
305
  */
306
  $this->extractStrings();
307
  $this->stripComments();
 
308
  $css = $this->replace($css);
309
 
310
  $css = $this->stripWhitespace($css);
311
+ $css = $this->shortenHex($css);
312
  $css = $this->shortenZeroes($css);
313
  $css = $this->shortenFontWeights($css);
314
  $css = $this->stripEmptyTags($css);
479
  *
480
  * @return string
481
  */
482
+ protected function shortenHex($content)
483
  {
484
+ $content = preg_replace('/(?<=[: ])#([0-9a-z])\\1([0-9a-z])\\2([0-9a-z])\\3(?=[; }])/i', '#$1$2$3', $content);
 
 
 
 
485
 
486
+ // we can shorten some even more by replacing them with their color name
487
  $colors = array(
 
488
  '#F0FFFF' => 'azure',
489
  '#F5F5DC' => 'beige',
490
  '#A52A2A' => 'brown',
512
  '#FF6347' => 'tomato',
513
  '#EE82EE' => 'violet',
514
  '#F5DEB3' => 'wheat',
 
 
 
515
  );
516
 
517
  return preg_replace_callback(
557
  // `5px - 0px` is valid, but `5px - 0` is not
558
  // `10px * 0` is valid (equates to 0), and so is `10 * 0px`, but
559
  // `10 * 0` is invalid
560
+ // best to just leave `calc()`s alone, even if they could be optimized
561
+ // (which is a whole other undertaking, where units & order of
562
+ // operations all need to be considered...)
563
+ $calcs = $this->findCalcs($content);
564
+ $content = str_replace($calcs, array_keys($calcs), $content);
565
 
566
  // reusable bits of code throughout these regexes:
567
  // before & after are used to make sure we don't match lose unintended
598
  $content = preg_replace('/flex:([0-9]+\s[0-9]+\s)0([;\}])/', 'flex:${1}0%${2}', $content);
599
  $content = preg_replace('/flex-basis:0([;\}])/', 'flex-basis:0%${1}', $content);
600
 
601
+ // restore `calc()` expressions
602
+ $content = str_replace(array_keys($calcs), $calcs, $content);
603
+
604
  return $content;
605
  }
606
 
624
  */
625
  protected function stripComments()
626
  {
 
 
 
 
 
 
 
 
 
 
 
627
  $this->registerPattern('/\/\*.*?\*\//s', '');
628
  }
629
 
646
  // remove whitespace around meta characters
647
  // inspired by stackoverflow.com/questions/15195750/minify-compress-css-with-regex
648
  $content = preg_replace('/\s*([\*$~^|]?+=|[{};,>~]|!important\b)\s*/', '$1', $content);
649
+ $content = preg_replace('/([\[(:])\s+/', '$1', $content);
650
+ $content = preg_replace('/\s+([\]\)])/', '$1', $content);
651
  $content = preg_replace('/\s+(:)(?![^\}]*\{)/', '$1', $content);
652
 
653
  // whitespace around + and - can only be stripped inside some pseudo-
664
  }
665
 
666
  /**
667
+ * Find all `calc()` occurrences.
668
+ *
669
+ * @param string $content The CSS content to find `calc()`s in.
670
+ *
671
+ * @return string[]
672
  */
673
+ protected function findCalcs($content)
674
  {
675
+ $results = array();
676
+ preg_match_all('/calc(\(.+?)(?=$|;|calc\()/', $content, $matches, PREG_SET_ORDER);
677
+
678
+ foreach ($matches as $match) {
679
  $length = strlen($match[1]);
680
  $expr = '';
681
  $opened = 0;
689
  break;
690
  }
691
  }
 
 
 
 
 
 
692
 
693
+ $results['calc('.count($results).')'] = 'calc'.$expr;
694
+ }
695
 
696
+ return $results;
697
  }
698
 
699
  /**
libs/matthiasmullie/minify/src/JS.php CHANGED
@@ -195,21 +195,11 @@ class JS extends Minify
195
  */
196
  protected function stripComments()
197
  {
198
- // PHP only supports $this inside anonymous functions since 5.4
199
- $minifier = $this;
200
- $callback = function ($match) use ($minifier) {
201
- $count = count($minifier->extracted);
202
- $placeholder = '/*'.$count.'*/';
203
- $minifier->extracted[$placeholder] = $match[0];
204
 
205
- return $placeholder;
206
- };
207
  // multi-line comments
208
- $this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
209
  $this->registerPattern('/\/\*.*?\*\//s', '');
210
-
211
- // single-line comments
212
- $this->registerPattern('/\/\/.*$/m', '');
213
  }
214
 
215
  /**
@@ -248,7 +238,7 @@ class JS extends Minify
248
  // closing the regex)
249
  // then also ignore bare `/` inside `[]`, where they don't need to be
250
  // escaped: anything inside `[]` can be ignored safely
251
- $pattern = '\\/(?!\*)(?:[^\\[\\/\\\\\n\r]++|(?:\\\\.)++|(?:\\[(?:[^\\]\\\\\n\r]++|(?:\\\\.)++)++\\])++)++\\/[gimuy]*';
252
 
253
  // a regular expression can only be followed by a few operators or some
254
  // of the RegExp methods (a `\` followed by a variable or value is
@@ -345,9 +335,7 @@ class JS extends Minify
345
  array(
346
  '/('.implode('|', $operatorsBefore).')\s+/',
347
  '/\s+('.implode('|', $operatorsAfter).')/',
348
- ),
349
- '\\1',
350
- $content
351
  );
352
 
353
  // make sure + and - can't be mistaken for, or joined into ++ and --
@@ -355,9 +343,7 @@ class JS extends Minify
355
  array(
356
  '/(?<![\+\-])\s*([\+\-])(?![\+\-])/',
357
  '/(?<![\+\-])([\+\-])\s*(?![\+\-])/',
358
- ),
359
- '\\1',
360
- $content
361
  );
362
 
363
  // collapse whitespace around reserved words into single space
195
  */
196
  protected function stripComments()
197
  {
198
+ // single-line comments
199
+ $this->registerPattern('/\/\/.*$/m', '');
 
 
 
 
200
 
 
 
201
  // multi-line comments
 
202
  $this->registerPattern('/\/\*.*?\*\//s', '');
 
 
 
203
  }
204
 
205
  /**
238
  // closing the regex)
239
  // then also ignore bare `/` inside `[]`, where they don't need to be
240
  // escaped: anything inside `[]` can be ignored safely
241
+ $pattern = '\\/(?:[^\\[\\/\\\\\n\r]+|(?:\\\\.)+|(?:\\[(?:[^\\]\\\\\n\r]+|(?:\\\\.)+)+\\])+)++\\/[gimuy]*';
242
 
243
  // a regular expression can only be followed by a few operators or some
244
  // of the RegExp methods (a `\` followed by a variable or value is
335
  array(
336
  '/('.implode('|', $operatorsBefore).')\s+/',
337
  '/\s+('.implode('|', $operatorsAfter).')/',
338
+ ), '\\1', $content
 
 
339
  );
340
 
341
  // make sure + and - can't be mistaken for, or joined into ++ and --
343
  array(
344
  '/(?<![\+\-])\s*([\+\-])(?![\+\-])/',
345
  '/(?<![\+\-])([\+\-])\s*(?![\+\-])/',
346
+ ), '\\1', $content
 
 
347
  );
348
 
349
  // collapse whitespace around reserved words into single space
libs/matthiasmullie/minify/src/Minify.php CHANGED
@@ -241,7 +241,7 @@ abstract class Minify
241
 
242
  // we can safely ignore patterns for positions we've unset earlier,
243
  // because we know these won't show up anymore
244
- if (array_key_exists($i, $positions) == false) {
245
  continue;
246
  }
247
 
241
 
242
  // we can safely ignore patterns for positions we've unset earlier,
243
  // because we know these won't show up anymore
244
+ if (!isset($positions[$i])) {
245
  continue;
246
  }
247
 
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.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,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.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
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.9
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.9 [2018.12.14] =
206
+ * improved the google fonts merging to only allow existing google fonts (no more google fonts 404 errors due to the merging of the fonts)
207
+ * downgraded PHP Minify to version 1.3.60 due to someone reporting a server error with the new version
208
+
209
  = 2.4.8 [2018.12.07] =
210
  * changed the file permissions for the generated cache directory and files, to match the uploads directory
211
  * added some extra checks for when PHP is running in safe mode