Add createMessage and createdMessage event to QuickReplyManager
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 21 Mar 2014 00:51:29 +0000 (01:51 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 24 Mar 2014 18:12:25 +0000 (19:12 +0100)
Closes #1596

wcfsetup/install/files/lib/system/message/QuickReplyManager.class.php

index 295a7ca27604c8c901e8ab201c3bc157d2b1d05d..fee4a6f56d298419fcf7ca67b5f8765a4f8a0e90 100644 (file)
@@ -48,6 +48,17 @@ class QuickReplyManager extends SingletonFactory {
         */
        public $type = '';
        
+       /**
+        * additional fields
+        * @var array
+        */
+       public $additionalFields = array();
+       
+       /**
+        * the message that just was created
+        */
+       public $message = null;
+       
        /**
         * Returns a stored message from session.
         * 
@@ -139,6 +150,8 @@ class QuickReplyManager extends SingletonFactory {
                
                // check for message quote ids
                $parameters['removeQuoteIDs'] = (isset($parameters['removeQuoteIDs']) && is_array($parameters['removeQuoteIDs'])) ? ArrayUtil::trim($parameters['removeQuoteIDs']) : array();
+               
+               EventHandler::getInstance()->fireAction($this, 'validateParameters');
        }
        
        /**
@@ -153,6 +166,8 @@ class QuickReplyManager extends SingletonFactory {
         * @return      array
         */
        public function createMessage(IMessageQuickReplyAction $object, array &$parameters, $containerActionClassName, $sortOrder, $templateName, $application = 'wcf') {
+               EventHandler::getInstance()->fireAction($this, 'createMessage');
+               
                $tableIndexName = call_user_func(array($this->container, 'getDatabaseTableIndexName'));
                $parameters['data'][$tableIndexName] = $parameters['objectID'];
                $parameters['data']['enableSmilies'] = WCF::getSession()->getPermission('user.message.canUseSmilies');
@@ -160,14 +175,25 @@ class QuickReplyManager extends SingletonFactory {
                $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;
+               $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);
                
-               $message = $object->create();
+               $parameters['data'] = array_merge($this->additionalFields, $parameters['data']);
+               
+               // clean up
+               $this->additionalFields = array();
+               
+               $this->message = $object->create();
+               EventHandler::getInstance()->fireAction($this, 'createdMessage');
+               $message = $this->message;
+               
+               // clean up
+               $this->message = null;
+               
                if ($message instanceof IMessage && !$message->isVisible()) {
                        return array(
                                'isVisible' => false