Example #1
0
 /**
  * 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="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" class="email">' . preg_replace('/\\?.*$/', '', $strEmail) . '</a>';
                         break;
                     case 'email_open':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $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 ? '?' : '&amp;';
                 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);
 }
Example #2
0
 /**
  * Replace insert tags with their values
  * 
  * @param string  $strBuffer The text with the tags to be replaced
  * @param boolean $blnCache  If true, some tags will be preserved
  * 
  * @return string The text with the replaced tags
  */
 protected function replaceInsertTags($strBuffer, $blnCache = false)
 {
     global $objPage;
     // Preserve insert tags
     if ($GLOBALS['TL_CONFIG']['disableInsertTags']) {
         return $this->restoreBasicEntities($strBuffer);
     }
     $tags = preg_split('/\\{\\{([^\\}]+)\\}\\}/', $strBuffer, -1, PREG_SPLIT_DELIM_CAPTURE);
     $strBuffer = '';
     $arrCache = array();
     for ($_rit = 0; $_rit < count($tags); $_rit = $_rit + 2) {
         $strBuffer .= $tags[$_rit];
         $strTag = $tags[$_rit + 1];
         // Skip empty tags
         if ($strTag == '') {
             continue;
         }
         // Load value from cache array
         if (isset($arrCache[$strTag])) {
             $strBuffer .= $arrCache[$strTag];
             continue;
         }
         $elements = explode('::', $strTag);
         // Skip certain elements if the output will be cached
         if ($blnCache) {
             if ($elements[0] == 'date' || $elements[0] == 'ua' || $elements[0] == 'file' || $elements[1] == 'back' || $elements[1] == 'referer' || $elements[0] == 'request_token' || strncmp($elements[0], 'cache_', 6) === 0) {
                 $strBuffer .= '{{' . $strTag . '}}';
                 continue;
             }
         }
         $arrCache[$strTag] = '';
         // Replace the tag
         switch (strtolower($elements[0])) {
             // Date
             case 'date':
                 $arrCache[$strTag] = $this->parseDate($elements[1] ?: $GLOBALS['TL_CONFIG']['dateFormat']);
                 break;
                 // Accessibility tags
             // Accessibility tags
             case 'lang':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '</span>';
                 } elseif ($objPage->outputFormat == 'xhtml') {
                     $arrCache[$strTag] = '<span lang="' . $elements[1] . '" xml:lang="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = $arrCache[$strTag] = '<span lang="' . $elements[1] . '">';
                 }
                 break;
                 // E-mail addresses
             // E-mail addresses
             case 'email':
             case 'email_open':
             case 'email_url':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $strEmail = \String::encodeEmail($elements[1]);
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'email':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" class="email">' . preg_replace('/\\?.*$/', '', $strEmail) . '</a>';
                         break;
                     case 'email_open':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $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;
                 }
                 $this->loadLanguageFile($keys[0]);
                 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 = deserialize($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] = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $value);
                     } elseif ($rgxp == 'time') {
                         $arrCache[$strTag] = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $value);
                     } elseif ($rgxp == 'datim') {
                         $arrCache[$strTag] = $this->parseDate($GLOBALS['TL_CONFIG']['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] = specialchars($arrCache[$strTag]);
                 }
                 break;
                 // Link
             // Link
             case 'link':
             case 'link_open':
             case 'link_url':
             case 'link_title':
                 // 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 = \String::encodeEmail($strUrl);
                             }
                             break;
                         case 'forward':
                             if (($objTarget = $objNextPage->getRelated('jumpTo')) !== null) {
                                 $strUrl = $this->generateFrontendUrl($objTarget->row());
                                 break;
                             } elseif (($objTarget = \PageModel::findFirstPublishedRegularByPid($objNextPage->id)) !== null) {
                                 if ($GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
                                     $objTarget = $this->getPageDetails($objTarget);
                                     // see #3983
                                     $strUrl = $this->generateFrontendUrl($objTarget->row(), null, $objTarget->language);
                                 } else {
                                     $strUrl = $this->generateFrontendUrl($objTarget->row());
                                 }
                                 break;
                             }
                             // DO NOT ADD A break; STATEMENT
                         // DO NOT ADD A break; STATEMENT
                         default:
                             if ($GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
                                 $objNextPage = $this->getPageDetails($objNextPage);
                                 // see #3983
                                 $strUrl = $this->generateFrontendUrl($objNextPage->row(), null, $objNextPage->language);
                             } else {
                                 $strUrl = $this->generateFrontendUrl($objNextPage->row());
                             }
                             break;
                     }
                     $strName = $objNextPage->title;
                     $strTarget = $objNextPage->target ? $objPage->outputFormat == 'xhtml' ? LINK_NEW_WINDOW : ' 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, specialchars($strTitle), $strTarget, specialchars($strName));
                         break;
                     case 'link_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>', $strUrl, specialchars($strTitle), $strTarget);
                         break;
                     case 'link_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'link_title':
                         $arrCache[$strTag] = specialchars($strTitle);
                         break;
                     case 'link_target':
                         $arrCache[$strTag] = $strTarget;
                         break;
                 }
                 break;
                 // Closing link tag
             // Closing link tag
             case 'link_close':
                 $arrCache[$strTag] = '</a>';
                 break;
                 // Insert article
             // Insert article
             case 'insert_article':
                 if (($strOutput = $this->getArticle($elements[1], false, true)) !== false) {
                     $arrCache[$strTag] = $this->replaceInsertTags(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->replaceInsertTags($this->getContentElement($elements[1]));
                 break;
                 // Insert module
             // Insert module
             case 'insert_module':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getFrontendModule($elements[1]));
                 break;
                 // Insert form
             // Insert form
             case 'insert_form':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getForm($elements[1]));
                 break;
                 // Article
             // Article
             case 'article':
             case 'article_open':
             case 'article_url':
             case 'article_title':
                 $objArticle = \ArticleModel::findByIdOrAlias($elements[1]);
                 if ($objArticle === null) {
                     break;
                 } else {
                     $strUrl = $this->generateFrontendUrl($objArticle->row(), '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objArticle->alias) ? $objArticle->alias : $objArticle->id));
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'article':
                         $strLink = specialchars($objArticle->title);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'article_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objArticle->title));
                         break;
                     case 'article_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'article_title':
                         $arrCache[$strTag] = specialchars($objArticle->title);
                         break;
                 }
                 break;
                 // FAQ
             // FAQ
             case 'faq':
             case 'faq_open':
             case 'faq_url':
             case 'faq_title':
                 $objFaq = \FaqModel::findByIdOrAlias($elements[1]);
                 if ($objFaq === null) {
                     break;
                 } else {
                     $strUrl = $this->generateFrontendUrl($objFaq->row(), ($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objFaq->alias != '' ? $objFaq->alias : $objFaq->id));
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'faq':
                         $strLink = specialchars($objFaq->question);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'faq_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objFaq->question));
                         break;
                     case 'faq_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'faq_title':
                         $arrCache[$strTag] = specialchars($objFaq->question);
                         break;
                 }
                 break;
                 // News
             // News
             case 'news':
             case 'news_open':
             case 'news_url':
             case 'news_title':
                 $objNews = \NewsModel::findByIdOrAlias($elements[1]);
                 if ($objNews === null) {
                     break;
                 } elseif ($objNews->source == 'internal') {
                     $strUrl = $this->generateFrontendUrl($objNews->getRelated('jumpTo')->row());
                 } elseif ($objNews->source == 'article') {
                     $objArticle = \ArticleModel::findByPk($objNews->articleId, array('eager' => true));
                     $strUrl = $this->generateFrontendUrl($objArticle->pid, '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
                 } elseif ($objNews->source == 'external') {
                     $strUrl = $objNews->url;
                 } else {
                     $strUrl = $this->generateFrontendUrl($objNews->pid, ($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objNews->alias != '' ? $objNews->alias : $objNews->id));
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'news':
                         $strLink = specialchars($objNews->headline);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'news_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objNews->headline));
                         break;
                     case 'news_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'news_title':
                         $arrCache[$strTag] = specialchars($objNews->headline);
                         break;
                 }
                 break;
                 // Events
             // Events
             case 'event':
             case 'event_open':
             case 'event_url':
             case 'event_title':
                 $objEvent = \CalendarEventsModel::findByIdOrAlias($elements[1]);
                 if ($objEvent === null) {
                     break;
                 } elseif ($objEvent->source == 'internal') {
                     $strUrl = $this->generateFrontendUrl($objEvent->getRelated('jumpTo')->row());
                 } elseif ($objEvent->source == 'article') {
                     $objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true));
                     $strUrl = $this->generateFrontendUrl($objArticle->pid, '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
                 } elseif ($objEvent->source == 'external') {
                     $strUrl = $objEvent->url;
                 } else {
                     $strUrl = $this->generateFrontendUrl($objEvent->pid, ($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/events/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objEvent->alias != '' ? $objEvent->alias : $objEvent->id));
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'event':
                         $strLink = specialchars($objEvent->title);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'event_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objEvent->title));
                         break;
                     case 'event_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'event_title':
                         $arrCache[$strTag] = specialchars($objEvent->title);
                         break;
                 }
                 break;
                 // Article teaser
             // Article teaser
             case 'article_teaser':
                 $objTeaser = \ArticleModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \String::toXhtml($this->replaceInsertTags($objTeaser->teaser));
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($this->replaceInsertTags($objTeaser->teaser));
                     }
                 }
                 break;
                 // News teaser
             // News teaser
             case 'news_teaser':
                 $objTeaser = \NewsModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \String::toXhtml($objTeaser->teaser);
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($objTeaser->teaser);
                     }
                 }
                 break;
                 // Event teaser
             // Event teaser
             case 'event_teaser':
                 $objTeaser = \CalendarEventsModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \String::toXhtml($objTeaser->teaser);
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($objTeaser->teaser);
                     }
                 }
                 break;
                 // News feed URL
             // News feed URL
             case 'news_feed':
                 // FIXME: feeds are now in tl_calendar_feed
                 $objFeed = \NewsArchiveModel::findByPk($elements[1]);
                 if ($objFeed !== null) {
                     $arrCache[$strTag] = $objFeed->feedBase . $objFeed->alias . '.xml';
                 }
                 break;
                 // Calendar feed URL
             // Calendar feed URL
             case 'calendar_feed':
                 // FIXME: feeds are now in tl_calendar_feed
                 $objFeed = \CalendarModel::findByPk($elements[1]);
                 if ($objFeed !== null) {
                     $arrCache[$strTag] = $objFeed->feedBase . $objFeed->alias . '.xml';
                 }
                 break;
                 // Last update
             // Last update
             case 'last_update':
                 $objUpdate = \Database::getInstance()->execute("SELECT MAX(tstamp) AS tc, (SELECT MAX(tstamp) FROM tl_news) AS tn, (SELECT MAX(tstamp) FROM tl_calendar_events) AS te FROM tl_content");
                 if ($objUpdate->numRows) {
                     $arrCache[$strTag] = $this->parseDate($elements[1] ?: $GLOBALS['TL_CONFIG']['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;
                 // Conditional tags
             // Conditional tags
             case 'iflng':
                 if ($elements[1] != '' && $elements[1] != $objPage->language) {
                     for ($_rit; $_rit < count($tags); $_rit += 2) {
                         if ($tags[$_rit + 1] == 'iflng') {
                             break;
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
             case 'ifnlng':
                 if ($elements[1] != '') {
                     $langs = trimsplit(',', $elements[1]);
                     if (in_array($objPage->language, $langs)) {
                         for ($_rit; $_rit < count($tags); $_rit += 2) {
                             if ($tags[$_rit + 1] == 'ifnlng') {
                                 break;
                             }
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
                 // Environment
             // Environment
             case 'env':
                 switch ($elements[1]) {
                     case 'host':
                         $arrCache[$strTag] = \Environment::get('host');
                         break;
                     case 'http_host':
                         $arrCache[$strTag] = \Environment::get('httpHost');
                         break;
                     case 'url':
                         $arrCache[$strTag] = \Environment::get('url');
                         break;
                     case 'path':
                         $arrCache[$strTag] = \Environment::get('base');
                         break;
                     case 'request':
                         $arrCache[$strTag] = $this->getIndexFreeRequest(true);
                         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 'script_url':
                         $arrCache[$strTag] = TL_SCRIPT_URL;
                         break;
                     case 'plugins_url':
                         $arrCache[$strTag] = TL_PLUGINS_URL;
                         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';
                 }
                 $arrCache[$strTag] = specialchars($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;
                 // Acronyms
             // Acronyms
             case 'acronym':
                 if ($objPage->outputFormat == 'xhtml') {
                     if ($elements[1] != '') {
                         $arrCache[$strTag] = '<acronym title="' . $elements[1] . '">';
                     } else {
                         $arrCache[$strTag] = '</acronym>';
                     }
                     break;
                 }
                 // NO break;
                 // Abbreviations
             // NO break;
             // Abbreviations
             case 'abbr':
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = '<abbr title="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = '</abbr>';
                 }
                 break;
                 // Images
             // Images
             case 'image':
                 $width = null;
                 $height = null;
                 $alt = '';
                 $class = '';
                 $rel = '';
                 $strFile = $elements[1];
                 $mode = '';
                 // Take arguments
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]), 2);
                     $strSource = \String::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 = specialchars($value);
                                 break;
                             case 'class':
                                 $class = $value;
                                 break;
                             case 'rel':
                                 $rel = $value;
                                 break;
                             case 'mode':
                                 $mode = $value;
                                 break;
                         }
                     }
                     $strFile = $arrChunks[0];
                 }
                 // Sanitize path
                 $strFile = str_replace('../', '', $strFile);
                 // Check maximum image width
                 if ($GLOBALS['TL_CONFIG']['maxImageWidth'] > 0 && $width > $GLOBALS['TL_CONFIG']['maxImageWidth']) {
                     $width = $GLOBALS['TL_CONFIG']['maxImageWidth'];
                     $height = null;
                 }
                 // Generate the thumbnail image
                 try {
                     $src = \Image::get($strFile, $width, $height, $mode);
                     $dimensions = '';
                     // Add the image dimensions
                     if (($imgSize = @getimagesize(TL_ROOT . '/' . rawurldecode($src))) !== false) {
                         $dimensions = $imgSize[3];
                     }
                     // Generate the HTML markup
                     if ($rel != '') {
                         if (strncmp($rel, 'lightbox', 8) !== 0 || $objPage->outputFormat == 'xhtml') {
                             $attribute = ' rel="' . $rel . '"';
                         } else {
                             $attribute = ' data-lightbox="' . substr($rel, 8) . '"';
                         }
                         $arrCache[$strTag] = '<a href="' . TL_FILES_URL . $strFile . '"' . ($alt != '' ? ' title="' . $alt . '"' : '') . $attribute . '><img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . ($objPage->outputFormat == 'xhtml' ? ' />' : '>') . '</a>';
                     } else {
                         $arrCache[$strTag] = '<img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . ($objPage->outputFormat == 'xhtml' ? ' />' : '>');
                     }
                 } catch (Exception $e) {
                     $arrCache[$strTag] = '';
                 }
                 break;
                 // Files from the templates directory
             // Files from the templates directory
             case 'file':
                 $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 = \String::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];
                 }
                 // Sanitize path
                 $strFile = str_replace('../', '', $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_contents();
                     ob_end_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]($strTag);
                         // Replace the tag and stop the loop
                         if ($varValue !== false) {
                             $arrCache[$strTag] = $varValue;
                             break;
                         }
                     }
                 }
                 break;
         }
         $strBuffer .= $arrCache[$strTag];
     }
     return $this->restoreBasicEntities($strBuffer);
 }
Example #3
0
 /**
  * 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 replaceInsertTags($strBuffer, $blnCache = true)
 {
     global $objPage;
     // Preserve insert tags
     if (\Config::get('disableInsertTags')) {
         return \String::restoreBasicEntities($strBuffer);
     }
     $tags = preg_split('/\\{\\{(([^\\{\\}]*|(?R))*)\\}\\}/', $strBuffer, -1, PREG_SPLIT_DELIM_CAPTURE);
     $strBuffer = '';
     static $arrCache = array();
     for ($_rit = 0, $_cnt = count($tags); $_rit < $_cnt; $_rit += 3) {
         $strBuffer .= $tags[$_rit];
         $strTag = $tags[$_rit + 1];
         // Skip empty tags
         if ($strTag == '') {
             continue;
         }
         // Run the replacement again if there are more tags (see #4402)
         if (strpos($strTag, '{{') !== false) {
             $strTag = $this->replaceInsertTags($strTag, $blnCache);
         }
         $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>';
                 } elseif ($objPage->outputFormat == 'xhtml') {
                     $arrCache[$strTag] = '<span lang="' . $elements[1] . '" xml:lang="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = $arrCache[$strTag] = '<span lang="' . $elements[1] . '">';
                 }
                 break;
                 // Line break
             // Line break
             case 'br':
                 $arrCache[$strTag] = '<br' . ($objPage->outputFormat == 'xhtml' ? ' />' : '>');
                 break;
                 // E-mail addresses
             // E-mail addresses
             case 'email':
             case 'email_open':
             case 'email_url':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $strEmail = \String::encodeEmail($elements[1]);
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'email':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" class="email">' . preg_replace('/\\?.*$/', '', $strEmail) . '</a>';
                         break;
                     case 'email_open':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $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;
                 }
                 \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 = deserialize($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] = specialchars($arrCache[$strTag]);
                 }
                 break;
                 // Link
             // Link
             case 'link':
             case 'link_open':
             case 'link_url':
             case 'link_title':
                 $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 = $this->replaceInsertTags($objNextPage->url);
                             // see #6765
                             if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
                                 $strUrl = \String::encodeEmail($strUrl);
                             }
                             break;
                         case 'forward':
                             if ($objNextPage->jumpTo) {
                                 $objNext = $objNextPage->getRelated('jumpTo');
                             } else {
                                 $objNext = \PageModel::findFirstPublishedRegularByPid($objNextPage->id);
                             }
                             if ($objNext !== null) {
                                 $strForceLang = null;
                                 $objNext->loadDetails();
                                 // Check the target page language (see #4706)
                                 if (\Config::get('addLanguageToUrl')) {
                                     $strForceLang = $objNext->language;
                                 }
                                 $strUrl = $this->generateFrontendUrl($objNext->row(), null, $strForceLang, true);
                                 break;
                             }
                             // DO NOT ADD A break; STATEMENT
                         // DO NOT ADD A break; STATEMENT
                         default:
                             $strForceLang = null;
                             $objNextPage->loadDetails();
                             // Check the target page language (see #4706, #5465)
                             if (\Config::get('addLanguageToUrl')) {
                                 $strForceLang = $objNextPage->language;
                             }
                             $strUrl = $this->generateFrontendUrl($objNextPage->row(), null, $strForceLang, true);
                             break;
                     }
                     $strName = $objNextPage->title;
                     $strTarget = $objNextPage->target ? $objPage->outputFormat == 'xhtml' ? LINK_NEW_WINDOW : ' 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, specialchars($strTitle), $strTarget, specialchars($strName));
                         break;
                     case 'link_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>', $strUrl, specialchars($strTitle), $strTarget);
                         break;
                     case 'link_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'link_title':
                         $arrCache[$strTag] = specialchars($strTitle);
                         break;
                     case 'link_target':
                         $arrCache[$strTag] = $strTarget;
                         break;
                 }
                 break;
                 // Closing link tag
             // Closing link tag
             case 'link_close':
                 $arrCache[$strTag] = '</a>';
                 break;
                 // Insert article
             // Insert article
             case 'insert_article':
                 if (($strOutput = $this->getArticle($elements[1], false, true)) !== false) {
                     $arrCache[$strTag] = $this->replaceInsertTags(ltrim($strOutput), $blnCache);
                 } 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->replaceInsertTags($this->getContentElement($elements[1]), $blnCache);
                 break;
                 // Insert module
             // Insert module
             case 'insert_module':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getFrontendModule($elements[1]), $blnCache);
                 break;
                 // Insert form
             // Insert form
             case 'insert_form':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getForm($elements[1]), $blnCache);
                 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')) === null) {
                     break;
                 }
                 $strUrl = $this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && strlen($objArticle->alias) ? $objArticle->alias : $objArticle->id));
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'article':
                         $strLink = specialchars($objArticle->title);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'article_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objArticle->title));
                         break;
                     case 'article_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'article_title':
                         $arrCache[$strTag] = specialchars($objArticle->title);
                         break;
                 }
                 break;
                 // FAQ
             // FAQ
             case 'faq':
             case 'faq_open':
             case 'faq_url':
             case 'faq_title':
                 if (($objFaq = \FaqModel::findByIdOrAlias($elements[1])) === null || ($objPid = $objFaq->getRelated('pid')) === null || ($objJumpTo = $objPid->getRelated('jumpTo')) === null) {
                     break;
                 }
                 $strUrl = $this->generateFrontendUrl($objJumpTo->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objFaq->alias != '' ? $objFaq->alias : $objFaq->id));
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'faq':
                         $strLink = specialchars($objFaq->question);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'faq_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objFaq->question));
                         break;
                     case 'faq_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'faq_title':
                         $arrCache[$strTag] = specialchars($objFaq->question);
                         break;
                 }
                 break;
                 // News
             // News
             case 'news':
             case 'news_open':
             case 'news_url':
             case 'news_title':
                 if (($objNews = \NewsModel::findByIdOrAlias($elements[1])) === null) {
                     break;
                 }
                 $strUrl = '';
                 if ($objNews->source == 'external') {
                     $strUrl = $objNews->url;
                 } elseif ($objNews->source == 'internal') {
                     if (($objJumpTo = $objNews->getRelated('jumpTo')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objJumpTo->row());
                     }
                 } elseif ($objNews->source == 'article') {
                     if (($objArticle = \ArticleModel::findByPk($objNews->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
                     }
                 } else {
                     if (($objArchive = $objNews->getRelated('pid')) !== null && ($objJumpTo = $objArchive->getRelated('jumpTo')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objJumpTo->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objNews->alias != '' ? $objNews->alias : $objNews->id));
                     }
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'news':
                         $strLink = specialchars($objNews->headline);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'news_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objNews->headline));
                         break;
                     case 'news_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'news_title':
                         $arrCache[$strTag] = specialchars($objNews->headline);
                         break;
                 }
                 break;
                 // Events
             // Events
             case 'event':
             case 'event_open':
             case 'event_url':
             case 'event_title':
                 if (($objEvent = \CalendarEventsModel::findByIdOrAlias($elements[1])) === null) {
                     break;
                 }
                 $strUrl = '';
                 if ($objEvent->source == 'external') {
                     $strUrl = $objEvent->url;
                 } elseif ($objEvent->source == 'internal') {
                     if (($objJumpTo = $objEvent->getRelated('jumpTo')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objJumpTo->row());
                     }
                 } elseif ($objEvent->source == 'article') {
                     if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
                     }
                 } else {
                     if (($objCalendar = $objEvent->getRelated('pid')) !== null && ($objJumpTo = $objCalendar->getRelated('jumpTo')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objJumpTo->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/events/') . (!\Config::get('disableAlias') && $objEvent->alias != '' ? $objEvent->alias : $objEvent->id));
                     }
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'event':
                         $strLink = specialchars($objEvent->title);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'event_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objEvent->title));
                         break;
                     case 'event_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'event_title':
                         $arrCache[$strTag] = specialchars($objEvent->title);
                         break;
                 }
                 break;
                 // Article teaser
             // Article teaser
             case 'article_teaser':
                 $objTeaser = \ArticleModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \String::toXhtml($this->replaceInsertTags($objTeaser->teaser), $blnCache);
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($this->replaceInsertTags($objTeaser->teaser), $blnCache);
                     }
                 }
                 break;
                 // News teaser
             // News teaser
             case 'news_teaser':
                 $objTeaser = \NewsModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \String::toXhtml($objTeaser->teaser);
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($objTeaser->teaser);
                     }
                 }
                 break;
                 // Event teaser
             // Event teaser
             case 'event_teaser':
                 $objTeaser = \CalendarEventsModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \String::toXhtml($objTeaser->teaser);
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($objTeaser->teaser);
                     }
                 }
                 break;
                 // News feed URL
             // News feed URL
             case 'news_feed':
                 $objFeed = \NewsFeedModel::findByPk($elements[1]);
                 if ($objFeed !== null) {
                     $arrCache[$strTag] = $objFeed->feedBase . 'share/' . $objFeed->alias . '.xml';
                 }
                 break;
                 // Calendar feed URL
             // Calendar feed URL
             case 'calendar_feed':
                 $objFeed = \CalendarFeedModel::findByPk($elements[1]);
                 if ($objFeed !== null) {
                     $arrCache[$strTag] = $objFeed->feedBase . 'share/' . $objFeed->alias . '.xml';
                 }
                 break;
                 // Last update
             // Last update
             case 'last_update':
                 $strQuery = "SELECT MAX(tstamp) AS tc";
                 if (in_array('news', \ModuleLoader::getActive())) {
                     $strQuery .= ", (SELECT MAX(tstamp) FROM tl_news) AS tn";
                 }
                 if (in_array('calendar', \ModuleLoader::getActive())) {
                     $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 ? '?' : '&amp;';
                 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="' . 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="' . 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 += 3) {
                         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 = trimsplit(',', $elements[1]);
                     if (in_array($objPage->language, $langs)) {
                         for (; $_rit < $_cnt; $_rit += 3) {
                             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;
                 }
                 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 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;
                 // Acronyms
             // Acronyms
             case 'acronym':
                 if ($objPage->outputFormat == 'xhtml') {
                     if ($elements[1] != '') {
                         $arrCache[$strTag] = '<acronym title="' . $elements[1] . '">';
                     } else {
                         $arrCache[$strTag] = '</acronym>';
                     }
                     break;
                 }
                 // NO break;
                 // Abbreviations
             // NO break;
             // Abbreviations
             case 'abbr':
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = '<abbr title="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = '</abbr>';
                 }
                 break;
                 // Images
             // Images
             case 'image':
                 $width = null;
                 $height = null;
                 $alt = '';
                 $class = '';
                 $rel = '';
                 $strFile = $elements[1];
                 $mode = '';
                 // Take arguments
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]), 2);
                     $strSource = \String::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 = specialchars($value);
                                 break;
                             case 'class':
                                 $class = $value;
                                 break;
                             case 'rel':
                                 $rel = $value;
                                 break;
                             case 'mode':
                                 $mode = $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 {
                     // Sanitize the path
                     $strFile = str_replace('../', '', $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 {
                     $src = \Image::get($strFile, $width, $height, $mode);
                     $dimensions = '';
                     // Add the image dimensions
                     if (($imgSize = @getimagesize(TL_ROOT . '/' . rawurldecode($src))) !== false) {
                         $dimensions = $imgSize[3];
                     }
                     // Generate the HTML markup
                     if ($rel != '') {
                         if (strncmp($rel, 'lightbox', 8) !== 0 || $objPage->outputFormat == 'xhtml') {
                             $attribute = ' rel="' . $rel . '"';
                         } else {
                             $attribute = ' data-lightbox="' . substr($rel, 8) . '"';
                         }
                         $arrCache[$strTag] = '<a href="' . TL_FILES_URL . $strFile . '"' . ($alt != '' ? ' title="' . $alt . '"' : '') . $attribute . '><img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . ($objPage->outputFormat == 'xhtml' ? ' />' : '>') . '</a>';
                     } else {
                         $arrCache[$strTag] = '<img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . ($objPage->outputFormat == 'xhtml' ? ' />' : '>');
                     }
                 } 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 = \String::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];
                 }
                 // Sanitize path
                 $strFile = str_replace('../', '', $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_contents();
                     ob_end_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 'base64_encode':
                     case 'base64_decode':
                     case 'urlencode':
                     case 'rawurlencode':
                         $arrCache[$strTag] = $flag($arrCache[$strTag]);
                         break;
                     case 'encodeEmail':
                     case 'decodeEntities':
                         $arrCache[$strTag] = \String::$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;
                         // 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 \String::restoreBasicEntities($strBuffer);
 }
 protected function compile()
 {
     // Read jump to page details
     $objPage = \PageModel::findByIdOrAlias($this->jumpTo);
     // Check if filter should be displayed
     if (!$this->company_filter_disabled) {
         $objTemplateFilter = new FrontendTemplate('company_list_filter');
         // Filter category
         $intFilterCategory = Input::get('filterCategory');
         $strFilterUrl = '';
         if ($intFilterCategory > 0) {
             $strFilterUrl = '&filterCategory=' . $intFilterCategory;
         }
         // Filter search
         $strSearch = Input::get('search');
         $strSearchUrl = 'search=%s';
         $objTemplateFilter->strLink = $strSearch != '' ? Environment::get('base') . $this->addToUrl(sprintf($strSearchUrl, $strSearch) . '&filterCategory=ID', true) : Environment::get('base') . $this->addToUrl('filterCategory=ID', true);
         // Generate letters
         $arrAlphabet = range('A', 'Z');
         $strHtml = '<a href="' . $this->addToUrl($strFilterUrl, TRUE) . '">Alle</a> ';
         for ($i = 0; $i < count($arrAlphabet); $i++) {
             $strHtml .= '<a href="' . $this->addToUrl(sprintf($strSearchUrl, $arrAlphabet[$i]) . $strFilterUrl, TRUE) . '">' . $arrAlphabet[$i] . '</a> ';
         }
         $objTemplateFilter->strFilterName = $strHtml;
         // Get Categories
         $this->loadLanguageFile('tl_company_category');
         $objCategories = CompanyCategoryModel::findBy('pid', $this->company_archiv, array('order' => 'title ASC'));
         $strOptions = '<option value="0">' . $GLOBALS['TL_LANG']['tl_company_category']['category'][0] . '</option>';
         if ($objCategories) {
             while ($objCategories->next()) {
                 $strOptions .= '<option value="' . $objCategories->id . '"' . ($intFilterCategory != $objCategories->id ? '' : ' selected') . '>' . $objCategories->title . '</option>';
             }
         }
         $objTemplateFilter->strCategoryOptions = $strOptions;
         $this->Template->strFilter = $objTemplateFilter->parse();
     } else {
         $strSearch = '';
         $intFilterCategory = 0;
     }
     // Get items to calculate total number of items
     $objCompanies = CompanyModel::findItems($this->company_archiv, $strSearch, $intFilterCategory);
     // Pagination
     $intLimit = 0;
     $intOffset = 0;
     $intTotal = 0;
     // Set limit to maximum number of items
     if ($this->numberOfItems > 0) {
         $intLimit = $this->numberOfItems;
         $intTotal = $this->numberOfItems;
     } elseif ($objCompanies) {
         $intTotal = $objCompanies->count();
     }
     // If per page is set and maximum number of items greater than per page use Pagination
     if ($objCompanies && $this->perPage > 0 && ($intLimit == 0 || $this->numberOfItems > $this->perPage)) {
         // Set limit, page and offset
         $intLimit = $this->perPage;
         $intPage = $this->Input->get('page') ? $this->Input->get('page') : 1;
         $intOffset = ($intPage - 1) * $intLimit;
         // Add pagination menu
         $objPagination = new \Pagination($intTotal, $intLimit);
         $this->Template->strPagination = $objPagination->generate();
     }
     // Order
     $objCompanyArchive = CompanyArchiveModel::findByPk($this->company_archiv);
     switch ($objCompanyArchive->sort_order) {
         case 2:
             $strOrder = 'sorting ASC';
             break;
         case 1:
         default:
             $strOrder = $this->company_random ? 'RAND()' : 'company ASC';
             break;
     }
     $objCompanies = CompanyModel::findItems($this->company_archiv, $strSearch, $intFilterCategory, $intOffset, $intLimit, $strOrder);
     if ($objCompanies) {
         $this->Template->strCompanies = $this->getCompanies($objCompanies, $objPage);
     } else {
         $this->Template->strCompanies = 'Mit den ausgewählten Filterkriterien sind keine Einträge vorhanden.';
     }
 }
 /**
  * Check if current be user has permission to edit the given page type
  *
  * @param $arrRow
  * @param $strTable
  *
  * @return boolean
  */
 private function userHasPermissionToEditPageType($arrRow, $strTable = 'tl_page_i18nl10n')
 {
     return $this->User->isAdmin || in_array($strTable === 'tl_page_i18nl10n' ? \PageModel::findByIdOrAlias($arrRow['pid'])->type : $arrRow['type'], (array) $this->User->alpty);
 }
Example #6
0
 /**
  * Edit the Frontend Template
  */
 public function parseCustomizeFrontendTemplate($strContent, $strTemplate)
 {
     global $objPage;
     $isFullpage = $this->isFullPageEnabled($objPage);
     if ($strTemplate == "mod_article") {
         $sectionHeaderID = 3;
         // TODO: verwaltbar machen!!!
         $sectionFooterID = 4;
         $objArticle = NULL;
         $articleClass = array();
         $articlePattern = '/<div([A-Za-z0-9\\s\\-_=;",:\\.\\(\\)\'#\\/%]{0,})class="mod_article([A-Za-z0-9\\s\\-_]{0,})"([A-Za-z0-9\\s\\-_=;",:\\.\\(\\)\'#\\/%]{0,})>/';
         preg_match_all('/id="([A-Za-z0-9\\-_]{0,})"/', $strContent, $idMatches);
         if (is_array($idMatches) && count($idMatches[0]) > 0) {
             $objArticle = \ArticleModel::findByIdOrAlias($idMatches[1][0]);
         }
         if ($isFullpage) {
             if ($objArticle) {
                 if ($objArticle->enableSectionHeader) {
                     $sectionHeaderID = $objArticle->sectionHeaderModule;
                     $strContent = preg_replace($articlePattern, '<div$1class="mod_article$2"$3><div class="header section-header">{{insert_module::' . $sectionHeaderID . '}}</div>', $strContent);
                 }
                 if ($objArticle->enableSectionFooter) {
                     $sectionFooterID = $objArticle->sectionFooterModule;
                     $strContent = preg_replace('/<\\/div>$/', '<div class="footer section-footer">{{insert_module::' . $sectionFooterID . '}}</div></div>', $strContent);
                 }
                 if ($objArticle->enableOverlay) {
                     $strOverlayContent = '';
                     if ($objArticle->showTitleInOverlay) {
                         $strArticleTitle = $objArticle->title;
                         if (strlen($objArticle->alt_title)) {
                             $strArticleTitle = $objArticle->alt_title;
                         }
                         $strOverlayContent = '<div class="overlay-title"><div class="title-inner">' . $strArticleTitle . '</div></div>';
                     }
                     $strClass = "";
                     if ($objArticle->overlayTransparent) {
                         $strClass = " overlay-trans";
                     }
                     $strOverlayTags = '<div class="show-overlay"></div><div class="overlay article-overlay' . $strClass . ' shown"><div class="close"></div>' . $strOverlayContent . '</div>';
                     $strContent = preg_replace($articlePattern, '<div$1class="mod_article has-overlay$2"$3>', $strContent);
                     $strContent = preg_replace('/<\\/div>$/', $strOverlayTags . '</div>', $strContent);
                 }
                 if ($objArticle->enableFullpageNavigation) {
                     $navNext = "";
                     $navPrev = "";
                     if ($objPage->fullpageDirection == "horizontal") {
                         // TODO NAVI RIGHT UND LEFT!!
                     } else {
                         $navNext = '<div class="navigation-top" onClick="DPS.Fullpage.sectionBack(this);"></div>';
                         $navPrev = '<div class="navigation-bottom" onClick="DPS.Fullpage.sectionForward(this);"></div>';
                     }
                     $navigationTags = '<div class="fullpage-navigation">' . $navNext . $navPrev . '</div>';
                     //						$strContent			= preg_replace($articlePattern, '', $strContent);
                     $strContent = preg_replace('/<\\/div>$/', $navigationTags . '</div>', $strContent);
                 }
             }
             if ($objPage->fullpageDirection == "horizontal") {
                 $articleClass[] = 'slide';
             } else {
                 $articleClass[] = 'section';
             }
             //				$strContent = preg_replace('/<div([A-Za-z0-9\s\-_=;",:\\.\(\)\'#\/%]{0,})class="mod_article([A-Za-z0-9\s\-_]{0,})"([A-Za-z0-9\s\-_=;",:\\.\(\)\'#\/%]{0,})>/', '<div$1class="mod_article$2"$3><div class="article-inner">', $strContent);
             //				$strContent = $strContent . '</div>';
         }
         if ($objArticle) {
             if ($objArticle->enableBackgroundImage && $objArticle->singleSRC != "") {
                 $objFile = \FilesModel::findByUuid($objArticle->singleSRC);
                 if ($objFile === null && !\Validator::isUuid($objArticle->singleSRC)) {
                     $strContent = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>' . $strContent;
                 }
                 if ($objFile && is_file(TL_ROOT . '/' . $objFile->path)) {
                     preg_match_all($articlePattern, $strContent, $arrArticleMatches);
                     if (is_array($arrArticleMatches[0]) && count($arrArticleMatches[0]) > 0) {
                         $bgPosition = str_replace('_', ' ', $objArticle->backgroundImagePosition);
                         if (!$bgPosition) {
                             $bgPosition = "center center";
                         }
                         if (preg_match('/style="/', $arrArticleMatches[0][0])) {
                             $styles = 'background-image:url(\'' . $objFile->path . '\');background-position:' . $bgPosition . ';';
                             $replStyles = '';
                             if (preg_match('/style="/', $arrArticleMatches[1][0])) {
                                 $replStyles = str_replace('style="', 'style="' . $styles, $arrArticleMatches[1][0]);
                             } elseif (preg_match('/style="/', $arrArticleMatches[3][0])) {
                                 $replStyles = str_replace('style="', 'style="' . $styles, $arrArticleMatches[3][0]);
                             }
                             $strContent = preg_replace($articlePattern, '<div' . $replStyles . 'class="mod_article$2"$3>', $strContent);
                         } else {
                             $strContent = preg_replace($articlePattern, '<div$1class="mod_article$2" style="background-image:url(\'' . $objFile->path . '\');background-position:' . $bgPosition . ';"$3>', $strContent);
                         }
                         $strContent = preg_replace($articlePattern, '<div$1class="mod_article has-background-image bg-fixed bg-image bg-cover$2"$3">', $strContent);
                     }
                 }
             }
             if ($objArticle->enableNavigation) {
                 $articleNavigationTag = '<div class="navigation-container">';
                 $objAllArticles = \ArticleModel::findBy(array("pid=?", "inColumn=?", "published=?"), array($objArticle->pid, "main", "1"), array("order" => "sorting"));
                 $nextArticle = false;
                 $prevArticle = false;
                 if ($objAllArticles) {
                     $isActive = false;
                     $setNext = false;
                     while ($objAllArticles->next()) {
                         $objCurrentArticle = $objAllArticles->current();
                         if ($objCurrentArticle->id == $objArticle->id) {
                             $isActive = true;
                         } else {
                             if (!$isActive) {
                                 $prevArticle = $objCurrentArticle;
                             } else {
                                 if (!$setNext) {
                                     $nextArticle = $objCurrentArticle;
                                     $setNext = true;
                                     break;
                                 }
                             }
                         }
                     }
                 }
                 //					if( $objArticle->navNext && $nextArticle )
                 if ($objArticle->navNext) {
                     //						$nextAlias = $nextArticle->alias;
                     $nextAlias = $objArticle->alias;
                     $articleNavigationTag .= '<div class="nav-item nav-next"><a href="javascript:void(0);" data-anker="' . $nextAlias . '" onclick="DPS.Content.scrollTo(this)"></a></div>';
                 }
                 if ($objArticle->navPrev && $prevArticle) {
                     $prevAlias = $prevArticle->alias;
                     $articleNavigationTag .= '<div class="nav-item nav-prev"><a href="javascript:void(0);" data-anker="' . $prevAlias . '" onclick="DPS.Content.scrollTo(this)"></a></div>';
                 }
                 $articleNavigationTag .= '</div>';
                 $strContent = preg_replace('/<\\/div>$/', $articleNavigationTag . '</div>', $strContent);
             }
             $objArticles = \ArticleModel::findPublishedByPidAndColumn($objPage->id, "main");
             if ($objArticles) {
                 $index = 0;
                 while ($objArticles->next()) {
                     if ($objArticle->id == $objArticles->id) {
                         break;
                     }
                     $index++;
                 }
                 if ($index == 1) {
                     $articleClass[] = 'secondArticle';
                 }
                 $articleClass[] = 'article-' . ($index + 1);
                 if ($objArticles->count() > 1) {
                     $strContent = preg_replace($articlePattern, '<div$1class="mod_article$2"$3 data-index="' . $index . '">', $strContent);
                 }
             }
         }
         if (is_array($articleClass) && count($articleClass) > 0) {
             $strContent = preg_replace('/class="mod_article/', 'class="mod_article ' . implode(" ", $articleClass), $strContent);
         }
         $addAroundDivStart = "";
         $addAroundDivEnd = "";
         $articleClasses = deserialize($objArticle->cssID, true);
         if (preg_match('/add-bg/', $articleClasses[1])) {
             $addAroundDivStart = '<div class="background-outer bg-image bg-cover bg-scroll" data-0="background-position:0px 0px;"><div class="background-inner bg-image bg-cover bg-scroll" data-0="background-position:0px 0px;">';
             $addAroundDivEnd = '</div></div>';
         }
         $strContent = preg_replace('/<div([A-Za-z0-9\\s\\-_="\'.,;:\\(\\)\\/#]{0,})class="mod_article([A-Za-z0-9\\s\\-_\\{\\}\\(\\)\']{0,})"([A-Za-z0-9\\s\\-_="\'.,;:\\(\\)\\/#%]{0,})>/', '<div$1class="mod_article$2"$3>' . $addAroundDivStart . '<div class="article-inside">', $strContent);
         $strContent = preg_replace('/<\\/div>$/', '</div></div>' . $addAroundDivEnd, $strContent);
     } elseif ($strTemplate == "ce_image") {
         preg_match_all('/class="ce_image([a-zA-Z0-9\\s\\-_]{0,})"/', $strContent, $classMatches);
         if (is_array($classMatches) && count($classMatches[0]) > 0) {
             if (preg_match("/start-logo/", $classMatches[1][0])) {
                 preg_match_all('/<img([a-zA-Z0-9\\s\\-_=:;"\'\\(\\).\\/,\\%#]{0,})height="([0-9\\s\\-_]{0,4})"/', $strContent, $imgMatches);
                 if (is_array($imgMatches) && count($imgMatches[0]) > 0) {
                     $marginTop = ceil((int) $imgMatches[2][0] / 2);
                     if (preg_match('/margint-top/', $strContent)) {
                         $strContent = preg_replace('/margin-top:(\\s)([0-9\\-]{0,5})px;/', 'margin-top:-' . $marginTop . 'px"', $strContent);
                     } else {
                         $strContent = preg_replace('/<figure class="image_container"/', '<figure class="image_container" style="margin-top:-' . $marginTop . 'px"', $strContent);
                     }
                 }
             }
         }
     } elseif ($strTemplate == "ce_hyperlink") {
         if (preg_match("/link-arrow/", $strContent)) {
             preg_match_all('/href="([0-9]{0,})"/', $strContent, $hrefMatches);
             if (is_array($hrefMatches) && count($hrefMatches[0]) > 0) {
                 $indexID = $hrefMatches[1][0];
                 $strContent = preg_replace('/class="hyperlink_txt/', 'data-index="' . $indexID . '" class="hyperlink_txt', $strContent);
                 $strContent = preg_replace('/href="' . $indexID . '"/', 'href="javascript:void(0);"', $strContent);
             }
             $strContent = preg_replace('/class="hyperlink_txt/', 'class="hyperlink_txt toSlide', $strContent);
         }
     } elseif ($strTemplate == "mod_navigation") {
         preg_match_all('/id="skipNavigation([0-9]{0,})"/', $strContent, $navMatches);
         if (is_array($navMatches[0]) && count($navMatches[0]) > 0) {
             $objModule = \ModuleModel::findByPk($navMatches[1][0]);
             if ($objModule) {
                 if (!$objModule->hideSubtitles) {
                     preg_match_all('/<li([A-Za-z0-9\\s\\-_:;.,\\(\\)#"\'=\\/]{0,})><(a|span)([A-Za-z0-9\\s\\-_:;.,\\/\\(\\)#"\'=]{0,})>([A-Za-z0-9\\s\\-.:;,#+&\\[\\]\\(\\)=ßöäüÖÄÜ?!%$"\']{0,})<\\/(a|span)><\\/li>/', $strContent, $navListMatches);
                     if (is_array($navListMatches[0]) && count($navListMatches[0]) > 0) {
                         foreach ($navListMatches[3] as $index => $strLink) {
                             if ($navListMatches[2][$index] == "span") {
                                 $linkTitle = $navListMatches[4][$index];
                                 $objLinkPage = \PageModel::findBy("title", $linkTitle);
                                 if ($objLinkPage) {
                                     if ($objLinkPage->count() > 1) {
                                         $objLinkPage = \PageModel::findByPk($this->getPageIdFromUrl());
                                     }
                                     $subtitle = '<span class="subtitle">' . ($objLinkPage->subtitlePosition == "after" ? ' ' : '') . trim($objLinkPage->subtitle) . ($objLinkPage->subtitlePosition == "before" ? ' ' : '') . '</span>';
                                     if (strlen(trim($objLinkPage->subtitle))) {
                                         if ($objLinkPage->subtitlePosition == "before") {
                                             $strContent = preg_replace('/' . preg_quote($navListMatches[0][$index], "/") . '/', '<li' . $navListMatches[1][$index] . '><' . $navListMatches[2][$index] . $navListMatches[3][$index] . '>' . $subtitle . $navListMatches[4][$index] . '</' . $navListMatches[5][$index] . '></li>', $strContent);
                                         } elseif ($objLinkPage->subtitlePosition == "after") {
                                             $strContent = preg_replace('/' . preg_quote($navListMatches[0][$index], "/") . '/', '<li' . $navListMatches[1][$index] . '><' . $navListMatches[2][$index] . $navListMatches[3][$index] . '>' . $navListMatches[4][$index] . $subtitle . '</' . $navListMatches[5][$index] . '></li>', $strContent);
                                         }
                                     }
                                 }
                             } else {
                                 preg_match_all('/href="([A-Za-z0-9\\-\\/._#&]{0,})"/', $strLink, $linkMatches);
                                 if (is_array($linkMatches[0]) && count($linkMatches[0]) > 0) {
                                     $linkParts = explode("/", $linkMatches[1][0]);
                                     $linkPart = str_replace('.html', '', array_pop($linkParts));
                                     $objLinkPage = \PageModel::findByIdOrAlias($linkPart);
                                     $subtitle = '<span class="subtitle">' . ($objLinkPage->subtitlePosition == "after" ? ' ' : '') . trim($objLinkPage->subtitle) . ($objLinkPage->subtitlePosition == "before" ? ' ' : '') . '</span>';
                                     if ($objLinkPage) {
                                         if (strlen(trim($objLinkPage->subtitle))) {
                                             if ($objLinkPage->subtitlePosition == "before") {
                                                 $strContent = preg_replace('/' . preg_quote($navListMatches[0][$index], "/") . '/', '<li' . $navListMatches[1][$index] . '><' . $navListMatches[2][$index] . $navListMatches[3][$index] . '>' . $subtitle . $navListMatches[4][$index] . '</' . $navListMatches[5][$index] . '></li>', $strContent);
                                             } elseif ($objLinkPage->subtitlePosition == "after") {
                                                 $strContent = preg_replace('/' . preg_quote($navListMatches[0][$index], "/") . '/', '<li' . $navListMatches[1][$index] . '><' . $navListMatches[2][$index] . $navListMatches[3][$index] . '>' . $navListMatches[4][$index] . $subtitle . '</' . $navListMatches[5][$index] . '></li>', $strContent);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $strContent;
 }