From 2ccdf11fcc5914161af8bf6760e79bab44035cdd Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 6 Jul 2016 16:40:09 +0200 Subject: [PATCH] Added support for embedded media in page content --- ...ediaMessageEmbeddedObjectHandler.class.php | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) 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; + } + } + } -- 2.20.1