public function getStringAsHTML($sKey, $aParams = array(), $sLanguageId = null, $sDefaultValue = null) { $mResult = TranslationPeer::getString($sKey, $sLanguageId, $sDefaultValue, $aParams, true); $oTemplate = new Template(TemplateIdentifier::constructIdentifier('result'), null, true); $oTemplate->replaceIdentifier('result', $mResult); return $oTemplate->render(); }
public function testPStringWithHTMLAsTemplate() { $sString = TranslationPeer::getString('simple_quote', 'de', null, array('quoted' => 'String')); $oTemplate = new Template(TemplateIdentifier::constructIdentifier('string'), null, true); $oTemplate->replaceIdentifier('string', $sString); $this->assertSame(">String<", $oTemplate->render()); }
/** * @dataProvider validCalculations */ public function testCalculations($sCalculation, $sExpectedResult = '0') { $oTemplate = new Template(TemplateIdentifier::constructIdentifier('doCalculation', $sCalculation), null, true); $oExpected = new Template(TemplateIdentifier::constructIdentifier('result'), null, true); $oExpected->replaceIdentifier('result', $sExpectedResult); $this->assertSame($oExpected->render(), $oTemplate->render()); }
private function listInSidebar(Template $oTemplate) { $aWidgets = Module::listModulesByType(WidgetModule::getType()); $oLinks = new Template(TemplateIdentifier::constructIdentifier('links'), null, true); foreach ($aWidgets as $sWidgetName => $aWidgetInfo) { $oLink = new Template('<a href="{{href}}">{{name}}</a><br />', null, true); $oLink->replaceIdentifier('href', LinkUtil::link(array($sWidgetName), get_class())); $oLink->replaceIdentifier('name', WidgetModule::getDisplayNameByName($sWidgetName)); $oLinks->replaceIdentifierMultiple('links', $oLink); } $oTemplate->replaceIdentifierMultiple('sidebar_content', $oLinks); }
public function saveData($aCondition) { $oContentObject = ContentObjectQuery::create()->findPk($this->iContentObjectId); $bHasCondition = false; if (trim($aCondition['condition_left']) === '') { $oContentObject->setConditionSerialized(null); } else { $oConditionTemplate = new Template('', null, true); $aTemplateContents = array(); $oIf = new TemplateIdentifier('if', $aCondition['comparison'], array(), $oConditionTemplate); $oIf->setParameter('1', $aCondition['condition_left']); $oIf->setParameter('2', $aCondition['condition_right']); $aTemplateContents[] = $oIf; $aTemplateContents[] = 'visible'; $aTemplateContents[] = new TemplateIdentifier('endIf', null, array(), $oConditionTemplate); $oConditionTemplate = new Template($aTemplateContents, null, true); $oContentObject->setConditionSerialized(serialize($oConditionTemplate)); $bHasCondition = true; } $oContentObject->save(); return $bHasCondition; }
public function renderFile() { $iTemplateFlags = 0; $oResourceFinder = ResourceFinder::create(array(DIRNAME_MODULES, $this->sModuleType, $this->sModuleName, DIRNAME_TEMPLATES))->returnObjects(); $sFileName = "{$this->sModuleName}.{$this->sModuleType}.{$this->sResourceType}"; $oResourceFinder->addPath($sFileName . Template::$SUFFIX); if ($this->sResourceType === ResourceIncluder::RESOURCE_TYPE_CSS) { header("Content-Type: text/css;charset=utf-8"); $oResourceFinder->all(); } else { if ($this->sResourceType === ResourceIncluder::RESOURCE_TYPE_JS) { header("Content-Type: text/javascript;charset=utf-8"); $iTemplateFlags = Template::ESCAPE | Template::NO_HTML_ESCAPE; } else { header("Content-Type: text/html;charset=utf-8"); } } $oCache = new Cache('template_resource-' . $sFileName . '-' . Session::language(), 'resource'); $oTemplate = null; if ($oCache->entryExists() && !$oCache->isOutdated($oResourceFinder)) { $oCache->sendCacheControlHeaders(); $oTemplate = $oCache->getContentsAsVariable(); } else { $oTemplate = new Template(TemplateIdentifier::constructIdentifier('contents'), null, true, false, null, $sFileName); $aResources = $oResourceFinder->find(); if (!$aResources) { $aResources = array(); } if ($aResources instanceof FileResource) { $aResources = array($aResources); } foreach ($aResources as $oResource) { $oSubTemplate = new Template($oResource, null, false, false, null, null, $iTemplateFlags); $oTemplate->replaceIdentifierMultiple('contents', $oSubTemplate, null, Template::LEAVE_IDENTIFIERS); } $oCache->setContents($oTemplate); $oCache->sendCacheControlHeaders(); } print $oTemplate->render(); }
<?php define("XHTML_TEMPLATE_LANGUAGE_IDENTIFIER", TemplateIdentifier::constructIdentifier("language")); define("XHTML_TEMPLATE_CHARSET_IDENTIFIER", TemplateIdentifier::constructIdentifier("charset")); define("DOCTYPE_HTML_4_STRICT", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html lang=\"" . XHTML_TEMPLATE_LANGUAGE_IDENTIFIER . "\"{{identifierContext=start;name=className}} class=\"{{className}}\"{{identifierContext=end;name=className}}>\n"); define("DOCTYPE_HTML_4_TRANSITIONAL", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html lang=\"" . XHTML_TEMPLATE_LANGUAGE_IDENTIFIER . "\"{{identifierContext=start;name=className}} class=\"{{className}}\"{{identifierContext=end;name=className}}>\n"); define("DOCTYPE_HTML_5", "<!DOCTYPE HTML>\n<html lang=\"" . XHTML_TEMPLATE_LANGUAGE_IDENTIFIER . "\"{{identifierContext=start;name=className}} class=\"{{className}}\"{{identifierContext=end;name=className}}>\n"); define("DOCTYPE_XHTML_STRICT", "<?xml version=\"1.0\" encoding=\"" . XHTML_TEMPLATE_CHARSET_IDENTIFIER . "\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" . XHTML_TEMPLATE_LANGUAGE_IDENTIFIER . "\"{{identifierContext=start;name=className}} class=\"{{className}}\"{{identifierContext=end;name=className}}>\n"); define("DOCTYPE_XHTML_TRANSITIONAL", "<?xml version=\"1.0\" encoding=\"" . XHTML_TEMPLATE_CHARSET_IDENTIFIER . "\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" . XHTML_TEMPLATE_LANGUAGE_IDENTIFIER . "\"{{identifierContext=start;name=className}} class=\"{{className}}\"{{identifierContext=end;name=className}}>\n"); define("DOCTYPE_XHTML_5", "<?xml version=\"1.0\" encoding=\"" . XHTML_TEMPLATE_CHARSET_IDENTIFIER . "\" ?>\n<!DOCTYPE HTML>\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" . XHTML_TEMPLATE_LANGUAGE_IDENTIFIER . "\"{{identifierContext=start;name=className}} class=\"{{className}}\"{{identifierContext=end;name=className}}>\n"); class XHTMLOutput { const SETTING_STRICT = 'strict'; const SETTING_TRANSITIONAL = 'transitional'; const SETTING_HTML_4_STRICT = 'html4_strict'; const SETTING_HTML_4_TRANSITIONAL = 'html4_transitional'; const SETTING_HTML_5 = 'html5'; const SETTING_XHTML_5 = 'xhtml5'; const SETTING_NONE = 'none'; private $sCharset; private $sContentType; private $sLanguage; private $sSetting; private $bPrintDoctype; private $sClassName; public function __construct($sSetting = null, $bPrintDoctype = true, $sClassName = null, $sLanguage = null) { $this->sContentType = "text/html"; if ($sLanguage === null) { $sLanguage = Session::language(); }
public static function listItemsFromArray($aArray) { if (count($aArray) === 0) { return ""; } $oTemplate = new Template(TemplateIdentifier::constructIdentifier('result'), null, true); foreach ($aArray as $sListItem) { $oOptionTemplate = new Template('<li>' . TemplateIdentifier::constructIdentifier('value') . '</li>', null, true); $oOptionTemplate->replaceIdentifier("value", $sListItem); $oTemplate->replaceIdentifierMultiple("result", $oOptionTemplate); } return $oTemplate; }
/** * Returns a Template containing all of the necessary HTML code for the browser to load the included resources. * @param $bPrintNewlines Whether to put each include on a new line. Turn this off for “location_only”-type includes. * @param $bConsolidate Whether to consolidate CSS and JS includes into a single tag which will point to a new location which will serve all the scripts of one type concatenated. * Valid values — true: Consolidate all css/js resources, false: Don’t consolidate, 'internal': Only consolidate internal scripts, but not the ones loaded from external servers, null: Use the default value from the general/consolidate_resources configuration seting from resource_includer.yml. * Note that all concatenated scripts will have to be in the same charset, namely the one defined in the encoding/browser configuration setting. * Also note that a value of "internal" for $bConsolidate will only have an effect on js libraries if they’re not being locally cached (use_local_library_cache is false) */ public function getIncludes($bPrintNewlines = true, $bConsolidate = null) { $bConsolidateSetting = Settings::getSetting('general', 'consolidate_resources', false, 'resource_includer'); if ($bConsolidate === null) { $bConsolidate = $bConsolidateSetting; } if ($bConsolidate === 'never' || $bConsolidateSetting === 'never') { //In the “never” case, $bConsolidateSetting overrides a local $bConsolidate $bConsolidate = false; } if ($bConsolidate && !ini_get('allow_url_fopen')) { // Never consolidate external files if fopen_wrappers are disabled $bConsolidate = 'internal'; } if ($bConsolidate) { $this->replaceContentsWithConsolidated($bConsolidate === 'internal'); } $this->cleanupReverseDependencies(); $iTemplateFlags = 0; if (!$bPrintNewlines) { $iTemplateFlags = Template::NO_NEWLINE; } $oTemplate = new Template(TemplateIdentifier::constructIdentifier('includes'), null, true, false, null, null, $iTemplateFlags); $aTemplateMasters = array(); foreach ($this->aIncludedResources as $iPriority => $aIncludedResourcesOfType) { if (count($aIncludedResourcesOfType) === 0) { continue; } foreach ($aIncludedResourcesOfType as $aResourceInfo) { if (!isset($aTemplateMasters[$aResourceInfo['template']])) { $aTemplateMasters[$aResourceInfo['template']] = new Template($aResourceInfo['template'], array(DIRNAME_TEMPLATES, 'resource_includers')); } $oIncludeTemplate = clone $aTemplateMasters[$aResourceInfo['template']]; foreach ($aResourceInfo as $sResourceInfoKey => $sResourceInfoValue) { $oIncludeTemplate->replaceIdentifier($sResourceInfoKey, $sResourceInfoValue); } if (isset($aResourceInfo['ie_condition'])) { $oIeConditionalTemplate = $this->ieConditionalTemplate(); $oIeConditionalTemplate->replaceIdentifier('condition', $aResourceInfo['ie_condition']); $oIeConditionalTemplate->replaceIdentifier('content', $oIncludeTemplate); $oIncludeTemplate = $oIeConditionalTemplate; } $oTemplate->replaceIdentifierMultiple('includes', $oIncludeTemplate); } } return $oTemplate; }
/** * Used as a callback to calculate the value of `page_link` identifiers in the template. * @param TemplateIdentifier $oTemplateIdentifier The TemplateIdentifier whose name is “page_link” * @return Template the Template containing a link * used in fillAttributes to replace page_link identifiers * - get a page by name * - get a page by id * - get a page by identifier string * - get nearest neighbor page {@link PageQuery::findOneByName()} */ public static function replacePageLinkIdentifier($oTemplateIdentifier) { $oPage = null; $sIdentifier = $oTemplateIdentifier->getParameter('identifier'); if ($sIdentifier !== null) { $oPage = PageQuery::create()->findOneByIdentifier($sIdentifier); } else { $iId = $oTemplateIdentifier->getParameter('id'); if ($iId !== null) { $oPage = PageQuery::create()->findPk($iId); } else { $sName = $oTemplateIdentifier->getParameter('name'); if ($sName !== null) { if ($oTemplateIdentifier->hasParameter('nearest_neighbour')) { $oPage = self::$CURRENT_PAGE->getPageOfName($sName); } else { $oPage = PageQuery::create()->findOneByName($sName); } } } } if ($oPage === null) { return null; } // hack to be able to display another name than the page_name, thanks to sl if ($oTemplateIdentifier->hasParameter('href_only')) { return LinkUtil::link($oPage->getLink()); } if (self::$CURRENT_PAGE !== null && self::$CURRENT_PAGE->getId() == $oPage->getId()) { return TagWriter::quickTag('span', array('class' => "meta_navigation {$oPage->getName()}", 'title' => $oPage->getPageTitle()), $oPage->getLinkText()); } return TagWriter::quickTag('a', array('class' => "meta_navigation {$oPage->getName()}", 'href' => LinkUtil::link($oPage->getLink()), 'title' => $oPage->getPageTitle()), $oPage->getLinkText()); }
private function renderJournalEntries(JournalEntryQuery $oQuery = null, Template $oEntryTemplatePrototype, Template $oFullTemplate, Template $oCommentTemplate = null, $sContainer = null, $sIdentifier = null) { if ($oQuery === null) { $oQuery = FrontendJournalEntryQuery::create(); } if ($sIdentifier === null) { $sIdentifier = 'container'; if ($sContainer === null) { $sContainer = $this->sContainer; } } if (null !== $this->aFilteredJournalIds) { $oQuery->filterByJournalId($this->aFilteredJournalIds); } else { if ($this->aJournalIds) { $oQuery->filterByJournalId($this->aJournalIds); } } if (!empty($this->aFilteredTags)) { $oQuery->filterByTagName($this->aFilteredTags); } $this->addPagination($oQuery, $oFullTemplate); $aEntries = $oQuery->orderByPublishAt(Criteria::DESC)->find(); if (count($aEntries) === 0) { $oFullTemplate->replaceIdentifier('no_result_info', $this->renderNoResult()); return; } // create journal entry button in preview if ($this->bIsPreview) { $oInnerTemplate = new Template(TemplateIdentifier::constructIdentifier($sIdentifier, $sContainer), null, true); $oAddJournals = parent::constructTemplate('preview_add_entry_button'); $oAddJournals->replaceIdentifier('item_template_name', $oEntryTemplatePrototype->getTemplateName()); $aJournalsAvailable = JournalQuery::create()->filterById($this->aFilteredJournalIds)->find(); $bSingleJournals = count($aJournalsAvailable) === 1; foreach ($aJournalsAvailable as $oJournal) { if (!$bSingleJournals) { $oAddJournals->replaceIdentifierMultiple('journal', array('id' => $oJournal->getId(), 'name' => $oJournal->getName())); } else { $oAddJournals->replaceIdentifier('journal_id_data', " data-journal_id={$oJournal->getId()}"); continue; } } $oInnerTemplate->replaceIdentifierMultiple($sIdentifier, $oAddJournals, $sContainer); $oFullTemplate->replaceIdentifier($sIdentifier, TagWriter::quickTag('div', array('class' => 'journal_list-container'), $oInnerTemplate), $sContainer, Template::LEAVE_IDENTIFIERS); } foreach ($aEntries as $oEntry) { $oFullTemplate->replaceIdentifierMultiple($sIdentifier, $this->renderEntry($oEntry, clone $oEntryTemplatePrototype), $sContainer); } }
public function textTagParseCallback($oHtmlTag, $sParsedChildren) { if ($oHtmlTag->getName() === 'text') { return $sParsedChildren; } if ($oHtmlTag->getName() === 'img') { if (preg_match("%display_document/(\\d+)%", $oHtmlTag->getParameter('src'), $aMatches)) { $aParameters = $oHtmlTag->getParameters(); $this->addTrackReference($aMatches[1], "Document"); return TemplateIdentifier::constructIdentifier('image', $aMatches[1], $aParameters); } } if ($oHtmlTag->getName() === 'a') { if ($sParsedChildren === '') { return ''; } $bHasMatched = preg_match("%/" . preg_quote(Manager::getPrefixForManager('FileManager'), "%") . "/([^/]+)/(\\d+)((\\D.+)?)\$%", $oHtmlTag->getParameter('href'), $aMatches) === 1; if ($bHasMatched) { $sFileMethod = $aMatches[1]; $iId = $aMatches[2]; $sAdditional = $aMatches[3]; $sIdentifier = 'file_link'; $sModel = 'Document'; if ($sFileMethod === 'external_link_proxy') { $sIdentifier = 'external_link'; $sModel = 'Link'; } else { if ($sFileMethod === 'internal_link_proxy') { $sIdentifier = 'internal_link'; $sModel = 'Page'; } } $this->addTrackReference($iId, $sModel); return TemplateIdentifier::constructIdentifier($sIdentifier, "{$iId}{$sAdditional}", array_merge($oHtmlTag->getParameters(), array('link_text' => $sParsedChildren))); } else { if (strpos($oHtmlTag->getParameter('href'), "mailto:") === 0) { return TemplateIdentifier::constructIdentifier("mailto_link", substr($oHtmlTag->getParameter('href'), strlen("mailto:")), array("link_text" => $sParsedChildren)); } } } $oTagWriter = new TagWriter($oHtmlTag->getName(), $oHtmlTag->getParameters(), $sParsedChildren); $oTagTemplate = $oTagWriter->parse(true); $oTagTemplate->bKillIdentifiersBeforeRender = false; return $oTagTemplate->render(); }
public function adminGetContainers() { $oTemplate = $this->oPage->getTemplate(); foreach ($oTemplate->identifiersMatching('container', Template::$ANY_VALUE) as $oIdentifier) { $oInheritedFrom = null; $sContainerName = $oIdentifier->getValue(); if (BooleanParser::booleanForString($oIdentifier->getParameter('inherit'))) { $oInheritedFrom = $this->oPage; $iInheritedObjectCount = 0; while ($iInheritedObjectCount === 0 && ($oInheritedFrom = $oInheritedFrom->getParent()) !== null) { $iInheritedObjectCount = $oInheritedFrom->countObjectsForContainer($sContainerName); } } $sInheritedFrom = $oInheritedFrom ? $oInheritedFrom->getName() : ''; $aTagParams = array('class' => 'template-container template-container-' . $sContainerName, 'data-container-name' => $sContainerName, 'data-container-string' => TranslationPeer::getString('container_name.' . $sContainerName, null, $sContainerName), 'data-inherited-from' => $sInheritedFrom); $oContainerTag = TagWriter::quickTag('ol', $aTagParams); $mInnerTemplate = new Template(TemplateIdentifier::constructIdentifier('content'), null, true); //Replace container info //…name $mInnerTemplate->replaceIdentifierMultiple('content', TagWriter::quickTag('div', array('class' => 'template-container-description'), TranslationPeer::getString('wns.page.template_container', null, null, array('container' => TranslationPeer::getString('template_container.' . $sContainerName, null, $sContainerName)), true))); //…additional info $mInnerTemplate->replaceIdentifierMultiple('content', TagWriter::quickTag('div', array('class' => 'template-container-info'))); //…tag $mInnerTemplate->replaceIdentifierMultiple('content', $oContainerTag); //Replace actual container $oTemplate->replaceIdentifier($oIdentifier, $mInnerTemplate); } $bUseParsedCss = Settings::getSetting('admin', 'use_parsed_css_in_config', true); $oStyle = null; if ($bUseParsedCss) { $sTemplateName = $this->oPage->getTemplateNameUsed() . Template::$SUFFIX; $sCacheKey = 'parsed-css-' . $sTemplateName; $oCssCache = new Cache($sCacheKey, DIRNAME_PRELOAD); $sCssContents = ""; if (!$oCssCache->entryExists() || $oCssCache->isOutdated(ResourceFinder::create(array(DIRNAME_TEMPLATES, $sTemplateName)))) { $oIncluder = new ResourceIncluder(); foreach ($oTemplate->identifiersMatching('addResourceInclude', Template::$ANY_VALUE) as $oIdentifier) { $oIncluder->addResourceFromTemplateIdentifier($oIdentifier); } foreach ($oIncluder->getAllIncludedResources() as $sIdentifier => $aResource) { if ($aResource['resource_type'] === ResourceIncluder::RESOURCE_TYPE_CSS && !isset($aResource['ie_condition']) && !isset($aResource['frontend_specific'])) { if (isset($aResource['media'])) { $sCssContents .= "@media {$aResource['media']} {"; } if (isset($aResource['file_resource'])) { $sCssContents .= file_get_contents($aResource['file_resource']->getFullPath()); } else { // Absolute link, requires fopen wrappers $sCssContents .= file_get_contents($aResource['location']); } if (isset($aResource['media'])) { $sCssContents .= "}"; } } } $oParser = new Sabberworm\CSS\Parser($sCssContents, Sabberworm\CSS\Settings::create()->withDefaultCharset(Settings::getSetting("encoding", "browser", "utf-8"))); $oCss = $oParser->parse(); $this->cleanupCSS($oCss); $sCssContents = Template::htmlEncode($oCss->render(Sabberworm\CSS\OutputFormat::createCompact())); $oCssCache->setContents($sCssContents); } else { $sCssContents = $oCssCache->getContentsAsString(); } $oStyle = new HtmlTag('style'); $oStyle->addParameters(array('scoped' => 'scoped')); $oStyle->appendChild($sCssContents); } $sTemplate = $oTemplate->render(); $sTemplate = substr($sTemplate, strpos($sTemplate, '<body') + 5); $sTemplate = substr($sTemplate, strpos($sTemplate, '>') + 1); $sTemplate = substr($sTemplate, 0, strpos($sTemplate, '</body')); $oParser = new TagParser("<body>{$sTemplate}</body>"); $oTag = $oParser->getTag(); $this->cleanupContainerStructure($oTag); if ($bUseParsedCss) { $oTag->appendChild($oStyle); } $sResult = $oTag->__toString(); $sResult = substr($sResult, strpos($sResult, '<body>') + 6); $sResult = substr($sResult, 0, strrpos($sResult, '</body>')); return array('html' => $sResult, 'css_parsed' => $bUseParsedCss); }
public function renderFrontend() { $aOptions = @unserialize($this->getData()); if (!$aOptions) { $aOptions = array(); } $oTemplate = new Template(TemplateIdentifier::constructIdentifier("content"), null, true); foreach ($aOptions as $aDocumentInfo) { $oDocument = DocumentQuery::create()->findPk($aDocumentInfo['document_id']); $sMimeType = @$aDocumentInfo['mimetype']; $sSrc = null; if ($oDocument !== null) { $aParameters = array(); if (@$aDocumentInfo['max_width']) { $aParameters['max_width'] = $aDocumentInfo['max_width']; } if (@$aDocumentInfo['max_height']) { $aParameters['max_height'] = $aDocumentInfo['max_width']; } if (@$aDocumentInfo['force_refresh']) { $aParameters['refresh'] = time(); } $sSrc = $oDocument->getDisplayUrl($aParameters); if (!$sMimeType) { $sMimeType = $oDocument->getMimetype(); } } else { if (@$aDocumentInfo['url']) { $sSrcToCheck = $aDocumentInfo['url']; if (($iQSPos = strrpos($sSrcToCheck, '?')) !== false) { $sSrcToCheck = substr($sSrcToCheck, 0, $iQSPos); } if (file_exists(MAIN_DIR . '/' . $sSrcToCheck)) { $aDocumentInfo['url'] = MAIN_DIR_FE . $aDocumentInfo['url']; } $sSrc = @$aDocumentInfo['url']; } else { continue; } } $oSubTemplate = null; try { try { $oSubTemplate = $this->constructTemplate($sMimeType); } catch (Exception $e) { $sMimeTypePrefix = explode('/', $sMimeType); $sMimeTypePrefix = $sMimeTypePrefix[0]; $oSubTemplate = $this->constructTemplate("{$sMimeTypePrefix}/generic"); } } catch (Exception $e) { $oSubTemplate = $this->constructTemplate("generic"); } if (@$aDocumentInfo['width']) { $oSubTemplate->replaceIdentifier('width', $aDocumentInfo['width']); } if (@$aDocumentInfo['height']) { $oSubTemplate->replaceIdentifier('height', $aDocumentInfo['height']); } $oSubTemplate->replaceIdentifier('src', $sSrc); $oSubTemplate->replaceIdentifier('mimeType', $sMimeType); $oTemplate->replaceIdentifier("content", $oSubTemplate, null, Template::LEAVE_IDENTIFIERS); } return $oTemplate; }
/** * @param main template * description: * - @see config.yml section language_chooser * - use parameter replaced in method * @return Template The rendered language chooser */ public static function getLanguageChooser($oMainTemplate) { $oTemplate = new Template(TemplateIdentifier::constructIdentifier('languages'), null, true); $oLanguageTemplate = new Template(Settings::getSetting("language_chooser", 'template', 'language'), array(DIRNAME_TEMPLATES, DIRNAME_NAVIGATION)); $sLinkSeparator = Settings::getSetting("language_chooser", 'link_separator', ' | '); $oLanguageActiveTemplate = null; $bShowActiveLanguage = Settings::getSetting("language_chooser", 'show_active_language', false); $bIsPreview = Manager::getCurrentManager() instanceof PreviewManager; if ($bShowActiveLanguage) { if (Settings::getSetting("language_chooser", 'template_active', false) !== false) { $oLanguageActiveTemplate = new Template(Settings::getSetting("language_chooser", 'template_active', 'language_active'), array(DIRNAME_TEMPLATES, DIRNAME_NAVIGATION)); } else { $oLanguageActiveTemplate = clone $oLanguageTemplate; } } // Find request variables $aParameters = array_diff_assoc($_REQUEST, $_COOKIE); unset($aParameters['path']); unset($aParameters['content_language']); // Check whether manager needs language to be included $bCurrentPathIncludesLanguage = call_user_func(array(Manager::getManagerClassNormalized(null), 'shouldIncludeLanguageInLink')); $aRequestPath = explode("/", Manager::getRequestedPath()); $aLanguages = LanguageQuery::create()->filterByIsActive(true)->exclude($bShowActiveLanguage ? false : ($bIsPreview ? 'edit' : 'current'))->orderBySort()->find(); foreach ($aLanguages as $i => $oLanguage) { $oLangTemplate = null; $oPageString = null; if ($oLanguage->getId() === Session::language()) { $oLangTemplate = $oLanguageActiveTemplate; $oLangTemplate->replaceIdentifier('class', 'active'); } else { $oPageString = PageStringQuery::create()->filterByPage(FrontendManager::$CURRENT_PAGE)->filterByLanguageId($oLanguage->getId())->filterByIsInactive(false)->findOne(); if ($oPageString === null) { continue; } $oLangTemplate = clone $oLanguageTemplate; } // If language is included, replace it by language id and set include_language param to false if ($bCurrentPathIncludesLanguage) { $aRequestPath[0] = $oLanguage->getPathPrefix(); $sLink = LinkUtil::link($aRequestPath, null, $aParameters, false); } else { $sLink = LinkUtil::link($aRequestPath, null, array_merge($aParameters, array('content_language' => $oLanguage->getId()))); } $oLangTemplate->replaceIdentifier('link', $sLink); // Add alternate language links if ($oPageString) { ResourceIncluder::metaIncluder()->addCustomResource(array('template' => 'link', 'rel' => 'alternate', 'lang' => $oLanguage->getId(), 'location' => $sLink, 'title' => $oPageString->getPageTitle())); } $oLangTemplate->replaceIdentifier('id', $oLanguage->getId()); $oLangTemplate->replaceIdentifier('name', $oLanguage->getLanguageName($oLanguage->getId())); $oLangTemplate->replaceIdentifier('name_in_current_lang', $oLanguage->getLanguageName()); $oTemplate->replaceIdentifierMultiple('languages', $oLangTemplate, null, Template::NO_NEWLINE); if ($i + 1 < count($aLanguages)) { $oTemplate->replaceIdentifierMultiple('languages', $sLinkSeparator, null, Template::NO_HTML_ESCAPE | Template::NO_NEWLINE); } } return $oTemplate; }