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();
79 $this->article
= ViewableArticle
::getArticle($this->articleContent
->articleID
, false);
80 $this->category
= $this->article
->getCategory();
82 // update interface language
83 if (!WCF
::getUser()->userID
&& $this->article
->isMultilingual
&& $this->articleContent
->languageID
!= WCF
::getLanguage()->languageID
) {
84 WCF
::setLanguage($this->articleContent
->languageID
);
91 public function checkPermissions() {
92 parent
::checkPermissions();
94 if (!$this->article
->canRead()) {
95 throw new PermissionDeniedException();
102 public function readData() {
106 $articleEditor = new ArticleEditor($this->article
->getDecoratedObject());
107 $articleEditor->updateCounters([
112 if (MODULE_TAGGING
&& WCF
::getSession()->getPermission('user.tag.canViewTag')) {
113 $this->tags
= TagEngine
::getInstance()->getObjectTags(
114 'com.woltlab.wcf.article',
115 $this->articleContent
->articleContentID
,
116 [$this->articleContent
->languageID ?
: LanguageFactory
::getInstance()->getDefaultLanguageID()]
120 // get related articles
121 if (MODULE_TAGGING
&& ARTICLE_RELATED_ARTICLES
) {
122 if (!empty($this->tags
)) {
123 $conditionBuilder = new PreparedStatementConditionBuilder();
124 $conditionBuilder->add('objectTypeID = ?', [TagEngine
::getInstance()->getObjectTypeID('com.woltlab.wcf.article')]);
125 $conditionBuilder->add('tagID IN (?)', [array_keys($this->tags
)]);
126 $conditionBuilder->add('objectID <> ?', [$this->articleContentID
]);
127 $sql = "SELECT objectID, COUNT(*) AS count
128 FROM wcf" . WCF_N
. "_tag_to_object
129 " . $conditionBuilder . "
131 HAVING COUNT(*) >= " . round(count($this->tags
) * ARTICLE_RELATED_ARTICLES_MATCH_THRESHOLD
/ 100) . "
132 ORDER BY count DESC";
133 $statement = WCF
::getDB()->prepareStatement($sql, ARTICLE_RELATED_ARTICLES
);
134 $statement->execute($conditionBuilder->getParameters());
135 $articleContentIDs = $statement->fetchAll(\PDO
::FETCH_COLUMN
);
137 if (!empty($articleContentIDs)) {
138 $conditionBuilder = new PreparedStatementConditionBuilder();
139 $conditionBuilder->add('articleContentID IN (?)', [$articleContentIDs]);
140 $sql = "SELECT articleID
141 FROM wcf" . WCF_N
. "_article_content
142 " . $conditionBuilder;
143 $statement = WCF
::getDB()->prepareStatement($sql);
144 $statement->execute($conditionBuilder->getParameters());
145 $articleIDs = $statement->fetchAll(\PDO
::FETCH_COLUMN
);
147 $this->relatedArticles
= new AccessibleArticleList();
148 $this->relatedArticles
->getConditionBuilder()->add('article.articleID IN (?)', [$articleIDs]);
149 $this->relatedArticles
->sqlOrderBy
= 'article.time';
150 $this->relatedArticles
->readObjects();
156 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $this->article
->categoryID
, $this->article
->getCategory());
157 foreach (array_reverse($this->article
->getCategory()->getParentCategories()) as $parentCategory) {
158 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $parentCategory->categoryID
, $parentCategory);
165 public function assignVariables() {
166 parent
::assignVariables();
168 WCF
::getTPL()->assign([
169 'articleContentID' => $this->articleContentID
,
170 'articleContent' => $this->articleContent
,
171 'article' => $this->article
,
172 'category' => $this->category
,
173 'relatedArticles' => $this->relatedArticles
,
174 'tags' => $this->tags