Beispiel #1
0
 /**
  * @param null $blockId
  */
 public function getBlockConfig($blockId = null)
 {
     $configXml = null;
     if ($blockId) {
         $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId);
         $configXml = $this->blockParser->getXMLObjectFromString($this->blockParser->wrapBlockConfig($block));
     }
     $this->imageController->getBlockConfig($configXml);
 }
Beispiel #2
0
 /**
  * Loading the block xml configuration. Response JSON.
  *
  * @return bool
  */
 public function getBlockConfig()
 {
     // set if the block exsists
     $id = $this->request->gp('id', false);
     // set if the block is a new one
     $extensionId = $this->request->gp('extensionId', false);
     $result = new \stdClass();
     $extension = null;
     if ($extensionId) {
         $extension = $this->db->getRepository('\\Fraym\\Block\\Entity\\Extension')->findOneById($extensionId);
         $result = $extension->toArray(1);
     } elseif ($id) {
         $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($id);
         if ($block) {
             if ($block->changeSets->count()) {
                 $block = $block->changeSets->last();
             }
             $extension = $block->extension;
             $arrayFromXml = $this->blockParser->xmlToArray($this->blockParser->getXmlObjectFromString($this->blockParser->wrapBlockConfig($block)));
             $result->xml = $arrayFromXml['block'];
             $result = (object) array_merge($block->toArray(2), $block->extension->toArray(1), (array) $result);
             $result->blockName = $block->name;
         }
     }
     return $extension ? $this->response->sendAsJson($result) : false;
 }
Beispiel #3
0
 /**
  * @return string
  */
 public function getContentBlockStructure()
 {
     $template_id = intval($this->request->gp('template_id', 0));
     $result = $this->db->getRepository('\\Fraym\\Template\\Entity\\Template')->findOneById($template_id);
     $result = $this->blockParser->getBlockOfType('content', $result->html);
     return implode('', $result);
 }
Beispiel #4
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;
 }
Beispiel #5
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;
 }
Beispiel #6
0
 /**
  * @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();
     }
 }
Beispiel #7
0
 /**
  * @param null $blockId
  */
 public function getBlockConfig($blockId = null)
 {
     $configXml = null;
     $config = [];
     if ($blockId) {
         $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId);
         $configXml = $this->blockParser->getXmlObjectFromString($this->blockParser->wrapBlockConfig($block));
         $config = json_decode($configXml->mailformOptions, true);
     }
     $this->mailformController->getBlockConfig($config);
 }
Beispiel #8
0
 /**
  * @param $template
  * @return \SimpleXMLElement
  */
 public function getTemplateXmlObject($template)
 {
     $template = $this->getTemplatePath() . DIRECTORY_SEPARATOR . $template;
     $templateContent = file_get_contents($template);
     $blocks = $this->blockParser->getAllBlocks($templateContent);
     foreach ($blocks as $block) {
         $obj = $this->blockParser->getXmlObjectFromString($block);
         if ($this->blockParser->getXmlAttr($obj, 'type') === 'config') {
             return $obj;
         }
     }
 }
 /**
  * @Fraym\Annotation\Route("/fraym/load-dynamic-template-config", name="dynamicTemplateConfig", permission={"\Fraym\User\User"="isAdmin"})
  */
 public function loadDynamicTemplateConfig()
 {
     $template = $this->request->post('template');
     $blockId = $this->request->post('blockId');
     $variables = [];
     if ($blockId) {
         $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId);
         if ($block->changeSets->count()) {
             $block = $block->changeSets->last();
         }
         $xml = $this->blockParser->getXmlObjectFromString($this->blockParser->wrapBlockConfig($block));
         $variables = unserialize((string) $xml->dynamicTemplateConfig);
     }
     $localeResult = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findAll();
     foreach ($localeResult as $locale) {
         $locales[] = $locale->toArray(1);
     }
     $obj = $this->dynamicTemplate->getTemplateXmlObject($template);
     $objTemplate = $obj ? (string) $obj->template : '';
     return $this->renderConfig($objTemplate, $locales, $variables);
 }
Beispiel #10
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>'));
     }
 }
Beispiel #11
0
 /**
  *  Render a only a block template
  */
 public function renderContentBlock($xml)
 {
     $this->blockParser->setCurrentParsingBlockId($this->blockParser->getXMLAttr($xml, 'id'));
     $this->view->setTemplate('Content');
 }
Beispiel #12
0
 /**
  * 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);
 }