2 namespace wcf\system\message\embedded\object;
3 use wcf\data\article\Article;
4 use wcf\data\article\ArticleList;
5 use wcf\system\html\input\HtmlInputProcessor;
8 * Parses embedded articles and outputs their link or title.
10 * @author Alexander Ebert
11 * @copyright 2001-2018 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\System\Message\Embedded\Object
15 class ArticleMessageEmbeddedObjectHandler extends AbstractSimpleMessageEmbeddedObjectHandler {
19 public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData) {
21 if (!empty($embeddedData['wsa'])) {
22 for ($i = 0, $length = count($embeddedData['wsa']); $i < $length; $i++) {
23 $articleIDs[] = intval($embeddedData['wsa'][$i][0]);
27 return array_unique($articleIDs);
33 public function loadObjects(array $objectIDs) {
34 $articleList = new ArticleList();
35 $articleList->setObjectIDs($objectIDs);
36 $articleList->readObjects();
38 return $articleList->getObjects();
44 public function validateValues($objectType, $objectID, array $values) {
45 $articleList = new ArticleList();
46 $articleList->setObjectIDs($values);
47 $articleList->readObjects();
48 $articles = $articleList->getObjects();
50 return array_filter($values, function($value) use ($articles) {
51 return isset($articles[$value]);
58 public function replaceSimple($objectType, $objectID, $value, array $attributes) {
59 /** @var Article $article */
60 $article = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.article', $value);
61 if ($article === null) {
65 $return = (!empty($attributes['return'])) ? $attributes['return'] : 'link';
68 return $article->getTitle();
73 return $article->getLink();