Example #1
0
 /**
  * Combines an array of CSS or JS files and places them as a single file
  *
  * @param string $type     The type of compilation, 'css' or 'js'
  * @param string $element  The element name
  * @param array  $values   An array of file paths
  * @return void
  */
 protected function handleMinified($type, $element, $values)
 {
     $paths = array();
     $media = NULL;
     foreach ($values as $value) {
         if (is_array($value)) {
             $paths[] = $this->minification_prefix . $value['path'];
             if ($type == 'css') {
                 $media = !empty($value['media']) ? $value['media'] : NULL;
             }
         } else {
             $paths[] = $this->minification_prefix . $value;
         }
     }
     $hash = sha1(join('|', $paths));
     $cache_file = $this->minification_directory . $hash . '.' . $type;
     $regenerate = FALSE;
     $checked_paths = FALSE;
     if (!file_exists($cache_file)) {
         $regenerate = TRUE;
     } elseif ($this->minification_mode == 'development') {
         $cache_mtime = filemtime($cache_file);
         $checked_paths = TRUE;
         foreach ($paths as $path) {
             if (!file_exists($path)) {
                 throw new fEnvironmentException('The file specified, %s, does not exist under the $path_prefix specified', preg_replace('#^' . preg_quote($this->minification_prefix, '#') . '#', '', $path));
             }
             if (filemtime($path) > $cache_mtime) {
                 $regenerate = TRUE;
                 break;
             }
         }
     }
     if ($regenerate) {
         $minified = '';
         foreach ($paths as $path) {
             $path_cache_file = $this->minification_directory . sha1($path) . '.' . $type;
             if ($checked_paths && !file_exists($path)) {
                 throw new fEnvironmentException('The file specified, %s, does not exist under the $path_prefix specified', preg_replace('#^' . preg_quote($this->minification_prefix, '#') . '#', '', $path));
             }
             // Checks if this path has been cached
             if (file_exists($path_cache_file) && filemtime($path_cache_file) >= filemtime($path)) {
                 $minified_path = file_get_contents($path_cache_file);
             } else {
                 $minified_path = trim($this->minify(file_get_contents($path), $type));
                 file_put_contents($path_cache_file, $minified_path);
             }
             $minified .= "\n" . $minified_path;
         }
         file_put_contents($cache_file, substr($minified, 1));
     }
     $version = filemtime($cache_file);
     $compiled_value = fFilesystem::translateToWebPath($cache_file) . '?v=' . $version;
     if ($type == 'css' && $media) {
         $compiled_value = array('path' => $compiled_value, 'media' => $media);
     }
     $method = 'place' . strtoupper($type);
     $this->{$method}($compiled_value);
 }
 /**
  * Gets the directory's current path
  * 
  * If the web path is requested, uses translations set with
  * fFilesystem::addWebPathTranslation()
  * 
  * @param  boolean $translate_to_web_path  If the path should be the web path
  * @return string  The path for the directory
  */
 public function getPath($translate_to_web_path = FALSE)
 {
     $this->tossIfDeleted();
     if ($translate_to_web_path) {
         return fFilesystem::translateToWebPath($this->directory);
     }
     return $this->directory;
 }
Example #3
0
 /**
  * Gets the file's current path (directory and filename)
  * 
  * If the web path is requested, uses translations set with
  * fFilesystem::addWebPathTranslation()
  * 
  * @param  boolean $translate_to_web_path  If the path should be the web path
  * @return string  The path (directory and filename) for the file
  */
 public function getPath($translate_to_web_path = FALSE)
 {
     if ($translate_to_web_path) {
         return fFilesystem::translateToWebPath($this->file);
     }
     return $this->file;
 }