Added support for [wsm] and partially [wsmg]
authorAlexander Ebert <ebert@woltlab.com>
Wed, 6 Jul 2016 13:41:14 +0000 (15:41 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 6 Jul 2016 13:41:14 +0000 (15:41 +0200)
com.woltlab.wcf/objectType.xml
com.woltlab.wcf/templates/mediaBBCodeTag.tpl [new file with mode: 0644]
wcfsetup/install/files/js/WoltLab/WCF/Media/Manager/Editor.js
wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Metacode.js
wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php
wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaBBCode.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaGalleryBBCode.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/cache/runtime/MediaRuntimeCache.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/html/input/filter/MessageHtmlInputFilter.class.php
wcfsetup/install/files/lib/system/message/embedded/object/MediaMessageEmbeddedObjectHandler.class.php [new file with mode: 0644]

index 57f1adfc65229f05ff98918ac8959d2720507f96..c27854df964faeb7edc9a86405f54123946ceaf9 100644 (file)
                        <definitionname>com.woltlab.wcf.message.embeddedObject</definitionname>
                        <classname><![CDATA[wcf\system\message\embedded\object\PageMessageEmbeddedObjectHandler]]></classname>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.media</name>
+                       <definitionname>com.woltlab.wcf.message.embeddedObject</definitionname>
+                       <classname><![CDATA[wcf\system\message\embedded\object\MediaMessageEmbeddedObjectHandler]]></classname>
+               </type>
                <!-- embedded object handlers -->
                
                <type>
diff --git a/com.woltlab.wcf/templates/mediaBBCodeTag.tpl b/com.woltlab.wcf/templates/mediaBBCodeTag.tpl
new file mode 100644 (file)
index 0000000..448dcfe
--- /dev/null
@@ -0,0 +1 @@
+<img src="{if $thumbnailSize == 'original'}{$media->getLink()}{else}{$media->getThumbnailLink($thumbnailSize)}{/if}" alt="{$media->getTitle()}"{if $float != 'none'} class="messageFloatObject{$float|ucfirst}"{/if}> 
\ No newline at end of file
index d0b6fe44ec47654d111489bcd1dbbbd93f35dad5..c8255cd64a2b13c61799069a562fe4055fd5fc01 100644 (file)
@@ -208,7 +208,7 @@ define(['Core', 'Dictionary', 'Dom/Traverse', 'Language', 'Ui/Dialog', 'WoltLab/
                        });
                        
                        this._options.editor.buffer.set();
-                       this._options.editor.insert.text('[wsm]' + mediaIds.join(',') + '[/wsm]');
+                       this._options.editor.insert.text("[wsmg='" + mediaIds.join(',') + "'][/wsmg]");
                },
                
                /**
@@ -241,7 +241,7 @@ define(['Core', 'Dictionary', 'Dom/Traverse', 'Language', 'Ui/Dialog', 'WoltLab/
                                this._options.editor.insert.html('<img src="' + item[thumbnailSize + 'ThumbnailLink'] + '" class="woltlabSuiteMedia" data-media-id="' + item.mediaID + '" data-media-size="' + thumbnailSize + '">');
                        }
                        else {
-                               this._options.editor.insert.text('[wsm]' + item.mediaID + '[/wsm]');
+                               this._options.editor.insert.text("[wsm='" + item.mediaID + "'][/wsm]");
                        }
                },
                
index a988193d8d7b7eb7a8108e81711aae281dd1bcf8..fba6bb17ba228c6653c191632a752e18e2b971bc 100644 (file)
@@ -66,6 +66,12 @@ define(['Dom/Util'], function(DomUtil) {
                        
                        var buffer = '[' + name;
                        if (attributes.length) {
+                               for (var i = 0, length = attributes.length; i < length; i++) {
+                                       if (!/^'.*'$/.test(attributes[i])) {
+                                               attributes[i] = "'" + attributes[i] + "'";
+                                       }
+                               }
+                               
                                buffer += '=' + attributes.join(',');
                        }
                        
index 8bb65fbb28774c479193639dcd1b66d1cf8a60aa..d3acbf260e127ef285d1fbfdba33bb494f9a0798 100644 (file)
@@ -9,7 +9,7 @@ use wcf\util\StringUtil;
  * that can be safely passed through HTMLPurifier's validation mechanism.
  * 
  * All though not exactly required for all bbcodes, the actual output of an bbcode
- * cannot be forseen and potentially conflict with HTMLPurifier's whitelist. Examples
+ * cannot be foreseen and potentially conflict with HTMLPurifier's whitelist. Examples
  * are <iframe> or other embedded media that is allowed as a result of a bbcode, but
  * not allowed to be directly provided by a user. 
  * 
diff --git a/wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaBBCode.class.php b/wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaBBCode.class.php
new file mode 100644 (file)
index 0000000..257d594
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+namespace wcf\system\bbcode;
+use wcf\data\media\Media;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
+
+/**
+ * Parses the [wsm] bbcode tag.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Bbcode
+ * @since       3.0
+ */
+class WoltLabSuiteMediaBBCode extends AbstractBBCode {
+       /**
+        * @inheritDoc
+        */
+       public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) {
+               $mediaID = (!empty($openingTag['attributes'][0])) ? intval($openingTag['attributes'][0]) : 0;
+               if (!$mediaID) {
+                       return '';
+               }
+               
+               /** @var Media $media */
+               $media = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.media', $mediaID);
+               
+               if ($media !== null) {
+                       if ($media->isImage) {
+                               $thumbnailSize = (!empty($openingTag['attributes'][1])) ? $openingTag['attributes'][1] : 'original';
+                               $float = (!empty($openingTag['attributes'][2])) ? $openingTag['attributes'][2] : 'none';
+                               
+                               WCF::getTPL()->assign([
+                                       'float' => $float,
+                                       'media' => $media,
+                                       'thumbnailSize' => $thumbnailSize
+                               ]);
+                               
+                               return WCF::getTPL()->fetch('mediaBBCodeTag', 'wcf');
+                       }
+                       
+                       return StringUtil::getAnchorTag($media->getLink(), $media->getTitle());
+               }
+               
+               return '';
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaGalleryBBCode.class.php b/wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaGalleryBBCode.class.php
new file mode 100644 (file)
index 0000000..278a08b
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+namespace wcf\system\bbcode;
+
+/**
+ * Parses the [wsmg] bbcode tag.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Bbcode
+ */
+class WoltLabSuiteMediaGalleryBBCode extends AbstractBBCode {
+       /**
+        * @inheritDoc
+        */
+       public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) {
+               return '<p>TODO: WoltLabSuiteMediaGalleryBBCode</p>';
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/cache/runtime/MediaRuntimeCache.class.php b/wcfsetup/install/files/lib/system/cache/runtime/MediaRuntimeCache.class.php
new file mode 100644 (file)
index 0000000..4264357
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+namespace wcf\system\cache\runtime;
+use wcf\data\media\Media;
+use wcf\data\media\MediaList;
+
+/**
+ * Runtime cache implementation for shared media.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Cache\Runtime
+ * @since      3.0
+ * 
+ * @method     Media[]         getCachedObjects()
+ * @method     Media           getObject($objectID)
+ * @method     Media[]         getObjects(array $objectIDs)
+ */
+class MediaRuntimeCache extends AbstractRuntimeCache {
+       /**
+        * @inheritDoc
+        */
+       protected $listClassName = MediaList::class;
+}
index 35adbfe6fb0980248205f539fdaa3809978dcd13..0ef1557801035c55d5be4c1b382b94a9ddc47ad2 100644 (file)
@@ -63,6 +63,10 @@ class MessageHtmlInputFilter implements IHtmlInputFilter {
                // size
                $definition->addElement('woltlab-size', 'Inline', 'Inline', '', ['class' => 'Text']);
                
+               // media
+               $definition->addAttribute('img', 'data-media-id', 'Number');
+               $definition->addAttribute('img', 'data-media-size', new \HTMLPurifier_AttrDef_Enum(['small', 'medium', 'large', 'original']));
+               
                // mention
                $definition->addElement('woltlab-mention', 'Inline', 'Inline', '', [
                        'data-user-id' => 'Number',
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
new file mode 100644 (file)
index 0000000..1514103
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+namespace wcf\system\message\embedded\object;
+use wcf\system\cache\runtime\MediaRuntimeCache;
+use wcf\system\html\input\HtmlInputProcessor;
+use wcf\util\ArrayUtil;
+
+/**
+ * IMessageEmbeddedObjectHandler implementation for shared media.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Message\Embedded\Object
+ */
+class MediaMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler {
+       /**
+        * @inheritDoc
+        */
+       public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData) {
+               $mediaIDs = [];
+               foreach (['wsm', 'wsmg'] as $name) {
+                       if (empty($embeddedData[$name])) {
+                               continue;
+                       }
+                       
+                       for ($i = 0, $length = count($embeddedData[$name]); $i < $length; $i++) {
+                               $parsedIDs = ArrayUtil::toIntegerArray(explode(',', $embeddedData[$name][$i][0]));
+                               
+                               $mediaIDs = array_merge($mediaIDs, $parsedIDs);
+                       }
+               }
+               
+               return $mediaIDs;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function loadObjects(array $objectIDs) {
+               return MediaRuntimeCache::getInstance()->getObjects($objectIDs);
+       }
+}