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 $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $currentLocaleId = $this->route->getCurrentMenuItemTranslation()->locale->id;
     $locales = $xml->xpath('html[@locale="' . $currentLocaleId . '"]');
     $html = trim((string) current($locales));
     // set template content for custom templates
     $this->htmlEditorController->renderHtml($this->replaceLinkTags($html));
 }
Example #3
0
 /**
  * @param \SimpleXMLElement $obj
  * @param null $parent
  * @return \Doctrine\Common\Collections\ArrayCollection
  */
 protected function getItems(\SimpleXMLElement $obj, $parent = null)
 {
     $returnChildren = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($obj->children() as $objData) {
         $id = $this->blockParser->getXmlAttr($objData, 'id');
         $menuItemTranslation = $this->db->createQueryBuilder()->select("menu, translation")->from('\\Fraym\\Menu\\Entity\\MenuItemTranslation', 'translation')->join('translation.menuItem', 'menu')->where('menu.id = :id AND translation.locale = :localeId AND translation.active = 1')->setParameter('id', $id)->setParameter('localeId', $this->route->getCurrentMenuItemTranslation()->locale->id)->getQuery()->getOneOrNullResult();
         $this->db->free();
         if ($menuItemTranslation) {
             $menuItem = clone $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuItemTranslation->menuItem->id);
             $children = $this->getItems($objData, $menuItem);
             $menuItem->parent = $parent;
             $menuItem->children = $children;
             $returnChildren->set($menuItem->id, $menuItem);
         }
     }
     return $returnChildren;
 }
Example #4
0
 /**
  * @return string
  */
 public function getMainTemplate()
 {
     if (empty($this->mainTemplate)) {
         return $this->route->getCurrentMenuItemTranslation()->menuItem->template ? $this->route->getCurrentMenuItemTranslation()->menuItem->template->html : $this->getDefaultMenuItemTemplate();
     }
     return $this->mainTemplate;
 }
Example #5
0
 /**
  * @param $menuId
  * @param $contentId
  * @return mixed
  */
 public function findBlocks($menuId, $contentId)
 {
     $result = $this->db->createQueryBuilder()->select("block, byRef")->from('\\Fraym\\Block\\Entity\\Block', 'block')->leftJoin('block.byRef', 'byRef')->orderBy('block.position', 'asc')->where("block.contentId = :contentId")->andWhere("block.menuItem IS NULL OR block.menuItem = :menuId")->andWhere("block.site = :site")->andWhere("block.menuItemTranslation IS NULL OR block.menuItemTranslation = :menuTranslationId")->setParameter('menuId', $menuId)->setParameter('menuTranslationId', $this->route->getCurrentMenuItemTranslation()->id)->setParameter('site', $this->route->getCurrentMenuItem()->site)->setParameter('contentId', $contentId)->getQuery()->getResult();
     return $result;
 }
Example #6
0
 /**
  * @param $menuId
  * @param $contentId
  * @return mixed
  */
 public function findBlocks($menuId, $contentId)
 {
     $queryBuilder = $this->db->createQueryBuilder();
     $menuTranslationId = $this->route->getCurrentMenuItemTranslation()->id;
     $siteId = $this->route->getCurrentMenuItem()->site->id;
     $blocks = [];
     $query = $queryBuilder->select("block")->from('\\Fraym\\Block\\Entity\\Block', 'block')->andWhere('block INSTANCE OF \\Fraym\\Block\\Entity\\Block OR block.block IS NULL');
     if ($this->user->isAdmin() === false) {
         $query = $query->andWhere("block.menuItem IS NULL OR block.menuItem = :menuId")->andWhere("block.site = :site")->andWhere("block.menuItemTranslation IS NULL OR block.menuItemTranslation = :menuTranslationId")->setParameter('menuId', $menuId)->setParameter('menuTranslationId', $menuTranslationId)->setParameter('site', $siteId);
     }
     $results = $query->addOrderBy('block.position', 'asc')->addOrderBy('block.id', 'desc')->getQuery()->getResult();
     foreach ($results as $result) {
         if ($this->user->isAdmin() && $result->changeSets->count() > 0) {
             $lastChange = $result->changeSets->last();
             if ($lastChange->contentId === $contentId && ($lastChange->menuItem === null || $lastChange->menuItem->id === $menuId) && ($lastChange->menuItemTranslation === null || $lastChange->menuItemTranslation->id === $menuTranslationId) && $lastChange->site->id == $siteId && $lastChange->type !== Entity\ChangeSet::DELETED) {
                 // Changed blocks
                 $lastChange = clone $lastChange;
                 $lastChange->id = $result->id;
                 $blocks[$result->id] = $lastChange;
             }
         } elseif ($this->user->isAdmin() && $result->contentId === $contentId && ($result->menuItem === null || $result->menuItem->id === $menuId) && ($result->menuItemTranslation === null || $result->menuItemTranslation->id === $menuTranslationId) && $result->site->id == $siteId && get_class($result) === 'Fraym\\Block\\Entity\\ChangeSet') {
             // New blocks
             $blocks[$result->id] = $result;
         } elseif ($contentId === $result->contentId && ($result->menuItem === null || $result->menuItem->id === $menuId) && ($result->menuItemTranslation === null || $result->menuItemTranslation->id === $menuTranslationId) && $result->site->id == $siteId && get_class($result) === 'Fraym\\Block\\Entity\\Block') {
             // Old none changed blocks
             $blocks[$result->id] = $result;
         }
     }
     if ($this->user->isAdmin()) {
         uasort($blocks, function ($a, $b) {
             if ($a->position === $b->position) {
                 return $a->id < $b->id ? 1 : -1;
             }
             return $a->position > $b->position ? 1 : -1;
         });
     }
     return $blocks;
 }