Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * @param int $mode
  */
 public function init($mode = Core::ROUTE_NORMAL)
 {
     $globalConfigs = array('ENV' => self::ENV_DEVELOPMENT, 'JS_FOLDER' => '/js', 'CSS_FOLDER' => '/css', 'CONSOLIDATE_FOLDER' => '/consolidated', 'PROFILER_ENABLED' => false);
     foreach ($globalConfigs as $config => $val) {
         if (!defined($config)) {
             define($config, $val);
         }
     }
     if (ENV == self::ENV_DEVELOPMENT) {
         error_reporting(E_ALL | E_STRICT);
         ini_set("display_errors", 1);
     }
     if (is_object($this->session) && $this->isCLI() === false) {
         $this->session->start();
     }
     $this->mode = $mode;
     $this->startTimer(__CLASS__);
     // Assign our output handler to output clean errors
     ob_start();
     // ingore user abort, is recommed for ajax request and db changes
     if ($this->request->isXmlHttpRequest()) {
         ignore_user_abort(true);
     }
     $this->registryManager->init();
     if ($this->isCLI() === false) {
         // Sanitize all request variables
         $_GET = $this->sanitize($_GET);
         $_POST = $this->sanitize($_POST);
         $_COOKIE = $this->sanitize($_COOKIE);
         if ($mode === Core::ROUTE_NORMAL) {
             $this->cache->load();
             // Try to load a site by the requested URI
             $this->route->loadSite();
             if (!$this->request->isXmlHttpRequest() && !$this->request->isPost()) {
                 echo '<!-- ' . $this->getPageLoadTime() . 'sec -->';
             }
             $this->response->finish(false, true);
         }
     } else {
         $params = getopt('p:');
         if ($params['p']) {
             $_SERVER['REQUEST_URI'] = $params['p'];
             $this->route->loadVirtualRoutes();
             echo $this->route->checkVirtualRoute();
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @param $xml
  * @param $blockHtml
  * @return mixed|\SimpleXMLElement|string
  */
 protected function processBlockAttributes($xml, $blockHtml)
 {
     $blockType = strtolower($this->getXmlAttr($xml, 'type'));
     if ($this->block->inEditMode() && in_array($blockType, $this->editModeTypes)) {
         $block = null;
         if (($this->getXmlAttr($xml, 'type') === 'extension' || $this->getXmlAttr($xml, 'type') === null) && ($id = $this->getXmlAttr($xml, 'id'))) {
             $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($id);
         }
         $editable = $this->getXmlAttr($xml, 'editable');
         if ($editable === true || $editable === null) {
             $blockHtml = $this->blockController->addBlockInfo($block, $blockHtml, $xml, true);
         }
     }
     // interleaved unique content elements -> pop last element
     if (end($this->parsingBlockIds) == $this->getXmlAttr($xml, 'id')) {
         array_pop($this->parsingBlockIds);
     }
     // Disable cache on block attribute or on element level
     if ($this->getXmlAttr($xml, 'cached') != '1' && ($this->getXmlAttr($xml, 'cache') === false || isset($xml->cache) && $xml->cache == 0 && !$this->request->isPost() && GLOBAL_CACHING_ENABLED === true && $this->route->getCurrentMenuItem()->caching === true)) {
         $blockHtml = $this->disableBlockCaching($xml);
     } else {
         // add block state to check permission or end/start date on caching
         $blockHtml = $this->addBlockCacheState($xml, $blockHtml);
     }
     if ($this->getXmlAttr($xml, 'placeholder') !== null) {
         return $this->addPlaceholderReplacement($xml, $blockHtml);
     }
     return $blockHtml;
 }