Exemple #1
0
 /**
  * Replace the {{theme_plus_cached_asset::*}} insert tag.
  *
  * @see \Contao\Controller::replaceInsertTags
  *
  * @param $tag
  *
  * @return bool|mixed|string
  * @SuppressWarnings(PHPMD.EvalExpression)
  */
 public function replaceCachedAssetInsertTag($tag)
 {
     if ('theme_plus_cached_asset::' === substr($tag, 0, 25)) {
         /** @var string $cacheKey The cache key. */
         $cacheKey = substr($tag, 25);
         /** @var string $assets */
         $assets = $this->cache->fetch($cacheKey);
         if ($assets) {
             $variables = $this->compiler->getVariables();
             extract($variables);
             return eval($assets);
         }
         return '';
     }
     return false;
 }
 /**
  * Load all stylesheets from the cache.
  *
  * @param \LayoutModel $layout
  * @param array        $stylesheets The search and replace array.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.EvalExpression)
  */
 protected function loadStylesheets(\PageModel $page, \LayoutModel $layout, &$stylesheets)
 {
     $key = 'css:' . $page->id;
     $assets = $this->cache->fetch($key);
     if ($assets) {
         if ($page->cache) {
             $stylesheets .= sprintf('{{theme_plus_cached_asset::%s|uncached}}', $key);
         } else {
             $variables = $this->compiler->getVariables();
             extract($variables);
             $stylesheets .= eval($assets);
         }
     } else {
         $page->cache = false;
         $this->parseStylesheets(RenderMode::LIVE, $page, $layout, $stylesheets);
     }
 }
 /**
  * Load all javascripts from the cache.
  *
  * @param \LayoutModel $layout
  * @param array        $scripts The search and replace array.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.EvalExpression)
  */
 protected function loadJavaScripts(\PageModel $page, \LayoutModel $layout, &$headScripts, &$bodyScripts)
 {
     $headKey = 'js:head:' . $page->id;
     $headAssets = $this->cache->fetch($headKey);
     $bodyKey = 'js:body:' . $page->id;
     $bodyAssets = $this->cache->fetch($bodyKey);
     if ($headAssets && $bodyAssets) {
         if ($page->cache) {
             $headScripts .= sprintf('{{theme_plus_cached_asset::%s|uncached}}', $headKey);
             $bodyScripts .= sprintf('{{theme_plus_cached_asset::%s|uncached}}', $bodyKey);
         } else {
             $variables = $this->compiler->getVariables();
             extract($variables);
             $headScripts .= eval($headAssets);
             $bodyScripts .= eval($bodyAssets);
         }
     } else {
         $page->cache = false;
         $this->parseJavaScripts(RenderMode::LIVE, $page, $layout, $headScripts, $bodyScripts);
     }
 }