Пример #1
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \StringUtil::toXhtml($this->text);
     } else {
         $this->text = \StringUtil::toHtml5($this->text);
     }
     // Add the static files URL to images
     if (TL_FILES_URL != '') {
         $path = \Config::get('uploadPath') . '/';
         $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text);
     }
     $this->Template->text = \StringUtil::encodeEmail($this->text);
     $this->Template->addImage = false;
     // Add an image
     if ($this->addImage && $this->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($this->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($this->singleSRC)) {
                 $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             $this->singleSRC = $objModel->path;
             $this->addImageToTemplate($this->Template, $this->arrData);
         }
     }
 }
Пример #2
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \StringUtil::toXhtml($this->text);
     } else {
         $this->text = \StringUtil::toHtml5($this->text);
     }
     $this->Template->text = \StringUtil::encodeEmail($this->text);
     $this->Template->addImage = false;
     // Add an image
     if ($this->addImage && $this->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($this->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($this->singleSRC)) {
                 $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             $this->singleSRC = $objModel->path;
             $this->addImageToTemplate($this->Template, $this->arrData);
         }
     }
     $classes = deserialize($this->mooClasses);
     $this->Template->toggler = $classes[0] ?: 'toggler';
     $this->Template->accordion = $classes[1] ?: 'accordion';
     $this->Template->headlineStyle = $this->mooStyle;
     $this->Template->headline = $this->mooHeadline;
 }
Пример #3
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 = \StringUtil::toXhtml($this->text);
     } else {
         $this->text = \StringUtil::toHtml5($this->text);
     }
     return $this->text;
 }
 /**
  * Generate the widget and return it as string
  *
  * @return string The widget markup
  */
 public function generate()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \StringUtil::toXhtml($this->text);
     } else {
         $this->text = \StringUtil::toHtml5($this->text);
     }
     // Add the static files URL to images
     if (TL_FILES_URL != '') {
         $path = \Config::get('uploadPath') . '/';
         $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text);
     }
     return \StringUtil::encodeEmail($this->text);
 }
 protected function generateFields($objItem)
 {
     $arrItem = parent::generateFields($objItem);
     global $objPage;
     $arrItem['fields']['newsHeadline'] = $objItem->headline;
     $arrItem['fields']['subHeadline'] = $objItem->subheadline;
     $arrItem['fields']['hasSubHeadline'] = $objItem->subheadline ? true : false;
     $arrItem['fields']['linkHeadline'] = ModuleNews::generateLink($this, $objItem->headline, $objItem, false);
     $arrItem['fields']['more'] = ModuleNews::generateLink($this, $GLOBALS['TL_LANG']['MSC']['more'], $objItem, false, true);
     $arrItem['fields']['link'] = ModuleNews::generateNewsUrl($this, $objItem, false);
     $arrItem['fields']['text'] = '';
     // Clean the RTE output
     if ($objItem->teaser != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $arrItem['fields']['teaser'] = \StringUtil::toXhtml($objItem->teaser);
         } else {
             $arrItem['fields']['teaser'] = \StringUtil::toHtml5($objItem->teaser);
         }
         $arrItem['fields']['teaser'] = \StringUtil::encodeEmail($arrItem['fields']['teaser']);
     }
     // Display the "read more" button for external/article links
     if ($objItem->source != 'default') {
         $arrItem['fields']['text'] = true;
     } else {
         $objElement = \ContentModel::findPublishedByPidAndTable($objItem->id, 'tl_news');
         if ($objElement !== null) {
             while ($objElement->next()) {
                 $arrItem['fields']['text'] .= $this->getContentElement($objElement->current());
             }
         }
     }
     $arrMeta = ModuleNews::getMetaFields($this, $objItem);
     // Add the meta information
     $arrItem['fields']['date'] = $arrMeta['date'];
     $arrItem['fields']['hasMetaFields'] = !empty($arrMeta);
     $arrItem['fields']['numberOfComments'] = $arrMeta['ccount'];
     $arrItem['fields']['commentCount'] = $arrMeta['comments'];
     $arrItem['fields']['timestamp'] = $objItem->date;
     $arrItem['fields']['author'] = $arrMeta['author'];
     $arrItem['fields']['datetime'] = date('Y-m-d\\TH:i:sP', $objItem->date);
     $arrItem['fields']['addImage'] = false;
     // Add an image
     $this->addImage($objItem, 'singleSRC', $arrItem);
     // enclosures are added in runBeforeTemplateParsing
     return $arrItem;
 }
Пример #6
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     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->objParent->getFrontendUrl($link);
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->Template->text = \StringUtil::toXhtml($objArticle->teaser);
     } else {
         $this->Template->text = \StringUtil::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'];
 }
Пример #7
0
 /**
  * Generate content element
  */
 protected function compile()
 {
     global $objPage;
     if ($this->teaser_page_link) {
         $objArticle = $this->Database->prepare("\n\t\t\t\tSELECT\n\t\t\t\t\tp.id AS id,\n\t\t\t\t\tp.alias AS alias,\n\t\t\t\t\ta.id AS aid,\n\t\t\t\t\ta.title AS title,\n\t\t\t\t\ta.alias AS aalias,\n\t\t\t\t\ta.teaser AS teaser,\n\t\t\t\t\ta.inColumn AS inColumn,\n\t\t\t\t\ta.cssID AS cssID\n\t\t\t\tFROM\n\t\t\t\t\ttl_article a,\n\t\t\t\t\ttl_page p\n\t\t\t\tWHERE\n\t\t\t\t\ta.id=?\n\t\t\t\t\tAND a.pid=p.id\n\t\t\t")->limit(1)->execute($this->article);
         if ($objArticle->numRows < 1) {
             return;
         }
         $link = $this->generateFrontendUrl($objArticle->row());
         if (version_compare(VERSION, '2.9', '>')) {
             // Clean the RTE output
             if ($objPage->outputFormat == 'xhtml') {
                 $articleTeaser = \StringUtil::toXhtml($objArticle->teaser);
             } else {
                 $articleTeaser = \StringUtil::toHtml5($objArticle->teaser);
             }
         } else {
             $articleTeaser = $objArticle->teaser;
         }
         if ($this->teaser_fragment_identifier) {
             $cssID = deserialize($objArticle->cssID, true);
             if (strlen($cssID[0])) {
                 $link .= '#' . $cssID[0];
             } else {
                 $link .= '#' . $objArticle->aalias;
             }
         }
         $this->Template->href = $link;
         $this->Template->headline = $objArticle->title;
         $this->Template->text = $articleTeaser;
         $this->Template->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->title));
         $this->Template->more = $GLOBALS['TL_LANG']['MSC']['more'];
     } else {
         parent::compile();
     }
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     $objFaq = \FaqModel::findPublishedByPids($this->faq_categories);
     if ($objFaq === null) {
         $this->Template->faq = array();
         return;
     }
     /** @var \PageModel $objPage */
     global $objPage;
     $arrFaqs = array_fill_keys($this->faq_categories, array());
     // Add FAQs
     while ($objFaq->next()) {
         /** @var \FaqModel $objFaq */
         $objTemp = (object) $objFaq->row();
         // Clean RTE output
         if ($objPage->outputFormat == 'xhtml') {
             $objTemp->answer = \StringUtil::toXhtml($objFaq->answer);
         } else {
             $objTemp->answer = \StringUtil::toHtml5($objFaq->answer);
         }
         $objTemp->answer = \StringUtil::encodeEmail($objTemp->answer);
         $objTemp->addImage = false;
         // Add an image
         if ($objFaq->addImage && $objFaq->singleSRC != '') {
             $objModel = \FilesModel::findByUuid($objFaq->singleSRC);
             if ($objModel === null) {
                 if (!\Validator::isUuid($objFaq->singleSRC)) {
                     $objTemp->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
                 }
             } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
                 // Do not override the field now that we have a model registry (see #6303)
                 $arrFaq = $objFaq->row();
                 $arrFaq['singleSRC'] = $objModel->path;
                 $strLightboxId = 'lightbox[' . substr(md5('mod_faqpage_' . $objFaq->id), 0, 6) . ']';
                 // see #5810
                 $this->addImageToTemplate($objTemp, $arrFaq, null, $strLightboxId);
             }
         }
         $objTemp->enclosure = array();
         // Add enclosure
         if ($objFaq->addEnclosure) {
             $this->addEnclosuresToTemplate($objTemp, $objFaq->row());
         }
         /** @var \UserModel $objAuthor */
         $objAuthor = $objFaq->getRelated('author');
         $objTemp->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], \Date::parse($objPage->dateFormat, $objFaq->tstamp), $objAuthor->name);
         /** @var \FaqCategoryModel $objPid */
         $objPid = $objFaq->getRelated('pid');
         // Order by PID
         $arrFaqs[$objFaq->pid]['items'][] = $objTemp;
         $arrFaqs[$objFaq->pid]['headline'] = $objPid->headline;
         $arrFaqs[$objFaq->pid]['title'] = $objPid->title;
     }
     $arrFaqs = array_values(array_filter($arrFaqs));
     $limit_i = count($arrFaqs) - 1;
     // Add classes first, last, even and odd
     for ($i = 0; $i <= $limit_i; $i++) {
         $class = ($i == 0 ? 'first ' : '') . ($i == $limit_i ? 'last ' : '') . ($i % 2 == 0 ? 'even' : 'odd');
         $arrFaqs[$i]['class'] = trim($class);
         $limit_j = count($arrFaqs[$i]['items']) - 1;
         for ($j = 0; $j <= $limit_j; $j++) {
             $class = ($j == 0 ? 'first ' : '') . ($j == $limit_j ? 'last ' : '') . ($j % 2 == 0 ? 'even' : 'odd');
             $arrFaqs[$i]['items'][$j]->class = trim($class);
         }
     }
     $this->Template->faq = $arrFaqs;
     $this->Template->request = \Environment::get('indexFreeRequest');
     $this->Template->topLink = $GLOBALS['TL_LANG']['MSC']['backToTop'];
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     $this->Template->referer = 'javascript:history.go(-1)';
     $objFaq = \FaqModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->faq_categories);
     if (null === $objFaq) {
         /** @var \PageError404 $objHandler */
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
     }
     // Overwrite the page title and description (see #2853 and #4955)
     if ($objFaq->question != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($objFaq->question));
         $objPage->description = $this->prepareMetaDescription($objFaq->question);
     }
     $this->Template->question = $objFaq->question;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $objFaq->answer = \StringUtil::toXhtml($objFaq->answer);
     } else {
         $objFaq->answer = \StringUtil::toHtml5($objFaq->answer);
     }
     $this->Template->answer = \StringUtil::encodeEmail($objFaq->answer);
     $this->Template->addImage = false;
     // Add image
     if ($objFaq->addImage && $objFaq->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objFaq->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objFaq->singleSRC)) {
                 $this->Template->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             // Do not override the field now that we have a model registry (see #6303)
             $arrFaq = $objFaq->row();
             $arrFaq['singleSRC'] = $objModel->path;
             $this->addImageToTemplate($this->Template, $arrFaq);
         }
     }
     $this->Template->enclosure = array();
     // Add enclosure
     if ($objFaq->addEnclosure) {
         $this->addEnclosuresToTemplate($this->Template, $objFaq->row());
     }
     $strAuthor = '';
     // Add the author
     if (($objAuthor = $objFaq->getRelated('author')) !== null) {
         $strAuthor = $objAuthor->name;
     }
     $this->Template->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], \Date::parse($objPage->dateFormat, $objFaq->tstamp), $strAuthor);
     // HOOK: comments extension required
     if ($objFaq->noComments || !in_array('comments', \ModuleLoader::getActive())) {
         $this->Template->allowComments = false;
         return;
     }
     /** @var \FaqCategoryModel $objCategory */
     $objCategory = $objFaq->getRelated('pid');
     $this->Template->allowComments = $objCategory->allowComments;
     // Comments are not allowed
     if (!$objCategory->allowComments) {
         return;
     }
     // Adjust the comments headline level
     $intHl = min(intval(str_replace('h', '', $this->hl)), 5);
     $this->Template->hlc = 'h' . ($intHl + 1);
     $this->import('Comments');
     $arrNotifies = array();
     // Notify the system administrator
     if ($objCategory->notify != 'notify_author') {
         $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
     }
     // Notify the author
     if ($objCategory->notify != 'notify_admin') {
         /** @var \UserModel $objAuthor */
         if (($objAuthor = $objFaq->getRelated('author')) !== null && $objAuthor->email != '') {
             $arrNotifies[] = $objAuthor->email;
         }
     }
     $objConfig = new \stdClass();
     $objConfig->perPage = $objCategory->perPage;
     $objConfig->order = $objCategory->sortOrder;
     $objConfig->template = $this->com_template;
     $objConfig->requireLogin = $objCategory->requireLogin;
     $objConfig->disableCaptcha = $objCategory->disableCaptcha;
     $objConfig->bbcode = $objCategory->bbcode;
     $objConfig->moderate = $objCategory->moderate;
     $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_faq', $objFaq->id, $arrNotifies);
 }
Пример #10
0
 /**
  * Generate content element
  */
 protected function compile()
 {
     if (TL_MODE == 'FE' || defined('EX_TL_MODE_FE')) {
         global $objPage;
     } else {
         $objArticle = \Database::getInstance()->prepare("SELECT `pid` FROM `tl_article` WHERE `id`=?")->execute($this->pid);
         if ($objArticle->next()) {
             $objPage = \Database::getInstance()->prepare("SELECT * FROM `tl_page` WHERE `id`=?")->execute($objArticle->pid)->next();
         }
     }
     $rootPage = $this->getRootPage($objPage->id);
     if (TL_MODE == 'BE' && !defined('EX_TL_MODE_FE')) {
         $objPage->domain = $rootPage['dns'];
         $objPage->rootLanguage = $rootPage['language'];
     }
     $objTargetPage = \Database::getInstance()->prepare("\n\t\t\tSELECT\n\t\t\t\t`id`,\n\t\t\t\t`alias`,\n\t\t\t\t`title`,\n\t\t\t\t`type`\n\t\t\tFROM\n\t\t\t\t`tl_page`\n\t\t\tWHERE\n\t\t\t\t" . (!\Input::cookie('FE_PREVIEW') && TL_MODE == 'FE' ? "`published`='1' AND " : "") . "\n\t\t\t\t`id`=?")->limit(1)->execute($this->page_teaser_page);
     $link = '';
     if ($objTargetPage->numRows < 1) {
         $this->pageCode = -1;
         $this->pageLink = sprintf($GLOBALS['TL_LANG']['page_teaser']['not_found'], $this->page_teaser_page);
     } else {
         $targetId = $objTargetPage->id;
         if ($targetRoot = $this->getRootPage($objTargetPage->id)) {
             if ($objPage->domain != $targetRoot['dns']) {
                 $link = ($this->Environment->ssl ? 'https://' : 'http://') . $targetRoot['dns'] . '/';
             }
             if ($rootPage['id'] != $targetRoot['id']) {
                 $this->pageCode = 1;
             }
         }
         if ($objTargetPage->type != 'root') {
             if (version_compare(VERSION, '3.5', '>=')) {
                 $link = $this->generateFrontendUrl($objTargetPage->row(), null, null, true);
             } elseif (version_compare(VERSION, '2.10', '>') && $GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
                 $link .= $this->generateFrontendUrl($objTargetPage->row(), null, $targetRoot['language']);
             } else {
                 $link .= $this->generateFrontendUrl($objTargetPage->row());
             }
         }
     }
     $this->pageLink = $link;
     if (version_compare(VERSION, '2.9', '>')) {
         // Clean the RTE output
         if ($objPage->outputFormat == 'xhtml') {
             $this->text = \StringUtil::toXhtml($this->text);
         } else {
             $this->text = \StringUtil::toHtml5($this->text);
         }
     }
     // Add the static files URL to images
     if (TL_FILES_URL != '') {
         $path = $GLOBALS['TL_CONFIG']['uploadPath'] . '/';
         $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text);
     }
     $this->cssID = array($this->cssID[0], $this->cssID[1] . (PAGE_TEASER_JS_LINK == 1 ? ' ce_teaser_link' : ''));
     $this->Template->href = $link;
     $this->Template->headline = $this->headline;
     $this->Template->text = $this->text;
     $this->Template->showMore = $this->page_teaser_show_more;
     $this->Template->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objTargetPage->title));
     $this->Template->more = $GLOBALS['TL_LANG']['MSC']['more'];
     $this->Template->addImage = false;
     // Add an image
     if ($this->addImage && $this->singleSRC != '') {
         if (version_compare(VERSION, '3', '>=')) {
             if (version_compare(VERSION, '3.2', '>=')) {
                 $objModel = \FilesModel::findByUuid($this->singleSRC);
             } 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);
             }
         } else {
             if ($this->addImage && strlen($this->singleSRC) && is_file(TL_ROOT . '/' . $this->singleSRC)) {
                 $this->addImageToTemplate($this->Template, $this->arrData);
             }
         }
     }
 }
Пример #11
0
 /**
  * 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 = \StringUtil::toXhtml($objArticle->teaser);
         } else {
             $objTemplate->teaser = \StringUtil::toHtml5($objArticle->teaser);
         }
         $objTemplate->teaser = \StringUtil::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();
 }
Пример #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 \StringUtil::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 = \StringUtil::encodeEmail($elements[1]);
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'email':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" class="email">' . preg_replace('/\\?.*$/', '', $strEmail) . '</a>';
                         break;
                     case 'email_open':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" title="' . $strEmail . '" class="email">';
                         break;
                     case 'email_url':
                         $arrCache[$strTag] = $strEmail;
                         break;
                 }
                 break;
                 // Label tags
             // Label tags
             case 'label':
                 $keys = explode(':', $elements[1]);
                 if (count($keys) < 2) {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $file = $keys[0];
                 // Map the key (see #7217)
                 switch ($file) {
                     case 'CNT':
                         $file = 'countries';
                         break;
                     case 'LNG':
                         $file = 'languages';
                         break;
                     case 'MOD':
                     case 'FMD':
                         $file = 'modules';
                         break;
                     case 'FFL':
                         $file = 'tl_form_field';
                         break;
                     case 'CACHE':
                         $file = 'tl_page';
                         break;
                     case 'XPL':
                         $file = 'explain';
                         break;
                     case 'XPT':
                         $file = 'exception';
                         break;
                     case 'MSC':
                     case 'ERR':
                     case 'CTE':
                     case 'PTY':
                     case 'FOP':
                     case 'CHMOD':
                     case 'DAYS':
                     case 'MONTHS':
                     case 'UNITS':
                     case 'CONFIRM':
                     case 'DP':
                     case 'COLS':
                         $file = 'default';
                         break;
                 }
                 \System::loadLanguageFile($file);
                 if (count($keys) == 2) {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]];
                 } else {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]][$keys[2]];
                 }
                 break;
                 // Front end user
             // Front end user
             case 'user':
                 if (FE_USER_LOGGED_IN) {
                     $this->import('FrontendUser', 'User');
                     $value = $this->User->{$elements[1]};
                     if ($value == '') {
                         $arrCache[$strTag] = $value;
                         break;
                     }
                     $this->loadDataContainer('tl_member');
                     if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['inputType'] == 'password') {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $value = 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 = \StringUtil::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, $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] = $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':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, specialchars($objArticle->title), $objArticle->title);
                         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':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, specialchars($objFaq->question), $objFaq->question);
                         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':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, specialchars($objNews->headline), $objNews->headline);
                         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':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, specialchars($objEvent->title), $objEvent->title);
                         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] = \StringUtil::toXhtml($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     } else {
                         $arrCache[$strTag] = \StringUtil::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] = \StringUtil::toXhtml($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     } else {
                         $arrCache[$strTag] = \StringUtil::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] = \StringUtil::toXhtml($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     } else {
                         $arrCache[$strTag] = \StringUtil::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 = \StringUtil::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         list($key, $value) = explode('=', $strParam);
                         switch ($key) {
                             case 'width':
                                 $width = $value;
                                 break;
                             case 'height':
                                 $height = $value;
                                 break;
                             case 'alt':
                                 $alt = 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 = \StringUtil::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         $arrParam = explode('=', $strParam);
                         $_GET[$arrParam[0]] = $arrParam[1];
                     }
                     $strFile = $arrChunks[0];
                 }
                 // Check the path
                 if (\Validator::isInsecurePath($strFile)) {
                     throw new \RuntimeException('Invalid path ' . $strFile);
                 }
                 // Include .php, .tpl, .xhtml and .html5 files
                 if (preg_match('/\\.(php|tpl|xhtml|html5)$/', $strFile) && file_exists(TL_ROOT . '/templates/' . $strFile)) {
                     ob_start();
                     include TL_ROOT . '/templates/' . $strFile;
                     $arrCache[$strTag] = ob_get_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] = \StringUtil::$flag($arrCache[$strTag]);
                         break;
                     case 'number_format':
                         $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 0);
                         break;
                     case 'currency_format':
                         $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 2);
                         break;
                     case 'readable_size':
                         $arrCache[$strTag] = \System::getReadableSize($arrCache[$strTag]);
                         break;
                     case 'flatten':
                         if (!is_array($arrCache[$strTag])) {
                             break;
                         }
                         $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arrCache[$strTag]));
                         $result = array();
                         foreach ($it as $leafValue) {
                             $keys = array();
                             foreach (range(0, $it->getDepth()) as $depth) {
                                 $keys[] = $it->getSubIterator($depth)->key();
                             }
                             $result[] = implode('.', $keys) . ': ' . $leafValue;
                         }
                         $arrCache[$strTag] = implode(', ', $result);
                         break;
                         // HOOK: pass unknown flags to callback functions
                     // HOOK: pass unknown flags to callback functions
                     default:
                         if (isset($GLOBALS['TL_HOOKS']['insertTagFlags']) && is_array($GLOBALS['TL_HOOKS']['insertTagFlags'])) {
                             foreach ($GLOBALS['TL_HOOKS']['insertTagFlags'] as $callback) {
                                 $this->import($callback[0]);
                                 $varValue = $this->{$callback[0]}->{$callback[1]}($flag, $tag, $arrCache[$strTag], $flags, $blnCache, $tags, $arrCache, $_rit, $_cnt);
                                 // see #5806
                                 // Replace the tag and stop the loop
                                 if ($varValue !== false) {
                                     $arrCache[$strTag] = $varValue;
                                     break;
                                 }
                             }
                         }
                         if (\Config::get('debugMode')) {
                             $GLOBALS['TL_DEBUG']['unknown_insert_tag_flags'][] = $flag;
                         }
                         break;
                 }
             }
         }
         $strBuffer .= $arrCache[$strTag];
     }
     return \StringUtil::restoreBasicEntities($strBuffer);
 }
Пример #13
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $this->Template->event = '';
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     // Get the current event
     $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias(\Input::get('events'), $this->cal_calendar);
     if (null === $objEvent) {
         /** @var \PageError404 $objHandler */
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
     }
     // Overwrite the page title (see #2853 and #4955)
     if ($objEvent->title != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($objEvent->title));
     }
     // Overwrite the page description
     if ($objEvent->teaser != '') {
         $objPage->description = $this->prepareMetaDescription($objEvent->teaser);
     }
     $intStartTime = $objEvent->startTime;
     $intEndTime = $objEvent->endTime;
     $span = \Calendar::calculateSpan($intStartTime, $intEndTime);
     // Do not show dates in the past if the event is recurring (see #923)
     if ($objEvent->recurring) {
         $arrRange = deserialize($objEvent->repeatEach);
         if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) {
             while ($intStartTime < time() && $intEndTime < $objEvent->repeatEnd) {
                 $intStartTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intStartTime);
                 $intEndTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intEndTime);
             }
         }
     }
     $strDate = \Date::parse($objPage->dateFormat, $intStartTime);
     if ($span > 0) {
         $strDate = \Date::parse($objPage->dateFormat, $intStartTime) . ' – ' . \Date::parse($objPage->dateFormat, $intEndTime);
     }
     $strTime = '';
     if ($objEvent->addTime) {
         if ($span > 0) {
             $strDate = \Date::parse($objPage->datimFormat, $intStartTime) . ' – ' . \Date::parse($objPage->datimFormat, $intEndTime);
         } elseif ($intStartTime == $intEndTime) {
             $strTime = \Date::parse($objPage->timeFormat, $intStartTime);
         } else {
             $strTime = \Date::parse($objPage->timeFormat, $intStartTime) . ' – ' . \Date::parse($objPage->timeFormat, $intEndTime);
         }
     }
     $until = '';
     $recurring = '';
     // Recurring event
     if ($objEvent->recurring) {
         $arrRange = deserialize($objEvent->repeatEach);
         if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) {
             $strKey = 'cal_' . $arrRange['unit'];
             $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']);
             if ($objEvent->recurrences > 0) {
                 $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], \Date::parse($objPage->dateFormat, $objEvent->repeatEnd));
             }
         }
     }
     /** @var \FrontendTemplate|object $objTemplate */
     $objTemplate = new \FrontendTemplate($this->cal_template);
     $objTemplate->setData($objEvent->row());
     $objTemplate->date = $strDate;
     $objTemplate->time = $strTime;
     $objTemplate->datetime = $objEvent->addTime ? date('Y-m-d\\TH:i:sP', $intStartTime) : date('Y-m-d', $intStartTime);
     $objTemplate->begin = $intStartTime;
     $objTemplate->end = $intEndTime;
     $objTemplate->class = $objEvent->cssClass != '' ? ' ' . $objEvent->cssClass : '';
     $objTemplate->recurring = $recurring;
     $objTemplate->until = $until;
     $objTemplate->locationLabel = $GLOBALS['TL_LANG']['MSC']['location'];
     $objTemplate->details = '';
     $objTemplate->hasDetails = false;
     $objTemplate->hasTeaser = false;
     // Clean the RTE output
     if ($objEvent->teaser != '') {
         $objTemplate->hasTeaser = true;
         if ($objPage->outputFormat == 'xhtml') {
             $objTemplate->teaser = \StringUtil::toXhtml($objEvent->teaser);
         } else {
             $objTemplate->teaser = \StringUtil::toHtml5($objEvent->teaser);
         }
         $objTemplate->teaser = \StringUtil::encodeEmail($objTemplate->teaser);
     }
     // Display the "read more" button for external/article links
     if ($objEvent->source != 'default') {
         $objTemplate->details = true;
         $objTemplate->hasDetails = true;
     } else {
         $id = $objEvent->id;
         $objTemplate->details = function () use($id) {
             $strDetails = '';
             $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_calendar_events');
             if ($objElement !== null) {
                 while ($objElement->next()) {
                     $strDetails .= $this->getContentElement($objElement->current());
                 }
             }
             return $strDetails;
         };
         $objTemplate->hasDetails = \ContentModel::countPublishedByPidAndTable($id, 'tl_calendar_events') > 0;
     }
     $objTemplate->addImage = false;
     // Add an image
     if ($objEvent->addImage && $objEvent->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objEvent->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objEvent->singleSRC)) {
                 $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             // Do not override the field now that we have a model registry (see #6303)
             $arrEvent = $objEvent->row();
             // Override the default image size
             if ($this->imgSize != '') {
                 $size = deserialize($this->imgSize);
                 if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
                     $arrEvent['size'] = $this->imgSize;
                 }
             }
             $arrEvent['singleSRC'] = $objModel->path;
             $this->addImageToTemplate($objTemplate, $arrEvent);
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures
     if ($objEvent->addEnclosure) {
         $this->addEnclosuresToTemplate($objTemplate, $objEvent->row());
     }
     $this->Template->event = $objTemplate->parse();
     // HOOK: comments extension required
     if ($objEvent->noComments || !in_array('comments', \ModuleLoader::getActive())) {
         $this->Template->allowComments = false;
         return;
     }
     /** @var \CalendarModel $objCalendar */
     $objCalendar = $objEvent->getRelated('pid');
     $this->Template->allowComments = $objCalendar->allowComments;
     // Comments are not allowed
     if (!$objCalendar->allowComments) {
         return;
     }
     // Adjust the comments headline level
     $intHl = min(intval(str_replace('h', '', $this->hl)), 5);
     $this->Template->hlc = 'h' . ($intHl + 1);
     $this->import('Comments');
     $arrNotifies = array();
     // Notify the system administrator
     if ($objCalendar->notify != 'notify_author') {
         $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
     }
     // Notify the author
     if ($objCalendar->notify != 'notify_admin') {
         /** @var \UserModel $objAuthor */
         if (($objAuthor = $objEvent->getRelated('author')) !== null && $objAuthor->email != '') {
             $arrNotifies[] = $objAuthor->email;
         }
     }
     $objConfig = new \stdClass();
     $objConfig->perPage = $objCalendar->perPage;
     $objConfig->order = $objCalendar->sortOrder;
     $objConfig->template = $this->com_template;
     $objConfig->requireLogin = $objCalendar->requireLogin;
     $objConfig->disableCaptcha = $objCalendar->disableCaptcha;
     $objConfig->bbcode = $objCalendar->bbcode;
     $objConfig->moderate = $objCalendar->moderate;
     $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_calendar_events', $objEvent->id, $arrNotifies);
 }
 /**
  * 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 = \GalleryCreatorAlbumsModel::findByPk($intAlbumId);
     if ($objAlbum === null) {
         return;
     }
     // add meta tags to the page object
     if (TL_MODE == 'FE' && $this->viewMode == 'detail_view') {
         $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
     foreach ($objAlbum->row() as $k => $v) {
         $this->Template->arrAlbumdata = $objAlbum->row();
     }
     // 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' ? \StringUtil::toXhtml($objAlbum->comment) : \StringUtil::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->viewMode == '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;
     $this->Template->objElement = $this;
 }
Пример #15
0
 public function addTestimonialsToTemplate(\FrontendTemplate $objTemplate, \stdClass $objConfig, $intParent, $arrNotifies)
 {
     global $objPage;
     $limit = 0;
     $offset = 0;
     $total = 0;
     $gtotal = 0;
     $arrTestimonials = array();
     $objTemplate->testimonials = array();
     // Pagination
     if ($objConfig->perPage > 0) {
         // Get the total number of testimonials
         $intTotal = \TestimonialsModel::countPublishedTestimonials($intParent);
         $total = $gtotal = $intTotal;
         // Get the current page
         $id = 'page_entry' . $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');
             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  ");
     }
     // Get all published testimonials
     if ($limit) {
         $objTestimonials = \TestimonialsModel::findPublishedTestimonials($intParent, $objConfig->order == 'descending', $limit, $offset);
     } else {
         $objTestimonials = \TestimonialsModel::findPublishedTestimonials($intParent, $objConfig->order == 'descending');
     }
     // Parse the testimonials
     if ($objTestimonials !== null && ($total = $objTestimonials->count()) > 0) {
         $count = 0;
         if ($objConfig->template == '') {
             $objConfig->template = 'testimonial_entry';
         }
         $objPartial = new \FrontendTemplate($objConfig->template);
         while ($objTestimonials->next()) {
             $objPartial->setData($objTestimonials->row());
             // Clean the RTE output
             if ($objPage->outputFormat == 'xhtml') {
                 $objTestimonials->testimonial = \StringUtil::toXhtml($objTestimonials->testimonial);
             } else {
                 $objTestimonials->testimonial = \StringUtil::toHtml5($objTestimonials->testimonial);
             }
             $objPartial->testimonial = trim(str_replace(array('{{', '}}'), array('&#123;&#123;', '&#125;&#125;'), $objTestimonials->testimonial));
             $objPartial->datim = $this->parseDate($objPage->datimFormat, $objTestimonials->date);
             $objPartial->date = $this->parseDate($objPage->dateFormat, $objTestimonials->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 = 'entry_' . $objTestimonials->id;
             $objPartial->timestamp = $objTestimonials->date;
             $objPartial->datetime = date('Y-m-d\\TH:i:sP', $objTestimonials->date);
             $objPartial->avatar = $this->get_gravatar($objTestimonials->email, $objTestimonials->name, $objConfig->AvatarMode, $objConfig->AvatarSize, $objConfig->DefaultGravatar, $objConfig->DefaultGravatarRating, $objConfig->DefaultAvatar);
             $objPartial->titel = $objTestimonials->title;
             $objPartial->addVote = $objConfig->addVote;
             $objPartial->enableVoteField1 = $objConfig->enableVoteField1;
             $objPartial->enableVoteField2 = $objConfig->enableVoteField2;
             $objPartial->enableVoteField3 = $objConfig->enableVoteField3;
             $objPartial->enableVoteField4 = $objConfig->enableVoteField4;
             $objPartial->enableVoteField5 = $objConfig->enableVoteField5;
             $objPartial->enableVoteField6 = $objConfig->enableVoteField6;
             $objPartial->VoteField1Name = $objConfig->VoteField1Name;
             $objPartial->VoteField2Name = $objConfig->VoteField2Name;
             $objPartial->VoteField3Name = $objConfig->VoteField3Name;
             $objPartial->VoteField4Name = $objConfig->VoteField4Name;
             $objPartial->VoteField5Name = $objConfig->VoteField5Name;
             $objPartial->VoteField6Name = $objConfig->VoteField6Name;
             $objPartial->design = $objConfig->design;
             $arrTestimonials[] = $objPartial->parse();
             ++$count;
         }
     }
     $objTemplate->testimonials = $arrTestimonials;
     $objTemplate->addVote = $objConfig->addVote;
     $objTemplate->name = $GLOBALS['TL_LANG']['MSC']['tm_name'];
     $objTemplate->email = $GLOBALS['TL_LANG']['MSC']['tm_email'];
     $objTemplate->url = $GLOBALS['TL_LANG']['MSC']['tm_website'];
     $objTemplate->company = $GLOBALS['TL_LANG']['MSC']['tm_company'];
     $objTemplate->title = $GLOBALS['TL_LANG']['MSC']['tm_title'];
     $objTemplate->TestimonialsTotal = $limit ? $gtotal : $total;
     // Add a form to create new testimonials
     $this->renderTestimonialForm($objTemplate, $objConfig, $intParent);
 }
Пример #16
0
 /**
  * Returns the information-array about an album
  *
  * @param null $intPictureId
  * @param $objContentElement
  * @return array|null
  */
 public static function getPictureInformationArray($intPictureId = null, $objContentElement)
 {
     if ($intPictureId < 1) {
         return null;
     }
     global $objPage;
     $hasCustomThumb = false;
     $defaultThumbSRC = $objContentElement->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);
     $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 = $objContentElement->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($objContentElement->gc_size_detailview);
     //Generate the thumbnails and the picture element
     try {
         $thumbSrc = \Image::create($strImageSrc, $arrSize)->executeResize()->getResizedPath();
         // overwrite $thumbSrc if there is a valid custom thumb
         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) {
                         $thumbSrc = \Image::create($objFileCustomThumb->path, $arrSize)->executeResize()->getResizedPath();
                         $hasCustomThumb = true;
                     }
                 }
             }
         }
         $thumbPath = $hasCustomThumb ? $objFileCustomThumb->path : $strImageSrc;
         $picture = \Picture::create($thumbPath, $arrSize)->getTemplateData();
     } 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(\StringUtil::toXhtml($objPicture->comment)) : specialchars(\StringUtil::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;
     }
     //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' && $objContentElement->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(\StringUtil::toXhtml($objPicture->comment)) : specialchars(\StringUtil::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']), 'caption' => $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\StringUtil::toXhtml($objPicture->comment)) : specialchars(\StringUtil::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 = \GalleryCreatorPicturesModel::findByPk($intPictureId);
     if ($objPicture !== null) {
         $arrPicture = array_merge($objPicture->row(), $arrPicture);
     }
     return $arrPicture;
 }
 /**
  * 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' ? \StringUtil::toXhtml($objAlbum->comment) : \StringUtil::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;
 }
Пример #18
0
 /**
  * Add an event to the array of active events
  *
  * @param \CalendarEventsModel $objEvent
  * @param integer              $intStart
  * @param integer              $intEnd
  * @param string               $strUrl
  * @param string               $strBase
  */
 protected function addEvent($objEvent, $intStart, $intEnd, $strUrl, $strBase)
 {
     if ($intEnd < time()) {
         return;
     }
     /** @var \PageModel $objPage */
     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'] = \StringUtil::toXhtml($objEvent->teaser);
     } else {
         $arrEvent['teaser'] = \StringUtil::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;
 }
Пример #19
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;
     $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];
     $span = \Calendar::calculateSpan($intStart, $intEnd);
     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);
         }
     }
     $until = '';
     $recurring = '';
     // Recurring event
     if ($objEvents->recurring) {
         $arrRange = deserialize($objEvents->repeatEach);
         if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) {
             $strKey = 'cal_' . $arrRange['unit'];
             $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']);
             if ($objEvents->recurrences > 0) {
                 $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], \Date::parse($objPage->dateFormat, $objEvents->repeatEnd));
             }
         }
     }
     // Store raw data
     $arrEvent = $objEvents->row();
     // Overwrite some settings
     $arrEvent['date'] = $strDate;
     $arrEvent['time'] = $strTime;
     $arrEvent['datetime'] = $objEvents->addTime ? date('Y-m-d\\TH:i:sP', $intStart) : date('Y-m-d', $intStart);
     $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['recurring'] = $recurring;
     $arrEvent['until'] = $until;
     $arrEvent['begin'] = $intStart;
     $arrEvent['end'] = $intEnd;
     $arrEvent['details'] = '';
     $arrEvent['hasDetails'] = false;
     $arrEvent['hasTeaser'] = false;
     // 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'] != '') {
         $arrEvent['hasTeaser'] = true;
         if ($objPage->outputFormat == 'xhtml') {
             $arrEvent['teaser'] = \StringUtil::toXhtml($arrEvent['teaser']);
         } else {
             $arrEvent['teaser'] = \StringUtil::toHtml5($arrEvent['teaser']);
         }
         $arrEvent['teaser'] = \StringUtil::encodeEmail($arrEvent['teaser']);
     }
     // Display the "read more" button for external/article links
     if ($objEvents->source != 'default') {
         $arrEvent['details'] = true;
         $arrEvent['hasDetails'] = 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;
         };
         $arrEvent['hasDetails'] = \ContentModel::countPublishedByPidAndTable($id, 'tl_calendar_events') > 0;
     }
     // 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) {
             break;
         }
         $intDate = strtotime('+ 1 day', $intDate);
         $intNextKey = date('Ymd', $intDate);
         $this->arrEvents[$intNextKey][$intDate][] = $arrEvent;
     }
 }
Пример #20
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     if ($this->blnNoMarkup) {
         /** @var \FrontendTemplate|object $objTemplate */
         $objTemplate = new \FrontendTemplate('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 = \StringUtil::toXhtml($this->teaser);
     } else {
         $this->teaser = \StringUtil::toHtml5($this->teaser);
     }
     // Show the teaser only
     if ($this->multiMode && $this->showTeaser) {
         /** @var \FrontendTemplate|object $objTemplate */
         $objTemplate = new \FrontendTemplate('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 = $objPage->getFrontendUrl($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);
         }
     }
 }
Пример #21
0
 /**
  * Add comments to a template
  *
  * @param \FrontendTemplate|object $objTemplate
  * @param \stdClass                $objConfig
  * @param string                   $strSource
  * @param integer                  $intParent
  * @param mixed                    $varNotifies
  */
 public function addCommentsToTemplate(\FrontendTemplate $objTemplate, \stdClass $objConfig, $strSource, $intParent, $varNotifies)
 {
     /** @var \PageModel $objPage */
     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) !== null ? \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)) {
             /** @var \PageError404 $objHandler */
             $objHandler = new $GLOBALS['TL_PTY']['error_404']();
             $objHandler->generate($objPage->id);
         }
         // 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';
         }
         /** @var \FrontendTemplate|object $objPartial */
         $objPartial = new \FrontendTemplate($objConfig->template);
         while ($objComments->next()) {
             $objPartial->setData($objComments->row());
             // Clean the RTE output
             if ($objPage->outputFormat == 'xhtml') {
                 $objPartial->comment = \StringUtil::toXhtml($objComments->comment);
             } else {
                 $objPartial->comment = \StringUtil::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 = \StringUtil::toXhtml($objPartial->reply);
                     } else {
                         $objPartial->reply = \StringUtil::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);
 }
Пример #22
0
 /**
  * Generate an Atom feed and return it as XML string
  *
  * @return string The Atom feed markup
  */
 public function generateAtom()
 {
     $this->adjustPublicationDate();
     $xml = '<?xml version="1.0" encoding="' . \Config::get('characterSet') . '"?>';
     $xml .= '<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="' . $this->language . '">';
     $xml .= '<title>' . specialchars($this->title) . '</title>';
     $xml .= '<subtitle>' . specialchars($this->description) . '</subtitle>';
     $xml .= '<link rel="alternate" href="' . specialchars($this->link) . '" />';
     $xml .= '<id>' . specialchars($this->link) . '</id>';
     $xml .= '<updated>' . preg_replace('/00$/', ':00', date('Y-m-d\\TH:i:sO', $this->published)) . '</updated>';
     $xml .= '<generator>Contao Open Source CMS</generator>';
     $xml .= '<link href="' . specialchars(\Environment::get('base') . 'share/' . $this->strName) . '.xml" rel="self" />';
     foreach ($this->arrItems as $objItem) {
         $xml .= '<entry>';
         $xml .= '<title>' . specialchars($objItem->title) . '</title>';
         $xml .= '<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">' . preg_replace('/[\\n\\r]+/', ' ', \StringUtil::toXhtml($objItem->description)) . '</div></content>';
         $xml .= '<link rel="alternate" href="' . specialchars($objItem->link) . '" />';
         $xml .= '<updated>' . preg_replace('/00$/', ':00', date('Y-m-d\\TH:i:sO', $objItem->published)) . '</updated>';
         $xml .= '<id>' . ($objItem->guid ? $objItem->guid : specialchars($objItem->link)) . '</id>';
         $xml .= '<author><name>' . $objItem->author . '</name></author>';
         // Enclosures
         if (is_array($objItem->enclosure)) {
             foreach ($objItem->enclosure as $arrEnclosure) {
                 $xml .= '<link rel="enclosure" type="' . $arrEnclosure['type'] . '" href="' . $arrEnclosure['url'] . '" length="' . $arrEnclosure['length'] . '" />';
             }
         }
         $xml .= '</entry>';
     }
     return $xml . '</feed>';
 }