/**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $languageMenu = array();
     $currentLocale = $this->locale->getLocale()->id;
     $currentMenuItem = $this->route->getCurrentMenuItem();
     foreach ($currentMenuItem->translations as $translation) {
         $url = $translation->getUrl(true);
         $languageMenu[$translation->locale->id] = array('enable' => $translation->active, 'url' => $url, 'active' => $translation->locale->id === $currentLocale, 'name' => $translation->locale->name);
     }
     foreach ($languageMenu as $locale => $language) {
         if ($language['enable'] === false) {
             $menuItem = $currentMenuItem;
             do {
                 $menuItem = $menuItem->parent;
             } while ($menuItem->parent);
             $translation = $menuItem->getTranslation($locale);
             $languageMenu[$locale]['url'] = $translation ? $translation->url : '/';
         } else {
             $localeData = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findOneById($locale);
             $localeData = explode('_', strtolower($localeData->locale));
             $this->template->addHeadData('<link rel="alternate" hreflang="' . $localeData[0] . '" href="' . $language['url'] . '" />', 'hreflang_' . $localeData[0]);
         }
     }
     $this->languageMenuController->renderHtml($languageMenu);
 }
Example #2
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $languageMenu = array();
     $currentLocale = $this->locale->getLocale()->id;
     $defaultLocale = $this->locale->getDefaultLocale();
     $currentMenuItem = $this->route->getCurrentMenuItem();
     $locales = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findAll();
     foreach ($currentMenuItem->translations as $translation) {
         $url = $translation->url === '' ? '/' : $translation->url;
         $languageMenu[$translation->locale->id] = array('url' => $url, 'active' => $translation->locale->id === $currentLocale, 'name' => $translation->locale->name);
     }
     foreach ($locales as $locale) {
         if (!isset($languageMenu[$locale->id])) {
             $menuItem = $currentMenuItem;
             do {
                 $m = $menuItem->parent;
                 if ($m) {
                     $menuItem = $m;
                 }
             } while ($m);
             foreach ($menuItem->translations as $mTranslation) {
                 if ($mTranslation->locale->id === $locale->id) {
                     $url = $mTranslation->url;
                     break;
                 } elseif ($mTranslation->locale->id === $defaultLocale->id) {
                     $url = $mTranslation->url;
                 }
             }
             $languageMenu[$locale->id] = array('url' => $url === '' ? '/' : $url, 'active' => $locale->id === $currentLocale, 'name' => $locale->name);
         }
     }
     $this->languageMenuController->renderHtml($languageMenu);
 }
Example #3
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;
 }
 /**
  * @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($html);
 }
Example #5
0
 /**
  * @param $menuItems
  * @return bool|\stdClass
  */
 public function buildMenu($menuItems)
 {
     if (isset($menuItems) && $menuItems->children !== null) {
         $menu = new \stdClass();
         $menu->children = $this->getItems($menuItems);
     } else {
         // Get the root menuItem of the current site.
         $menu = $this->route->getMenu();
     }
     return $menu;
 }
Example #6
0
 /**
  * @param $blockHtml
  * @return mixed
  */
 public function replaceLinkTags($blockHtml)
 {
     $callback = function ($matches) {
         $id = trim(trim($matches[1], '"'), "'");
         if (is_numeric($id)) {
             $menuItemTranslation = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItemTranslation')->findOneById($id);
             if ($menuItemTranslation) {
                 return ' href="' . $this->route->buildFullUrl($menuItemTranslation->menuItem, true) . '"';
             }
         }
         return $matches[0];
     };
     return preg_replace_callback('#\\s*(?i)href\\s*=\\s*(\\"([^"]*\\")|\'[^\']*\'|([^\'">\\s]+))#si', $callback, $blockHtml);
 }
Example #7
0
 /**
  * @param $xml
  */
 protected function listFilter($xml)
 {
     $listPageUrl = '';
     $listPage = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($xml->listPage);
     if ($listPage) {
         $listPageUrl = $listPage->getUrl($this->route, true);
     }
     if ((string) $xml->view == 'list-category') {
         $categories = $this->db->createQueryBuilder()->select("c")->from('\\Extension\\News\\Entity\\Category', 'c')->join('c.news', 'n')->leftJoin('n.sites', 's')->where("s = :site OR n.sites IS EMPTY")->orderBy("c.name", 'asc')->setParameter('site', $this->route->getCurrentMenuItem()->site)->getQuery()->getResult();
         return $this->newsController->renderNewsCategories($listPageUrl, $categories);
     } elseif ((string) $xml->view == 'list-tag') {
         $tags = $this->db->createQueryBuilder()->select("t")->from('\\Extension\\News\\Entity\\Tag', 't')->join('t.news', 'n')->leftJoin('n.sites', 's')->where("s = :site OR n.sites IS EMPTY")->orderBy("t.name", 'asc')->setParameter('site', $this->route->getCurrentMenuItem()->site)->getQuery()->getResult();
         return $this->newsController->renderNewsTags($listPageUrl, $tags);
     }
 }
Example #8
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();
         }
     }
 }
Example #9
0
File: Core.php Project: fraym/core
 /**
  * @param int $mode
  */
 public function init($mode = Core::ROUTE_NORMAL)
 {
     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();
             $this->response->finish(false, true);
         }
     } else {
         $params = getopt('p:');
         if ($params['p']) {
             $_SERVER['REQUEST_URI'] = $params['p'];
             $this->route->loadRoutes();
             echo $this->route->getVirtualRouteContent();
         }
     }
 }
Example #10
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 #11
0
 /**
  * @param null $contentId
  * @return mixed|string
  */
 private function getDataFromBlocksByContentId($contentId = null)
 {
     $html = '';
     $blocks = $this->findBlocks($this->route->getCurrentMenuItem()->id, $contentId);
     if ($blocks && is_array($blocks)) {
         foreach ($blocks as $block) {
             $html .= $this->parseBlock($block);
         }
     }
     return $html;
 }