-<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>
--- /dev/null
+<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>
<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}
<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
--- /dev/null
+{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
-{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">
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'}
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);
});
'{@$__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() {
+++ /dev/null
-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);
- }
-};
+++ /dev/null
-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();
- }
-};
$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;
},
$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();
// 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'));
},
/**
}
}
- if ($preselect === true) {
+ if ($preselect === true && this._tabs.length) {
// pick the first available tab
this._tabs[0].tab.children('a').trigger('click');
}
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);
+ });
}
});
* @param string identifier
* @param string action
* @param object listener
+ * @return string
*/
addListener: function(identifier, action, listener) {
if (typeof this._listeners[identifier] === 'undefined') {
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;
},
/**
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);
}
}
}
--- /dev/null
+<?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
+ );
+ }
+}
// 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');
}
$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']);