Permalink
Browse files

add a simple autoloader (#3792)

* add a simple autoloader

fix #3767

Also update minify to v1.3.42

Signed-off-by: John Rayes <live627@gmail.com>

* Update index.php
  • Loading branch information...
1 parent c71d4fc commit 42c11ab0036f515f66dec7c24108b7b6d6160b3c @live627 live627 committed on GitHub Jan 5, 2017
@@ -1,31 +0,0 @@
-<?php
-
-/*
- * An autoloader for ReCaptcha\Foo classes. This should be require()d
- * by the user before attempting to instantiate any of the ReCaptcha
- * classes.
- */
-
-spl_autoload_register(function ($class) {
- if (substr($class, 0, 10) !== 'ReCaptcha\\') {
- /*
- * If the class does not lie under the "ReCaptcha" namespace,
- * then we can exit immediately.
- */
- return;
- }
-
- /*
- * All of the classes have names like "ReCaptcha\Foo", so we need
- * to replace the backslashes with frontslashes if we want the
- * name to map directly to a location in the filesystem.
- */
- $class = str_replace('\\', '/', $class);
-
- // Check under the current directory.
- $path = __DIR__.'/'.$class.'.php';
- if (is_readable($path)) {
- require_once $path;
- return;
- }
-});
@@ -2128,8 +2128,6 @@ function create_control_verification(&$verificationOptions, $do_test = false)
if ($thisVerification['can_recaptcha'])
{
- require_once($sourcedir . '/ReCaptcha/autoload.php');
-
$reCaptcha = new \ReCaptcha\ReCaptcha($modSettings['recaptcha_secret_key']);
// Was there a reCAPTCHA response?
View
@@ -3594,12 +3594,6 @@ function custMinify($data, $type, $do_deferred = false)
if (!empty($toCache))
return true;
- // Yep, need a bunch of files.
- require_once($sourcedir . '/minify/src/Minify.php');
- require_once($sourcedir . '/minify/src/'. strtoupper($type) .'.php');
- require_once($sourcedir . '/minify/src/Exception.php');
- require_once($sourcedir . '/minify/src/Converter.php');
-
// No namespaces, sorry!
$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -45,3 +45,19 @@ interface
protected
implements
instanceof
+abstract
+boolean
+byte
+char
+double
+final
+float
+goto
+int
+long
+native
+short
+synchronized
+throws
+transient
+volatile
@@ -0,0 +1,46 @@
++
+-
+*
+/
+%
+=
++=
+-=
+*=
+/=
+%=
+<<=
+>>=
+>>>=
+&=
+^=
+|=
+&
+|
+^
+~
+<<
+>>
+>>>
+==
+===
+!=
+!==
+>
+<
+>=
+<=
+&&
+||
+!
+.
+[
+]
+?
+:
+,
+;
+(
+)
+{
+}
@@ -41,5 +41,4 @@
;
(
)
-{
}
@@ -48,12 +48,12 @@ public function __construct($from, $to)
$to = realpath($to) ?: $to;
}
- $from = $this->normalize($from);
- $to = $this->normalize($to);
-
$from = $this->dirname($from);
$to = $this->dirname($to);
+ $from = $this->normalize($from);
+ $to = $this->normalize($to);
+
$this->from = $from;
$this->to = $to;
}
@@ -12,7 +12,7 @@
*
* @author Matthias Mullie <minify@mullie.eu>
* @author Tijs Verkoyen <minify@verkoyen.eu>
- * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved.
+ * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
* @license MIT License
*/
class CSS extends Minify
@@ -76,15 +76,14 @@ public function setImportExtensions(array $extensions)
protected function moveImportsToTop($content)
{
if (preg_match_all('/@import[^;]+;/', $content, $matches)) {
-
// remove from content
foreach ($matches[0] as $import) {
$content = str_replace($import, '', $content);
}
// add to top
$content = implode('', $matches[0]).$content;
- };
+ }
return $content;
}
@@ -95,9 +94,9 @@ protected function moveImportsToTop($content)
* @import's will be loaded and their content merged into the original file,
* to save HTTP requests.
*
- * @param string $source The file to combine imports for.
- * @param string $content The CSS content to combine imports for.
- * @param string[] $parents Parent paths, for circular reference checks.
+ * @param string $source The file to combine imports for
+ * @param string $content The CSS content to combine imports for
+ * @param string[] $parents Parent paths, for circular reference checks
*
* @return string
*
@@ -247,8 +246,8 @@ protected function combineImports($source, $content, $parents)
* @url(image.jpg) images will be loaded and their content merged into the
* original file, to save HTTP requests.
*
- * @param string $source The file to import files for.
- * @param string $content The CSS content to import files for.
+ * @param string $source The file to import files for
+ * @param string $content The CSS content to import files for
*
* @return string
*/
@@ -291,10 +290,10 @@ protected function importFiles($source, $content)
* Minify the data.
* Perform CSS optimizations.
*
- * @param string[optional] $path Path to write the data to.
- * @param string[] $parents Parent paths, for circular reference checks.
+ * @param string[optional] $path Path to write the data to
+ * @param string[] $parents Parent paths, for circular reference checks
*
- * @return string The minified data.
+ * @return string The minified data
*/
public function execute($path = null, $parents = array())
{
@@ -315,6 +314,7 @@ public function execute($path = null, $parents = array())
$css = $this->stripWhitespace($css);
$css = $this->shortenHex($css);
$css = $this->shortenZeroes($css);
+ $css = $this->shortenFontWeights($css);
$css = $this->stripEmptyTags($css);
// restore the string we've extracted earlier
@@ -351,7 +351,7 @@ public function execute($path = null, $parents = array())
* (e.g. ../../images/image.gif, if the new CSS file is 1 folder deeper).
*
* @param Converter $converter Relative path converter
- * @param string $content The CSS content to update relative urls for.
+ * @param string $content The CSS content to update relative urls for
*
* @return string
*/
@@ -479,21 +479,79 @@ protected function move(Converter $converter, $content)
* Shorthand hex color codes.
* #FF0000 -> #F00.
*
- * @param string $content The CSS content to shorten the hex color codes for.
+ * @param string $content The CSS content to shorten the hex color codes for
*
* @return string
*/
protected function shortenHex($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(?=[; }])/i', '#$1$2$3', $content);
+
+ // we can shorten some even more by replacing them with their color name
+ $colors = array(
+ '#F0FFFF' => 'azure',
+ '#F5F5DC' => 'beige',
+ '#A52A2A' => 'brown',
+ '#FF7F50' => 'coral',
+ '#FFD700' => 'gold',
+ '#808080' => 'gray',
+ '#008000' => 'green',
+ '#4B0082' => 'indigo',
+ '#FFFFF0' => 'ivory',
+ '#F0E68C' => 'khaki',
+ '#FAF0E6' => 'linen',
+ '#800000' => 'maroon',
+ '#000080' => 'navy',
+ '#808000' => 'olive',
+ '#CD853F' => 'peru',
+ '#FFC0CB' => 'pink',
+ '#DDA0DD' => 'plum',
+ '#800080' => 'purple',
+ '#F00' => 'red',
+ '#FA8072' => 'salmon',
+ '#A0522D' => 'sienna',
+ '#C0C0C0' => 'silver',
+ '#FFFAFA' => 'snow',
+ '#D2B48C' => 'tan',
+ '#FF6347' => 'tomato',
+ '#EE82EE' => 'violet',
+ '#F5DEB3' => 'wheat',
+ );
- return $content;
+ return preg_replace_callback(
+ '/(?<=[: ])('.implode(array_keys($colors), '|').')(?=[; }])/i',
+ function ($match) use ($colors) {
+ return $colors[strtoupper($match[0])];
+ },
+ $content
+ );
+ }
+
+ /**
+ * Shorten CSS font weights.
+ *
+ * @param string $content The CSS content to shorten the font weights for
+ *
+ * @return string
+ */
+ protected function shortenFontWeights($content)
+ {
+ $weights = array(
+ 'normal' => 400,
+ 'bold' => 700,
+ );
+
+ $callback = function ($match) use ($weights) {
+ return $match[1].$weights[$match[2]];
+ };
+
+ return preg_replace_callback('/(font-weight\s*:\s*)('.implode('|', array_keys($weights)).')(?=[;}])/', $callback, $content);
}
/**
* Shorthand 0 values to plain 0, instead of e.g. -0em.
*
- * @param string $content The CSS content to shorten the zero values for.
+ * @param string $content The CSS content to shorten the zero values for
*
* @return string
*/
@@ -527,6 +585,24 @@ protected function shortenZeroes($content)
// strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0)
$content = preg_replace('/'.$before.'-?0+'.$units.'?'.$after.'/', '0\\1', $content);
+ // remove zeroes where they make no sense in calc: e.g. calc(100px - 0)
+ // the 0 doesn't have any effect, and this isn't even valid without unit
+ // strip all `+ 0` or `- 0` occurrences: calc(10% + 0) -> calc(10%)
+ // looped because there may be multiple 0s inside 1 group of parentheses
+ do {
+ $previous = $content;
+ $content = preg_replace('/\(([^\(\)]+)\s+[\+\-]\s+0(\s+[^\(\)]+)?\)/', '(\\1\\2)', $content);
+ } while ($content !== $previous);
+ // strip all `0 +` occurrences: calc(0 + 10%) -> calc(10%)
+ $content = preg_replace('/\(\s*0\s+\+\s+([^\(\)]+)\)/', '(\\1)', $content);
+ // strip all `0 -` occurrences: calc(0 - 10%) -> calc(-10%)
+ $content = preg_replace('/\(\s*0\s+\-\s+([^\(\)]+)\)/', '(-\\1)', $content);
+ // I'm not going to attempt to optimize away `x * 0` instances:
+ // it's dumb enough code already that it likely won't occur, and it's
+ // too complex to do right (order of operations would have to be
+ // respected etc)
+ // what I cared about most here was fixing incorrectly truncated units
+
return $content;
}
@@ -539,7 +615,7 @@ protected function shortenZeroes($content)
*/
protected function stripEmptyTags($content)
{
- return preg_replace('/(^|\})[^\{\}]+\{\s*\}/', '\\1', $content);
+ return preg_replace('/(^|\}|;)[^\{\};]+\{\s*\}/', '\\1', $content);
}
/**
@@ -553,7 +629,7 @@ protected function stripComments()
/**
* Strip whitespace.
*
- * @param string $content The CSS content to strip the whitespace for.
+ * @param string $content The CSS content to strip the whitespace for
*
* @return string
*/
@@ -587,7 +663,7 @@ protected function stripWhitespace($content)
/**
* Check if file is small enough to be imported.
*
- * @param string $path The path to the file.
+ * @param string $path The path to the file
*
* @return bool
*/
Oops, something went wrong.

0 comments on commit 42c11ab

Please sign in to comment.