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;
10 * Parses URLs of articles.
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
18 class ArticleLinkHtmlInputNodeProcessorListener extends AbstractHtmlInputNodeProcessorListener {
22 public function execute($eventObj, $className, $eventName, array &$parameters) {
23 /** @var HtmlInputNodeProcessor $eventObj */
25 $regex = $this->getRegexFromLink(LinkHandler::getInstance()->getLink('Article', [
26 'forceFrontend' => true
28 $articleContentIDs = $this->getObjectIDs($eventObj, $regex);
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();
36 // collect ids of the articles
38 foreach ($articleContentList as $articleContent) {
39 $articleIDs[] = $articleContent->articleID;
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();
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;
56 $this->setObjectTitles($eventObj, $regex, $articleContents);