/** * Generate an article and return it as string * * @param mixed $varId The article ID or a Model object * @param boolean $blnMultiMode If true, only teasers will be shown * @param boolean $blnIsInsertTag If true, there will be no page relation * @param string $strColumn The name of the column * * @return string|boolean The article HTML markup or false */ protected function getArticle($varId, $blnMultiMode = false, $blnIsInsertTag = false, $strColumn = 'main') { global $objPage; if (is_object($varId)) { $objRow = $varId; } else { if (!$varId) { return ''; } $objRow = \ArticleModel::findByIdOrAliasAndPid($varId, !$blnIsInsertTag ? $objPage->id : null); } // Return if the article does not exist if ($objRow === null) { return false; } // Print the article as PDF if (\Input::get('pdf') == $objRow->id) { // Backwards compatibility if ($objRow->printable == 1) { $this->printArticleAsPdf($objRow); } elseif ($objRow->printable != '') { $options = deserialize($objRow->printable); if (is_array($options) && in_array('pdf', $options)) { $this->printArticleAsPdf($objRow); } } } $objRow->headline = $objRow->title; $objRow->multiMode = $blnMultiMode; // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getArticle']) && is_array($GLOBALS['TL_HOOKS']['getArticle'])) { foreach ($GLOBALS['TL_HOOKS']['getArticle'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($objRow); } } $objArticle = new \ModuleArticle($objRow, $strColumn); return $objArticle->generate($blnIsInsertTag); }
protected function getContentFromArticle($id, $type = "") { $tmpContent = ""; $thumb = ""; $sharelink = ""; $retArr = array(); $time = time(); $base = \Environment::get('base'); $table = ""; if ($type == 'news') { $table = "tl_news"; } else { if ($table == 'event') { $table = "tl_calendar_events"; } else { $table = "tl_article"; } } $openComment = $type == 'news' ? "open" : "closed"; $commentCount = 0; $result = ""; $query = "SELECT * FROM `{$table}` WHERE `id` = '" . $id . "' "; $articleRes = \Database::getInstance()->query($query)->fetchAssoc(); if ($type == "news") { switch ($articleRes['source']) { case 'external': $sharelink = $articleRes['url']; break; case 'article': $sharelink = $base . \Controller::replaceInsertTags("{{article_url::" . $articleRes['articleId'] . "}}"); break; case 'internal': $sharelink = $base . \Controller::replaceInsertTags("{{link_url::" . $articleRes['jumpTo'] . "}}"); break; default: $sharelink = $base . \Controller::replaceInsertTags("{{news_url::" . $articleRes['id'] . "}}"); break; } $newsModel = \NewsModel::findPublishedByParentAndIdOrAlias($id, array(0 => $articleRes['pid'])); $result = $this->parseNews($newsModel); } else { if ($type == "event") { $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias($id, array($this->settings['calendar'])); $objTemplate = new \FrontendTemplate("event_full"); $objTemplate->setData($objEvent->row()); $objTemplate->date = $date; $objTemplate->start = $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 = ''; $objElement = \ContentModel::findPublishedByPidAndTable($objEvent->id, 'tl_calendar_events'); if ($objElement !== null) { while ($objElement->next()) { $objTemplate->details .= $this->getContentElement($objElement->id); } } $objTemplate->addImage = false; if ($objEvent->addImage && $objEvent->singleSRC != '') { $objModel = \FilesModel::findByUuid($objEvent->singleSRC); if (is_file(TL_ROOT . '/' . $objModel->path)) { $arrEvent = $objEvent->row(); $arrEvent['singleSRC'] = $objModel->path; $this->addImageToTemplate($objTemplate, $arrEvent); } } $objTemplate->enclosure = array(); if ($objEvent->addEnclosure) { $this->addEnclosuresToTemplate($objTemplate, $objEvent->row()); } $result = $objTemplate->parse(); } else { $result = \ArticleModel::findByIdOrAliasAndPid($id, $articleRes['pid']); } } $sharelink = $sharelink == "" ? $base . \Controller::replaceInsertTags("{{link_url::" . $articleRes['pid'] . "}}") : $sharelink; if ($result != "") { if ($type != "news" && $type != "event") { $pageTitleRes = \Controller::getPageDetails($articleRes['pid']); $objArticle = new \ModuleArticle($result); $tmpContent = $objArticle->generate(true); } else { $tmpContent = $result; } $tmpContent = \Controller::replaceInsertTags($tmpContent); $tmpContent = str_replace('src="files/', 'src="' . $base . 'files/', $tmpContent); $tmpContent = str_replace('src="assets/', 'src="' . $base . 'assets/', $tmpContent); $tmpContent = str_replace('href="index.php/', 'href="' . $base . 'index.php/', $tmpContent); if ($pageTitleRes->thumb) { $thumb = $this->getFilePath($pageTitleRes->thumb); } if ($openComment == "open") { $commentCount = \CommentsModel::countPublishedBySourceAndParent("tl_news", $id); } $retArr['tstamp'] = time(); $retArr['img']['src'] = ""; $retArr['img']['thumb'] = $thumb; $retArr['pid'] = $id; $retArr['title'] = $type != "news" ? $pageTitleRes->title : $articleRes['headline']; $retArr['commentStatus'] = $openComment; $retArr['commentCount'] = $commentCount; $retArr['sharelink'] = $sharelink; $tmpContent = str_replace(']]>', ']]>', $tmpContent); $tmpContent = str_replace("\r\n", '\\n', $tmpContent); $retArr['content'] = preg_replace('/[\\x00-\\x1F\\x80-\\x9F]/u', '', $tmpContent); } else { $retArr = false; } return $retArr; }
/** * Generate an article and return it as string * * @param mixed $varId The article ID or a Model object * @param boolean $blnMultiMode If true, only teasers will be shown * @param boolean $blnIsInsertTag If true, there will be no page relation * @param string $strColumn The name of the column * * @return string|boolean The article HTML markup or false */ public static function getArticle($varId, $blnMultiMode = false, $blnIsInsertTag = false, $strColumn = 'main') { /** @var \PageModel $objPage */ global $objPage; if (is_object($varId)) { $objRow = $varId; } else { if (!$varId) { return ''; } $objRow = \ArticleModel::findByIdOrAliasAndPid($varId, !$blnIsInsertTag ? $objPage->id : null); if ($objRow === null) { return false; } } // Check the visibility (see #6311) if (!static::isVisibleElement($objRow)) { return ''; } // Print the article as PDF if (isset($_GET['pdf']) && \Input::get('pdf') == $objRow->id) { // Backwards compatibility if ($objRow->printable == 1) { $objArticle = new \ModuleArticle($objRow); $objArticle->generatePdf(); } elseif ($objRow->printable != '') { $options = deserialize($objRow->printable); if (is_array($options) && in_array('pdf', $options)) { $objArticle = new \ModuleArticle($objRow); $objArticle->generatePdf(); } } } $objRow->headline = $objRow->title; $objRow->multiMode = $blnMultiMode; // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getArticle']) && is_array($GLOBALS['TL_HOOKS']['getArticle'])) { foreach ($GLOBALS['TL_HOOKS']['getArticle'] as $callback) { static::importStatic($callback[0])->{$callback[1]}($objRow); } } $objArticle = new \ModuleArticle($objRow, $strColumn); $strBuffer = $objArticle->generate($blnIsInsertTag); // Disable indexing if protected if ($objArticle->protected && !preg_match('/^\\s*<!-- indexer::stop/', $strBuffer)) { $strBuffer = "\n<!-- indexer::stop -->" . $strBuffer . "<!-- indexer::continue -->\n"; } return $strBuffer; }
/** * Generate an article and return it as string. * * @param int * @param bool * @param bool * @param string * * @return string */ protected function getPageArticle($page, $articleId) { $article = \ArticleModel::findByIdOrAliasAndPid($articleId, $page->id); if ($article === null) { return ''; } return $this->getArticle($article); }