(bug 25735) Fix regex error in PHP < 5.2.2 by using old (?P<name>) syntax for named...
[lhc/web/wiklou.git] / includes / libs / CSSMin.php
index 93b75ac..7271b36 100644 (file)
@@ -34,7 +34,7 @@ class CSSMin {
         * result in a 1/3 increase in size.
         */
        const EMBED_SIZE_LIMIT = 24576;
-       const URL_REGEX = 'url\([\'"]?(?<file>[^\?\)\:\'"]*)\??[^\)\'"]*[\'"]?\)';
+       const URL_REGEX = 'url\([\'"]?(?P<file>[^\?\)\:\'"]*)\??[^\)\'"]*[\'"]?\)';
        
        /* Protected Static Members */
        
@@ -78,11 +78,13 @@ class CSSMin {
         * Remaps CSS URL paths and automatically embeds data URIs for URL rules preceded by an /* @embed * / comment
         *
         * @param $source string CSS data to remap
-        * @param $path string File path where the source was read from
+        * @param $local string File path where the source was read from
+        * @param $remote string URL path to the file
+        * @param $embed ???
         * @return string Remapped CSS data
         */
        public static function remap( $source, $local, $remote, $embed = true ) {
-               $pattern = '/((?<embed>\s*\/\*\s*\@embed\s*\*\/)(?<pre>[^\;\}]*))?' . self::URL_REGEX . '(?<post>[^;]*)[\;]?/';
+               $pattern = '/((?P<embed>\s*\/\*\s*\@embed\s*\*\/)(?P<pre>[^\;\}]*))?' . self::URL_REGEX . '(?P<post>[^;]*)[\;]?/';
                $offset = 0;
                while ( preg_match( $pattern, $source, $match, PREG_OFFSET_CAPTURE, $offset ) ) {
                        // Shortcuts
@@ -91,16 +93,17 @@ class CSSMin {
                        $post = $match['post'][0];
                        $file = "{$local}/{$match['file'][0]}";
                        $url = "{$remote}/{$match['file'][0]}";
-                       // Only proceed if we can access the fill
+                       // Only proceed if we can access the file
                        if ( file_exists( $file ) ) {
                                // Add version parameter as a time-stamp in ISO 8601 format, using Z for the timezone, meaning GMT
                                $url .= '?' . gmdate( 'Y-m-d\TH:i:s\Z', round( filemtime( $file ), -2 ) );
                                // If we the mime-type can't be determined, no embedding will take place
                                $type = false;
+                               $realpath = realpath( $file );
                                // Try a couple of different ways to get the mime-type of a file, in order of preference
-                               if ( function_exists( 'finfo_file' ) && function_exists( 'finfo_open' ) ) {
+                               if ( $realpath && function_exists( 'finfo_file' ) && function_exists( 'finfo_open' ) ) {
                                        // As of PHP 5.3, this is how you get the mime-type of a file; it uses the Fileinfo PECL extension
-                                       $type = finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $file );
+                                       $type = finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $realpath );
                                } else if ( function_exists( 'mime_content_type' ) ) {
                                        // Before this was deprecated in PHP 5.3, this used to be how you get the mime-type of a file
                                        $type = mime_content_type( $file );
@@ -139,7 +142,7 @@ class CSSMin {
        /**
         * Removes whitespace from CSS data
         *
-        * @param $source string CSS data to minify
+        * @param $css string CSS data to minify
         * @return string Minified CSS data
         */
        public static function minify( $css ) {