Improved Redactor integration
authorAlexander Ebert <ebert@woltlab.com>
Tue, 8 Jul 2014 11:32:05 +0000 (13:32 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 8 Jul 2014 11:32:05 +0000 (13:32 +0200)
12 files changed:
com.woltlab.wcf/templates/messageFormSettings.tpl
com.woltlab.wcf/templates/messageFormSettingsInline.tpl [new file with mode: 0644]
com.woltlab.wcf/templates/messageFormSmilies.tpl
com.woltlab.wcf/templates/messageFormTabs.tpl
com.woltlab.wcf/templates/messageFormTabsInline.tpl [new file with mode: 0644]
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor/plugins/woptions.js [deleted file]
wcfsetup/install/files/js/3rdParty/redactor/plugins/wupload.js [deleted file]
wcfsetup/install/files/js/WCF.Message.js
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/system/message/MessageFormSettingsHandler.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/message/QuickReplyManager.class.php

index c41c4a04c9d4418eca0d78ea23b1eded24e2ac7d..f7146dc5b3561af7dd4e2a0d05d51932f30b26ec 100644 (file)
@@ -1,4 +1,4 @@
-<fieldset id="settings" class="settingsContent tabMenuContent container containerPadding">
+<fieldset id="settings_{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}" class="settingsContent tabMenuContent container containerPadding">
        <dl class="wide">
                {if $__wcf->getSession()->getPermission($permissionCanUseBBCodes)}
                        <dt></dt>
diff --git a/com.woltlab.wcf/templates/messageFormSettingsInline.tpl b/com.woltlab.wcf/templates/messageFormSettingsInline.tpl
new file mode 100644 (file)
index 0000000..64e7219
--- /dev/null
@@ -0,0 +1,51 @@
+<fieldset id="settings_{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}" class="container containerPadding">
+       <dl class="wide">
+               {if $__wcf->getSession()->getPermission('user.message.canUseBBCodes')}
+                       <dt></dt>
+                       <dd>
+                               <label><input id="preParse_{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}" name="preParse" type="checkbox" value="1"{if !$enableBBCodes|isset || $enableBBCodes} checked="checked"{/if} data-submit-empty="0" /> {lang}wcf.message.settings.preParse{/lang}</label>
+                               <small>{lang}wcf.message.settings.preParse.description{/lang}</small>
+                       </dd>
+               {/if}
+               {if MODULE_SMILEY && $__wcf->getSession()->getPermission('user.message.canUseSmilies')}
+                       <dt></dt>
+                       <dd>
+                               <label><input id="enableSmilies_{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}" name="enableSmilies" type="checkbox" value="1"{if !$enableSmilies|isset || $enableSmilies} checked="checked"{/if} data-submit-empty="0" /> {lang}wcf.message.settings.enableSmilies{/lang}</label>
+                               <small>{lang}wcf.message.settings.enableSmilies.description{/lang}</small>
+                       </dd>
+               {/if}
+               {if $__wcf->getSession()->getPermission('user.message.canUseBBCodes')}
+                       <dt></dt>
+                       <dd>
+                               <label><input id="enableBBCodes_{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}" name="enableBBCodes" type="checkbox" value="1"{if !$enableBBCodes|isset || $enableBBCodes} checked="checked"{/if} data-submit-empty="0" /> {lang}wcf.message.settings.enableBBCodes{/lang}</label>
+                               <small>{lang}wcf.message.settings.enableBBCodes.description{/lang}</small>
+                       </dd>
+               {/if}
+               
+               {event name='settings'}
+       </dl>
+</fieldset>
+<script data-relocate="true">
+       $(function() {
+               WCF.System.Event.addListener('com.woltlab.wcf.messageOptionsInline', 'submit_{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}', function(parameters) {
+                       var $settings = $('#settings_{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}');
+                       $settings.find('input, select, textarea').each(function(index, element) {
+                               var $element = $(element);
+                               var $value = $element.val();
+                               
+                               if ($element.getTagName() == 'input') {
+                                       if (!$element.is(':checked')) {
+                                               if ($element.prop('type') == 'checkbox' && $element.data('submitEmpty') !== undefined) {
+                                                       $value = $element.data('submitEmpty');
+                                               }
+                                               else {
+                                                       return true;
+                                               }
+                                       }
+                               }
+                               
+                               parameters[$element.prop('name')] = $value;
+                       });
+               });
+       });
+</script>
index f3abb1229d81c53bf1da911edb8de624de82b4c9..38fe26a612b95962be73b09df9ef06090bdb64a4 100644 (file)
@@ -9,7 +9,7 @@
 
 <div class="container containerPadding{if $__tabCount} messageTabMenu{/if}" data-preselect="true" data-collapsible="false" id="smilies-{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}">
        {capture assign=__defaultSmilies}
-               {include file='__messageFormSmilies' smilies=$defaultSmilies}
+               {include file='__messageFormSmilies' smilies=$__wcf->getSmileyCache()->getCategorySmilies()}
        {/capture}
        
        {if $__tabCount > 1}
index b09fef638a639f81a4cc256e799ba68dc94d6391..0adf6d72c954bb9d66f9398f716e3b5156899b6b 100644 (file)
 <script data-relocate="true">
        //<![CDATA[
        $(function() {
-               if (!$.browser.redactor) $('#smiliesTab, #smilies').remove();
-               
-               $('.redactorMessageOptions > nav > ul > li > a').removeAttr('title');
-               
                $('.messageTabMenu').messageTabMenu();
-               
-               /*$('.redactorMessageOptions > nav > ul > li > a').click(function() {
-                       var $a = $(this);
-                       var $p = $a.parent();
-                       var $h = $p.hasClass('active');
-                       
-                       $('.redactorMessageOptions > nav > ul > li').removeClass('active');
-                       $('.redactorMessageOptions > div, .redactorMessageOptions > fieldset').hide();
-                       
-                       if (!$h) {
-                               $p.addClass('active');
-                               $('#' + $a.prop('href').replace(/[^#]+#/, '')).show();
-                       }
-                       
-                       return false;
-               });
-               
-               $('.redactorMessageOptions > nav > ul > li > a:eq(0)').trigger('click');
-               
-               $('.redactorMessageOptions > div:eq(0) > nav > ul > li:eq(0)').addClass('active');*/
        });
        //]]>
 </script>
\ No newline at end of file
diff --git a/com.woltlab.wcf/templates/messageFormTabsInline.tpl b/com.woltlab.wcf/templates/messageFormTabsInline.tpl
new file mode 100644 (file)
index 0000000..db551ae
--- /dev/null
@@ -0,0 +1,28 @@
+{assign var=smileyCategories value=$__wcf->getSmileyCache()->getCategories()}
+{if !$permissionCanUseSmilies|isset}{assign var=permissionCanUseSmilies value='user.message.canUseSmilies'}{/if}
+{if !$wysiwygContainerID|isset}{assign var=wysiwygContainerID value='text'}{/if}
+<div class="messageTabMenu">
+       <nav class="messageTabMenuNavigation jsOnly">
+               <ul>
+                       {if MODULE_SMILEY && $__wcf->getSession()->getPermission($permissionCanUseSmilies) && $smileyCategories|count}<li data-name="smilies"><a>{lang}wcf.message.smilies{/lang}</a></li>{/if}
+                       {if MODULE_ATTACHMENT && !$attachmentHandler|empty && $attachmentHandler->canUpload()}<li data-name="attachments"><a>{lang}wcf.attachment.attachments{/lang}</a></li>{/if}
+                       <li data-name="settings"><a>{lang}wcf.message.settings{/lang}</a></li>
+                       {event name='tabMenuTabs'}
+               </ul>
+       </nav>
+       
+       {if MODULE_SMILEY && $__wcf->getSession()->getPermission($permissionCanUseSmilies) && $smileyCategories|count}{include file='messageFormSmilies'}{/if}
+       {if MODULE_ATTACHMENT && !$attachmentHandler|empty && $attachmentHandler->canUpload()}{include file='messageFormAttachments'}{/if}
+       
+       {include file='messageFormSettingsInline'}
+       
+       {event name='tabMenuContents'}
+</div>
+
+<script data-relocate="true">
+       //<![CDATA[
+       $(function() {
+               $('.messageTabMenu').messageTabMenu();
+       });
+       //]]>
+</script>
\ No newline at end of file
index 3249394339a4afd882a7b9308fe0c435e8af91e5..94ec2e67fb9e8f86bbfd1cd24c34e448f5efa48b 100644 (file)
@@ -1,8 +1,7 @@
-{if !$wysiwygEnableUpload|isset}{assign var=wysiwygEnableUpload value=false}{/if}
 <script data-relocate="true">
 var __REDACTOR_ICON_PATH = '{@$__wcf->getPath()}icon/';
 var __REDACTOR_BUTTONS = [ {implode from=$__wcf->getBBCodeHandler()->getButtonBBCodes() item=__bbcode}{ icon: '{$__bbcode->wysiwygIcon}', label: '{$__bbcode->buttonLabel|language}', name: '{$__bbcode->bbcodeTag}' }{/implode} ];
-var __REDACTOR_SMILIES = { {implode from=$defaultSmilies item=smiley}'{@$smiley->smileyCode|encodeJS}': '{@$smiley->getURL()|encodeJS}'{/implode} };
+var __REDACTOR_SMILIES = { {implode from=$__wcf->getSmileyCache()->getCategorySmilies() item=smiley}'{@$smiley->smileyCode|encodeJS}': '{@$smiley->getURL()|encodeJS}'{/implode} };
 var __REDACTOR_SOURCE_BBCODES = [ {implode from=$__wcf->getBBCodeHandler()->getSourceBBCodes() item=__bbcode}'{@$__bbcode->bbcodeTag}'{/implode} ];
 </script>
 <script data-relocate="true">
@@ -10,25 +9,9 @@ $(function() {
        var $editorName = '{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}';
        var $callbackIdentifier = 'Redactor_' + $editorName;
        
-       {if $wysiwygEnableUpload}
-               WCF.Language.addObject({
-                       'wcf.attachment.upload.error.invalidExtension': '{lang}wcf.attachment.upload.error.invalidExtension{/lang}',
-                       'wcf.attachment.upload.error.tooLarge': '{lang}wcf.attachment.upload.error.tooLarge{/lang}',
-                       'wcf.attachment.upload.error.reachedLimit': '{lang}wcf.attachment.upload.error.reachedLimit{/lang}',
-                       'wcf.attachment.upload.error.reachedRemainingLimit': '{lang}wcf.attachment.upload.error.reachedRemainingLimit{/lang}',
-                       'wcf.attachment.upload.error.uploadFailed': '{lang}wcf.attachment.upload.error.uploadFailed{/lang}',
-                       'wcf.global.button.upload': '{lang}wcf.global.button.upload{/lang}',
-                       'wcf.attachment.insert': '{lang}wcf.attachment.insert{/lang}',
-                       'wcf.attachment.insertAll': '{lang}wcf.attachment.insertAll{/lang}',
-                       'wcf.attachment.delete.sure': '{lang}wcf.attachment.delete.sure{/lang}',
-                       'wcf.attachment.upload.limits': '{'wcf.attachment.upload.limits'|language|encodeJS}'
-               });
-       {/if}
-       
        WCF.System.Dependency.Manager.setup($callbackIdentifier, function() {
                var $textarea = $('#' + $editorName);
                var $buttons = [ ];
-               var __wysiwygMessageOptions = (typeof $wysiwygMessageOptions === 'undefined') ? [ ] : $wysiwygMessageOptions;
                
                {include file='wysiwygToolbar'}
                
@@ -42,62 +25,16 @@ $(function() {
                        lang: '{@$__wcf->getLanguage()->getFixedLanguageCode()}',
                        minHeight: 200,
                        imageResizable: false,
-                       plugins: [ 'wutil',  'wmonkeypatch', 'wbutton', 'wbbcode',  'wfontcolor', 'wfontfamily', 'wfontsize', 'woptions' ],
+                       plugins: [ 'wutil',  'wmonkeypatch', 'wbutton', 'wbbcode',  'wfontcolor', 'wfontfamily', 'wfontsize' ],
                        wautosave: {
                                active: ($autosave) ? true : false,
                                key: ($autosave) ? '{@$__wcf->getAutosavePrefix()}_' + $autosave : '',
                                saveOnInit: {if !$errorField|empty}true{else}false{/if}
-                       },
-                       wMessageOptions: [ ]
+                       }
                };
                
-               {if $wysiwygEnableUpload}
-                       $config.plugins.push('wupload');
-                       $config.wMessageOptions.push({
-                               containerID: 'attachments',
-                               title: '{lang}wcf.attachment.attachments{/lang}',
-                               items: [ ]
-                       });
-                       $config.wattachment = {
-                               attachments: [ ],
-                               maxCount: {@$attachmentHandler->getMaxCount()},
-                               objectType: '{@$attachmentObjectType}',
-                               objectID: '{@$attachmentObjectID}',
-                               parentObjectID: '{@$attachmentParentObjectID}',
-                               tmpHash: '{$tmpHash|encodeJS}'
-                       };
-                       
-                       {if $attachmentList|isset && !$attachmentList|empty}
-                               {foreach from=$attachmentList item=attachment}
-                                       $config.wattachment.attachments.push({
-                                               attachmentID: {@$attachment->attachmentID},
-                                               filename: '{$attachment->filename|encodeJs}',
-                                               isImage: {if $attachment->isImage}true{else}false{/if},
-                                               tinyThumbnailUrl: '{if $attachment->tinyThumbnailType}{link controller='Attachment' object=$attachment}tiny=1{/link}{/if}',
-                                               url: '{link controller='Attachment' object=$attachment}{/link}'
-                                       });
-                               {/foreach}
-                       {/if}
-               {/if}
-               
                {event name='javascriptInit'}
                
-               if (__wysiwygMessageOptions.length) {
-                       $config.wMessageOptions.push({
-                               containerID: 'settings',
-                               title: '{lang}wcf.message.settings{/lang}',
-                               items: __wysiwygMessageOptions
-                       });
-               }
-               
-               if (false && $.getLength(__REDACTOR_SMILIES)) {
-                       $config.wMessageOptions.push({
-                               containerID: 'smilies',
-                               title: '{lang}wcf.message.smilies{/lang}',
-                               items: [ ]
-                       });
-               }
-               
                $textarea.redactor($config);
        });
        
@@ -114,8 +51,6 @@ $(function() {
                        '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wfontsize.js?v={@$__wcfVersion}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wmonkeypatch.js?v={@$__wcfVersion}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wutil.js?v={@$__wcfVersion}',
-                       '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wupload.js?v={@$__wcfVersion}',
-                       '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/woptions.js?v={@$__wcfVersion}'
                {/if}
                {event name='javascriptFiles'}
        ], function() {
diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/woptions.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/woptions.js
deleted file mode 100644 (file)
index bb2d8e5..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-if (!RedactorPlugins) var RedactorPlugins = {};
-
-/**
- * Provides message option tabs for Redactor.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2014 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- */
-RedactorPlugins.woptions = {
-       /**
-        * list of message option elements grouped by instance
-        * @var object<object>
-        */
-       _messageOptions: { },
-       
-       /**
-        * message option container per instance
-        * @var object<jQuery>
-        */
-       _messageOptionContainer: { },
-       
-       /**
-        * navigation container per instance
-        * @var object<jQuery>
-        */
-       _messageOptionNavigation: { },
-       
-       /**
-        * Initializes the RedactorPlugins.woptions plugin.
-        */
-       init: function() {
-               var $options = this.getOption('wMessageOptions');
-               if (!$options.length) {
-                       return;
-               }
-               
-               var $instanceID = this.$source.wcfIdentify();
-               this.$box.wrap('<div class="redactorContainer" />')
-               this._messageOptionContainer[$instanceID] = $('<div id="redactorMessageOptions" class="redactorMessageOptions" />').insertAfter(this.$box);
-               this._messageOptionNavigation[$instanceID] = $('<nav><ul /></nav>').appendTo(this._messageOptionContainer[$instanceID]).children('ul');
-               this._messageOptions[$instanceID] = { };
-               
-               for (var $i = 0; $i < $options.length; $i++) {
-                       var $container = $options[$i];
-                       
-                       var $listItem = $('<li><a>' + $container.title + '</a></li>').appendTo(this._messageOptionNavigation[$instanceID]);
-                       $listItem.data('containerID', $container.containerID).click($.proxy(this._showMessageOptionContainer, this));
-                       
-                       var $tabContainer = $('<div class="redactorMessageOptionContainer redactorMessageOptions_' + $container.containerID + '" />').hide().appendTo(this._messageOptionContainer[$instanceID]);
-                       for (var $j = 0; $j < $container.items.length; $j++) {
-                               $($container.items[$j]).appendTo($tabContainer);
-                       }
-                       
-                       this._messageOptions[$instanceID][$container.containerID] = {
-                               container: $tabContainer,
-                               listItem: $listItem
-                       };
-               }
-               
-               WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'updateMessageOptions', this._messageOptions);
-               
-               WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'reset', $.proxy(this._wOptionsListener, this));
-       },
-       
-       /**
-        * Toggles the specified message option container.
-        * 
-        * @param       object          event
-        * @param       string          containerID
-        */
-       _showMessageOptionContainer: function(event, containerID) {
-               var $containerID = (event === null) ? containerID : $(event.currentTarget).data('containerID');
-               var $instanceID = this.$source.wcfIdentify();
-               
-               if (this._messageOptions[$instanceID][$containerID].listItem.hasClass('active')) {
-                       this._messageOptions[$instanceID][$containerID].listItem.removeClass('active');
-                       this._messageOptions[$instanceID][$containerID].container.hide();
-                       
-                       return;
-               }
-               
-               $.each(this._messageOptions[$instanceID], function(containerID, elements) {
-                       if (containerID == $containerID) {
-                               elements.listItem.addClass('active');
-                               elements.container.show();
-                       }
-                       else {
-                               elements.listItem.removeClass('active');
-                               elements.container.hide();
-                       }
-               });
-       },
-       
-       /**
-        * Collapses all message option containers.
-        * 
-        * @param       object          data
-        */
-       _wOptionsListener: function(data) {
-               $.each(this._messageOptions, function(containerID, elements) {
-                       elements.listItem.removeClass('active');
-                       elements.container.hide();
-                       
-                       elements.container.find('input, select, textarea').each(function(index, element) {
-                               var $element = $(element);
-                               switch ($element.getTagName()) {
-                                       case 'input':
-                                               $element.prop('checked', false);
-                                       break;
-                                       
-                                       default:
-                                               $element.val('');
-                                       break;
-                               }
-                       });
-               });
-               
-               WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'updateMessageOptions', this._messageOptions);
-       }
-};
diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wupload.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wupload.js
deleted file mode 100644 (file)
index 209162d..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-if (!RedactorPlugins) var RedactorPlugins = {};
-
-/**
- * Provides file uploads for Redactor.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2014 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- */
-RedactorPlugins.wupload = {
-       /**
-        * attachments container object
-        * @var jQuery
-        */
-       _attachmentsContainer: null,
-       
-       /**
-        * Initializes the RedactorPlugins.wupload plugin.
-        */
-       init: function() {
-               var self = this;
-               this.buttonReplace('upload', 'upload', 'Upload', function() { self._attachmentsContainer.toggle(); });
-               this.buttonAwesome('upload', 'fa-upload');
-               
-               this._initAttachments();
-               
-               WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'reset', $.proxy(this._wUploadListener, this));
-       },
-       
-       /**
-        * Initializes the attachments user interface.
-        */
-       _initAttachments: function() {
-               this._attachmentsContainer = this._messageOptions[this.$source.wcfIdentify()].attachments.container;
-               var $attachmentList = $('<ul class="formAttachmentList clearfix" />').hide().appendTo(this._attachmentsContainer);
-               $('<dl class="wide"><dt></dt><dd><div data-max-size="{@$attachmentHandler->getMaxSize()}"></div><small>' + WCF.String.unescapeHTML(WCF.Language.get('wcf.attachment.upload.limits')) + '</small></dd></dl>').appendTo(this._attachmentsContainer);
-               
-               var $options = this.getOption('wattachment');
-               if ($options.attachments.length) {
-                       for (var $i = 0; $i < $options.attachments.length; $i++) {
-                               var $attachment = $options.attachments[$i];
-                               var $listItem = $('<li class="box48" />').data('objectID', $attachment.attachmentID);
-                               if ($attachment.tinyThumbnailUrl) {
-                                       $('<img src="' + $attachment.tinyThumbnailUrl + '" alt="" class="attachmentTinyThumbnail" />').appendTo($listItem);
-                               }
-                               else {
-                                       $('<span class="icon icon48 icon-paper-clip" />').appendTo($listItem);
-                               }
-                               
-                               var $div = $('<div />').appendTo($listItem);
-                               $('<div><p><a href="' + $attachment.url + '"' + ($attachment.isImage ? ' title="' + $attachment.filename + '" class="jsImageViewer"' : '') + '>' + $attachment.filename + '</a></p></div>').appendTo($div);
-                               var $list = $('<ul />').appendTo($div);
-                               $('<li><span class="icon icon16 icon-remove pointer jsTooltip jsDeleteButton " title="' + WCF.Language.get('wcf.global.button.delete') + '" data-object-id="' + $attachment.attachmentID + '" data-confirm-message="' + WCF.Language.get('wcf.attachment.delete.sure') + '"></span></li>').appendTo($list);
-                               $('<li><span class="icon icon16 icon-paste pointer jsTooltip jsButtonInsertAttachment" title="' + WCF.Language.get('wcf.attachment.insert') + '" data-object-id="' + $attachment.attachmentID + '"></span></li>').appendTo($list);
-                               
-                               $listItem.appendTo($attachmentList);
-                               
-                               $attachmentList.show();
-                       }
-                       
-                       this._showMessageOptionContainer(null, 'attachments');
-               }
-               
-               new WCF.Attachment.Upload(this._attachmentsContainer.find('> dl > dd > div'), this._attachmentsContainer.children('ul'), $options.objectType, $options.objectID, $options.tmpHash, $options.parentObjectID, $options.maxCount, this.$source.wcfIdentify());
-               new WCF.Action.Delete('wcf\\data\\attachment\\AttachmentAction', '.formAttachmentList > li');
-       },
-       
-       _wUploadListener: function(data) {
-               this._attachmentsContainer.children('.formAttachmentList').hide().empty();
-               this._attachmentsContainer.find('.jsButtonAttachmentInsertAll').hide();
-       }
-};
index ab69c071f134c420b458243335c4005111e387a3..15ebee4cde1fbdd330d3946af0fc115d9caddb80 100644 (file)
@@ -809,37 +809,7 @@ WCF.Message.QuickReply = Class.extend({
                        $parameters.anchor = this._container.data('anchor');
                }
                
-               // check for additional settings
-               var $container = $('#redactorMessageOptions_settings');
-               if ($container.length) {
-                       $parameters.settings = { };
-                       $container.find('input, textarea, select').each(function(index, element) {
-                               var $element = $(element);
-                               switch ($element.getTagName()) {
-                                       case 'input':
-                                               switch ($element.prop('type')) {
-                                                       case 'checkbox':
-                                                       case 'radio':
-                                                               if ($element.is(':checked')) {
-                                                                       $parameters.settings[$element.prop('name')] = $element.val();
-                                                               }
-                                                               else if ($element.data('submitEmpty')) {
-                                                                       $parameters.settings[$element.prop('name')] = 0;
-                                                               }
-                                                       break;
-                                                       
-                                                       default:
-                                                               $parameters.settings[$element.prop('name')] = $element.val();
-                                                       break;
-                                               }
-                                       break;
-                                       
-                                       default:
-                                               $parameters.settings[$element.prop('name')] = $element.val();
-                                       break;
-                               }
-                       });
-               }
+               WCF.System.Event.fireEvent('com.woltlab.wcf.messageOptionsInline', 'submit_' + this._messageField.wcfIdentify(), $parameters.data);
                
                return $parameters;
        },
@@ -1396,17 +1366,21 @@ WCF.Message.InlineEditor = Class.extend({
                        $message = $('#' + this._messageEditorIDPrefix + $objectID).val();
                }
                
+               var $parameters = {
+                       containerID: this._containerID,
+                       data: {
+                               message: $message
+                       },
+                       objectID: $objectID
+               };
+               
+               WCF.System.Event.fireEvent('com.woltlab.wcf.messageOptionsInline', 'submit_' + this._messageEditorIDPrefix + $objectID, $parameters);
+               
                this._proxy.setOption('data', {
                        actionName: 'save',
                        className: this._getClassName(),
                        interfaceName: 'wcf\\data\\IMessageInlineEditorAction',
-                       parameters: {
-                               containerID: this._containerID,
-                               data: {
-                                       message: $message
-                               },
-                               objectID: $objectID
-                       }
+                       parameters: $parameters
                });
                this._proxy.sendRequest();
                
@@ -1521,6 +1495,9 @@ WCF.Message.InlineEditor = Class.extend({
                
                // purge DOM elements
                $container.find('.messageBody > div > .messageInlineEditor').remove();
+               
+               // remove event listeners
+               WCF.System.Event.removeAllListeners('com.woltlab.wcf.messageOptionsInline', 'submit_' + this._messageEditorIDPrefix + $container.data('objectID'));
        },
        
        /**
@@ -3469,7 +3446,7 @@ $.widget('wcf.messageTabMenu', {
                        }
                }
                
-               if ($preselect === true) {
+               if ($preselect === true && this._tabs.length) {
                        // pick the first available tab
                        this._tabs[0].tab.children('a').trigger('click');
                }
index 1fb907995aad7fa32e7432ec1d044d3dbfcc41f7..8dc72225b1a4b967239b54b8fa7dc584d37c6ceb 100755 (executable)
@@ -730,6 +730,19 @@ $.extend(WCF, {
                                element.css($property, '');
                        }
                }
+       },
+       
+       /**
+        * Returns a RFC4122 version 4 compilant UUID.
+        * 
+        * @see         http://stackoverflow.com/a/2117523
+        * @return      string
+        */
+       getUUID: function() {
+               return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
+                       var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
+                       return v.toString(16);
+               });
        }
 });
 
@@ -7672,6 +7685,7 @@ WCF.System.Event = {
         * @param       string          identifier
         * @param       string          action
         * @param       object          listener
+        * @return      string
         */
        addListener: function(identifier, action, listener) {
                if (typeof this._listeners[identifier] === 'undefined') {
@@ -7682,7 +7696,52 @@ WCF.System.Event = {
                        this._listeners[identifier][action] = [ ];
                }
                
-               this._listeners[identifier][action].push(listener);
+               var $uuid = WCF.getUUID();
+               this._listeners[identifier][action].push({
+                       callback: listener,
+                       uuid: $uuid
+               });
+               
+               return $uuid;
+       },
+       
+       /**
+        * Removes a listener, requires the uuid returned by addListener().
+        * 
+        * @param       string          identifier
+        * @param       string          action
+        * @param       string          uuid
+        * @return      boolean
+        */
+       removeListener: function(identifier, action, uuid) {
+               if (this._listeners[identifier] && this._listeners[identifier][action]) {
+                       for (var $i = 0; $i < this._listeners[identifier][action].length; $i++) {
+                               if (this._listeners[identifier][action][$i].uuid = uuid) {
+                                       this._listeners[identifier][action].splice($i, 1);
+                                       
+                                       return true;
+                               }
+                       }
+               }
+               
+               return false;
+       },
+       
+       /**
+        * Removes all registered event listeners for given identifier and action.
+        * 
+        * @param       string          identifier
+        * @param       string          action
+        * @return      boolean
+        */
+       removeAllListeners: function(identifier, action) {
+               if (this._listeners[identifier] && this._listeners[identifier][action]) {
+                       delete this._listeners[identifier][action];
+                       
+                       return true;
+               }
+               
+               return false;
        },
        
        /**
@@ -7697,7 +7756,7 @@ WCF.System.Event = {
                
                if (this._listeners[identifier] && this._listeners[identifier][action]) {
                        for (var $i = 0; $i < this._listeners[identifier][action].length; $i++) {
-                               this._listeners[identifier][action][$i](data);
+                               this._listeners[identifier][action][$i].callback(data);
                        }
                }
        }
diff --git a/wcfsetup/install/files/lib/system/message/MessageFormSettingsHandler.class.php b/wcfsetup/install/files/lib/system/message/MessageFormSettingsHandler.class.php
new file mode 100644 (file)
index 0000000..e2c18a5
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+namespace wcf\system\message;
+use wcf\data\DatabaseObject;
+use wcf\system\WCF;
+
+/**
+ * Provides utility functions for common tasks related to inline editing and quick reply.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2014 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.message
+ * @category   Community Framework
+ */
+class MessageFormSettingsHandler {
+       /**
+        * Computes the settings for BBCodes, Smilies and pre parsing. Optionally accepts the corresponding DatabaseObject
+        * whose values will be used in case the settings did not contain the individual values (legacy support).
+        * 
+        * @param       array<array>                    $parameters
+        * @param       \wcf\data\DatabaseObject        $object
+        * @param       string                          $permissionCanUseBBCodes
+        * @param       string                          $permissionCanUseSmilies
+        * @return      array
+        */
+       public static function getSettings(array $parameters, DatabaseObject $object = null, $permissionCanUseBBCodes = '', $permissionCanUseSmilies = '') {
+               $permissionCanUseBBCodes = ($permissionCanUseBBCodes) ?: 'user.message.canUseBBCodes';
+               $permissionCanUseSmilies = ($permissionCanUseSmilies) ?: 'user.message.canUseSmilies';
+               
+               $enableSmilies = 0;
+               $enableBBCodes = 0;
+               $preParse = 0;
+               
+               if (WCF::getSession()->getPermission($permissionCanUseSmilies)) {
+                       if (isset($parameters['enableSmilies'])) {
+                               $enableSmilies = ($parameters['enableSmilies']) ? 1 : 0;
+                       }
+                       else {
+                               $enableSmilies = ($object === null) ? 1 : $object->enableSmilies;
+                       }
+               }
+               else if ($object !== null) {
+                       $enableSmilies = ($object->enableSmilies) ? 1 : 0;
+               }
+               
+               if (WCF::getSession()->getPermission($permissionCanUseBBCodes)) {
+                       if (isset($parameters['enableBBCodes'])) {
+                               $enableBBCodes = ($parameters['enableBBCodes']) ? 1 : 0;
+                       }
+                       else {
+                               $enableBBCodes = ($object === null) ? 1 : $object->enableBBCodes;
+                       }
+                       
+                       if (isset($parameters['preParse'])) {
+                               $preParse = ($parameters['preParse'] && $enableBBCodes) ? 1 : 0;
+                       }
+                       else {
+                               $preParse = $enableBBCodes;
+                       }
+               }
+               else if ($object !== null) {
+                       $enableBBCodes = $preParse = ($object->enableBBCodes) ? 1 : 0;
+               }
+               
+               return array(
+                       'enableSmilies' => $enableSmilies,
+                       'enableBBCodes' => $enableBBCodes,
+                       'preParse' => $preParse
+               );
+       }
+}
index 016186389b5a95661869faf66c7f410aef149de8..2bb68353e04867e10feff4fb6f6f7325a1839c58 100644 (file)
@@ -157,6 +157,12 @@ class QuickReplyManager extends SingletonFactory {
                // check for tmp hash (attachments)
                $parameters['tmpHash'] = (isset($parameters['tmpHash'])) ? StringUtil::trim($parameters['tmpHash']) : '';
                
+               // message settings
+               $parameters['data'] = array_merge($parameters['data'], MessageFormSettingsHandler::getSettings($parameters));
+               
+               $parameters['data']['enableHtml'] = 0;
+               $parameters['data']['showSignature'] = (WCF::getUser()->userID ? WCF::getUser()->showSignature : 0);
+               
                EventHandler::getInstance()->fireAction($this, 'validateParameters');
        }
        
@@ -176,17 +182,16 @@ class QuickReplyManager extends SingletonFactory {
                
                $tableIndexName = call_user_func(array($this->container, 'getDatabaseTableIndexName'));
                $parameters['data'][$tableIndexName] = $parameters['objectID'];
-               $parameters['data']['enableSmilies'] = WCF::getSession()->getPermission('user.message.canUseSmilies');
-               $parameters['data']['enableHtml'] = 0;
-               $parameters['data']['enableBBCodes'] = WCF::getSession()->getPermission('user.message.canUseBBCodes');
-               $parameters['data']['showSignature'] = (WCF::getUser()->userID ? WCF::getUser()->showSignature : 0);
                $parameters['data']['time'] = TIME_NOW;
                $parameters['data']['userID'] = WCF::getUser()->userID ?: null;
                $parameters['data']['username'] = WCF::getUser()->username;
                
                // pre-parse message text
                $parameters['data']['message'] = MessageUtil::stripCrap($parameters['data']['message']);
-               $parameters['data']['message'] = PreParser::getInstance()->parse($parameters['data']['message'], $this->allowedBBodes);
+               if ($parameters['data']['preParse']) {
+                       $parameters['data']['message'] = PreParser::getInstance()->parse($parameters['data']['message'], $this->allowedBBodes);
+               }
+               unset($parameters['data']['preParse']);
                
                $parameters['data'] = array_merge($this->additionalFields, $parameters['data']);