예제 #1
0
파일: Cache.php 프로젝트: jewelhuq/fraym
 /**
  * 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;
 }
예제 #2
0
파일: Route.php 프로젝트: jewelhuq/fraym
 /**
  * @param bool $routeInit
  * @param null $menuItemTranslation
  */
 public function renderSite($routeInit = true, $menuItemTranslation = null)
 {
     $tpl = $this->template;
     if (is_object($menuItemTranslation)) {
         $this->loadVirtualRoutes();
         $menuItemTranslation = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItemTranslation')->findOneById($menuItemTranslation->id);
         if (!$this->getCurrentDomain()) {
             $this->setCurrentDomain($this->getRequestDomain());
         }
         // must set before check route, because the locale must be set
         $this->setupPage($menuItemTranslation);
         $virtualRouteContent = $this->checkVirtualRoute();
         if ($virtualRouteContent === false && $this->request->isXmlHttpRequest() === false && $this->isHTTPS() === false && $this->currentMenuItem->https === true) {
             $this->redirectToURL('https://' . $this->getRequestRoute());
         }
         $this->sitefullRoute = rtrim($this->buildFullUrl($this->currentMenuItem), '/');
         if ($routeInit == true) {
             if ($virtualRouteContent !== false) {
                 // virtual route content
                 $this->response->send($virtualRouteContent, true);
             }
             if ($this->currentMenuItem->checkPermission === true && $this->currentMenuItem->parent !== null && $this->user->isLoggedIn() === false) {
                 return $this->menuItemNotFound();
             }
             // read the template content
             $mainTemplateString = $menuItemTranslation->menuItem->template ? $menuItemTranslation->menuItem->template->html : $this->getDefaultMenuItemTemplate();
             if ($this->getFoundURI(false) != trim($this->getRequestRoute(false, false), '/')) {
                 $this->blockParser->setCheckRouteError(true);
                 $tpl->setTemplate('string:' . $mainTemplateString);
                 $content = $tpl->prepareTemplate();
                 $routeExistModules = $this->blockParser->moduleRouteExist($content);
                 if ($routeExistModules === false) {
                     return $this->menuItemNotFound();
                 } else {
                     if ($this->request->isXmlHttpRequest() === true) {
                         // only exec modules where we find the route
                         $this->core->response->send($this->blockParser->parse($routeExistModules));
                     } else {
                         $this->siteManager->addAdminPanel();
                         echo $this->blockParser->parse($content);
                     }
                 }
             } else {
                 $this->siteManager->addAdminPanel();
                 $tpl->renderString($mainTemplateString);
             }
             // cache page if cache enable
             $this->cache->setCacheContent();
         } else {
             $tpl->renderString($menuItemTranslation->menuItem->template->html);
         }
     } else {
         $this->menuItemNotFound();
     }
 }
예제 #3
0
 /**
  * Add block xml before </body> to add the site manager admin panel
  */
 public function addAdminPanel()
 {
     if ($this->user->isAdmin()) {
         $this->template->addFootData($this->blockParser->parse('<block type="module" permission="user" editable="false"><class>\\Fraym\\SiteManager\\SiteManagerController</class><method>adminPanelInit</method><checkRoute>checkRoute</checkRoute></block>'));
     }
 }
예제 #4
0
파일: Template.php 프로젝트: fraym/core
 /**
  * preOutputFiler
  *
  * @param string $source
  * @return string
  */
 public function outputFilter($source)
 {
     // if cached return the source only
     if ($this->outputFilterEnabled === false) {
         return $source;
     }
     $source = $this->blockParser->parse($source, __FUNCTION__);
     $source = $this->addCmsInfo()->prependHeadDataToDocument($source);
     $source = $this->appendFootDataToDocument($source);
     $this->headData = [];
     $this->footData = [];
     // replace title
     $title = htmlspecialchars(trim($this->pageTitle), ENT_QUOTES, 'utf-8');
     $search = '/<title>(.*)<\\/title>/im';
     $replaceWith = empty($title) ? '' : "<title>{$title}</title>";
     $source = preg_replace($search, $replaceWith, $source);
     // replace description
     $description = htmlspecialchars(trim($this->pageDescription), ENT_QUOTES, 'utf-8');
     $search = '/<meta\\s*name=\\"description\\"\\s*content=\\"(.*)\\"\\s*\\/>/im';
     $replaceWith = empty($description) ? '' : '<meta name="description" content="' . $description . '" />';
     $source = preg_replace($search, $replaceWith, $source);
     if (count($this->keywords)) {
         // replace keywords
         $keywords = htmlspecialchars(trim(implode(',', $this->keywords), ','), ENT_QUOTES, 'utf-8');
         $search = '/<meta\\s*name=\\"keywords\\"\\s*content=\\"(.*)\\"\\s*\\/>/im';
         $replaceWith = empty($keywords) ? '' : '<meta name="keywords" content="' . $keywords . '" />';
         $source = preg_replace($search, $replaceWith, $source);
     }
     return $this->execOutputFilters($source);
 }