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\ArticleEditor
;
7 use wcf\data\article\ViewableArticle
;
9 use wcf\system\database\util\PreparedStatementConditionBuilder
;
10 use wcf\system\exception\IllegalLinkException
;
11 use wcf\system\exception\PermissionDeniedException
;
12 use wcf\system\language\LanguageFactory
;
13 use wcf\system\page\PageLocationManager
;
14 use wcf\system\tagging\TagEngine
;
18 * Abstract implementation of the article page.
21 * @copyright 2001-2017 WoltLab GmbH
22 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
23 * @package WoltLabSuite\Core\Page
26 abstract class AbstractArticlePage
extends AbstractPage
{
30 public $neededModules = ['MODULE_ARTICLE'];
36 public $articleContentID = 0;
39 * article content object
40 * @var ViewableArticleContent
42 public $articleContent;
46 * @var ViewableArticle
58 * @var ArticleCategory
63 * list of related articles
64 * @var AccessibleArticleList
66 public $relatedArticles;
71 public function readParameters() {
72 parent
::readParameters();
74 if (isset($_REQUEST['id'])) $this->articleContentID
= intval($_REQUEST['id']);
75 $this->articleContent
= ViewableArticleContent
::getArticleContent($this->articleContentID
);
76 if ($this->articleContent
=== null) {
77 throw new IllegalLinkException();
80 // check if the language has been disabled
81 if ($this->articleContent
->languageID
&& LanguageFactory
::getInstance()->getLanguage($this->articleContent
->languageID
) === null) {
82 throw new IllegalLinkException();
85 $this->article
= ViewableArticle
::getArticle($this->articleContent
->articleID
, false);
86 $this->category
= $this->article
->getCategory();
88 // update interface language
89 if (!WCF
::getUser()->userID
&& $this->article
->isMultilingual
&& $this->articleContent
->languageID
!= WCF
::getLanguage()->languageID
) {
90 WCF
::setLanguage($this->articleContent
->languageID
);
97 public function checkPermissions() {
98 parent
::checkPermissions();
100 if (!$this->article
->canRead()) {
101 throw new PermissionDeniedException();
108 public function readData() {
112 $articleEditor = new ArticleEditor($this->article
->getDecoratedObject());
113 $articleEditor->updateCounters([
118 if (MODULE_TAGGING
&& WCF
::getSession()->getPermission('user.tag.canViewTag')) {
119 $this->tags
= TagEngine
::getInstance()->getObjectTags(
120 'com.woltlab.wcf.article',
121 $this->articleContent
->articleContentID
,
122 [$this->articleContent
->languageID ?
: LanguageFactory
::getInstance()->getDefaultLanguageID()]
126 // get related articles
127 if (MODULE_TAGGING
&& ARTICLE_RELATED_ARTICLES
) {
128 if (!empty($this->tags
)) {
129 $conditionBuilder = new PreparedStatementConditionBuilder();
130 $conditionBuilder->add('objectTypeID = ?', [TagEngine
::getInstance()->getObjectTypeID('com.woltlab.wcf.article')]);
131 $conditionBuilder->add('tagID IN (?)', [array_keys($this->tags
)]);
132 $conditionBuilder->add('objectID <> ?', [$this->articleContentID
]);
133 $sql = "SELECT objectID, COUNT(*) AS count
134 FROM wcf" . WCF_N
. "_tag_to_object
135 " . $conditionBuilder . "
137 HAVING COUNT(*) >= " . round(count($this->tags
) * ARTICLE_RELATED_ARTICLES_MATCH_THRESHOLD
/ 100) . "
138 ORDER BY count DESC";
139 $statement = WCF
::getDB()->prepareStatement($sql, ARTICLE_RELATED_ARTICLES
);
140 $statement->execute($conditionBuilder->getParameters());
141 $articleContentIDs = $statement->fetchAll(\PDO
::FETCH_COLUMN
);
143 if (!empty($articleContentIDs)) {
144 $conditionBuilder = new PreparedStatementConditionBuilder();
145 $conditionBuilder->add('articleContentID IN (?)', [$articleContentIDs]);
146 $sql = "SELECT articleID
147 FROM wcf" . WCF_N
. "_article_content
148 " . $conditionBuilder;
149 $statement = WCF
::getDB()->prepareStatement($sql);
150 $statement->execute($conditionBuilder->getParameters());
151 $articleIDs = $statement->fetchAll(\PDO
::FETCH_COLUMN
);
153 $this->relatedArticles
= new AccessibleArticleList();
154 $this->relatedArticles
->getConditionBuilder()->add('article.articleID IN (?)', [$articleIDs]);
155 $this->relatedArticles
->sqlOrderBy
= 'article.time';
156 $this->relatedArticles
->readObjects();
162 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $this->article
->categoryID
, $this->article
->getCategory());
163 foreach (array_reverse($this->article
->getCategory()->getParentCategories()) as $parentCategory) {
164 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $parentCategory->categoryID
, $parentCategory);
171 public function assignVariables() {
172 parent
::assignVariables();
174 WCF
::getTPL()->assign([
175 'articleContentID' => $this->articleContentID
,
176 'articleContent' => $this->articleContent
,
177 'article' => $this->article
,
178 'category' => $this->category
,
179 'relatedArticles' => $this->relatedArticles
,
180 'tags' => $this->tags