public static function cachePage($page_id, $language_id, $content) { if (Config::get()->cacheActivated) { if (Settings::get('useCache', false) === true) { $pages = new Pages(); $page_properties = $pages->getProperties($page_id); if ($page_properties['cachable'] > 0) { $page_folder = $pages->getPagePublishedFolder($page_id, $page_properties); if (is_dir(rtrim($page_folder, "/"))) { $cache_file = $page_folder . $language_id . self::CACHE_FILENAME; $res = @file_put_contents($cache_file, $content); if ($res !== false) { Db::delete('page_cache', "(`page-id` = :pageId) AND (`language-id` = :languageId)", array(':pageId' => $page_id, ':languageId' => $language_id)); Db::insert('page_cache', array('page-id' => $page_id, 'language-id' => $language_id, 'timestamp' => time())); } } } } } return true; }
public function onBeforeLoadPageDataFields($parameters, &$data) { $pages = new Pages(); $this->parameters = $parameters; $page_id = $parameters['pageId']; $page_properties = $pages->getProperties($page_id); $template_id = $page_properties['template-id']; $page_structure = $this->getPageStructure($template_id); $inherit = array(); foreach ($page_structure as $block_id => $block) { if ($block['type'] == 'datablock') { foreach ($block['fields'] as $field) { if (isset($field['inherit'])) { if ($field['inherit'] === true) { $inherit[] = array('data_block_id' => $block_id, 'field_id' => $field['id']); } } } } } if (count($inherit) > 0) { $this->page_data = $data; $this->loadAncestorPages($page_id); foreach ($inherit as $item) { $this->inherit($template_id, $item['data_block_id'], $item['field_id']); } $data = $this->page_data; } }
public function getPage($page_id, $language_id, $preview = false) { // Smarty initialisieren $smarty = new Template(); // Seiten-Infos laden $pages = new Pages(); $page_properties = $pages->getProperties($page_id); if ($page_properties === false) { Helpers::fatalError('A page with the ID "' . $page_id . '" does not exist!'); } // Wenn die Vorschau-Version der Seite angefordert wurde, // überprüfen, ob überhaupt eine editierte Version der Seite existiert, // wenn nicht, Vorschau-Modus ignorieren if ($preview) { if ($page_properties['status'] == Pages::STATUS_PUBLISHED) { $preview = false; } } // Seiteneigenes Verzeichnis abhängig von $preview auslesen if ($preview) { $page_files = $pages->getPageFilesEditFolder($page_id, $page_properties); $page_files_url = $pages->getPageFilesEditUrl($page_id, $page_properties); } else { $page_files = $pages->getPageFilesPublishedFolder($page_id, $page_properties); $page_files_url = $pages->getPageFilesPublishedUrl($page_id, $page_properties); } $page_url = $pages->getPageUrl($page_id, $language_id, $page_properties); // Grundlegende Variablen zuweisen, die zwar mit dem Inhalt nichts zu tun haben, aber wichtig sind :-) $smarty->assign('baseUrl', Config::get()->baseUrl); $smarty->assign('publicUrl', Config::get()->baseUrl . 'system/custom/frontend/public/'); $smarty->assign('pageUrl', $page_url); $smarty->assign('pageId', $page_id); $smarty->assign('languageId', $language_id); $smarty->assign('templateId', $page_properties['template-id']); $smarty->assign('uniqueId', $page_properties['unique-id']); $smarty->assign('pageFiles', $page_files); $smarty->assign('pageFilesUrl', $page_files_url); $languages = Config::get()->languages->list->getArrayCopy(); foreach ($languages as $key => $value) { $languages[$key]['id'] = $key; } $smarty->assign('languages', $languages); // Seiten-Struktur laden $pages_structure = DataStructure::pagesArray(); if (!isset($pages_structure[$page_properties['template-id']]['structure'])) { Helpers::fatalError('A page template with the ID "' . $page_properties['template-id'] . '" does not exist!'); } $page_structure = $pages_structure[$page_properties['template-id']]['structure']; // Die folgenden Parameter werden an die Modifikatoren und Plugins übergeben $parameters = array('preview' => $preview, 'pageId' => $page_id, 'languageId' => $language_id, 'templateId' => $page_properties['template-id'], 'uniqueId' => $page_properties['unique-id'], 'pageUrl' => $page_url, 'pageFiles' => $page_files, 'pageFilesUrl' => $page_files_url, 'smarty' => $smarty); // Seiten-Inhalt laden $content_object = new PageContent(); if (!$content_object->load($page_id, !$preview)) { Helpers::fatalError('The content of the page with the ID "' . $page_id . '" could not be loaded!'); } $page_content = $content_object->getArray($language_id, $smarty, $parameters); // Globale Elemente laden $this->loadGlobalElementsPage($smarty, $language_id); $this->assignGlobalElementsToSmarty($smarty, $language_id); // Inhalte zuweisen foreach ($page_structure as $block_id => $block) { if ($block['type'] == 'datablock') { $block_data = null; if (isset($page_content[$block_id])) { $block_data = $page_content[$block_id]; } $smarty->assign($block_id, $block_data); } elseif ($block['type'] == 'container') { $container_content = ''; if (isset($page_content[$block_id])) { if (is_array($page_content[$block_id])) { foreach ($page_content[$block_id] as $container_element_key => $container_element) { $container_content = $container_content . $this->getElement($page_id, $language_id, $container_element['elementId'], $container_element['content'], $preview); } } } $smarty->assign($block_id, $container_content); } } // registrierte Plugins aufrufen, vielleicht hat ja noch jemand etwas hinzuzufügen :-) Plugins::call(Plugins::ASSIGN_PAGE_DATA, $parameters); // Smarty-Template für die Template-ID der aktuellen Seite zurückgeben $page_template = $pages_structure[$page_properties['template-id']]; return $smarty->fetch('file:[pages]' . $page_template['template']); }