Пример #1
0
 /**
  * In CSS content, prepend a path to relative URIs
  *
  * @param string $css
  *
  * @param string $path The path to prepend.
  *
  * @return string
  */
 public static function prepend($css, $path)
 {
     self::$_prependPath = $path;
     $css = self::_trimUrls($css);
     // append
     $css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/', array(self::$className, '_processUriCB'), $css);
     $css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/', array(self::$className, '_processUriCB'), $css);
     self::$_prependPath = null;
     return $css;
 }
Пример #2
0
 /**
  * Takes a list of files, and combines them into a single minified file.
  * Doesn't bother if none of the files have been modified since the cache
  * file was written.
  *
  * @param string $type 'css' or 'js'.
  * @param array $file_group Array of ('file' => filename, 'minified' => is_minified) to combine and minify.
  * @param bool $minify Whether to minify the files, as well as combining them.
  * @param $inline @todo Not used, document this
  *
  * @return string The path to the cache file which was written.
  * @throws Asset_Exception
  */
 protected static function combine($type, $file_group, $minify, $inline)
 {
     // Get the last modified time of all of the component files.
     $last_mod = 0;
     foreach ($file_group as $file) {
         // If it is a remote file just assume it is not modified,
         // otherwise we are stuck making a ton of HTTP requests.
         if (strpos($file['file'], '//') !== false) {
             continue;
         }
         $mod = filemtime(FCPATH . $file['file']);
         if ($mod > $last_mod) {
             $last_mod = $mod;
         }
     }
     // $filename = md5(implode('', array_map(function($a) {
     // 	return $a['file'];
     // }, $file_group)).($minify ? 'min' : '').$last_mod).'.'.$type;
     // PHP 5.2
     $bits = array();
     foreach ($file_group as $a) {
         $bits[] = $a['file'];
     }
     $filename = md5(implode('', $bits) . ($minify ? 'min' : '') . $last_mod) . '.' . $type;
     $filepath = FCPATH . self::$cache_path . '/' . $filename;
     $needs_update = !file_exists($filepath);
     if ($needs_update) {
         $content = '';
         foreach ($file_group as $file) {
             if (self::$show_files_inline) {
                 $content .= PHP_EOL . '/* ' . $file['file'] . ' */' . PHP_EOL . PHP_EOL;
             }
             if ($file['minified'] || !$minify) {
                 $content_temp = self::load_file($file['file'], $type, $file_group) . PHP_EOL;
                 if ($type == 'css') {
                     $content .= Asset_Cssurirewriter::rewrite($content_temp, dirname($file['file']), null, self::$symlinks);
                 } else {
                     $content .= $content_temp;
                 }
             } else {
                 $file_content = self::load_file($file['file'], $type, $file_group);
                 if ($file_content === false) {
                     show_error("Couldn't not open file {$file['file']}");
                     //						throw new Asset_Exception("Couldn't not open file {$file['file']}");
                 }
                 if ($type == 'js') {
                     $content .= Asset_JSMin::minify($file_content) . PHP_EOL;
                 } elseif ($type == 'css') {
                     $css = Asset_Csscompressor::process($file_content) . PHP_EOL;
                     $content .= Asset_Cssurirewriter::rewrite($css, dirname($file['file']), null, self::$symlinks);
                 }
             }
         }
         file_put_contents($filepath, $content, LOCK_EX);
         $mtime = time();
         // @todo Not used variable.
     }
     return $filename;
 }