3 use wcf\data\article\category\ArticleCategory
;
4 use wcf\data\article\content\ViewableArticleContent
;
5 use wcf\data\article\AccessibleArticleList
;
6 use wcf\data\article\ArticleAction
;
7 use wcf\data\article\ArticleEditor
;
8 use wcf\data\article\ViewableArticle
;
10 use wcf\system\database\util\PreparedStatementConditionBuilder
;
11 use wcf\system\exception\IllegalLinkException
;
12 use wcf\system\exception\PermissionDeniedException
;
13 use wcf\system\language\LanguageFactory
;
14 use wcf\system\page\PageLocationManager
;
15 use wcf\system\tagging\TagEngine
;
19 * Abstract implementation of the article page.
22 * @copyright 2001-2018 WoltLab GmbH
23 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
24 * @package WoltLabSuite\Core\Page
27 abstract class AbstractArticlePage
extends AbstractPage
{
31 public $neededModules = ['MODULE_ARTICLE'];
37 public $articleContentID = 0;
40 * article content object
41 * @var ViewableArticleContent
43 public $articleContent;
47 * @var ViewableArticle
59 * @var ArticleCategory
64 * list of related articles
65 * @var AccessibleArticleList
67 public $relatedArticles;
72 public function readParameters() {
73 parent
::readParameters();
75 if (isset($_REQUEST['id'])) $this->articleContentID
= intval($_REQUEST['id']);
76 $this->articleContent
= ViewableArticleContent
::getArticleContent($this->articleContentID
);
77 if ($this->articleContent
=== null) {
78 throw new IllegalLinkException();
80 $this->article
= ViewableArticle
::getArticle($this->articleContent
->articleID
, false);
81 $this->category
= $this->article
->getCategory();
83 // update interface language
84 if (!WCF
::getUser()->userID
&& $this->article
->isMultilingual
&& $this->articleContent
->languageID
!= WCF
::getLanguage()->languageID
) {
85 WCF
::setLanguage($this->articleContent
->languageID
);
92 public function checkPermissions() {
93 parent
::checkPermissions();
95 if (!$this->article
->canRead()) {
96 throw new PermissionDeniedException();
103 public function readData() {
107 $articleEditor = new ArticleEditor($this->article
->getDecoratedObject());
108 $articleEditor->updateCounters([
112 // update article visit
113 if (ARTICLE_ENABLE_VISIT_TRACKING
&& $this->article
->isNew()) {
114 $articleAction = new ArticleAction([$this->article
->getDecoratedObject()], 'markAsRead', [
115 'viewableArticle' => $this->article
117 $articleAction->executeAction();
121 if (MODULE_TAGGING
&& WCF
::getSession()->getPermission('user.tag.canViewTag')) {
122 $this->tags
= TagEngine
::getInstance()->getObjectTags(
123 'com.woltlab.wcf.article',
124 $this->articleContent
->articleContentID
,
125 [$this->articleContent
->languageID ?
: LanguageFactory
::getInstance()->getDefaultLanguageID()]
129 // get related articles
130 if (MODULE_TAGGING
&& ARTICLE_RELATED_ARTICLES
) {
131 if (!empty($this->tags
)) {
132 $conditionBuilder = new PreparedStatementConditionBuilder();
133 $conditionBuilder->add('objectTypeID = ?', [TagEngine
::getInstance()->getObjectTypeID('com.woltlab.wcf.article')]);
134 $conditionBuilder->add('tagID IN (?)', [array_keys($this->tags
)]);
135 $conditionBuilder->add('objectID <> ?', [$this->articleContentID
]);
136 $sql = "SELECT objectID, COUNT(*) AS count
137 FROM wcf" . WCF_N
. "_tag_to_object
138 " . $conditionBuilder . "
140 HAVING COUNT(*) >= " . round(count($this->tags
) * ARTICLE_RELATED_ARTICLES_MATCH_THRESHOLD
/ 100) . "
141 ORDER BY count DESC";
142 $statement = WCF
::getDB()->prepareStatement($sql, ARTICLE_RELATED_ARTICLES
);
143 $statement->execute($conditionBuilder->getParameters());
144 $articleContentIDs = $statement->fetchAll(\PDO
::FETCH_COLUMN
);
146 if (!empty($articleContentIDs)) {
147 $conditionBuilder = new PreparedStatementConditionBuilder();
148 $conditionBuilder->add('articleContentID IN (?)', [$articleContentIDs]);
149 $sql = "SELECT articleID
150 FROM wcf" . WCF_N
. "_article_content
151 " . $conditionBuilder;
152 $statement = WCF
::getDB()->prepareStatement($sql);
153 $statement->execute($conditionBuilder->getParameters());
154 $articleIDs = $statement->fetchAll(\PDO
::FETCH_COLUMN
);
156 $this->relatedArticles
= new AccessibleArticleList();
157 $this->relatedArticles
->getConditionBuilder()->add('article.articleID IN (?)', [$articleIDs]);
158 $this->relatedArticles
->sqlOrderBy
= 'article.time';
159 $this->relatedArticles
->readObjects();
165 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $this->article
->categoryID
, $this->article
->getCategory());
166 foreach (array_reverse($this->article
->getCategory()->getParentCategories()) as $parentCategory) {
167 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $parentCategory->categoryID
, $parentCategory);
174 public function assignVariables() {
175 parent
::assignVariables();
177 WCF
::getTPL()->assign([
178 'articleContentID' => $this->articleContentID
,
179 'articleContent' => $this->articleContent
,
180 'article' => $this->article
,
181 'category' => $this->category
,
182 'relatedArticles' => $this->relatedArticles
,
183 'tags' => $this->tags