Explorar o código

#2553 PHP 7.4 compatibility issues

RomanL %!s(int64=6) %!d(string=hai) anos
pai
achega
0c13ccd37b

+ 0 - 2
inc/classes/BxDolBadgesQuery.php

@@ -23,8 +23,6 @@ class BxDolBadgesQuery extends BxDolDb
 
     public function getData($aParams = array(), &$aItems = false)
     {
-        $CNF = &$this->_oConfig->CNF;
-
         $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
 
         $sSelectClause = "`sc`.*";

+ 0 - 2
inc/classes/BxDolCategoriesQuery.php

@@ -23,8 +23,6 @@ class BxDolCategoriesQuery extends BxDolDb
 
     public function getData($aParams = array())
     {
-        $CNF = &$this->_oConfig->CNF;
-
         $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
 
         $sSelectClause = "`sc`.*";

+ 0 - 2
inc/classes/BxDolLabelQuery.php

@@ -23,8 +23,6 @@ class BxDolLabelQuery extends BxDolDb
 
     public function getLabels($aParams = array())
     {
-        $CNF = &$this->_oConfig->CNF;
-
         $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
 
         $sSelectClause = "`tl`.*";

+ 2 - 5
inc/utils.inc.php

@@ -113,9 +113,6 @@ function bx_process_input ($mixedData, $iDataType = BX_DATA_TEXT, $mixedParams =
         return $mixedData;
     }
 
-    if (get_magic_quotes_gpc() && $isCheckMagicQuotes)
-        $mixedData = stripslashes($mixedData);
-
     switch ($iDataType) {
     case BX_DATA_INT:
         return filter_var(trim($mixedData), FILTER_VALIDATE_INT);
@@ -1054,7 +1051,7 @@ function bx_parse_html_tag ($sContent, $sTag, $sAttrNameName, $sAttrNameValue, $
 function return_bytes($val)
 {
     $val = trim($val);
-    $last = strtolower($val{strlen($val)-1});
+    $last = strtolower($val[strlen($val)-1]);
     $val = (int)$val;
     switch($last) {
         // The 'G' modifier is available since PHP 5.1.0
@@ -1082,7 +1079,7 @@ function genRndPwd($iLength = 8, $bSpecialCharacters = true)
 
     for($i = 0; $i < $iLength; $i++) {
         $x = mt_rand(0, strlen($sChars) -1);
-        $sPassword .= $sChars{$x};
+        $sPassword .= $sChars[$x];
     }
 
     return $sPassword;

+ 43 - 28
plugins/matthiasmullie/minify/CSS.php

@@ -217,6 +217,8 @@ class CSS extends Minify
             // grab referenced file & minify it (which may include importing
             // yet other @import statements recursively)
             $minifier = new static($importPath);
+            $minifier->setMaxImportSize($this->maxImportSize);
+            $minifier->setImportExtensions($this->importExtensions);
             $importContent = $minifier->execute($source, $parents);
 
             // check if this is only valid for certain media
@@ -305,10 +307,11 @@ class CSS extends Minify
              */
             $this->extractStrings();
             $this->stripComments();
+            $this->extractCalcs();
             $css = $this->replace($css);
 
             $css = $this->stripWhitespace($css);
-            $css = $this->shortenHex($css);
+            $css = $this->shortenColors($css);
             $css = $this->shortenZeroes($css);
             $css = $this->shortenFontWeights($css);
             $css = $this->stripEmptyTags($css);
@@ -479,12 +482,16 @@ class CSS extends Minify
      *
      * @return string
      */
-    protected function shortenHex($content)
+    protected function shortenColors($content)
     {
-        $content = preg_replace('/(?<=[: ])#([0-9a-z])\\1([0-9a-z])\\2([0-9a-z])\\3(?=[; }])/i', '#$1$2$3', $content);
+        $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);
+
+        // remove alpha channel if it's pointless...
+        $content = preg_replace('/(?<=[: ])#([0-9a-z]{6})ff?(?=[; }])/i', '#$1', $content);
+        $content = preg_replace('/(?<=[: ])#([0-9a-z]{3})f?(?=[; }])/i', '#$1', $content);
 
-        // we can shorten some even more by replacing them with their color name
         $colors = array(
+            // we can shorten some even more by replacing them with their color name
             '#F0FFFF' => 'azure',
             '#F5F5DC' => 'beige',
             '#A52A2A' => 'brown',
@@ -512,10 +519,13 @@ class CSS extends Minify
             '#FF6347' => 'tomato',
             '#EE82EE' => 'violet',
             '#F5DEB3' => 'wheat',
+            // or the other way around
+            'WHITE' => '#fff',
+            'BLACK' => '#000',
         );
 
         return preg_replace_callback(
-            '/(?<=[: ])('.implode(array_keys($colors), '|').')(?=[; }])/i',
+            '/(?<=[: ])('.implode('|', array_keys($colors)).')(?=[; }])/i',
             function ($match) use ($colors) {
                 return $colors[strtoupper($match[0])];
             },
@@ -557,11 +567,7 @@ class CSS extends Minify
         // `5px - 0px` is valid, but `5px - 0` is not
         // `10px * 0` is valid (equates to 0), and so is `10 * 0px`, but
         // `10 * 0` is invalid
-        // best to just leave `calc()`s alone, even if they could be optimized
-        // (which is a whole other undertaking, where units & order of
-        // operations all need to be considered...)
-        $calcs = $this->findCalcs($content);
-        $content = str_replace($calcs, array_keys($calcs), $content);
+        // we've extracted calcs earlier, so we don't need to worry about this
 
         // reusable bits of code throughout these regexes:
         // before & after are used to make sure we don't match lose unintended
@@ -598,9 +604,6 @@ class CSS extends Minify
         $content = preg_replace('/flex:([0-9]+\s[0-9]+\s)0([;\}])/', 'flex:${1}0%${2}', $content);
         $content = preg_replace('/flex-basis:0([;\}])/', 'flex-basis:0%${1}', $content);
 
-        // restore `calc()` expressions
-        $content = str_replace(array_keys($calcs), $calcs, $content);
-
         return $content;
     }
 
@@ -624,6 +627,17 @@ class CSS extends Minify
      */
     protected function stripComments()
     {
+        // PHP only supports $this inside anonymous functions since 5.4
+        $minifier = $this;
+        $callback = function ($match) use ($minifier) {
+            $count = count($minifier->extracted);
+            $placeholder = '/*'.$count.'*/';
+            $minifier->extracted[$placeholder] = $match[0];
+
+            return $placeholder;
+        };
+        $this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
+
         $this->registerPattern('/\/\*.*?\*\//s', '');
     }
 
@@ -646,8 +660,8 @@ class CSS extends Minify
         // remove whitespace around meta characters
         // inspired by stackoverflow.com/questions/15195750/minify-compress-css-with-regex
         $content = preg_replace('/\s*([\*$~^|]?+=|[{};,>~]|!important\b)\s*/', '$1', $content);
-        $content = preg_replace('/([\[(:])\s+/', '$1', $content);
-        $content = preg_replace('/\s+([\]\)])/', '$1', $content);
+        $content = preg_replace('/([\[(:>\+])\s+/', '$1', $content);
+        $content = preg_replace('/\s+([\]\)>\+])/', '$1', $content);
         $content = preg_replace('/\s+(:)(?![^\}]*\{)/', '$1', $content);
 
         // whitespace around + and - can only be stripped inside some pseudo-
@@ -664,18 +678,13 @@ class CSS extends Minify
     }
 
     /**
-     * Find all `calc()` occurrences.
-     *
-     * @param string $content The CSS content to find `calc()`s in.
-     *
-     * @return string[]
+     * Replace all `calc()` occurrences.
      */
-    protected function findCalcs($content)
+    protected function extractCalcs()
     {
-        $results = array();
-        preg_match_all('/calc(\(.+?)(?=$|;|calc\()/', $content, $matches, PREG_SET_ORDER);
-
-        foreach ($matches as $match) {
+        // PHP only supports $this inside anonymous functions since 5.4
+        $minifier = $this;
+        $callback = function ($match) use ($minifier) {
             $length = strlen($match[1]);
             $expr = '';
             $opened = 0;
@@ -689,11 +698,17 @@ class CSS extends Minify
                     break;
                 }
             }
+            $rest = str_replace($expr, '', $match[1]);
+            $expr = trim(substr($expr, 1, -1));
 
-            $results['calc('.count($results).')'] = 'calc'.$expr;
-        }
+            $count = count($minifier->extracted);
+            $placeholder = 'calc('.$count.')';
+            $minifier->extracted[$placeholder] = 'calc('.$expr.')';
+
+            return $placeholder.$rest;
+        };
 
-        return $results;
+        $this->registerPattern('/calc(\(.+?)(?=$|;|calc\()/', $callback);
     }
 
     /**

+ 19 - 5
plugins/matthiasmullie/minify/JS.php

@@ -195,11 +195,21 @@ class JS extends Minify
      */
     protected function stripComments()
     {
-        // single-line comments
-        $this->registerPattern('/\/\/.*$/m', '');
+        // PHP only supports $this inside anonymous functions since 5.4
+        $minifier = $this;
+        $callback = function ($match) use ($minifier) {
+            $count = count($minifier->extracted);
+            $placeholder = '/*'.$count.'*/';
+            $minifier->extracted[$placeholder] = $match[0];
 
+            return $placeholder;
+        };
         // multi-line comments
+        $this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
         $this->registerPattern('/\/\*.*?\*\//s', '');
+
+        // single-line comments
+        $this->registerPattern('/\/\/.*$/m', '');
     }
 
     /**
@@ -238,7 +248,7 @@ class JS extends Minify
         // closing the regex)
         // then also ignore bare `/` inside `[]`, where they don't need to be
         // escaped: anything inside `[]` can be ignored safely
-        $pattern = '\\/(?:[^\\[\\/\\\\\n\r]+|(?:\\\\.)+|(?:\\[(?:[^\\]\\\\\n\r]+|(?:\\\\.)+)+\\])+)++\\/[gimuy]*';
+        $pattern = '\\/(?!\*)(?:[^\\[\\/\\\\\n\r]++|(?:\\\\.)++|(?:\\[(?:[^\\]\\\\\n\r]++|(?:\\\\.)++)++\\])++)++\\/[gimuy]*';
 
         // a regular expression can only be followed by a few operators or some
         // of the RegExp methods (a `\` followed by a variable or value is
@@ -335,7 +345,9 @@ class JS extends Minify
             array(
                 '/('.implode('|', $operatorsBefore).')\s+/',
                 '/\s+('.implode('|', $operatorsAfter).')/',
-            ), '\\1', $content
+            ),
+            '\\1',
+            $content
         );
 
         // make sure + and - can't be mistaken for, or joined into ++ and --
@@ -343,7 +355,9 @@ class JS extends Minify
             array(
                 '/(?<![\+\-])\s*([\+\-])(?![\+\-])/',
                 '/(?<![\+\-])([\+\-])\s*(?![\+\-])/',
-            ), '\\1', $content
+            ),
+            '\\1',
+            $content
         );
 
         // collapse whitespace around reserved words into single space

+ 1 - 1
plugins/matthiasmullie/minify/Minify.php

@@ -241,7 +241,7 @@ abstract class Minify
 
                 // we can safely ignore patterns for positions we've unset earlier,
                 // because we know these won't show up anymore
-                if (!isset($positions[$i])) {
+                if (array_key_exists($i, $positions) == false) {
                     continue;
                 }
 

+ 1 - 3
template/scripts/BxBaseAuditGrid.php

@@ -136,8 +136,6 @@ class BxBaseAuditGrid extends BxDolAuditGrid
         if(empty($sFilterName) || empty($aFilterValues))
             return '';
 
-		$CNF = &$this->_oModule->_oConfig->CNF;		
-
 		foreach($aFilterValues as $sKey => $sValue)
 			$aFilterValues[$sKey] = _t($sValue);
 
@@ -149,7 +147,7 @@ class BxBaseAuditGrid extends BxDolAuditGrid
                 'onChange' => 'javascript:' . $this->sJsObject . '.onChangeFilter(this)'
             ),
             'value' => $sFilterValue,
-            'values' => array_merge(array('' => _t($CNF['T']['filter_item_select_one_' . $sFilterName])), $aFilterValues)
+            'values' => $aFilterValues
         );
 
         $oForm = new BxTemplFormView(array());