/**
  * Renders the current frontend page into the basic frontend template.html file and adds some useful data to the
  * template (e.x. logged in user if there is any, site title, etc.)
  * 
  * @param PageModel $pageModel
  *
  * @return HttpResponse The rendered CMS page ready to send it to the client
  * @throws HttpException if the page does not exist or is not accessible for the current user
  */
 protected function generateCMSPage(PageModel $pageModel)
 {
     if ($this->cmsPage === null) {
         $this->eventDispatcher->dispatch('cms.page_not_found', new PageNotFoundEvent($this->httpRequest));
         throw new HttpException('Could not find cms page', 404);
     }
     if (!$pageModel->hasUserReadAccess($this->cmsPage, $this->auth)) {
         $this->eventDispatcher->dispatch('cms.page_access_denied', new PageAccessDeniedEvent($this->httpRequest));
         throw new HttpException('You don\'t have access to this page', 403);
     }
     $currentEnv = $this->core->getCurrentDomain()->environment;
     $lastChanged = new \DateTime($this->cmsPage->getLastModified());
     $cacheDuration = 18000;
     //31536000; <-- a year
     $responseHeaders = array('Content-Type' => 'text/html; charset=utf-8', 'Content-Language' => $this->cmsPage->getLanguage(), 'Cache-Control' => 'No-Cache', 'Last-Modified' => null, 'Vary' => 'Accept-Encoding');
     // Don't cache if a module controls page content
     /*if($this->cmsRoute->getModuleID() === null)
     		$responseHeaders['Last-Modified'] = gmdate('D, d M Y H:i:s \G\M\T', $lastChanged->getTimestamp());*/
     /*if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $this->cmsPage->getLastModified() <= date('Y-m-d H:i:s', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])))
     		return new HttpResponse(304, null, $responseHeaders);*/
     $lang = $this->getLocaleHandler()->getLanguage();
     // HTML Cache here!
     $pageCacheActive = isset($this->core->getSettings()->cms->{$currentEnv}->page_cache) ? $this->core->getSettings()->cms->{$currentEnv}->page_cache : false;
     $pageCacheMode = $this->cmsPage->getCacheMode();
     $cacheDir = $this->core->getSiteCacheDir() . 'html' . DIRECTORY_SEPARATOR;
     $pageCacheFile = $cacheDir . 'page-' . $this->cmsPage->getID() . '.html';
     if ($pageCacheActive === true && $this->auth->isLoggedIn() === false && in_array($pageCacheMode, array(CmsPage::CACHE_MODE_PRIVATE, CmsPage::CACHE_MODE_PUBLIC)) && stream_resolve_include_path($pageCacheFile)) {
         $fileTime = filemtime($pageCacheFile);
         // TODO: check if a parent page has changed not only the current
         if ($this->cmsPage->getLastModified() === null || $fileTime >= $lastChanged->getTimestamp()) {
             if ($currentEnv === 'dev') {
                 echo 'Cached page found from: ' . date('d.m.Y H:i:s', $fileTime);
             }
             return new HttpResponse(200, $pageCacheFile, $responseHeaders, true);
         }
     }
     $pageElementCache = isset($this->core->getSettings()->cms->{$currentEnv}) && $this->core->getSettings()->cms->{$currentEnv}->page_cache === true;
     $elementModel = new ElementModel($this->db);
     $elements = $elementModel->getElementTree($this->cmsPage, $pageElementCache);
     if ($this->cmsPage->getLayoutID() !== null && $elements->offsetExists($this->cmsPage->getLayoutID())) {
         $this->cmsPage->setLayout($elements->offsetGet($this->cmsPage->getLayoutID()));
     }
     $elementView = new CmsView($this->templateEngine, $this->core->getSiteRoot() . 'templates' . DIRECTORY_SEPARATOR . $this->currentDomain->template . DIRECTORY_SEPARATOR . 'elements' . DIRECTORY_SEPARATOR);
     // Last modified
     $dtLastModified = new \DateTime($this->cmsPage->getLastModified());
     $dtCreated = new \DateTime($this->cmsPage->getCreated());
     $pageHtml = $this->cmsPage->render($this, $elementView);
     /*$dtLastModifiedRender = new \DateTime($this->cmsPage->getLastModified());
     
     		$responseHeaders['Last-Modified'] = gmdate('D, d M Y H:i:s \G\M\T', $dtLastModifiedRender->getTimestamp());*/
     $tplVars = array('siteTitle' => $this->cmsPage->getTitle(), 'meta_description' => $this->cmsPage->getDescription(), 'page_id' => $this->cmsPage->getID(), 'page_html' => $pageHtml, 'modifier_name' => $this->cmsPage->getModifierName(), 'creator_name' => $this->cmsPage->getCreatorName(), 'date_modified' => $dtLastModified->format($this->getLocaleHandler()->getDateTimeFormat()), 'date_created' => $dtCreated->format($this->getLocaleHandler()->getDateTimeFormat()), 'logged_in' => $this->auth->isLoggedIn(), 'cms_page' => true, 'area_head' => $this->generateAreaHead($this->cmsPage), 'area_body' => $this->generateAreaBody($this->cmsPage), 'current_uri' => urlencode($this->httpRequest->getURI()));
     if ($this->auth->isLoggedIn()) {
         $stmntElements = $this->db->prepare("SELECT ID, name, class FROM cms_element_available WHERE active = '1' ORDER BY name");
         $resElements = $this->db->select($stmntElements);
         $elementList = array();
         foreach ($resElements as $mod) {
             $mod->author = null;
             $mod->version = null;
             $mod->description = null;
             $settingsFile = $this->core->getSiteRoot() . 'settings' . DIRECTORY_SEPARATOR . 'elements' . DIRECTORY_SEPARATOR . $mod->name . '.config.json';
             if (stream_resolve_include_path($settingsFile) === false) {
                 $elementList[] = $mod;
                 continue;
             }
             try {
                 $jsonObj = JsonUtils::decodeFile($settingsFile);
                 if (isset($jsonObj->name) === true) {
                     $mod->name = isset($jsonObj->name->{$lang}) ? $jsonObj->name->{$lang} : $jsonObj->name->en;
                 }
                 if (isset($jsonObj->description) === true) {
                     $mod->description = isset($jsonObj->description->{$lang}) ? $jsonObj->description->{$lang} : $jsonObj->description->en;
                 }
             } catch (\Exception $e) {
                 $this->logger->error('Could not parse config file of element: ' . $mod->name, $e);
             }
             $elementList[] = $mod;
         }
         usort($elementList, function ($a, $b) {
             return strtolower($a->name) > strtolower($b->name);
         });
         $tplVars['elements'] = $elementList;
     }
     $html = $this->renderBasicTemplate('template.html', $tplVars);
     if ($pageCacheActive === true && $this->auth->isLoggedIn() === false && in_array($pageCacheMode, array(CmsPage::CACHE_MODE_PRIVATE, CmsPage::CACHE_MODE_PUBLIC))) {
         file_put_contents($pageCacheFile, $html);
     }
     $httpStatusCode = $this->cmsPage->getErrorCode() !== null ? $this->cmsPage->getErrorCode() : 200;
     return new HttpResponse($httpStatusCode, $html, $responseHeaders);
 }
Example #2
0
 public function getSettings($settingsName, $componentType = null)
 {
     $moduleConfigPath = $this->core->getSiteRoot() . 'settings' . DIRECTORY_SEPARATOR;
     if ($componentType !== null) {
         $moduleConfigPath .= $componentType . DIRECTORY_SEPARATOR;
     }
     $moduleConfigFileName = $settingsName . '.json';
     if (file_exists($moduleConfigPath . $moduleConfigFileName) === false) {
         return new \stdClass();
     }
     $currentEnv = $this->core->getCurrentDomain()->environment;
     $jsonSettings = JsonUtils::decodeFile($moduleConfigPath . $moduleConfigFileName);
     if (isset($jsonSettings->{$currentEnv}) === true) {
         return $jsonSettings->{$currentEnv};
     } elseif (isset($jsonSettings->default) === true) {
         return $jsonSettings->default;
     }
     return new \stdClass();
 }
Example #3
0
 public function getModulesWithFrontendController()
 {
     $stmntMods = $this->db->prepare("\n\t\t\tSELECT *\n\t\t\tFROM cms_mod_available\n\t\t\tWHERE active = 1\n\t\t\tAND frontendcontroller IS NOT NULL\n\t\t\tORDER BY name\n\t\t");
     $resMods = $this->db->select($stmntMods);
     foreach ($resMods as $mod) {
         $mod->manifest_content = JsonUtils::decode($mod->manifest_content);
     }
     return $resMods;
 }
 public function renderDestinationColumn($value, $record, $selector, $tableRenderer)
 {
     $lang = $this->getLocaleHandler()->getLanguage();
     $destination = null;
     if ($record->external_source !== null) {
         $destination = 'External: <a href="' . $record->external_source . '">' . $record->external_source . '</a>';
     } elseif ($record->redirect_route_IDFK !== null) {
         $destination = 'Route redirect: <a href="#">' . $record->rr_pattern . ' (#' . $record->rrID . ')</a>';
     } elseif ($record->page_ID !== null) {
         $pagePath = $this->pageModel->getPagePath($record->page_ID);
         $pagePathHtml = array();
         foreach ($pagePath as $id => $title) {
             $pagePathHtml[] = '<a href="/backend/page/' . $id . '">' . $title . '</a>';
         }
         $pagePathHtml[] = ' <a href="#">' . $record->page_title . ' (#' . $record->page_ID . ', ' . $record->page_lang . ')</a>';
         $destination = 'Page: ' . implode(' > ', $pagePathHtml);
     } else {
         $destination = null;
     }
     if ($record->mod_IDFK !== null) {
         $jsonMod = JsonUtils::decode($record->manifest_content);
         $destination .= ', Module: <a href="/backend/module/' . $record->mod_name . '">' . (isset($jsonMod->name->{$lang}) ? $jsonMod->name->{$lang} : $record->mod_name) . '</a>';
     }
     return $destination;
 }
Example #5
0
 /**
  * Checks if the element has settings to configure per element instance
  * 
  * @param FrontendController $fec
  *
  * @return bool True if it has settings else false
  */
 protected function hasConfig(FrontendController $fec)
 {
     $configFilePath = $fec->getCore()->getSiteRoot() . 'settings' . DIRECTORY_SEPARATOR . 'elements' . DIRECTORY_SEPARATOR;
     $configFile = $configFilePath . $this->identifier . '.config.json';
     if (file_exists($configFile) === false) {
         return false;
     }
     try {
         $json = JsonUtils::decodeFile($configFile);
         if (!isset($json->settings)) {
             return false;
         }
     } catch (\Exception $e) {
         var_dump($e, JsonUtils::minify(file_get_contents($configFile)));
         return false;
     }
     return true;
 }
 /**
  * Shows all the pages and their dependencies
  * 
  * @return HttpResponse
  */
 public function getModulesOverview()
 {
     if ($this->httpRequest->getVar('deactivate') !== null) {
         $this->setActivationOfModule($this->httpRequest->getVar('deactivate'), false);
     }
     if ($this->httpRequest->getVar('activate') !== null) {
         $this->setActivationOfModule($this->httpRequest->getVar('activate'), true);
     }
     $stmntMods = $this->db->prepare("\n\t\t\tSELECT ID, name identifier, active, path, manifest_content\n\t\t\tFROM cms_mod_available\n\t\t\tORDER BY name\n\t\t");
     $resMods = $this->db->select($stmntMods);
     $lang = $this->core->getLocaleHandler()->getLanguage();
     foreach ($resMods as $mod) {
         $mod->version = null;
         $mod->author = null;
         $mod->description = null;
         $mod->name = null;
         $mod->active_link = $mod->active == 1 ? 'yes [<a href="?deactivate=' . $mod->ID . '">deactivate</a>]' : 'no [<a href="?activate=' . $mod->ID . '">activate</a>]';
         try {
             $manifestObj = JsonUtils::decode($mod->manifest_content);
             if (isset($manifestObj->version)) {
                 $mod->version = $manifestObj->version;
             }
             if (isset($manifestObj->author->name)) {
                 $mod->author = $manifestObj->author->name;
             }
             if (isset($manifestObj->desciption->{$lang})) {
                 $mod->description = $manifestObj->description->{$lang};
             } elseif (isset($manifestObj->description->en)) {
                 $mod->description = $manifestObj->description->de;
             }
             if (isset($manifestObj->name->{$lang})) {
                 $mod->name = $manifestObj->name->{$lang};
             } elseif (isset($manifestObj->name->en)) {
                 $mod->name = $manifestObj->name->de;
             }
         } catch (\Exception $e) {
             $this->logger->error('Could not load module information from json string', $e);
             continue;
         }
     }
     return $this->generatePageFromTemplate('backend-modules-overview.html', array('modules' => $resMods, 'siteTitle' => 'Modules'));
 }
 /**
  * @param string $keywords
  * @param string $language
  *
  * @return \stdClass[]
  */
 protected function getCmsSearchResults($keywords, $language)
 {
     $searchModel = new SearchModel($this->cmsController->getDB());
     $searchIndex = Lucene::open($this->cmsController->getCore()->getSiteRoot() . 'index' . DIRECTORY_SEPARATOR . $language);
     /*$query = new Boolean(); // new Fuzzy()
     		$query->addSubquery(QueryParser::parse(
     			$keywords
     		), true);*/
     QueryParser::suppressQueryParsingExceptions();
     $query = QueryParser::parse($keywords);
     //$hits = $searchIndex->find($query, 'score', SORT_NUMERIC, SORT_DESC);
     $hits = $searchIndex->find($query);
     //echo'<pre>'; var_dump(/*$hits, */$indexSize, $documents);
     $searchResultsArr = array();
     $highlighter = new CmsSearchHighlighter($keywords);
     //$highlighter = new DefaultHighlighter();
     foreach ($hits as $hit) {
         /** @var QueryHit $hit */
         $searchResult = new \stdClass();
         // Gibt Zend_Search_Lucene_Document Objekte für diesen Treffer zurück
         /** @var Document $document */
         $document = $hit->getDocument();
         $doc = $searchModel->getDocumentByID($document->getFieldUtf8Value('ID'));
         if ($doc->getID() === null) {
             continue;
         }
         $fldType = $doc->getType();
         if ($fldType !== 'core_page') {
             $contentChunks = $highlighter->highlightMatches(strip_tags($doc->getDescription()), 'UTF-8');
             if ($contentChunks == '') {
                 $contentChunks = null;
             }
             // Gibt ein Zend_Search_Lucene_Field Objekt von
             // Zend_Search_Lucene_Document zurück
             $searchResult->title = $highlighter->highlightMatches(strip_tags($doc->getTitle()), 'UTF-8');
             $searchResult->description = $contentChunks;
             $searchResult->url = $doc->getPath();
             if (isset($searchResultsArr[$fldType]) === false) {
                 $stmntModName = $this->cmsController->getDB()->prepare("\n\t\t\t\t\t\tSELECT manifest_content FROM cms_mod_available WHERE name = ?\n\t\t\t\t\t");
                 $resModName = $this->cmsController->getDB()->select($stmntModName, array($fldType));
                 $displayName = $fldType;
                 try {
                     $manifestObj = JsonUtils::decode($resModName[0]->manifest_content);
                     if (isset($manifestObj->name->{$language})) {
                         $displayName = $manifestObj->name->{$language};
                     } elseif (isset($manifestObj->name->en)) {
                         $displayName = $manifestObj->name->en;
                     }
                 } catch (\Exception $e) {
                 }
                 $searchResultsArr[$fldType] = new \stdClass();
                 $searchResultsArr[$fldType]->title = $displayName;
                 $searchResultsArr[$fldType]->results = array();
             }
             $searchResultsArr[$doc->getType()]->results[] = $searchResult;
         } else {
             $contentChunks = $this->createChunkedHighlighting($highlighter->highlightMatches(strip_tags($doc->getDescription()), 'UTF-8'));
             if ($contentChunks == '') {
                 $contentChunks = null;
             }
             // Gibt ein Zend_Search_Lucene_Field Objekt von
             // Zend_Search_Lucene_Document zurück
             $searchResult->title = $highlighter->highlightMatches(strip_tags($doc->getTitle()), 'UTF-8');
             $searchResult->description = $contentChunks;
             $searchResult->url = $doc->getPath();
             if (isset($searchResultsArr[$fldType]) === false) {
                 $searchResultsArr[$fldType] = new \stdClass();
                 $searchResultsArr[$fldType]->title = 'Andere Suchresultate';
                 $searchResultsArr[$fldType]->results = array();
             }
             $searchResultsArr[$doc->getType()]->results[] = $searchResult;
         }
     }
     return $searchResultsArr;
 }
    /**
     * Generates the HTML config form for the element
     * 
     * @param BackendController $backendController
     * @param int $pageID The current pages ID
     *
     * @return string The config box as HTML
     * @throws CMSException
     * @throws \Exception
     */
    public function generateConfigBox(BackendController $backendController, $pageID)
    {
        $lang = $backendController->getLocaleHandler()->getLanguage();
        $configFilePath = $backendController->getCore()->getSiteRoot() . 'settings' . DIRECTORY_SEPARATOR . 'elements' . DIRECTORY_SEPARATOR;
        $configFile = $configFilePath . $this->identifier . '.config.json';
        if (file_exists($configFile) === false) {
            throw new CMSException('No settings found for this module: ' . $this->identifier);
        }
        try {
            $jsonConfig = JsonUtils::decode(file_get_contents($configFile));
            if (!isset($jsonConfig->settings)) {
                return 500;
            }
        } catch (\Exception $e) {
            throw $e;
        }
        $modIDStr = 'mod-' . $this->ID . '-' . $pageID;
        $boxHtml = '<form method="post" class="mod-config-form" element="' . $modIDStr . '"><fieldset><legend>Element specific</legend>';
        foreach ($jsonConfig->settings as $key => $entry) {
            $fld = null;
            $hintHtml = isset($entry->hint) ? '<abbr title="' . $entry->hint->{$lang} . '">?</abbr>' : null;
            $settingValue = isset($this->settings->{$key}) ? $this->settings->{$key} : null;
            $idStr = 'mod-' . $this->ID . '-' . $pageID . '-' . $key;
            $requiredHtml = $entry->required ? '<em title="required">*</em>' : null;
            $requiredAttr = $entry->required ? ' required' : null;
            if (in_array($entry->type, array('select', 'option', 'select-multi', 'multi-option'))) {
                $multiple = null;
                $multiBrackets = null;
                if (in_array($entry->type, array('select-multi', 'multi-option'))) {
                    $multiple = ' multiple';
                    $multiBrackets = '[]';
                }
                $fld .= '<dl><dt><label for="' . $idStr . '">' . $entry->label->{$lang} . $requiredHtml . '</label></dt>
				<dd><select name="' . $key . $multiBrackets . '" id="' . $idStr . '"' . $requiredAttr . $multiple . '>';
                $values = $this->getValues($entry->options, $backendController);
                foreach ($values as $optKey => $optVal) {
                    if (in_array($entry->type, array('select-multi', 'multi-option'))) {
                        $selected = in_array($optKey, $this->settings->{$key}) ? ' selected' : null;
                    } else {
                        $selected = $this->settings->{$key} == $optKey ? ' selected' : null;
                    }
                    $fld .= '<option value="' . $optKey . '"' . $selected . '>' . $optVal . '</option>';
                }
                $fld .= '</select>' . $hintHtml . '</dd></dl>';
            } elseif (in_array($entry->type, array('input', 'email', 'number', 'url', 'regex', 'string', 'text', 'file'))) {
                $dataAttrs = null;
                if (in_array($entry->type, array('input', 'text', 'string', 'number', 'regex'))) {
                    $typeStr = 'text';
                    $dataAttrs = ' data-type="string"';
                } elseif ($entry->type === 'file') {
                    $typeStr = 'text';
                    $dataAttrs = ' class="filechooser"';
                } else {
                    $typeStr = $entry->type;
                    $dataAttrs = ' data-type="' . $entry->type . '"';
                }
                if ($entry->type === 'regex' && isset($entry->regex)) {
                    $dataAttrs = ' data-type="regex" regex="' . $entry->regex . '"';
                }
                if ($entry->type === 'number') {
                    $minStr = isset($entry->min) ? ' min="' . $entry->min . '"' : null;
                    $maxStr = isset($entry->max) ? ' max="' . $entry->max . '"' : null;
                    if ($minStr !== null || $maxStr !== null) {
                        $dataAttrs = $minStr . $maxStr;
                    }
                }
                if (in_array($entry->type, array('input', 'text', 'string'))) {
                    $minStr = isset($entry->minLength) ? ' minlength="' . $entry->minLength . '"' : null;
                    $maxStr = isset($entry->maxLength) ? ' maxlength="' . $entry->maxLength . '"' : null;
                    if ($minStr !== null || $maxStr !== null) {
                        $dataAttrs = $minStr . $maxStr;
                    }
                }
                $sizeClass = StringUtils::afterFirst($entry->type, '-');
                $sizeClassStr = $sizeClass !== '' ? ' class="' . $sizeClass . '"' : null;
                $fld .= '<dl><dt><label for="' . $idStr . '">' . $entry->label->{$lang} . $requiredHtml . '</label></dt>
				<dd><input type="' . $typeStr . '" name="' . $key . '" id="' . $idStr . '" value="' . $settingValue . '"' . $sizeClassStr . '' . $requiredAttr . '' . $dataAttrs . '>' . $hintHtml . '</dd></dl>';
            } elseif (in_array($entry->type, array('radio', 'multi-checkbox'))) {
                $values = $this->getValues($entry->options, $backendController);
                $type = null;
                $multiBrackets = in_array($entry->type, array('multi-checkbox')) ? '[]' : null;
                $selectedArr = is_array($this->settings->{$key}) ? $this->settings->{$key} : array($this->settings->{$key});
                if ($entry->type === 'radio') {
                    $type = 'radio';
                } elseif ($entry->type === 'multi-checkbox') {
                    $type = 'checkbox';
                }
                $fld .= '<dl><dt>' . $entry->label->{$lang} . '</dt>
				<dd><ul>';
                foreach ($values as $optKey => $optVal) {
                    $checked = in_array($optKey, $selectedArr) ? ' checked' : null;
                    $fld .= '<li><label><input type="' . $type . '" name="' . $key . $multiBrackets . '" value="' . $optKey . '"' . $checked . '>' . $optVal . '</label></li>';
                }
                $fld .= '</ul></dd></dl>';
            } elseif ($entry->type == 'toggle') {
                $checked = $this->settings->{$key} == 1 ? ' checked' : null;
                $fld .= '<dl><dt><label for="' . $idStr . '">' . $entry->label->{$lang} . $requiredHtml . '</label></dt>
				<dd><input type="checkbox" name="' . $key . '" id="' . $idStr . '" value="1"' . $requiredAttr . $checked . '>' . $hintHtml . '</dd></dl>';
            } elseif ($entry->type === 'wysiwyg') {
                $fld .= '<dl><dt><label for="' . $idStr . '">' . $entry->label->{$lang} . $requiredHtml . '</label></dt>
				<dd><textarea class="ckeditor" name="' . $key . '" id="' . $idStr . '"' . $requiredAttr . '>' . $settingValue . '</textarea>' . $hintHtml . '</dd></dl>';
            } else {
                throw new CMSException('Unknow settings data-type: ' . $entry->type);
            }
            $boxHtml .= $fld;
        }
        $boxHtml .= '</fieldset><fieldset><legend>General</legend>
			<dl><dt>Pass on</dt>
				<dd><ul>
					<li><label><input type="checkbox" value="1">Override children\'s settings</label></li>
				</ul></dd>
			</dl>';
        if ($this->settingsSelf) {
            $boxHtml .= '<dl>
				<dt>Delete</dt>
				<dd><ul>
					<li><label><input name="delete_settings" type="checkbox" value="1">Delete specific element settings on this page</label></li>
				</ul></dd>
			</dl>';
        }
        $boxHtml .= '</fieldset></form>
		<script src="/js/ckeditor/ckeditor.js"></script>
		<script src="/js/ckeditor/config.js"></script>
		<script src="/js/jquery.filechooser.js"></script>
		<script src="/js/cms.settingsbox.js"></script>';
        return $boxHtml;
    }