06e16d750552e65fc0d31f1cab87f7e3f0a9a579
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\event\listener;
3 use wcf\data\article\content\ArticleContentList;
4 use wcf\data\article\AccessibleArticleList;
5 use wcf\system\html\input\node\HtmlInputNodeProcessor;
6 use wcf\system\request\LinkHandler;
7
8 /**
9 * Parses URLs of articles.
10 *
11 * @author Matthias Schmidt
12 * @copyright 2001-2017 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\System\Event\Listener
15 * @since 3.1
16 */
17 class ArticleLinkHtmlInputNodeProcessorListener extends AbstractHtmlInputNodeProcessorListener {
18 /**
19 * @inheritDoc
20 */
21 public function execute($eventObj, $className, $eventName, array &$parameters) {
22 /** @var HtmlInputNodeProcessor $eventObj */
23
24 $regex = $this->getRegexFromLink(LinkHandler::getInstance()->getLink('Article', [
25 'forceFrontend' => true
26 ]));
27 $articleContentIDs = $this->getObjectIDs($eventObj, $regex);
28
29 if (!empty($articleContentIDs)) {
30 // read linked article contents
31 $articleContentList = new ArticleContentList();
32 $articleContentList->getConditionBuilder()->add('article_content.articleContentID IN (?)', [$articleContentIDs]);
33 $articleContentList->readObjects();
34
35 // collect ids of the articles
36 $articleIDs = [];
37 foreach ($articleContentList as $articleContent) {
38 $articleIDs[] = $articleContent->articleID;
39 }
40
41 if (!empty($articleIDs)) {
42 // read the accessible articles of the ones that are linked
43 $articleList = new AccessibleArticleList();
44 $articleList->getConditionBuilder()->add('article.articleID IN (?)', [array_unique($articleIDs)]);
45 $articleList->readObjects();
46
47 // filter the article contents by accessibility
48 $articleContents = [];
49 foreach ($articleContentList as $articleContent) {
50 if ($articleList->search($articleContent->articleID) !== null) {
51 $articleContents[$articleContent->articleContentID] = $articleContent;
52 }
53 }
54
55 $this->setObjectTitles($eventObj, $regex, $articleContents);
56 }
57 }
58 }
59 }