Пример #1
0
function asset_url($path)
{
    if (strpos($path, 'http') === 0) {
        return $path;
    }
    $version = Glucose::config('dynamic', 'assets') ? filemtime(BASE_PATH . $path) : static_asset_version();
    return Glucose::config('base_url', 'assets') . "{$path}?{$version}";
}
Пример #2
0
 /**
  * @todo This is messy. Clean it up.
  */
 private function versionFileAssets($url)
 {
     if (strpos($url, 'http') === 0) {
         return $url;
     }
     $cache_name = md5($url) . '.versioned.css';
     $cache_path = BASE_PATH . Glucose::config('cache_dir', 'template') . $cache_name;
     $orig_mtime = Glucose::config('dynamic', 'assets') == true ? filemtime($this->urlToPath($url)) : static_asset_version();
     if (file_exists($cache_path) && $orig_mtime < filemtime($cache_path)) {
         $file = Glucose::config('cache_dir', 'template') . $cache_name;
         $file_path = $cache_path;
         if (Glucose::config('dynmaic', 'assets') == false) {
             return $file;
         }
     } else {
         $file = $url;
         $file_path = $this->urlToPath($url);
     }
     $file_contents = file_get_contents($file_path);
     $new_contents = $this->versionAssets($file_contents);
     if ($file_contents !== $new_contents) {
         file_put_contents($cache_path, $new_contents);
         return Glucose::config('cache_dir', 'template') . $cache_name;
     } else {
         return $file;
     }
 }