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