From: Alexander Ebert Date: Wed, 6 Jul 2016 14:40:09 +0000 (+0200) Subject: Added support for embedded media in page content X-Git-Tag: 3.0.0_Beta_1~1253 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2ccdf11fcc5914161af8bf6760e79bab44035cdd;p=GitHub%2FWoltLab%2FWCF.git Added support for embedded media in page content --- diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/MediaMessageEmbeddedObjectHandler.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/MediaMessageEmbeddedObjectHandler.class.php index 1514103408..fd11d4ad9a 100644 --- a/wcfsetup/install/files/lib/system/message/embedded/object/MediaMessageEmbeddedObjectHandler.class.php +++ b/wcfsetup/install/files/lib/system/message/embedded/object/MediaMessageEmbeddedObjectHandler.class.php @@ -1,5 +1,7 @@ * @package WoltLabSuite\Core\System\Message\Embedded\Object */ -class MediaMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler { +class MediaMessageEmbeddedObjectHandler extends AbstractSimpleMessageEmbeddedObjectHandler { /** * @inheritDoc */ @@ -39,4 +41,52 @@ class MediaMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHan public function loadObjects(array $objectIDs) { return MediaRuntimeCache::getInstance()->getObjects($objectIDs); } + + /** + * @inheritDoc + */ + public function validateValues($objectType, $objectID, array $values) { + $mediaList = new MediaList(); + $mediaList->getConditionBuilder()->add("media.mediaID IN (?)", [$values]); + $mediaList->readObjectIDs(); + + return $mediaList->getObjectIDs(); + } + + /** + * @inheritDoc + */ + public function replaceSimple($objectType, $objectID, $value, array $attributes) { + /** @var Media $media */ + $media = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.media', $value); + if ($media === null) { + return null; + } + + $return = (!empty($attributes['return'])) ? $attributes['return'] : 'link'; + switch ($return) { + case 'title': + return $media->getTitle(); + break; + + case 'link': + default: + $size = (!empty($attributes['size'])) ? $attributes['size'] : 'original'; + switch ($size) { + case 'small': + case 'medium': + case 'large': + return $media->getThumbnailLink($size); + break; + + case 'original': + default: + return $media->getLink(); + break; + } + + break; + } + } + }