From: Matthias Schmidt Date: Thu, 24 Aug 2017 12:03:22 +0000 (+0200) Subject: Fix automatic conversion of article links X-Git-Tag: 3.1.0_Alpha_2~37 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=faa9ed677b9ce02293d3baa23da258634c6166b1;p=GitHub%2FWoltLab%2FWCF.git Fix automatic conversion of article links Links to the article page contain the id of the article content object, not the article itself. See #2186 --- diff --git a/wcfsetup/install/files/lib/system/event/listener/ArticleLinkHtmlInputNodeProcessorListener.class.php b/wcfsetup/install/files/lib/system/event/listener/ArticleLinkHtmlInputNodeProcessorListener.class.php index cd68759a6b..0cf0970bc4 100644 --- a/wcfsetup/install/files/lib/system/event/listener/ArticleLinkHtmlInputNodeProcessorListener.class.php +++ b/wcfsetup/install/files/lib/system/event/listener/ArticleLinkHtmlInputNodeProcessorListener.class.php @@ -1,6 +1,7 @@ getRegexFromLink(LinkHandler::getInstance()->getLink('Article')); - $articleIDs = $this->getObjectIDs($eventObj, $regex); + $articleContentIDs = $this->getObjectIDs($eventObj, $regex); - if (!empty($articleIDs)) { - $articleList = new AccessibleArticleList(); - $articleList->getConditionBuilder()->add('article.articleID IN (?)', [$articleIDs]); - $articleList->readObjects(); + if (!empty($articleContentIDs)) { + // read linked article contents + $articleContentList = new ArticleContentList(); + $articleContentList->getConditionBuilder()->add('article_content.articleContentID IN (?)', [$articleContentIDs]); + $articleContentList->readObjects(); - $this->setObjectTitles($eventObj, $regex, $articleList->getObjects()); + // collect ids of the articles + $articleIDs = []; + foreach ($articleContentList as $articleContent) { + $articleIDs[] = $articleContent->articleID; + } + + if (!empty($articleIDs)) { + // read the accessible articles of the ones that are linked + $articleList = new AccessibleArticleList(); + $articleList->getConditionBuilder()->add('article.articleID IN (?)', [array_unique($articleIDs)]); + $articleList->readObjects(); + + // filter the article contents by accessibility + $articleContents = []; + foreach ($articleContentList as $articleContent) { + if ($articleList->search($articleContent->articleID) !== null) { + $articleContents[$articleContent->articleContentID] = $articleContent; + } + } + + $this->setObjectTitles($eventObj, $regex, $articleContents); + } } } }