Ejemplo n.º 1
0
 /**
  * @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);
 }
Ejemplo n.º 2
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $errors = array();
     $submit = false;
     $values = $this->request->getGPAsArray();
     if ($this->request->post('mailform')) {
         $submit = true;
         $required = $values['required'];
         $fields = $values['field'];
         $this->validation->setData($fields);
         $this->validation->addRule('email', 'email');
         $errorMessages = array();
         foreach ($required as $field => $val) {
             $this->validation->addRule($field, 'notEmpty');
             $errorMessages = array_merge($errorMessages, array($field => array($field => $this->translation->getTranslation('Please fill out the field'))));
         }
         $this->validation->setErrorMessages($errorMessages);
         $check = $this->validation->check();
         if ($check === true) {
             $msg = $this->mail->getMessageInstance();
             $msg->setFrom(array($fields['email']));
             $msg->setSubject($this->config->get('MAILFORM_SUBJECT')->value);
             $msg->setTo(explode(',', $this->config->get('MAILFORM_TO')->value));
             $this->template->assign('fields', $fields);
             $msg->setBody($this->template->fetch('Extension/Mailform/Mail'), 'text/html');
             $this->mail->send();
         } else {
             $errors = $check;
         }
     }
     $this->mailformController->renderHtml($submit, $values, $errors);
 }
Ejemplo n.º 3
0
 /**
  * @param $xml
  * @return string
  */
 public function execBlock($xml)
 {
     if ((string) $xml->view === 'login-logout') {
         return $this->userController->renderForm($xml);
     }
     $this->template->setTemplate("string:");
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
0
 /**
  * @param $xml
  * @return null|string
  */
 protected function getTemplateContent($xml)
 {
     $content = $this->blockParser->getBlockTemplateString($xml);
     if ($content === null) {
         $template = $this->template->setView(self::class)->getTemplateFilePath('Block');
         $content = file_get_contents($template);
     }
     return $content;
 }
Ejemplo n.º 6
0
 /**
  * @return \Fraym\Registry\Entity\text|string
  */
 protected function getTemplatePath()
 {
     $config = $this->config->get('DYNAMIC_TEMPLATE_PATH');
     if (!empty($config->value)) {
         $path = $config->value;
     } else {
         $path = $this->template->getTemplateDir() . DIRECTORY_SEPARATOR . 'Dynamic';
     }
     return $path;
 }
Ejemplo n.º 7
0
 /**
  * @param bool $exit
  * @param bool $parseOutput
  * @return $this
  */
 public function finish($exit = true, $parseOutput = false)
 {
     // get the output and eval for precaching
     $content = ob_get_clean();
     if ($parseOutput === true) {
         // Output the source to the client, for dynamic cache we need to eval the output source
         $content = $this->core->evalString($content);
         // Filter the output to assign css or js files, sets title or meta tags
         $content = $this->template->outputFilter($content);
     }
     $this->addHTTPHeader("Content-Length: " . strlen($content));
     foreach ($this->_httpHeaders as $header) {
         $this->sendHTTPHeader($header);
     }
     echo $content;
     if ($exit) {
         exit;
     }
     return $this;
 }
Ejemplo n.º 8
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>'));
     }
 }
Ejemplo n.º 9
0
 /**
  * @param $xml
  * @return string
  */
 private function execBlockOfTypeJS($xml)
 {
     $consolidatedContent = '';
     if ($this->sequence === false && !$this->getXMLAttr($xml, 'sequence') || $this->sequence !== false && $this->sequence === $this->getXMLAttr($xml, 'sequence')) {
         $jsReplace = '';
         $isUrl = 0;
         $group = $this->getXMLAttr($xml, 'group') ?: 'default';
         foreach ($this->template->getJsFiles($group) as $jsFile) {
             if ($isUrl = preg_match("#((http|https|ftp)://(\\S*?\\.\\S*?))(\\s|\\;|\\)|\\]|\\[|\\{|\\}|,|\"|'|:|\\<|\$|\\.\\s)#ie", $jsFile)) {
                 $file = $jsFile;
             } else {
                 $file = substr($jsFile, 0, 1) == '/' ? $jsFile : rtrim(JS_FOLDER, '/') . '/' . $jsFile;
             }
             if ($isUrl == 0 && $this->getXMLAttr($xml, 'consolidate') === true) {
                 $consolidatedContent .= file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/' . ltrim($file, '/'));
             } else {
                 $fileHash = hash_file('crc32', 'Public/' . $file);
                 $jsReplace .= '<script type="text/javascript" src="' . $file . '?' . $fileHash . '"></script>';
             }
         }
         if ($isUrl == 0 && $this->getXMLAttr($xml, 'consolidate') === true) {
             $jsReplace = $this->consolidateJs($consolidatedContent);
         }
         if ($this->getXMLAttr($xml, 'placeholder')) {
             $this->addPlaceholderReplacement($xml, $jsReplace);
             return '';
         }
         return $jsReplace;
     }
     return $this->xmlString;
 }
Ejemplo n.º 10
0
 /**
  * @param \Fraym\Menu\Entity\MenuItemTranslation $page404
  * @return bool|void
  */
 private function render404Site(\Fraym\Menu\Entity\MenuItemTranslation $page404)
 {
     $this->setupPage($page404);
     $this->response->sendHTTPStatusCode(404);
     if ($this->request->isXmlHttpRequest() === true) {
         return false;
     }
     $this->siteManager->addAdminPanel();
     return $this->template->renderString($this->currentMenuItem->template->html);
 }
Ejemplo n.º 11
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $currentNewsItem = $this->getCurrentNewsItem();
     if ((string) $xml->view === 'list' && (!$currentNewsItem || (string) $xml->forceShowOnDetail == '1')) {
         return $this->newsList($xml);
     }
     if (in_array((string) $xml->view, array('list-category', 'list-tag'))) {
         return $this->listFilter($xml);
     } elseif (in_array((string) $xml->view, array('detail-category', 'detail-tag', 'detail')) && $currentNewsItem) {
         return $this->newsDetail($xml, $currentNewsItem);
     }
     $this->template->setTemplate('string:');
 }
Ejemplo n.º 12
0
 /**
  * @param $xml
  * @return string
  */
 protected function execBlockOfTypeJS($xml)
 {
     $consolidatedContent = '';
     if ($this->sequence === false && !$this->getXmlAttr($xml, 'sequence') || $this->sequence !== false && $this->sequence === $this->getXmlAttr($xml, 'sequence')) {
         $jsReplace = '';
         $isUrl = 0;
         $fileHash = null;
         $group = $this->getXmlAttr($xml, 'group') ?: 'default';
         $jsFiles = $this->template->getJsFiles($group);
         $fileHash = md5(serialize($jsFiles));
         $consolidatedJsFilePath = rtrim(CONSOLIDATE_FOLDER, '/') . '/' . $fileHash . '.js';
         $consolidatedFileExists = is_file('Public' . $consolidatedJsFilePath);
         $consolidate = GLOBAL_CACHING_ENABLED ? $this->getXmlAttr($xml, 'consolidate') : false;
         foreach ($jsFiles as $jsFileData) {
             $jsFile = $jsFileData['file'];
             if ($isUrl = preg_match("#((http|https|ftp)://(\\S*?\\.\\S*?))(\\s|\\;|\\)|\\]|\\[|\\{|\\}|,|\"|'|:|\\<|\$|\\.\\s)#ie", $jsFile)) {
                 $file = $jsFile;
             } else {
                 $file = substr($jsFile, 0, 1) == '/' ? $jsFile : rtrim(JS_FOLDER, '/') . '/' . $jsFile;
             }
             if ($isUrl == 0 && $consolidatedFileExists === false && $consolidate === true) {
                 $consolidatedContent .= ";\n" . file_get_contents('Public/' . ltrim($file, '/'));
             } elseif ($isUrl !== 0 || $consolidate !== true) {
                 if (!$isUrl) {
                     $fileHash = hash_file('crc32', 'Public/' . $file);
                 }
                 $jsReplace .= '<script type="text/javascript" src="' . $file . ($fileHash ? '?' . $fileHash : '') . '"' . (count($jsFileData['attributes']) ? ' ' . implode(' ', $jsFileData['attributes']) : '') . '></script>';
             }
         }
         if ($consolidate === true && (!empty($consolidatedContent) || $consolidatedFileExists)) {
             if ($consolidatedFileExists) {
                 $jsReplace .= '<script type="text/javascript" src="' . $consolidatedJsFilePath . '"></script>';
             } else {
                 $jsReplace .= $this->consolidateJs($consolidatedJsFilePath, $consolidatedContent);
             }
         }
         if ($this->getXmlAttr($xml, 'placeholder')) {
             $this->addPlaceholderReplacement($xml, $jsReplace);
             return '';
         }
         return $jsReplace;
     }
     return $this->xmlString;
 }