* 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
class MessageQuoteManager extends SingletonFactory {
/**
* current object ids
- * @var array<integer>
+ * @var integer[]
*/
- protected $objectIDs = array();
+ protected $objectIDs = [];
/**
* current object type name
/**
* list of object types
- * @var array<\wcf\data\object\type\ObjectType>
+ * @var ObjectType[]
*/
- protected $objectTypes = array();
+ protected $objectTypes = [];
/**
* primary application's package id
* 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
/**
* 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
}
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);
// 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;
* 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) {
}
// 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];
}
$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);
}
* 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;
// no quotes found
if (empty($data)) {
- return array();
+ return [];
}
// mark quotes for removal
$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);
}
* @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];
// no quotes found
if (empty($data)) {
- return array();
+ return [];
}
// mark quotes for removal
$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);
}
/**
* Marks quote ids for removal.
*
- * @param array<string> $quoteIDs
+ * @param string[] $quoteIDs
*/
public function markQuotesForRemoval(array $quoteIDs) {
foreach ($quoteIDs as $index => $quoteID) {
/**
* 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
- );
+ ];
}
}
}
// reset list of quote ids marked for removal
- $this->removeQuoteIDs = array();
+ $this->removeQuoteIDs = [];
$this->updateSession();
}
/**
* 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) {
* 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])) {
* 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)) {
}
}
- WCF::getTPL()->assign(array(
+ WCF::getTPL()->assign([
'__quoteCount' => $this->countQuotes(),
'__quoteFullQuote' => $fullQuoteObjectIDs,
'__quoteRemove' => $this->removeQuoteIDs
- ));
+ ]);
}
/**
/**
* Removes orphaned quote ids
*
- * @param array<integer> $quoteIDs
+ * @param integer[] $quoteIDs
*/
public function removeOrphanedQuotes(array $quoteIDs) {
foreach ($quoteIDs as $quoteID) {
* 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
- ));
+ ]);
}
}