/** * Parse an item and return it as string * @param object * @param boolean * @param string * @param integer * @return string */ protected function parseArticle($objArticle, $blnAddArchive = false, $strClass = '', $intCount = 0) { global $objPage; $arrCategories = deserialize($objArticle->categories, true); $objTemplate = new \FrontendTemplate($this->news_template); $objTemplate->setData($objArticle->row()); $objTemplate->class = ($objArticle->cssClass != '' ? ' ' . $objArticle->cssClass : '') . $strClass; $objTemplate->newsHeadline = $objArticle->headline; $objTemplate->subHeadline = $objArticle->subheadline; $objTemplate->hasSubHeadline = $objArticle->subheadline ? true : false; $objTemplate->linkHeadline = $this->generateLink($objArticle->headline, $objArticle, $blnAddArchive); $objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objArticle, $blnAddArchive, true); $objTemplate->link = $this->generateNewsUrl($objArticle, $blnAddArchive); $objTemplate->linkTarget = $objArticle->target ? $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"' : ''; $objTemplate->linkTitle = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->headline), true); $objTemplate->count = $intCount; // see #5708 $objTemplate->text = ''; $objTemplate->hasText = false; $objTemplate->hasTeaser = false; // print pdf if ($this->news_pdfJumpTo) { $objTemplate->showPdfButton = true; $pdfPage = \PageModel::findByPk($this->news_pdfJumpTo); $pdfArticle = \ArticleModel::findPublishedByPidAndColumn($this->news_pdfJumpTo, 'main'); $options = deserialize($pdfArticle->printable); if (in_array('pdf', $options)) { $objTemplate->pdfArticleId = $pdfArticle->id; } $strUrl = \Controller::generateFrontendUrl($pdfPage->row()); $objTemplate->pdfJumpTo = $strUrl; } $objArchive = \NewsArchiveModel::findByPk($objArticle->pid); $objTemplate->archive = $objArchive; $objTemplate->archive->title = $objTemplate->archive->displayTitle ? $objTemplate->archive->displayTitle : $objTemplate->archive->title; $objTemplate->archive->class = ModuleNewsListPlus::getArchiveClassFromTitle($objTemplate->archive->title, true); $objTemplate->archiveTitle = $objTemplate->archive->title; $arrCategoryTitles = array(); if ($this->news_archiveTitleAppendCategories && !empty($arrCategories)) { $arrTitleCategories = array_intersect($arrCategories, deserialize($this->news_archiveTitleCategories, true)); if (!empty($arrTitleCategories)) { $objTitleCategories = NewsCategoryModel::findPublishedByIds($arrTitleCategories); if ($objTitleCategories !== null) { while ($objTitleCategories->next()) { if ($objTitleCategories->frontendTitle) { $arrCategoryTitles[$objTitleCategories->id] = $objTitleCategories->frontendTitle; continue; } $arrCategoryTitles[$objTitleCategories->id] = $objTitleCategories->title; } $objTemplate->archiveTitle .= ' : ' . implode(' : ', $arrCategoryTitles); } } } // add tags $objTemplate->showTags = $this->news_showtags; if ($this->news_showtags && $this->news_template_modal && $this->Environment->isAjaxRequest) { $helper = new NewsPlusTagHelper(); $tagsandlist = $helper->getTagsAndTaglistForIdAndTable($objArticle->id, 'tl_news', $this->tag_jumpTo); $tags = $tagsandlist['tags']; $taglist = $tagsandlist['taglist']; $objTemplate->showTagClass = $this->tag_named_class; $objTemplate->tags = $tags; $objTemplate->taglist = $taglist; $objTemplate->news = 'IN'; } // nav $strUrl = ''; $objArchive = \NewsArchiveModel::findByPk($objArticle->pid); if ($objArchive !== null && $objArchive->jumpTo && ($objTarget = $objArchive->getRelated('jumpTo')) !== null) { $strUrl = $this->generateFrontendUrl($objTarget->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/news/%s'); } $objTemplate->nav = static::generateArrowNavigation($objArticle, $strUrl, $this->news_readerModule); // Clean the RTE output if ($objArticle->teaser != '') { $objTemplate->hasTeaser = true; if ($objPage->outputFormat == 'xhtml') { $objTemplate->teaser = \String::toXhtml($objArticle->teaser); } else { $objTemplate->teaser = \String::toHtml5($objArticle->teaser); } $objTemplate->teaser = \String::encodeEmail($objTemplate->teaser); } // Display the "read more" button for external/article links if ($objArticle->source != 'default') { $objTemplate->text = true; $objTemplate->hasText = true; } else { $id = $objArticle->id; $objTemplate->text = function () use($id) { $strText = ''; $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_news'); if ($objElement !== null) { while ($objElement->next()) { $strText .= $this->getContentElement($objElement->current()); } } return $strText; }; $objTemplate->hasText = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news') !== null; } $arrMeta = $this->getMetaFields($objArticle); // Add the meta information $objTemplate->date = $arrMeta['date']; $objTemplate->hasMetaFields = !empty($arrMeta); $objTemplate->numberOfComments = $arrMeta['ccount']; $objTemplate->commentCount = $arrMeta['comments']; $objTemplate->timestamp = $objArticle->date; $objTemplate->author = $arrMeta['author']; $objTemplate->datetime = date('Y-m-d\\TH:i:sP', $objArticle->date); $objTemplate->addImage = false; // Add an image if ($objArticle->addImage && $objArticle->singleSRC != '') { $objModel = \FilesModel::findByUuid($objArticle->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($objArticle->singleSRC)) { $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { // Do not override the field now that we have a model registry (see #6303) $arrArticle = $objArticle->row(); // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) { $arrArticle['size'] = $this->imgSize; } } $arrArticle['singleSRC'] = $objModel->path; $this->addImageToTemplate($objTemplate, $arrArticle); } } $objTemplate->enclosure = array(); // Add enclosures if ($objArticle->addEnclosure) { $this->addEnclosuresToTemplate($objTemplate, $objArticle->row()); } if (in_array('share', \ModuleLoader::getActive())) { $objArticle->title = $objArticle->headline; $objShare = new \HeimrichHannot\Share\Share($this->objModel, $objArticle); $objTemplate->share = $objShare->generate(); } // Modal if ($this->news_showInModal && $objArticle->source == 'default' && $this->news_readerModule) { $objTemplate->modal = true; $objTemplate->modalTarget = '#' . NewsPlusHelper::getCSSModalID($this->news_readerModule); } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['parseArticles']) && is_array($GLOBALS['TL_HOOKS']['parseArticles'])) { foreach ($GLOBALS['TL_HOOKS']['parseArticles'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($objTemplate, $objArticle->row(), $this); } } return $objTemplate->parse(); }
protected function compile() { global $objPage; $this->Template->event = ''; $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; if ($this->objEvent === null) { // Do not index or cache the page $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); $this->Template->event = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('events')) . '</p>'; // remove page from search index if ($this->cal_showInModal) { \HeimrichHannot\SearchPlus\Search::removePageFromIndex(\Environment::get('request')); } return; } // Overwrite the page title (see #2853 and #4955) if ($this->objEvent->title != '') { $objPage->pageTitle = strip_tags(strip_insert_tags($this->objEvent->title)); } // Overwrite the page description if ($this->objEvent->teaser != '') { $objPage->description = $this->prepareMetaDescription($this->objEvent->teaser); } $strUrl = ''; $objCalendar = \CalendarModel::findByPk($this->objEvent->pid); // Get the current "jumpTo" page if ($objCalendar !== null && $objCalendar->jumpTo && ($objTarget = $objCalendar->getRelated('jumpTo')) !== null) { $strUrl = $this->generateFrontendUrl($objTarget->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/events/%s'); } $intStartTime = $this->objEvent->startTime; $intEndTime = $this->objEvent->endTime; $span = \Calendar::calculateSpan($intStartTime, $intEndTime); // Do not show dates in the past if the event is recurring (see #923) if ($this->objEvent->recurring) { $arrRange = deserialize($this->objEvent->repeatEach); while ($intStartTime < time() && $intEndTime < $this->objEvent->repeatEnd) { $intStartTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intStartTime); $intEndTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intEndTime); } } $objEvent = (object) $this->getEventDetails($this->objEvent, $intStartTime, $intEndTime, $strUrl, $intStartTime, $this->objEvent->pid); $arrSubEvents = array(); if (!$this->cal_ungroupSubevents) { $objChildEvents = CalendarPlusEventsModel::findPublishedSubEvents($objEvent->id); if ($objChildEvents !== null) { while ($objChildEvents->next()) { $arrSubEvents[$objChildEvents->id] = $this->addSingleEvent($objChildEvents, $intStartTime); } } } if ($objPage->outputFormat == 'xhtml') { $strTimeStart = ''; $strTimeEnd = ''; $strTimeClose = ''; } else { $strTimeStart = '<time datetime="' . date('Y-m-d\\TH:i:sP', $intStartTime) . '">'; $strTimeEnd = '<time datetime="' . date('Y-m-d\\TH:i:sP', $intEndTime) . '">'; $strTimeClose = '</time>'; } // Get date if ($span > 0) { $date = $strTimeStart . \Date::parse($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $intStartTime) . $strTimeClose . ' - ' . $strTimeEnd . \Date::parse($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $intEndTime) . $strTimeClose; } elseif ($intStartTime == $intEndTime) { $date = $strTimeStart . \Date::parse($objPage->dateFormat, $intStartTime) . ($objEvent->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStartTime) . ')' : '') . $strTimeClose; } else { $date = $strTimeStart . \Date::parse($objPage->dateFormat, $intStartTime) . ($objEvent->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStartTime) . $strTimeClose . ' - ' . $strTimeEnd . \Date::parse($objPage->timeFormat, $intEndTime) . ')' : '') . $strTimeClose; } $until = ''; $recurring = ''; // Recurring event if ($objEvent->recurring) { $arrRange = deserialize($objEvent->repeatEach); $strKey = 'cal_' . $arrRange['unit']; $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']); if ($objEvent->recurrences > 0) { $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], \Date::parse($objPage->dateFormat, $objEvent->repeatEnd)); } } // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) { $objEvent->size = $this->imgSize; } } $imgSize = false; // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) { $imgSize = $this->imgSize; } } $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData((array) $objEvent); $objTemplate->nav = $this->generateArrowNavigation($objEvent, $strUrl); if ($this->registration !== null) { $objTemplate->registration = $this->registration; $objTemplate->module = $this; // falback } if (is_array($arrSubEvents) && !empty($arrSubEvents)) { $strSubEvents = ''; foreach ($arrSubEvents as $subID => $arrSubEvent) { $objSubEventTemplate = new \FrontendTemplate($this->cal_templateSubevent); $objSubEventTemplate->setData($arrSubEvent); $this->addEventDetailsToTemplate($objSubEventTemplate, $arrSubEvent, '', '', $imgSize); $strSubEvents .= $objSubEventTemplate->parse() . "\n"; } $objTemplate->subEvents = $strSubEvents; } if ($this->addShare && in_array('share', $this->Config->getActiveModules())) { $objShare = new \HeimrichHannot\Share\Share($this->objModel, $objEvent); $objTemplate->share = $objShare->generate(); } $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(); $arrEvent['singleSRC'] = $objModel->path; $this->addImageToTemplate($objTemplate, $arrEvent); } } $objTemplate->enclosure = array(); // Add enclosures if ($objEvent->addEnclosure) { $this->addEnclosuresToTemplate($objTemplate, $this->objEvent->row()); } $this->Template->event = $objTemplate->parse(); // HOOK: comments extension required if ($objEvent->noComments || !in_array('comments', \ModuleLoader::getActive())) { $this->Template->allowComments = false; return; } $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') { 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); }