/** * save the output to cache file * * @return bool ture or false */ public function setCacheContent() { if (!is_dir(self::DIR_PAGES)) { mkdir(self::DIR_PAGES, 0755, true); } $filename = $this->getCacheName(); // create the cache filename $cacheFilename = self::DIR_PAGES . $filename . '.cache.php'; $cacheFilenamePhpData = self::DIR_PAGES . $filename . '.cache.config.php'; $cacheInfo = "/*\n\n" . str_ireplace('*', '', print_r($_SERVER, true)) . "\n\n*/\n\n"; $phpCode = '<?php ' . $cacheInfo; $currentMenuItem = $this->route->getCurrentMenuItemTranslation(); if (!$this->request->isXmlHttpRequest() && !$this->request->isPost() && $this->user->isAdmin() === false && (!is_file($cacheFilename) || !is_file($cacheFilenamePhpData)) && $this->isCachingActive($currentMenuItem->menuItem)) { // save cached file $source = $this->template->outputFilter(ob_get_contents()); $phpCode .= '$menuItemTranslation = <<<\'EOT\'' . "\n" . json_encode($currentMenuItem->toArray()) . "\n" . 'EOT;' . "\n"; $phpCode .= '$domain = "' . $this->route->getCurrentDomain() . '";'; $phpCode .= '$executedBlocks = <<<\'EOT\'' . "\n" . json_encode($this->blockParser->getExecutedBlocks()) . "\n" . 'EOT;' . "\n"; file_put_contents($cacheFilenamePhpData, $phpCode); file_put_contents($cacheFilename, $source . "<!-- CACHED : " . date('Y-m-d H:i:s') . " -->"); // clean the output buffer ob_clean(); // parse cached blocks for first output echo $this->blockParser->parse($source, false, true); return true; } $source = $this->template->outputFilter(ob_get_contents()); // clean the output buffer ob_clean(); // parse cached blocks for first output echo $this->blockParser->parse($source, false, true); return false; }