Temporarily fix MessageQuoteManager
authorMatthias Schmidt <gravatronics@live.com>
Fri, 1 Jan 2016 06:53:39 +0000 (07:53 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 1 Jan 2016 06:53:39 +0000 (07:53 +0100)
wcfsetup/install/files/lib/system/message/quote/MessageQuoteManager.class.php

index 402294c6c7cd21bd3b0643a35c67fcb7b8799223..d50b644f1c02f4748797746c62bbb4951be9ac39 100644 (file)
@@ -12,7 +12,7 @@ use wcf\util\ArrayUtil;
  * Manages message quotes.
  * 
  * @author     Alexander Ebert
- * @copyright  2001-2015 WoltLab GmbH
+ * @copyright  2001-2016 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.message.quote
@@ -21,9 +21,9 @@ use wcf\util\ArrayUtil;
 class MessageQuoteManager extends SingletonFactory {
        /**
         * current object ids
-        * @var array<integer>
+        * @var integer[]
         */
-       protected $objectIDs = array();
+       protected $objectIDs = [];
        
        /**
         * current object type name
@@ -33,9 +33,9 @@ class MessageQuoteManager extends SingletonFactory {
        
        /**
         * list of object types
-        * @var array<\wcf\data\object\type\ObjectType>
+        * @var ObjectType[]
         */
-       protected $objectTypes = array();
+       protected $objectTypes = [];
        
        /**
         * primary application's package id
@@ -47,13 +47,13 @@ class MessageQuoteManager extends SingletonFactory {
         * list of stored quotes
         * @var array<array>
         */
-       protected $quotes = array();
+       protected $quotes = [];
        
        /**
         * list of quote messages by quote id
-        * @var array<string>
+        * @var string[]
         */
-       protected $quoteData = array();
+       protected $quoteData = [];
        
        /**
         * message id for quoting
@@ -63,22 +63,24 @@ class MessageQuoteManager extends SingletonFactory {
        
        /**
         * list of quote ids to be removed
-        * @var array<string>
+        * @var string[]
         */
-       protected $removeQuoteIDs = array();
+       protected $removeQuoteIDs = [];
        
        /**
-        * @see \wcf\system\SingletonFactory::init()
+        * @inheritDoc
         */
        protected function init() {
-               $this->packageID = ApplicationHandler::getInstance()->getPrimaryApplication()->packageID;
+               // @todo
+               $this->packageID = 1;
+               //$this->packageID = ApplicationHandler::getInstance()->getPrimaryApplication()->packageID;
                
                // load stored quotes from session
                $messageQuotes = WCF::getSession()->getVar('__messageQuotes'.$this->packageID);
                if (is_array($messageQuotes)) {
-                       $this->quotes = (isset($messageQuotes['quotes'])) ? $messageQuotes['quotes'] : array();
-                       $this->quoteData = (isset($messageQuotes['quoteData'])) ? $messageQuotes['quoteData'] : array();
-                       $this->removeQuoteIDs = (isset($messageQuotes['removeQuoteIDs'])) ? $messageQuotes['removeQuoteIDs'] : array();
+                       $this->quotes = (isset($messageQuotes['quotes'])) ? $messageQuotes['quotes'] : [];
+                       $this->quoteData = (isset($messageQuotes['quoteData'])) ? $messageQuotes['quoteData'] : [];
+                       $this->removeQuoteIDs = (isset($messageQuotes['removeQuoteIDs'])) ? $messageQuotes['removeQuoteIDs'] : [];
                }
                
                // load object types
@@ -106,11 +108,11 @@ class MessageQuoteManager extends SingletonFactory {
                }
                
                if (!isset($this->quotes[$objectType])) {
-                       $this->quotes[$objectType] = array();
+                       $this->quotes[$objectType] = [];
                }
                
                if (!isset($this->quotes[$objectType][$objectID])) {
-                       $this->quotes[$objectType][$objectID] = array();
+                       $this->quotes[$objectType][$objectID] = [];
                }
                
                $quoteID = $this->getQuoteID($objectType, $objectID, $message, $fullQuote);
@@ -121,15 +123,15 @@ class MessageQuoteManager extends SingletonFactory {
                        // save parent object id
                        
                        if (!isset($this->quoteData['parents'])) {
-                               $this->quoteData['parents'] = array();
+                               $this->quoteData['parents'] = [];
                        }
                        
                        if (!isset($this->quoteData['parents'][$objectType])) {
-                               $this->quoteData['parents'][$objectType] = array();
+                               $this->quoteData['parents'][$objectType] = [];
                        }
                        
                        if (!isset($this->quoteData['parents'][$objectType][$parentObjectID])) {
-                               $this->quoteData['parents'][$objectType][$parentObjectID] = array();
+                               $this->quoteData['parents'][$objectType][$parentObjectID] = [];
                        }
                        
                        $this->quoteData['parents'][$objectType][$parentObjectID][] = $objectID;
@@ -230,7 +232,7 @@ class MessageQuoteManager extends SingletonFactory {
         * Returns an array containing the quote author, link and text.
         * 
         * @param       string          $quoteID
-        * @return      array<string>
+        * @return      string[]
         */
        public function getQuoteComponents($quoteID) {
                if ($this->getQuote($quoteID, false) === null) {
@@ -238,18 +240,18 @@ class MessageQuoteManager extends SingletonFactory {
                }
                
                // find the quote and simulate a regular call to render quotes
-               $quoteData = array();
+               $quoteData = [];
                foreach ($this->quotes as $objectType => $objectIDs) {
                        foreach ($objectIDs as $objectID => $quoteIDs) {
                                if (isset($quoteIDs[$quoteID])) {
-                                       $quoteHandler = call_user_func(array($this->objectTypes[$objectType]->className, 'getInstance'));
-                                       $renderedQuotes = $quoteHandler->renderQuotes(array(
-                                               $objectID => array(
+                                       $quoteHandler = call_user_func([$this->objectTypes[$objectType]->className, 'getInstance']);
+                                       $renderedQuotes = $quoteHandler->renderQuotes([
+                                               $objectID => [
                                                        $quoteID => $quoteIDs[$quoteID]
-                                               )
-                                       ), true, false);
+                                               ]
+                                       ], true, false);
                                        
-                                       $this->markQuotesForRemoval(array($quoteID));
+                                       $this->markQuotesForRemoval([$quoteID]);
                                        
                                        return $renderedQuotes[0];
                                }
@@ -266,7 +268,7 @@ class MessageQuoteManager extends SingletonFactory {
                $template = '';
                
                foreach ($this->quotes as $objectType => $objectData) {
-                       $quoteHandler = call_user_func(array($this->objectTypes[$objectType]->className, 'getInstance'));
+                       $quoteHandler = call_user_func([$this->objectTypes[$objectType]->className, 'getInstance']);
                        $template .= $quoteHandler->render($objectData, $supportPaste);
                }
                
@@ -277,17 +279,17 @@ class MessageQuoteManager extends SingletonFactory {
         * Returns a list of quotes by object type and id.
         * 
         * @param       string          $objectType
-        * @param       array<integer>  $objectIDs
+        * @param       integer[]       $objectIDs
         * @param       boolean         $markForRemoval
-        * @return      array<string>
+        * @return      string[]
         */
        public function getQuotesByObjectIDs($objectType, array $objectIDs, $markForRemoval = true) {
                if (!isset($this->quotes[$objectType])) {
-                       return array();
+                       return [];
                }
                
-               $data = array();
-               $removeQuoteIDs = array();
+               $data = [];
+               $removeQuoteIDs = [];
                foreach ($this->quotes[$objectType] as $objectID => $quoteIDs) {
                        if (in_array($objectID, $objectIDs)) {
                                $data[$objectID] = $quoteIDs;
@@ -301,7 +303,7 @@ class MessageQuoteManager extends SingletonFactory {
                
                // no quotes found
                if (empty($data)) {
-                       return array();
+                       return [];
                }
                
                // mark quotes for removal
@@ -309,7 +311,7 @@ class MessageQuoteManager extends SingletonFactory {
                        $this->markQuotesForRemoval($removeQuoteIDs);
                }
                
-               $quoteHandler = call_user_func(array($this->objectTypes[$objectType]->className, 'getInstance'));
+               $quoteHandler = call_user_func([$this->objectTypes[$objectType]->className, 'getInstance']);
                return $quoteHandler->renderQuotes($data);
        }
        
@@ -319,15 +321,15 @@ class MessageQuoteManager extends SingletonFactory {
         * @param       string          $objectType
         * @param       integer         $parentObjectID
         * @param       boolean         $markForRemoval
-        * @return      array<string>
+        * @return      string[]
         */
        public function getQuotesByParentObjectID($objectType, $parentObjectID, $markForRemoval = true) {
                if (!isset($this->quoteData['parents'][$objectType][$parentObjectID])) {
-                       return array();
+                       return [];
                }
                
-               $data = array();
-               $removeQuoteIDs = array();
+               $data = [];
+               $removeQuoteIDs = [];
                foreach ($this->quoteData['parents'][$objectType][$parentObjectID] as $objectID) {
                        if (isset($this->quotes[$objectType][$objectID])) {
                                $data[$objectID] = $this->quotes[$objectType][$objectID];
@@ -341,7 +343,7 @@ class MessageQuoteManager extends SingletonFactory {
                
                // no quotes found
                if (empty($data)) {
-                       return array();
+                       return [];
                }
                
                // mark quotes for removal
@@ -349,7 +351,7 @@ class MessageQuoteManager extends SingletonFactory {
                        $this->markQuotesForRemoval($removeQuoteIDs);
                }
                
-               $quoteHandler = call_user_func(array($this->objectTypes[$objectType]->className, 'getInstance'));
+               $quoteHandler = call_user_func([$this->objectTypes[$objectType]->className, 'getInstance']);
                return $quoteHandler->renderQuotes($data, false);
        }
        
@@ -394,7 +396,7 @@ class MessageQuoteManager extends SingletonFactory {
        /**
         * Marks quote ids for removal.
         * 
-        * @param       array<string>   $quoteIDs
+        * @param       string[]        $quoteIDs
         */
        public function markQuotesForRemoval(array $quoteIDs) {
                foreach ($quoteIDs as $index => $quoteID) {
@@ -412,24 +414,24 @@ class MessageQuoteManager extends SingletonFactory {
        /**
         * Renders a quote for given message.
         * 
-        * @param       \wcf\data\IMessage      $message
-        * @param       string                  $text
-        * @param       boolean                 $renderAsString
+        * @param       IMessage        $message
+        * @param       string          $text
+        * @param       boolean         $renderAsString
         * @return      string
         */
        public function renderQuote(IMessage $message, $text, $renderAsString = true) {
-               $escapedUsername = str_replace(array("\\", "'"), array("\\\\", "\'"), $message->getUsername());
-               $escapedLink = str_replace(array("\\", "'"), array("\\\\", "\'"), $message->getLink());
+               $escapedUsername = str_replace(["\\", "'"], ["\\\\", "\'"], $message->getUsername());
+               $escapedLink = str_replace(["\\", "'"], ["\\\\", "\'"], $message->getLink());
                
                if ($renderAsString) {
                        return "[quote='".$escapedUsername."','".$escapedLink."']".$text."[/quote]";
                }
                else {
-                       return array(
+                       return [
                                'username' => $escapedUsername,
                                'link' => $escapedLink,
                                'text' => $text
-                       );
+                       ];
                }
        }
        
@@ -443,7 +445,7 @@ class MessageQuoteManager extends SingletonFactory {
                        }
                        
                        // reset list of quote ids marked for removal
-                       $this->removeQuoteIDs = array();
+                       $this->removeQuoteIDs = [];
                        
                        $this->updateSession();
                }
@@ -468,18 +470,18 @@ class MessageQuoteManager extends SingletonFactory {
        /**
         * Returns a list of full quotes by object id for given object types.
         * 
-        * @param       array<string>           $objectTypes
+        * @param       string[]                $objectTypes
         * @return      array<array>
         */
        public function getFullQuoteObjectIDs(array $objectTypes) {
-               $objectIDs = array();
+               $objectIDs = [];
                
                foreach ($objectTypes as $objectType) {
                        if (!isset($this->objectTypes[$objectType])) {
                                throw new SystemException("Object type '".$objectType."' is unknown");
                        }
                        
-                       $objectIDs[$objectType] = array();
+                       $objectIDs[$objectType] = [];
                        if (isset($this->quotes[$objectType])) {
                                foreach ($this->quotes[$objectType] as $objectID => $quotes) {
                                        foreach ($quotes as $quoteID => $isFullQuote) {
@@ -499,7 +501,7 @@ class MessageQuoteManager extends SingletonFactory {
         * Sets object type and object ids.
         * 
         * @param       string          $objectType
-        * @param       array<integer>  $objectIDs
+        * @param       integer[]       $objectIDs
         */
        public function initObjects($objectType, array $objectIDs) {
                if (!isset($this->objectTypes[$objectType])) {
@@ -546,7 +548,7 @@ class MessageQuoteManager extends SingletonFactory {
         * Assigns variables on page load.
         */
        public function assignVariables() {
-               $fullQuoteObjectIDs = array();
+               $fullQuoteObjectIDs = [];
                if (!empty($this->objectType) && !empty($this->objectIDs) && isset($this->quotes[$this->objectType])) {
                        foreach ($this->quotes[$this->objectType] as $objectID => $quotes) {
                                if (!in_array($objectID, $this->objectIDs)) {
@@ -562,11 +564,11 @@ class MessageQuoteManager extends SingletonFactory {
                        }
                }
                
-               WCF::getTPL()->assign(array(
+               WCF::getTPL()->assign([
                        '__quoteCount' => $this->countQuotes(),
                        '__quoteFullQuote' => $fullQuoteObjectIDs,
                        '__quoteRemove' => $this->removeQuoteIDs
-               ));
+               ]);
        }
        
        /**
@@ -581,7 +583,7 @@ class MessageQuoteManager extends SingletonFactory {
        /**
         * Removes orphaned quote ids
         * 
-        * @param       array<integer>          $quoteIDs
+        * @param       integer[]               $quoteIDs
         */
        public function removeOrphanedQuotes(array $quoteIDs) {
                foreach ($quoteIDs as $quoteID) {
@@ -595,10 +597,10 @@ class MessageQuoteManager extends SingletonFactory {
         * Updates data stored in session,
         */
        protected function updateSession() {
-               WCF::getSession()->register('__messageQuotes'.$this->packageID, array(
+               WCF::getSession()->register('__messageQuotes'.$this->packageID, [
                        'quotes' => $this->quotes,
                        'quoteData' => $this->quoteData,
                        'removeQuoteIDs' => $this->removeQuoteIDs
-               ));
+               ]);
        }
 }