@@ -69,7 +69,7 @@ |
||
69 | 69 | |
70 | 70 | // For any reason if required IV size needs greater value. |
71 | 71 | if ($length > strlen($allowedIVString)) { |
72 | - $repeatedIVString = str_repeat($allowedIVString, ceil($length/strlen($allowedIVString))); |
|
72 | + $repeatedIVString = str_repeat($allowedIVString, ceil($length / strlen($allowedIVString))); |
|
73 | 73 | $allowedIVString .= $repeatedIVString; |
74 | 74 | } |
75 | 75 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | protected $inputLength = 0; |
70 | 70 | protected $lookAhead = null; |
71 | 71 | protected $output = ''; |
72 | - protected $lastByteOut = ''; |
|
72 | + protected $lastByteOut = ''; |
|
73 | 73 | protected $keptComment = ''; |
74 | 74 | |
75 | 75 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | $mbIntEnc = null; |
110 | - if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { |
|
110 | + if (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload') & 2)) { |
|
111 | 111 | $mbIntEnc = mb_internal_encoding(); |
112 | 112 | mb_internal_encoding('8bit'); |
113 | 113 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | && ($this->b === $this->lastByteOut)) { |
125 | 125 | // Don't delete this space. If we do, the addition/subtraction |
126 | 126 | // could be parsed as a post-increment |
127 | - } elseif (! $this->isAlphaNum($this->b)) { |
|
127 | + } elseif (!$this->isAlphaNum($this->b)) { |
|
128 | 128 | $command = self::ACTION_DELETE_A; |
129 | 129 | } |
130 | 130 | } elseif ($this->a === "\n") { |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | // otherwise mb_strpos will give WARNING |
136 | 136 | } elseif ($this->b === null |
137 | 137 | || (false === strpos('{[(+-!~', $this->b) |
138 | - && ! $this->isAlphaNum($this->b))) { |
|
138 | + && !$this->isAlphaNum($this->b))) { |
|
139 | 139 | $command = self::ACTION_DELETE_A; |
140 | 140 | } |
141 | - } elseif (! $this->isAlphaNum($this->a)) { |
|
141 | + } elseif (!$this->isAlphaNum($this->a)) { |
|
142 | 142 | if ($this->b === ' ' |
143 | 143 | || ($this->b === "\n" |
144 | 144 | && (false === strpos('}])+-\'', $this->a)))) { |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $this->a = $this->b; |
195 | 195 | if ($this->a === "'" || $this->a === '"') { // string literal |
196 | 196 | $str = $this->a; // in case needed for exception |
197 | - for(;;) { |
|
197 | + for (;;) { |
|
198 | 198 | $this->output .= $this->a; |
199 | 199 | $this->lastByteOut = $this->a; |
200 | 200 | |
@@ -224,11 +224,11 @@ discard block |
||
224 | 224 | if ($this->b === '/' && $this->isRegexpLiteral()) { |
225 | 225 | $this->output .= $this->a . $this->b; |
226 | 226 | $pattern = '/'; // keep entire pattern in case we need to report it in the exception |
227 | - for(;;) { |
|
227 | + for (;;) { |
|
228 | 228 | $this->a = $this->get(); |
229 | 229 | $pattern .= $this->a; |
230 | 230 | if ($this->a === '[') { |
231 | - for(;;) { |
|
231 | + for (;;) { |
|
232 | 232 | $this->output .= $this->a; |
233 | 233 | $this->a = $this->get(); |
234 | 234 | $pattern .= $this->a; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | if ($this->isEOF($this->a)) { |
244 | 244 | throw new JSMin_UnterminatedRegExpException( |
245 | 245 | "JSMin: Unterminated set in RegExp at byte " |
246 | - . $this->inputIndex .": {$pattern}"); |
|
246 | + . $this->inputIndex . ": {$pattern}"); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | } |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | { |
398 | 398 | $this->get(); |
399 | 399 | $comment = ''; |
400 | - for(;;) { |
|
400 | + for (;;) { |
|
401 | 401 | $get = $this->get(); |
402 | 402 | if ($get === '*') { |
403 | 403 | if ($this->peek() === '/') { // end of comment reached |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function __construct(CssParser $parser, array $configuration = null) |
136 | 136 | { |
137 | - $this->configuration = $configuration; |
|
138 | - $this->parser = $parser; |
|
137 | + $this->configuration = $configuration; |
|
138 | + $this->parser = $parser; |
|
139 | 139 | } |
140 | 140 | /** |
141 | 141 | * Returns the array of chars triggering the parser plugin. |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function __construct(CssMinifier $minifier, array $configuration = array()) |
198 | 198 | { |
199 | - $this->configuration = $configuration; |
|
200 | - $this->minifier = $minifier; |
|
199 | + $this->configuration = $configuration; |
|
200 | + $this->minifier = $minifier; |
|
201 | 201 | } |
202 | 202 | /** |
203 | 203 | * Apply the plugin to the token. |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public function __construct(CssMinifier $minifier, array $configuration = array()) |
252 | 252 | { |
253 | - $this->configuration = $configuration; |
|
254 | - $this->minifier = $minifier; |
|
253 | + $this->configuration = $configuration; |
|
254 | + $this->minifier = $minifier; |
|
255 | 255 | } |
256 | 256 | /** |
257 | 257 | * Filter the tokens. |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | { |
306 | 306 | $this->tokens = $tokens; |
307 | 307 | $this->indent = !is_null($indent) ? $indent : $this->indent; |
308 | - $this->padding = !is_null($padding) ? $padding : $this->padding; |
|
308 | + $this->padding = !is_null($padding) ? $padding : $this->padding; |
|
309 | 309 | } |
310 | 310 | /** |
311 | 311 | * Returns the array of aCssToken as formatted string. |
@@ -362,10 +362,10 @@ discard block |
||
362 | 362 | */ |
363 | 363 | public function __construct($property, $value, $isImportant = false, $isLast = false) |
364 | 364 | { |
365 | - $this->Property = $property; |
|
366 | - $this->Value = $value; |
|
367 | - $this->IsImportant = $isImportant; |
|
368 | - $this->IsLast = $isLast; |
|
365 | + $this->Property = $property; |
|
366 | + $this->Value = $value; |
|
367 | + $this->IsImportant = $isImportant; |
|
368 | + $this->IsLast = $isLast; |
|
369 | 369 | } |
370 | 370 | /** |
371 | 371 | * Implements {@link aCssToken::__toString()}. |
@@ -435,13 +435,13 @@ discard block |
||
435 | 435 | */ |
436 | 436 | public function __toString() |
437 | 437 | { |
438 | - $r = array(); |
|
438 | + $r = array(); |
|
439 | 439 | $level = 0; |
440 | 440 | for ($i = 0, $l = count($this->tokens); $i < $l; $i++) |
441 | 441 | { |
442 | 442 | $token = $this->tokens[$i]; |
443 | 443 | $class = get_class($token); |
444 | - $indent = str_repeat($this->indent, $level); |
|
444 | + $indent = str_repeat($this->indent, $level); |
|
445 | 445 | if ($class === "CssCommentToken") |
446 | 446 | { |
447 | 447 | $lines = array_map("trim", explode("\n", $token->Comment)); |
@@ -585,14 +585,14 @@ discard block |
||
585 | 585 | { |
586 | 586 | if (stripos($token->Value, "var") !== false && preg_match_all($this->reMatch, $token->Value, $m)) |
587 | 587 | { |
588 | - $mediaTypes = $token->MediaTypes; |
|
588 | + $mediaTypes = $token->MediaTypes; |
|
589 | 589 | if (!in_array("all", $mediaTypes)) |
590 | 590 | { |
591 | 591 | $mediaTypes[] = "all"; |
592 | 592 | } |
593 | 593 | for ($i = 0, $l = count($m[0]); $i < $l; $i++) |
594 | 594 | { |
595 | - $variable = trim($m[1][$i]); |
|
595 | + $variable = trim($m[1][$i]); |
|
596 | 596 | foreach ($mediaTypes as $mediaType) |
597 | 597 | { |
598 | 598 | if (isset($this->variables[$mediaType], $this->variables[$mediaType][$variable])) |
@@ -617,8 +617,7 @@ discard block |
||
617 | 617 | */ |
618 | 618 | public function getTriggerTokens() |
619 | 619 | { |
620 | - return array |
|
621 | - ( |
|
620 | + return array( |
|
622 | 621 | "CssAtFontFaceDeclarationToken", |
623 | 622 | "CssAtPageDeclarationToken", |
624 | 623 | "CssRulesetDeclarationToken" |
@@ -658,11 +657,11 @@ discard block |
||
658 | 657 | */ |
659 | 658 | public function apply(array &$tokens) |
660 | 659 | { |
661 | - $variables = array(); |
|
662 | - $defaultMediaTypes = array("all"); |
|
663 | - $mediaTypes = array(); |
|
664 | - $remove = array(); |
|
665 | - for($i = 0, $l = count($tokens); $i < $l; $i++) |
|
660 | + $variables = array(); |
|
661 | + $defaultMediaTypes = array("all"); |
|
662 | + $mediaTypes = array(); |
|
663 | + $remove = array(); |
|
664 | + for ($i = 0, $l = count($tokens); $i < $l; $i++) |
|
666 | 665 | { |
667 | 666 | // @variables at-rule block found |
668 | 667 | if (get_class($tokens[$i]) === "CssAtVariablesStartToken") |
@@ -677,7 +676,7 @@ discard block |
||
677 | 676 | } |
678 | 677 | } |
679 | 678 | // Read the variable declaration tokens |
680 | - for($i = $i; $i < $l; $i++) |
|
679 | + for ($i = $i; $i < $l; $i++) |
|
681 | 680 | { |
682 | 681 | // Found a variable declaration => read the variable values |
683 | 682 | if (get_class($tokens[$i]) === "CssAtVariablesDeclarationToken") |
@@ -698,9 +697,9 @@ discard block |
||
698 | 697 | } |
699 | 698 | } |
700 | 699 | // Variables in @variables at-rule blocks |
701 | - foreach($variables as $mediaType => $null) |
|
700 | + foreach ($variables as $mediaType => $null) |
|
702 | 701 | { |
703 | - foreach($variables[$mediaType] as $variable => $value) |
|
702 | + foreach ($variables[$mediaType] as $variable => $value) |
|
704 | 703 | { |
705 | 704 | // If a var() statement in a variable value found... |
706 | 705 | if (stripos($value, "var") !== false && preg_match_all("/var\((.+)\)/iSU", $value, $m)) |
@@ -883,7 +882,7 @@ discard block |
||
883 | 882 | // escape chars is uneven do not end the string |
884 | 883 | if ($previousChar == "\\") |
885 | 884 | { |
886 | - $source = $this->parser->getSource(); |
|
885 | + $source = $this->parser->getSource(); |
|
887 | 886 | $c = 1; |
888 | 887 | $i = $index - 2; |
889 | 888 | while (substr($source, $i, 1) === "\\") |
@@ -1211,7 +1210,7 @@ discard block |
||
1211 | 1210 | public function __construct($property, $value, $mediaTypes = null, $isImportant = false, $isLast = false) |
1212 | 1211 | { |
1213 | 1212 | parent::__construct($property, $value, $isImportant, $isLast); |
1214 | - $this->MediaTypes = $mediaTypes ? $mediaTypes : array("all"); |
|
1213 | + $this->MediaTypes = $mediaTypes ? $mediaTypes : array("all"); |
|
1215 | 1214 | } |
1216 | 1215 | } |
1217 | 1216 | |
@@ -1239,8 +1238,8 @@ discard block |
||
1239 | 1238 | { |
1240 | 1239 | for ($i = 0, $l = count($tokens); $i < $l; $i++) |
1241 | 1240 | { |
1242 | - $current = get_class($tokens[$i]); |
|
1243 | - $next = isset($tokens[$i+1]) ? get_class($tokens[$i+1]) : false; |
|
1241 | + $current = get_class($tokens[$i]); |
|
1242 | + $next = isset($tokens[$i + 1]) ? get_class($tokens[$i + 1]) : false; |
|
1244 | 1243 | if (($current === "CssRulesetDeclarationToken" && $next === "CssRulesetEndToken") || |
1245 | 1244 | ($current === "CssAtFontFaceDeclarationToken" && $next === "CssAtFontFaceEndToken") || |
1246 | 1245 | ($current === "CssAtPageDeclarationToken" && $next === "CssAtPageEndToken")) |
@@ -1276,14 +1275,14 @@ discard block |
||
1276 | 1275 | $r = 0; |
1277 | 1276 | for ($i = 0, $l = count($tokens); $i < $l; $i++) |
1278 | 1277 | { |
1279 | - $current = get_class($tokens[$i]); |
|
1278 | + $current = get_class($tokens[$i]); |
|
1280 | 1279 | $next = isset($tokens[$i + 1]) ? get_class($tokens[$i + 1]) : false; |
1281 | 1280 | if (($current === "CssRulesetStartToken" && $next === "CssRulesetEndToken") || |
1282 | 1281 | ($current === "CssAtKeyframesRulesetStartToken" && $next === "CssAtKeyframesRulesetEndToken" && !array_intersect(array("from", "0%", "to", "100%"), array_map("strtolower", $tokens[$i]->Selectors))) |
1283 | 1282 | ) |
1284 | 1283 | { |
1285 | - $tokens[$i] = null; |
|
1286 | - $tokens[$i + 1] = null; |
|
1284 | + $tokens[$i] = null; |
|
1285 | + $tokens[$i + 1] = null; |
|
1287 | 1286 | $i++; |
1288 | 1287 | $r = $r + 2; |
1289 | 1288 | } |
@@ -1316,15 +1315,15 @@ discard block |
||
1316 | 1315 | $r = 0; |
1317 | 1316 | for ($i = 0, $l = count($tokens); $i < $l; $i++) |
1318 | 1317 | { |
1319 | - $current = get_class($tokens[$i]); |
|
1318 | + $current = get_class($tokens[$i]); |
|
1320 | 1319 | $next = isset($tokens[$i + 1]) ? get_class($tokens[$i + 1]) : false; |
1321 | 1320 | if (($current === "CssAtFontFaceStartToken" && $next === "CssAtFontFaceEndToken") || |
1322 | 1321 | ($current === "CssAtKeyframesStartToken" && $next === "CssAtKeyframesEndToken") || |
1323 | 1322 | ($current === "CssAtPageStartToken" && $next === "CssAtPageEndToken") || |
1324 | 1323 | ($current === "CssAtMediaStartToken" && $next === "CssAtMediaEndToken")) |
1325 | 1324 | { |
1326 | - $tokens[$i] = null; |
|
1327 | - $tokens[$i + 1] = null; |
|
1325 | + $tokens[$i] = null; |
|
1326 | + $tokens[$i + 1] = null; |
|
1328 | 1327 | $i++; |
1329 | 1328 | $r = $r + 2; |
1330 | 1329 | } |
@@ -1437,8 +1436,7 @@ discard block |
||
1437 | 1436 | */ |
1438 | 1437 | public function __construct($source = null, array $plugins = null) |
1439 | 1438 | { |
1440 | - $plugins = array_merge(array |
|
1441 | - ( |
|
1439 | + $plugins = array_merge(array( |
|
1442 | 1440 | "Comment" => true, |
1443 | 1441 | "String" => true, |
1444 | 1442 | "Url" => true, |
@@ -1457,7 +1455,7 @@ discard block |
||
1457 | 1455 | { |
1458 | 1456 | if ($config !== false) |
1459 | 1457 | { |
1460 | - $class = "Css" . $name . "ParserPlugin"; |
|
1458 | + $class = "Css" . $name . "ParserPlugin"; |
|
1461 | 1459 | $config = is_array($config) ? $config : array(); |
1462 | 1460 | if (class_exists($class)) |
1463 | 1461 | { |
@@ -1604,19 +1602,19 @@ discard block |
||
1604 | 1602 | $this->tokens = array(); |
1605 | 1603 | // Create a global and plugin lookup table for trigger chars; set array of plugins as local variable and create |
1606 | 1604 | // several helper variables for plugin handling |
1607 | - $globalTriggerChars = ""; |
|
1608 | - $plugins = $this->plugins; |
|
1605 | + $globalTriggerChars = ""; |
|
1606 | + $plugins = $this->plugins; |
|
1609 | 1607 | $pluginCount = count($plugins); |
1610 | 1608 | $pluginIndex = array(); |
1611 | 1609 | $pluginTriggerStates = array(); |
1612 | 1610 | $pluginTriggerChars = array(); |
1613 | 1611 | for ($i = 0, $l = count($plugins); $i < $l; $i++) |
1614 | 1612 | { |
1615 | - $tPluginClassName = get_class($plugins[$i]); |
|
1613 | + $tPluginClassName = get_class($plugins[$i]); |
|
1616 | 1614 | $pluginTriggerChars[$i] = implode("", $plugins[$i]->getTriggerChars()); |
1617 | - $tPluginTriggerStates = $plugins[$i]->getTriggerStates(); |
|
1615 | + $tPluginTriggerStates = $plugins[$i]->getTriggerStates(); |
|
1618 | 1616 | $pluginTriggerStates[$i] = $tPluginTriggerStates === false ? false : "|" . implode("|", $tPluginTriggerStates) . "|"; |
1619 | - $pluginIndex[$tPluginClassName] = $i; |
|
1617 | + $pluginIndex[$tPluginClassName] = $i; |
|
1620 | 1618 | for ($ii = 0, $ll = strlen($pluginTriggerChars[$i]); $ii < $ll; $ii++) |
1621 | 1619 | { |
1622 | 1620 | $c = substr($pluginTriggerChars[$i], $ii, 1); |
@@ -1627,13 +1625,13 @@ discard block |
||
1627 | 1625 | } |
1628 | 1626 | } |
1629 | 1627 | // Normalise line endings |
1630 | - $source = str_replace("\r\n", "\n", $source); // Windows to Unix line endings |
|
1631 | - $source = str_replace("\r", "\n", $source); // Mac to Unix line endings |
|
1632 | - $this->source = $source; |
|
1628 | + $source = str_replace("\r\n", "\n", $source); // Windows to Unix line endings |
|
1629 | + $source = str_replace("\r", "\n", $source); // Mac to Unix line endings |
|
1630 | + $this->source = $source; |
|
1633 | 1631 | // Variables |
1634 | 1632 | $buffer = &$this->buffer; |
1635 | - $exclusive = &$this->stateExclusive; |
|
1636 | - $state = &$this->state; |
|
1633 | + $exclusive = &$this->stateExclusive; |
|
1634 | + $state = &$this->state; |
|
1637 | 1635 | $c = $p = null; |
1638 | 1636 | // -- |
1639 | 1637 | for ($i = 0, $l = strlen($source); $i < $l; $i++) |
@@ -1811,13 +1809,13 @@ discard block |
||
1811 | 1809 | */ |
1812 | 1810 | public function __toString() |
1813 | 1811 | { |
1814 | - $r = array(); |
|
1812 | + $r = array(); |
|
1815 | 1813 | $level = 0; |
1816 | 1814 | for ($i = 0, $l = count($this->tokens); $i < $l; $i++) |
1817 | 1815 | { |
1818 | 1816 | $token = $this->tokens[$i]; |
1819 | 1817 | $class = get_class($token); |
1820 | - $indent = str_repeat($this->indent, $level); |
|
1818 | + $indent = str_repeat($this->indent, $level); |
|
1821 | 1819 | if ($class === "CssCommentToken") |
1822 | 1820 | { |
1823 | 1821 | $lines = array_map("trim", explode("\n", $token->Comment)); |
@@ -1960,8 +1958,7 @@ discard block |
||
1960 | 1958 | */ |
1961 | 1959 | public function __construct($source = null, array $filters = null, array $plugins = null) |
1962 | 1960 | { |
1963 | - $filters = array_merge(array |
|
1964 | - ( |
|
1961 | + $filters = array_merge(array( |
|
1965 | 1962 | "ImportImports" => false, |
1966 | 1963 | "RemoveComments" => true, |
1967 | 1964 | "RemoveEmptyRulesets" => true, |
@@ -1971,8 +1968,7 @@ discard block |
||
1971 | 1968 | "Variables" => true, |
1972 | 1969 | "RemoveLastDelarationSemiColon" => true |
1973 | 1970 | ), is_array($filters) ? $filters : array()); |
1974 | - $plugins = array_merge(array |
|
1975 | - ( |
|
1971 | + $plugins = array_merge(array( |
|
1976 | 1972 | "Variables" => true, |
1977 | 1973 | "ConvertFontWeight" => false, |
1978 | 1974 | "ConvertHslColors" => false, |
@@ -1987,7 +1983,7 @@ discard block |
||
1987 | 1983 | { |
1988 | 1984 | if ($config !== false) |
1989 | 1985 | { |
1990 | - $class = "Css" . $name . "MinifierFilter"; |
|
1986 | + $class = "Css" . $name . "MinifierFilter"; |
|
1991 | 1987 | $config = is_array($config) ? $config : array(); |
1992 | 1988 | if (class_exists($class)) |
1993 | 1989 | { |
@@ -2004,7 +2000,7 @@ discard block |
||
2004 | 2000 | { |
2005 | 2001 | if ($config !== false) |
2006 | 2002 | { |
2007 | - $class = "Css" . $name . "MinifierPlugin"; |
|
2003 | + $class = "Css" . $name . "MinifierPlugin"; |
|
2008 | 2004 | $config = is_array($config) ? $config : array(); |
2009 | 2005 | if (class_exists($class)) |
2010 | 2006 | { |
@@ -2059,10 +2055,10 @@ discard block |
||
2059 | 2055 | public function minify($source) |
2060 | 2056 | { |
2061 | 2057 | // Variables |
2062 | - $r = ""; |
|
2058 | + $r = ""; |
|
2063 | 2059 | $parser = new CssParser($source); |
2064 | 2060 | $tokens = $parser->getTokens(); |
2065 | - $filters = $this->filters; |
|
2061 | + $filters = $this->filters; |
|
2066 | 2062 | $filterCount = count($this->filters); |
2067 | 2063 | $plugins = $this->plugins; |
2068 | 2064 | $pluginCount = count($plugins); |
@@ -2071,8 +2067,8 @@ discard block |
||
2071 | 2067 | $globalTriggerTokens = array(); |
2072 | 2068 | for ($i = 0, $l = count($plugins); $i < $l; $i++) |
2073 | 2069 | { |
2074 | - $tPluginClassName = get_class($plugins[$i]); |
|
2075 | - $pluginTriggerTokens[$i] = $plugins[$i]->getTriggerTokens(); |
|
2070 | + $tPluginClassName = get_class($plugins[$i]); |
|
2071 | + $pluginTriggerTokens[$i] = $plugins[$i]->getTriggerTokens(); |
|
2076 | 2072 | foreach ($pluginTriggerTokens[$i] as $v) |
2077 | 2073 | { |
2078 | 2074 | if (!in_array($v, $globalTriggerTokens)) |
@@ -2081,13 +2077,13 @@ discard block |
||
2081 | 2077 | } |
2082 | 2078 | } |
2083 | 2079 | $pluginTriggerTokens[$i] = "|" . implode("|", $pluginTriggerTokens[$i]) . "|"; |
2084 | - $pluginIndex[$tPluginClassName] = $i; |
|
2080 | + $pluginIndex[$tPluginClassName] = $i; |
|
2085 | 2081 | } |
2086 | 2082 | $globalTriggerTokens = "|" . implode("|", $globalTriggerTokens) . "|"; |
2087 | 2083 | /* |
2088 | 2084 | * Apply filters |
2089 | 2085 | */ |
2090 | - for($i = 0; $i < $filterCount; $i++) |
|
2086 | + for ($i = 0; $i < $filterCount; $i++) |
|
2091 | 2087 | { |
2092 | 2088 | // Apply the filter; if the return value is larger than 0... |
2093 | 2089 | if ($filters[$i]->apply($tokens) > 0) |
@@ -2100,12 +2096,12 @@ discard block |
||
2100 | 2096 | /* |
2101 | 2097 | * Apply plugins |
2102 | 2098 | */ |
2103 | - for($i = 0; $i < $tokenCount; $i++) |
|
2099 | + for ($i = 0; $i < $tokenCount; $i++) |
|
2104 | 2100 | { |
2105 | 2101 | $triggerToken = "|" . get_class($tokens[$i]) . "|"; |
2106 | 2102 | if (strpos($globalTriggerTokens, $triggerToken) !== false) |
2107 | 2103 | { |
2108 | - for($ii = 0; $ii < $pluginCount; $ii++) |
|
2104 | + for ($ii = 0; $ii < $pluginCount; $ii++) |
|
2109 | 2105 | { |
2110 | 2106 | if (strpos($pluginTriggerTokens[$ii], $triggerToken) !== false || $pluginTriggerTokens[$ii] === false) |
2111 | 2107 | { |
@@ -2119,7 +2115,7 @@ discard block |
||
2119 | 2115 | } |
2120 | 2116 | } |
2121 | 2117 | // Stringify the tokens |
2122 | - for($i = 0; $i < $tokenCount; $i++) |
|
2118 | + for ($i = 0; $i < $tokenCount; $i++) |
|
2123 | 2119 | { |
2124 | 2120 | $r .= (string) $tokens[$i]; |
2125 | 2121 | } |
@@ -2344,7 +2340,7 @@ discard block |
||
2344 | 2340 | { |
2345 | 2341 | if (!isset($this->configuration["BasePath"]) || !is_dir($this->configuration["BasePath"])) |
2346 | 2342 | { |
2347 | - CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Base path <code>" . ($this->configuration["BasePath"] ? $this->configuration["BasePath"] : "null"). "</code> is not a directory")); |
|
2343 | + CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Base path <code>" . ($this->configuration["BasePath"] ? $this->configuration["BasePath"] : "null") . "</code> is not a directory")); |
|
2348 | 2344 | return 0; |
2349 | 2345 | } |
2350 | 2346 | for ($i = 0, $l = count($tokens); $i < $l; $i++) |
@@ -2355,12 +2351,12 @@ discard block |
||
2355 | 2351 | // Import file was not found/is not a file |
2356 | 2352 | if (!is_file($import)) |
2357 | 2353 | { |
2358 | - CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Import file <code>" . $import. "</code> was not found.", (string) $tokens[$i])); |
|
2354 | + CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Import file <code>" . $import . "</code> was not found.", (string) $tokens[$i])); |
|
2359 | 2355 | } |
2360 | 2356 | // Import file already imported; remove this @import at-rule to prevent recursions |
2361 | 2357 | elseif (in_array($import, $this->imported)) |
2362 | 2358 | { |
2363 | - CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Import file <code>" . $import. "</code> was already imported.", (string) $tokens[$i])); |
|
2359 | + CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Import file <code>" . $import . "</code> was already imported.", (string) $tokens[$i])); |
|
2364 | 2360 | $tokens[$i] = null; |
2365 | 2361 | } |
2366 | 2362 | else |
@@ -2375,7 +2371,7 @@ discard block |
||
2375 | 2371 | /* |
2376 | 2372 | * Filter or set media types of @import at-rule or remove the @import at-rule if no media type is matching the parent @import at-rule |
2377 | 2373 | */ |
2378 | - for($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2374 | + for ($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2379 | 2375 | { |
2380 | 2376 | if (get_class($import[$ii]) === "CssAtImportToken") |
2381 | 2377 | { |
@@ -2406,7 +2402,7 @@ discard block |
||
2406 | 2402 | /* |
2407 | 2403 | * Remove media types of @media at-rule block not defined in the @import at-rule |
2408 | 2404 | */ |
2409 | - for($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2405 | + for ($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2410 | 2406 | { |
2411 | 2407 | if (get_class($import[$ii]) === "CssAtMediaStartToken") |
2412 | 2408 | { |
@@ -2423,7 +2419,7 @@ discard block |
||
2423 | 2419 | /* |
2424 | 2420 | * If no media types left of the @media at-rule block remove the complete block |
2425 | 2421 | */ |
2426 | - for($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2422 | + for ($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2427 | 2423 | { |
2428 | 2424 | if (get_class($import[$ii]) === "CssAtMediaStartToken") |
2429 | 2425 | { |
@@ -2448,7 +2444,7 @@ discard block |
||
2448 | 2444 | * If the media types of the @media at-rule equals the media types defined in the @import |
2449 | 2445 | * at-rule remove the CssAtMediaStartToken and CssAtMediaEndToken token |
2450 | 2446 | */ |
2451 | - for($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2447 | + for ($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2452 | 2448 | { |
2453 | 2449 | if (get_class($import[$ii]) === "CssAtMediaStartToken" && count(array_diff($tokens[$i]->MediaTypes, $import[$ii]->MediaTypes)) === 0) |
2454 | 2450 | { |
@@ -2471,7 +2467,7 @@ discard block |
||
2471 | 2467 | /** |
2472 | 2468 | * Extract CssAtImportToken and CssAtCharsetToken tokens |
2473 | 2469 | */ |
2474 | - for($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2470 | + for ($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2475 | 2471 | { |
2476 | 2472 | $class = get_class($import[$ii]); |
2477 | 2473 | if ($class === "CssAtImportToken" || $class === "CssAtCharsetToken") |
@@ -2483,7 +2479,7 @@ discard block |
||
2483 | 2479 | /* |
2484 | 2480 | * Extract the @font-face, @media and @page at-rule block |
2485 | 2481 | */ |
2486 | - for($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2482 | + for ($ii = 0, $ll = count($import); $ii < $ll; $ii++) |
|
2487 | 2483 | { |
2488 | 2484 | $class = get_class($import[$ii]); |
2489 | 2485 | if ($class === "CssAtFontFaceStartToken" || $class === "CssAtMediaStartToken" || $class === "CssAtPageStartToken" || $class === "CssAtVariablesStartToken") |
@@ -2651,8 +2647,8 @@ discard block |
||
2651 | 2647 | { |
2652 | 2648 | $this->File = $file; |
2653 | 2649 | $this->Line = $line; |
2654 | - $this->Message = $message; |
|
2655 | - $this->Source = $source; |
|
2650 | + $this->Message = $message; |
|
2651 | + $this->Source = $source; |
|
2656 | 2652 | } |
2657 | 2653 | /** |
2658 | 2654 | * Returns the error as formatted string. |
@@ -2661,7 +2657,7 @@ discard block |
||
2661 | 2657 | */ |
2662 | 2658 | public function __toString() |
2663 | 2659 | { |
2664 | - return $this->Message . ($this->Source ? ": <br /><code>" . $this->Source . "</code>": "") . "<br />in file " . $this->File . " at line " . $this->Line; |
|
2660 | + return $this->Message . ($this->Source ? ": <br /><code>" . $this->Source . "</code>" : "") . "<br />in file " . $this->File . " at line " . $this->Line; |
|
2665 | 2661 | } |
2666 | 2662 | } |
2667 | 2663 | |
@@ -2710,7 +2706,7 @@ discard block |
||
2710 | 2706 | $m[$i] = substr($m[$i], 0, -1); |
2711 | 2707 | $m[$i] = (int) (256 * ($m[$i] / 100)); |
2712 | 2708 | } |
2713 | - $m[$i] = str_pad(dechex($m[$i]), 2, "0", STR_PAD_LEFT); |
|
2709 | + $m[$i] = str_pad(dechex($m[$i]), 2, "0", STR_PAD_LEFT); |
|
2714 | 2710 | } |
2715 | 2711 | $token->Value = str_replace($m[0], "#" . $m[1] . $m[2] . $m[3], $token->Value); |
2716 | 2712 | } |
@@ -2723,8 +2719,7 @@ discard block |
||
2723 | 2719 | */ |
2724 | 2720 | public function getTriggerTokens() |
2725 | 2721 | { |
2726 | - return array |
|
2727 | - ( |
|
2722 | + return array( |
|
2728 | 2723 | "CssAtFontFaceDeclarationToken", |
2729 | 2724 | "CssAtPageDeclarationToken", |
2730 | 2725 | "CssRulesetDeclarationToken" |
@@ -2774,8 +2769,7 @@ discard block |
||
2774 | 2769 | * |
2775 | 2770 | * @var array |
2776 | 2771 | */ |
2777 | - private $transformation = array |
|
2778 | - ( |
|
2772 | + private $transformation = array( |
|
2779 | 2773 | "aliceblue" => "#f0f8ff", |
2780 | 2774 | "antiquewhite" => "#faebd7", |
2781 | 2775 | "aqua" => "#0ff", |
@@ -2956,8 +2950,7 @@ discard block |
||
2956 | 2950 | */ |
2957 | 2951 | public function getTriggerTokens() |
2958 | 2952 | { |
2959 | - return array |
|
2960 | - ( |
|
2953 | + return array( |
|
2961 | 2954 | "CssAtFontFaceDeclarationToken", |
2962 | 2955 | "CssAtPageDeclarationToken", |
2963 | 2956 | "CssRulesetDeclarationToken" |
@@ -2984,8 +2977,7 @@ discard block |
||
2984 | 2977 | * |
2985 | 2978 | * @var array |
2986 | 2979 | */ |
2987 | - private $transformations = array |
|
2988 | - ( |
|
2980 | + private $transformations = array( |
|
2989 | 2981 | // Property Array(Mozilla, Webkit, Opera, Internet Explorer); NULL values are placeholders and will get ignored |
2990 | 2982 | "animation" => array(null, "-webkit-animation", null, null), |
2991 | 2983 | "animation-delay" => array(null, "-webkit-animation-delay", null, null), |
@@ -3217,8 +3209,8 @@ discard block |
||
3217 | 3209 | } |
3218 | 3210 | else |
3219 | 3211 | { |
3220 | - $tValue = $tokens[$i]->Value; |
|
3221 | - $tMediaTypes = $tokens[$i]->MediaTypes; |
|
3212 | + $tValue = $tokens[$i]->Value; |
|
3213 | + $tMediaTypes = $tokens[$i]->MediaTypes; |
|
3222 | 3214 | foreach ($transformations[$tProperty] as $property) |
3223 | 3215 | { |
3224 | 3216 | if ($property !== null) |
@@ -3247,8 +3239,7 @@ discard block |
||
3247 | 3239 | */ |
3248 | 3240 | private static function filter($token) |
3249 | 3241 | { |
3250 | - $r = array |
|
3251 | - ( |
|
3242 | + $r = array( |
|
3252 | 3243 | new CssRulesetDeclarationToken("-ms-filter", "\"" . $token->Value . "\"", $token->MediaTypes), |
3253 | 3244 | ); |
3254 | 3245 | return $r; |
@@ -3263,8 +3254,7 @@ discard block |
||
3263 | 3254 | { |
3264 | 3255 | // Calculate the value for Internet Explorer filter statement |
3265 | 3256 | $ieValue = (int) ((float) $token->Value * 100); |
3266 | - $r = array |
|
3267 | - ( |
|
3257 | + $r = array( |
|
3268 | 3258 | // Internet Explorer >= 8 |
3269 | 3259 | new CssRulesetDeclarationToken("-ms-filter", "\"alpha(opacity=" . $ieValue . ")\"", $token->MediaTypes), |
3270 | 3260 | // Internet Explorer >= 4 <= 7 |
@@ -3283,8 +3273,7 @@ discard block |
||
3283 | 3273 | { |
3284 | 3274 | if (strtolower($token->Value) === "pre-wrap") |
3285 | 3275 | { |
3286 | - $r = array |
|
3287 | - ( |
|
3276 | + $r = array( |
|
3288 | 3277 | // Firefox < 3 |
3289 | 3278 | new CssRulesetDeclarationToken("white-space", "-moz-pre-wrap", $token->MediaTypes), |
3290 | 3279 | // Webkit |
@@ -3340,8 +3329,8 @@ discard block |
||
3340 | 3329 | } |
3341 | 3330 | if (get_class($tokens[$ii]) === "CssAtKeyframesEndToken") |
3342 | 3331 | { |
3343 | - $add = array(); |
|
3344 | - $source = array(); |
|
3332 | + $add = array(); |
|
3333 | + $source = array(); |
|
3345 | 3334 | for ($iii = $i; $iii <= $ii; $iii++) |
3346 | 3335 | { |
3347 | 3336 | $source[] = clone($tokens[$iii]); |
@@ -3423,8 +3412,7 @@ discard block |
||
3423 | 3412 | */ |
3424 | 3413 | public function getTriggerTokens() |
3425 | 3414 | { |
3426 | - return array |
|
3427 | - ( |
|
3415 | + return array( |
|
3428 | 3416 | "CssAtFontFaceDeclarationToken", |
3429 | 3417 | "CssAtPageDeclarationToken", |
3430 | 3418 | "CssRulesetDeclarationToken" |
@@ -3442,18 +3430,18 @@ discard block |
||
3442 | 3430 | */ |
3443 | 3431 | private function hsl2hex($hue, $saturation, $lightness) |
3444 | 3432 | { |
3445 | - $hue = $hue / 360; |
|
3446 | - $saturation = $saturation / 100; |
|
3447 | - $lightness = $lightness / 100; |
|
3433 | + $hue = $hue / 360; |
|
3434 | + $saturation = $saturation / 100; |
|
3435 | + $lightness = $lightness / 100; |
|
3448 | 3436 | if ($saturation == 0) |
3449 | 3437 | { |
3450 | - $red = $lightness * 255; |
|
3451 | - $green = $lightness * 255; |
|
3452 | - $blue = $lightness * 255; |
|
3438 | + $red = $lightness * 255; |
|
3439 | + $green = $lightness * 255; |
|
3440 | + $blue = $lightness * 255; |
|
3453 | 3441 | } |
3454 | 3442 | else |
3455 | 3443 | { |
3456 | - if ($lightness < 0.5 ) |
|
3444 | + if ($lightness < 0.5) |
|
3457 | 3445 | { |
3458 | 3446 | $v2 = $lightness * (1 + $saturation); |
3459 | 3447 | } |
@@ -3463,8 +3451,8 @@ discard block |
||
3463 | 3451 | } |
3464 | 3452 | $v1 = 2 * $lightness - $v2; |
3465 | 3453 | $red = 255 * self::hue2rgb($v1, $v2, $hue + (1 / 3)); |
3466 | - $green = 255 * self::hue2rgb($v1, $v2, $hue); |
|
3467 | - $blue = 255 * self::hue2rgb($v1, $v2, $hue - (1 / 3)); |
|
3454 | + $green = 255 * self::hue2rgb($v1, $v2, $hue); |
|
3455 | + $blue = 255 * self::hue2rgb($v1, $v2, $hue - (1 / 3)); |
|
3468 | 3456 | } |
3469 | 3457 | return "#" . str_pad(dechex(round($red)), 2, "0", STR_PAD_LEFT) . str_pad(dechex(round($green)), 2, "0", STR_PAD_LEFT) . str_pad(dechex(round($blue)), 2, "0", STR_PAD_LEFT); |
3470 | 3458 | } |
@@ -3496,7 +3484,7 @@ discard block |
||
3496 | 3484 | } |
3497 | 3485 | if ((3 * $hue) < 2) |
3498 | 3486 | { |
3499 | - return ($v1 + ($v2 - $v1) * (( 2 / 3) - $hue) * 6); |
|
3487 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $hue) * 6); |
|
3500 | 3488 | } |
3501 | 3489 | return $v1; |
3502 | 3490 | } |
@@ -3532,8 +3520,7 @@ discard block |
||
3532 | 3520 | * |
3533 | 3521 | * @var array |
3534 | 3522 | */ |
3535 | - private $include = array |
|
3536 | - ( |
|
3523 | + private $include = array( |
|
3537 | 3524 | "font", |
3538 | 3525 | "font-weight" |
3539 | 3526 | ); |
@@ -3554,8 +3541,7 @@ discard block |
||
3554 | 3541 | * |
3555 | 3542 | * @var array |
3556 | 3543 | */ |
3557 | - private $transformation = array |
|
3558 | - ( |
|
3544 | + private $transformation = array( |
|
3559 | 3545 | "normal" => "400", |
3560 | 3546 | "bold" => "700" |
3561 | 3547 | ); |
@@ -3570,7 +3556,7 @@ discard block |
||
3570 | 3556 | */ |
3571 | 3557 | public function __construct(CssMinifier $minifier) |
3572 | 3558 | { |
3573 | - $this->reMatch = "/(^|\s)+(" . implode("|", array_keys($this->transformation)). ")(\s|$)+/eiS"; |
|
3559 | + $this->reMatch = "/(^|\s)+(" . implode("|", array_keys($this->transformation)) . ")(\s|$)+/eiS"; |
|
3574 | 3560 | parent::__construct($minifier); |
3575 | 3561 | } |
3576 | 3562 | /** |
@@ -3594,8 +3580,7 @@ discard block |
||
3594 | 3580 | */ |
3595 | 3581 | public function getTriggerTokens() |
3596 | 3582 | { |
3597 | - return array |
|
3598 | - ( |
|
3583 | + return array( |
|
3599 | 3584 | "CssAtFontFaceDeclarationToken", |
3600 | 3585 | "CssAtPageDeclarationToken", |
3601 | 3586 | "CssRulesetDeclarationToken" |
@@ -3636,8 +3621,7 @@ discard block |
||
3636 | 3621 | * |
3637 | 3622 | * @var array |
3638 | 3623 | */ |
3639 | - private $re = array |
|
3640 | - ( |
|
3624 | + private $re = array( |
|
3641 | 3625 | "/(^| |-)0\.([0-9]+?)(0+)?(%|em|ex|px|in|cm|mm|pt|pc)/iS" => "\${1}.\${2}\${4}", |
3642 | 3626 | "/(^| )-?(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)/iS" => "\${1}0", |
3643 | 3627 | "/(^0\s0\s0\s0)|(^0\s0\s0$)|(^0\s0$)/iS" => "0" |
@@ -3672,8 +3656,7 @@ discard block |
||
3672 | 3656 | */ |
3673 | 3657 | public function getTriggerTokens() |
3674 | 3658 | { |
3675 | - return array |
|
3676 | - ( |
|
3659 | + return array( |
|
3677 | 3660 | "CssAtFontFaceDeclarationToken", |
3678 | 3661 | "CssAtPageDeclarationToken", |
3679 | 3662 | "CssRulesetDeclarationToken" |
@@ -3720,8 +3703,7 @@ discard block |
||
3720 | 3703 | */ |
3721 | 3704 | public function getTriggerTokens() |
3722 | 3705 | { |
3723 | - return array |
|
3724 | - ( |
|
3706 | + return array( |
|
3725 | 3707 | "CssAtFontFaceDeclarationToken", |
3726 | 3708 | "CssAtPageDeclarationToken", |
3727 | 3709 | "CssRulesetDeclarationToken" |
@@ -3783,8 +3765,7 @@ discard block |
||
3783 | 3765 | */ |
3784 | 3766 | public function getTriggerTokens() |
3785 | 3767 | { |
3786 | - return array |
|
3787 | - ( |
|
3768 | + return array( |
|
3788 | 3769 | "CssAtFontFaceDeclarationToken", |
3789 | 3770 | "CssAtPageDeclarationToken", |
3790 | 3771 | "CssRulesetDeclarationToken" |
@@ -4717,8 +4698,8 @@ discard block |
||
4717 | 4698 | */ |
4718 | 4699 | public function __construct($import, $mediaTypes) |
4719 | 4700 | { |
4720 | - $this->Import = $import; |
|
4721 | - $this->MediaTypes = $mediaTypes ? $mediaTypes : array(); |
|
4701 | + $this->Import = $import; |
|
4702 | + $this->MediaTypes = $mediaTypes ? $mediaTypes : array(); |
|
4722 | 4703 | } |
4723 | 4704 | /** |
4724 | 4705 | * Implements {@link aCssToken::__toString()}. |
@@ -4727,7 +4708,7 @@ discard block |
||
4727 | 4708 | */ |
4728 | 4709 | public function __toString() |
4729 | 4710 | { |
4730 | - return "@import \"" . $this->Import . "\"" . (count($this->MediaTypes) > 0 ? " " . implode(",", $this->MediaTypes) : ""). ";"; |
|
4711 | + return "@import \"" . $this->Import . "\"" . (count($this->MediaTypes) > 0 ? " " . implode(",", $this->MediaTypes) : "") . ";"; |
|
4731 | 4712 | } |
4732 | 4713 | } |
4733 | 4714 |
@@ -40,81 +40,81 @@ |
||
40 | 40 | // -- notes: aply data-no-min to a style or script node to exempt it |
41 | 41 | // -- HTML 4, XHTML, and HTML 5 compliant |
42 | 42 | |
43 | - class HtmlMin{ |
|
43 | + class HtmlMin { |
|
44 | 44 | // -- Function Name : minify - Params : $html, $js = true, $css = true |
45 | - public static function minify($html, $js = true, $css = true){ |
|
45 | + public static function minify($html, $js = true, $css = true) { |
|
46 | 46 | $doc = new \DOMDocument(); |
47 | 47 | $doc->preserveWhiteSpace = false; |
48 | 48 | @$doc->loadHTML($html); |
49 | 49 | $xpath = new \DOMXPath($doc); |
50 | 50 | foreach ($xpath->query('//comment()') as $comment) { |
51 | - $val= $comment->nodeValue; |
|
52 | - if( strpos($val,'[')!==0){ |
|
51 | + $val = $comment->nodeValue; |
|
52 | + if (strpos($val, '[') !== 0) { |
|
53 | 53 | $comment->parentNode->removeChild($comment); |
54 | 54 | } |
55 | 55 | } |
56 | 56 | $doc->normalizeDocument(); |
57 | 57 | $textnodes = $xpath->query('//text()'); |
58 | - $skip = ["style","pre","code","script","textarea"]; |
|
59 | - foreach($textnodes as $t){ |
|
58 | + $skip = ["style", "pre", "code", "script", "textarea"]; |
|
59 | + foreach ($textnodes as $t) { |
|
60 | 60 | $xp = $t->getNodePath(); |
61 | 61 | $doskip = false; |
62 | - foreach($skip as $pattern){ |
|
63 | - if(strpos($xp,"/$pattern")!==false){ |
|
62 | + foreach ($skip as $pattern) { |
|
63 | + if (strpos($xp, "/$pattern") !== false) { |
|
64 | 64 | $doskip = true; |
65 | 65 | break; |
66 | 66 | } |
67 | 67 | } |
68 | - if($doskip){ |
|
68 | + if ($doskip) { |
|
69 | 69 | continue; |
70 | 70 | } |
71 | 71 | $t->nodeValue = preg_replace("/\s{2,}/", " ", $t->nodeValue); |
72 | 72 | } |
73 | 73 | $doc->normalizeDocument(); |
74 | 74 | $divnodes = $xpath->query('//div|//p|//nav|//footer|//article|//script|//hr|//br'); |
75 | - foreach($divnodes as $d){ |
|
75 | + foreach ($divnodes as $d) { |
|
76 | 76 | $candidates = []; |
77 | - if(count($d->childNodes)){ |
|
77 | + if (count($d->childNodes)) { |
|
78 | 78 | $candidates[] = $d->firstChild; |
79 | 79 | $candidates[] = $d->lastChild; |
80 | 80 | $candidates[] = $d->previousSibling; |
81 | 81 | $candidates[] = $d->nextSibling; |
82 | 82 | } |
83 | - foreach($candidates as $c){ |
|
84 | - if($c==null){ |
|
83 | + foreach ($candidates as $c) { |
|
84 | + if ($c == null) { |
|
85 | 85 | continue; |
86 | 86 | } |
87 | - if($c->nodeType==3){ |
|
87 | + if ($c->nodeType == 3) { |
|
88 | 88 | $c->nodeValue = trim($c->nodeValue); |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | $doc->normalizeDocument(); |
93 | - if($js){ |
|
93 | + if ($js) { |
|
94 | 94 | $scriptnodes = $xpath->query('//script'); |
95 | - foreach($scriptnodes as $d){ |
|
96 | - if($d->hasAttribute("type") && strtolower($d->getAttribute("type"))!=='text/javascript' ){ |
|
95 | + foreach ($scriptnodes as $d) { |
|
96 | + if ($d->hasAttribute("type") && strtolower($d->getAttribute("type")) !== 'text/javascript') { |
|
97 | 97 | continue; |
98 | 98 | } |
99 | - if($d->hasAttribute("data-no-min")){ |
|
99 | + if ($d->hasAttribute("data-no-min")) { |
|
100 | 100 | continue; |
101 | 101 | } |
102 | - if(trim($d->nodeValue)==""){ |
|
102 | + if (trim($d->nodeValue) == "") { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | - $d->nodeValue = JSMin::minify( $d->nodeValue); |
|
105 | + $d->nodeValue = JSMin::minify($d->nodeValue); |
|
106 | 106 | } |
107 | 107 | } |
108 | - if($css){ |
|
108 | + if ($css) { |
|
109 | 109 | $cssnodes = $xpath->query('//style'); |
110 | - foreach($cssnodes as $d){ |
|
111 | - if($d->hasAttribute("data-no-min")){ |
|
110 | + foreach ($cssnodes as $d) { |
|
111 | + if ($d->hasAttribute("data-no-min")) { |
|
112 | 112 | continue; |
113 | 113 | } |
114 | - if(trim($d->nodeValue)==""){ |
|
114 | + if (trim($d->nodeValue) == "") { |
|
115 | 115 | continue; |
116 | 116 | } |
117 | - $d->nodeValue = CssMin::minify( $d->nodeValue); |
|
117 | + $d->nodeValue = CssMin::minify($d->nodeValue); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | return ($doc->saveHTML()); |
@@ -17,17 +17,17 @@ |
||
17 | 17 | |
18 | 18 | |
19 | 19 | |
20 | -class Minify{ |
|
20 | +class Minify { |
|
21 | 21 | |
22 | - public static function html($html){ |
|
22 | + public static function html($html) { |
|
23 | 23 | return HtmlMin::minify($html); |
24 | 24 | } |
25 | 25 | |
26 | - public static function css($css){ |
|
26 | + public static function css($css) { |
|
27 | 27 | return CssMin::minify($css); |
28 | 28 | } |
29 | 29 | |
30 | - public static function js($js){ |
|
30 | + public static function js($js) { |
|
31 | 31 | return JsMin::minify($js); |
32 | 32 | } |
33 | 33 |
@@ -3,35 +3,35 @@ |
||
3 | 3 | |
4 | 4 | $html = file_get_contents("http://en.wikipedia.org/wiki/Minification_%28programming%29"); |
5 | 5 | $minified = PHPWee\Minify::html($html); |
6 | -echo print_performance_graph("Wikipedia",$minified,$html); |
|
6 | +echo print_performance_graph("Wikipedia", $minified, $html); |
|
7 | 7 | |
8 | 8 | |
9 | 9 | $html = file_get_contents("http://www.codeproject.com/Articles/759094/Step-by-Step-PHP-Tutorials-for-Beginners-Creating"); |
10 | 10 | $minified = PHPWee\Minify::html($html); |
11 | -echo print_performance_graph("The Code Project",$minified,$html); |
|
11 | +echo print_performance_graph("The Code Project", $minified, $html); |
|
12 | 12 | |
13 | 13 | |
14 | 14 | $html = file_get_contents("https://github.com/php/php-src"); |
15 | 15 | $minified = PHPWee\Minify::html($html); |
16 | -print_performance_graph("GiHub",$minified,$html); |
|
16 | +print_performance_graph("GiHub", $minified, $html); |
|
17 | 17 | |
18 | 18 | |
19 | 19 | $html = file_get_contents("http://www.w3schools.com/php/"); |
20 | 20 | $minified = PHPWee\Minify::html($html); |
21 | -print_performance_graph("W3Schools",$minified,$html); |
|
21 | +print_performance_graph("W3Schools", $minified, $html); |
|
22 | 22 | |
23 | 23 | |
24 | 24 | $html = file_get_contents("http://searchturbine.com"); |
25 | 25 | $minified = PHPWee\Minify::html($html); |
26 | -print_performance_graph("SearchTurbine",$minified,$html); |
|
26 | +print_performance_graph("SearchTurbine", $minified, $html); |
|
27 | 27 | |
28 | 28 | |
29 | 29 | /////////////////////////////////////////////////////////////// |
30 | 30 | |
31 | 31 | |
32 | -function print_performance_graph($subject,$minified,$html){ |
|
32 | +function print_performance_graph($subject, $minified, $html) { |
|
33 | 33 | $before = strlen(gzcompress($html)); |
34 | 34 | $after = strlen(gzcompress($minified)); |
35 | - $improvement = 100 * (1-($after/$before)); |
|
35 | + $improvement = 100 * (1 - ($after / $before)); |
|
36 | 36 | echo "<table style='width:100%; border:1px solid grey;text-align:center'><tr><th colspan=3><b>$subject</th><tr><th>Gzipped Bytes Before PHPWee</th><th>Gzipped Bytes After PHPWee</th><th>% Performance Boost</th></tr><tr><td>$before before</td><td>$after after</td><td> $improvement % faster </td></table><br><br>"; |
37 | 37 | } |
38 | 38 | \ No newline at end of file |
@@ -121,14 +121,14 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @param mixed $offset |
123 | 123 | */ |
124 | - public function offsetExists($offset){} |
|
124 | + public function offsetExists($offset) {} |
|
125 | 125 | |
126 | 126 | /** |
127 | 127 | * \ArrayAccess unused method |
128 | 128 | * |
129 | 129 | * @param mixed $offset |
130 | 130 | */ |
131 | - public function offsetUnset($offset){} |
|
131 | + public function offsetUnset($offset) {} |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * \ArrayAccess - get array value from object |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | { |
301 | 301 | if ($isNameProvided) { |
302 | 302 | $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); |
303 | - }else{ |
|
303 | + } else { |
|
304 | 304 | $this->name = uniqid('', true) . '_' . str_shuffle(implode(range('e', 'q'))); |
305 | 305 | } |
306 | 306 | |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $isDirectoryValid = $this->isDirectoryValid($dir); |
379 | 379 | |
380 | 380 | if (!$isDirectoryValid) { |
381 | - $this->error = 'Can not create a directory \''.$dir.'\', please check write permission'; |
|
381 | + $this->error = 'Can not create a directory \'' . $dir . '\', please check write permission'; |
|
382 | 382 | return false; |
383 | 383 | } |
384 | 384 | |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | |
418 | 418 | /* check image size based on the settings */ |
419 | 419 | if ($this->_files['size'] < $minSize || $this->_files['size'] > $maxSize) { |
420 | - $min = $minSize.' bytes ('.intval($minSize / 1000).' kb)'; |
|
421 | - $max = $maxSize.' bytes ('.intval($maxSize / 1000).' kb)'; |
|
422 | - $this->error = 'Image size should be minimum '.$min.', upto maximum '.$max; |
|
420 | + $min = $minSize . ' bytes (' . intval($minSize / 1000) . ' kb)'; |
|
421 | + $max = $maxSize . ' bytes (' . intval($maxSize / 1000) . ' kb)'; |
|
422 | + $this->error = 'Image size should be minimum ' . $min . ', upto maximum ' . $max; |
|
423 | 423 | return false; |
424 | 424 | } |
425 | 425 |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | if ($thumbnail_aspect_ratio < $source_aspect_ratio) { |
66 | 66 | $src_h = $imgHeight; |
67 | 67 | $src_w = $imgHeight * $thumbnail_aspect_ratio; |
68 | - $src_x = (int) (($imgWidth - $src_w)/2); |
|
68 | + $src_x = (int) (($imgWidth - $src_w) / 2); |
|
69 | 69 | $src_y = 0; |
70 | 70 | } else { |
71 | 71 | $src_w = $imgWidth; |
72 | 72 | $src_h = (int) ($imgWidth / $thumbnail_aspect_ratio); |
73 | 73 | $src_x = 0; |
74 | - $src_y = (int) (($imgHeight - $src_h)/2); |
|
74 | + $src_y = (int) (($imgHeight - $src_h) / 2); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | // Checks whether image upsizing is enabled |
@@ -86,26 +86,26 @@ discard block |
||
86 | 86 | if ($newHeight > $newHeightOrig) { |
87 | 87 | $newHeight = $newHeightOrig; |
88 | 88 | $src_h = $newHeight; |
89 | - $src_y = (int) (($imgHeight - $src_h)/2); |
|
89 | + $src_y = (int) (($imgHeight - $src_h) / 2); |
|
90 | 90 | } |
91 | 91 | |
92 | - $src_x=0; |
|
92 | + $src_x = 0; |
|
93 | 93 | $src_w = $imgWidth; |
94 | 94 | } |
95 | 95 | |
96 | 96 | // If the given height is larger then the image height, then resize it. |
97 | 97 | if ($newHeightOrig > $imgHeight) { |
98 | 98 | $newHeight = $imgHeight; |
99 | - $src_y=0; |
|
99 | + $src_y = 0; |
|
100 | 100 | $src_h = $imgHeight; |
101 | - $src_w = (int) ($src_h * ( $newWidth / $newHeight )); |
|
102 | - $src_x = (int) (($imgWidth - $src_w)/2); |
|
101 | + $src_w = (int) ($src_h * ($newWidth / $newHeight)); |
|
102 | + $src_x = (int) (($imgWidth - $src_w) / 2); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | } else { |
106 | 106 | |
107 | 107 | // First, calculate the height. |
108 | - $height = (int) ($newWidth / $imgWidth * $imgHeight); // 75 |
|
108 | + $height = (int) ($newWidth / $imgWidth * $imgHeight); // 75 |
|
109 | 109 | |
110 | 110 | // If the height is too large, set it to the maximum height and calculate the width. |
111 | 111 | if ($height > $newHeight) { |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | ); |
170 | 170 | |
171 | 171 | if ($destination !== false) { // checks if was destination provided |
172 | - if(substr( $destination, -1 ) == '/' ) { // check whether prowided destination was folder or file. |
|
172 | + if (substr($destination, -1) == '/') { // check whether prowided destination was folder or file. |
|
173 | 173 | $create = !is_dir($destination) ? @mkdir($destination, $permission, true) : true; // if it was folder, it will crtete it if needed |
174 | 174 | if ($create) { |
175 | 175 | $path_parts = pathinfo($image); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | $path_parts = pathinfo($destination); |
187 | - $create = !is_dir($path_parts['dirname'].'/') ? @mkdir($path_parts['dirname'].'/', $permission, true) : true; |
|
187 | + $create = !is_dir($path_parts['dirname'] . '/') ? @mkdir($path_parts['dirname'] . '/', $permission, true) : true; |
|
188 | 188 | if (!$create) { |
189 | 189 | return false; // TODO: throw error/exception |
190 | 190 | } |
@@ -193,35 +193,35 @@ discard block |
||
193 | 193 | case "jpeg": |
194 | 194 | case "jpg": |
195 | 195 | $q = 90; // function's default value - if everything else fails, this is used. |
196 | - if( false !== $image ) { |
|
197 | - if ((!empty($quality['jpg']['fallback'])) AND ( (int) $quality['jpg']['fallback'] ) AND ( $quality['jpg']['fallback'] > 0 ) AND ( $quality['jpg']['fallback'] <=100 ) ) { |
|
196 | + if (false !== $image) { |
|
197 | + if ((!empty($quality['jpg']['fallback'])) AND ((int) $quality['jpg']['fallback']) AND ($quality['jpg']['fallback'] > 0) AND ($quality['jpg']['fallback'] <= 100)) { |
|
198 | 198 | $q = $quality['jpg']['fallback']; |
199 | 199 | } |
200 | 200 | |
201 | - if ((!empty($quality['jpg']['orig'])) AND true ===$quality['jpg']['orig'] ){ |
|
202 | - if (extension_loaded('imagick')){ |
|
201 | + if ((!empty($quality['jpg']['orig'])) AND true === $quality['jpg']['orig']) { |
|
202 | + if (extension_loaded('imagick')) { |
|
203 | 203 | $im = new \Imagick($image); |
204 | 204 | $q = $im->getImageCompressionQuality(); |
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
208 | - if((!empty($quality['jpg']['max'])) AND $quality['jpg']['max'] < $q ){ |
|
208 | + if ((!empty($quality['jpg']['max'])) AND $quality['jpg']['max'] < $q) { |
|
209 | 209 | $q = $quality['jpg']['max']; |
210 | 210 | } |
211 | 211 | |
212 | - if((!empty($quality['jpg']['min'])) AND $quality['jpg']['min'] > $q ){ |
|
212 | + if ((!empty($quality['jpg']['min'])) AND $quality['jpg']['min'] > $q) { |
|
213 | 213 | $q = $quality['jpg']['min']; |
214 | 214 | } |
215 | 215 | } |
216 | - return imagejpeg($tmp, $destination, $q ); |
|
216 | + return imagejpeg($tmp, $destination, $q); |
|
217 | 217 | break; |
218 | 218 | case "png": |
219 | - if ((!empty($quality['png'])) AND ( (int) $quality['png'] ) AND ( $quality['png'] >= -1 ) AND ( $quality['png'] <=9 ) ) { |
|
219 | + if ((!empty($quality['png'])) AND ((int) $quality['png']) AND ($quality['png'] >= -1) AND ($quality['png'] <= 9)) { |
|
220 | 220 | $q = $quality['png']; |
221 | 221 | } else { |
222 | 222 | $q = -1; // -1 is zlib's default value which is currently ( 11/2018 ) equal to 6 |
223 | 223 | } |
224 | - return imagepng($tmp, $destination, $q ); |
|
224 | + return imagepng($tmp, $destination, $q); |
|
225 | 225 | break; |
226 | 226 | case "gif": |
227 | 227 | return imagegif($tmp, $destination); |
@@ -28,21 +28,21 @@ discard block |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | // check if the name provide in the html input is read by bulletproof |
31 | - public function testImageNameIsSame () { |
|
31 | + public function testImageNameIsSame() { |
|
32 | 32 | $this->bulletproof->setName('samayo'); |
33 | 33 | $this->assertEquals($this->bulletproof->getName(), 'samayo'); |
34 | 34 | } |
35 | 35 | |
36 | 36 | |
37 | 37 | // test image accepts certain mime types |
38 | - public function testMimeTypes () { |
|
38 | + public function testMimeTypes() { |
|
39 | 39 | $this->bulletproof->setMime(['jpeg']); |
40 | 40 | $upload = $this->bulletproof->upload(); |
41 | 41 | $this->assertEquals($upload->getMime(), 'jpeg'); |
42 | 42 | } |
43 | 43 | |
44 | 44 | // check dimensions params |
45 | - public function testDimensions () { |
|
45 | + public function testDimensions() { |
|
46 | 46 | // give it out of range (minimum dimentions than the class requires) |
47 | 47 | $this->bulletproof->setDimension(1, 'b'); |
48 | 48 | $upload = $this->bulletproof->upload(); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | |
53 | 53 | // check size of the image is correct |
54 | - public function testSize () { |
|
54 | + public function testSize() { |
|
55 | 55 | $this->bulletproof->upload(); |
56 | 56 | $this->assertEquals($this->bulletproof->getSize(), 17438); // 17438 is size of the monkey.jpg |
57 | 57 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | // check if setting image storage is correct |
76 | - public function testLocation () { |
|
76 | + public function testLocation() { |
|
77 | 77 | $this->bulletproof->setLocation('uploads'); |
78 | 78 | $this->assertEquals($this->bulletproof->getStorage(), 'uploads'); |
79 | 79 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | // check full path of image uploaded |
83 | 83 | |
84 | - public function testFullpath(){ |
|
84 | + public function testFullpath() { |
|
85 | 85 | $this->bulletproof->setLocation('uploads'); |
86 | 86 | $this->bulletproof->setName('2012'); |
87 | 87 | $this->bulletproof->setMime(['jpeg']); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | |
94 | 94 | // check json return value of image |
95 | - public function testJsonOutput(){ |
|
95 | + public function testJsonOutput() { |
|
96 | 96 | $upload = $this->bulletproof->setName('we_belive_in_json')->upload(); |
97 | 97 | $this->assertSame($upload->getJson(), |
98 | 98 | '{"name":"we_belive_in_json","mime":"jpeg","height":345,"width":384,"size":17438,"storage":"uploads","path":"uploads\/we_belive_in_json.jpeg"}'); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | |
102 | 102 | // check invalid mimetype fails |
103 | 103 | |
104 | - public function testMimeTypeFail () { |
|
104 | + public function testMimeTypeFail() { |
|
105 | 105 | $this->bulletproof->setMime(['gif']); |
106 | 106 | $upload = $this->bulletproof->upload(); |
107 | 107 | $this->assertFalse($upload); |
@@ -109,21 +109,21 @@ discard block |
||
109 | 109 | |
110 | 110 | // check invalid mimetype fails with msg |
111 | 111 | |
112 | - public function testMimeTypeFailWithMsg () { |
|
112 | + public function testMimeTypeFailWithMsg() { |
|
113 | 113 | $this->bulletproof->setMime(['gif']); |
114 | 114 | $upload = $this->bulletproof->upload(); |
115 | 115 | $this->assertEquals($this->bulletproof->getError(), 'Invalid File! Only (gif) image types are allowed'); |
116 | 116 | } |
117 | 117 | |
118 | 118 | // check invalid size with msg |
119 | - public function testImageSizeFailWithMsg () { |
|
119 | + public function testImageSizeFailWithMsg() { |
|
120 | 120 | $this->bulletproof->setSize(888, 9999); |
121 | 121 | $upload = $this->bulletproof->upload(); |
122 | 122 | $this->assertEquals($this->bulletproof->getError(), 'Image size should be minumum 888 bytes (0 kb), upto maximum 9999 bytes (9 kb)'); |
123 | 123 | } |
124 | 124 | |
125 | 125 | // check invalid dimension fails with msg |
126 | -public function testImageDimensionFailWithMsg () { |
|
126 | +public function testImageDimensionFailWithMsg() { |
|
127 | 127 | $this->bulletproof->setDimension(42, 43); |
128 | 128 | $this->bulletproof->upload(); |
129 | 129 | $this->assertEquals($this->bulletproof->getError(), 'Image height/width should be less than 43/42 pixels'); |