/** * Generate the widget and return it as string * * @return string The widget markup */ public function generate() { $this->text = \StringUtil::toHtml5($this->text); // Add the static files URL to images if (TL_FILES_URL != '') { $path = \Config::get('uploadPath') . '/'; $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text); } return \StringUtil::encodeEmail($this->text); }
/** * Generate the content element */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; if (substr($this->url, 0, 7) == 'mailto:') { $this->url = \StringUtil::encodeEmail($this->url); } else { $this->url = ampersand($this->url); } $embed = explode('%s', $this->embed); if ($this->linkTitle == '') { $this->linkTitle = $this->url; } // Use an image instead of the title if ($this->useImage && $this->singleSRC != '') { $objModel = \FilesModel::findByUuid($this->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($this->singleSRC)) { $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { /** @var \FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate('ce_hyperlink_image'); $this->Template = $objTemplate; $this->Template->setData($this->arrData); $this->singleSRC = $objModel->path; $this->addImageToTemplate($this->Template, $this->arrData); $this->Template->linkTitle = specialchars($this->linkTitle); } } if (strncmp($this->rel, 'lightbox', 8) !== 0 || $objPage->outputFormat == 'xhtml') { $this->Template->attribute = ' rel="' . $this->rel . '"'; } else { $this->Template->attribute = ' data-lightbox="' . substr($this->rel, 9, -1) . '"'; } $this->Template->rel = $this->rel; // Backwards compatibility $this->Template->href = $this->url; $this->Template->embed_pre = $embed[0]; $this->Template->embed_post = $embed[1]; $this->Template->link = $this->linkTitle; $this->Template->linkTitle = specialchars($this->titleText ?: $this->linkTitle); $this->Template->target = ''; // Override the link target if ($this->target) { $this->Template->target = $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"'; } // Unset the title attributes in the back end (see #6258) if (TL_MODE == 'BE') { $this->Template->title = ''; $this->Template->linkTitle = ''; } }
/** * Generate the content element */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $this->text = \StringUtil::toXhtml($this->text); } else { $this->text = \StringUtil::toHtml5($this->text); } // Add the static files URL to images if (TL_FILES_URL != '') { $path = \Config::get('uploadPath') . '/'; $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text); } $this->Template->text = \StringUtil::encodeEmail($this->text); $this->Template->addImage = false; // Add an image if ($this->addImage && $this->singleSRC != '') { $objModel = \FilesModel::findByUuid($this->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($this->singleSRC)) { $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { $this->singleSRC = $objModel->path; $this->addImageToTemplate($this->Template, $this->arrData); } } }
/** * Generate the content element */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; // Clean RTE output if ($objPage->outputFormat == 'xhtml') { $this->text = \StringUtil::toXhtml($this->text); } else { $this->text = \StringUtil::toHtml5($this->text); } $this->Template->text = \StringUtil::encodeEmail($this->text); $this->Template->addImage = false; // Add an image if ($this->addImage && $this->singleSRC != '') { $objModel = \FilesModel::findByUuid($this->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($this->singleSRC)) { $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { $this->singleSRC = $objModel->path; $this->addImageToTemplate($this->Template, $this->arrData); } } $classes = deserialize($this->mooClasses); $this->Template->toggler = $classes[0] ?: 'toggler'; $this->Template->accordion = $classes[1] ?: 'accordion'; $this->Template->headlineStyle = $this->mooStyle; $this->Template->headline = $this->mooHeadline; }
/** * Generate the module */ protected function compile() { global $objPage; $this->Template->content = ''; $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; if (TL_MODE == 'FE' && BE_USER_LOGGED_IN) { $objNewsletter = \NewsletterModel::findByIdOrAlias(\Input::get('items')); } else { $objNewsletter = \NewsletterModel::findSentByParentAndIdOrAlias(\Input::get('items'), $this->nl_channels); } if ($objNewsletter === null) { // Do not index or cache the page $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); $this->Template->content = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('items')) . '</p>'; return; } // Overwrite the page title (see #2853 and #4955) if ($objNewsletter->subject != '') { $objPage->pageTitle = strip_tags(strip_insert_tags($objNewsletter->subject)); } // Add enclosure if ($objNewsletter->addFile) { $this->addEnclosuresToTemplate($this->Template, $objNewsletter->row(), 'files'); } if (!$objNewsletter->sendText) { $nl2br = $objPage->outputFormat == 'xhtml' ? 'nl2br_xhtml' : 'nl2br_html5'; $strContent = ''; $objContentElements = \ContentModel::findPublishedByPidAndTable($objNewsletter->id, 'tl_newsletter'); if ($objContentElements !== null) { if (!defined('NEWSLETTER_CONTENT_PREVIEW')) { define('NEWSLETTER_CONTENT_PREVIEW', true); } foreach ($objContentElements as $objContentElement) { $strContent .= $this->getContentElement($objContentElement->id); } } // Parse simple tokens and insert tags $strContent = $this->replaceInsertTags($strContent); $strContent = \StringUtil::parseSimpleTokens($strContent, array()); // Encode e-mail addresses $strContent = \StringUtil::encodeEmail($strContent); $this->Template->content = $strContent; } else { $strContent = str_ireplace(' align="center"', '', $objNewsletter->content); } // Convert relative URLs $strContent = $this->convertRelativeUrls($strContent); // Parse simple tokens and insert tags $strContent = $this->replaceInsertTags($strContent); $strContent = \StringUtil::parseSimpleTokens($strContent, array()); // Encode e-mail addresses $strContent = \StringUtil::encodeEmail($strContent); $this->Template->content = $strContent; $this->Template->subject = $objNewsletter->subject; }
/** * Generate the widget and return it as string * * @return string The widget markup */ public function generate() { /** @var \PageModel $objPage */ global $objPage; // Clean RTE output if ($objPage->outputFormat == 'xhtml') { $this->text = \StringUtil::toXhtml($this->text); } else { $this->text = \StringUtil::toHtml5($this->text); } // Add the static files URL to images if (TL_FILES_URL != '') { $path = \Config::get('uploadPath') . '/'; $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text); } return \StringUtil::encodeEmail($this->text); }
protected function generateFields($objItem) { $arrItem = parent::generateFields($objItem); global $objPage; $arrItem['fields']['newsHeadline'] = $objItem->headline; $arrItem['fields']['subHeadline'] = $objItem->subheadline; $arrItem['fields']['hasSubHeadline'] = $objItem->subheadline ? true : false; $arrItem['fields']['linkHeadline'] = ModuleNews::generateLink($this, $objItem->headline, $objItem, false); $arrItem['fields']['more'] = ModuleNews::generateLink($this, $GLOBALS['TL_LANG']['MSC']['more'], $objItem, false, true); $arrItem['fields']['link'] = ModuleNews::generateNewsUrl($this, $objItem, false); $arrItem['fields']['text'] = ''; // Clean the RTE output if ($objItem->teaser != '') { if ($objPage->outputFormat == 'xhtml') { $arrItem['fields']['teaser'] = \StringUtil::toXhtml($objItem->teaser); } else { $arrItem['fields']['teaser'] = \StringUtil::toHtml5($objItem->teaser); } $arrItem['fields']['teaser'] = \StringUtil::encodeEmail($arrItem['fields']['teaser']); } // Display the "read more" button for external/article links if ($objItem->source != 'default') { $arrItem['fields']['text'] = true; } else { $objElement = \ContentModel::findPublishedByPidAndTable($objItem->id, 'tl_news'); if ($objElement !== null) { while ($objElement->next()) { $arrItem['fields']['text'] .= $this->getContentElement($objElement->current()); } } } $arrMeta = ModuleNews::getMetaFields($this, $objItem); // Add the meta information $arrItem['fields']['date'] = $arrMeta['date']; $arrItem['fields']['hasMetaFields'] = !empty($arrMeta); $arrItem['fields']['numberOfComments'] = $arrMeta['ccount']; $arrItem['fields']['commentCount'] = $arrMeta['comments']; $arrItem['fields']['timestamp'] = $objItem->date; $arrItem['fields']['author'] = $arrMeta['author']; $arrItem['fields']['datetime'] = date('Y-m-d\\TH:i:sP', $objItem->date); $arrItem['fields']['addImage'] = false; // Add an image $this->addImage($objItem, 'singleSRC', $arrItem); // enclosures are added in runBeforeTemplateParsing return $arrItem; }
/** * Generate the content element */ protected function compile() { if (substr($this->url, 0, 7) == 'mailto:') { $this->url = \StringUtil::encodeEmail($this->url); } else { $this->url = ampersand($this->url); } $embed = explode('%s', $this->embed); if ($this->linkTitle == '') { $this->linkTitle = $this->url; } // Use an image instead of the title if ($this->useImage && $this->singleSRC != '') { $objModel = \FilesModel::findByUuid($this->singleSRC); if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) { $this->singleSRC = $objModel->path; $this->addImageToTemplate($this->Template, $this->arrData); $this->Template->useImage = true; $this->Template->linkTitle = specialchars($this->linkTitle); } } if (strncmp($this->rel, 'lightbox', 8) !== 0) { $this->Template->attribute = ' rel="' . $this->rel . '"'; } else { $this->Template->attribute = ' data-lightbox="' . substr($this->rel, 9, -1) . '"'; } // Deprecated since Contao 4.0, to be removed in Contao 5.0 $this->Template->rel = $this->rel; $this->Template->href = $this->url; $this->Template->embed_pre = $embed[0]; $this->Template->embed_post = $embed[1]; $this->Template->link = $this->linkTitle; $this->Template->linkTitle = specialchars($this->titleText ?: $this->linkTitle); $this->Template->target = ''; // Override the link target if ($this->target) { $this->Template->target = ' target="_blank"'; } // Unset the title attributes in the back end (see #6258) if (TL_MODE == 'BE') { $this->Template->title = ''; $this->Template->linkTitle = ''; } }
/** * Generate the content element */ protected function compile() { $this->text = \StringUtil::toHtml5($this->text); // Add the static files URL to images if (TL_FILES_URL != '') { $path = \Config::get('uploadPath') . '/'; $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text); } $this->Template->text = \StringUtil::encodeEmail($this->text); $this->Template->addImage = false; // Add an image if ($this->addImage && $this->singleSRC != '') { $objModel = \FilesModel::findByUuid($this->singleSRC); if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) { $this->singleSRC = $objModel->path; $this->addImageToTemplate($this->Template, $this->arrData); } } }
/** * Generate the content element */ protected function compile() { // Clean the RTE output $this->text = \StringUtil::toHtml5($this->text); $this->Template->text = \StringUtil::encodeEmail($this->text); $this->Template->addImage = false; // Add an image if ($this->addImage && $this->singleSRC != '') { $objModel = \FilesModel::findByUuid($this->singleSRC); if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) { $this->singleSRC = $objModel->path; $this->addImageToTemplate($this->Template, $this->arrData); } } $classes = deserialize($this->mooClasses); $this->Template->toggler = $classes[0] ?: 'toggler'; $this->Template->accordion = $classes[1] ?: 'accordion'; $this->Template->headlineStyle = $this->mooStyle; $this->Template->headline = $this->mooHeadline; }
public function getEmailElement($strTag) { $params = preg_split('/::/', $strTag); if (is_array($params) && !empty($params)) { // general parameters $strInsertTag = $params[0]; $strEmail = \StringUtil::encodeEmail($params[1]); if ($strEmail === null || $strEmail === '') { return false; } switch ($strInsertTag) { case 'email_label': // label parameters $strLabel = $params[2] !== null && $params[2] !== "" ? $params[2] : preg_replace('/\\?.*$/', '', $strEmail); $strClasses = $params[3] !== null && $params[3] !== '' ? $params[3] . ' ' : ''; $strId = $params[4] !== null && $params[4] !== '' ? 'id="' . $params[4] . '" ' : ''; $strEmailLink = '<a ' . $strId . 'href="mailto:' . $strEmail . '" class="' . $strClasses . 'email">' . $strLabel . '</a>'; return $strEmailLink; default: return false; } } return false; }
/** * Replace bbcode and return the HTML string * * Supports the following tags: * * * [b][/b] bold * * [i][/i] italic * * [u][/u] underline * * [img][/img] * * [code][/code] * * [color=#ff0000][/color] * * [quote][/quote] * * [quote=tim][/quote] * * [url][/url] * * [url=http://][/url] * * [email][/email] * * [email=name@example.com][/email] * * @param string $strComment * * @return string */ public function parseBbCode($strComment) { $arrSearch = array('@\\[b\\](.*)\\[/b\\]@Uis', '@\\[i\\](.*)\\[/i\\]@Uis', '@\\[u\\](.*)\\[/u\\]@Uis', '@\\s*\\[code\\](.*)\\[/code\\]\\s*@Uis', '@\\[color=([^\\]" ]+)\\](.*)\\[/color\\]@Uis', '@\\s*\\[quote\\](.*)\\[/quote\\]\\s*@Uis', '@\\s*\\[quote=([^\\]]+)\\](.*)\\[/quote\\]\\s*@Uis', '@\\[img\\]\\s*([^\\[" ]+\\.(jpe?g|png|gif|bmp|tiff?|ico))\\s*\\[/img\\]@i', '@\\[url\\]\\s*([^\\[" ]+)\\s*\\[/url\\]@i', '@\\[url=([^\\]" ]+)\\](.*)\\[/url\\]@Uis', '@\\[email\\]\\s*([^\\[" ]+)\\s*\\[/email\\]@i', '@\\[email=([^\\]" ]+)\\](.*)\\[/email\\]@Uis', '@href="(([a-z0-9]+\\.)*[a-z0-9]+\\.([a-z]{2}|asia|biz|com|info|name|net|org|tel)(/|"))@i'); $arrReplace = array('<strong>$1</strong>', '<em>$1</em>', '<span style="text-decoration:underline">$1</span>', "\n\n" . '<div class="code"><p>' . $GLOBALS['TL_LANG']['MSC']['com_code'] . '</p><pre>$1</pre></div>' . "\n\n", '<span style="color:$1">$2</span>', "\n\n" . '<div class="quote">$1</div>' . "\n\n", "\n\n" . '<div class="quote"><p>' . sprintf($GLOBALS['TL_LANG']['MSC']['com_quote'], '$1') . '</p>$2</div>' . "\n\n", '<img src="$1" alt="" />', '<a href="$1">$1</a>', '<a href="$1">$2</a>', '<a href="mailto:$1">$1</a>', '<a href="mailto:$1">$2</a>', 'href="http://$1'); $strComment = preg_replace($arrSearch, $arrReplace, $strComment); // Encode e-mail addresses if (strpos($strComment, 'mailto:') !== false) { $strComment = \StringUtil::encodeEmail($strComment); } return $strComment; }
/** * Recursively compile the navigation menu and return it as HTML string * * @param integer $pid * @param integer $level * @param string $host * @param string $language * * @return string */ protected function renderNavigation($pid, $level = 1, $host = null, $language = null) { // Get all active subpages $objSubpages = \PageModel::findPublishedSubpagesWithoutGuestsByPid($pid, $this->showHidden, $this instanceof \ModuleSitemap); if ($objSubpages === null) { return ''; } $items = array(); $groups = array(); // Get all groups of the current front end user if (FE_USER_LOGGED_IN) { $this->import('FrontendUser', 'User'); $groups = $this->User->groups; } // Layout template fallback if ($this->navigationTpl == '') { $this->navigationTpl = 'nav_default'; } /** @var \FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->navigationTpl); $objTemplate->pid = $pid; $objTemplate->type = get_class($this); $objTemplate->cssID = $this->cssID; // see #4897 $objTemplate->level = 'level_' . $level++; /** @var \PageModel $objPage */ global $objPage; // Browse subpages foreach ($objSubpages as $objSubpage) { // Skip hidden sitemap pages if ($this instanceof \ModuleSitemap && $objSubpage->sitemap == 'map_never') { continue; } $subitems = ''; $_groups = deserialize($objSubpage->groups); // Override the domain (see #3765) if ($host !== null) { $objSubpage->domain = $host; } // Do not show protected pages unless a back end or front end user is logged in if (!$objSubpage->protected || BE_USER_LOGGED_IN || is_array($_groups) && count(array_intersect($_groups, $groups)) || $this->showProtected || $this instanceof \ModuleSitemap && $objSubpage->sitemap == 'map_always') { // Check whether there will be subpages if ($objSubpage->subpages > 0 && (!$this->showLevel || $this->showLevel >= $level || !$this->hardLimit && ($objPage->id == $objSubpage->id || in_array($objPage->id, $this->Database->getChildRecords($objSubpage->id, 'tl_page'))))) { $subitems = $this->renderNavigation($objSubpage->id, $level, $host, $language); } $href = null; // Get href switch ($objSubpage->type) { case 'redirect': $href = $objSubpage->url; if (strncasecmp($href, 'mailto:', 7) === 0) { $href = \StringUtil::encodeEmail($href); } break; case 'forward': if ($objSubpage->jumpTo) { /** @var \PageModel $objNext */ $objNext = $objSubpage->getRelated('jumpTo'); } else { $objNext = \PageModel::findFirstPublishedRegularByPid($objSubpage->id); } // Hide the link if the target page is invisible if ($objNext === null || !$objNext->published || $objNext->start != '' && $objNext->start > time() || $objNext->stop != '' && $objNext->stop < time()) { continue 2; } $href = $objNext->getFrontendUrl(); break; default: $href = $objSubpage->getFrontendUrl(); break; } $row = $objSubpage->row(); $trail = in_array($objSubpage->id, $objPage->trail); // Active page if (($objPage->id == $objSubpage->id || $objSubpage->type == 'forward' && $objPage->id == $objSubpage->jumpTo) && !$this instanceof \ModuleSitemap && $href == \Environment::get('request')) { // Mark active forward pages (see #4822) $strClass = ($objSubpage->type == 'forward' && $objPage->id == $objSubpage->jumpTo ? 'forward' . ($trail ? ' trail' : '') : 'active') . ($subitems != '' ? ' submenu' : '') . ($objSubpage->protected ? ' protected' : '') . ($objSubpage->cssClass != '' ? ' ' . $objSubpage->cssClass : ''); $row['isActive'] = true; $row['isTrail'] = false; } else { $strClass = ($subitems != '' ? 'submenu' : '') . ($objSubpage->protected ? ' protected' : '') . ($trail ? ' trail' : '') . ($objSubpage->cssClass != '' ? ' ' . $objSubpage->cssClass : ''); // Mark pages on the same level (see #2419) if ($objSubpage->pid == $objPage->pid) { $strClass .= ' sibling'; } $row['isActive'] = false; $row['isTrail'] = $trail; } $row['subitems'] = $subitems; $row['class'] = trim($strClass); $row['title'] = specialchars($objSubpage->title, true); $row['pageTitle'] = specialchars($objSubpage->pageTitle, true); $row['link'] = $objSubpage->title; $row['href'] = $href; $row['nofollow'] = strncmp($objSubpage->robots, 'noindex', 7) === 0; $row['target'] = ''; $row['description'] = str_replace(array("\n", "\r"), array(' ', ''), $objSubpage->description); // Override the link target if ($objSubpage->type == 'redirect' && $objSubpage->target) { $row['target'] = $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"'; } $items[] = $row; } } // Add classes first and last if (!empty($items)) { $last = count($items) - 1; $items[0]['class'] = trim($items[0]['class'] . ' first'); $items[$last]['class'] = trim($items[$last]['class'] . ' last'); } $objTemplate->items = $items; return !empty($items) ? $objTemplate->parse() : ''; }
/** * Generate a URL and return it as string * * @param NewsModel $objItem * @param boolean $blnAddArchive * * @return string */ public static function generateNewsUrl($objItem, $blnAddArchive = false) { $strCacheKey = 'id_' . $objItem->id; // Load the URL from cache if (isset(self::$arrUrlCache[$strCacheKey])) { return self::$arrUrlCache[$strCacheKey]; } // Initialize the cache self::$arrUrlCache[$strCacheKey] = null; switch ($objItem->source) { // Link to an external page case 'external': if (substr($objItem->url, 0, 7) == 'mailto:') { self::$arrUrlCache[$strCacheKey] = \StringUtil::encodeEmail($objItem->url); } else { self::$arrUrlCache[$strCacheKey] = ampersand($objItem->url); } break; // Link to an internal page // Link to an internal page case 'internal': if (($objTarget = $objItem->getRelated('jumpTo')) instanceof PageModel) { /** @var PageModel $objTarget */ self::$arrUrlCache[$strCacheKey] = ampersand($objTarget->getFrontendUrl()); } break; // Link to an article // Link to an article case 'article': if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) instanceof PageModel) { /** @var PageModel $objPid */ self::$arrUrlCache[$strCacheKey] = ampersand($objPid->getFrontendUrl('/articles/' . ($objArticle->alias ?: $objArticle->id))); } break; } // Link to the default page if (self::$arrUrlCache[$strCacheKey] === null) { $objPage = \PageModel::findByPk($objItem->getRelated('pid')->jumpTo); if (!$objPage instanceof PageModel) { self::$arrUrlCache[$strCacheKey] = ampersand(\Environment::get('request'), true); } else { self::$arrUrlCache[$strCacheKey] = ampersand($objPage->getFrontendUrl((\Config::get('useAutoItem') ? '/' : '/items/') . ($objItem->alias ?: $objItem->id))); } // Add the current archive parameter (news archive) if ($blnAddArchive && \Input::get('month') != '') { self::$arrUrlCache[$strCacheKey] .= '?month=' . \Input::get('month'); } } return self::$arrUrlCache[$strCacheKey]; }
/** * Generate the module */ protected function compile() { $objFaq = \FaqModel::findPublishedByPids($this->faq_categories); if ($objFaq === null) { $this->Template->faq = array(); return; } /** @var \PageModel $objPage */ global $objPage; $arrFaqs = array_fill_keys($this->faq_categories, array()); // Add FAQs while ($objFaq->next()) { /** @var \FaqModel $objFaq */ $objTemp = (object) $objFaq->row(); // Clean RTE output if ($objPage->outputFormat == 'xhtml') { $objTemp->answer = \StringUtil::toXhtml($objFaq->answer); } else { $objTemp->answer = \StringUtil::toHtml5($objFaq->answer); } $objTemp->answer = \StringUtil::encodeEmail($objTemp->answer); $objTemp->addImage = false; // Add an image if ($objFaq->addImage && $objFaq->singleSRC != '') { $objModel = \FilesModel::findByUuid($objFaq->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($objFaq->singleSRC)) { $objTemp->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { // Do not override the field now that we have a model registry (see #6303) $arrFaq = $objFaq->row(); $arrFaq['singleSRC'] = $objModel->path; $strLightboxId = 'lightbox[' . substr(md5('mod_faqpage_' . $objFaq->id), 0, 6) . ']'; // see #5810 $this->addImageToTemplate($objTemp, $arrFaq, null, $strLightboxId); } } $objTemp->enclosure = array(); // Add enclosure if ($objFaq->addEnclosure) { $this->addEnclosuresToTemplate($objTemp, $objFaq->row()); } /** @var \UserModel $objAuthor */ $objAuthor = $objFaq->getRelated('author'); $objTemp->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], \Date::parse($objPage->dateFormat, $objFaq->tstamp), $objAuthor->name); /** @var \FaqCategoryModel $objPid */ $objPid = $objFaq->getRelated('pid'); // Order by PID $arrFaqs[$objFaq->pid]['items'][] = $objTemp; $arrFaqs[$objFaq->pid]['headline'] = $objPid->headline; $arrFaqs[$objFaq->pid]['title'] = $objPid->title; } $arrFaqs = array_values(array_filter($arrFaqs)); $limit_i = count($arrFaqs) - 1; // Add classes first, last, even and odd for ($i = 0; $i <= $limit_i; $i++) { $class = ($i == 0 ? 'first ' : '') . ($i == $limit_i ? 'last ' : '') . ($i % 2 == 0 ? 'even' : 'odd'); $arrFaqs[$i]['class'] = trim($class); $limit_j = count($arrFaqs[$i]['items']) - 1; for ($j = 0; $j <= $limit_j; $j++) { $class = ($j == 0 ? 'first ' : '') . ($j == $limit_j ? 'last ' : '') . ($j % 2 == 0 ? 'even' : 'odd'); $arrFaqs[$i]['items'][$j]->class = trim($class); } } $this->Template->faq = $arrFaqs; $this->Template->request = \Environment::get('indexFreeRequest'); $this->Template->topLink = $GLOBALS['TL_LANG']['MSC']['backToTop']; }
/** * Generate a link and return it as string * * @param string $strLink * @param \NewsModel $objArticle * @param boolean $blnAddArchive * @param boolean $blnIsReadMore * * @return string */ protected function generateLink($strLink, $objArticle, $blnAddArchive = false, $blnIsReadMore = false) { // Internal link if ($objArticle->source != 'external') { return sprintf('<a href="%s" title="%s">%s%s</a>', $this->generateNewsUrl($objArticle, $blnAddArchive), specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->headline), true), $strLink, $blnIsReadMore ? ' <span class="invisible">' . $objArticle->headline . '</span>' : ''); } // Encode e-mail addresses if (substr($objArticle->url, 0, 7) == 'mailto:') { $strArticleUrl = \StringUtil::encodeEmail($objArticle->url); } else { $strArticleUrl = ampersand($objArticle->url); } /** @var \PageModel $objPage */ global $objPage; // External link return sprintf('<a href="%s" title="%s"%s>%s</a>', $strArticleUrl, specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['open'], $strArticleUrl)), $objArticle->target ? $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"' : '', $strLink); }
/** * Replace insert tags with their values * * @param string $strBuffer The text with the tags to be replaced * @param boolean $blnCache If false, non-cacheable tags will be replaced * * @return string The text with the replaced tags */ protected function doReplace($strBuffer, $blnCache) { /** @var PageModel $objPage */ global $objPage; // Preserve insert tags if (\Config::get('disableInsertTags')) { return \StringUtil::restoreBasicEntities($strBuffer); } $tags = preg_split('/{{([^{}]+)}}/', $strBuffer, -1, PREG_SPLIT_DELIM_CAPTURE); if (count($tags) < 2) { return \StringUtil::restoreBasicEntities($strBuffer); } $strBuffer = ''; // Create one cache per cache setting (see #7700) static $arrItCache; $arrCache =& $arrItCache[$blnCache]; for ($_rit = 0, $_cnt = count($tags); $_rit < $_cnt; $_rit += 2) { $strBuffer .= $tags[$_rit]; $strTag = $tags[$_rit + 1]; // Skip empty tags if ($strTag == '') { continue; } $flags = explode('|', $strTag); $tag = array_shift($flags); $elements = explode('::', $tag); // Load the value from cache if (isset($arrCache[$strTag]) && !in_array('refresh', $flags)) { $strBuffer .= $arrCache[$strTag]; continue; } // Skip certain elements if the output will be cached if ($blnCache) { if ($elements[0] == 'date' || $elements[0] == 'ua' || $elements[0] == 'post' || $elements[0] == 'file' || $elements[1] == 'back' || $elements[1] == 'referer' || $elements[0] == 'request_token' || $elements[0] == 'toggle_view' || strncmp($elements[0], 'cache_', 6) === 0 || in_array('uncached', $flags)) { $strBuffer .= '{{' . $strTag . '}}'; continue; } } $arrCache[$strTag] = ''; // Replace the tag switch (strtolower($elements[0])) { // Date case 'date': $arrCache[$strTag] = \Date::parse($elements[1] ?: \Config::get('dateFormat')); break; // Accessibility tags // Accessibility tags case 'lang': if ($elements[1] == '') { $arrCache[$strTag] = '</span>'; } else { $arrCache[$strTag] = $arrCache[$strTag] = '<span lang="' . $elements[1] . '">'; } break; // Line break // Line break case 'br': $arrCache[$strTag] = '<br>'; break; // E-mail addresses // E-mail addresses case 'email': case 'email_open': case 'email_url': if ($elements[1] == '') { $arrCache[$strTag] = ''; break; } $strEmail = \StringUtil::encodeEmail($elements[1]); // Replace the tag switch (strtolower($elements[0])) { case 'email': $arrCache[$strTag] = '<a href="mailto:' . $strEmail . '" class="email">' . preg_replace('/\\?.*$/', '', $strEmail) . '</a>'; break; case 'email_open': $arrCache[$strTag] = '<a href="mailto:' . $strEmail . '" title="' . $strEmail . '" class="email">'; break; case 'email_url': $arrCache[$strTag] = $strEmail; break; } break; // Label tags // Label tags case 'label': $keys = explode(':', $elements[1]); if (count($keys) < 2) { $arrCache[$strTag] = ''; break; } $file = $keys[0]; // Map the key (see #7217) switch ($file) { case 'CNT': $file = 'countries'; break; case 'LNG': $file = 'languages'; break; case 'MOD': case 'FMD': $file = 'modules'; break; case 'FFL': $file = 'tl_form_field'; break; case 'CACHE': $file = 'tl_page'; break; case 'XPL': $file = 'explain'; break; case 'XPT': $file = 'exception'; break; case 'MSC': case 'ERR': case 'CTE': case 'PTY': case 'FOP': case 'CHMOD': case 'DAYS': case 'MONTHS': case 'UNITS': case 'CONFIRM': case 'DP': case 'COLS': $file = 'default'; break; } \System::loadLanguageFile($file); if (count($keys) == 2) { $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]]; } else { $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]][$keys[2]]; } break; // Front end user // Front end user case 'user': if (FE_USER_LOGGED_IN) { $this->import('FrontendUser', 'User'); $value = $this->User->{$elements[1]}; if ($value == '') { $arrCache[$strTag] = $value; break; } $this->loadDataContainer('tl_member'); if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['inputType'] == 'password') { $arrCache[$strTag] = ''; break; } $value = \StringUtil::deserialize($value); // Decrypt the value if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['eval']['encrypt']) { $value = \Encryption::decrypt($value); } $rgxp = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['eval']['rgxp']; $opts = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['options']; $rfrc = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['reference']; if ($rgxp == 'date') { $arrCache[$strTag] = \Date::parse(\Config::get('dateFormat'), $value); } elseif ($rgxp == 'time') { $arrCache[$strTag] = \Date::parse(\Config::get('timeFormat'), $value); } elseif ($rgxp == 'datim') { $arrCache[$strTag] = \Date::parse(\Config::get('datimFormat'), $value); } elseif (is_array($value)) { $arrCache[$strTag] = implode(', ', $value); } elseif (is_array($opts) && array_is_assoc($opts)) { $arrCache[$strTag] = isset($opts[$value]) ? $opts[$value] : $value; } elseif (is_array($rfrc)) { $arrCache[$strTag] = isset($rfrc[$value]) ? is_array($rfrc[$value]) ? $rfrc[$value][0] : $rfrc[$value] : $value; } else { $arrCache[$strTag] = $value; } // Convert special characters (see #1890) $arrCache[$strTag] = \StringUtil::specialchars($arrCache[$strTag]); } break; // Link // Link case 'link': case 'link_open': case 'link_url': case 'link_title': case 'link_target': case 'link_name': $strTarget = null; // Back link if ($elements[1] == 'back') { $strUrl = 'javascript:history.go(-1)'; $strTitle = $GLOBALS['TL_LANG']['MSC']['goBack']; // No language files if the page is cached if (!strlen($strTitle)) { $strTitle = 'Go back'; } $strName = $strTitle; } elseif (strncmp($elements[1], 'http://', 7) === 0 || strncmp($elements[1], 'https://', 8) === 0) { $strUrl = $elements[1]; $strTitle = $elements[1]; $strName = str_replace(array('http://', 'https://'), '', $elements[1]); } else { // User login page if ($elements[1] == 'login') { if (!FE_USER_LOGGED_IN) { break; } $this->import('FrontendUser', 'User'); $elements[1] = $this->User->loginPage; } $objNextPage = \PageModel::findByIdOrAlias($elements[1]); if ($objNextPage === null) { break; } // Page type specific settings (thanks to Andreas Schempp) switch ($objNextPage->type) { case 'redirect': $strUrl = $objNextPage->url; if (strncasecmp($strUrl, 'mailto:', 7) === 0) { $strUrl = \StringUtil::encodeEmail($strUrl); } break; case 'forward': if ($objNextPage->jumpTo) { /** @var PageModel $objNext */ $objNext = $objNextPage->getRelated('jumpTo'); } else { $objNext = \PageModel::findFirstPublishedRegularByPid($objNextPage->id); } if ($objNext instanceof PageModel) { $strUrl = $objNext->getFrontendUrl(); break; } // DO NOT ADD A break; STATEMENT // DO NOT ADD A break; STATEMENT default: $strUrl = $objNextPage->getFrontendUrl(); break; } $strName = $objNextPage->title; $strTarget = $objNextPage->target ? ' target="_blank"' : ''; $strTitle = $objNextPage->pageTitle ?: $objNextPage->title; } // Replace the tag switch (strtolower($elements[0])) { case 'link': $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>%s</a>', $strUrl, \StringUtil::specialchars($strTitle), $strTarget, $strName); break; case 'link_open': $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>', $strUrl, \StringUtil::specialchars($strTitle), $strTarget); break; case 'link_url': $arrCache[$strTag] = $strUrl; break; case 'link_title': $arrCache[$strTag] = \StringUtil::specialchars($strTitle); break; case 'link_target': $arrCache[$strTag] = $strTarget; break; case 'link_name': $arrCache[$strTag] = $strName; break; } break; // Closing link tag // Closing link tag case 'link_close': case 'email_close': $arrCache[$strTag] = '</a>'; break; // Insert article // Insert article case 'insert_article': if (($strOutput = $this->getArticle($elements[1], false, true)) !== false) { $arrCache[$strTag] = ltrim($strOutput); } else { $arrCache[$strTag] = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $elements[1]) . '</p>'; } break; // Insert content element // Insert content element case 'insert_content': $arrCache[$strTag] = $this->getContentElement($elements[1]); break; // Insert module // Insert module case 'insert_module': $arrCache[$strTag] = $this->getFrontendModule($elements[1]); break; // Insert form // Insert form case 'insert_form': $arrCache[$strTag] = $this->getForm($elements[1]); break; // Article // Article case 'article': case 'article_open': case 'article_url': case 'article_title': if (($objArticle = \ArticleModel::findByIdOrAlias($elements[1])) === null || !($objPid = $objArticle->getRelated('pid')) instanceof PageModel) { break; } /** @var PageModel $objPid */ $strUrl = $objPid->getFrontendUrl('/articles/' . ($objArticle->alias ?: $objArticle->id)); // Replace the tag switch (strtolower($elements[0])) { case 'article': $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, \StringUtil::specialchars($objArticle->title), $objArticle->title); break; case 'article_open': $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, \StringUtil::specialchars($objArticle->title)); break; case 'article_url': $arrCache[$strTag] = $strUrl; break; case 'article_title': $arrCache[$strTag] = \StringUtil::specialchars($objArticle->title); break; } break; // Article teaser // Article teaser case 'article_teaser': $objTeaser = \ArticleModel::findByIdOrAlias($elements[1]); if ($objTeaser !== null) { $arrCache[$strTag] = \StringUtil::toHtml5($objTeaser->teaser); } break; // Last update // Last update case 'last_update': $strQuery = "SELECT MAX(tstamp) AS tc"; $bundles = \System::getContainer()->getParameter('kernel.bundles'); if (isset($bundles['ContaoNewsBundle'])) { $strQuery .= ", (SELECT MAX(tstamp) FROM tl_news) AS tn"; } if (isset($bundles['ContaoCalendarBundle'])) { $strQuery .= ", (SELECT MAX(tstamp) FROM tl_calendar_events) AS te"; } $strQuery .= " FROM tl_content"; $objUpdate = \Database::getInstance()->query($strQuery); if ($objUpdate->numRows) { $arrCache[$strTag] = \Date::parse($elements[1] ?: \Config::get('datimFormat'), max($objUpdate->tc, $objUpdate->tn, $objUpdate->te)); } break; // Version // Version case 'version': $arrCache[$strTag] = VERSION . '.' . BUILD; break; // Request token // Request token case 'request_token': $arrCache[$strTag] = REQUEST_TOKEN; break; // POST data // POST data case 'post': $arrCache[$strTag] = \Input::post($elements[1]); break; // Mobile/desktop toggle (see #6469) // Mobile/desktop toggle (see #6469) case 'toggle_view': $strUrl = ampersand(\Environment::get('request')); $strGlue = strpos($strUrl, '?') === false ? '?' : '&'; if (\Input::cookie('TL_VIEW') == 'mobile' || \Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop') { $arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=desktop" class="toggle_desktop" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['toggleDesktop'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleDesktop'][0] . '</a>'; } else { $arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=mobile" class="toggle_mobile" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['toggleMobile'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleMobile'][0] . '</a>'; } break; // Conditional tags (if) // Conditional tags (if) case 'iflng': if ($elements[1] != '' && $elements[1] != $objPage->language) { for (; $_rit < $_cnt; $_rit += 2) { if ($tags[$_rit + 1] == 'iflng' || $tags[$_rit + 1] == 'iflng::' . $objPage->language) { break; } } } unset($arrCache[$strTag]); break; // Conditional tags (if not) // Conditional tags (if not) case 'ifnlng': if ($elements[1] != '') { $langs = \StringUtil::trimsplit(',', $elements[1]); if (in_array($objPage->language, $langs)) { for (; $_rit < $_cnt; $_rit += 2) { if ($tags[$_rit + 1] == 'ifnlng') { break; } } } } unset($arrCache[$strTag]); break; // Environment // Environment case 'env': switch ($elements[1]) { case 'host': $arrCache[$strTag] = \Idna::decode(\Environment::get('host')); break; case 'http_host': $arrCache[$strTag] = \Idna::decode(\Environment::get('httpHost')); break; case 'url': $arrCache[$strTag] = \Idna::decode(\Environment::get('url')); break; case 'path': $arrCache[$strTag] = \Idna::decode(\Environment::get('base')); break; case 'request': $arrCache[$strTag] = \Environment::get('indexFreeRequest'); break; case 'ip': $arrCache[$strTag] = \Environment::get('ip'); break; case 'referer': $arrCache[$strTag] = $this->getReferer(true); break; case 'files_url': $arrCache[$strTag] = TL_FILES_URL; break; case 'assets_url': case 'plugins_url': case 'script_url': $arrCache[$strTag] = TL_ASSETS_URL; break; case 'base_url': $arrCache[$strTag] = \System::getContainer()->get('request_stack')->getCurrentRequest()->getBaseUrl(); break; } break; // Page // Page case 'page': if ($elements[1] == 'pageTitle' && $objPage->pageTitle == '') { $elements[1] = 'title'; } elseif ($elements[1] == 'parentPageTitle' && $objPage->parentPageTitle == '') { $elements[1] = 'parentTitle'; } elseif ($elements[1] == 'mainPageTitle' && $objPage->mainPageTitle == '') { $elements[1] = 'mainTitle'; } // Do not use \StringUtil::specialchars() here (see #4687) $arrCache[$strTag] = $objPage->{$elements[1]}; break; // User agent // User agent case 'ua': $ua = \Environment::get('agent'); if ($elements[1] != '') { $arrCache[$strTag] = $ua->{$elements[1]}; } else { $arrCache[$strTag] = ''; } break; // Abbreviations // Abbreviations case 'abbr': case 'acronym': if ($elements[1] != '') { $arrCache[$strTag] = '<abbr title="' . $elements[1] . '">'; } else { $arrCache[$strTag] = '</abbr>'; } break; // Images // Images case 'image': case 'picture': $width = null; $height = null; $alt = ''; $class = ''; $rel = ''; $strFile = $elements[1]; $mode = ''; $size = null; $strTemplate = 'picture_default'; // Take arguments if (strpos($elements[1], '?') !== false) { $arrChunks = explode('?', urldecode($elements[1]), 2); $strSource = \StringUtil::decodeEntities($arrChunks[1]); $strSource = str_replace('[&]', '&', $strSource); $arrParams = explode('&', $strSource); foreach ($arrParams as $strParam) { list($key, $value) = explode('=', $strParam); switch ($key) { case 'width': $width = $value; break; case 'height': $height = $value; break; case 'alt': $alt = \StringUtil::specialchars($value); break; case 'class': $class = $value; break; case 'rel': $rel = $value; break; case 'mode': $mode = $value; break; case 'size': $size = (int) $value; break; case 'template': $strTemplate = preg_replace('/[^a-z0-9_]/i', '', $value); break; } } $strFile = $arrChunks[0]; } if (\Validator::isUuid($strFile)) { // Handle UUIDs $objFile = \FilesModel::findByUuid($strFile); if ($objFile === null) { $arrCache[$strTag] = ''; break; } $strFile = $objFile->path; } elseif (is_numeric($strFile)) { // Handle numeric IDs (see #4805) $objFile = \FilesModel::findByPk($strFile); if ($objFile === null) { $arrCache[$strTag] = ''; break; } $strFile = $objFile->path; } else { // Check the path if (\Validator::isInsecurePath($strFile)) { throw new \RuntimeException('Invalid path ' . $strFile); } } // Check the maximum image width if (\Config::get('maxImageWidth') > 0 && $width > \Config::get('maxImageWidth')) { $width = \Config::get('maxImageWidth'); $height = null; } // Generate the thumbnail image try { // Image if (strtolower($elements[0]) == 'image') { $dimensions = ''; $imageObj = \Image::create($strFile, array($width, $height, $mode)); $src = $imageObj->executeResize()->getResizedPath(); $objFile = new \File(rawurldecode($src)); // Add the image dimensions if (($imgSize = $objFile->imageSize) !== false) { $dimensions = ' width="' . $imgSize[0] . '" height="' . $imgSize[1] . '"'; } $arrCache[$strTag] = '<img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . '>'; } else { $picture = \Picture::create($strFile, array(0, 0, $size))->getTemplateData(); $picture['alt'] = $alt; $picture['class'] = $class; $pictureTemplate = new \FrontendTemplate($strTemplate); $pictureTemplate->setData($picture); $arrCache[$strTag] = $pictureTemplate->parse(); } // Add a lightbox link if ($rel != '') { if (strncmp($rel, 'lightbox', 8) !== 0) { $attribute = ' rel="' . $rel . '"'; } else { $attribute = ' data-lightbox="' . substr($rel, 8) . '"'; } $arrCache[$strTag] = '<a href="' . TL_FILES_URL . $strFile . '"' . ($alt != '' ? ' title="' . $alt . '"' : '') . $attribute . '>' . $arrCache[$strTag] . '</a>'; } } catch (\Exception $e) { $arrCache[$strTag] = ''; } break; // Files (UUID or template path) // Files (UUID or template path) case 'file': if (\Validator::isUuid($elements[1])) { $objFile = \FilesModel::findByUuid($elements[1]); if ($objFile !== null) { $arrCache[$strTag] = $objFile->path; break; } } $arrGet = $_GET; \Input::resetCache(); $strFile = $elements[1]; // Take arguments and add them to the $_GET array if (strpos($elements[1], '?') !== false) { $arrChunks = explode('?', urldecode($elements[1])); $strSource = \StringUtil::decodeEntities($arrChunks[1]); $strSource = str_replace('[&]', '&', $strSource); $arrParams = explode('&', $strSource); foreach ($arrParams as $strParam) { $arrParam = explode('=', $strParam); $_GET[$arrParam[0]] = $arrParam[1]; } $strFile = $arrChunks[0]; } // Check the path if (\Validator::isInsecurePath($strFile)) { throw new \RuntimeException('Invalid path ' . $strFile); } // Include .php, .tpl, .xhtml and .html5 files if (preg_match('/\\.(php|tpl|xhtml|html5)$/', $strFile) && file_exists(TL_ROOT . '/templates/' . $strFile)) { ob_start(); include TL_ROOT . '/templates/' . $strFile; $arrCache[$strTag] = ob_get_clean(); } $_GET = $arrGet; \Input::resetCache(); break; // HOOK: pass unknown tags to callback functions // HOOK: pass unknown tags to callback functions default: if (isset($GLOBALS['TL_HOOKS']['replaceInsertTags']) && is_array($GLOBALS['TL_HOOKS']['replaceInsertTags'])) { foreach ($GLOBALS['TL_HOOKS']['replaceInsertTags'] as $callback) { $this->import($callback[0]); $varValue = $this->{$callback[0]}->{$callback[1]}($tag, $blnCache, $arrCache[$strTag], $flags, $tags, $arrCache, $_rit, $_cnt); // see #6672 // Replace the tag and stop the loop if ($varValue !== false) { $arrCache[$strTag] = $varValue; break; } } } if (\Config::get('debugMode')) { $GLOBALS['TL_DEBUG']['unknown_insert_tags'][] = $strTag; } break; } // Handle the flags if (!empty($flags)) { foreach ($flags as $flag) { switch ($flag) { case 'addslashes': case 'stripslashes': case 'standardize': case 'ampersand': case 'specialchars': case 'nl2br': case 'nl2br_pre': case 'strtolower': case 'utf8_strtolower': case 'strtoupper': case 'utf8_strtoupper': case 'ucfirst': case 'lcfirst': case 'ucwords': case 'trim': case 'rtrim': case 'ltrim': case 'utf8_romanize': case 'strrev': case 'urlencode': case 'rawurlencode': $arrCache[$strTag] = $flag($arrCache[$strTag]); break; case 'encodeEmail': case 'decodeEntities': $arrCache[$strTag] = \StringUtil::$flag($arrCache[$strTag]); break; case 'number_format': $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 0); break; case 'currency_format': $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 2); break; case 'readable_size': $arrCache[$strTag] = \System::getReadableSize($arrCache[$strTag]); break; case 'flatten': if (!is_array($arrCache[$strTag])) { break; } $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arrCache[$strTag])); $result = array(); foreach ($it as $leafValue) { $keys = array(); foreach (range(0, $it->getDepth()) as $depth) { $keys[] = $it->getSubIterator($depth)->key(); } $result[] = implode('.', $keys) . ': ' . $leafValue; } $arrCache[$strTag] = implode(', ', $result); break; // HOOK: pass unknown flags to callback functions // HOOK: pass unknown flags to callback functions default: if (isset($GLOBALS['TL_HOOKS']['insertTagFlags']) && is_array($GLOBALS['TL_HOOKS']['insertTagFlags'])) { foreach ($GLOBALS['TL_HOOKS']['insertTagFlags'] as $callback) { $this->import($callback[0]); $varValue = $this->{$callback[0]}->{$callback[1]}($flag, $tag, $arrCache[$strTag], $flags, $blnCache, $tags, $arrCache, $_rit, $_cnt); // see #5806 // Replace the tag and stop the loop if ($varValue !== false) { $arrCache[$strTag] = $varValue; break; } } } if (\Config::get('debugMode')) { $GLOBALS['TL_DEBUG']['unknown_insert_tag_flags'][] = $flag; } break; } } } $strBuffer .= $arrCache[$strTag]; } return \StringUtil::restoreBasicEntities($strBuffer); }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; $this->Template->content = ''; $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; $objNewsletter = \NewsletterModel::findSentByParentAndIdOrAlias(\Input::get('items'), $this->nl_channels); if (null === $objNewsletter) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } // Overwrite the page title (see #2853 and #4955) if ($objNewsletter->subject != '') { $objPage->pageTitle = strip_tags(strip_insert_tags($objNewsletter->subject)); } // Add enclosure if ($objNewsletter->addFile) { $this->addEnclosuresToTemplate($this->Template, $objNewsletter->row(), 'files'); } // Support plain text newsletters (thanks to Hagen Klemp) if ($objNewsletter->sendText) { $nl2br = $objPage->outputFormat == 'xhtml' ? 'nl2br_xhtml' : 'nl2br_html5'; $strContent = $nl2br($objNewsletter->text); } else { $strContent = str_ireplace(' align="center"', '', $objNewsletter->content); } // Parse simple tokens and insert tags $strContent = $this->replaceInsertTags($strContent); $strContent = \StringUtil::parseSimpleTokens($strContent, array()); // Encode e-mail addresses $strContent = \StringUtil::encodeEmail($strContent); $this->Template->content = $strContent; $this->Template->subject = $objNewsletter->subject; }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; $this->Template->event = ''; $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; // Get the current event $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias(\Input::get('events'), $this->cal_calendar); if (null === $objEvent) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } // Overwrite the page title (see #2853 and #4955) if ($objEvent->title != '') { $objPage->pageTitle = strip_tags(strip_insert_tags($objEvent->title)); } // Overwrite the page description if ($objEvent->teaser != '') { $objPage->description = $this->prepareMetaDescription($objEvent->teaser); } $intStartTime = $objEvent->startTime; $intEndTime = $objEvent->endTime; $span = \Calendar::calculateSpan($intStartTime, $intEndTime); // Do not show dates in the past if the event is recurring (see #923) if ($objEvent->recurring) { $arrRange = deserialize($objEvent->repeatEach); if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) { while ($intStartTime < time() && $intEndTime < $objEvent->repeatEnd) { $intStartTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intStartTime); $intEndTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intEndTime); } } } $strDate = \Date::parse($objPage->dateFormat, $intStartTime); if ($span > 0) { $strDate = \Date::parse($objPage->dateFormat, $intStartTime) . ' – ' . \Date::parse($objPage->dateFormat, $intEndTime); } $strTime = ''; if ($objEvent->addTime) { if ($span > 0) { $strDate = \Date::parse($objPage->datimFormat, $intStartTime) . ' – ' . \Date::parse($objPage->datimFormat, $intEndTime); } elseif ($intStartTime == $intEndTime) { $strTime = \Date::parse($objPage->timeFormat, $intStartTime); } else { $strTime = \Date::parse($objPage->timeFormat, $intStartTime) . ' – ' . \Date::parse($objPage->timeFormat, $intEndTime); } } $until = ''; $recurring = ''; // Recurring event if ($objEvent->recurring) { $arrRange = deserialize($objEvent->repeatEach); if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) { $strKey = 'cal_' . $arrRange['unit']; $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']); if ($objEvent->recurrences > 0) { $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], \Date::parse($objPage->dateFormat, $objEvent->repeatEnd)); } } } /** @var \FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData($objEvent->row()); $objTemplate->date = $strDate; $objTemplate->time = $strTime; $objTemplate->datetime = $objEvent->addTime ? date('Y-m-d\\TH:i:sP', $intStartTime) : date('Y-m-d', $intStartTime); $objTemplate->begin = $intStartTime; $objTemplate->end = $intEndTime; $objTemplate->class = $objEvent->cssClass != '' ? ' ' . $objEvent->cssClass : ''; $objTemplate->recurring = $recurring; $objTemplate->until = $until; $objTemplate->locationLabel = $GLOBALS['TL_LANG']['MSC']['location']; $objTemplate->details = ''; $objTemplate->hasDetails = false; $objTemplate->hasTeaser = false; // Clean the RTE output if ($objEvent->teaser != '') { $objTemplate->hasTeaser = true; if ($objPage->outputFormat == 'xhtml') { $objTemplate->teaser = \StringUtil::toXhtml($objEvent->teaser); } else { $objTemplate->teaser = \StringUtil::toHtml5($objEvent->teaser); } $objTemplate->teaser = \StringUtil::encodeEmail($objTemplate->teaser); } // Display the "read more" button for external/article links if ($objEvent->source != 'default') { $objTemplate->details = true; $objTemplate->hasDetails = true; } else { $id = $objEvent->id; $objTemplate->details = function () use($id) { $strDetails = ''; $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_calendar_events'); if ($objElement !== null) { while ($objElement->next()) { $strDetails .= $this->getContentElement($objElement->current()); } } return $strDetails; }; $objTemplate->hasDetails = \ContentModel::countPublishedByPidAndTable($id, 'tl_calendar_events') > 0; } $objTemplate->addImage = false; // Add an image if ($objEvent->addImage && $objEvent->singleSRC != '') { $objModel = \FilesModel::findByUuid($objEvent->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($objEvent->singleSRC)) { $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { // Do not override the field now that we have a model registry (see #6303) $arrEvent = $objEvent->row(); // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) { $arrEvent['size'] = $this->imgSize; } } $arrEvent['singleSRC'] = $objModel->path; $this->addImageToTemplate($objTemplate, $arrEvent); } } $objTemplate->enclosure = array(); // Add enclosures if ($objEvent->addEnclosure) { $this->addEnclosuresToTemplate($objTemplate, $objEvent->row()); } $this->Template->event = $objTemplate->parse(); // HOOK: comments extension required if ($objEvent->noComments || !in_array('comments', \ModuleLoader::getActive())) { $this->Template->allowComments = false; return; } /** @var \CalendarModel $objCalendar */ $objCalendar = $objEvent->getRelated('pid'); $this->Template->allowComments = $objCalendar->allowComments; // Comments are not allowed if (!$objCalendar->allowComments) { return; } // Adjust the comments headline level $intHl = min(intval(str_replace('h', '', $this->hl)), 5); $this->Template->hlc = 'h' . ($intHl + 1); $this->import('Comments'); $arrNotifies = array(); // Notify the system administrator if ($objCalendar->notify != 'notify_author') { $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL']; } // Notify the author if ($objCalendar->notify != 'notify_admin') { /** @var \UserModel $objAuthor */ if (($objAuthor = $objEvent->getRelated('author')) !== null && $objAuthor->email != '') { $arrNotifies[] = $objAuthor->email; } } $objConfig = new \stdClass(); $objConfig->perPage = $objCalendar->perPage; $objConfig->order = $objCalendar->sortOrder; $objConfig->template = $this->com_template; $objConfig->requireLogin = $objCalendar->requireLogin; $objConfig->disableCaptcha = $objCalendar->disableCaptcha; $objConfig->bbcode = $objCalendar->bbcode; $objConfig->moderate = $objCalendar->moderate; $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_calendar_events', $objEvent->id, $arrNotifies); }
/** * Generate a URL and return it as string * * @param \CalendarEventsModel $objEvent * @param string $strUrl * * @return string */ protected function generateEventUrl($objEvent, $strUrl) { switch ($objEvent->source) { // Link to an external page case 'external': if (substr($objEvent->url, 0, 7) == 'mailto:') { return \StringUtil::encodeEmail($objEvent->url); } else { return ampersand($objEvent->url); } break; // Link to an internal page // Link to an internal page case 'internal': if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) { /** @var \PageModel $objTarget */ return ampersand($objTarget->getFrontendUrl()); } break; // Link to an article // Link to an article case 'article': if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) { /** @var \PageModel $objPid */ return ampersand($objPid->getFrontendUrl('/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id))); } break; } // Link to the default page return ampersand(sprintf($strUrl, !\Config::get('disableAlias') && $objEvent->alias != '' ? $objEvent->alias : $objEvent->id)); }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; $type = null; $pageId = $objPage->id; $pages = array($objPage); $items = array(); // Get all pages up to the root page $objPages = \PageModel::findParentsById($objPage->pid); if ($objPages !== null) { while ($pageId > 0 && $type != 'root' && $objPages->next()) { $type = $objPages->type; $pageId = $objPages->pid; $pages[] = $objPages->current(); } } // Get the first active regular page and display it instead of the root page if ($type == 'root') { $objFirstPage = \PageModel::findFirstPublishedByPid($objPages->id); $items[] = array('isRoot' => true, 'isActive' => false, 'href' => $objFirstPage !== null ? $objFirstPage->getFrontendUrl() : \Environment::get('base'), 'title' => specialchars($objPages->pageTitle ?: $objPages->title, true), 'link' => $objPages->title, 'data' => $objFirstPage->row(), 'class' => ''); array_pop($pages); } /** @var \PageModel[] $pages */ for ($i = count($pages) - 1; $i > 0; $i--) { if ($pages[$i]->hide && !$this->showHidden || !$pages[$i]->published && !BE_USER_LOGGED_IN) { continue; } // Get href switch ($pages[$i]->type) { case 'redirect': $href = $pages[$i]->url; if (strncasecmp($href, 'mailto:', 7) === 0) { $href = \StringUtil::encodeEmail($href); } break; case 'forward': if (($objNext = $pages[$i]->getRelated('jumpTo')) !== null || ($objNext = \PageModel::findFirstPublishedRegularByPid($pages[$i]->id)) !== null) { /** @var \PageModel $objNext */ $href = $objNext->getFrontendUrl(); break; } // DO NOT ADD A break; STATEMENT // DO NOT ADD A break; STATEMENT default: $href = $pages[$i]->getFrontendUrl(); break; } $items[] = array('isRoot' => false, 'isActive' => false, 'href' => $href, 'title' => specialchars($pages[$i]->pageTitle ?: $pages[$i]->title, true), 'link' => $pages[$i]->title, 'data' => $pages[$i]->row(), 'class' => ''); } // Active article if (isset($_GET['articles'])) { $items[] = array('isRoot' => false, 'isActive' => false, 'href' => $pages[0]->getFrontendUrl(), 'title' => specialchars($pages[0]->pageTitle ?: $pages[0]->title, true), 'link' => $pages[0]->title, 'data' => $pages[0]->row(), 'class' => ''); list($strSection, $strArticle) = explode(':', \Input::get('articles')); if ($strArticle === null) { $strArticle = $strSection; } $objArticle = \ArticleModel::findByIdOrAlias($strArticle); $strAlias = $objArticle->alias != '' && !\Config::get('disableAlias') ? $objArticle->alias : $objArticle->id; if ($objArticle->inColumn != 'main') { $strAlias = $objArticle->inColumn . ':' . $strAlias; } if ($objArticle !== null) { $items[] = array('isRoot' => false, 'isActive' => true, 'href' => $pages[0]->getFrontendUrl('/articles/' . $strAlias), 'title' => specialchars($objArticle->title, true), 'link' => $objArticle->title, 'data' => $objArticle->row(), 'class' => ''); } } else { $items[] = array('isRoot' => false, 'isActive' => true, 'href' => $pages[0]->getFrontendUrl(), 'title' => specialchars($pages[0]->pageTitle ?: $pages[0]->title), 'link' => $pages[0]->title, 'data' => $pages[0]->row(), 'class' => ''); } // Mark the first element (see #4833) $items[0]['class'] = 'first'; // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['generateBreadcrumb']) && is_array($GLOBALS['TL_HOOKS']['generateBreadcrumb'])) { foreach ($GLOBALS['TL_HOOKS']['generateBreadcrumb'] as $callback) { $this->import($callback[0]); $items = $this->{$callback[0]}->{$callback[1]}($items, $this); } } $this->Template->items = $items; }
/** * Format a value * * @param string $k * @param mixed $value * @param boolean $blnListSingle * * @return mixed */ protected function formatValue($k, $value, $blnListSingle = false) { $value = deserialize($value); // Return if empty if (empty($value)) { return ''; } /** @var \PageModel $objPage */ global $objPage; // Array if (is_array($value)) { $value = implode(', ', $value); } elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'date') { $value = \Date::parse($objPage->dateFormat, $value); } elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'time') { $value = \Date::parse($objPage->timeFormat, $value); } elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'datim') { $value = \Date::parse($objPage->datimFormat, $value); } elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'url' && preg_match('@^(https?://|ftp://)@i', $value)) { $value = \Idna::decode($value); // see #5946 $value = '<a href="' . $value . '"' . ($objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"') . '>' . $value . '</a>'; } elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'email') { $value = \StringUtil::encodeEmail(\Idna::decode($value)); // see #5946 $value = '<a href="mailto:' . $value . '">' . $value . '</a>'; } elseif (is_array($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['reference'])) { $value = $GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['reference'][$value]; } elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['isAssociative'] || array_is_assoc($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['options'])) { if ($blnListSingle) { $value = $GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['options'][$value]; } else { $value = '<span class="value">[' . $value . ']</span> ' . $GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['options'][$value]; } } return $value; }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; $this->Template->referer = 'javascript:history.go(-1)'; $objFaq = \FaqModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->faq_categories); if (null === $objFaq) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } // Overwrite the page title and description (see #2853 and #4955) if ($objFaq->question != '') { $objPage->pageTitle = strip_tags(strip_insert_tags($objFaq->question)); $objPage->description = $this->prepareMetaDescription($objFaq->question); } $this->Template->question = $objFaq->question; // Clean RTE output if ($objPage->outputFormat == 'xhtml') { $objFaq->answer = \StringUtil::toXhtml($objFaq->answer); } else { $objFaq->answer = \StringUtil::toHtml5($objFaq->answer); } $this->Template->answer = \StringUtil::encodeEmail($objFaq->answer); $this->Template->addImage = false; // Add image if ($objFaq->addImage && $objFaq->singleSRC != '') { $objModel = \FilesModel::findByUuid($objFaq->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($objFaq->singleSRC)) { $this->Template->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { // Do not override the field now that we have a model registry (see #6303) $arrFaq = $objFaq->row(); $arrFaq['singleSRC'] = $objModel->path; $this->addImageToTemplate($this->Template, $arrFaq); } } $this->Template->enclosure = array(); // Add enclosure if ($objFaq->addEnclosure) { $this->addEnclosuresToTemplate($this->Template, $objFaq->row()); } $strAuthor = ''; // Add the author if (($objAuthor = $objFaq->getRelated('author')) !== null) { $strAuthor = $objAuthor->name; } $this->Template->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], \Date::parse($objPage->dateFormat, $objFaq->tstamp), $strAuthor); // HOOK: comments extension required if ($objFaq->noComments || !in_array('comments', \ModuleLoader::getActive())) { $this->Template->allowComments = false; return; } /** @var \FaqCategoryModel $objCategory */ $objCategory = $objFaq->getRelated('pid'); $this->Template->allowComments = $objCategory->allowComments; // Comments are not allowed if (!$objCategory->allowComments) { return; } // Adjust the comments headline level $intHl = min(intval(str_replace('h', '', $this->hl)), 5); $this->Template->hlc = 'h' . ($intHl + 1); $this->import('Comments'); $arrNotifies = array(); // Notify the system administrator if ($objCategory->notify != 'notify_author') { $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL']; } // Notify the author if ($objCategory->notify != 'notify_admin') { /** @var \UserModel $objAuthor */ if (($objAuthor = $objFaq->getRelated('author')) !== null && $objAuthor->email != '') { $arrNotifies[] = $objAuthor->email; } } $objConfig = new \stdClass(); $objConfig->perPage = $objCategory->perPage; $objConfig->order = $objCategory->sortOrder; $objConfig->template = $this->com_template; $objConfig->requireLogin = $objCategory->requireLogin; $objConfig->disableCaptcha = $objCategory->disableCaptcha; $objConfig->bbcode = $objCategory->bbcode; $objConfig->moderate = $objCategory->moderate; $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_faq', $objFaq->id, $arrNotifies); }
/** * Generate a URL and return it as string * * @param CalendarEventsModel $objEvent * * @return string */ public static function generateEventUrl($objEvent) { $strCacheKey = 'id_' . $objEvent->id; // Load the URL from cache if (isset(self::$arrUrlCache[$strCacheKey])) { return self::$arrUrlCache[$strCacheKey]; } // Initialize the cache self::$arrUrlCache[$strCacheKey] = null; switch ($objEvent->source) { // Link to an external page case 'external': if (substr($objEvent->url, 0, 7) == 'mailto:') { self::$arrUrlCache[$strCacheKey] = \StringUtil::encodeEmail($objEvent->url); } else { self::$arrUrlCache[$strCacheKey] = ampersand($objEvent->url); } break; // Link to an internal page // Link to an internal page case 'internal': if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) { self::$arrUrlCache[$strCacheKey] = ampersand(\Controller::generateFrontendUrl($objTarget->row())); } break; // Link to an article // Link to an article case 'article': if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) { self::$arrUrlCache[$strCacheKey] = ampersand(\Controller::generateFrontendUrl($objPid->row(), '/articles/' . ($objArticle->alias ?: $objArticle->id))); } break; } // Link to the default page if (self::$arrUrlCache[$strCacheKey] === null) { $objPage = \PageModel::findByPk($objEvent->getRelated('pid')->jumpTo); if ($objPage === null) { self::$arrUrlCache[$strCacheKey] = ampersand(\Environment::get('request'), true); } else { self::$arrUrlCache[$strCacheKey] = ampersand(\Controller::generateFrontendUrl($objPage->row(), (\Config::get('useAutoItem') ? '/' : '/events/') . ($objEvent->alias ?: $objEvent->id))); } } return self::$arrUrlCache[$strCacheKey]; }
/** * Generate a link and return it as string * * @param string $strLink * @param NewsModel $objArticle * @param boolean $blnAddArchive * @param boolean $blnIsReadMore * * @return string */ protected function generateLink($strLink, $objArticle, $blnAddArchive = false, $blnIsReadMore = false) { // Internal link if ($objArticle->source != 'external') { return sprintf('<a href="%s" title="%s" itemprop="url">%s%s</a>', \News::generateNewsUrl($objArticle, $blnAddArchive), \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->headline), true), $strLink, $blnIsReadMore ? '<span class="invisible"> ' . $objArticle->headline . '</span>' : ''); } // Encode e-mail addresses if (substr($objArticle->url, 0, 7) == 'mailto:') { $strArticleUrl = \StringUtil::encodeEmail($objArticle->url); } else { $strArticleUrl = ampersand($objArticle->url); } // External link return sprintf('<a href="%s" title="%s"%s itemprop="url">%s</a>', $strArticleUrl, \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['open'], $strArticleUrl)), $objArticle->target ? ' target="_blank"' : '', $strLink); }
protected function getPageData($pagesResult, $imageSize = null) { $href = null; if ($pagesResult->type === 'redirect') { $href = $pagesResult->url; if (strncasecmp($href, 'mailto:', 7) === 0) { $href = \StringUtil::encodeEmail($href); } } else { if ($pagesResult->type === 'forward') { if ($pagesResult->jumpTo) { $targetPage = $pagesResult->getRelated('jumpTo'); } else { $targetPage = \PageModel::findFirstPublishedRegularByPid($pagesResult->id); } if ($targetPage !== null) { $forceLang = null; $targetPage->loadDetails(); if ($GLOBALS['TL_CONFIG']['addLanguageToUrl']) { $forceLang = $targetPage->language; } $href = $this->generateFrontendUrl($targetPage->row(), null, $forceLang); if ($targetPage->domain != '' && $targetPage->domain != \Environment::get('host')) { $href = (\Environment::get('ssl') ? 'https://' : 'http://') . $targetPage->domain . TL_PATH . '/' . $href; } } } } if (!$href) { $href = $this->generateFrontendUrl($pagesResult->row(), null, $language); if ($pagesResult->domain != '' && $pagesResult->domain != \Environment::get('host')) { $href = (\Environment::get('ssl') ? 'https://' : 'http://') . $pagesResult->domain . TL_PATH . '/' . $href; } } if (($GLOBALS['objPage']->id == $pagesResult->id || $pagesResult->type == 'forward' && $GLOBALS['objPage']->id == $pagesResult->jumpTo) && !\Input::get('articles')) { $cssClass = ($pagesResult->type == 'forward' && $GLOBALS['objPage']->id == $pagesResult->jumpTo ? 'forward' . (in_array($pagesResult->id, $GLOBALS['objPage']->trail) ? ' trail' : '') : 'active') . ($pagesResult->protected ? ' protected' : '') . ($pagesResult->cssClass != '' ? ' ' . $pagesResult->cssClass : ''); $page['isActive'] = true; } else { $cssClass = ($pagesResult->protected ? ' protected' : '') . (in_array($pagesResult->id, $GLOBALS['objPage']->trail) ? ' trail' : '') . ($pagesResult->cssClass != '' ? ' ' . $pagesResult->cssClass : ''); if ($pagesResult->pid == $GLOBALS['objPage']->pid) { $cssClass .= ' sibling'; } $page['isActive'] = false; } $page = $pagesResult->row(); $page['class'] = trim($cssClass); $page['title'] = specialchars($pagesResult->title, true); $page['pageTitle'] = specialchars($pagesResult->pageTitle, true); $page['link'] = $pagesResult->title; $page['href'] = $href ?: './'; $page['nofollow'] = strncmp($pagesResult->robots, 'noindex', 7) === 0; $page['target'] = ''; $page['description'] = str_replace(array("\n", "\r"), array(' ', ''), $pagesResult->description); $page['rsmm_image'] = $this->getImageObject($page['rsmm_image'], $imageSize); // Override the link target if ($pagesResult->type == 'redirect' && $pagesResult->target) { $page['target'] = ' target="_blank"'; } return $page; }
/** * Handle external urls * @return bool return true, or false if the url does not exist */ protected function handleExternal() { if ($this->url == '') { return false; } if (substr($this->url, 0, 7) == 'mailto:') { $this->setHref(\StringUtil::encodeEmail($this->url)); $this->setTitle(sprintf($GLOBALS['TL_LANG']['MSC']['linkteaser']['externalMailTitle'], $this->getHref())); $this->setLink(sprintf($this->getLink(), $this->getHref())); } else { $this->setHref(ampersand($this->url)); $strLinkTitle = $this->getLinkTitle($this->getHref()); $this->setTitle(sprintf($GLOBALS['TL_LANG']['MSC']['linkteaser']['externalLinkTitle'], $strLinkTitle)); $this->setLink(sprintf($this->getLink(), $strLinkTitle)); } return true; }