/**
  * Generate the content element
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \String::toXhtml($this->text);
     } else {
         $this->text = \String::toHtml5($this->text);
     }
     $this->Template->text = \String::encodeEmail($this->text);
     $this->Template->addImage = false;
     // Add an image
     if ($this->addImage && $this->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($this->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($this->singleSRC)) {
                 $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             $this->singleSRC = $objModel->path;
             $this->addImageToTemplate($this->Template, $this->arrData);
         }
     }
     $classes = deserialize($this->mooClasses);
     $this->Template->toggler = $classes[0] ?: 'toggler';
     $this->Template->accordion = $classes[1] ?: 'accordion';
     $this->Template->headlineStyle = $this->mooStyle;
     $this->Template->headline = $this->mooHeadline;
 }
Exemple #2
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     global $objPage;
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \String::toXhtml($this->text);
     } else {
         $this->text = \String::toHtml5($this->text);
     }
     // Add the static files URL to images
     if (TL_FILES_URL != '') {
         $path = $GLOBALS['TL_CONFIG']['uploadPath'] . '/';
         $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text);
     }
     $this->Template->text = \String::encodeEmail($this->text);
     $this->Template->addImage = false;
     // Add an image
     if ($this->addImage && $this->singleSRC != '') {
         if (!is_numeric($this->singleSRC)) {
             $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
         } else {
             $objModel = \FilesModel::findByPk($this->singleSRC);
             if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                 $this->singleSRC = $objModel->path;
                 $this->addImageToTemplate($this->Template, $this->arrData);
             }
         }
     }
 }
Exemple #3
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $objFaq = \FaqModel::findPublishedByPids($this->faq_categories);
     if ($objFaq === null) {
         $this->Template->faq = array();
         return;
     }
     global $objPage;
     $arrFaq = array_fill_keys($this->faq_categories, array());
     // Add FAQs
     while ($objFaq->next()) {
         $objTemp = (object) $objFaq->row();
         // Clean RTE output
         if ($objPage->outputFormat == 'xhtml') {
             $objFaq->answer = \String::toXhtml($objFaq->answer);
         } else {
             $objFaq->answer = \String::toHtml5($objFaq->answer);
         }
         $objTemp->answer = \String::encodeEmail($objFaq->answer);
         $objTemp->addImage = false;
         // Add an image
         if ($objFaq->addImage && $objFaq->singleSRC != '') {
             if (!is_numeric($objFaq->singleSRC)) {
                 $objTemp->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             } else {
                 $objModel = \FilesModel::findByPk($objFaq->singleSRC);
                 if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                     $objFaq->singleSRC = $objModel->path;
                     $this->addImageToTemplate($objTemp, $objFaq->row());
                 }
             }
         }
         $objTemp->enclosure = array();
         // Add enclosure
         if ($objFaq->addEnclosure) {
             $this->addEnclosuresToTemplate($objTemp, $objFaq->row());
         }
         $objTemp->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], $this->parseDate($objPage->dateFormat, $objFaq->tstamp), $objFaq->getRelated('author')->name);
         // Order by PID
         $arrFaq[$objFaq->pid]['items'][] = $objTemp;
         $arrFaq[$objFaq->pid]['headline'] = $objFaq->category;
     }
     $arrFaq = array_values(array_filter($arrFaq));
     $limit_i = count($arrFaq) - 1;
     // Add classes first, last, even and odd
     for ($i = 0; $i <= $limit_i; $i++) {
         $class = ($i == 0 ? 'first ' : '') . ($i == $limit_i ? 'last ' : '') . ($i % 2 == 0 ? 'even' : 'odd');
         $arrFaq[$i]['class'] = trim($class);
         $limit_j = count($arrFaq[$i]['items']) - 1;
         for ($j = 0; $j <= $limit_j; $j++) {
             $class = ($j == 0 ? 'first ' : '') . ($j == $limit_j ? 'last ' : '') . ($j % 2 == 0 ? 'even' : 'odd');
             $arrFaq[$i]['items'][$j]->class = trim($class);
         }
     }
     $this->Template->faq = $arrFaq;
     $this->Template->request = $this->getIndexFreeRequest(true);
     $this->Template->topLink = $GLOBALS['TL_LANG']['MSC']['backToTop'];
 }
Exemple #4
0
 /**
  * Generate the widget and return it as string
  * @return string
  */
 public function generate()
 {
     global $objPage;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         return \String::toXhtml($this->text);
     } else {
         return \String::toHtml5($this->text);
     }
 }
Exemple #5
0
 /**
  * Generate the widget and return it as string
  *
  * @return string The widget markup
  */
 public function generate()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \String::toXhtml($this->text);
     } else {
         $this->text = \String::toHtml5($this->text);
     }
     return $this->text;
 }
Exemple #6
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     // Accordion start
     if ($this->mooType == 'mooStart') {
         if (TL_MODE == 'FE') {
             $this->strTemplate = 'ce_accordion_start';
             $this->Template = new \FrontendTemplate($this->strTemplate);
             $this->Template->setData($this->arrData);
         } else {
             $this->strTemplate = 'be_wildcard';
             $this->Template = new \BackendTemplate($this->strTemplate);
             $this->Template->title = $this->mooHeadline;
         }
     } elseif ($this->mooType == 'mooStop') {
         if (TL_MODE == 'FE') {
             $this->strTemplate = 'ce_accordion_stop';
             $this->Template = new \FrontendTemplate($this->strTemplate);
             $this->Template->setData($this->arrData);
         } else {
             $this->strTemplate = 'be_wildcard';
             $this->Template = new \BackendTemplate($this->strTemplate);
         }
     } else {
         global $objPage;
         // Clean RTE output
         if ($objPage->outputFormat == 'xhtml') {
             $this->text = \String::toXhtml($this->text);
         } else {
             $this->text = \String::toHtml5($this->text);
         }
         $this->Template->text = \String::encodeEmail($this->text);
         $this->Template->addImage = false;
         // Add an image
         if ($this->addImage && $this->singleSRC != '') {
             if (!is_numeric($this->singleSRC)) {
                 $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             } else {
                 $objModel = \FilesModel::findByPk($this->singleSRC);
                 if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                     $this->singleSRC = $objModel->path;
                     $this->addImageToTemplate($this->Template, $this->arrData);
                 }
             }
         }
     }
     $classes = deserialize($this->mooClasses);
     $this->Template->toggler = $classes[0] ?: 'toggler';
     $this->Template->accordion = $classes[1] ?: 'accordion';
     $this->Template->headlineStyle = $this->mooStyle;
     $this->Template->headline = $this->mooHeadline;
 }
Exemple #7
0
 /**
  * Generate the widget and return it as string
  *
  * @return string The widget markup
  */
 public function generate()
 {
     global $objPage;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \String::toXhtml($this->text);
     } else {
         $this->text = \String::toHtml5($this->text);
     }
     // Add the static files URL to images
     if (TL_FILES_URL != '') {
         $path = \Config::get('uploadPath') . '/';
         $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text);
     }
     return \String::encodeEmail($this->text);
 }
Exemple #8
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     global $objPage;
     $link = '/articles/';
     $objArticle = $this->objArticle;
     if ($objArticle->inColumn != 'main') {
         $link .= $objArticle->inColumn . ':';
     }
     $link .= $objArticle->alias != '' && !\Config::get('disableAlias') ? $objArticle->alias : $objArticle->id;
     $this->Template->href = $this->generateFrontendUrl($this->objParent->row(), $link);
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->Template->text = \String::toXhtml($objArticle->teaser);
     } else {
         $this->Template->text = \String::toHtml5($objArticle->teaser);
     }
     $this->Template->headline = $objArticle->title;
     $this->Template->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->title));
     $this->Template->more = $GLOBALS['TL_LANG']['MSC']['more'];
 }
Exemple #9
0
 /**
  * Add comments to a template
  * @param \FrontendTemplate
  * @param \stdClass
  * @param string
  * @param integer
  * @param mixed
  */
 public function addCommentsToTemplate(\FrontendTemplate $objTemplate, \stdClass $objConfig, $strSource, $intParent, $varNotifies)
 {
     global $objPage;
     $limit = 0;
     $offset = 0;
     $total = 0;
     $gtotal = 0;
     $arrComments = array();
     $objTemplate->comments = array();
     // see #4064
     // Pagination
     if ($objConfig->perPage > 0) {
         // Get the total number of comments
         $intTotal = \CommentsModel::countPublishedBySourceAndParent($strSource, $intParent);
         $total = $gtotal = $intTotal;
         // Calculate the key (e.g. tl_form_field becomes page_cff12)
         $key = '';
         $chunks = explode('_', substr($strSource, strncmp($strSource, 'tl_', 3) === 0 ? 3 : 0));
         foreach ($chunks as $chunk) {
             $key .= substr($chunk, 0, 1);
         }
         // Get the current page
         $id = 'page_c' . $key . $intParent;
         // see #4141
         $page = \Input::get($id) ?: 1;
         // Do not index or cache the page if the page number is outside the range
         if ($page < 1 || $page > max(ceil($total / $objConfig->perPage), 1)) {
             global $objPage;
             $objPage->noSearch = 1;
             $objPage->cache = 0;
             // Send a 404 header
             header('HTTP/1.1 404 Not Found');
             $objTemplate->allowComments = false;
             return;
         }
         // Set limit and offset
         $limit = $objConfig->perPage;
         $offset = ($page - 1) * $objConfig->perPage;
         // Initialize the pagination menu
         $objPagination = new \Pagination($total, $objConfig->perPage, \Config::get('maxPaginationLinks'), $id);
         $objTemplate->pagination = $objPagination->generate("\n  ");
     }
     $objTemplate->allowComments = true;
     // Get all published comments
     if ($limit) {
         $objComments = \CommentsModel::findPublishedBySourceAndParent($strSource, $intParent, $objConfig->order == 'descending', $limit, $offset);
     } else {
         $objComments = \CommentsModel::findPublishedBySourceAndParent($strSource, $intParent, $objConfig->order == 'descending');
     }
     // Parse the comments
     if ($objComments !== null && ($total = $objComments->count()) > 0) {
         $count = 0;
         if ($objConfig->template == '') {
             $objConfig->template = 'com_default';
         }
         $objPartial = new \FrontendTemplate($objConfig->template);
         while ($objComments->next()) {
             $objPartial->setData($objComments->row());
             // Clean the RTE output
             if ($objPage->outputFormat == 'xhtml') {
                 $objPartial->comment = \String::toXhtml($objComments->comment);
             } else {
                 $objPartial->comment = \String::toHtml5($objComments->comment);
             }
             $objPartial->comment = trim(str_replace(array('{{', '}}'), array('&#123;&#123;', '&#125;&#125;'), $objPartial->comment));
             $objPartial->datim = \Date::parse($objPage->datimFormat, $objComments->date);
             $objPartial->date = \Date::parse($objPage->dateFormat, $objComments->date);
             $objPartial->class = ($count < 1 ? ' first' : '') . ($count >= $total - 1 ? ' last' : '') . ($count % 2 == 0 ? ' even' : ' odd');
             $objPartial->by = $GLOBALS['TL_LANG']['MSC']['com_by'];
             $objPartial->id = 'c' . $objComments->id;
             $objPartial->timestamp = $objComments->date;
             $objPartial->datetime = date('Y-m-d\\TH:i:sP', $objComments->date);
             $objPartial->addReply = false;
             // Reply
             if ($objComments->addReply && $objComments->reply != '') {
                 if (($objAuthor = $objComments->getRelated('author')) !== null) {
                     $objPartial->addReply = true;
                     $objPartial->rby = $GLOBALS['TL_LANG']['MSC']['com_reply'];
                     $objPartial->reply = $this->replaceInsertTags($objComments->reply);
                     $objPartial->author = $objAuthor;
                     // Clean the RTE output
                     if ($objPage->outputFormat == 'xhtml') {
                         $objPartial->reply = \String::toXhtml($objPartial->reply);
                     } else {
                         $objPartial->reply = \String::toHtml5($objPartial->reply);
                     }
                 }
             }
             $arrComments[] = $objPartial->parse();
             ++$count;
         }
     }
     $objTemplate->comments = $arrComments;
     $objTemplate->addComment = $GLOBALS['TL_LANG']['MSC']['addComment'];
     $objTemplate->name = $GLOBALS['TL_LANG']['MSC']['com_name'];
     $objTemplate->email = $GLOBALS['TL_LANG']['MSC']['com_email'];
     $objTemplate->website = $GLOBALS['TL_LANG']['MSC']['com_website'];
     $objTemplate->commentsTotal = $limit ? $gtotal : $total;
     // Add a form to create new comments
     $this->renderCommentForm($objTemplate, $objConfig, $strSource, $intParent, $varNotifies);
 }
Exemple #10
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);
 }
Exemple #11
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     global $objPage;
     $this->Template->event = '';
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     // Get the current event
     $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias(\Input::get('events'), $this->cal_calendar);
     if ($objEvent === null) {
         // Do not index or cache the page
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         // Send a 404 header
         header('HTTP/1.1 404 Not Found');
         $this->Template->event = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('events')) . '</p>';
         return;
     }
     // Overwrite the page title
     if ($objEvent->title != '') {
         $objPage->pageTitle = strip_insert_tags($objEvent->title);
     }
     // Overwrite the page description
     if ($objEvent->teaser != '') {
         $objPage->description = $this->prepareMetaDescription($objEvent->teaser);
     }
     $span = \Calendar::calculateSpan($objEvent->startTime, $objEvent->endTime);
     if ($objPage->outputFormat == 'xhtml') {
         $strTimeStart = '';
         $strTimeEnd = '';
         $strTimeClose = '';
     } else {
         $strTimeStart = '<time datetime="' . date('Y-m-d\\TH:i:sP', $objEvent->startTime) . '">';
         $strTimeEnd = '<time datetime="' . date('Y-m-d\\TH:i:sP', $objEvent->endTime) . '">';
         $strTimeClose = '</time>';
     }
     // Get date
     if ($span > 0) {
         $date = $strTimeStart . $this->parseDate($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $objEvent->startTime) . $strTimeClose . ' - ' . $strTimeEnd . $this->parseDate($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $objEvent->endTime) . $strTimeClose;
     } elseif ($objEvent->startTime == $objEvent->endTime) {
         $date = $strTimeStart . $this->parseDate($objPage->dateFormat, $objEvent->startTime) . ($objEvent->addTime ? ' (' . $this->parseDate($objPage->timeFormat, $objEvent->startTime) . ')' : '') . $strTimeClose;
     } else {
         $date = $strTimeStart . $this->parseDate($objPage->dateFormat, $objEvent->startTime) . ($objEvent->addTime ? ' (' . $this->parseDate($objPage->timeFormat, $objEvent->startTime) . $strTimeClose . ' - ' . $strTimeEnd . $this->parseDate($objPage->timeFormat, $objEvent->endTime) . ')' : '') . $strTimeClose;
     }
     $until = '';
     $recurring = '';
     // Recurring event
     if ($objEvent->recurring) {
         $arrRange = deserialize($objEvent->repeatEach);
         $strKey = 'cal_' . $arrRange['unit'];
         $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']);
         if ($objEvent->recurrences > 0) {
             $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], $this->parseDate($objPage->dateFormat, $objEvent->repeatEnd));
         }
     }
     // Override the default image size
     if ($this->imgSize != '') {
         $size = deserialize($this->imgSize);
         if ($size[0] > 0 || $size[1] > 0) {
             $objEvent->size = $this->imgSize;
         }
     }
     $objTemplate = new \FrontendTemplate($this->cal_template);
     $objTemplate->setData($objEvent->row());
     $objTemplate->date = $date;
     $objTemplate->start = $objEvent->startTime;
     $objTemplate->end = $objEvent->endTime;
     $objTemplate->class = $objEvent->cssClass != '' ? ' ' . $objEvent->cssClass : '';
     $objTemplate->recurring = $recurring;
     $objTemplate->until = $until;
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $objEvent->details = \String::toXhtml($objEvent->details);
     } else {
         $objEvent->details = \String::toHtml5($objEvent->details);
     }
     $objTemplate->details = \String::encodeEmail($objEvent->details);
     $objTemplate->addImage = false;
     // Add an image
     if ($objEvent->addImage && $objEvent->singleSRC != '') {
         if (!is_numeric($objEvent->singleSRC)) {
             $objTemplate->details = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
         } else {
             $objModel = \FilesModel::findByPk($objEvent->singleSRC);
             if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                 $objEvent->singleSRC = $objModel->path;
                 $this->addImageToTemplate($objTemplate, $objEvent->row());
             }
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures
     if ($objEvent->addEnclosure) {
         $this->addEnclosuresToTemplate($objTemplate, $objEvent->row());
     }
     $this->Template->event = $objTemplate->parse();
     // HOOK: comments extension required
     if ($objEvent->noComments || !in_array('comments', $this->Config->getActiveModules())) {
         $this->Template->allowComments = false;
         return;
     }
     $objCalendar = $objEvent->getRelated('pid');
     $this->Template->allowComments = $objCalendar->allowComments;
     // Adjust the comments headline level
     $intHl = min(intval(str_replace('h', '', $this->hl)), 5);
     $this->Template->hlc = 'h' . ($intHl + 1);
     $this->import('Comments');
     $arrNotifies = array();
     // Notify the system administrator
     if ($objCalendar->notify != 'notify_author') {
         $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
     }
     // Notify the author
     if ($objCalendar->notify != 'notify_admin') {
         if (($objAuthor = $objEvent->getRelated('author')) !== null && $objAuthor->email != '') {
             $arrNotifies[] = $objAuthor->email;
         }
     }
     $objConfig = new \stdClass();
     $objConfig->perPage = $objCalendar->perPage;
     $objConfig->order = $objCalendar->sortOrder;
     $objConfig->template = $this->com_template;
     $objConfig->requireLogin = $objCalendar->requireLogin;
     $objConfig->disableCaptcha = $objCalendar->disableCaptcha;
     $objConfig->bbcode = $objCalendar->bbcode;
     $objConfig->moderate = $objCalendar->moderate;
     $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_calendar_events', $objEvent->id, $arrNotifies);
 }
Exemple #12
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
  */
 public function replace($strBuffer, $blnCache = true)
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Preserve insert tags
     if (\Config::get('disableInsertTags')) {
         return \String::restoreBasicEntities($strBuffer);
     }
     $tags = preg_split('/\\{\\{(([^\\{\\}]*|(?R))*)\\}\\}/', $strBuffer, -1, PREG_SPLIT_DELIM_CAPTURE);
     $strBuffer = '';
     // Create one cache per cache setting (see #7700)
     static $arrItCache;
     $arrCache =& $arrItCache[$blnCache];
     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->replace($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 . '" 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 = 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] = 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 = $this->replaceInsertTags($objNextPage->url);
                             // see #6765
                             if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
                                 $strUrl = \String::encodeEmail($strUrl);
                             }
                             break;
                         case 'forward':
                             if ($objNextPage->jumpTo) {
                                 /** @var \PageModel $objNext */
                                 $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;
                     case 'link_name':
                         $arrCache[$strTag] = specialchars($strName);
                         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($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     }
                 }
                 break;
                 // Event teaser
             // Event teaser
             case 'event_teaser':
                 $objTeaser = \CalendarEventsModel::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 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':
             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 = \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;
                             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), true);
                         // 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 . '"' : '') . ($objPage->outputFormat == 'xhtml' ? ' />' : '>');
                     } 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 || $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 . '>' . $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 = \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];
                 }
                 // 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_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 '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);
 }
Exemple #13
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     if ($this->blnNoMarkup) {
         /** @var \FrontendTemplate|object $objTemplate */
         $objTemplate = new \BackendTemplate('mod_article_plain');
         $this->Template = $objTemplate;
         $this->Template->setData($this->arrData);
     }
     $alias = $this->alias ?: 'article';
     if (in_array($alias, array('article', 'top', 'wrapper', 'header', 'container', 'left', 'main', 'right', 'footer'))) {
         $alias .= '-' . $this->id;
     }
     $alias = standardize($alias);
     // Generate the cssID if it is not set
     if ($this->cssID[0] == '') {
         $this->cssID = array($alias, $this->cssID[1]);
     }
     $this->Template->column = $this->inColumn;
     // Add the modification date
     $this->Template->timestamp = $this->tstamp;
     $this->Template->date = \Date::parse($objPage->datimFormat, $this->tstamp);
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->teaser = \String::toXhtml($this->teaser);
     } else {
         $this->teaser = \String::toHtml5($this->teaser);
     }
     // Show the teaser only
     if ($this->multiMode && $this->showTeaser) {
         /** @var \FrontendTemplate|object $objTemplate */
         $objTemplate = new \BackendTemplate('mod_article_teaser');
         $this->Template = $objTemplate;
         $this->Template->setData($this->arrData);
         $this->cssID = array($alias, '');
         $arrCss = deserialize($this->teaserCssID);
         // Override the CSS ID and class
         if (is_array($arrCss) && count($arrCss) == 2) {
             if ($arrCss[0] == '') {
                 $arrCss[0] = $alias;
             }
             $this->cssID = $arrCss;
         }
         $article = !\Config::get('disableAlias') && $this->alias != '' ? $this->alias : $this->id;
         $href = '/articles/' . ($this->inColumn != 'main' ? $this->inColumn . ':' : '') . $article;
         $this->Template->headline = $this->headline;
         $this->Template->href = $this->generateFrontendUrl($objPage->row(), $href);
         $this->Template->teaser = $this->teaser;
         $this->Template->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $this->headline), true);
         $this->Template->more = $GLOBALS['TL_LANG']['MSC']['more'];
         return;
     }
     // Get section and article alias
     list($strSection, $strArticle) = explode(':', \Input::get('articles'));
     if ($strArticle === null) {
         $strArticle = $strSection;
     }
     // Overwrite the page title (see #2853 and #4955)
     if (!$this->blnNoMarkup && $strArticle != '' && ($strArticle == $this->id || $strArticle == $this->alias) && $this->title != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($this->title));
         if ($this->teaser != '') {
             $objPage->description = $this->prepareMetaDescription($this->teaser);
         }
     }
     $this->Template->printable = false;
     $this->Template->backlink = false;
     // Back link
     if (!$this->multiMode && $strArticle != '' && ($strArticle == $this->id || $strArticle == $this->alias)) {
         $this->Template->backlink = 'javascript:history.go(-1)';
         // see #6955
         $this->Template->back = specialchars($GLOBALS['TL_LANG']['MSC']['goBack']);
     }
     $arrElements = array();
     $objCte = \ContentModel::findPublishedByPidAndTable($this->id, 'tl_article');
     if ($objCte !== null) {
         $intCount = 0;
         $intLast = $objCte->count() - 1;
         while ($objCte->next()) {
             $arrCss = array();
             /** @var \ContentModel $objRow */
             $objRow = $objCte->current();
             // Add the "first" and "last" classes (see #2583)
             if ($intCount == 0 || $intCount == $intLast) {
                 if ($intCount == 0) {
                     $arrCss[] = 'first';
                 }
                 if ($intCount == $intLast) {
                     $arrCss[] = 'last';
                 }
             }
             $objRow->classes = $arrCss;
             $arrElements[] = $this->getContentElement($objRow, $this->strColumn);
             ++$intCount;
         }
     }
     $this->Template->teaser = $this->teaser;
     $this->Template->elements = $arrElements;
     if ($this->keywords != '') {
         $GLOBALS['TL_KEYWORDS'] .= ($GLOBALS['TL_KEYWORDS'] != '' ? ', ' : '') . $this->keywords;
     }
     // Backwards compatibility
     if ($this->printable == 1) {
         $this->Template->printable = true;
         $this->Template->pdfButton = true;
     } elseif ($this->printable != '') {
         $options = deserialize($this->printable);
         if (!empty($options) && is_array($options)) {
             $this->Template->printable = true;
             $this->Template->printButton = in_array('print', $options);
             $this->Template->pdfButton = in_array('pdf', $options);
             $this->Template->facebookButton = in_array('facebook', $options);
             $this->Template->twitterButton = in_array('twitter', $options);
             $this->Template->gplusButton = in_array('gplus', $options);
         }
     }
     // Add syndication variables
     if ($this->Template->printable) {
         $request = \Environment::get('indexFreeRequest');
         $this->Template->print = '#';
         $this->Template->encUrl = rawurlencode(\Environment::get('base') . \Environment::get('request'));
         $this->Template->encTitle = rawurlencode($objPage->pageTitle);
         $this->Template->href = $request . (strpos($request, '?') !== false ? '&amp;' : '?') . 'pdf=' . $this->id;
         $this->Template->printTitle = specialchars($GLOBALS['TL_LANG']['MSC']['printPage']);
         $this->Template->pdfTitle = specialchars($GLOBALS['TL_LANG']['MSC']['printAsPdf']);
         $this->Template->facebookTitle = specialchars($GLOBALS['TL_LANG']['MSC']['facebookShare']);
         $this->Template->twitterTitle = specialchars($GLOBALS['TL_LANG']['MSC']['twitterShare']);
         $this->Template->gplusTitle = specialchars($GLOBALS['TL_LANG']['MSC']['gplusShare']);
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['compileArticle']) && is_array($GLOBALS['TL_HOOKS']['compileArticle'])) {
         foreach ($GLOBALS['TL_HOOKS']['compileArticle'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($this->Template, $this->arrData, $this);
         }
     }
 }
Exemple #14
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     global $objPage;
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     $this->Template->referer = 'javascript:history.go(-1)';
     $objFaq = \FaqModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->faq_categories);
     if ($objFaq === null) {
         // Do not index or cache the page
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         // Send a 404 header
         header('HTTP/1.1 404 Not Found');
         $this->Template->error = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('items')) . '</p>';
         return;
     }
     // Overwrite the page title and description
     if ($objFaq->question != '') {
         $objPage->pageTitle = strip_insert_tags($objFaq->question);
         $objPage->description = $this->prepareMetaDescription($objFaq->question);
     }
     $this->Template->question = $objFaq->question;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $objFaq->answer = \String::toXhtml($objFaq->answer);
     } else {
         $objFaq->answer = \String::toHtml5($objFaq->answer);
     }
     $this->Template->answer = \String::encodeEmail($objFaq->answer);
     $this->Template->addImage = false;
     // Add image
     if ($objFaq->addImage && $objFaq->singleSRC != '') {
         if (!is_numeric($objFaq->singleSRC)) {
             $this->Template->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
         } else {
             $objModel = \FilesModel::findByPk($objFaq->singleSRC);
             if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                 $objFaq->singleSRC = $objModel->path;
                 $this->addImageToTemplate($this->Template, $objFaq->row());
             }
         }
     }
     $this->Template->enclosure = array();
     // Add enclosure
     if ($objFaq->addEnclosure) {
         $this->addEnclosuresToTemplate($this->Template, $objFaq->row());
     }
     $this->Template->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], $this->parseDate($objPage->dateFormat, $objFaq->tstamp), $objFaq->getRelated('author')->name);
     // HOOK: comments extension required
     if ($objFaq->noComments || !in_array('comments', $this->Config->getActiveModules())) {
         $this->Template->allowComments = false;
         return;
     }
     $objCategory = $objFaq->getRelated('pid');
     // Check whether comments are allowed
     if (!$objCategory->allowComments) {
         $this->Template->allowComments = false;
         return;
     }
     $this->Template->allowComments = true;
     // Adjust the comments headline level
     $intHl = min(intval(str_replace('h', '', $this->hl)), 5);
     $this->Template->hlc = 'h' . ($intHl + 1);
     $this->import('Comments');
     $arrNotifies = array();
     // Notify the system administrator
     if ($objCategory->notify != 'notify_author') {
         $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
     }
     // Notify the author
     if ($objCategory->notify != 'notify_admin') {
         if (($objAuthor = $objFaq->getRelated('author')) !== null && $objAuthor->email != '') {
             $arrNotifies[] = $objAuthor->email;
         }
     }
     $objConfig = new \stdClass();
     $objConfig->perPage = $objCategory->perPage;
     $objConfig->order = $objCategory->sortOrder;
     $objConfig->template = $this->com_template;
     $objConfig->requireLogin = $objCategory->requireLogin;
     $objConfig->disableCaptcha = $objCategory->disableCaptcha;
     $objConfig->bbcode = $objCategory->bbcode;
     $objConfig->moderate = $objCategory->moderate;
     $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_faq', $objFaq->id, $arrNotifies);
 }
Exemple #15
0
 /**
  * Add an event to the array of active events
  * @param object
  * @param integer
  * @param integer
  * @param string
  * @param integer
  * @param integer
  * @param integer
  */
 protected function addEvent($objEvents, $intStart, $intEnd, $strUrl, $intBegin, $intLimit, $intCalendar)
 {
     global $objPage;
     $intDate = $intStart;
     $intKey = date('Ymd', $intStart);
     $span = \Calendar::calculateSpan($intStart, $intEnd);
     $strDate = $this->parseDate($objPage->dateFormat, $intStart);
     $strDay = $GLOBALS['TL_LANG']['DAYS'][date('w', $intStart)];
     $strMonth = $GLOBALS['TL_LANG']['MONTHS'][date('n', $intStart) - 1];
     if ($span > 0) {
         $strDate = $this->parseDate($objPage->dateFormat, $intStart) . ' - ' . $this->parseDate($objPage->dateFormat, $intEnd);
         $strDay = '';
     }
     $strTime = '';
     if ($objEvents->addTime) {
         if ($span > 0) {
             $strDate = $this->parseDate($objPage->datimFormat, $intStart) . ' - ' . $this->parseDate($objPage->datimFormat, $intEnd);
         } elseif ($intStart == $intEnd) {
             $strTime = $this->parseDate($objPage->timeFormat, $intStart);
         } else {
             $strTime = $this->parseDate($objPage->timeFormat, $intStart) . ' - ' . $this->parseDate($objPage->timeFormat, $intEnd);
         }
     }
     // Store raw data
     $arrEvent = $objEvents->row();
     // Overwrite some settings
     $arrEvent['time'] = $strTime;
     $arrEvent['date'] = $strDate;
     $arrEvent['day'] = $strDay;
     $arrEvent['month'] = $strMonth;
     $arrEvent['parent'] = $intCalendar;
     $arrEvent['link'] = $objEvents->title;
     $arrEvent['target'] = '';
     $arrEvent['title'] = specialchars($objEvents->title, true);
     $arrEvent['href'] = $this->generateEventUrl($objEvents, $strUrl);
     $arrEvent['class'] = $objEvents->cssClass != '' ? ' ' . $objEvents->cssClass : '';
     $arrEvent['details'] = \String::encodeEmail($objEvents->details);
     $arrEvent['start'] = $intStart;
     $arrEvent['end'] = $intEnd;
     // Override the link target
     if ($objEvents->source == 'external' && $objEvents->target) {
         $arrEvent['target'] = $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"';
     }
     // Clean the RTE output
     if ($arrEvent['teaser'] != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $arrEvent['teaser'] = \String::toXhtml($arrEvent['teaser']);
         } else {
             $arrEvent['teaser'] = \String::toHtml5($arrEvent['teaser']);
         }
     }
     // Display the "read more" button for external/article links
     if (($objEvents->source == 'external' || $objEvents->source == 'article') && $objEvents->details == '') {
         $arrEvent['details'] = true;
     } else {
         if ($objPage->outputFormat == 'xhtml') {
             $arrEvent['details'] = \String::toXhtml($arrEvent['details']);
         } else {
             $arrEvent['details'] = \String::toHtml5($arrEvent['details']);
         }
     }
     // Get todays start and end timestamp
     if ($this->intTodayBegin === null) {
         $this->intTodayBegin = strtotime('00:00:00');
     }
     if ($this->intTodayEnd === null) {
         $this->intTodayEnd = strtotime('23:59:59');
     }
     // Mark past and upcoming events (see #3692)
     if ($intEnd < $this->intTodayBegin) {
         $arrEvent['class'] .= ' bygone';
     } elseif ($intStart > $this->intTodayEnd) {
         $arrEvent['class'] .= ' upcoming';
     } else {
         $arrEvent['class'] .= ' current';
     }
     $this->arrEvents[$intKey][$intStart][] = $arrEvent;
     // Multi-day event
     for ($i = 1; $i <= $span && $intDate <= $intLimit; $i++) {
         // Only show first occurrence
         if ($this->cal_noSpan && $intDate >= $intBegin) {
             break;
         }
         $intDate = strtotime('+ 1 day', $intDate);
         $intNextKey = date('Ymd', $intDate);
         $this->arrEvents[$intNextKey][$intDate][] = $arrEvent;
     }
 }
Exemple #16
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     global $objPage;
     if ($this->blnNoMarkup) {
         $this->Template = new \FrontendTemplate('mod_article_plain');
         $this->Template->setData($this->arrData);
     }
     $alias = $this->alias ?: $this->title;
     if (in_array($alias, array('header', 'container', 'left', 'main', 'right', 'footer'))) {
         $alias .= '-' . $this->id;
     }
     $alias = standardize($alias);
     // Generate the cssID if it is not set
     if ($this->cssID[0] == '') {
         $this->cssID = array($alias, $this->cssID[1]);
     }
     $this->Template->column = $this->inColumn;
     // Add the modification date
     $this->Template->timestamp = $this->tstamp;
     $this->Template->date = $this->parseDate($objPage->datimFormat, $this->tstamp);
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->teaser = \String::toXhtml($this->teaser);
     } else {
         $this->teaser = \String::toHtml5($this->teaser);
     }
     // Show the teaser only
     if ($this->multiMode && $this->showTeaser) {
         $this->Template = new \FrontendTemplate('mod_article_teaser');
         $this->Template->setData($this->arrData);
         $this->cssID = array($alias, '');
         $arrCss = deserialize($this->teaserCssID);
         // Override the CSS ID and class
         if (is_array($arrCss) && count($arrCss) == 2) {
             if ($arrCss[0] == '') {
                 $arrCss[0] = $alias;
             }
             $this->cssID = $arrCss;
         }
         $article = !$GLOBALS['TL_CONFIG']['disableAlias'] && $this->alias != '' ? $this->alias : $this->id;
         $href = 'articles=' . ($this->inColumn != 'main' ? $this->inColumn . ':' : '') . $article;
         $this->Template->headline = $this->headline;
         $this->Template->href = $this->addToUrl($href);
         $this->Template->teaser = $this->teaser;
         $this->Template->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $this->headline), true);
         $this->Template->more = $GLOBALS['TL_LANG']['MSC']['more'];
         return;
     }
     // Get section and article alias
     list($strSection, $strArticle) = explode(':', \Input::get('articles'));
     if ($strArticle === null) {
         $strArticle = $strSection;
     }
     // Overwrite the page title
     if (!$this->blnNoMarkup && $strArticle != '' && ($strArticle == $this->id || $strArticle == $this->alias) && $this->title != '') {
         $objPage->pageTitle = strip_insert_tags($this->title);
     }
     $this->Template->printable = false;
     $this->Template->backlink = false;
     // Back link
     if (!$this->multiMode && $strArticle != '' && ($strArticle == $this->id || $strArticle == $this->alias)) {
         $this->Template->back = specialchars($GLOBALS['TL_LANG']['MSC']['goBack']);
         // Remove the "/articles/…" part from the URL
         if ($GLOBALS['TL_CONFIG']['disableAlias']) {
             $this->Template->backlink = preg_replace('@&(amp;)?articles=[^&]+@', '', \Environment::get('request'));
         } else {
             $this->Template->backlink = preg_replace('@/articles/[^/]+@', '', \Environment::get('request')) . $GLOBALS['TL_CONFIG']['urlSuffix'];
         }
     }
     $arrElements = array();
     $objCte = \ContentModel::findPublishedByPid($this->id);
     if ($objCte !== null) {
         while ($objCte->next()) {
             $arrElements[] = $this->getContentElement($objCte);
         }
     }
     $this->Template->teaser = $this->teaser;
     $this->Template->elements = $arrElements;
     if ($this->keywords != '') {
         $GLOBALS['TL_KEYWORDS'] .= ($GLOBALS['TL_KEYWORDS'] != '' ? ', ' : '') . $this->keywords;
     }
     // Backwards compatibility
     if ($this->printable == 1) {
         $this->Template->printable = true;
         $this->Template->pdfButton = true;
     } elseif ($this->printable != '') {
         $options = deserialize($this->printable);
         if (is_array($options) && !empty($options)) {
             $this->Template->printable = true;
             $this->Template->printButton = in_array('print', $options);
             $this->Template->pdfButton = in_array('pdf', $options);
             $this->Template->facebookButton = in_array('facebook', $options);
             $this->Template->twitterButton = in_array('twitter', $options);
             $this->Template->gplusButton = in_array('gplus', $options);
         }
     }
     // Add syndication variables
     if ($this->Template->printable) {
         $request = $this->getIndexFreeRequest(true);
         $this->Template->print = '#';
         $this->Template->encUrl = rawurlencode(\Environment::get('base') . \Environment::get('request'));
         $this->Template->encTitle = rawurlencode($objPage->pageTitle);
         $this->Template->href = $request . (strpos($request, '?') !== false ? '&amp;' : '?') . 'pdf=' . $this->id;
         $this->Template->printTitle = specialchars($GLOBALS['TL_LANG']['MSC']['printPage']);
         $this->Template->pdfTitle = specialchars($GLOBALS['TL_LANG']['MSC']['printAsPdf']);
         $this->Template->facebookTitle = specialchars($GLOBALS['TL_LANG']['MSC']['facebookShare']);
         $this->Template->twitterTitle = specialchars($GLOBALS['TL_LANG']['MSC']['twitterShare']);
         $this->Template->glpusTitle = specialchars($GLOBALS['TL_LANG']['MSC']['gplusShare']);
     }
 }
Exemple #17
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     $this->Template->referer = 'javascript:history.go(-1)';
     $objFaq = \FaqModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->faq_categories);
     if (null === $objFaq) {
         /** @var \PageError404 $objHandler */
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
     }
     // Overwrite the page title and description (see #2853 and #4955)
     if ($objFaq->question != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($objFaq->question));
         $objPage->description = $this->prepareMetaDescription($objFaq->question);
     }
     $this->Template->question = $objFaq->question;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $objFaq->answer = \String::toXhtml($objFaq->answer);
     } else {
         $objFaq->answer = \String::toHtml5($objFaq->answer);
     }
     $this->Template->answer = \String::encodeEmail($objFaq->answer);
     $this->Template->addImage = false;
     // Add image
     if ($objFaq->addImage && $objFaq->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objFaq->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objFaq->singleSRC)) {
                 $this->Template->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             // Do not override the field now that we have a model registry (see #6303)
             $arrFaq = $objFaq->row();
             $arrFaq['singleSRC'] = $objModel->path;
             $this->addImageToTemplate($this->Template, $arrFaq);
         }
     }
     $this->Template->enclosure = array();
     // Add enclosure
     if ($objFaq->addEnclosure) {
         $this->addEnclosuresToTemplate($this->Template, $objFaq->row());
     }
     $strAuthor = '';
     // Add the author
     if (($objAuthor = $objFaq->getRelated('author')) !== null) {
         $strAuthor = $objAuthor->name;
     }
     $this->Template->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], \Date::parse($objPage->dateFormat, $objFaq->tstamp), $strAuthor);
     // HOOK: comments extension required
     if ($objFaq->noComments || !in_array('comments', \ModuleLoader::getActive())) {
         $this->Template->allowComments = false;
         return;
     }
     /** @var \FaqCategoryModel $objCategory */
     $objCategory = $objFaq->getRelated('pid');
     $this->Template->allowComments = $objCategory->allowComments;
     // Comments are not allowed
     if (!$objCategory->allowComments) {
         return;
     }
     // Adjust the comments headline level
     $intHl = min(intval(str_replace('h', '', $this->hl)), 5);
     $this->Template->hlc = 'h' . ($intHl + 1);
     $this->import('Comments');
     $arrNotifies = array();
     // Notify the system administrator
     if ($objCategory->notify != 'notify_author') {
         $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
     }
     // Notify the author
     if ($objCategory->notify != 'notify_admin') {
         /** @var \UserModel $objAuthor */
         if (($objAuthor = $objFaq->getRelated('author')) !== null && $objAuthor->email != '') {
             $arrNotifies[] = $objAuthor->email;
         }
     }
     $objConfig = new \stdClass();
     $objConfig->perPage = $objCategory->perPage;
     $objConfig->order = $objCategory->sortOrder;
     $objConfig->template = $this->com_template;
     $objConfig->requireLogin = $objCategory->requireLogin;
     $objConfig->disableCaptcha = $objCategory->disableCaptcha;
     $objConfig->bbcode = $objCategory->bbcode;
     $objConfig->moderate = $objCategory->moderate;
     $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_faq', $objFaq->id, $arrNotifies);
 }
 protected function getEventDetails($objEvent, $intStart, $intEnd, $strUrl, $intBegin, $intCalendar)
 {
     global $objPage;
     $span = \Calendar::calculateSpan($intStart, $intEnd);
     // Adjust the start time of a multi-day event (see #6802)
     if ($this->cal_noSpan && $span > 0 && $intStart < $intBegin && $intBegin < $intEnd) {
         $intStart = $intBegin;
     }
     $strDate = \Date::parse($objPage->dateFormat, $intStart);
     $strDay = $GLOBALS['TL_LANG']['DAYS'][date('w', $intStart)];
     $strMonth = $GLOBALS['TL_LANG']['MONTHS'][date('n', $intStart) - 1];
     $strMemberTemplate = $this->mlTemplate;
     if ($span > 0) {
         $strDate = \Date::parse($objPage->dateFormat, $intStart) . ' - ' . \Date::parse($objPage->dateFormat, $intEnd);
         $strDay = '';
     }
     $strTime = '';
     if ($objEvent->addTime) {
         if ($span > 0) {
             $strDate = \Date::parse($objPage->datimFormat, $intStart) . ' - ' . \Date::parse($objPage->datimFormat, $intEnd);
         } elseif ($intStart == $intEnd) {
             $strTime = \Date::parse($objPage->timeFormat, $intStart);
         } else {
             $strTime = \Date::parse($objPage->timeFormat, $intStart) . ' - ' . \Date::parse($objPage->timeFormat, $intEnd);
         }
     }
     // Store raw data
     $arrEvent = $objEvent->row();
     // Overwrite some settings
     $arrEvent['time'] = $strTime;
     $arrEvent['date'] = $strDate;
     $arrEvent['day'] = $strDay;
     $arrEvent['month'] = $strMonth;
     $arrEvent['parent'] = $intCalendar;
     $arrEvent['link'] = $objEvent->title;
     $arrEvent['target'] = '';
     $arrEvent['title'] = specialchars($objEvent->title, true);
     $arrEvent['href'] = $this->generateEventUrl($objEvent, $strUrl);
     if (($intParentEvent = $objEvent->parentEvent) > 0) {
         if (($objParentEvent = CalendarPlusEventsModel::findPublishedByParentAndIdOrAlias($intParentEvent, array($objEvent->pid))) !== null) {
             $arrEvent['parentHref'] = $this->generateEventUrl($objParentEvent, $strUrl);
             $arrEvent['isSubEvent'] = true;
         }
     }
     $arrEvent['class'] = $objEvent->cssClass != '' ? ' ' . $objEvent->cssClass : '';
     $arrEvent['begin'] = $intStart;
     $arrEvent['end'] = $intEnd;
     $arrEvent['details'] = '';
     $arrEvent['startTimeFormated'] = $objEvent->startTime > 0 ? \Date::parse($objPage->timeFormat, $objEvent->startTime) : null;
     $arrEvent['endTimeFormated'] = $objEvent->endTime > 0 ? \Date::parse($objPage->timeFormat, $objEvent->endTime) : null;
     // modal
     if ($this->cal_showInModal && $objEvent->source == 'default' && $this->cal_readerModule) {
         $arrEvent['modal'] = true;
         $arrEvent['modalTarget'] = '#' . EventsPlusHelper::getCSSModalID($this->cal_readerModule);
     }
     $arrPromoters = deserialize($objEvent->promoter, true);
     if (!empty($arrPromoters)) {
         $objPromoters = CalendarPromotersModel::findMultipleByIds($arrPromoters);
         if ($objPromoters !== null) {
             while ($objPromoters->next()) {
                 $objPromoter = $objPromoters->current();
                 if ($objPromoter->website != '') {
                     $strWebsiteLink = $objPromoter->website;
                     // Add http:// to the website
                     if ($strWebsiteLink != '' && !preg_match('@^(https?://|ftp://|mailto:|#)@i', $strWebsiteLink)) {
                         $objPromoter->website = 'http://' . $strWebsiteLink;
                     }
                 }
                 $arrEvent['promoterList'][] = $objPromoter;
             }
         }
     }
     $objEvent->docents = deserialize($objEvent->docents, true);
     if (is_array($objEvent->docents) && !empty($objEvent->docents)) {
         $objDocents = CalendarDocentsModel::findMultipleByIds($objEvent->docents);
         if ($objDocents !== null) {
             while ($objDocents->next()) {
                 $arrEvent['docentList'][] = $objDocents->current();
             }
         }
     }
     $objEvent->memberDocents = deserialize($objEvent->memberDocents, true);
     if (is_array($objEvent->memberDocents) && !empty($objEvent->memberDocents)) {
         $objMembers = MemberPlusMemberModel::findMultipleByIds($objEvent->memberDocents);
         if ($objMembers !== null) {
             while ($objMembers->next()) {
                 $objMemberPlus = new \HeimrichHannot\MemberPlus\MemberPlus($this->objModel);
                 // custom subevent memberlist template
                 $objMemberPlus->mlTemplate = $arrEvent['isSubEvent'] && $this->cal_subeventDocentTemplate != '' ? $this->cal_subeventDocentTemplate : $objMemberPlus->mlTemplate;
                 $arrEvent['memberDocentList'][] = $objMemberPlus->parseMember($objMembers);
             }
         }
     }
     $objEvent->hosts = deserialize($objEvent->hosts, true);
     if (is_array($objEvent->hosts) && !empty($objEvent->hosts)) {
         $objDocents = CalendarDocentsModel::findMultipleByIds($objEvent->hosts);
         if ($objDocents !== null) {
             while ($objDocents->next()) {
                 $arrEvent['hostList'][] = $objDocents->current();
             }
         }
     }
     $objEvent->memberHosts = deserialize($objEvent->memberHosts, true);
     if (is_array($objEvent->memberHosts) && !empty($objEvent->memberHosts)) {
         $objMembers = MemberPlusMemberModel::findMultipleByIds($objEvent->memberHosts);
         if ($objMembers !== null) {
             while ($objMembers->next()) {
                 $objMemberPlus = new \HeimrichHannot\MemberPlus\MemberPlus($this->objModel);
                 // custom subevent memberlist template
                 $objMemberPlus->mlTemplate = $arrEvent['isSubEvent'] && $this->cal_subeventHostTemplate != '' ? $this->cal_subeventHostTemplate : $objMemberPlus->mlTemplate;
                 $arrEvent['memberHostList'][] = $objMemberPlus->parseMember($objMembers);
             }
         }
     }
     $objEvent->eventtypes = deserialize($objEvent->eventtypes, true);
     if (is_array($objEvent->eventtypes) && !empty($objEvent->eventtypes)) {
         $objEventTypes = CalendarEventtypesModel::findMultipleByIds($objEvent->eventtypes);
         if ($objEventTypes !== null) {
             while ($objEventTypes->next()) {
                 $objEventtypesArchive = $objEventTypes->getRelated('pid');
                 if ($objEventtypesArchive === null) {
                     continue;
                 }
                 $strClass = $objEventTypes->cssClass != '' ? ' ' . $objEventTypes->cssClass : '';
                 $strClass .= $objEventtypesArchive->cssClass != '' ? ' ' . $objEventtypesArchive->cssClass : '';
                 $objEventTypes->class = $strClass;
                 $arrEvent['eventtypeList'][] = $objEventTypes->current();
             }
         }
     }
     // time diff
     if ($objEvent->endTime > $objEvent->startTime) {
         $objDateStartTime = new \DateTime();
         $objDateStartTime->setTimestamp($objEvent->startTime);
         $objDateEndTime = new \DateTime();
         $objDateEndTime->setTimestamp($objEvent->endTime);
         $arrEvent['timeDiff'] = $objDateStartTime->diff($objDateEndTime);
     }
     if ($objEvent->website != '') {
         $arrEvent['websiteLink'] = $objEvent->website;
         // Add http:// to the website
         if ($objEvent->website != '' && !preg_match('@^(https?://|ftp://|mailto:|#)@i', $objEvent->website)) {
             $arrEvent['websiteLink'] = 'http://' . $objEvent->website;
         }
     }
     // Override the link target
     if ($objEvent->source == 'external' && $objEvent->target) {
         $arrEvent['target'] = $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"';
     }
     // Clean the RTE output
     if ($arrEvent['teaser'] != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $arrEvent['teaser'] = \String::toXhtml($arrEvent['teaser']);
         } else {
             $arrEvent['teaser'] = \String::toHtml5($arrEvent['teaser']);
         }
     }
     // Display the "read more" button for external/article links
     if ($objEvent->source != 'default') {
         $arrEvent['details'] = true;
     } else {
         $objElement = \ContentModel::findPublishedByPidAndTable($objEvent->id, 'tl_calendar_events');
         if ($objElement !== null) {
             while ($objElement->next()) {
                 $arrEvent['details'] .= $this->getContentElement($objElement->current());
             }
         }
     }
     // Get todays start and end timestamp
     if ($this->intTodayBegin === null) {
         $this->intTodayBegin = strtotime('00:00:00');
     }
     if ($this->intTodayEnd === null) {
         $this->intTodayEnd = strtotime('23:59:59');
     }
     // Mark past and upcoming events (see #3692)
     if ($intEnd < $this->intTodayBegin) {
         $arrEvent['class'] .= ' bygone';
     } elseif ($intStart > $this->intTodayEnd) {
         $arrEvent['class'] .= ' upcoming';
     } else {
         $arrEvent['class'] .= ' current';
     }
     return $arrEvent;
 }
 /**
  * Set the template-vars to the template object for the selected album
  *
  * @param integer
  */
 protected function getAlbumTemplateVars($intAlbumId)
 {
     global $objPage;
     // Get the page model
     $objPageModel = \PageModel::findByPk($objPage->id);
     // Load the current album from db
     $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id=?')->execute($intAlbumId);
     // add meta tags to the page object
     if (TL_MODE == 'FE' && $this->DETAIL_VIEW === true && $objAlbum !== null) {
         $objPage->description = $objAlbum->description != '' ? specialchars($objAlbum->description) : $objPage->description;
         $GLOBALS['TL_KEYWORDS'] = ltrim($GLOBALS['TL_KEYWORDS'] . ',' . specialchars($objAlbum->keywords), ',');
     }
     //store all album-data in the array
     $objAlbum->reset();
     $this->Template->arrAlbumdata = $objAlbum->fetchAssoc();
     // store the data of the current album in the session
     $_SESSION['gallery_creator']['CURRENT_ALBUM'] = $this->Template->arrAlbumdata;
     //der back-Link
     $this->Template->backLink = $this->generateBackLink($intAlbumId);
     //Der dem Bild uebergeordnete Albumname
     $this->Template->Albumname = $objAlbum->name;
     // Albumbesucher (Anzahl Klicks)
     $this->Template->visitors = $objAlbum->vistors;
     //Der Kommentar zum gewaehlten Album
     $this->Template->albumComment = $objPage->outputFormat == 'xhtml' ? \String::toXhtml($objAlbum->comment) : \String::toHtml5($objAlbum->comment);
     // In der Detailansicht kann optional ein Artikel vor dem Album hinzugefuegt werden
     $this->Template->insertArticlePre = $objAlbum->insert_article_pre ? sprintf('{{insert_article::%s}}', $objAlbum->insert_article_pre) : null;
     // In der Detailansicht kann optional ein Artikel nach dem Album hinzugefuegt werden
     $this->Template->insertArticlePost = $objAlbum->insert_article_post ? sprintf('{{insert_article::%s}}', $objAlbum->insert_article_post) : null;
     //Das Event-Datum des Albums als unix-timestamp
     $this->Template->eventTstamp = $objAlbum->date;
     //Das Event-Datum des Albums formatiert
     $this->Template->eventDate = \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $objAlbum->date);
     //Abstaende
     $this->Template->imagemargin = $this->DETAIL_VIEW ? $this->generateMargin(deserialize($this->gc_imagemargin_detailview), 'margin') : $this->generateMargin(deserialize($this->gc_imagemargin_albumlisting), 'margin');
     //Anzahl Spalten pro Reihe
     $this->Template->colsPerRow = $this->gc_rows == "" ? 4 : $this->gc_rows;
     //Pfad zur xml-Ausgabe fuer jw_imagerotator
     $this->Template->jw_imagerotator_path = TL_MODE == 'FE' ? $objPageModel->getFrontendUrl(($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . $objAlbum->alias . '/jw_imagerotator/true') : null;
     //Inhaltselement Id anhaengen wenn es sich um ein Inhaltselement handelt
     if ($this->moduleType == 'cte') {
         //Pfad zur xml-Ausgabe fuer jw_imagerotator
         if ($this->countGcContentElementsOnPage() > 1) {
             $this->Template->jw_imagerotator_path = TL_MODE == 'FE' ? $this->Template->jw_imagerotator_path . '/ce/' . $this->id : null;
         }
     }
     $this->Template->objElement = $this;
 }
 /**
  * Set the template-vars to the template object for the selected album
  * @param $intAlbumId
  */
 protected function getAlbumTemplateVars($intAlbumId)
 {
     global $objPage;
     // Load the current album from db
     $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id=?')->execute($intAlbumId);
     $objPage->description = $objAlbum->description != '' ? specialchars($objAlbum->description) : $objPage->description;
     $GLOBALS['TL_KEYWORDS'] = ltrim($GLOBALS['TL_KEYWORDS'] . ',' . specialchars($objAlbum->keywords), ',');
     // Store all album-data in the array
     $objAlbum->reset();
     $this->Template->arrAlbumdata = $objAlbum->fetchAssoc();
     // Albumname
     $this->Template->Albumname = $objAlbum->name;
     // Album visitors
     $this->Template->visitors = $objAlbum->vistors;
     // Album caption
     $this->Template->albumComment = $objPage->outputFormat == 'xhtml' ? \String::toXhtml($objAlbum->comment) : \String::toHtml5($objAlbum->comment);
     // Insert article pre
     $this->Template->insertArticlePre = $objAlbum->insert_article_pre ? sprintf('{{insert_article::%s}}', $objAlbum->insert_article_pre) : null;
     // Insert article after
     $this->Template->insertArticlePost = $objAlbum->insert_article_post ? sprintf('{{insert_article::%s}}', $objAlbum->insert_article_post) : null;
     // event date as unix timestamp
     $this->Template->eventTstamp = $objAlbum->date;
     // formated event date
     $this->Template->eventDate = \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $objAlbum->date);
     // Margins
     $this->Template->imagemargin = $this->generateMargin(deserialize($this->gc_imagemargin_detailview), 'margin');
     // Cols per row
     $this->Template->colsPerRow = $this->gc_rows == "" ? 4 : $this->gc_rows;
     $this->Template->objElement = $this;
 }
Exemple #21
0
 /**
  * Returns the information-array about an album
  *
  * @param null $intPictureId
  * @param $objThis
  * @return array|null
  */
 public static function getPictureInformationArray($intPictureId = null, $objThis)
 {
     if ($intPictureId < 1) {
         return;
     }
     global $objPage;
     $defaultThumbSRC = $objThis->defaultThumb;
     if (\Config::get('gc_error404_thumb') !== '') {
         $objFile = \FilesModel::findByUuid(\Config::get('gc_error404_thumb'));
         if ($objFile !== null) {
             if (\Validator::isUuid(\Config::get('gc_error404_thumb'))) {
                 if (is_file(TL_ROOT . '/' . $objFile->path)) {
                     $defaultThumbSRC = $objFile->path;
                 }
             }
         }
     }
     // Get the page model
     $objPageModel = \PageModel::findByPk($objPage->id);
     $objPicture = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE id=?')->execute($intPictureId);
     //Alle Informationen zum Album in ein array packen
     $objAlbum = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id=?')->execute($objPicture->pid);
     $arrAlbumInfo = $objAlbum->fetchAssoc();
     //Bild-Besitzer
     $objOwner = \Database::getInstance()->prepare('SELECT name FROM tl_user WHERE id=?')->execute($objPicture->owner);
     $strImageSrc = '';
     $arrMeta = array();
     $objFileModel = \FilesModel::findByUuid($objPicture->uuid);
     if ($objFileModel == null) {
         $strImageSrc = $defaultThumbSRC;
     } else {
         $strImageSrc = $objFileModel->path;
         if (!is_file(TL_ROOT . '/' . $strImageSrc)) {
             // Fallback to the default thumb
             $strImageSrc = $defaultThumbSRC;
         }
         //meta
         $arrMeta = $objThis->getMetaData($objFileModel->meta, $objPage->language);
         // Use the file name as title if none is given
         if ($arrMeta['title'] == '') {
             $arrMeta['title'] = specialchars($objFileModel->name);
         }
     }
     // get thumb dimensions
     $arrSize = unserialize($objThis->gc_size_detailview);
     //Generate the thumbnails and the picture element
     try {
         $thumbSrc = \Image::create($strImageSrc, $arrSize)->executeResize()->getResizedPath();
         $picture = \Picture::create($strImageSrc, $arrSize)->getTemplateData();
         if ($thumbSrc !== $strImageSrc) {
             $objFile = new \File(rawurldecode($thumbSrc), true);
         }
     } catch (\Exception $e) {
         \System::log('Image "' . $strImageSrc . '" could not be processed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
         $thumbSrc = '';
         $picture = array('img' => array('src' => '', 'srcset' => ''), 'sources' => array());
     }
     $picture['alt'] = $objPicture->title != '' ? specialchars($objPicture->title) : specialchars($arrMeta['title']);
     $picture['title'] = $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\String::toXhtml($objPicture->comment)) : specialchars(\String::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']);
     $objFileThumb = new \File(rawurldecode($thumbSrc));
     $arrSize[0] = $objFileThumb->width;
     $arrSize[1] = $objFileThumb->height;
     $arrFile["thumb_width"] = $objFileThumb->width;
     $arrFile["thumb_height"] = $objFileThumb->height;
     // get some image params
     if (is_file(TL_ROOT . '/' . $strImageSrc)) {
         $objFileImage = new \File($strImageSrc);
         if (!$objFileImage->isGdImage) {
             return null;
         }
         $arrFile["path"] = $objFileImage->path;
         $arrFile["basename"] = $objFileImage->basename;
         // filename without extension
         $arrFile["filename"] = $objFileImage->filename;
         $arrFile["extension"] = $objFileImage->extension;
         $arrFile["dirname"] = $objFileImage->dirname;
         $arrFile["image_width"] = $objFileImage->width;
         $arrFile["image_height"] = $objFileImage->height;
     } else {
         return null;
     }
     //check if there is a custom thumbnail selected
     if ($objPicture->addCustomThumb && !empty($objPicture->customThumb)) {
         $customThumbModel = \FilesModel::findByUuid($objPicture->customThumb);
         if ($customThumbModel !== null) {
             if (is_file(TL_ROOT . '/' . $customThumbModel->path)) {
                 $objFileCustomThumb = new \File($customThumbModel->path, true);
                 if ($objFileCustomThumb->isGdImage) {
                     $arrSize = unserialize($objThis->gc_size_detailview);
                     $thumbSrc = \Image::get($objFileCustomThumb->path, $arrSize[0], $arrSize[1], $arrSize[2]);
                     $objFileCustomThumb = new \File(rawurldecode($thumbSrc));
                     $arrSize[0] = $objFileCustomThumb->width;
                     $arrSize[1] = $objFileCustomThumb->height;
                     $arrFile["thumb_width"] = $objFileCustomThumb->width;
                     $arrFile["thumb_height"] = $objFileCustomThumb->height;
                 }
             }
         }
     }
     //exif
     if ($GLOBALS['TL_CONFIG']['gc_read_exif']) {
         try {
             $exif = is_callable('exif_read_data') && TL_MODE == 'FE' ? exif_read_data($strImageSrc) : array('info' => "The function 'exif_read_data()' is not available on this server.");
         } catch (Exception $e) {
             $exif = array('info' => "The function 'exif_read_data()' is not available on this server.");
         }
     } else {
         $exif = array('info' => "The function 'exif_read_data()' has not been activated in the Contao backend settings.");
     }
     //video-integration
     $strMediaSrc = trim($objPicture->socialMediaSRC) != "" ? trim($objPicture->socialMediaSRC) : "";
     if (\Validator::isUuid($objPicture->localMediaSRC)) {
         //get path of a local Media
         $objMovieFile = \FilesModel::findById($objPicture->localMediaSRC);
         $strMediaSrc = $objMovieFile !== null ? $objMovieFile->path : $strMediaSrc;
     }
     $href = null;
     if (TL_MODE == 'FE' && $objThis->gc_fullsize) {
         $href = $strMediaSrc != "" ? $strMediaSrc : \System::urlEncode($strImageSrc);
     }
     //cssID
     $cssID = deserialize($objPicture->cssID, true);
     // build the array
     $arrPicture = array('id' => $objPicture->id, 'pid' => $objPicture->pid, 'date' => $objPicture->date, 'owner' => $objPicture->owner, 'owners_name' => $objOwner->name, 'album_id' => $objPicture->pid, 'name' => specialchars($arrFile["basename"]), 'filename' => $arrFile["filename"], 'uuid' => $objPicture->uuid, 'path' => $arrFile["path"], 'basename' => $arrFile["basename"], 'dirname' => $arrFile["dirname"], 'extension' => $arrFile["extension"], 'alt' => $objPicture->title != '' ? specialchars($objPicture->title) : specialchars($arrMeta['title']), 'title' => $objPicture->title != '' ? specialchars($objPicture->title) : specialchars($arrMeta['title']), 'comment' => $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\String::toXhtml($objPicture->comment)) : specialchars(\String::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']), 'caption' => $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\String::toXhtml($objPicture->comment)) : specialchars(\String::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']), 'href' => TL_FILES_URL . $href, 'single_image_url' => $objPageModel->getFrontendUrl(($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . \Input::get('items') . '/img/' . $arrFile["filename"], $objPage->language), 'image_src' => $arrFile["path"], 'media_src' => $strMediaSrc, 'socialMediaSRC' => $objPicture->socialMediaSRC, 'localMediaSRC' => $objPicture->localMediaSRC, 'addCustomThumb' => $objPicture->addCustomThumb, 'thumb_src' => isset($thumbSrc) ? TL_FILES_URL . $thumbSrc : '', 'size' => $arrSize, 'thumb_width' => $arrFile["thumb_width"], 'thumb_height' => $arrFile["thumb_height"], 'image_width' => $arrFile["image_width"], 'image_height' => $arrFile["image_height"], 'lightbox' => $objPage->outputFormat == 'xhtml' ? 'rel="lightbox[lb' . $objPicture->pid . ']"' : 'data-lightbox="lb' . $objPicture->pid . '"', 'tstamp' => $objPicture->tstamp, 'sorting' => $objPicture->sorting, 'published' => $objPicture->published, 'exif' => $exif, 'albuminfo' => $arrAlbumInfo, 'metaData' => $arrMeta, 'cssID' => $cssID[0] != '' ? $cssID[0] : '', 'cssClass' => $cssID[1] != '' ? $cssID[1] : '', 'externalFile' => $objPicture->externalFile, 'picture' => $picture);
     //Fuegt dem Array weitere Eintraege hinzu, falls tl_gallery_creator_pictures erweitert wurde
     $objPicture = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE id=?')->execute($intPictureId);
     foreach ($objPicture->fetchAssoc() as $key => $value) {
         if (!array_key_exists($key, $arrPicture)) {
             $arrPicture[$key] = $value;
         }
     }
     return $arrPicture;
 }
Exemple #22
0
 /**
  * Add an event to the array of active events
  *
  * @param \CalendarEventsModel $objEvents
  * @param integer              $intStart
  * @param integer              $intEnd
  * @param string               $strUrl
  * @param integer              $intBegin
  * @param integer              $intLimit
  * @param integer              $intCalendar
  */
 protected function addEvent($objEvents, $intStart, $intEnd, $strUrl, $intBegin, $intLimit, $intCalendar)
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $span = \Calendar::calculateSpan($intStart, $intEnd);
     // Adjust the start time of a multi-day event (see #6802)
     if ($this->cal_noSpan && $span > 0 && $intStart < $intBegin && $intBegin < $intEnd) {
         $intStart = $intBegin;
     }
     $intDate = $intStart;
     $intKey = date('Ymd', $intStart);
     $strDate = \Date::parse($objPage->dateFormat, $intStart);
     $strDay = $GLOBALS['TL_LANG']['DAYS'][date('w', $intStart)];
     $strMonth = $GLOBALS['TL_LANG']['MONTHS'][date('n', $intStart) - 1];
     if ($span > 0) {
         $strDate = \Date::parse($objPage->dateFormat, $intStart) . ' - ' . \Date::parse($objPage->dateFormat, $intEnd);
         $strDay = '';
     }
     $strTime = '';
     if ($objEvents->addTime) {
         if ($span > 0) {
             $strDate = \Date::parse($objPage->datimFormat, $intStart) . ' - ' . \Date::parse($objPage->datimFormat, $intEnd);
         } elseif ($intStart == $intEnd) {
             $strTime = \Date::parse($objPage->timeFormat, $intStart);
         } else {
             $strTime = \Date::parse($objPage->timeFormat, $intStart) . ' - ' . \Date::parse($objPage->timeFormat, $intEnd);
         }
     }
     // Store raw data
     $arrEvent = $objEvents->row();
     // Overwrite some settings
     $arrEvent['time'] = $strTime;
     $arrEvent['date'] = $strDate;
     $arrEvent['day'] = $strDay;
     $arrEvent['month'] = $strMonth;
     $arrEvent['parent'] = $intCalendar;
     $arrEvent['calendar'] = $objEvents->getRelated('pid');
     $arrEvent['link'] = $objEvents->title;
     $arrEvent['target'] = '';
     $arrEvent['title'] = specialchars($objEvents->title, true);
     $arrEvent['href'] = $this->generateEventUrl($objEvents, $strUrl);
     $arrEvent['class'] = $objEvents->cssClass != '' ? ' ' . $objEvents->cssClass : '';
     $arrEvent['begin'] = $intStart;
     $arrEvent['end'] = $intEnd;
     $arrEvent['details'] = '';
     // Override the link target
     if ($objEvents->source == 'external' && $objEvents->target) {
         $arrEvent['target'] = $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"';
     }
     // Clean the RTE output
     if ($arrEvent['teaser'] != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $arrEvent['teaser'] = \String::toXhtml($arrEvent['teaser']);
         } else {
             $arrEvent['teaser'] = \String::toHtml5($arrEvent['teaser']);
         }
     }
     // Display the "read more" button for external/article links
     if ($objEvents->source != 'default') {
         $arrEvent['details'] = true;
     } else {
         $id = $objEvents->id;
         $arrEvent['details'] = function () use($id) {
             $strDetails = '';
             $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_calendar_events');
             if ($objElement !== null) {
                 while ($objElement->next()) {
                     $strDetails .= $this->getContentElement($objElement->current());
                 }
             }
             return $strDetails;
         };
     }
     // Get todays start and end timestamp
     if ($this->intTodayBegin === null) {
         $this->intTodayBegin = strtotime('00:00:00');
     }
     if ($this->intTodayEnd === null) {
         $this->intTodayEnd = strtotime('23:59:59');
     }
     // Mark past and upcoming events (see #3692)
     if ($intEnd < $this->intTodayBegin) {
         $arrEvent['class'] .= ' bygone';
     } elseif ($intStart > $this->intTodayEnd) {
         $arrEvent['class'] .= ' upcoming';
     } else {
         $arrEvent['class'] .= ' current';
     }
     $this->arrEvents[$intKey][$intStart][] = $arrEvent;
     // Multi-day event
     for ($i = 1; $i <= $span && $intDate <= $intLimit; $i++) {
         // Only show first occurrence
         if ($this->cal_noSpan && $intDate >= $intBegin) {
             break;
         }
         $intDate = strtotime('+ 1 day', $intDate);
         $intNextKey = date('Ymd', $intDate);
         $this->arrEvents[$intNextKey][$intDate][] = $arrEvent;
     }
 }
Exemple #23
0
 /**
  * Add an event to the array of active events
  * @param object
  * @param integer
  * @param integer
  * @param string
  * @param string
  */
 protected function addEvent($objEvent, $intStart, $intEnd, $strUrl, $strBase)
 {
     if ($intEnd < time()) {
         return;
     }
     global $objPage;
     // Called in the back end (see #4026)
     if ($objPage === null) {
         $objPage = new \stdClass();
         $objPage->dateFormat = $GLOBALS['TL_CONFIG']['dateFormat'];
         $objPage->datimFormat = $GLOBALS['TL_CONFIG']['datimFormat'];
         $objPage->timeFormat = $GLOBALS['TL_CONFIG']['timeFormat'];
     }
     $intKey = date('Ymd', $intStart);
     $span = self::calculateSpan($intStart, $intEnd);
     $format = $objEvent->addTime ? 'datimFormat' : 'dateFormat';
     // Add date
     if ($span > 0) {
         $title = $this->parseDate($objPage->{$format}, $intStart) . ' - ' . $this->parseDate($objPage->{$format}, $intEnd);
     } else {
         $title = $this->parseDate($objPage->dateFormat, $intStart) . ($objEvent->addTime ? ' (' . $this->parseDate($objPage->timeFormat, $intStart) . ($intStart < $intEnd ? ' - ' . $this->parseDate($objPage->timeFormat, $intEnd) : '') . ')' : '');
     }
     // Add title and link
     $title .= ' ' . $objEvent->title;
     $link = '';
     switch ($objEvent->source) {
         case 'external':
             $link = $objEvent->url;
             break;
         case 'internal':
             if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) {
                 $link = $strBase . $this->generateFrontendUrl($objTarget->row());
             }
             break;
         case 'article':
             if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null) {
                 $link = $strBase . ampersand($this->generateFrontendUrl($objArticle->getRelated('pid')->row(), '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
             }
             break;
     }
     // Link to the default page
     if ($link == '') {
         $link = $strBase . sprintf($strUrl, $objEvent->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objEvent->alias : $objEvent->id);
     }
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $objEvent->teaser = \String::toXhtml($objEvent->teaser);
     } else {
         $objEvent->teaser = \String::toHtml5($objEvent->teaser);
     }
     $arrEvent = array('title' => $title, 'description' => $objEvent->details, 'teaser' => $objEvent->teaser, 'link' => $link, 'published' => $objEvent->tstamp, 'authorName' => $objEvent->authorName);
     // Add the article image as enclosure
     if ($objEvent->addImage) {
         $objFile = \FilesModel::findByPk($objEvent->singleSRC);
         if ($objFile !== null) {
             $arrEvent['enclosure'][] = $objFile->path;
         }
     }
     // Enclosures
     if ($objEvent->addEnclosure) {
         $arrEnclosure = deserialize($objEvent->enclosure, true);
         if (is_array($arrEnclosure)) {
             $objFile = \FilesModel::findMultipleByIds($arrEnclosure);
             while ($objFile->next()) {
                 $arrEvent['enclosure'][] = $objFile->path;
             }
         }
     }
     $this->arrEvents[$intKey][$intStart][] = $arrEvent;
 }
Exemple #24
0
 /**
  * Parse an item and return it as string
  * @param object
  * @param boolean
  * @param string
  * @return string
  */
 protected function parseArticle($objArticle, $blnAddArchive = false, $strClass = '')
 {
     global $objPage;
     $objTemplate = new \FrontendTemplate($this->news_template);
     $objTemplate->setData($objArticle->row());
     $objTemplate->class = ($objArticle->cssClass != '' ? ' ' . $objArticle->cssClass : '') . $strClass;
     $objTemplate->newsHeadline = $objArticle->headline;
     $objTemplate->subHeadline = $objArticle->subheadline;
     $objTemplate->hasSubHeadline = $objArticle->subheadline ? true : false;
     $objTemplate->linkHeadline = $this->generateLink($objArticle->headline, $objArticle, $blnAddArchive);
     $objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objArticle, $blnAddArchive, true);
     $objTemplate->link = $this->generateNewsUrl($objArticle, $blnAddArchive);
     $objTemplate->archive = $objArticle->archive;
     // Clean the RTE output
     if ($objArticle->teaser != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $objArticle->teaser = \String::toXhtml($objArticle->teaser);
         } else {
             $objArticle->teaser = \String::toHtml5($objArticle->teaser);
         }
         $objTemplate->teaser = \String::encodeEmail($objArticle->teaser);
     }
     // Display the "read more" button for external/article links
     if (($objArticle->source == 'external' || $objArticle->source == 'article') && $objArticle->text == '') {
         $objTemplate->text = true;
     } else {
         // Clean the RTE output
         if ($objPage->outputFormat == 'xhtml') {
             $objArticle->text = \String::toXhtml($objArticle->text);
         } else {
             $objArticle->text = \String::toHtml5($objArticle->text);
         }
         $objTemplate->text = \String::encodeEmail($objArticle->text);
     }
     $arrMeta = $this->getMetaFields($objArticle);
     // Add the meta information
     $objTemplate->date = $arrMeta['date'];
     $objTemplate->hasMetaFields = !empty($arrMeta);
     $objTemplate->numberOfComments = $arrMeta['ccount'];
     $objTemplate->commentCount = $arrMeta['comments'];
     $objTemplate->timestamp = $objArticle->date;
     $objTemplate->author = $arrMeta['author'];
     $objTemplate->datetime = date('Y-m-d\\TH:i:sP', $objArticle->date);
     $objTemplate->addImage = false;
     // Add an image
     if ($objArticle->addImage && $objArticle->singleSRC != '') {
         if (!is_numeric($objArticle->singleSRC)) {
             $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
         } else {
             $objModel = \FilesModel::findByPk($objArticle->singleSRC);
             if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                 // Override the default image size
                 if ($this->imgSize != '') {
                     $size = deserialize($this->imgSize);
                     if ($size[0] > 0 || $size[1] > 0) {
                         $objArticle->size = $this->imgSize;
                     }
                 }
                 $objArticle->singleSRC = $objModel->path;
                 $this->addImageToTemplate($objTemplate, $objArticle->row());
             }
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures
     if ($objArticle->addEnclosure) {
         $this->addEnclosuresToTemplate($objTemplate, $objArticle->row());
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['parseArticles']) && is_array($GLOBALS['TL_HOOKS']['parseArticles'])) {
         foreach ($GLOBALS['TL_HOOKS']['parseArticles'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objTemplate, $objArticle->row(), $this);
         }
     }
     return $objTemplate->parse();
 }
 /**
  * Parse an item and return it as string
  * @param object
  * @param boolean
  * @param string
  * @param integer
  * @return string
  */
 protected function parseArticle($objArticle, $blnAddArchive = false, $strClass = '', $intCount = 0)
 {
     global $objPage;
     $arrCategories = deserialize($objArticle->categories, true);
     $objTemplate = new \FrontendTemplate($this->news_template);
     $objTemplate->setData($objArticle->row());
     $objTemplate->class = ($objArticle->cssClass != '' ? ' ' . $objArticle->cssClass : '') . $strClass;
     $objTemplate->newsHeadline = $objArticle->headline;
     $objTemplate->subHeadline = $objArticle->subheadline;
     $objTemplate->hasSubHeadline = $objArticle->subheadline ? true : false;
     $objTemplate->linkHeadline = $this->generateLink($objArticle->headline, $objArticle, $blnAddArchive);
     $objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objArticle, $blnAddArchive, true);
     $objTemplate->link = $this->generateNewsUrl($objArticle, $blnAddArchive);
     $objTemplate->linkTarget = $objArticle->target ? $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"' : '';
     $objTemplate->linkTitle = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->headline), true);
     $objTemplate->count = $intCount;
     // see #5708
     $objTemplate->text = '';
     $objTemplate->hasText = false;
     $objTemplate->hasTeaser = false;
     // print pdf
     if ($this->news_pdfJumpTo) {
         $objTemplate->showPdfButton = true;
         $pdfPage = \PageModel::findByPk($this->news_pdfJumpTo);
         $pdfArticle = \ArticleModel::findPublishedByPidAndColumn($this->news_pdfJumpTo, 'main');
         $options = deserialize($pdfArticle->printable);
         if (in_array('pdf', $options)) {
             $objTemplate->pdfArticleId = $pdfArticle->id;
         }
         $strUrl = \Controller::generateFrontendUrl($pdfPage->row());
         $objTemplate->pdfJumpTo = $strUrl;
     }
     $objArchive = \NewsArchiveModel::findByPk($objArticle->pid);
     $objTemplate->archive = $objArchive;
     $objTemplate->archive->title = $objTemplate->archive->displayTitle ? $objTemplate->archive->displayTitle : $objTemplate->archive->title;
     $objTemplate->archive->class = ModuleNewsListPlus::getArchiveClassFromTitle($objTemplate->archive->title, true);
     $objTemplate->archiveTitle = $objTemplate->archive->title;
     $arrCategoryTitles = array();
     if ($this->news_archiveTitleAppendCategories && !empty($arrCategories)) {
         $arrTitleCategories = array_intersect($arrCategories, deserialize($this->news_archiveTitleCategories, true));
         if (!empty($arrTitleCategories)) {
             $objTitleCategories = NewsCategoryModel::findPublishedByIds($arrTitleCategories);
             if ($objTitleCategories !== null) {
                 while ($objTitleCategories->next()) {
                     if ($objTitleCategories->frontendTitle) {
                         $arrCategoryTitles[$objTitleCategories->id] = $objTitleCategories->frontendTitle;
                         continue;
                     }
                     $arrCategoryTitles[$objTitleCategories->id] = $objTitleCategories->title;
                 }
                 $objTemplate->archiveTitle .= ' : ' . implode(' : ', $arrCategoryTitles);
             }
         }
     }
     // add tags
     $objTemplate->showTags = $this->news_showtags;
     if ($this->news_showtags && $this->news_template_modal && $this->Environment->isAjaxRequest) {
         $helper = new NewsPlusTagHelper();
         $tagsandlist = $helper->getTagsAndTaglistForIdAndTable($objArticle->id, 'tl_news', $this->tag_jumpTo);
         $tags = $tagsandlist['tags'];
         $taglist = $tagsandlist['taglist'];
         $objTemplate->showTagClass = $this->tag_named_class;
         $objTemplate->tags = $tags;
         $objTemplate->taglist = $taglist;
         $objTemplate->news = 'IN';
     }
     // nav
     $strUrl = '';
     $objArchive = \NewsArchiveModel::findByPk($objArticle->pid);
     if ($objArchive !== null && $objArchive->jumpTo && ($objTarget = $objArchive->getRelated('jumpTo')) !== null) {
         $strUrl = $this->generateFrontendUrl($objTarget->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/news/%s');
     }
     $objTemplate->nav = static::generateArrowNavigation($objArticle, $strUrl, $this->news_readerModule);
     // Clean the RTE output
     if ($objArticle->teaser != '') {
         $objTemplate->hasTeaser = true;
         if ($objPage->outputFormat == 'xhtml') {
             $objTemplate->teaser = \String::toXhtml($objArticle->teaser);
         } else {
             $objTemplate->teaser = \String::toHtml5($objArticle->teaser);
         }
         $objTemplate->teaser = \String::encodeEmail($objTemplate->teaser);
     }
     // Display the "read more" button for external/article links
     if ($objArticle->source != 'default') {
         $objTemplate->text = true;
         $objTemplate->hasText = true;
     } else {
         $id = $objArticle->id;
         $objTemplate->text = function () use($id) {
             $strText = '';
             $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_news');
             if ($objElement !== null) {
                 while ($objElement->next()) {
                     $strText .= $this->getContentElement($objElement->current());
                 }
             }
             return $strText;
         };
         $objTemplate->hasText = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news') !== null;
     }
     $arrMeta = $this->getMetaFields($objArticle);
     // Add the meta information
     $objTemplate->date = $arrMeta['date'];
     $objTemplate->hasMetaFields = !empty($arrMeta);
     $objTemplate->numberOfComments = $arrMeta['ccount'];
     $objTemplate->commentCount = $arrMeta['comments'];
     $objTemplate->timestamp = $objArticle->date;
     $objTemplate->author = $arrMeta['author'];
     $objTemplate->datetime = date('Y-m-d\\TH:i:sP', $objArticle->date);
     $objTemplate->addImage = false;
     // Add an image
     if ($objArticle->addImage && $objArticle->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objArticle->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objArticle->singleSRC)) {
                 $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             // Do not override the field now that we have a model registry (see #6303)
             $arrArticle = $objArticle->row();
             // Override the default image size
             if ($this->imgSize != '') {
                 $size = deserialize($this->imgSize);
                 if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
                     $arrArticle['size'] = $this->imgSize;
                 }
             }
             $arrArticle['singleSRC'] = $objModel->path;
             $this->addImageToTemplate($objTemplate, $arrArticle);
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures
     if ($objArticle->addEnclosure) {
         $this->addEnclosuresToTemplate($objTemplate, $objArticle->row());
     }
     if (in_array('share', \ModuleLoader::getActive())) {
         $objArticle->title = $objArticle->headline;
         $objShare = new \HeimrichHannot\Share\Share($this->objModel, $objArticle);
         $objTemplate->share = $objShare->generate();
     }
     // Modal
     if ($this->news_showInModal && $objArticle->source == 'default' && $this->news_readerModule) {
         $objTemplate->modal = true;
         $objTemplate->modalTarget = '#' . NewsPlusHelper::getCSSModalID($this->news_readerModule);
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['parseArticles']) && is_array($GLOBALS['TL_HOOKS']['parseArticles'])) {
         foreach ($GLOBALS['TL_HOOKS']['parseArticles'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objTemplate, $objArticle->row(), $this);
         }
     }
     return $objTemplate->parse();
 }
 /**
  * Generate content element
  */
 protected function compile()
 {
     global $objPage;
     $this->import('String');
     $arrDownloadFiles = array();
     $time = time();
     foreach ($this->arrDownloadfiles as $k => $archive) {
         $objArchive = \FelixPfeiffer\Downloadarchive\DownloadarchiveModel::findByPk($k);
         $strLightboxId = 'lightbox[' . substr(md5($objArchive->title . '_' . $objArchive->id), 0, 6) . ']';
         foreach ($archive as $f => $arrFile) {
             #$objFile = \FilesModel::findByUuid($arrFile['singleSRC']);
             $objFile = new \File($f, true);
             // Clean the RTE output
             if ($objPage->outputFormat == 'xhtml') {
                 $arrFile['description'] = \String::toXhtml($arrFile['description']);
             } else {
                 $arrFile['description'] = \String::toHtml5($arrFile['description']);
             }
             $arrFile['description'] = \String::encodeEmail($arrFile['description']);
             $arrFile['css'] = $objArchive->class != "" ? $objArchive->class . ' ' : '';
             $arrFile['ctime'] = $objFile->ctime;
             $arrFile['ctimeformated'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $objFile->ctime);
             $arrFile['mtime'] = $objFile->mtime;
             $arrFile['mtimeformated'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $objFile->mtime);
             $arrFile['atime'] = $objFile->mtime;
             $arrFile['atimeformated'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $objFile->atime);
             // Add an image
             if ($arrFile['addImage'] && $arrFile['imgSRC'] != '') {
                 $objModel = \FilesModel::findByUuid($arrFile['imgSRC']);
                 if (is_file(TL_ROOT . '/' . $objModel->path)) {
                     $size = deserialize($arrFile['size']);
                     $arrFile['imgSRC'] = $arrFile['imgSrc'] = \Image::get($objModel->path, $size[0], $size[1], $size[2]);
                     // Image dimensions
                     if (($imgSize = @getimagesize(TL_ROOT . '/' . rawurldecode($arrFile['imgSRC']))) !== false) {
                         $arrFile['arrSize'] = $imgSize;
                         $arrFile['imageSize'] = ' ' . $imgSize[3];
                     }
                     $arrFile['imgHref'] = $objModel->path;
                     $arrFile['alt'] = specialchars($arrFile['alt']);
                     $arrFile['imagemargin'] = $this->generateMargin(deserialize($arrFile['imagemargin']), 'padding');
                     $arrFile['floating'] = in_array($arrFile['floating'], array('left', 'right')) ? sprintf(' float:%s;', $arrFile['floating']) : '';
                     $arrFile['addImage'] = true;
                     $arrFile['lightbox'] = $objPage->outputFormat == 'xhtml' || VERSION < 2.11 ? ' rel="' . $strLightboxId . '"' : ' data-lightbox="' . substr($strLightboxId, 9, -1) . '"';
                 }
             }
             $arrFile['size'] = $this->getReadableSize($objFile->filesize);
             $src = TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon;
             if (($imgSize = @getimagesize(TL_ROOT . '/' . $src)) !== false) {
                 $arrFile['iconSize'] = ' ' . $imgSize[3];
             }
             $arrFile['icon'] = $src;
             $arrFile['href'] = $this->Environment->request . (stristr($this->Environment->request, '?') ? '&' : '?') . 'file=' . $this->urlEncode($f);
             $arrFile['archive'] = $objArchive->title;
             $strSorting = str_replace(array(' ASC', ' DESC'), '', $this->downloadSorting);
             $arrDownloadFiles[$arrFile[$strSorting]][] = $arrFile;
         }
     }
     if (stristr($this->downloadSorting, 'DESC')) {
         krsort($arrDownloadFiles);
     } else {
         ksort($arrDownloadFiles);
     }
     $arrFiles = array();
     foreach ($arrDownloadFiles as $row) {
         foreach ($row as $file) {
             $arrFiles[] = $file;
         }
     }
     if ($this->downloadNumberOfItems > 0) {
         $arrFiles = array_slice($arrFiles, 0, $this->downloadNumberOfItems);
     }
     $i = 0;
     $length = count($arrFiles);
     if ($this->perPage > 0) {
         // Get the current page
         $page = $this->Input->get('page') ? $this->Input->get('page') : 1;
         if ($page > $length / $this->perPage) {
             $page = ceil($length / $this->perPage);
         }
         $offset = (($page > 1 ? $page : 1) - 1) * $this->perPage;
         $arrFiles = array_slice($arrFiles, $offset, $this->perPage);
         // Add pagination menu
         $objPagination = new Pagination($length, $this->perPage);
         $this->Template->pagination = $objPagination->generate("\n  ");
         $length = count($arrFiles);
     }
     foreach ($arrFiles as $file) {
         $class = "";
         if ($i++ == 0) {
             $class = "first ";
         }
         $class .= $i % 2 == 0 ? "even" : "odd";
         if ($i == $length) {
             $class .= " last";
         }
         $arrFiles[$i - 1]['css'] .= $class;
     }
     if (count($arrFiles) < 1) {
         $this->Template->arrFiles = $GLOBALS['TL_LANG']['MSC']['keinDownload'];
     } else {
         $this->Template->showMeta = $this->downloadShowMeta ? true : false;
         $this->Template->hideDate = $this->downloadHideDate ? true : false;
         $this->Template->arrFiles = $arrFiles;
     }
 }
Exemple #27
0
 /**
  * Add an event to the array of active events
  * @param object
  * @param integer
  * @param integer
  * @param string
  * @param string
  */
 protected function addEvent($objEvent, $intStart, $intEnd, $strUrl, $strBase)
 {
     if ($intEnd < time()) {
         return;
     }
     global $objPage;
     // Called in the back end (see #4026)
     if ($objPage === null) {
         $objPage = new \stdClass();
         $objPage->dateFormat = \Config::get('dateFormat');
         $objPage->datimFormat = \Config::get('datimFormat');
         $objPage->timeFormat = \Config::get('timeFormat');
     }
     $intKey = date('Ymd', $intStart);
     $span = self::calculateSpan($intStart, $intEnd);
     $format = $objEvent->addTime ? 'datimFormat' : 'dateFormat';
     // Add date
     if ($span > 0) {
         $title = \Date::parse($objPage->{$format}, $intStart) . ' - ' . \Date::parse($objPage->{$format}, $intEnd);
     } else {
         $title = \Date::parse($objPage->dateFormat, $intStart) . ($objEvent->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStart) . ($intStart < $intEnd ? ' - ' . \Date::parse($objPage->timeFormat, $intEnd) : '') . ')' : '');
     }
     // Add title and link
     $title .= ' ' . $objEvent->title;
     $link = '';
     switch ($objEvent->source) {
         case 'external':
             $link = $objEvent->url;
             break;
         case 'internal':
             if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) {
                 $link = $strBase . $this->generateFrontendUrl($objTarget->row());
             }
             break;
         case 'article':
             if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                 $link = $strBase . ampersand($this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
             }
             break;
     }
     // Link to the default page
     if ($link == '') {
         $link = $strBase . sprintf($strUrl, $objEvent->alias != '' && !\Config::get('disableAlias') ? $objEvent->alias : $objEvent->id);
     }
     // Store the whole row (see #5085)
     $arrEvent = $objEvent->row();
     // Override link and title
     $arrEvent['link'] = $link;
     $arrEvent['title'] = $title;
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $arrEvent['teaser'] = \String::toXhtml($objEvent->teaser);
     } else {
         $arrEvent['teaser'] = \String::toHtml5($objEvent->teaser);
     }
     // Reset the enclosures (see #5685)
     $arrEvent['enclosure'] = array();
     // Add the article image as enclosure
     if ($objEvent->addImage) {
         $objFile = \FilesModel::findByUuid($objEvent->singleSRC);
         if ($objFile !== null) {
             $arrEvent['enclosure'][] = $objFile->path;
         }
     }
     // Enclosures
     if ($objEvent->addEnclosure) {
         $arrEnclosure = deserialize($objEvent->enclosure, true);
         if (is_array($arrEnclosure)) {
             $objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
             if ($objFile !== null) {
                 while ($objFile->next()) {
                     $arrEvent['enclosure'][] = $objFile->path;
                 }
             }
         }
     }
     $this->arrEvents[$intKey][$intStart][] = $arrEvent;
 }
 /**
  * Gibt die Ausgabe entsprechend der Einstellungen in HTML5 oder XHTML zurück
  *
  * @param string welcher konvertiert werden soll
  * @return  string konvertierter String
  */
 protected function _getCleanRteOutput($strOutput)
 {
     global $objPage;
     // Clean the RTE output
     if ($strOutput != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $strOutput = \String::toXhtml($strOutput);
         } else {
             $strOutput = \String::toHtml5($strOutput);
         }
     }
     return $strOutput;
 }
Exemple #29
0
 /**
  * Add comments to a template
  * @param \FrontendTemplate
  * @param \stdClass
  * @param string
  * @param integer
  * @param array
  */
 public function addCommentsToTemplate(\FrontendTemplate $objTemplate, \stdClass $objConfig, $strSource, $intParent, $arrNotifies)
 {
     global $objPage;
     $limit = 0;
     $offset = 0;
     $total = 0;
     $gtotal = 0;
     $arrComments = array();
     $objTemplate->comments = array();
     // see #4064
     // Pagination
     if ($objConfig->perPage > 0) {
         // Get the total number of comments
         $intTotal = \CommentsModel::countPublishedBySourceAndParent($strSource, $intParent);
         $total = $gtotal = $intTotal;
         // Get the current page
         $id = 'page_c' . $this->id;
         $page = \Input::get($id) ?: 1;
         // Do not index or cache the page if the page number is outside the range
         if ($page < 1 || $page > max(ceil($total / $objConfig->perPage), 1)) {
             global $objPage;
             $objPage->noSearch = 1;
             $objPage->cache = 0;
             // Send a 404 header
             header('HTTP/1.1 404 Not Found');
             $objTemplate->allowComments = false;
             return;
         }
         // Set limit and offset
         $limit = $objConfig->perPage;
         $offset = ($page - 1) * $objConfig->perPage;
         // Initialize the pagination menu
         $objPagination = new \Pagination($total, $objConfig->perPage, 7, $id);
         $objTemplate->pagination = $objPagination->generate("\n  ");
     }
     $objTemplate->allowComments = true;
     // Get all published comments
     if ($limit) {
         $objComments = \CommentsModel::findPublishedBySourceAndParent($strSource, $intParent, $limit, $offset);
     } else {
         $objComments = \CommentsModel::findPublishedBySourceAndParent($strSource, $intParent);
     }
     if ($objComments !== null && ($total = $objComments->count()) > 0) {
         $count = 0;
         if ($objConfig->template == '') {
             $objConfig->template = 'com_default';
         }
         $objPartial = new \FrontendTemplate($objConfig->template);
         while ($objComments->next()) {
             $objPartial->setData($objComments->row());
             // Clean the RTE output
             if ($objPage->outputFormat == 'xhtml') {
                 $objComments->comment = \String::toXhtml($objComments->comment);
             } else {
                 $objComments->comment = \String::toHtml5($objComments->comment);
             }
             $objPartial->comment = trim(str_replace(array('{{', '}}'), array('&#123;&#123;', '&#125;&#125;'), $objComments->comment));
             $objPartial->datim = $this->parseDate($objPage->datimFormat, $objComments->date);
             $objPartial->date = $this->parseDate($objPage->dateFormat, $objComments->date);
             $objPartial->class = ($count < 1 ? ' first' : '') . ($count >= $total - 1 ? ' last' : '') . ($count % 2 == 0 ? ' even' : ' odd');
             $objPartial->by = $GLOBALS['TL_LANG']['MSC']['comment_by'];
             $objPartial->id = 'c' . $objComments->id;
             $objPartial->timestamp = $objComments->date;
             $objPartial->datetime = date('Y-m-d\\TH:i:sP', $objComments->date);
             $objPartial->addReply = false;
             // Reply
             if ($objComments->addReply && $objComments->reply != '') {
                 if (($objAuthor = $objComments->getRelated('author')) !== null) {
                     $objPartial->addReply = true;
                     $objPartial->rby = $GLOBALS['TL_LANG']['MSC']['reply_by'];
                     $objPartial->reply = $this->replaceInsertTags($objComments->reply);
                     $objPartial->author = $objAuthor;
                     // Clean the RTE output
                     if ($objPage->outputFormat == 'xhtml') {
                         $objPartial->reply = \String::toXhtml($objPartial->reply);
                     } else {
                         $objPartial->reply = \String::toHtml5($objPartial->reply);
                     }
                 }
             }
             $arrComments[] = $objPartial->parse();
             ++$count;
         }
     }
     $objTemplate->comments = $arrComments;
     $objTemplate->addComment = $GLOBALS['TL_LANG']['MSC']['addComment'];
     $objTemplate->name = $GLOBALS['TL_LANG']['MSC']['com_name'];
     $objTemplate->email = $GLOBALS['TL_LANG']['MSC']['com_email'];
     $objTemplate->website = $GLOBALS['TL_LANG']['MSC']['com_website'];
     $objTemplate->commentsTotal = $limit ? $gtotal : $total;
     // Get the front end user object
     $this->import('FrontendUser', 'User');
     // Access control
     if ($objConfig->requireLogin && !BE_USER_LOGGED_IN && !FE_USER_LOGGED_IN) {
         $objTemplate->requireLogin = true;
         return;
     }
     // Form fields
     $arrFields = array('name' => array('name' => 'name', 'label' => $GLOBALS['TL_LANG']['MSC']['com_name'], 'value' => trim($this->User->firstname . ' ' . $this->User->lastname), 'inputType' => 'text', 'eval' => array('mandatory' => true, 'maxlength' => 64)), 'email' => array('name' => 'email', 'label' => $GLOBALS['TL_LANG']['MSC']['com_email'], 'value' => $this->User->email, 'inputType' => 'text', 'eval' => array('rgxp' => 'email', 'mandatory' => true, 'maxlength' => 128, 'decodeEntities' => true)), 'website' => array('name' => 'website', 'label' => $GLOBALS['TL_LANG']['MSC']['com_website'], 'inputType' => 'text', 'eval' => array('rgxp' => 'url', 'maxlength' => 128, 'decodeEntities' => true)));
     // Captcha
     if (!$objConfig->disableCaptcha) {
         $arrFields['captcha'] = array('name' => 'captcha', 'inputType' => 'captcha', 'eval' => array('mandatory' => true));
     }
     // Comment field
     $arrFields['comment'] = array('name' => 'comment', 'label' => $GLOBALS['TL_LANG']['MSC']['com_comment'], 'inputType' => 'textarea', 'eval' => array('mandatory' => true, 'rows' => 4, 'cols' => 40, 'preserveTags' => true));
     $doNotSubmit = false;
     $arrWidgets = array();
     $strFormId = 'com_' . $strSource . '_' . $intParent;
     // Initialize widgets
     foreach ($arrFields as $arrField) {
         $strClass = $GLOBALS['TL_FFL'][$arrField['inputType']];
         // Continue if the class is not defined
         if (!$this->classFileExists($strClass)) {
             continue;
         }
         $arrField['eval']['required'] = $arrField['eval']['mandatory'];
         $objWidget = new $strClass($this->prepareForWidget($arrField, $arrField['name'], $arrField['value']));
         // Validate the widget
         if (\Input::post('FORM_SUBMIT') == $strFormId) {
             $objWidget->validate();
             if ($objWidget->hasErrors()) {
                 $doNotSubmit = true;
             }
         }
         $arrWidgets[$arrField['name']] = $objWidget;
     }
     $objTemplate->fields = $arrWidgets;
     $objTemplate->submit = $GLOBALS['TL_LANG']['MSC']['com_submit'];
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->messages = '';
     // Backwards compatibility
     $objTemplate->formId = $strFormId;
     $objTemplate->hasError = $doNotSubmit;
     // Do not index or cache the page with the confirmation message
     if ($_SESSION['TL_COMMENT_ADDED']) {
         global $objPage;
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         $objTemplate->confirm = $GLOBALS['TL_LANG']['MSC']['com_confirm'];
         $_SESSION['TL_COMMENT_ADDED'] = false;
     }
     // Add the comment
     if (!$doNotSubmit && \Input::post('FORM_SUBMIT') == $strFormId) {
         $strWebsite = $arrWidgets['website']->value;
         // Add http:// to the website
         if ($strWebsite != '' && !preg_match('@^(https?://|ftp://|mailto:|#)@i', $strWebsite)) {
             $strWebsite = 'http://' . $strWebsite;
         }
         // Do not parse any tags in the comment
         $strComment = htmlspecialchars(trim($arrWidgets['comment']->value));
         $strComment = str_replace(array('&amp;', '&lt;', '&gt;'), array('[&]', '[lt]', '[gt]'), $strComment);
         // Remove multiple line feeds
         $strComment = preg_replace('@\\n\\n+@', "\n\n", $strComment);
         // Parse BBCode
         if ($objConfig->bbcode) {
             $strComment = $this->parseBbCode($strComment);
         }
         // Prevent cross-site request forgeries
         $strComment = preg_replace('/(href|src|on[a-z]+)="[^"]*(contao\\/main\\.php|typolight\\/main\\.php|javascript|vbscri?pt|script|alert|document|cookie|window)[^"]*"+/i', '$1="#"', $strComment);
         $time = time();
         // Prepare the record
         $arrSet = array('source' => $strSource, 'parent' => $intParent, 'tstamp' => $time, 'name' => $arrWidgets['name']->value, 'email' => $arrWidgets['email']->value, 'website' => $strWebsite, 'comment' => $this->convertLineFeeds($strComment), 'ip' => $this->anonymizeIp(\Environment::get('ip')), 'date' => $time, 'published' => $objConfig->moderate ? '' : 1);
         $objComment = new \CommentsModel();
         $objComment->setRow($arrSet);
         $objComment->save();
         $insertId = $objComment->id;
         // HOOK: add custom logic
         if (isset($GLOBALS['TL_HOOKS']['addComment']) && is_array($GLOBALS['TL_HOOKS']['addComment'])) {
             foreach ($GLOBALS['TL_HOOKS']['addComment'] as $callback) {
                 $this->import($callback[0]);
                 $this->{$callback}[0]->{$callback}[1]($insertId, $arrSet, $this);
             }
         }
         // Notification
         $objEmail = new \Email();
         $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
         $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
         $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['com_subject'], \Environment::get('host'));
         // Convert the comment to plain text
         $strComment = strip_tags($strComment);
         $strComment = \String::decodeEntities($strComment);
         $strComment = str_replace(array('[&]', '[lt]', '[gt]'), array('&', '<', '>'), $strComment);
         // Add comment details
         $objEmail->text = sprintf($GLOBALS['TL_LANG']['MSC']['com_message'], $arrSet['name'] . ' (' . $arrSet['email'] . ')', $strComment, \Environment::get('base') . \Environment::get('request'), \Environment::get('base') . 'contao/main.php?do=comments&act=edit&id=' . $insertId);
         // Do not send notifications twice
         if (is_array($arrNotifies)) {
             $arrNotifies = array_unique($arrNotifies);
         }
         $objEmail->sendTo($arrNotifies);
         // Pending for approval
         if ($objConfig->moderate) {
             $_SESSION['TL_COMMENT_ADDED'] = true;
         }
         $this->reload();
     }
 }
 /**
  * Parse an item and return it as string
  *
  * @param \NewsModel $objArticle
  * @param boolean    $blnAddArchive
  * @param string     $strClass
  * @param integer    $intCount
  *
  * @return string
  */
 protected function parseArticle($objArticle, $blnAddArchive = false, $strClass = '', $intCount = 0)
 {
     /** @var \PageModel $objPage */
     global $objPage;
     /** @var \FrontendTemplate|object $objTemplate */
     $objTemplate = new \FrontendTemplate($this->news_template);
     $objTemplate->setData($objArticle->row());
     $objTemplate->class = ($objArticle->cssClass != '' ? ' ' . $objArticle->cssClass : '') . $strClass;
     $objTemplate->newsHeadline = $objArticle->headline;
     $objTemplate->subHeadline = $objArticle->subheadline;
     $objTemplate->hasSubHeadline = $objArticle->subheadline ? true : false;
     $objTemplate->linkHeadline = $this->generateLink($objArticle->headline, $objArticle, $blnAddArchive);
     $objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objArticle, $blnAddArchive, true);
     $objTemplate->link = $this->generateNewsUrl($objArticle, $blnAddArchive);
     $objTemplate->archive = $objArticle->getRelated('pid');
     $objTemplate->count = $intCount;
     // see #5708
     $objTemplate->text = '';
     // Clean the RTE output
     if ($objArticle->teaser != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $objTemplate->teaser = \String::toXhtml($objArticle->teaser);
         } else {
             $objTemplate->teaser = \String::toHtml5($objArticle->teaser);
         }
         $objTemplate->teaser = \String::encodeEmail($objTemplate->teaser);
     }
     // Display the "read more" button for external/article links
     if ($objArticle->source != 'default') {
         $objTemplate->text = true;
     } else {
         $id = $objArticle->id;
         $objTemplate->text = function () use($id) {
             $strText = '';
             $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_news');
             if ($objElement !== null) {
                 while ($objElement->next()) {
                     $strText .= $this->getContentElement($objElement->current());
                 }
             }
             return $strText;
         };
     }
     $arrMeta = $this->getMetaFields($objArticle);
     // Add the meta information
     $objTemplate->date = $arrMeta['date'];
     $objTemplate->hasMetaFields = !empty($arrMeta);
     $objTemplate->numberOfComments = $arrMeta['ccount'];
     $objTemplate->commentCount = $arrMeta['comments'];
     $objTemplate->timestamp = $objArticle->date;
     $objTemplate->author = $arrMeta['author'];
     $objTemplate->datetime = date('Y-m-d\\TH:i:sP', $objArticle->date);
     $objTemplate->addImage = false;
     // Add an image
     if ($objArticle->addImage && $objArticle->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objArticle->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objArticle->singleSRC)) {
                 $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             // Do not override the field now that we have a model registry (see #6303)
             $arrArticle = $objArticle->row();
             // Override the default image size
             if ($this->imgSize != '') {
                 $size = deserialize($this->imgSize);
                 if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
                     $arrArticle['size'] = $this->imgSize;
                 }
             }
             $arrArticle['singleSRC'] = $objModel->path;
             $this->addImageToTemplate($objTemplate, $arrArticle);
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures
     if ($objArticle->addEnclosure) {
         $this->addEnclosuresToTemplate($objTemplate, $objArticle->row());
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['parseArticles']) && is_array($GLOBALS['TL_HOOKS']['parseArticles'])) {
         foreach ($GLOBALS['TL_HOOKS']['parseArticles'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objTemplate, $objArticle->row(), $this);
         }
     }
     return $objTemplate->parse();
 }