2 namespace wcf\system\message\embedded\object;
3 use wcf\data\media\Media;
4 use wcf\data\media\MediaList;
5 use wcf\system\cache\runtime\ViewableMediaRuntimeCache;
6 use wcf\system\database\util\PreparedStatementConditionBuilder;
7 use wcf\system\html\input\HtmlInputProcessor;
9 use wcf\util\ArrayUtil;
12 * IMessageEmbeddedObjectHandler implementation for shared media.
14 * @author Alexander Ebert
15 * @copyright 2001-2017 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 MediaMessageEmbeddedObjectHandler extends AbstractSimpleMessageEmbeddedObjectHandler {
23 public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData) {
25 foreach (['wsm', 'wsmg'] as $name) {
26 if (empty($embeddedData[$name])) {
30 for ($i = 0, $length = count($embeddedData[$name]); $i < $length; $i++) {
31 $parsedIDs = ArrayUtil::toIntegerArray(explode(',', $embeddedData[$name][$i][0]));
33 $mediaIDs = array_merge($mediaIDs, $parsedIDs);
43 public function loadObjects(array $objectIDs) {
44 $viewableMedia = ViewableMediaRuntimeCache::getInstance()->getObjects($objectIDs);
45 $contentLanguageID = MessageEmbeddedObjectManager::getInstance()->getContentLanguageID();
46 if ($contentLanguageID !== null) {
48 foreach ($viewableMedia as $media) {
49 if ($media->localizedLanguageID != $contentLanguageID) {
50 $mediaIDs[] = $media->getDecoratedObject()->mediaID;
54 if (!empty($mediaIDs)) {
55 $conditions = new PreparedStatementConditionBuilder();
56 $conditions->add("mediaID IN (?)", [$mediaIDs]);
57 $conditions->add("languageID = ?", [$contentLanguageID]);
60 FROM wcf".WCF_N."_media_content
62 $statement = WCF::getDB()->prepareStatement($sql);
63 $statement->execute($conditions->getParameters());
64 while ($row = $statement->fetchArray()) {
65 $viewableMedia[$row['mediaID']]->setLocalizedContent($row['languageID'], $row);
70 return $viewableMedia;
76 public function validateValues($objectType, $objectID, array $values) {
77 $mediaList = new MediaList();
78 $mediaList->getConditionBuilder()->add("media.mediaID IN (?)", [$values]);
79 $mediaList->readObjectIDs();
81 return $mediaList->getObjectIDs();
87 public function replaceSimple($objectType, $objectID, $value, array $attributes) {
88 /** @var Media $media */
89 $media = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.media', $value);
90 if ($media === null) {
94 $return = (!empty($attributes['return'])) ? $attributes['return'] : 'link';
97 return $media->getTitle();
102 $size = (!empty($attributes['size'])) ? $attributes['size'] : 'original';
107 return $media->getThumbnailLink($size);
112 return $media->getLink();