3 namespace wcf\system\message\embedded\object;
5 use wcf\data\article\AccessibleArticleList;
6 use wcf\data\article\Article;
7 use wcf\data\article\content\ViewableArticleContentList;
8 use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
9 use wcf\system\html\input\HtmlInputProcessor;
12 * Parses embedded articles and outputs their link or title.
14 * @author Alexander Ebert
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\System\Message\Embedded\Object
19 class ArticleMessageEmbeddedObjectHandler extends AbstractSimpleMessageEmbeddedObjectHandler
24 public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData)
27 if (!empty($embeddedData['wsa'])) {
28 for ($i = 0, $length = \count($embeddedData['wsa']); $i < $length; $i++) {
29 $articleIDs[] = \intval($embeddedData['wsa'][$i][0]);
33 return \array_unique($articleIDs);
39 public function loadObjects(array $objectIDs)
41 $viewableArticles = ViewableArticleRuntimeCache::getInstance()->getObjects($objectIDs);
42 $contentLanguageID = MessageEmbeddedObjectManager::getInstance()->getContentLanguageID();
43 if ($contentLanguageID !== null) {
45 foreach ($viewableArticles as $article) {
48 && $article->getArticleContent()->languageID
49 && $article->getArticleContent()->languageID != $contentLanguageID
51 $articleIDs[] = $article->articleID;
55 if (!empty($articleIDs)) {
56 $list = new ViewableArticleContentList();
57 $list->getConditionBuilder()->add("articleID IN (?)", [$articleIDs]);
58 $list->getConditionBuilder()->add("languageID = ?", [$contentLanguageID]);
61 foreach ($list->getObjects() as $articleContent) {
62 $viewableArticles[$articleContent->articleID]->setArticleContent($articleContent);
67 return $viewableArticles;
73 public function validateValues($objectType, $objectID, array $values)
75 $articleList = new AccessibleArticleList();
76 $articleList->getConditionBuilder()->add('article.articleID IN (?)', [$values]);
77 $articleList->readObjects();
78 $articles = $articleList->getObjects();
80 return \array_filter($values, static function ($value) use ($articles) {
81 return isset($articles[$value]);
88 public function replaceSimple($objectType, $objectID, $value, array $attributes)
90 /** @var Article $article */
91 $article = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.article', $value);
92 if ($article === null) {
96 $return = (!empty($attributes['return'])) ? $attributes['return'] : 'link';
99 return $article->getTitle();
104 return $article->getLink();