/** * 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(); }