function smarty_function_load($params, Smarty_Internal_Template $template) { if (isset($params['page']) && isset($params['var'])) { $page_id = trim($params['page']); } else { return; } if (isset($params['language'])) { $language_id = trim($params['language']); } else { $language_id = null; } $page_content = new PageContent(); if ($page_content->load($page_id)) { $data = $page_content->getArray($language_id); $template->assign($params['var'], $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']); }