Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * @param bool $exit
  * @param bool $parseOutput
  * @return $this
  */
 public function finish($exit = true, $parseOutput = false)
 {
     // get the output and eval for precaching
     $content = ob_get_clean();
     if ($parseOutput === true) {
         // Output the source to the client, for dynamic cache we need to eval the output source
         $content = $this->core->evalString($content);
         // Filter the output to assign css or js files, sets title or meta tags
         $content = $this->template->outputFilter($content);
     }
     $this->addHTTPHeader("Content-Length: " . strlen($content));
     foreach ($this->_httpHeaders as $header) {
         $this->sendHTTPHeader($header);
     }
     echo $content;
     if ($exit) {
         exit;
     }
     return $this;
 }