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