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\html\input\HtmlInputProcessor;
7 use wcf\util\ArrayUtil;
10 * IMessageEmbeddedObjectHandler implementation for shared media.
12 * @author Alexander Ebert
13 * @copyright 2001-2016 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\Message\Embedded\Object
17 class MediaMessageEmbeddedObjectHandler extends AbstractSimpleMessageEmbeddedObjectHandler {
21 public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData) {
23 foreach (['wsm', 'wsmg'] as $name) {
24 if (empty($embeddedData[$name])) {
28 for ($i = 0, $length = count($embeddedData[$name]); $i < $length; $i++) {
29 $parsedIDs = ArrayUtil::toIntegerArray(explode(',', $embeddedData[$name][$i][0]));
31 $mediaIDs = array_merge($mediaIDs, $parsedIDs);
41 public function loadObjects(array $objectIDs) {
42 return ViewableMediaRuntimeCache::getInstance()->getObjects($objectIDs);
48 public function validateValues($objectType, $objectID, array $values) {
49 $mediaList = new MediaList();
50 $mediaList->getConditionBuilder()->add("media.mediaID IN (?)", [$values]);
51 $mediaList->readObjectIDs();
53 return $mediaList->getObjectIDs();
59 public function replaceSimple($objectType, $objectID, $value, array $attributes) {
60 /** @var Media $media */
61 $media = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.media', $value);
62 if ($media === null) {
66 $return = (!empty($attributes['return'])) ? $attributes['return'] : 'link';
69 return $media->getTitle();
74 $size = (!empty($attributes['size'])) ? $attributes['size'] : 'original';
79 return $media->getThumbnailLink($size);
84 return $media->getLink();