Example #1
0
 public function __toString()
 {
     $collected = $this->get();
     #
     # cached ouput
     #
     try {
         if ($this->use_cache) {
             $recent = 0;
             $root = DOCUMENT_ROOT;
             foreach ($collected as $file) {
                 $recent = max($recent, filemtime($root . $file));
             }
             $cache = new FileCache([FileCache::T_REPOSITORY => \ICanBoogie\app()->config['repository.files'] . '/assets', FileCache::T_MODIFIED_TIME => $recent]);
             $key = sha1(implode(',', $collected)) . '.js';
             $rc = $cache->get($key, [$this, 'cache_construct'], [$collected]);
             if ($rc) {
                 return PHP_EOL . PHP_EOL . '<script type="text/javascript" src="' . $cache->repository . '/' . $key . '"></script>' . PHP_EOL . PHP_EOL;
             }
         }
     } catch (\Exception $e) {
         echo render_exception($e);
     }
     #
     # default output
     #
     $rc = '';
     foreach ($collected as $url) {
         $rc .= '<script type="text/javascript" src="' . escape($url) . '"></script>' . PHP_EOL;
     }
     return $rc;
 }
Example #2
0
    public function __toString()
    {
        $collected = $this->get();
        try {
            if ($this->use_cache) {
                $recent = 0;
                $root = DOCUMENT_ROOT;
                foreach ($collected as $file) {
                    $recent = max($recent, filemtime($root . $file));
                }
                $cache = new FileCache([FileCache::T_REPOSITORY => \ICanBoogie\app()->config['repository.files'] . '/assets', FileCache::T_MODIFIED_TIME => $recent]);
                $key = sha1(implode(',', $collected)) . '.css';
                $rc = $cache->get($key, [$this, 'cache_construct'], [$collected]);
                if ($rc) {
                    $list = json_encode($collected);
                    return <<<EOT

<link type="text/css" href="{$cache->repository}/{$key}" rel="stylesheet" />

<script type="text/javascript">

var brickrouge_cached_css_assets = {$list};

</script>

EOT;
                }
            }
        } catch (\Exception $e) {
            echo render_exception($e);
        }
        #
        # default ouput
        #
        $rc = '';
        foreach ($collected as $url) {
            $rc .= '<link type="text/css" href="' . escape($url) . '" rel="stylesheet" />' . PHP_EOL;
        }
        return $rc;
    }
Example #3
0
 /**
  * An operation (save, delete, online, offline) has invalidated the cache, thus we have to
  * reset it.
  */
 public static function invalidate_cache()
 {
     global $core;
     $cache = new FileCache(array(FileCache::T_REPOSITORY => $core->config['repository.cache'] . '/pages'));
     return $cache->clear();
 }