From 00167fc6ed26277e9893a0b415c7b7fcb45e8233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 4 Mar 2022 18:10:24 +0100 Subject: [PATCH] Reformat PHP files as PSR-12 --- files/acp/be.bastelstu.chat_install.php | 20 +- files/acp/be.bastelstu.chat_update.php | 43 +- files/acp/global.php | 11 +- files/acp/index.php | 10 +- files/global.php | 9 +- files/index.php | 10 +- .../acp/form/CommandTriggerAddForm.class.php | 258 ++++--- .../acp/form/CommandTriggerEditForm.class.php | 175 +++-- files/lib/acp/form/RoomAddForm.class.php | 357 +++++---- files/lib/acp/form/RoomEditForm.class.php | 203 +++-- .../acp/page/CommandTriggerListPage.class.php | 74 +- files/lib/acp/page/RoomListPage.class.php | 56 +- .../lib/acp/page/SuspensionListPage.class.php | 369 ++++----- files/lib/data/command/Command.class.php | 63 +- files/lib/data/command/CommandCache.class.php | 171 +++-- .../lib/data/command/CommandEditor.class.php | 18 +- files/lib/data/command/CommandList.class.php | 10 +- .../lib/data/command/CommandTrigger.class.php | 73 +- .../command/CommandTriggerAction.class.php | 30 +- .../command/CommandTriggerEditor.class.php | 33 +- .../data/command/CommandTriggerList.class.php | 11 +- files/lib/data/message/Message.class.php | 94 +-- .../lib/data/message/MessageAction.class.php | 721 ++++++++++-------- .../lib/data/message/MessageEditor.class.php | 46 +- files/lib/data/message/MessageList.class.php | 10 +- .../data/message/ViewableMessage.class.php | 86 ++- files/lib/data/room/Room.class.php | 441 ++++++----- files/lib/data/room/RoomAction.class.php | 718 +++++++++-------- files/lib/data/room/RoomCache.class.php | 90 ++- files/lib/data/room/RoomEditor.class.php | 36 +- files/lib/data/room/RoomList.class.php | 18 +- .../lib/data/suspension/Suspension.class.php | 178 +++-- .../suspension/SuspensionAction.class.php | 101 ++- .../suspension/SuspensionEditor.class.php | 18 +- .../data/suspension/SuspensionList.class.php | 11 +- files/lib/data/user/User.class.php | 171 +++-- files/lib/data/user/UserAction.class.php | 198 ++--- files/lib/data/user/UserList.class.php | 16 +- files/lib/page/LogPage.class.php | 294 +++---- files/lib/page/RoomListPage.class.php | 83 +- files/lib/page/RoomPage.class.php | 193 +++-- files/lib/page/TConfiguredPage.class.php | 81 +- files/lib/system/CHATCore.class.php | 51 +- .../MessageAttachmentObjectType.class.php | 164 ++-- .../box/RoomListBoxController.class.php | 198 ++--- .../builder/CommandCacheBuilder.class.php | 60 +- .../builder/PermissionCacheBuilder.class.php | 72 +- .../cache/builder/RoomCacheBuilder.class.php | 30 +- .../cache/runtime/UserRuntimeCache.class.php | 19 +- .../system/command/AbstractCommand.class.php | 115 +-- .../AbstractInputProcessedCommand.class.php | 152 ++-- .../AbstractSuspensionCommand.class.php | 304 ++++---- .../AbstractUnsuspensionCommand.class.php | 274 ++++--- .../lib/system/command/AwayCommand.class.php | 146 ++-- .../lib/system/command/BackCommand.class.php | 131 ++-- files/lib/system/command/BanCommand.class.php | 152 ++-- .../system/command/BroadcastCommand.class.php | 139 ++-- .../lib/system/command/ColorCommand.class.php | 541 +++++++------ files/lib/system/command/ICommand.class.php | 108 +-- .../lib/system/command/InfoCommand.class.php | 137 ++-- files/lib/system/command/MeCommand.class.php | 150 ++-- .../lib/system/command/MuteCommand.class.php | 87 ++- .../lib/system/command/PlainCommand.class.php | 137 ++-- files/lib/system/command/TNeedsUser.class.php | 74 +- .../lib/system/command/TeamCommand.class.php | 138 ++-- .../system/command/TemproomCommand.class.php | 279 ++++--- .../lib/system/command/UnbanCommand.class.php | 89 ++- .../system/command/UnmuteCommand.class.php | 87 ++- .../lib/system/command/WhereCommand.class.php | 113 +-- .../system/command/WhisperCommand.class.php | 139 ++-- .../room/RoomFilledCondition.class.php | 52 +- ...ronjobExecuteChatCleanUpListener.class.php | 47 +- ...UpCronjobExecuteTemproomListener.class.php | 55 +- .../InfoCommandSuspensionsListener.class.php | 75 +- ...mActionGetUsersModeratorListener.class.php | 51 +- .../listener/RoomCanJoinBanListener.class.php | 51 +- .../RoomCanJoinUserLimitListener.class.php | 53 +- .../RoomCanSeeTemproomListener.class.php | 55 +- ...RoomCanWritePubliclyMuteListener.class.php | 51 +- .../RoomEditFormTemproomListener.class.php | 28 +- .../RoomListPageTemproomListener.class.php | 23 +- ...spensionListPageTemproomListener.class.php | 28 +- .../type/AttachmentMessageType.class.php | 125 +-- .../message/type/AwayMessageType.class.php | 116 +-- .../message/type/BackMessageType.class.php | 116 +-- .../type/BroadcastMessageType.class.php | 137 ++-- .../type/ChatUpdateMessageType.class.php | 68 +- .../message/type/ColorMessageType.class.php | 87 ++- .../type/IDeletableMessageType.class.php | 30 +- .../message/type/IMessageType.class.php | 104 +-- .../message/type/InfoMessageType.class.php | 25 +- .../message/type/JoinMessageType.class.php | 25 +- .../message/type/LeaveMessageType.class.php | 25 +- .../message/type/MeMessageType.class.php | 46 +- .../message/type/PlainMessageType.class.php | 125 +-- .../message/type/SuspendMessageType.class.php | 134 ++-- .../message/type/TCanSeeCreator.class.php | 95 ++- .../message/type/TCanSeeInSameRoom.class.php | 95 ++- .../message/type/TDefaultPayload.class.php | 43 +- .../message/type/TeamMessageType.class.php | 137 ++-- .../type/TemproomCreatedMessageType.class.php | 25 +- .../type/TemproomInvitedMessageType.class.php | 149 ++-- .../type/TombstoneMessageType.class.php | 87 ++- .../type/UnsuspendMessageType.class.php | 134 ++-- .../message/type/WhereMessageType.class.php | 79 +- .../message/type/WhisperMessageType.class.php | 186 +++-- .../page/handler/LogPageHandler.class.php | 112 ++- .../handler/RoomListPageHandler.class.php | 56 +- .../page/handler/RoomPageHandler.class.php | 114 ++- .../page/handler/TRoomPageHandler.class.php | 102 +-- .../permission/PermissionHandler.class.php | 207 ++--- .../system/suspension/BanSuspension.class.php | 59 +- .../system/suspension/ISuspension.class.php | 24 +- .../suspension/MuteSuspension.class.php | 59 +- ...CommandPackageInstallationPlugin.class.php | 279 +++---- 115 files changed, 7658 insertions(+), 5810 deletions(-) diff --git a/files/acp/be.bastelstu.chat_install.php b/files/acp/be.bastelstu.chat_install.php index b724755..eba29ea 100644 --- a/files/acp/be.bastelstu.chat_install.php +++ b/files/acp/be.bastelstu.chat_install.php @@ -1,21 +1,25 @@ createBoxCondition( 'be.bastelstu.chat.roomListDashboard' - , 'be.bastelstu.chat.box.roomList.condition' - , 'be.bastelstu.chat.roomFilled' - , [ 'chatRoomIsFilled' => 1 ] - ); +BoxHandler::getInstance()->createBoxCondition( + 'be.bastelstu.chat.roomListDashboard', + 'be.bastelstu.chat.box.roomList.condition', + 'be.bastelstu.chat.roomFilled', + [ + 'chatRoomIsFilled' => 1, + ] +); diff --git a/files/acp/be.bastelstu.chat_update.php b/files/acp/be.bastelstu.chat_update.php index 5849109..df7d961 100644 --- a/files/acp/be.bastelstu.chat_update.php +++ b/files/acp/be.bastelstu.chat_update.php @@ -1,35 +1,44 @@ getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.chatUpdate'); +$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.messageType', + 'be.bastelstu.chat.messageType.chatUpdate' +); if ($objectTypeID) { - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => null - , 'userID' => null - , 'username' => '' - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ ]) - ] - ] - ) - )->executeAction(); + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => null, + 'userID' => null, + 'username' => '', + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ ]), + ], + ] + ))->executeAction(); } -$CHATCore = file_get_contents(__DIR__.'/../lib/system/CHATCore.class.php'); -if (strpos($CHATCore, 'chat.phar.php') === false) { - @unlink(__DIR__.'/../chat.phar.php'); +$CHATCore = \file_get_contents(__DIR__ . '/../lib/system/CHATCore.class.php'); +if (\strpos($CHATCore, 'chat.phar.php') === false) { + @\unlink(__DIR__ . '/../chat.phar.php'); } diff --git a/files/acp/global.php b/files/acp/global.php index 365044b..800a7c6 100644 --- a/files/acp/global.php +++ b/files/acp/global.php @@ -1,18 +1,19 @@ handle('chat', true); + +RequestHandler::getInstance()->handle('chat', true); diff --git a/files/global.php b/files/global.php index 09398c5..ffe7c9f 100644 --- a/files/global.php +++ b/files/global.php @@ -1,16 +1,17 @@ handle('chat'); + +RequestHandler::getInstance()->handle('chat'); diff --git a/files/lib/acp/form/CommandTriggerAddForm.class.php b/files/lib/acp/form/CommandTriggerAddForm.class.php index 2085116..32f23f6 100644 --- a/files/lib/acp/form/CommandTriggerAddForm.class.php +++ b/files/lib/acp/form/CommandTriggerAddForm.class.php @@ -1,11 +1,12 @@ sqlOrderBy = 'command.className'; - $commandList->readObjects(); + /** + * @inheritDoc + */ + public function readData() + { + $commandList = new CommandList(); + $commandList->sqlOrderBy = 'command.className'; + $commandList->readObjects(); - $this->commands = $commandList->getObjects(); + $this->commands = $commandList->getObjects(); - parent::readData(); - } + parent::readData(); + } - /** - * @inheritDoc - */ - public function readFormParameters() { - parent::readFormParameters(); + /** + * @inheritDoc + */ + public function readFormParameters() + { + parent::readFormParameters(); - if (isset($_POST['commandTrigger'])) $this->commandTrigger = \wcf\util\StringUtil::trim($_POST['commandTrigger']); - if (isset($_POST['className'])) $this->className = \wcf\util\StringUtil::trim($_POST['className']); - } + if (isset($_POST['commandTrigger'])) { + $this->commandTrigger = StringUtil::trim($_POST['commandTrigger']); + } + if (isset($_POST['className'])) { + $this->className = StringUtil::trim($_POST['className']); + } + } - /** - * @inheritDoc - */ - public function validate() { - parent::validate(); + /** + * @inheritDoc + */ + public function validate() + { + parent::validate(); - if (empty($this->commandTrigger)) { - throw new UserInputException('commandTrigger', 'empty'); - } + if (empty($this->commandTrigger)) { + throw new UserInputException('commandTrigger', 'empty'); + } - // Triggers must not contain whitespace - if (preg_match('~\s~', $this->commandTrigger)) { - throw new UserInputException('commandTrigger', 'invalid'); - } + // Triggers must not contain whitespace + if (\preg_match('~\s~', $this->commandTrigger)) { + throw new UserInputException('commandTrigger', 'invalid'); + } - // Check for duplicates - $trigger = CommandTrigger::getTriggerByName($this->commandTrigger); - if ((!isset($this->trigger) && $trigger->triggerID) || (isset($this->trigger) && $trigger->triggerID != $this->trigger->triggerID)) { - throw new UserInputException('commandTrigger', 'duplicate'); - } + // Check for duplicates + $trigger = CommandTrigger::getTriggerByName($this->commandTrigger); + if ( + (!isset($this->trigger) && $trigger->triggerID) + || (isset($this->trigger) && $trigger->triggerID != $this->trigger->triggerID) + ) { + throw new UserInputException('commandTrigger', 'duplicate'); + } - if (empty($this->className)) { - throw new UserInputException('className', 'empty'); - } + if (empty($this->className)) { + throw new UserInputException('className', 'empty'); + } - // Check if the command is registered - foreach ($this->commands as $command) { - if ($command->className === $this->className) { - $this->command = $command; - break; - } - } + // Check if the command is registered + foreach ($this->commands as $command) { + if ($command->className === $this->className) { + $this->command = $command; + break; + } + } - if (!$this->command) { - throw new UserInputException('className', 'notFound'); - } - } + if (!$this->command) { + throw new UserInputException('className', 'notFound'); + } + } - /** - * @inheritDoc - */ - public function save() { - parent::save(); + /** + * @inheritDoc + */ + public function save() + { + parent::save(); - $fields = [ 'commandTrigger' => $this->commandTrigger - , 'commandID' => $this->command->commandID - ]; + $fields = [ + 'commandTrigger' => $this->commandTrigger, + 'commandID' => $this->command->commandID, + ]; - // create room - $this->objectAction = new \chat\data\command\CommandTriggerAction([ ], 'create', [ 'data' => array_merge($this->additionalFields, $fields) ]); - $this->objectAction->executeAction(); + // create room + $this->objectAction = new CommandTriggerAction( + [ ], + 'create', + [ + 'data' => \array_merge( + $this->additionalFields, + $fields + ), + ] + ); + $this->objectAction->executeAction(); - $this->saved(); + $this->saved(); - // reset values - $this->commandTrigger = $this->className = ''; + // reset values + $this->commandTrigger = $this->className = ''; - // show success message - WCF::getTPL()->assign('success', true); - } + // show success message + WCF::getTPL()->assign('success', true); + } - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); - WCF::getTPL()->assign([ 'action' => 'add' - , 'commandTrigger' => $this->commandTrigger - , 'className' => $this->className - , 'availableCommands' => $this->commands - ]); - } + WCF::getTPL()->assign([ + 'action' => 'add', + 'commandTrigger' => $this->commandTrigger, + 'className' => $this->className, + 'availableCommands' => $this->commands, + ]); + } } diff --git a/files/lib/acp/form/CommandTriggerEditForm.class.php b/files/lib/acp/form/CommandTriggerEditForm.class.php index bf389ea..e33674a 100644 --- a/files/lib/acp/form/CommandTriggerEditForm.class.php +++ b/files/lib/acp/form/CommandTriggerEditForm.class.php @@ -1,11 +1,12 @@ triggerID = intval($_REQUEST['id']); - $this->trigger = new CommandTrigger($this->triggerID); + /** + * @inheritDoc + */ + public function readParameters() + { + if (isset($_REQUEST['id'])) { + $this->triggerID = \intval($_REQUEST['id']); + } + $this->trigger = new CommandTrigger($this->triggerID); - if (!$this->trigger) { - throw new IllegalLinkException(); - } + if (!$this->trigger) { + throw new IllegalLinkException(); + } - parent::readParameters(); - } + parent::readParameters(); + } - /** - * @inheritDoc - */ - public function readData() { - parent::readData(); + /** + * @inheritDoc + */ + public function readData() + { + parent::readData(); - if (empty($_POST)) { - $commandList = new \chat\data\command\CommandList(); - $commandList->getConditionBuilder()->add('command.commandID = ?', [ $this->trigger->commandID ]); - $commandList->readObjects(); - $commands = $commandList->getObjects(); + if (empty($_POST)) { + $commandList = new CommandList(); + $commandList->getConditionBuilder()->add('command.commandID = ?', [ $this->trigger->commandID ]); + $commandList->readObjects(); + $commands = $commandList->getObjects(); - if (!count($commands)) { - throw new IllegalLinkException(); - } + if (!\count($commands)) { + throw new IllegalLinkException(); + } - $this->commandTrigger = $this->trigger->commandTrigger; - $this->className = $commands[$this->trigger->commandID]->className; - } - } + $this->commandTrigger = $this->trigger->commandTrigger; + $this->className = $commands[$this->trigger->commandID]->className; + } + } - /** - * @inheritDoc - */ - public function save() { - \wcf\form\AbstractForm::save(); + /** + * @inheritDoc + */ + public function save() + { + AbstractForm::save(); - $fields = [ 'commandTrigger' => $this->commandTrigger - , 'commandID' => $this->command->commandID - ]; + $fields = [ + 'commandTrigger' => $this->commandTrigger, + 'commandID' => $this->command->commandID, + ]; - // update trigger - $this->objectAction = new CommandTriggerAction([ $this->trigger ], 'update', [ 'data' => array_merge($this->additionalFields, $fields) ]); - $this->objectAction->executeAction(); + // update trigger + $this->objectAction = new CommandTriggerAction( + [ + $this->trigger, + ], + 'update', + [ + 'data' => \array_merge( + $this->additionalFields, + $fields + ), + ] + ); + $this->objectAction->executeAction(); - $this->saved(); + $this->saved(); - // show success message - WCF::getTPL()->assign('success', true); - } + // show success message + WCF::getTPL()->assign('success', true); + } - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); - WCF::getTPL()->assign([ 'action' => 'edit' - , 'triggerID' => $this->trigger->triggerID - ]); - } + WCF::getTPL()->assign([ + 'action' => 'edit', + 'triggerID' => $this->trigger->triggerID, + ]); + } } diff --git a/files/lib/acp/form/RoomAddForm.class.php b/files/lib/acp/form/RoomAddForm.class.php index 332f9f4..82d14d6 100644 --- a/files/lib/acp/form/RoomAddForm.class.php +++ b/files/lib/acp/form/RoomAddForm.class.php @@ -1,11 +1,12 @@ register('title'); - I18nHandler::getInstance()->register('topic'); + I18nHandler::getInstance()->register('title'); + I18nHandler::getInstance()->register('topic'); - $this->aclObjectTypeID = ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room'); - } + $this->aclObjectTypeID = ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room'); + } - /** - * @inheritDoc - */ - public function readFormParameters() { - parent::readFormParameters(); + /** + * @inheritDoc + */ + public function readFormParameters() + { + parent::readFormParameters(); - // read i18n values - I18nHandler::getInstance()->readValues(); + // read i18n values + I18nHandler::getInstance()->readValues(); - // handle i18n plain input - if (I18nHandler::getInstance()->isPlainValue('title')) $this->title = I18nHandler::getInstance()->getValue('title'); - if (I18nHandler::getInstance()->isPlainValue('topic')) $this->topic = I18nHandler::getInstance()->getValue('topic'); - if (isset($_POST['userLimit'])) $this->userLimit = intval($_POST['userLimit']); - if (isset($_POST['topicUseHtml'])) $this->topicUseHtml = true; - } + // handle i18n plain input + if (I18nHandler::getInstance()->isPlainValue('title')) { + $this->title = I18nHandler::getInstance()->getValue('title'); + } + if (I18nHandler::getInstance()->isPlainValue('topic')) { + $this->topic = I18nHandler::getInstance()->getValue('topic'); + } + if (isset($_POST['userLimit'])) { + $this->userLimit = \intval($_POST['userLimit']); + } + if (isset($_POST['topicUseHtml'])) { + $this->topicUseHtml = true; + } + } - /** - * @inheritDoc - */ - public function validate() { - parent::validate(); + /** + * @inheritDoc + */ + public function validate() + { + parent::validate(); - // validate title - if (!I18nHandler::getInstance()->validateValue('title')) { - if (I18nHandler::getInstance()->isPlainValue('title')) { - throw new UserInputException('title'); - } - else { - throw new UserInputException('title', 'multilingual'); - } - } + // validate title + if (!I18nHandler::getInstance()->validateValue('title')) { + if (I18nHandler::getInstance()->isPlainValue('title')) { + throw new UserInputException('title'); + } else { + throw new UserInputException('title', 'multilingual'); + } + } - // validate topic - if (!I18nHandler::getInstance()->validateValue('topic', false, true)) { - throw new UserInputException('topic'); - } + // validate topic + if (!I18nHandler::getInstance()->validateValue('topic', false, true)) { + throw new UserInputException('topic'); + } - if (mb_strlen($this->topic) > 10000) { - throw new UserInputException('topic', 'tooLong'); - } + if (\mb_strlen($this->topic) > 10000) { + throw new UserInputException('topic', 'tooLong'); + } - if ($this->userLimit < 0) { - throw new UserInputException('userLimit', 'negative'); - } - } + if ($this->userLimit < 0) { + throw new UserInputException('userLimit', 'negative'); + } + } - /** - * @inheritDoc - */ - public function save() { - parent::save(); + /** + * @inheritDoc + */ + public function save() + { + parent::save(); - $fields = [ 'title' => $this->title - , 'topic' => $this->topic - , 'topicUseHtml' => (int) $this->topicUseHtml - , 'userLimit' => $this->userLimit - , 'position' => 0 // TODO - ]; + $fields = [ + 'title' => $this->title, + 'topic' => $this->topic, + 'topicUseHtml' => (int)$this->topicUseHtml, + 'userLimit' => $this->userLimit, + 'position' => 0, // TODO + ]; - // create room - $this->objectAction = new \chat\data\room\RoomAction([], 'create', [ 'data' => array_merge($this->additionalFields, $fields) ]); - $returnValues = $this->objectAction->executeAction(); + // create room + $this->objectAction = new RoomAction( + [ ], + 'create', + [ + 'data' => \array_merge( + $this->additionalFields, + $fields + ), + ] + ); + $returnValues = $this->objectAction->executeAction(); - // save i18n values - $this->saveI18nValue($returnValues['returnValues'], [ 'title', 'topic' ]); + // save i18n values + $this->saveI18nValue( + $returnValues['returnValues'], + [ + 'title', + 'topic', + ] + ); - // save ACL - ACLHandler::getInstance()->save($returnValues['returnValues']->roomID, $this->aclObjectTypeID); + // save ACL + ACLHandler::getInstance()->save($returnValues['returnValues']->roomID, $this->aclObjectTypeID); - $this->saved(); + $this->saved(); - // reset values - $this->title = $this->topic = ''; - $this->userLimit = 0; - $this->topicUseHtml = false; + // reset values + $this->title = $this->topic = ''; + $this->userLimit = 0; + $this->topicUseHtml = false; - I18nHandler::getInstance()->reset(); - ACLHandler::getInstance()->disableAssignVariables(); + I18nHandler::getInstance()->reset(); + ACLHandler::getInstance()->disableAssignVariables(); - // show success message - WCF::getTPL()->assign('success', true); - } + // show success message + WCF::getTPL()->assign('success', true); + } - /** - * Saves i18n values. - * - * @param Room $room - * @param string[] $columns - */ - public function saveI18nValue(Room $room, $columns) { - $data = [ ]; + /** + * Saves i18n values. + * + * @param Room $room + * @param string[] $columns + */ + public function saveI18nValue(Room $room, $columns) + { + $data = [ ]; - foreach ($columns as $columnName) { - $languageItem = 'chat.room.room'.$room->roomID.'.'.$columnName; + foreach ($columns as $columnName) { + $languageItem = 'chat.room.room' . $room->roomID . '.' . $columnName; - if (I18nHandler::getInstance()->isPlainValue($columnName)) { - if ($room->$columnName === $languageItem) { - I18nHandler::getInstance()->remove($languageItem); - } - } - else { - $packageID = \wcf\data\package\PackageCache::getInstance()->getPackageID('be.bastelstu.chat'); + if (I18nHandler::getInstance()->isPlainValue($columnName)) { + if ($room->{$columnName} === $languageItem) { + I18nHandler::getInstance()->remove($languageItem); + } + } else { + $packageID = PackageCache::getInstance()->getPackageID('be.bastelstu.chat'); - I18nHandler::getInstance()->save( $columnName - , $languageItem - , 'chat.room' - , $packageID - ); + I18nHandler::getInstance()->save( + $columnName, + $languageItem, + 'chat.room', + $packageID + ); - $data[$columnName] = $languageItem; - } - } + $data[$columnName] = $languageItem; + } + } - if (!empty($data)) { - (new RoomEditor($room))->update($data); - } - } + if (!empty($data)) { + (new RoomEditor($room))->update($data); + } + } - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); - ACLHandler::getInstance()->assignVariables($this->aclObjectTypeID); - I18nHandler::getInstance()->assignVariables(); + ACLHandler::getInstance()->assignVariables($this->aclObjectTypeID); + I18nHandler::getInstance()->assignVariables(); - WCF::getTPL()->assign([ 'action' => 'add' - , 'aclObjectTypeID' => $this->aclObjectTypeID - , 'userLimit' => $this->userLimit - , 'topicUseHtml' => $this->topicUseHtml - ]); - } + WCF::getTPL()->assign([ + 'action' => 'add', + 'aclObjectTypeID' => $this->aclObjectTypeID, + 'userLimit' => $this->userLimit, + 'topicUseHtml' => $this->topicUseHtml, + ]); + } } - diff --git a/files/lib/acp/form/RoomEditForm.class.php b/files/lib/acp/form/RoomEditForm.class.php index 1b05d0b..dfc55af 100644 --- a/files/lib/acp/form/RoomEditForm.class.php +++ b/files/lib/acp/form/RoomEditForm.class.php @@ -1,11 +1,12 @@ roomID = intval($_REQUEST['id']); - $this->room = new Room($this->roomID); + /** + * @inheritDoc + */ + public function readParameters() + { + if (isset($_REQUEST['id'])) { + $this->roomID = \intval($_REQUEST['id']); + } + $this->room = new Room($this->roomID); - if (!$this->room) { - throw new IllegalLinkException(); - } + if (!$this->room) { + throw new IllegalLinkException(); + } - parent::readParameters(); - } + parent::readParameters(); + } - /** - * @inheritDoc - */ - public function readData() { - parent::readData(); + /** + * @inheritDoc + */ + public function readData() + { + parent::readData(); - if (empty($_POST)) { - $packageID = \wcf\data\package\PackageCache::getInstance()->getPackageID('be.bastelstu.chat'); - I18nHandler::getInstance()->setOptions('title', $packageID, $this->room->title, 'chat.room.room\d+.title'); - I18nHandler::getInstance()->setOptions('topic', $packageID, $this->room->topic, 'chat.room.room\d+.topic'); - $this->userLimit = $this->room->userLimit; - $this->topicUseHtml = $this->room->topicUseHtml; - } - } + if (empty($_POST)) { + $packageID = PackageCache::getInstance()->getPackageID('be.bastelstu.chat'); + I18nHandler::getInstance()->setOptions( + 'title', + $packageID, + $this->room->title, + 'chat.room.room\d+.title' + ); + I18nHandler::getInstance()->setOptions( + 'topic', + $packageID, + $this->room->topic, + 'chat.room.room\d+.topic' + ); + $this->userLimit = $this->room->userLimit; + $this->topicUseHtml = $this->room->topicUseHtml; + } + } - /** - * @inheritDoc - */ - public function save() { - \wcf\form\AbstractForm::save(); + /** + * @inheritDoc + */ + public function save() + { + AbstractForm::save(); - $fields = [ 'title' => $this->title - , 'topic' => $this->topic - , 'topicUseHtml' => (int) $this->topicUseHtml - , 'userLimit' => $this->userLimit - , 'position' => 0 // TODO - ]; + $fields = [ + 'title' => $this->title, + 'topic' => $this->topic, + 'topicUseHtml' => (int)$this->topicUseHtml, + 'userLimit' => $this->userLimit, + 'position' => 0, // TODO + ]; - // update room - $this->objectAction = new RoomAction([ $this->room ], 'update', [ 'data' => array_merge($this->additionalFields, $fields) ]); - $returnValues = $this->objectAction->executeAction(); + // update room + $this->objectAction = new RoomAction( + [ $this->room ], + 'update', + [ + 'data' => \array_merge( + $this->additionalFields, + $fields + ), + ] + ); + $returnValues = $this->objectAction->executeAction(); - // save i18n values - $this->saveI18nValue($this->room, [ 'title', 'topic' ]); + // save i18n values + $this->saveI18nValue( + $this->room, + [ + 'title', + 'topic', + ] + ); - // save ACL - ACLHandler::getInstance()->save($this->room->roomID, $this->aclObjectTypeID); + // save ACL + ACLHandler::getInstance()->save( + $this->room->roomID, + $this->aclObjectTypeID + ); - $this->saved(); + $this->saved(); - // show success message - WCF::getTPL()->assign('success', true); - } + // show success message + WCF::getTPL()->assign('success', true); + } - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); - I18nHandler::getInstance()->assignVariables(!empty($_POST)); + I18nHandler::getInstance()->assignVariables(!empty($_POST)); - WCF::getTPL()->assign([ 'action' => 'edit' - , 'roomID' => $this->room->roomID - , 'room' => $this->room - ]); - } + WCF::getTPL()->assign([ + 'action' => 'edit', + 'roomID' => $this->room->roomID, + 'room' => $this->room, + ]); + } } diff --git a/files/lib/acp/page/CommandTriggerListPage.class.php b/files/lib/acp/page/CommandTriggerListPage.class.php index 9d8b93a..e6d0922 100644 --- a/files/lib/acp/page/CommandTriggerListPage.class.php +++ b/files/lib/acp/page/CommandTriggerListPage.class.php @@ -1,11 +1,12 @@ objectList->sqlSelects = 'command.className'; - $this->objectList->sqlJoins = 'LEFT JOIN chat'.WCF_N.'_command command ON (command.commandID = command_trigger.commandID)'; - } + $this->objectList->sqlSelects = 'command.className'; + $this->objectList->sqlJoins = 'LEFT JOIN chat' . WCF_N . '_command command ON (command.commandID = command_trigger.commandID)'; + } } diff --git a/files/lib/acp/page/RoomListPage.class.php b/files/lib/acp/page/RoomListPage.class.php index f4988d0..9b1bcae 100644 --- a/files/lib/acp/page/RoomListPage.class.php +++ b/files/lib/acp/page/RoomListPage.class.php @@ -1,11 +1,12 @@ roomID = intval($_REQUEST['roomID']); - if (isset($_REQUEST['userID']) && $_REQUEST['userID'] !== '') $this->userID = intval($_REQUEST['userID']); - if (isset($_REQUEST['judgeID']) && $_REQUEST['judgeID'] !== '') $this->judgeID = intval($_REQUEST['judgeID']); - if (isset($_REQUEST['objectTypeID']) && $_REQUEST['objectTypeID'] !== '') $this->objectTypeID = intval($_REQUEST['objectTypeID']); - // Checkboxes need special handling - if (!empty($_POST) && !isset($_POST['showExpired'])) $this->showExpired = false; + if (isset($_REQUEST['roomID']) && $_REQUEST['roomID'] !== '') { + $this->roomID = \intval($_REQUEST['roomID']); + } + if (isset($_REQUEST['userID']) && $_REQUEST['userID'] !== '') { + $this->userID = \intval($_REQUEST['userID']); + } + if (isset($_REQUEST['judgeID']) && $_REQUEST['judgeID'] !== '') { + $this->judgeID = \intval($_REQUEST['judgeID']); + } + if (isset($_REQUEST['objectTypeID']) && $_REQUEST['objectTypeID'] !== '') { + $this->objectTypeID = \intval($_REQUEST['objectTypeID']); + } + // Checkboxes need special handling + if (!empty($_POST) && !isset($_POST['showExpired'])) { + $this->showExpired = false; + } - if (isset($_POST['searchUsername'])) { - $this->searchUsername = StringUtil::trim($_POST['searchUsername']); + if (isset($_POST['searchUsername'])) { + $this->searchUsername = StringUtil::trim($_POST['searchUsername']); - if (!empty($this->searchUsername)) { - $this->userID = User::getUserByUsername($this->searchUsername)->userID; - } - } - else if ($this->userID !== null) { - $this->searchUsername = (new User($this->userID))->username; - } + if (!empty($this->searchUsername)) { + $this->userID = User::getUserByUsername($this->searchUsername)->userID; + } + } elseif ($this->userID !== null) { + $this->searchUsername = (new User($this->userID))->username; + } - if (isset($_POST['searchJudge'])) { - $this->searchJudge = StringUtil::trim($_POST['searchJudge']); + if (isset($_POST['searchJudge'])) { + $this->searchJudge = StringUtil::trim($_POST['searchJudge']); - if (!empty($this->searchJudge)) { - $this->judgeID = User::getUserByUsername($this->searchJudge)->userID; - } - } - else if ($this->judgeID !== null) { - $this->searchJudge = (new User($this->judgeID))->username; - } - } + if (!empty($this->searchJudge)) { + $this->judgeID = User::getUserByUsername($this->searchJudge)->userID; + } + } elseif ($this->judgeID !== null) { + $this->searchJudge = (new User($this->judgeID))->username; + } + } - /** - * @inheritDoc - */ - public function readData() { - $this->availableObjectTypes = \wcf\data\object\type\ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.suspension'); + /** + * @inheritDoc + */ + public function readData() + { + $this->availableObjectTypes = ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.suspension'); - $roomList = new \chat\data\room\RoomList(); - $roomList->sqlOrderBy = "room.position"; - $roomList->readObjects(); - $this->availableRooms = $roomList->getObjects(); + $roomList = new RoomList(); + $roomList->sqlOrderBy = "room.position"; + $roomList->readObjects(); + $this->availableRooms = $roomList->getObjects(); - parent::readData(); + parent::readData(); - \wcf\system\cache\runtime\UserRuntimeCache::getInstance()->cacheObjectIDs(array_map(function (Suspension $s) { - return $s->userID; - }, $this->objectList->getObjects())); - } + UserRuntimeCache::getInstance()->cacheObjectIDs(\array_map(static function (Suspension $s) { + return $s->userID; + }, $this->objectList->getObjects())); + } - /** - * @inheritDoc - */ - protected function initObjectList() { - parent::initObjectList(); + /** + * @inheritDoc + */ + protected function initObjectList() + { + parent::initObjectList(); - $this->objectList->sqlSelects .= 'COALESCE(suspension.revoked, suspension.expires, 2147483647) AS expiresSort'; + $this->objectList->sqlSelects .= 'COALESCE(suspension.revoked, suspension.expires, 2147483647) AS expiresSort'; - if (!empty($this->availableRooms)) { - $this->objectList->getConditionBuilder()->add('(roomID IN (?) OR roomID IS NULL)', [ array_map(function (Room $room) { - return $room->roomID; - }, $this->availableRooms) ]); - } - else { - $this->objectList->getConditionBuilder()->add('1 = 0'); - } + if (!empty($this->availableRooms)) { + $this->objectList->getConditionBuilder()->add('(roomID IN (?) OR roomID IS NULL)', [ \array_map(static function (Room $room) { + return $room->roomID; + }, $this->availableRooms) ]); + } else { + $this->objectList->getConditionBuilder()->add('1 = 0'); + } - if ($this->userID !== null) { - $this->objectList->getConditionBuilder()->add('userID = ?', [ $this->userID ]); - } + if ($this->userID !== null) { + $this->objectList->getConditionBuilder()->add('userID = ?', [ $this->userID ]); + } - if ($this->roomID !== null) { - if ($this->roomID === 0) { - $this->objectList->getConditionBuilder()->add('roomID IS NULL'); - } - else { - $this->objectList->getConditionBuilder()->add('roomID = ?', [ $this->roomID ]); - } - } + if ($this->roomID !== null) { + if ($this->roomID === 0) { + $this->objectList->getConditionBuilder()->add('roomID IS NULL'); + } else { + $this->objectList->getConditionBuilder()->add('roomID = ?', [ $this->roomID ]); + } + } - if ($this->objectTypeID !== null) { - $this->objectList->getConditionBuilder()->add('objectTypeID = ?', [ $this->objectTypeID ]); - } + if ($this->objectTypeID !== null) { + $this->objectList->getConditionBuilder()->add('objectTypeID = ?', [ $this->objectTypeID ]); + } - if ($this->judgeID !== null) { - $this->objectList->getConditionBuilder()->add('judgeID = ?', [ $this->judgeID ]); - } + if ($this->judgeID !== null) { + $this->objectList->getConditionBuilder()->add('judgeID = ?', [ $this->judgeID ]); + } - if ($this->showExpired === false) { - $this->objectList->getConditionBuilder()->add('expires >= ?', [ TIME_NOW ]); - } - } + if ($this->showExpired === false) { + $this->objectList->getConditionBuilder()->add('expires >= ?', [ TIME_NOW ]); + } + } - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); - WCF::getTPL()->assign([ 'userID' => $this->userID - , 'roomID' => $this->roomID - , 'objectTypeID' => $this->objectTypeID - , 'judgeID' => $this->judgeID - , 'availableRooms' => $this->availableRooms - , 'availableObjectTypes' => $this->availableObjectTypes - , 'searchUsername' => $this->searchUsername - , 'searchJudge' => $this->searchJudge - , 'showExpired' => $this->showExpired - ]); - } + WCF::getTPL()->assign([ + 'userID' => $this->userID, + 'roomID' => $this->roomID, + 'objectTypeID' => $this->objectTypeID, + 'judgeID' => $this->judgeID, + 'availableRooms' => $this->availableRooms, + 'availableObjectTypes' => $this->availableObjectTypes, + 'searchUsername' => $this->searchUsername, + 'searchJudge' => $this->searchJudge, + 'showExpired' => $this->showExpired, + ]); + } } diff --git a/files/lib/data/command/Command.class.php b/files/lib/data/command/Command.class.php index 8b54281..ac63f14 100644 --- a/files/lib/data/command/Command.class.php +++ b/files/lib/data/command/Command.class.php @@ -1,6 +1,7 @@ getPackageID('be.bastelstu.chat'); - } + if ($chatPackageID === null) { + $chatPackageID = PackageCache::getInstance()->getPackageID('be.bastelstu.chat'); + } - if ($this->packageID === $chatPackageID && $this->identifier === 'plain') { - return true; - } + if ($this->packageID === $chatPackageID && $this->identifier === 'plain') { + return true; + } - $sql = "SELECT COUNT(*) - FROM chat1_command_trigger - WHERE commandID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ $this->commandID ]); - return $statement->fetchSingleColumn() > 0; - } + $sql = "SELECT COUNT(*) + FROM chat1_command_trigger + WHERE commandID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ + $this->commandID, + ]); + + return $statement->fetchSingleColumn() > 0; + } } diff --git a/files/lib/data/command/CommandCache.class.php b/files/lib/data/command/CommandCache.class.php index c802d89..7990c11 100644 --- a/files/lib/data/command/CommandCache.class.php +++ b/files/lib/data/command/CommandCache.class.php @@ -1,11 +1,12 @@ getData(); + /** + * @inheritDoc + */ + protected function init() + { + $data = CommandCacheBuilder::getInstance()->getData(); - $this->commands = $data['commands']; - $this->packages = $data['packages']; - $this->triggers = $data['triggers']; - } + $this->commands = $data['commands']; + $this->packages = $data['packages']; + $this->triggers = $data['triggers']; + } - /** - * Returns a specific command. - * - * @param integer $commandID - * @return Command - */ - public function getCommand($commandID) { - if (isset($this->commands[$commandID])) { - return $this->commands[$commandID]; - } + /** + * Returns a specific command. + * + * @param integer $commandID + * @return Command + */ + public function getCommand($commandID) + { + if (isset($this->commands[$commandID])) { + return $this->commands[$commandID]; + } - return null; - } + return null; + } - /** - * Returns a specific command defined by a trigger. - * - * @param string $trigger - * @return Command - */ - public function getCommandByTrigger($trigger) { - if (isset($this->triggers[$trigger])) { - return $this->commands[$this->triggers[$trigger]]; - } + /** + * Returns a specific command defined by a trigger. + * + * @param string $trigger + * @return Command + */ + public function getCommandByTrigger($trigger) + { + if (isset($this->triggers[$trigger])) { + return $this->commands[$this->triggers[$trigger]]; + } - return null; - } + return null; + } - /** - * Returns the command defined by the given package and identifier. - * - * @param \wcf\data\package\Package $package - * @param string $identifier - * @return Command - */ - public function getCommandByPackageAndIdentifier(\wcf\data\package\Package $package, $identifier) { - if (isset($this->packages[$package->packageID][$identifier])) { - return $this->packages[$package->packageID][$identifier]; - } + /** + * Returns the command defined by the given package and identifier. + * + * @param string $identifier + * @return Command + */ + public function getCommandByPackageAndIdentifier(Package $package, $identifier) + { + if (isset($this->packages[$package->packageID][$identifier])) { + return $this->packages[$package->packageID][$identifier]; + } - return null; - } + return null; + } - /** - * Returns all commands. - * - * @return Command[] - */ - public function getCommands() { - return $this->commands; - } + /** + * Returns all commands. + * + * @return Command[] + */ + public function getCommands() + { + return $this->commands; + } - /** - * Returns all triggers. - * - * @return int[] - */ - public function getTriggers() { - return $this->triggers; - } + /** + * Returns all triggers. + * + * @return int[] + */ + public function getTriggers() + { + return $this->triggers; + } } diff --git a/files/lib/data/command/CommandEditor.class.php b/files/lib/data/command/CommandEditor.class.php index a09a999..f069044 100644 --- a/files/lib/data/command/CommandEditor.class.php +++ b/files/lib/data/command/CommandEditor.class.php @@ -1,11 +1,12 @@ commandTrigger; - } +class CommandTrigger extends DatabaseObject implements IRouteController +{ + /** + * @inheritDoc + */ + public function getTitle() + { + return $this->commandTrigger; + } - /** - * @inheritDoc - */ - public function getObjectID() { - return $this->triggerID; - } + /** + * @inheritDoc + */ + public function getObjectID() + { + return $this->triggerID; + } - /** - * Returns the trigger specified by its commandTrigger value - * - * @param string $name - * @return CommandTrigger - */ - public static function getTriggerByName($name) { - $sql = "SELECT * - FROM chat1_command_trigger - WHERE commandTrigger = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ $name ]); - $row = $statement->fetchArray(); - if (!$row) $row = []; + /** + * Returns the trigger specified by its commandTrigger value + * + * @param string $name + * @return CommandTrigger + */ + public static function getTriggerByName($name) + { + $sql = "SELECT * + FROM chat1_command_trigger + WHERE commandTrigger = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ $name ]); + $row = $statement->fetchArray(); + if (!$row) { + $row = []; + } - return new self(null, $row); - } + return new self(null, $row); + } } diff --git a/files/lib/data/command/CommandTriggerAction.class.php b/files/lib/data/command/CommandTriggerAction.class.php index 4d0b9fb..45fb3b7 100644 --- a/files/lib/data/command/CommandTriggerAction.class.php +++ b/files/lib/data/command/CommandTriggerAction.class.php @@ -1,11 +1,12 @@ reset(); - } + /** + * @inheritDoc + */ + public static function resetCache() + { + CommandCacheBuilder::getInstance()->reset(); + } } diff --git a/files/lib/data/command/CommandTriggerList.class.php b/files/lib/data/command/CommandTriggerList.class.php index 4613945..54ad845 100644 --- a/files/lib/data/command/CommandTriggerList.class.php +++ b/files/lib/data/command/CommandTriggerList.class.php @@ -1,11 +1,12 @@ data['payload'] = @unserialize($this->data['payload']); - if (!is_array($this->data['payload'])) { - $this->data['payload'] = [ ]; - } - } + $this->data['payload'] = @\unserialize($this->data['payload']); + if (!\is_array($this->data['payload'])) { + $this->data['payload'] = [ ]; + } + } - /** - * Returns whether this message already is inside the log. - */ - public function isInLog(): bool { - return $this->time < (TIME_NOW - CHAT_ARCHIVE_AFTER); - } + /** + * Returns whether this message already is inside the log. + */ + public function isInLog(): bool + { + return $this->time < (TIME_NOW - CHAT_ARCHIVE_AFTER); + } - /** - * Returns the message type object of this message. - */ - public function getMessageType(): ObjectType { - return ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID); - } + /** + * Returns the message type object of this message. + */ + public function getMessageType(): ObjectType + { + return ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID); + } - /** - * Returns the chat room that contains this message. - */ - public function getRoom(): Room { - return \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); - } + /** + * Returns the chat room that contains this message. + */ + public function getRoom(): Room + { + return RoomCache::getInstance()->getRoom($this->roomID); + } } diff --git a/files/lib/data/message/MessageAction.class.php b/files/lib/data/message/MessageAction.class.php index 10138c3..72a7dce 100644 --- a/files/lib/data/message/MessageAction.class.php +++ b/files/lib/data/message/MessageAction.class.php @@ -1,6 +1,7 @@ parameters['updateTimestamp']) && $this->parameters['updateTimestamp']) { - $sql = "UPDATE chat1_room_to_user SET lastPush = ? WHERE roomID = ? AND userID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ TIME_NOW, $message->roomID, $message->userID ]); - } - if (isset($this->parameters['grantPoints']) && $this->parameters['grantPoints']) { - UserActivityPointHandler::getInstance()->fireEvent('be.bastelstu.chat.activityPointEvent.message', $message->messageID, $message->userID); - } + if (isset($this->parameters['updateTimestamp']) && $this->parameters['updateTimestamp']) { + $sql = "UPDATE chat1_room_to_user + SET lastPush = ? + WHERE roomID = ? + AND userID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ + TIME_NOW, + $message->roomID, + $message->userID, + ]); + } + if (isset($this->parameters['grantPoints']) && $this->parameters['grantPoints']) { + UserActivityPointHandler::getInstance()->fireEvent( + 'be.bastelstu.chat.activityPointEvent.message', + $message->messageID, + $message->userID + ); + } - $pushHandler = \wcf\system\push\PushHandler::getInstance(); - if ($pushHandler->isEnabled() && in_array('target:channels', $pushHandler->getFeatureFlags())) { - $fastSelect = $message->getMessageType()->getProcessor()->supportsFastSelect(); - if ($fastSelect) { - $target = [ 'channels' => [ 'be.bastelstu.chat.room-'.$message->roomID ] ]; - } - else { - $target = [ 'channels' => [ 'be.bastelstu.chat' ] ]; - } - $pushHandler->sendMessage([ 'message' => 'be.bastelstu.chat.message' - , 'target' => $target - ]); - } + $pushHandler = PushHandler::getInstance(); + if ($pushHandler->isEnabled() && \in_array('target:channels', $pushHandler->getFeatureFlags())) { + $fastSelect = $message->getMessageType()->getProcessor()->supportsFastSelect(); + if ($fastSelect) { + $target = [ + 'channels' => [ + 'be.bastelstu.chat.room-' . $message->roomID, + ], + ]; + } else { + $target = [ + 'channels' => [ + 'be.bastelstu.chat', + ], + ]; + } + $pushHandler->sendMessage([ + 'message' => 'be.bastelstu.chat.message', + 'target' => $target, + ]); + } - return $message; - } + return $message; + } - /** - * Validates parameters and permissions. - */ - public function validateTrash() { - // read objects - if (empty($this->objects)) { - $this->readObjects(); + /** + * Validates parameters and permissions. + */ + public function validateTrash() + { + // read objects + if (empty($this->objects)) { + $this->readObjects(); - if (empty($this->objects)) { - throw new UserInputException('objectIDs'); - } - } + if (empty($this->objects)) { + throw new UserInputException('objectIDs'); + } + } - foreach ($this->getObjects() as $message) { - if ($message->isDeleted) continue; + foreach ($this->getObjects() as $message) { + if ($message->isDeleted) { + continue; + } - $messageType = $message->getMessageType()->getProcessor(); - if (!($messageType instanceof \chat\system\message\type\IDeletableMessageType) || !$messageType->canDelete($message->getDecoratedObject())) { - throw new PermissionDeniedException(); - } - } - } + $messageType = $message->getMessageType()->getProcessor(); + if ( + !($messageType instanceof IDeletableMessageType) + || !$messageType->canDelete($message->getDecoratedObject()) + ) { + throw new PermissionDeniedException(); + } + } + } - /** - * Marks this message as deleted and creates a tombstone message. - * - * Note: Contrary to other applications there is no way to undelete a message. - */ - public function trash() { - if (empty($this->objects)) { - $this->readObjects(); - } + /** + * Marks this message as deleted and creates a tombstone message. + * + * Note: Contrary to other applications there is no way to undelete a message. + */ + public function trash() + { + if (empty($this->objects)) { + $this->readObjects(); + } - $data = [ 'isDeleted' => 1 - ]; + $data = [ + 'isDeleted' => 1, + ]; - $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.tombstone'); - if (!$objectTypeID) { - throw new \LogicException('Missing object type'); - } + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.messageType', + 'be.bastelstu.chat.messageType.tombstone' + ); + if (!$objectTypeID) { + throw new \LogicException('Missing object type'); + } - WCF::getDB()->beginTransaction(); - $objectAction = new static($this->getObjects(), 'update', [ 'data' => $data ]); - $objectAction->executeAction(); - foreach ($this->getObjects() as $message) { - if ($message->isDeleted) continue; + WCF::getDB()->beginTransaction(); + $objectAction = new static( + $this->getObjects(), + 'update', + [ + 'data' => $data, + ] + ); + $objectAction->executeAction(); + foreach ($this->getObjects() as $message) { + if ($message->isDeleted) { + continue; + } - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $message->roomID - , 'userID' => null - , 'username' => '' - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'messageID' => $message->messageID ]) - ] - ] - ) - )->executeAction(); - } - WCF::getDB()->commitTransaction(); - } + (new self( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $message->roomID, + 'userID' => null, + 'username' => '', + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'messageID' => $message->messageID, + ]), + ], + ] + ))->executeAction(); + } + WCF::getDB()->commitTransaction(); + } - /** - * Prunes chat messages older than chat_log_archivetime days. - */ - public function prune() { - // Check whether pruning is disabled. - if (!CHAT_LOG_ARCHIVETIME) return; + /** + * Prunes chat messages older than chat_log_archivetime days. + */ + public function prune() + { + // Check whether pruning is disabled. + if (!CHAT_LOG_ARCHIVETIME) { + return; + } - $sql = "SELECT messageID - FROM chat1_message - WHERE time < ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ TIME_NOW - CHAT_LOG_ARCHIVETIME * 86400 ]); - $messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); + $sql = "SELECT messageID + FROM chat1_message + WHERE time < ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ TIME_NOW - CHAT_LOG_ARCHIVETIME * 86400 ]); + $messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); - return call_user_func([$this->className, 'deleteAll'], $messageIDs); - } + return \call_user_func( + [$this->className, 'deleteAll'], + $messageIDs + ); + } - /** - * Validates parameters and permissions. - */ - public function validatePull() { - $this->readString('sessionID', true); - if ($this->parameters['sessionID']) { - $this->parameters['sessionID'] = pack('H*', str_replace('-', '', $this->parameters['sessionID'])); - } + /** + * Validates parameters and permissions. + */ + public function validatePull() + { + $this->readString('sessionID', true); + if ($this->parameters['sessionID']) { + $this->parameters['sessionID'] = \pack( + 'H*', + \str_replace('-', '', $this->parameters['sessionID']) + ); + } - $this->readInteger('roomID'); - $this->readBoolean('inLog', true); + $this->readInteger('roomID'); + $this->readBoolean('inLog', true); - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); - if (!$room->canSee($user = null, $reason)) throw $reason; - $user = new \chat\data\user\User(WCF::getUser()); - if (!$this->parameters['inLog'] && !$user->isInRoom($room)) throw new PermissionDeniedException(); - if ($this->parameters['inLog'] && !$room->canSeeLog(null, $reason)) throw $reason; + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } + if (!$room->canSee($user = null, $reason)) { + throw $reason; + } + $user = new ChatUser(WCF::getUser()); + if (!$this->parameters['inLog'] && !$user->isInRoom($room)) { + throw new PermissionDeniedException(); + } + if ($this->parameters['inLog'] && !$room->canSeeLog(null, $reason)) { + throw $reason; + } - $this->readInteger('from', true); - $this->readInteger('to', true); + $this->readInteger('from', true); + $this->readInteger('to', true); - // One may not pass both 'from' and 'to' - if ($this->parameters['from'] && $this->parameters['to']) { - throw new UserInputException(); - } - } + // One may not pass both 'from' and 'to' + if ($this->parameters['from'] && $this->parameters['to']) { + throw new UserInputException(); + } + } - /** - * Pulls messages for the given room. - */ - public function pull() { - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); + /** + * Pulls messages for the given room. + */ + public function pull() + { + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } - if (($sessionID = $this->parameters['sessionID'])) { - if (strlen($sessionID) !== 16) throw new UserInputException('sessionID'); + if (($sessionID = $this->parameters['sessionID'])) { + if (\strlen($sessionID) !== 16) { + throw new UserInputException('sessionID'); + } - (new \chat\data\user\UserAction([], 'clearDeadSessions'))->executeAction(); + (new ChatUserAction([], 'clearDeadSessions'))->executeAction(); - WCF::getDB()->beginTransaction(); - // update timestamp - $sql = "UPDATE chat1_room_to_user - SET lastPull = ? - WHERE roomID = ? - AND userID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ TIME_NOW - , $room->roomID - , WCF::getUser()->userID - ]); + WCF::getDB()->beginTransaction(); + // update timestamp + $sql = "UPDATE chat1_room_to_user + SET lastPull = ? + WHERE roomID = ? + AND userID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ TIME_NOW, + $room->roomID, + WCF::getUser()->userID, + ]); - $sql = "UPDATE chat1_session - SET lastRequest = ? - WHERE roomID = ? - AND userID = ? - AND sessionID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ TIME_NOW - , $room->roomID - , WCF::getUser()->userID - , $sessionID - ]); - WCF::getDB()->commitTransaction(); - } + $sql = "UPDATE chat1_session + SET lastRequest = ? + WHERE roomID = ? + AND userID = ? + AND sessionID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ TIME_NOW, + $room->roomID, + WCF::getUser()->userID, + $sessionID, + ]); + WCF::getDB()->commitTransaction(); + } - // Determine message types supporting fast select - $objectTypes = \wcf\data\object\type\ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType'); - $fastSelect = array_map(function ($item) { - return $item->objectTypeID; - }, array_filter($objectTypes, function ($item) { - return $item->getProcessor()->supportsFastSelect(); - })); + // Determine message types supporting fast select + $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType'); + $fastSelect = \array_map(static function ($item) { + return $item->objectTypeID; + }, \array_filter($objectTypes, static function ($item) { + return $item->getProcessor()->supportsFastSelect(); + })); - // Build fast select filter - $condition = new \wcf\system\database\util\PreparedStatementConditionBuilder(); - $condition->add('((roomID = ? AND objectTypeID IN (?)) OR objectTypeID NOT IN (?))', [ $room->roomID, $fastSelect, $fastSelect ]); + // Build fast select filter + $condition = new PreparedStatementConditionBuilder(); + $condition->add('((roomID = ? AND objectTypeID IN (?)) OR objectTypeID NOT IN (?))', [ $room->roomID, $fastSelect, $fastSelect ]); - $sortOrder = 'DESC'; - // Add offset - if ($this->parameters['from']) { - $condition->add('messageID >= ?', [ $this->parameters['from'] ]); - $sortOrder = 'ASC'; - } - if ($this->parameters['to']) { - $condition->add('messageID <= ?', [ $this->parameters['to'] ]); - } + $sortOrder = 'DESC'; + // Add offset + if ($this->parameters['from']) { + $condition->add('messageID >= ?', [ $this->parameters['from'] ]); + $sortOrder = 'ASC'; + } + if ($this->parameters['to']) { + $condition->add('messageID <= ?', [ $this->parameters['to'] ]); + } - $sql = "SELECT messageID - FROM chat1_message - ".$condition." - ORDER BY messageID ".$sortOrder; - $statement = WCF::getDB()->prepare($sql, 20); - $statement->execute($condition->getParameters()); - $messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); + $sql = "SELECT messageID + FROM chat1_message + " . $condition . " + ORDER BY messageID " . $sortOrder; + $statement = WCF::getDB()->prepare($sql, 20); + $statement->execute($condition->getParameters()); + $messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); - $objectList = new MessageList(); - $objectList->setObjectIDs($messageIDs); - $objectList->readObjects(); - $objects = $objectList->getObjects(); + $objectList = new MessageList(); + $objectList->setObjectIDs($messageIDs); + $objectList->readObjects(); + $objects = $objectList->getObjects(); - $canSeeLog = $room->canSeeLog(); - $messages = array_map(function (Message $item) use ($room) { - return new ViewableMessage($item, $room); - }, array_filter($objects, function (Message $message) use ($canSeeLog, $room) { - if ($this->parameters['inLog'] || $message->isInLog()) { - return $canSeeLog && $message->getMessageType()->getProcessor()->canSeeInLog($message, $room); - } - else { - return $message->getMessageType()->getProcessor()->canSee($message, $room); - } - })); + $canSeeLog = $room->canSeeLog(); + $messages = \array_map(static function (Message $item) use ($room) { + return new ViewableMessage($item, $room); + }, \array_filter($objects, function (Message $message) use ($canSeeLog, $room) { + if ($this->parameters['inLog'] || $message->isInLog()) { + return $canSeeLog && $message->getMessageType()->getProcessor()->canSeeInLog($message, $room); + } else { + return $message->getMessageType()->getProcessor()->canSee($message, $room); + } + })); - $embeddedObjectMessageIDs = array_map(function ($message) { - return $message->messageID; - }, array_filter($messages, function ($message) { - return $message->hasEmbeddedObjects; - })); + $embeddedObjectMessageIDs = \array_map(static function ($message) { + return $message->messageID; + }, \array_filter($messages, static function ($message) { + return $message->hasEmbeddedObjects; + })); - if (!empty($embeddedObjectMessageIDs)) { - // load embedded objects - \wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->loadObjects('be.bastelstu.chat.message', $embeddedObjectMessageIDs); - } + if (!empty($embeddedObjectMessageIDs)) { + // load embedded objects + MessageEmbeddedObjectManager::getInstance()->loadObjects('be.bastelstu.chat.message', $embeddedObjectMessageIDs); + } - return [ 'messages' => $messages - , 'from' => $this->parameters['from'] ?: (!empty($objects) ? reset($objects)->messageID : $this->parameters['to'] + 1) - , 'to' => $this->parameters['to'] ?: (!empty($objects) ? end($objects)->messageID : $this->parameters['from'] - 1) - ]; - } + return [ + 'messages' => $messages, + 'from' => $this->parameters['from'] ?: (!empty($objects) ? \reset($objects)->messageID : $this->parameters['to'] + 1), + 'to' => $this->parameters['to'] ?: (!empty($objects) ? \end($objects)->messageID : $this->parameters['from'] - 1), + ]; + } - /** - * Validates parameters and permissions. - */ - public function validatePush() { - $this->readInteger('roomID'); + /** + * Validates parameters and permissions. + */ + public function validatePush() + { + $this->readInteger('roomID'); - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); - if (!$room->canSee($user = null, $reason)) throw $reason; - $user = new \chat\data\user\User(WCF::getUser()); - if (!$user->isInRoom($room)) throw new PermissionDeniedException(); + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } + if (!$room->canSee($user = null, $reason)) { + throw $reason; + } + $user = new ChatUser(WCF::getUser()); + if (!$user->isInRoom($room)) { + throw new PermissionDeniedException(); + } - $this->readInteger('commandID'); - $command = CommandCache::getInstance()->getCommand($this->parameters['commandID']); - if ($command === null) throw new UserInputException('commandID'); - if (!$command->hasTriggers()) { - if (!$command->getProcessor()->allowWithoutTrigger()) { - throw new UserInputException('commandID'); - } - } + $this->readInteger('commandID'); + $command = CommandCache::getInstance()->getCommand($this->parameters['commandID']); + if ($command === null) { + throw new UserInputException('commandID'); + } + if (!$command->hasTriggers()) { + if (!$command->getProcessor()->allowWithoutTrigger()) { + throw new UserInputException('commandID'); + } + } - $this->readJSON('parameters', true); - } + $this->readJSON('parameters', true); + } - /** - * Pushes a new message into the given room. - */ - public function push() { - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); + /** + * Pushes a new message into the given room. + */ + public function push() + { + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } - $command = CommandCache::getInstance()->getCommand($this->parameters['commandID']); - if ($command === null) throw new UserInputException('commandID'); + $command = CommandCache::getInstance()->getCommand($this->parameters['commandID']); + if ($command === null) { + throw new UserInputException('commandID'); + } - $processor = $command->getProcessor(); - $processor->validate($this->parameters['parameters'], $room); - $processor->execute($this->parameters['parameters'], $room); - } + $processor = $command->getProcessor(); + $processor->validate($this->parameters['parameters'], $room); + $processor->execute($this->parameters['parameters'], $room); + } - /** - * Validates parameters and permissions. - */ - public function validatePushAttachment() { - $this->readInteger('roomID'); + /** + * Validates parameters and permissions. + */ + public function validatePushAttachment() + { + $this->readInteger('roomID'); - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); - if (!$room->canSee($user = null, $reason)) throw $reason; - $user = new \chat\data\user\User(WCF::getUser()); - if (!$user->isInRoom($room)) throw new PermissionDeniedException(); + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } + if (!$room->canSee($user = null, $reason)) { + throw $reason; + } + $user = new ChatUser(WCF::getUser()); + if (!$user->isInRoom($room)) { + throw new PermissionDeniedException(); + } - if (!$room->canWritePublicly(null, $reason)) throw $reason; + if (!$room->canWritePublicly(null, $reason)) { + throw $reason; + } - $this->readString('tmpHash'); - } + $this->readString('tmpHash'); + } - /** - * Pushes a new attachment into the given room. - */ - public function pushAttachment() { - $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.attachment'); - if (!$objectTypeID) throw new \LogicException('Missing object type'); + /** + * Pushes a new attachment into the given room. + */ + public function pushAttachment() + { + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.messageType', + 'be.bastelstu.chat.messageType.attachment' + ); + if (!$objectTypeID) { + throw new \LogicException('Missing object type'); + } - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } - $attachmentHandler = new AttachmentHandler('be.bastelstu.chat.message', 0, $this->parameters['tmpHash'], $room->roomID); - $attachments = $attachmentHandler->getAttachmentList(); - $attachmentIDs = []; - foreach ($attachments as $attachment) { - $attachmentIDs[] = $attachment->attachmentID; - } + $attachmentHandler = new AttachmentHandler( + 'be.bastelstu.chat.message', + 0, + $this->parameters['tmpHash'], + $room->roomID + ); + $attachments = $attachmentHandler->getAttachmentList(); + $attachmentIDs = []; + foreach ($attachments as $attachment) { + $attachmentIDs[] = $attachment->attachmentID; + } - $processor = new \wcf\system\html\input\HtmlInputProcessor(); - $processor->process(implode(' ', array_map(function ($attachmentID) { - return '[attach='.$attachmentID.',none,true][/attach]'; - }, $attachmentIDs)), 'be.bastelstu.chat.message', 0); + $processor = new HtmlInputProcessor(); + $processor->process(\implode(' ', \array_map(static function ($attachmentID) { + return '[attach=' . $attachmentID . ',none,true][/attach]'; + }, $attachmentIDs)), 'be.bastelstu.chat.message', 0); - WCF::getDB()->beginTransaction(); - /** @var Message $message */ - $message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => WCF::getUser()->userID - , 'username' => WCF::getUser()->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'attachmentIDs' => $attachmentIDs - , 'message' => $processor->getHtml() - ]) - ] - ] - ) - )->executeAction()['returnValues']; + WCF::getDB()->beginTransaction(); + /** @var Message $message */ + $message = (new self( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => WCF::getUser()->userID, + 'username' => WCF::getUser()->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'attachmentIDs' => $attachmentIDs, + 'message' => $processor->getHtml(), + ]), + ], + ] + ))->executeAction()['returnValues']; - $attachmentHandler->updateObjectID($message->messageID); - $processor->setObjectID($message->messageID); - if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($processor)) { - (new MessageEditor($message))->update([ - 'hasEmbeddedObjects' => 1 - ]); - } - WCF::getDB()->commitTransaction(); - } + $attachmentHandler->updateObjectID($message->messageID); + $processor->setObjectID($message->messageID); + if (MessageEmbeddedObjectManager::getInstance()->registerObjects($processor)) { + (new MessageEditor($message))->update([ + 'hasEmbeddedObjects' => 1, + ]); + } + WCF::getDB()->commitTransaction(); + } } diff --git a/files/lib/data/message/MessageEditor.class.php b/files/lib/data/message/MessageEditor.class.php index ba3bf29..de3c263 100644 --- a/files/lib/data/message/MessageEditor.class.php +++ b/files/lib/data/message/MessageEditor.class.php @@ -1,11 +1,12 @@ beginTransaction(); + /** + * @inheritDoc + */ + public static function deleteAll(array $messageIDs = []) + { + WCF::getDB()->beginTransaction(); - $result = parent::deleteAll($messageIDs); - if (!empty($messageIDs)) { - AttachmentHandler::removeAttachments('be.bastelstu.chat.message', $messageIDs); - } + $result = parent::deleteAll($messageIDs); + if (!empty($messageIDs)) { + AttachmentHandler::removeAttachments('be.bastelstu.chat.message', $messageIDs); + } - WCF::getDB()->commitTransaction(); + WCF::getDB()->commitTransaction(); - return $result; - } + return $result; + } } diff --git a/files/lib/data/message/MessageList.class.php b/files/lib/data/message/MessageList.class.php index e4197d3..3c352c7 100644 --- a/files/lib/data/message/MessageList.class.php +++ b/files/lib/data/message/MessageList.class.php @@ -1,11 +1,12 @@ room = $room; - } + $this->room = $room; + } - /** - * @inheritDoc - */ - public function jsonSerialize() { - $link = LinkHandler::getInstance()->getLink('Log', [ 'application' => 'chat' - , 'messageid' => $this->messageID - , 'object' => $this->room - ]); + /** + * @inheritDoc + */ + public function jsonSerialize() + { + $link = LinkHandler::getInstance()->getLink( + 'Log', + [ + 'application' => 'chat', + 'messageid' => $this->messageID, + 'object' => $this->room, + ] + ); - if ($this->isDeleted) { - $payload = false; - $objectType = 'be.bastelstu.chat.messageType.tombstone'; - } - else { - $payload = $this->getMessageType()->getProcessor()->getPayload($this->getDecoratedObject()); - $objectType = $this->getMessageType()->objectType; - } + if ($this->isDeleted) { + $payload = false; + $objectType = 'be.bastelstu.chat.messageType.tombstone'; + } else { + $payload = $this->getMessageType()->getProcessor()->getPayload($this->getDecoratedObject()); + $objectType = $this->getMessageType()->objectType; + } - return [ 'messageID' => $this->messageID - , 'userID' => $this->userID - , 'username' => $this->username - , 'time' => $this->time - , 'payload' => $payload - , 'objectType' => $objectType - , 'link' => $link - , 'isIgnored' => WCF::getUserProfileHandler()->isIgnoredUser($this->userID) - , 'isDeleted' => (bool) $this->isDeleted - ]; - } + return [ + 'messageID' => $this->messageID, + 'userID' => $this->userID, + 'username' => $this->username, + 'time' => $this->time, + 'payload' => $payload, + 'objectType' => $objectType, + 'link' => $link, + 'isIgnored' => WCF::getUserProfileHandler()->isIgnoredUser($this->userID), + 'isDeleted' => (bool)$this->isDeleted, + ]; + } } diff --git a/files/lib/data/room/Room.class.php b/files/lib/data/room/Room.class.php index 34b7a57..d88f10b 100644 --- a/files/lib/data/room/Room.class.php +++ b/files/lib/data/room/Room.class.php @@ -1,6 +1,7 @@ getTitle(); - } + /** + * @see Room::getTitle() + */ + public function __toString() + { + return $this->getTitle(); + } - /** - * Returns whether the given user can see at least - * one chat room. If no user is given the current user - * should be assumed - */ - public static function canSeeAny(\wcf\data\user\UserProfile $user = null): bool { - $rooms = RoomCache::getInstance()->getRooms(); - foreach ($rooms as $room) { - if ($room->canSee($user)) return true; - } + /** + * Returns whether the given user can see at least + * one chat room. If no user is given the current user + * should be assumed + */ + public static function canSeeAny(?UserProfile $user = null): bool + { + $rooms = RoomCache::getInstance()->getRooms(); + foreach ($rooms as $room) { + if ($room->canSee($user)) { + return true; + } + } - return false; - } + return false; + } - /** - * Returns whether the given user can see this room. - * If no user is given the current user should be assumed. - */ - public function canSee(\wcf\data\user\UserProfile $user = null, \Exception &$reason = null): bool { - static $cache = [ ]; - if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); + /** + * Returns whether the given user can see this room. + * If no user is given the current user should be assumed. + */ + public function canSee(?UserProfile $user = null, ?\Exception &$reason = null): bool + { + static $cache = [ ]; + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - if (!isset($cache[$this->roomID])) $cache[$this->roomID] = []; - if (array_key_exists($user->userID, $cache[$this->roomID])) { - return ($reason = $cache[$this->roomID][$user->userID]) === null; - } + if (!isset($cache[$this->roomID])) { + $cache[$this->roomID] = []; + } + if (\array_key_exists($user->userID, $cache[$this->roomID])) { + return ($reason = $cache[$this->roomID][$user->userID]) === null; + } - if (!$user->userID) { - $reason = new PermissionDeniedException(); - return ($cache[$this->roomID][$user->userID] = $reason) === null; - } + if (!$user->userID) { + $reason = new PermissionDeniedException(); - $result = null; - if (!PermissionHandler::get($user)->getPermission($this, 'user.canSee')) { - $result = new PermissionDeniedException(); - } + return ($cache[$this->roomID][$user->userID] = $reason) === null; + } - $parameters = [ 'user' => $user - , 'result' => $result - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - $reason = $parameters['result']; + $result = null; + if (!PermissionHandler::get($user)->getPermission($this, 'user.canSee')) { + $result = new PermissionDeniedException(); + } - if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { - throw new \DomainException('Result of canSee must be a \Throwable or null.'); - } + $parameters = [ + 'user' => $user, + 'result' => $result, + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $reason = $parameters['result']; - return ($cache[$this->roomID][$user->userID] = $reason) === null; - } + if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { + throw new \DomainException('Result of canSee must be a \Throwable or null.'); + } - /** - * Returns whether the given user can see the log of this room. - * If no user is given the current user should be assumed. - */ - public function canSeeLog(\wcf\data\user\UserProfile $user = null, \Exception &$reason = null): bool { - static $cache = [ ]; - if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); + return ($cache[$this->roomID][$user->userID] = $reason) === null; + } - if (!isset($cache[$this->roomID])) $cache[$this->roomID] = []; - if (array_key_exists($user->userID, $cache[$this->roomID])) { - return ($reason = $cache[$this->roomID][$user->userID]) === null; - } + /** + * Returns whether the given user can see the log of this room. + * If no user is given the current user should be assumed. + */ + public function canSeeLog(?UserProfile $user = null, ?\Exception &$reason = null): bool + { + static $cache = [ ]; + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $result = null; - if (!PermissionHandler::get($user)->getPermission($this, 'user.canSeeLog')) { - $result = new PermissionDeniedException(); - } + if (!isset($cache[$this->roomID])) { + $cache[$this->roomID] = []; + } + if (\array_key_exists($user->userID, $cache[$this->roomID])) { + return ($reason = $cache[$this->roomID][$user->userID]) === null; + } - $parameters = [ 'user' => $user - , 'result' => $result - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeLog', $parameters); - $reason = $parameters['result']; + $result = null; + if (!PermissionHandler::get($user)->getPermission($this, 'user.canSeeLog')) { + $result = new PermissionDeniedException(); + } - if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { - throw new \DomainException('Result of canSeeLog must be a \Throwable or null.'); - } + $parameters = [ + 'user' => $user, + 'result' => $result, + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeLog', $parameters); + $reason = $parameters['result']; - return ($cache[$this->roomID][$user->userID] = $reason) === null; - } + if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { + throw new \DomainException('Result of canSeeLog must be a \Throwable or null.'); + } - /** - * Returns whether the given user can join this room. - * If no user is given the current user should be assumed. - */ - public function canJoin(\wcf\data\user\UserProfile $user = null, \Exception &$reason = null): bool { - static $cache = [ ]; - if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); + return ($cache[$this->roomID][$user->userID] = $reason) === null; + } - if (!isset($cache[$this->roomID])) $cache[$this->roomID] = []; - if (array_key_exists($user->userID, $cache[$this->roomID])) { - return ($reason = $cache[$this->roomID][$user->userID]) === null; - } + /** + * Returns whether the given user can join this room. + * If no user is given the current user should be assumed. + */ + public function canJoin(?UserProfile $user = null, ?\Exception &$reason = null): bool + { + static $cache = [ ]; + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'user' => $user - , 'result' => null - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canJoin', $parameters); - $reason = $parameters['result']; + if (!isset($cache[$this->roomID])) { + $cache[$this->roomID] = []; + } + if (\array_key_exists($user->userID, $cache[$this->roomID])) { + return ($reason = $cache[$this->roomID][$user->userID]) === null; + } - if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { - throw new \DomainException('Result of canJoin must be a \Throwable or null.'); - } + $parameters = [ + 'user' => $user, + 'result' => null, + ]; + EventHandler::getInstance()->fireAction($this, 'canJoin', $parameters); + $reason = $parameters['result']; - return ($cache[$this->roomID][$user->userID] = $reason) === null; - } + if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { + throw new \DomainException('Result of canJoin must be a \Throwable or null.'); + } - /** - * Returns whether the given user can write public messages in this room. - * If no user is given the current user should be assumed. - */ - public function canWritePublicly(\wcf\data\user\UserProfile $user = null, \Exception &$reason = null): bool { - static $cache = [ ]; - if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); + return ($cache[$this->roomID][$user->userID] = $reason) === null; + } - if (!isset($cache[$this->roomID])) $cache[$this->roomID] = []; - if (array_key_exists($user->userID, $cache[$this->roomID])) { - return ($reason = $cache[$this->roomID][$user->userID]) === null; - } + /** + * Returns whether the given user can write public messages in this room. + * If no user is given the current user should be assumed. + */ + public function canWritePublicly(?UserProfile $user = null, ?\Exception &$reason = null): bool + { + static $cache = [ ]; + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $result = null; - if (!PermissionHandler::get($user)->getPermission($this, 'user.canWrite')) { - $result = new PermissionDeniedException(); - } + if (!isset($cache[$this->roomID])) { + $cache[$this->roomID] = []; + } + if (\array_key_exists($user->userID, $cache[$this->roomID])) { + return ($reason = $cache[$this->roomID][$user->userID]) === null; + } - $parameters = [ 'user' => $user - , 'result' => $result - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canWritePublicly', $parameters); - $reason = $parameters['result']; + $result = null; + if (!PermissionHandler::get($user)->getPermission($this, 'user.canWrite')) { + $result = new PermissionDeniedException(); + } - if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { - throw new \DomainException('Result of canWritePublicly must be a \Throwable or null.'); - } + $parameters = [ + 'user' => $user, + 'result' => $result, + ]; + EventHandler::getInstance()->fireAction($this, 'canWritePublicly', $parameters); + $reason = $parameters['result']; - return ($cache[$this->roomID][$user->userID] = $reason) === null; - } + if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { + throw new \DomainException('Result of canWritePublicly must be a \Throwable or null.'); + } - /** - * @inheritDoc - */ - public function getTitle() { - return WCF::getLanguage()->get($this->title); - } + return ($cache[$this->roomID][$user->userID] = $reason) === null; + } - /** - * @inheritDoc - */ - public function getTopic() { - $topic = StringUtil::trim(WCF::getLanguage()->get($this->topic)); + /** + * @inheritDoc + */ + public function getTitle() + { + return WCF::getLanguage()->get($this->title); + } - if (!$this->topicUseHtml) { - $topic = StringUtil::encodeHTML($topic); - } + /** + * @inheritDoc + */ + public function getTopic() + { + $topic = StringUtil::trim(WCF::getLanguage()->get($this->topic)); - return $topic; - } + if (!$this->topicUseHtml) { + $topic = StringUtil::encodeHTML($topic); + } - /** - * Returns an array of users in this room. - */ - public function getUsers() { - if (self::$userToRoom === null) { - $sql = "SELECT r2u.userID, r2u.roomID - FROM chat1_room_to_user r2u - INNER JOIN wcf1_user u - ON r2u.userID = u.userID - WHERE r2u.active = ? - ORDER BY u.username ASC"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ 1 ]); - self::$userToRoom = $statement->fetchMap('roomID', 'userID', false); + return $topic; + } - if (!empty(self::$userToRoom)) { - UserRuntimeCache::getInstance()->cacheObjectIDs(array_merge(...self::$userToRoom)); - } - } + /** + * Returns an array of users in this room. + */ + public function getUsers() + { + if (self::$userToRoom === null) { + $sql = "SELECT r2u.userID, + r2u.roomID + FROM chat1_room_to_user r2u + INNER JOIN wcf1_user u + ON r2u.userID = u.userID + WHERE r2u.active = ? + ORDER BY u.username ASC"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ 1 ]); + self::$userToRoom = $statement->fetchMap('roomID', 'userID', false); - if (!isset(self::$userToRoom[$this->roomID])) return [ ]; + if (!empty(self::$userToRoom)) { + ChatUserRuntimeCache::getInstance()->cacheObjectIDs(\array_merge(...self::$userToRoom)); + } + } - return UserRuntimeCache::getInstance()->getObjects(self::$userToRoom[$this->roomID]); - } + if (!isset(self::$userToRoom[$this->roomID])) { + return [ ]; + } - /** - * @inheritDoc - */ - public function getLink() { - return LinkHandler::getInstance()->getLink('Room', [ 'application' => 'chat' - , 'object' => $this - , 'forceFrontend' => true - ] - ); - } + return ChatUserRuntimeCache::getInstance()->getObjects(self::$userToRoom[$this->roomID]); + } - /** - * @inheritDoc - */ - public function jsonSerialize() { - return [ 'title' => $this->getTitle() - , 'topic' => $this->getTopic() - , 'link' => $this->getLink() - ]; - } + /** + * @inheritDoc + */ + public function getLink() + { + return LinkHandler::getInstance()->getLink( + 'Room', + [ + 'application' => 'chat', + 'object' => $this, + 'forceFrontend' => true, + ] + ); + } + + /** + * @inheritDoc + */ + public function jsonSerialize() + { + return [ + 'title' => $this->getTitle(), + 'topic' => $this->getTopic(), + 'link' => $this->getLink(), + ]; + } } diff --git a/files/lib/data/room/RoomAction.class.php b/files/lib/data/room/RoomAction.class.php index 19f4343..c4d11f6 100644 --- a/files/lib/data/room/RoomAction.class.php +++ b/files/lib/data/room/RoomAction.class.php @@ -1,6 +1,7 @@ parameters['user']); + /** + * Validates parameters and permissions. + */ + public function validateJoin() + { + unset($this->parameters['user']); - $this->readString('sessionID'); - $this->parameters['sessionID'] = pack('H*', str_replace('-', '', $this->parameters['sessionID'])); + $this->readString('sessionID'); + $this->parameters['sessionID'] = \pack( + 'H*', + \str_replace('-', '', $this->parameters['sessionID']) + ); - $this->readInteger('roomID'); + $this->readInteger('roomID'); - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); - if (!$room->canSee($user = null, $reason)) throw $reason; - if (!$room->canJoin($user = null, $reason)) throw $reason; - } + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } + if (!$room->canSee($user = null, $reason)) { + throw $reason; + } + if (!$room->canJoin($user = null, $reason)) { + throw $reason; + } + } - /** - * Makes the given user join the current chat room. - */ - public function join() { - $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.join'); - if (!$objectTypeID) throw new \LogicException('Missing object type'); - // User cannot be set during an AJAX request, but may be set by Tim’s Chat itself. - if (!isset($this->parameters['user'])) $this->parameters['user'] = WCF::getUser(); - $user = new ChatUser($this->parameters['user']); + /** + * Makes the given user join the current chat room. + */ + public function join() + { + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.messageType', + 'be.bastelstu.chat.messageType.join' + ); + if (!$objectTypeID) { + throw new \LogicException('Missing object type'); + } + // User cannot be set during an AJAX request, but may be set by Tim’s Chat itself. + if (!isset($this->parameters['user'])) { + $this->parameters['user'] = WCF::getUser(); + } + $user = new ChatUser($this->parameters['user']); - // Check parameters - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); - $sessionID = $this->parameters['sessionID']; - if (strlen($sessionID) !== 16) throw new UserInputException('sessionID'); + // Check parameters + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } + $sessionID = $this->parameters['sessionID']; + if (\strlen($sessionID) !== 16) { + throw new UserInputException('sessionID'); + } - try { - // Create room_to_user mapping. - $sql = "INSERT INTO chat1_room_to_user (active, roomID, userID) VALUES (?, ?, ?)"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ 0, $room->roomID, $user->userID ]); - } - catch (\wcf\system\database\exception\DatabaseException $e) { - // Ignore if there already is a mapping. - if ((string) $e->getCode() !== '23000') throw $e; - } + try { + // Create room_to_user mapping. + $sql = "INSERT INTO chat1_room_to_user + (active, roomID, userID) + VALUES (?, ?, ?)"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ 0, $room->roomID, $user->userID ]); + } catch (\wcf\system\database\exception\DatabaseException $e) { + // Ignore if there already is a mapping. + if ((string)$e->getCode() !== '23000') { + throw $e; + } + } - try { - $sql = "INSERT INTO chat1_session (roomID, userID, sessionID, lastRequest) VALUES (?, ?, ?, ?)"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ $room->roomID, $user->userID, $sessionID, TIME_NOW ]); - } - catch (\wcf\system\database\exception\DatabaseException $e) { - if ((string) $e->getCode() !== '23000') throw $e; + try { + $sql = "INSERT INTO chat1_session + (roomID, userID, sessionID, lastRequest) + VALUES (?, ?, ?, ?)"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ + $room->roomID, + $user->userID, + $sessionID, + TIME_NOW, + ]); + } catch (\wcf\system\database\exception\DatabaseException $e) { + if ((string)$e->getCode() !== '23000') { + throw $e; + } - throw new UserInputException('sessionID'); - } + throw new UserInputException('sessionID'); + } - $markAsBack = function () use ($user, $room) { - $userProfile = new \wcf\data\user\UserProfile($user->getDecoratedObject()); - $package = \wcf\data\package\PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat'); - $command = \chat\data\command\CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'back'); - $processor = $command->getProcessor(); - $processor->execute([ ], $room, $userProfile); - }; + $markAsBack = static function () use ($user, $room) { + $userProfile = new UserProfile($user->getDecoratedObject()); + $package = PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat'); + $command = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'back'); + $processor = $command->getProcessor(); + $processor->execute([ ], $room, $userProfile); + }; - if ($user->chatAway !== null) { - $markAsBack(); - } + if ($user->chatAway !== null) { + $markAsBack(); + } - // Attempt to mark the user as active in the room. - $sql = "UPDATE chat1_room_to_user SET active = ? WHERE roomID = ? AND userID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ 1, $room->roomID, $user->userID ]); - if ($statement->getAffectedRows() === 0) { - // The User already is inside the room: Nothing to do here. - return; - } + // Attempt to mark the user as active in the room. + $sql = "UPDATE chat1_room_to_user + SET active = ? + WHERE roomID = ? + AND userID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ 1, $room->roomID, $user->userID ]); + if ($statement->getAffectedRows() === 0) { + // The User already is inside the room: Nothing to do here. + return; + } - // Update lastPull. This must not be merged into the above query, because of the 'getAffectedRows' check. - $sql = "UPDATE chat1_room_to_user SET lastPull = ? WHERE roomID = ? AND userID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ TIME_NOW, $room->roomID, $user->userID ]); + // Update lastPull. This must not be merged into the above query, because of the 'getAffectedRows' check. + $sql = "UPDATE chat1_room_to_user + SET lastPull = ? + WHERE roomID = ? + AND userID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ TIME_NOW, $room->roomID, $user->userID ]); - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ ]) - ] - ] - ) - )->executeAction(); + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ ]), + ], + ] + ))->executeAction(); - UserActivityPointHandler::getInstance()->fireEvent('be.bastelstu.chat.activityPointEvent.join', 0, $user->userID); - $pushHandler = \wcf\system\push\PushHandler::getInstance(); - $pushHandler->sendMessage([ 'message' => 'be.bastelstu.chat.join' - , 'target' => 'registered' - ]); - } + UserActivityPointHandler::getInstance()->fireEvent( + 'be.bastelstu.chat.activityPointEvent.join', + 0, + $user->userID + ); + $pushHandler = PushHandler::getInstance(); + $pushHandler->sendMessage([ + 'message' => 'be.bastelstu.chat.join', + 'target' => 'registered', + ]); + } - /** - * Validates parameters and permissions. - */ - public function validateLeave() { - unset($this->parameters['user']); + /** + * Validates parameters and permissions. + */ + public function validateLeave() + { + unset($this->parameters['user']); - $this->readString('sessionID'); - $this->parameters['sessionID'] = pack('H*', str_replace('-', '', $this->parameters['sessionID'])); + $this->readString('sessionID'); + $this->parameters['sessionID'] = \pack( + 'H*', + \str_replace('-', '', $this->parameters['sessionID']) + ); - $this->readInteger('roomID'); - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); - // Do not check permissions: If the user is not inside the room nothing happens, if he is it - // may lead to a faster eviction of the user. - } + $this->readInteger('roomID'); + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } + // Do not check permissions: If the user is not inside the room nothing happens, if he is it + // may lead to a faster eviction of the user. + } - /** - * Makes the given user leave the current chat room. - */ - public function leave() { - $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.leave'); - if ($objectTypeID) { - // User cannot be set during an AJAX request, but may be set by Tim’s Chat itself. - if (!isset($this->parameters['user'])) $this->parameters['user'] = WCF::getUser(); - $user = new ChatUser($this->parameters['user']); + /** + * Makes the given user leave the current chat room. + */ + public function leave() + { + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.messageType', + 'be.bastelstu.chat.messageType.leave' + ); + if ($objectTypeID) { + // User cannot be set during an AJAX request, but may be set by Tim’s Chat itself. + if (!isset($this->parameters['user'])) { + $this->parameters['user'] = WCF::getUser(); + } + $user = new ChatUser($this->parameters['user']); - $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); - if ($room === null) throw new UserInputException('roomID'); + $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); + if ($room === null) { + throw new UserInputException('roomID'); + } - $sessionID = null; - if (isset($this->parameters['sessionID'])) { - $sessionID = $this->parameters['sessionID']; - if (strlen($sessionID) !== 16) throw new UserInputException('sessionID'); - } + $sessionID = null; + if (isset($this->parameters['sessionID'])) { + $sessionID = $this->parameters['sessionID']; + if (\strlen($sessionID) !== 16) { + throw new UserInputException('sessionID'); + } + } - // Delete session. - $condition = new \wcf\system\database\util\PreparedStatementConditionBuilder(); - $condition->add('roomID = ?', [ $room->roomID ]); - $condition->add('userID = ?', [ $user->userID ]); - if ($sessionID !== null) { - $condition->add('sessionID = ?', [ $sessionID ]); - } - $sql = "DELETE FROM chat1_session - ".$condition; - $statement = WCF::getDB()->prepare($sql); - $statement->execute($condition->getParameters()); - if ($statement->getAffectedRows() === 0) { - throw new UserInputException('sessionID'); - } + // Delete session. + $condition = new PreparedStatementConditionBuilder(); + $condition->add('roomID = ?', [ $room->roomID ]); + $condition->add('userID = ?', [ $user->userID ]); + if ($sessionID !== null) { + $condition->add('sessionID = ?', [ $sessionID ]); + } + $sql = "DELETE FROM chat1_session + {$condition}"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute($condition->getParameters()); + if ($statement->getAffectedRows() === 0) { + throw new UserInputException('sessionID'); + } - try { - $commited = false; - WCF::getDB()->beginTransaction(); + try { + $commited = false; + WCF::getDB()->beginTransaction(); - // Check whether we deleted the last session. - $sql = "SELECT COUNT(*) - FROM chat1_session - WHERE roomID = ? - AND userID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ $room->roomID, $user->userID ]); + // Check whether we deleted the last session. + $sql = "SELECT COUNT(*) + FROM chat1_session + WHERE roomID = ? + AND userID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ $room->roomID, $user->userID ]); - // We did not: Nothing to do here. - if ($statement->fetchColumn()) return; + // We did not: Nothing to do here. + if ($statement->fetchColumn()) { + return; + } - // Mark the user as inactive. - $sql = "UPDATE chat1_room_to_user SET active = ? WHERE roomID = ? AND userID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ 0, $room->roomID, $user->userID ]); - if ($statement->getAffectedRows() === 0) throw new \LogicException('Unreachable'); + // Mark the user as inactive. + $sql = "UPDATE chat1_room_to_user + SET active = ? + WHERE roomID = ? + AND userID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ 0, $room->roomID, $user->userID ]); + if ($statement->getAffectedRows() === 0) { + throw new \LogicException('Unreachable'); + } - WCF::getDB()->commitTransaction(); - $commited = true; - } - finally { - if (!$commited) WCF::getDB()->rollBackTransaction(); - } + WCF::getDB()->commitTransaction(); + $commited = true; + } finally { + if (!$commited) { + WCF::getDB()->rollBackTransaction(); + } + } - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ ]) - ] - ] - ) - )->executeAction(); + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ ]), + ], + ] + ))->executeAction(); - $pushHandler = \wcf\system\push\PushHandler::getInstance(); - $pushHandler->sendMessage([ 'message' => 'be.bastelstu.chat.leave' - , 'target' => 'registered' - ]); - } - else { - throw new \LogicException('Missing object type'); - } - } + $pushHandler = PushHandler::getInstance(); + $pushHandler->sendMessage([ + 'message' => 'be.bastelstu.chat.leave', + 'target' => 'registered', + ]); + } else { + throw new \LogicException('Missing object type'); + } + } - /** - * Validates parameters and permissions. - */ - public function validateGetUsers() { - if (empty($this->getObjects())) { - $this->readObjects(); - } - if (count($this->getObjects()) !== 1) { - throw new UserInputException('objectIDs'); - } + /** + * Validates parameters and permissions. + */ + public function validateGetUsers() + { + if (empty($this->getObjects())) { + $this->readObjects(); + } + if (\count($this->getObjects()) !== 1) { + throw new UserInputException('objectIDs'); + } - $room = $this->getObjects()[0]; + $room = $this->getObjects()[0]; - $user = new ChatUser(WCF::getUser()); - if (!$user->isInRoom($room->getDecoratedObject())) throw new PermissionDeniedException(); - } + $user = new ChatUser(WCF::getUser()); + if (!$user->isInRoom($room->getDecoratedObject())) { + throw new PermissionDeniedException(); + } + } - /** - * Returns the userIDs of the users in this room. - */ - public function getUsers() { - if (empty($this->getObjects())) { - $this->readObjects(); - } - if (count($this->getObjects()) !== 1) { - throw new UserInputException('objectIDs'); - } + /** + * Returns the userIDs of the users in this room. + */ + public function getUsers() + { + if (empty($this->getObjects())) { + $this->readObjects(); + } + if (\count($this->getObjects()) !== 1) { + throw new UserInputException('objectIDs'); + } - $room = $this->getObjects()[0]; + $room = $this->getObjects()[0]; - $users = (new \chat\data\user\UserAction([ ], 'getUsersByID', [ - 'userIDs' => array_keys($room->getUsers()) - ]))->executeAction()['returnValues']; + $users = (new ChatUserAction( + [ ], + 'getUsersByID', + [ + 'userIDs' => \array_keys($room->getUsers()), + ] + ))->executeAction()['returnValues']; - $users = array_map(function (array $user) use ($room) { - $userProfile = UserProfileRuntimeCache::getInstance()->getObject($user['userID']); - if (!isset($user['permissions'])) $user['permissions'] = []; - $user['permissions']['canWritePublicly'] = $room->canWritePublicly($userProfile); + $users = \array_map(static function (array $user) use ($room) { + $userProfile = UserProfileRuntimeCache::getInstance()->getObject($user['userID']); + if (!isset($user['permissions'])) { + $user['permissions'] = []; + } + $user['permissions']['canWritePublicly'] = $room->canWritePublicly($userProfile); - return $user; - }, $users); - - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getUsers', $users); + return $user; + }, $users); - return $users; - } + EventHandler::getInstance()->fireAction($this, 'getUsers', $users); - /** - * @inheritDoc - */ - public function validateUpdatePosition() { - // validate permissions - if (is_array($this->permissionsUpdate) && !empty($this->permissionsUpdate)) { - WCF::getSession()->checkPermissions($this->permissionsUpdate); - } - else { - throw new PermissionDeniedException(); - } + return $users; + } - $this->readIntegerArray('structure', false, 'data'); + /** + * @inheritDoc + */ + public function validateUpdatePosition() + { + // validate permissions + if (\is_array($this->permissionsUpdate) && !empty($this->permissionsUpdate)) { + WCF::getSession()->checkPermissions($this->permissionsUpdate); + } else { + throw new PermissionDeniedException(); + } - $roomList = new RoomList(); - $roomList->readObjects(); + $this->readIntegerArray('structure', false, 'data'); - foreach ($this->parameters['data']['structure'][0] as $roomID) { - $room = $roomList->search($roomID); - if ($room === null) throw new UserInputException('structure'); - } - } + $roomList = new RoomList(); + $roomList->readObjects(); - /** - * @inheritDoc - */ - public function updatePosition() { - $roomList = new RoomList(); - $roomList->readObjects(); + foreach ($this->parameters['data']['structure'][0] as $roomID) { + $room = $roomList->search($roomID); + if ($room === null) { + throw new UserInputException('structure'); + } + } + } - $i = 0; - WCF::getDB()->beginTransaction(); - foreach ($this->parameters['data']['structure'][0] as $roomID) { - $room = $roomList->search($roomID); - if ($room === null) continue; + /** + * @inheritDoc + */ + public function updatePosition() + { + $roomList = new RoomList(); + $roomList->readObjects(); - $editor = new RoomEditor($room); - $editor->update([ 'position' => $i++ ]); - } - WCF::getDB()->commitTransaction(); - } + $i = 0; + WCF::getDB()->beginTransaction(); + foreach ($this->parameters['data']['structure'][0] as $roomID) { + $room = $roomList->search($roomID); + if ($room === null) { + continue; + } - /** - * Validates permissions. - */ - public function validateGetBoxRoomList() { - if (!\chat\data\room\Room::canSeeAny()) throw new \wcf\system\exception\PermissionDeniedException(); + $editor = new RoomEditor($room); + $editor->update([ + 'position' => $i++, + ]); + } + WCF::getDB()->commitTransaction(); + } - $this->readBoolean('isSidebar', true); - $this->readBoolean('skipEmptyRooms', true); - $this->readInteger('activeRoomID', true); + /** + * Validates permissions. + */ + public function validateGetBoxRoomList() + { + if (!Room::canSeeAny()) { + throw new PermissionDeniedException(); + } - unset($this->parameters['boxController']); - $this->readInteger('boxID', true); - if ($this->parameters['boxID']) { - $box = new \wcf\data\box\Box($this->parameters['boxID']); - if ($box->boxID) { - $this->parameters['boxController'] = $box->getController(); - if ($this->parameters['boxController'] instanceof \chat\system\box\RoomListBoxController) { - // all checks passed, end validation; otherwise throw the exception below - return; - } - } + $this->readBoolean('isSidebar', true); + $this->readBoolean('skipEmptyRooms', true); + $this->readInteger('activeRoomID', true); - throw new UserInputException('boxID'); - } - } + unset($this->parameters['boxController']); + $this->readInteger('boxID', true); + if ($this->parameters['boxID']) { + $box = new Box($this->parameters['boxID']); + if ($box->boxID) { + $this->parameters['boxController'] = $box->getController(); + if ($this->parameters['boxController'] instanceof RoomListBoxController) { + // all checks passed, end validation; otherwise throw the exception below + return; + } + } - /** - * Returns dashboard roomlist. - */ - public function getBoxRoomList() { - if (isset($this->parameters['boxController'])) { - $this->parameters['boxController']->setActiveRoomID($this->parameters['activeRoomID']); + throw new UserInputException('boxID'); + } + } - return [ 'template' => $this->parameters['boxController']->getContent() ]; - } + /** + * Returns dashboard roomlist. + */ + public function getBoxRoomList() + { + if (isset($this->parameters['boxController'])) { + $this->parameters['boxController']->setActiveRoomID($this->parameters['activeRoomID']); - // Fetch all rooms, the templates have filtering in place - $rooms = RoomCache::getInstance()->getRooms(); + return [ + 'template' => $this->parameters['boxController']->getContent(), + ]; + } - $template = 'boxRoomList'.($this->parameters['isSidebar'] ? 'Sidebar' : ''); + // Fetch all rooms, the templates have filtering in place + $rooms = RoomCache::getInstance()->getRooms(); - \wcf\system\WCF::getTPL()->assign([ 'boxRoomList' => $rooms - , 'skipEmptyRooms' => $this->parameters['skipEmptyRooms'] - , 'activeRoomID' => $this->parameters['activeRoomID'] - ]); + $template = 'boxRoomList' . ($this->parameters['isSidebar'] ? 'Sidebar' : ''); - return [ 'template' => \wcf\system\WCF::getTPL()->fetch($template, 'chat') ]; - } + WCF::getTPL()->assign([ + 'boxRoomList' => $rooms, + 'skipEmptyRooms' => $this->parameters['skipEmptyRooms'], + 'activeRoomID' => $this->parameters['activeRoomID'], + ]); + + return [ + 'template' => WCF::getTPL()->fetch($template, 'chat'), + ]; + } } diff --git a/files/lib/data/room/RoomCache.class.php b/files/lib/data/room/RoomCache.class.php index a1de524..48a4439 100644 --- a/files/lib/data/room/RoomCache.class.php +++ b/files/lib/data/room/RoomCache.class.php @@ -1,11 +1,12 @@ rooms = \chat\system\cache\builder\RoomCacheBuilder::getInstance()->getData(); - } + /** + * @inheritDoc + */ + protected function init() + { + $this->rooms = RoomCacheBuilder::getInstance()->getData(); + } - /** - * Returns a specific room. - * - * @param integer $roomID - * @return Room - */ - public function getRoom($roomID) { - if (isset($this->rooms[$roomID])) { - return $this->rooms[$roomID]; - } + /** + * Returns a specific room. + * + * @param integer $roomID + * @return Room + */ + public function getRoom($roomID) + { + if (isset($this->rooms[$roomID])) { + return $this->rooms[$roomID]; + } - return null; - } + return null; + } - /** - * Returns all rooms. - * - * @return Room[] - */ - public function getRooms() { - return $this->rooms; - } + /** + * Returns all rooms. + * + * @return Room[] + */ + public function getRooms() + { + return $this->rooms; + } } diff --git a/files/lib/data/room/RoomEditor.class.php b/files/lib/data/room/RoomEditor.class.php index ca217db..c85c651 100644 --- a/files/lib/data/room/RoomEditor.class.php +++ b/files/lib/data/room/RoomEditor.class.php @@ -1,11 +1,12 @@ reset(); - \chat\system\permission\PermissionHandler::resetCache(); - } + /** + * @inheritDoc + */ + public static function resetCache() + { + RoomCacheBuilder::getInstance()->reset(); + PermissionHandler::resetCache(); + } } diff --git a/files/lib/data/room/RoomList.class.php b/files/lib/data/room/RoomList.class.php index 237cc93..4fb6251 100644 --- a/files/lib/data/room/RoomList.class.php +++ b/files/lib/data/room/RoomList.class.php @@ -1,11 +1,12 @@ getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]); - $suspensionList->getConditionBuilder()->add('revoked IS NULL'); - $suspensionList->getConditionBuilder()->add('userID = ?', [ $user->userID ]); - $suspensionList->getConditionBuilder()->add('objectTypeID = ?', [ $objectTypeID ]); - $suspensionList->getConditionBuilder()->add('(roomID IS NULL OR roomID = ?)', [ $room->roomID ]); + $suspensionList->getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]); + $suspensionList->getConditionBuilder()->add('revoked IS NULL'); + $suspensionList->getConditionBuilder()->add('userID = ?', [ $user->userID ]); + $suspensionList->getConditionBuilder()->add('objectTypeID = ?', [ $objectTypeID ]); + $suspensionList->getConditionBuilder()->add('(roomID IS NULL OR roomID = ?)', [ $room->roomID ]); - $suspensionList->readObjects(); + $suspensionList->readObjects(); - return array_filter($suspensionList->getObjects(), function (Suspension $suspension) { - return $suspension->isActive(); - }); - } + return \array_filter($suspensionList->getObjects(), static function (self $suspension) { + return $suspension->isActive(); + }); + } - /** - * Returns the suspension object type of this message. - * - * @return \wcf\data\object\type\ObjectType - */ - public function getSuspensionType() { - return \wcf\data\object\type\ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID); - } + /** + * Returns the suspension object type of this message. + * + * @return \wcf\data\object\type\ObjectType + */ + public function getSuspensionType() + { + return ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID); + } - /** - * Returns whether this suspension still is in effect. - * - * @return boolean - */ - public function isActive() { - if ($this->revoked !== null) return false; - if (!$this->getSuspensionType()->getProcessor()->hasEffect($this)) return false; + /** + * Returns whether this suspension still is in effect. + * + * @return boolean + */ + public function isActive() + { + if ($this->revoked !== null) { + return false; + } + if (!$this->getSuspensionType()->getProcessor()->hasEffect($this)) { + return false; + } - if ($this->expires === null) return true; + if ($this->expires === null) { + return true; + } - return $this->expires > TIME_NOW; - } + return $this->expires > TIME_NOW; + } - /** - * Returns the chat room this suspension is in effect. - * Returns null if this is a global suspension. - * - * @return \chat\data\room\Room - */ - public function getRoom() { - if ($this->roomID === null) { - return null; - } + /** + * Returns the chat room this suspension is in effect. + * Returns null if this is a global suspension. + * + * @return \chat\data\room\Room + */ + public function getRoom() + { + if ($this->roomID === null) { + return null; + } - return \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); - } + return RoomCache::getInstance()->getRoom($this->roomID); + } - /** - * Returns the user that is affected by this suspension. - * - * @return \wcf\data\user\User - */ - public function getUser() { - return \wcf\system\cache\runtime\UserRuntimeCache::getInstance()->getObject($this->userID); - } + /** + * Returns the user that is affected by this suspension. + * + * @return \wcf\data\user\User + */ + public function getUser() + { + return UserRuntimeCache::getInstance()->getObject($this->userID); + } - /** - * @inheritDoc - */ - public function jsonSerialize() { - return [ 'userID' => $this->userID - , 'username' => $this->getUser()->username - , 'roomID' => $this->roomID - , 'time' => $this->time - , 'expires' => $this->expires - , 'reason' => $this->reason - , 'objectType' => $this->getSuspensionType()->objectType - , 'judgeID' => $this->judgeID - , 'judge' => $this->judge - ]; - } + /** + * @inheritDoc + */ + public function jsonSerialize() + { + return [ + 'userID' => $this->userID, + 'username' => $this->getUser()->username, + 'roomID' => $this->roomID, + 'time' => $this->time, + 'expires' => $this->expires, + 'reason' => $this->reason, + 'objectType' => $this->getSuspensionType()->objectType, + 'judgeID' => $this->judgeID, + 'judge' => $this->judge, + ]; + } } diff --git a/files/lib/data/suspension/SuspensionAction.class.php b/files/lib/data/suspension/SuspensionAction.class.php index 4e179fa..cc551ed 100644 --- a/files/lib/data/suspension/SuspensionAction.class.php +++ b/files/lib/data/suspension/SuspensionAction.class.php @@ -1,11 +1,12 @@ objects)) { - $this->readObjects(); + /** + * Validates parameters and permissions. + */ + public function validateRevoke() + { + if (empty($this->objects)) { + $this->readObjects(); - if (empty($this->objects)) { - throw new UserInputException('objectIDs'); - } - } + if (empty($this->objects)) { + throw new UserInputException('objectIDs'); + } + } - unset($this->parameters['revoker']); + unset($this->parameters['revoker']); - WCF::getSession()->checkPermissions([ 'admin.chat.canManageSuspensions' ]); + WCF::getSession()->checkPermissions([ + 'admin.chat.canManageSuspensions', + ]); - foreach ($this->getObjects() as $object) { - if (!$object->isActive()) throw new UserInputException('objectIDs', 'nonActive'); - } - } + foreach ($this->getObjects() as $object) { + if (!$object->isActive()) { + throw new UserInputException('objectIDs', 'nonActive'); + } + } + } - /** - * Revokes the suspensions - */ - public function revoke() { - if (empty($this->objects)) { - $this->readObjects(); - } + /** + * Revokes the suspensions + */ + public function revoke() + { + if (empty($this->objects)) { + $this->readObjects(); + } - // User cannot be set during an AJAX request, but may be set by Tim’s Chat itself. - if (!isset($this->parameters['revoker'])) $this->parameters['revoker'] = WCF::getUser(); + // User cannot be set during an AJAX request, but may be set by Tim’s Chat itself. + if (!isset($this->parameters['revoker'])) { + $this->parameters['revoker'] = WCF::getUser(); + } - $data = [ 'revoked' => TIME_NOW - , 'revokerID' => $this->parameters['revoker']->userID - , 'revoker' => $this->parameters['revoker']->username - ]; + $data = [ + 'revoked' => TIME_NOW, + 'revokerID' => $this->parameters['revoker']->userID, + 'revoker' => $this->parameters['revoker']->username, + ]; - $objectAction = new static($this->getObjects(), 'update', [ 'data' => $data ]); - $objectAction->executeAction(); - } + $objectAction = new static( + $this->getObjects(), + 'update', + [ + 'data' => $data, + ] + ); + $objectAction->executeAction(); + } } diff --git a/files/lib/data/suspension/SuspensionEditor.class.php b/files/lib/data/suspension/SuspensionEditor.class.php index fb2519d..44d72dd 100644 --- a/files/lib/data/suspension/SuspensionEditor.class.php +++ b/files/lib/data/suspension/SuspensionEditor.class.php @@ -1,11 +1,12 @@ roomToUser === null || $skipCache) { - $sql = "SELECT * - FROM chat1_room_to_user - WHERE userID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ $this->userID ]); - $this->roomToUser = [ ]; - while (($row = $statement->fetchArray())) { - $this->roomToUser[$row['roomID']] = $row; - } - } + /** + * Returns an array of the room_to_user arrays for this user. + * + * @return mixed[] + */ + public function getRoomAssociations($skipCache = false) + { + if ($this->roomToUser === null || $skipCache) { + $sql = "SELECT * + FROM chat1_room_to_user + WHERE userID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ $this->userID ]); + $this->roomToUser = [ ]; + while (($row = $statement->fetchArray())) { + $this->roomToUser[$row['roomID']] = $row; + } + } - return $this->roomToUser; - } + return $this->roomToUser; + } - /** - * Returns an array of Rooms this user is part of. - * - * @return \chat\data\room\Room[] - */ - public function getRooms($skipCache = false) { - return array_map(function ($assoc) { - return \chat\data\room\RoomCache::getInstance()->getRoom($assoc['roomID']); - }, array_filter($this->getRoomAssociations($skipCache), function ($assoc) { - return $assoc['active'] === 1; - })); - } + /** + * Returns an array of Rooms this user is part of. + * + * @return \chat\data\room\Room[] + */ + public function getRooms($skipCache = false) + { + return \array_map(static function ($assoc) { + return RoomCache::getInstance()->getRoom($assoc['roomID']); + }, \array_filter($this->getRoomAssociations($skipCache), static function ($assoc) { + return $assoc['active'] === 1; + })); + } - /** - * Returns whether the user is in the given room. - * - * @param \chat\data\room\Room $room - * @return boolean - */ - public function isInRoom(\chat\data\room\Room $room, $skipCache = false) { - $assoc = $this->getRoomAssociations($skipCache); + /** + * Returns whether the user is in the given room. + * + * @return boolean + */ + public function isInRoom(Room $room, $skipCache = false) + { + $assoc = $this->getRoomAssociations($skipCache); - if (!isset($assoc[$room->roomID])) return false; - return $assoc[$room->roomID]['active'] === 1; - } + if (!isset($assoc[$room->roomID])) { + return false; + } - /** - * Returns (userID, roomID, sessionID) triples where the client died. - * - * @return mixed[][] - */ - public static function getDeadSessions() { - $sql = "SELECT userID, roomID, sessionID - FROM chat1_session - WHERE lastRequest < ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ TIME_NOW - 60 * 3 ]); + return $assoc[$room->roomID]['active'] === 1; + } - return $statement->fetchAll(\PDO::FETCH_ASSOC); - } + /** + * Returns (userID, roomID, sessionID) triples where the client died. + * + * @return mixed[][] + */ + public static function getDeadSessions() + { + $sql = "SELECT userID, + roomID, + sessionID + FROM chat1_session + WHERE lastRequest < ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ + TIME_NOW - 60 * 3, + ]); - /** - * @inheritDoc - */ - public function jsonSerialize() { - return [ 'userID' => $this->userID - , 'username' => $this->username - , 'link' => $this->getLink() - ]; - } + return $statement->fetchAll(\PDO::FETCH_ASSOC); + } + + /** + * @inheritDoc + */ + public function jsonSerialize() + { + return [ + 'userID' => $this->userID, + 'username' => $this->username, + 'link' => $this->getLink(), + ]; + } } diff --git a/files/lib/data/user/UserAction.class.php b/files/lib/data/user/UserAction.class.php index e8f8284..ffabde3 100644 --- a/files/lib/data/user/UserAction.class.php +++ b/files/lib/data/user/UserAction.class.php @@ -1,11 +1,12 @@ readIntegerArray('userIDs'); - } + $this->readIntegerArray('userIDs'); + } - /** - * Returns information about the users identified by the given userIDs. - */ - public function getUsersByID() { - $userList = UserProfileRuntimeCache::getInstance()->getObjects($this->parameters['userIDs']); + /** + * Returns information about the users identified by the given userIDs. + */ + public function getUsersByID() + { + $userList = UserProfileRuntimeCache::getInstance()->getObjects($this->parameters['userIDs']); - return array_map(function ($user) { - if (!$user) return null; + return \array_map(function ($user) { + if (!$user) { + return null; + } - $payload = [ 'image16' => $user->getAvatar()->getImageTag(16) - , 'image24' => $user->getAvatar()->getImageTag(24) - , 'image32' => $user->getAvatar()->getImageTag(32) - , 'image48' => $user->getAvatar()->getImageTag(48) - , 'imageUrl' => $user->getAvatar()->getURL() - , 'link' => $user->getLink() - , 'anchor' => $user->getAnchorTag() - , 'userID' => $user->userID - , 'username' => $user->username - , 'userTitle' => $user->getUserTitle() - , 'userRankClass' => $user->getRank() ? $user->getRank()->cssClassName : null - , 'formattedUsername' => $user->getFormattedUsername() - , 'away' => $user->chatAway - , 'color1' => $user->chatColor1 - , 'color2' => $user->chatColor2 - ]; + $payload = [ + 'image16' => $user->getAvatar()->getImageTag(16), + 'image24' => $user->getAvatar()->getImageTag(24), + 'image32' => $user->getAvatar()->getImageTag(32), + 'image48' => $user->getAvatar()->getImageTag(48), + 'imageUrl' => $user->getAvatar()->getURL(), + 'link' => $user->getLink(), + 'anchor' => $user->getAnchorTag(), + 'userID' => $user->userID, + 'username' => $user->username, + 'userTitle' => $user->getUserTitle(), + 'userRankClass' => $user->getRank() ? $user->getRank()->cssClassName : null, + 'formattedUsername' => $user->getFormattedUsername(), + 'away' => $user->chatAway, + 'color1' => $user->chatColor1, + 'color2' => $user->chatColor2, + ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getUsersByID', $payload); + EventHandler::getInstance()->fireAction($this, 'getUsersByID', $payload); - return $payload; - }, $userList); - } + return $payload; + }, $userList); + } - /** - * Clears dead clients. - */ - public function clearDeadSessions() { - $sessions = User::getDeadSessions(); - if (empty($sessions)) return; - $userIDs = array_map(function ($item) { - return $item['userID']; - }, $sessions); - $users = UserRuntimeCache::getInstance()->getObjects($userIDs); - foreach ($sessions as $session) { - $parameters = [ 'user' => $users[$session['userID']] - , 'roomID' => $session['roomID'] - , 'sessionID' => $session['sessionID'] - ]; - try { - (new \chat\data\room\RoomAction([ ], 'leave', $parameters))->executeAction(); - } - catch (UserInputException $e) { - // Probably some other request has been faster to remove this session, ignore - } - } - } + /** + * Clears dead clients. + */ + public function clearDeadSessions() + { + $sessions = User::getDeadSessions(); + if (empty($sessions)) { + return; + } + $userIDs = \array_map(static function ($item) { + return $item['userID']; + }, $sessions); + $users = UserRuntimeCache::getInstance()->getObjects($userIDs); + foreach ($sessions as $session) { + $parameters = [ + 'user' => $users[$session['userID']], + 'roomID' => $session['roomID'], + 'sessionID' => $session['sessionID'], + ]; - /** - * @inheritDoc - */ - public function create() { - throw new \BadMethodCallException(); - } + try { + (new RoomAction( + [ ], + 'leave', + $parameters + ))->executeAction(); + } catch (UserInputException $e) { + // Probably some other request has been faster to remove this session, ignore + } + } + } - /** - * @inheritDoc - */ - public function update() { - throw new \BadMethodCallException(); - } + /** + * @inheritDoc + */ + public function create() + { + throw new \BadMethodCallException(); + } - /** - * @inheritDoc - */ - public function delete() { - throw new \BadMethodCallException(); - } + /** + * @inheritDoc + */ + public function update() + { + throw new \BadMethodCallException(); + } + + /** + * @inheritDoc + */ + public function delete() + { + throw new \BadMethodCallException(); + } } diff --git a/files/lib/data/user/UserList.class.php b/files/lib/data/user/UserList.class.php index 3985206..602188b 100644 --- a/files/lib/data/user/UserList.class.php +++ b/files/lib/data/user/UserList.class.php @@ -1,11 +1,12 @@ roomID = intval($_GET['id']); - $this->room = \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); + /** + * @inheritDoc + */ + public function readParameters() + { + parent::readParameters(); - if ($this->room === null) throw new IllegalLinkException(); - if (!$this->room->canSee($user = null, $reason)) throw $reason; - if (!$this->room->canSeeLog($user = null, $reason)) throw $reason; + if (isset($_GET['id'])) { + $this->roomID = \intval($_GET['id']); + } + $this->room = RoomCache::getInstance()->getRoom($this->roomID); - if (isset($_GET['messageid'])) $this->messageID = intval($_GET['messageid']); - if ($this->messageID) { - $this->message = new \chat\data\message\Message($this->messageID); - if (!$this->message->getMessageType()->getProcessor()->canSeeInLog($this->message, $this->room)) { - throw new PermissionDeniedException(); - } - } + if ($this->room === null) { + throw new IllegalLinkException(); + } + if (!$this->room->canSee($user = null, $reason)) { + throw $reason; + } + if (!$this->room->canSeeLog($user = null, $reason)) { + throw $reason; + } - if (isset($_REQUEST['datetime'])) $this->datetime = strtotime($_REQUEST['datetime']); - } + if (isset($_GET['messageid'])) { + $this->messageID = \intval($_GET['messageid']); + } + if ($this->messageID) { + $this->message = new Message($this->messageID); + if (!$this->message->getMessageType()->getProcessor()->canSeeInLog($this->message, $this->room)) { + throw new PermissionDeniedException(); + } + } - /** - * @inheritDoc - */ - public function readData() { - parent::readData(); + if (isset($_REQUEST['datetime'])) { + $this->datetime = \strtotime($_REQUEST['datetime']); + } + } - if ($this->datetime) { - // Determine message types supporting fast select - $objectTypes = \wcf\data\object\type\ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType'); - $fastSelect = array_map(function ($item) { - return $item->objectTypeID; - }, array_filter($objectTypes, function ($item) { - // TODO: Consider a method couldAppearInLog(): bool - return $item->getProcessor()->supportsFastSelect(); - })); + /** + * @inheritDoc + */ + public function readData() + { + parent::readData(); - $minimum = 0; - $loops = 0; - do { - // Build fast select filter - $condition = new \wcf\system\database\util\PreparedStatementConditionBuilder(); - $condition->add('((roomID = ? AND objectTypeID IN (?)) OR objectTypeID NOT IN (?))', [ $this->room->roomID, $fastSelect, $fastSelect ]); - $condition->add('time >= ?', [ $this->datetime ]); - if ($minimum) { - $condition->add('messageID > ?', [ $minimum ]); - } + if ($this->datetime) { + // Determine message types supporting fast select + $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType'); + $fastSelect = \array_map(static function ($item) { + return $item->objectTypeID; + }, \array_filter($objectTypes, static function ($item) { + // TODO: Consider a method couldAppearInLog(): bool + return $item->getProcessor()->supportsFastSelect(); + })); - $sql = "SELECT messageID - FROM chat1_message - ".$condition." - ORDER BY messageID ASC"; - $statement = WCF::getDB()->prepare($sql, 20); - $statement->execute($condition->getParameters()); - $messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); + $minimum = 0; + $loops = 0; + do { + // Build fast select filter + $condition = new PreparedStatementConditionBuilder(); + $condition->add('((roomID = ? AND objectTypeID IN (?)) OR objectTypeID NOT IN (?))', [ $this->room->roomID, $fastSelect, $fastSelect ]); + $condition->add('time >= ?', [ $this->datetime ]); + if ($minimum) { + $condition->add('messageID > ?', [ $minimum ]); + } - $objectList = new MessageList(); - $objectList->setObjectIDs($messageIDs); - $objectList->readObjects(); - $objects = $objectList->getObjects(); - if (empty($objects)) { - // TODO: UserInputException? - throw new IllegalLinkException(); - } + $sql = "SELECT messageID + FROM chat1_message + {$condition} + ORDER BY messageID ASC"; + $statement = WCF::getDB()->prepare($sql, 20); + $statement->execute($condition->getParameters()); + $messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); - foreach ($objects as $message) { - if ($message->getMessageType()->getProcessor()->canSeeInLog($message, $this->room)) { - $parameters = [ 'application' => 'chat' - , 'messageid' => $message->messageID - , 'object' => $this->room - ]; - \wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Log', $parameters)); - exit; - } - $minimum = $message->messageID; - } - } - while (++$loops <= 3); + $objectList = new MessageList(); + $objectList->setObjectIDs($messageIDs); + $objectList->readObjects(); + $objects = $objectList->getObjects(); + if (empty($objects)) { + // TODO: UserInputException? + throw new IllegalLinkException(); + } - // Do a best guess redirect to an ID that is as near as possible - $parameters = [ 'application' => 'chat' - , 'messageid' => $minimum - , 'object' => $this->room - ]; - \wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Log', $parameters)); - exit; - } - } + foreach ($objects as $message) { + if ($message->getMessageType()->getProcessor()->canSeeInLog($message, $this->room)) { + $parameters = [ + 'application' => 'chat', + 'messageid' => $message->messageID, + 'object' => $this->room, + ]; + HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Log', $parameters)); - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); + exit; + } + $minimum = $message->messageID; + } + } while (++$loops <= 3); - PageLocationManager::getInstance()->addParentLocation('be.bastelstu.chat.Room', $this->room->roomID, $this->room); - WCF::getTPL()->assign([ 'room' => $this->room - , 'roomList' => \chat\data\room\RoomCache::getInstance()->getRooms() - , 'messageID' => $this->messageID - , 'message' => $this->message - , 'config' => $this->getConfig() - ]); - } + // Do a best guess redirect to an ID that is as near as possible + $parameters = [ + 'application' => 'chat', + 'messageid' => $minimum, + 'object' => $this->room, + ]; + HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Log', $parameters)); + + exit; + } + } + + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); + + PageLocationManager::getInstance()->addParentLocation( + 'be.bastelstu.chat.Room', + $this->room->roomID, + $this->room + ); + WCF::getTPL()->assign([ + 'room' => $this->room, + 'roomList' => RoomCache::getInstance()->getRooms(), + 'messageID' => $this->messageID, + 'message' => $this->message, + 'config' => $this->getConfig(), + ]); + } } diff --git a/files/lib/page/RoomListPage.class.php b/files/lib/page/RoomListPage.class.php index 996f32d..4097f82 100644 --- a/files/lib/page/RoomListPage.class.php +++ b/files/lib/page/RoomListPage.class.php @@ -1,11 +1,12 @@ rooms = \chat\data\room\RoomCache::getInstance()->getRooms(); - } + $this->rooms = RoomCache::getInstance()->getRooms(); + } - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); - WCF::getTPL()->assign([ 'rooms' => $this->rooms ]); - } + WCF::getTPL()->assign([ + 'rooms' => $this->rooms, + ]); + } } diff --git a/files/lib/page/RoomPage.class.php b/files/lib/page/RoomPage.class.php index efc3828..34e2f8d 100644 --- a/files/lib/page/RoomPage.class.php +++ b/files/lib/page/RoomPage.class.php @@ -1,6 +1,7 @@ roomID = intval($_GET['id']); - $this->room = \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); + if (isset($_GET['id'])) { + $this->roomID = \intval($_GET['id']); + } + $this->room = RoomCache::getInstance()->getRoom($this->roomID); - if ($this->room === null) throw new IllegalLinkException(); - if (!$this->room->canSee($user = null, $reason)) throw $reason; - if (!$this->room->canJoin($user = null, $reason)) throw $reason; + if ($this->room === null) { + throw new IllegalLinkException(); + } + if (!$this->room->canSee($user = null, $reason)) { + throw $reason; + } + if (!$this->room->canJoin($user = null, $reason)) { + throw $reason; + } - $this->canonicalURL = $this->room->getLink(); - } + $this->canonicalURL = $this->room->getLink(); + } - /** - * @inheritDoc - */ - public function checkPermissions() { - parent::checkPermissions(); + /** + * @inheritDoc + */ + public function checkPermissions() + { + parent::checkPermissions(); - $package = \wcf\data\package\PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat'); - if (stripos($package->packageVersion, 'Alpha') !== false) { - $sql = "SELECT COUNT(*) FROM wcf1_user"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute(); - $userCount = $statement->fetchSingleColumn(); - if ((($userCount > 5 && !OFFLINE) || ($userCount > 30 && OFFLINE)) && sha1(WCF_UUID) !== '643a6b3af2a6ea3d393c4d8371e75d7d1b66e0d0') { - throw new PermissionDeniedException("Do not use alpha versions of Tims Chat in production communities!"); - } - } - } + $package = PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat'); + if (\stripos($package->packageVersion, 'Alpha') !== false) { + $sql = "SELECT COUNT(*) FROM wcf1_user"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute(); + $userCount = $statement->fetchSingleColumn(); + if ((($userCount > 5 && !OFFLINE) || ($userCount > 30 && OFFLINE)) && \sha1(WCF_UUID) !== '643a6b3af2a6ea3d393c4d8371e75d7d1b66e0d0') { + throw new PermissionDeniedException("Do not use alpha versions of Tims Chat in production communities!"); + } + } + } - /** - * @inheritDoc - */ - public function readData() { - $sql = "SELECT 1"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute(); - if ($statement->fetchSingleColumn() !== 1) { - throw new NamedUserException('PHP must be configured to use the MySQLnd driver, instead of libmysqlclient.'); - } + /** + * @inheritDoc + */ + public function readData() + { + $sql = "SELECT 1"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute(); + if ($statement->fetchSingleColumn() !== 1) { + throw new NamedUserException('PHP must be configured to use the MySQLnd driver, instead of libmysqlclient.'); + } - parent::readData(); + parent::readData(); - // This attachment handler gets only used for the language variable `wcf.attachment.upload.limits`! - $this->attachmentHandler = new \wcf\system\attachment\AttachmentHandler('be.bastelstu.chat.message', 0, 'DEADC0DE00000000DEADC0DE00000000DEADC0DE', $this->room->roomID); + // This attachment handler gets only used for the language variable `wcf.attachment.upload.limits`! + $this->attachmentHandler = new AttachmentHandler( + 'be.bastelstu.chat.message', + 0, + 'DEADC0DE00000000DEADC0DE00000000DEADC0DE', + $this->room->roomID + ); - $pushHandler = \wcf\system\push\PushHandler::getInstance(); - $pushHandler->joinChannel('be.bastelstu.chat'); - $pushHandler->joinChannel('be.bastelstu.chat.room-'.$this->room->roomID); - } + $pushHandler = PushHandler::getInstance(); + $pushHandler->joinChannel('be.bastelstu.chat'); + $pushHandler->joinChannel('be.bastelstu.chat.room-' . $this->room->roomID); + } - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); - WCF::getTPL()->assign([ 'room' => $this->room - , 'config' => $this->getConfig() - , 'attachmentHandler' => $this->attachmentHandler - ]); - } + WCF::getTPL()->assign([ + 'room' => $this->room, + 'config' => $this->getConfig(), + 'attachmentHandler' => $this->attachmentHandler, + ]); + } } diff --git a/files/lib/page/TConfiguredPage.class.php b/files/lib/page/TConfiguredPage.class.php index 3e10a1a..d50f37e 100644 --- a/files/lib/page/TConfiguredPage.class.php +++ b/files/lib/page/TConfiguredPage.class.php @@ -1,11 +1,12 @@ getTriggers(); +trait TConfiguredPage +{ + /** + * Returns the configuration for the chat's JavaScript. + */ + public function getConfig() + { + $triggers = CommandCache::getInstance()->getTriggers(); - $commands = array_map(function (Command $item) { - $package = PackageCache::getInstance()->getPackage($item->packageID)->package; - return [ 'package' => $package - , 'identifier' => $item->identifier - , 'commandID' => $item->commandID - , 'module' => $item->getProcessor()->getJavaScriptModuleName() - , 'isAvailable' => $item->getProcessor()->isAvailable($this->room) && ($item->hasTriggers() || $item->getProcessor()->allowWithoutTrigger()) - ]; - }, CommandCache::getInstance()->getCommands()); + $commands = \array_map(function (Command $item) { + $package = PackageCache::getInstance()->getPackage($item->packageID)->package; - $messageTypes = array_map(function ($item) { - return [ 'module' => $item->getProcessor()->getJavaScriptModuleName() - ]; - }, ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType')); + return [ + 'package' => $package, + 'identifier' => $item->identifier, + 'commandID' => $item->commandID, + 'module' => $item->getProcessor()->getJavaScriptModuleName(), + 'isAvailable' => $item->getProcessor()->isAvailable($this->room) && ($item->hasTriggers() || $item->getProcessor()->allowWithoutTrigger()), + ]; + }, CommandCache::getInstance()->getCommands()); - $config = [ 'clientVersion' => 1 - , 'reloadTime' => (int) CHAT_RELOADTIME - , 'autoAwayTime' => (int) CHAT_AUTOAWAYTIME - , 'commands' => $commands - , 'triggers' => $triggers - , 'messageTypes' => $messageTypes - ]; + $messageTypes = \array_map(static function ($item) { + return [ + 'module' => $item->getProcessor()->getJavaScriptModuleName(), + ]; + }, ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType')); - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'config', $config); - - return \wcf\util\JSON::encode($config); - } + $config = [ + 'clientVersion' => 1, + 'reloadTime' => (int)CHAT_RELOADTIME, + 'autoAwayTime' => (int)CHAT_AUTOAWAYTIME, + 'commands' => $commands, + 'triggers' => $triggers, + 'messageTypes' => $messageTypes, + ]; + + EventHandler::getInstance()->fireAction($this, 'config', $config); + + return JSON::encode($config); + } } diff --git a/files/lib/system/CHATCore.class.php b/files/lib/system/CHATCore.class.php index 274f8a6..db2a27b 100644 --- a/files/lib/system/CHATCore.class.php +++ b/files/lib/system/CHATCore.class.php @@ -1,11 +1,12 @@ setStaticController('chat', 'Log'); - $route->setBuildSchema('/{controller}/{id}-{title}/{messageid}'); - $route->setPattern('~^/?(?P[^/]+)/(?P\d+)(?:-(?P[^/]+))?/(?P<messageid>\d+)~x'); - $route->setRequiredComponents([ 'id' => '~^\d+$~' - , 'messageid' => '~^\d+$~' - ]); - $route->setMatchController(true); +class CHATCore extends AbstractApplication +{ + /** + * @inheritDoc + */ + protected $primaryController = RoomListPage::class; - \wcf\system\request\RouteHandler::getInstance()->addRoute($route); - } + /** + * @inheritDoc + */ + public function __run() + { + $route = new StaticRequestRoute(); + $route->setStaticController('chat', 'Log'); + $route->setBuildSchema('/{controller}/{id}-{title}/{messageid}'); + $route->setPattern('~^/?(?P<controller>[^/]+)/(?P<id>\d+)(?:-(?P<title>[^/]+))?/(?P<messageid>\d+)~x'); + $route->setRequiredComponents([ + 'id' => '~^\d+$~', + 'messageid' => '~^\d+$~', + ]); + $route->setMatchController(true); + + RouteHandler::getInstance()->addRoute($route); + } } diff --git a/files/lib/system/attachment/MessageAttachmentObjectType.class.php b/files/lib/system/attachment/MessageAttachmentObjectType.class.php index 8cd6fbc..99212d4 100644 --- a/files/lib/system/attachment/MessageAttachmentObjectType.class.php +++ b/files/lib/system/attachment/MessageAttachmentObjectType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,95 +15,108 @@ namespace chat\system\attachment; -use \chat\data\message\Message; -use \chat\data\message\MessageList; -use \chat\data\room\RoomCache; -use \wcf\system\WCF; +use chat\data\message\Message; +use chat\data\message\MessageList; +use chat\data\room\RoomCache; +use wcf\system\attachment\AbstractAttachmentObjectType; +use wcf\system\WCF; +use wcf\util\ArrayUtil; /** * Attachment object type implementation for messages. */ -class MessageAttachmentObjectType extends \wcf\system\attachment\AbstractAttachmentObjectType { - /** - * @inheritDoc - */ - public function canDownload($objectID) { - if ($objectID) { - $message = new Message($objectID); +class MessageAttachmentObjectType extends AbstractAttachmentObjectType +{ + /** + * @inheritDoc + */ + public function canDownload($objectID) + { + if ($objectID) { + $message = new Message($objectID); - if ($message->getMessageType()->objectType !== 'be.bastelstu.chat.messageType.attachment') { - throw new \LogicException('Unreachable'); - } - $room = $message->getRoom(); + if ($message->getMessageType()->objectType !== 'be.bastelstu.chat.messageType.attachment') { + throw new \LogicException('Unreachable'); + } + $room = $message->getRoom(); - return $room->canSee(); - } + return $room->canSee(); + } - return false; - } + return false; + } - /** - * @inheritDoc - */ - public function canUpload($objectID, $parentObjectID = 0) { - if ($objectID) { - return false; - } + /** + * @inheritDoc + */ + public function canUpload($objectID, $parentObjectID = 0) + { + if ($objectID) { + return false; + } - if (!WCF::getSession()->getPermission('user.chat.canAttach')) { - return false; - } + if (!WCF::getSession()->getPermission('user.chat.canAttach')) { + return false; + } - $room = null; - if ($parentObjectID) { - $room = RoomCache::getInstance()->getRoom($parentObjectID); - } + $room = null; + if ($parentObjectID) { + $room = RoomCache::getInstance()->getRoom($parentObjectID); + } - if ($room !== null) { - return $room->canSee(); - } + if ($room !== null) { + return $room->canSee(); + } - return false; - } + return false; + } - /** - * @inheritDoc - */ - public function canDelete($objectID) { - return false; - } + /** + * @inheritDoc + */ + public function canDelete($objectID) + { + return false; + } - /** - * @inheritDoc - */ - public function getMaxCount() { - return 1; - } + /** + * @inheritDoc + */ + public function getMaxCount() + { + return 1; + } - /** - * @inheritDoc - */ - public function getMaxSize() { - return WCF::getSession()->getPermission('user.chat.attachment.maxSize'); - } + /** + * @inheritDoc + */ + public function getMaxSize() + { + return WCF::getSession()->getPermission('user.chat.attachment.maxSize'); + } - /** - * @inheritDoc - */ - public function getAllowedExtensions() { - return \wcf\util\ArrayUtil::trim(\explode("\n", WCF::getSession()->getPermission('user.chat.attachment.allowedExtensions'))); - } + /** + * @inheritDoc + */ + public function getAllowedExtensions() + { + return ArrayUtil::trim(\explode( + "\n", + WCF::getSession()->getPermission('user.chat.attachment.allowedExtensions') + )); + } - /** - * @inheritDoc - */ - public function cacheObjects(array $objectIDs) { - $messageList = new MessageList(); - $messageList->setObjectIDs($objectIDs); - $messageList->readObjects(); + /** + * @inheritDoc + */ + public function cacheObjects(array $objectIDs) + { + $messageList = new MessageList(); + $messageList->setObjectIDs($objectIDs); + $messageList->readObjects(); - foreach ($messageList->getObjects() as $objectID => $object) { - $this->cachedObjects[$objectID] = $object; - } - } + foreach ($messageList->getObjects() as $objectID => $object) { + $this->cachedObjects[$objectID] = $object; + } + } } diff --git a/files/lib/system/box/RoomListBoxController.class.php b/files/lib/system/box/RoomListBoxController.class.php index e94e575..3967c94 100644 --- a/files/lib/system/box/RoomListBoxController.class.php +++ b/files/lib/system/box/RoomListBoxController.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,107 +15,130 @@ namespace chat\system\box; -use \wcf\system\request\RequestHandler; -use \wcf\system\WCF; +use chat\data\room\Room; +use chat\data\room\RoomList; +use chat\page\RoomPage; +use wcf\system\box\AbstractDatabaseObjectListBoxController; +use wcf\system\request\LinkHandler; +use wcf\system\request\RequestHandler; +use wcf\system\WCF; /** * Dynamic box controller implementation for a list of rooms. */ -class RoomListBoxController extends \wcf\system\box\AbstractDatabaseObjectListBoxController { - /** - * @inheritDoc - */ - protected static $supportedPositions = [ 'contentBottom', 'contentTop', 'sidebarLeft', 'sidebarRight' ]; +class RoomListBoxController extends AbstractDatabaseObjectListBoxController +{ + /** + * @inheritDoc + */ + protected static $supportedPositions = [ + 'contentBottom', + 'contentTop', + 'sidebarLeft', + 'sidebarRight', + ]; - /** - * @inheritDoc - */ - protected $conditionDefinition = 'be.bastelstu.chat.box.roomList.condition'; + /** + * @inheritDoc + */ + protected $conditionDefinition = 'be.bastelstu.chat.box.roomList.condition'; - /** - * @var int - */ - protected $activeRoomID = null; + /** + * @var int + */ + protected $activeRoomID; - /** - * @inheritDoc - */ - public function __construct() { - parent::__construct(); + /** + * @inheritDoc + */ + public function __construct() + { + parent::__construct(); - $activeRequest = RequestHandler::getInstance()->getActiveRequest(); - if ($activeRequest && $activeRequest->getRequestObject() instanceof \chat\page\RoomPage) { - $this->activeRoomID = $activeRequest->getRequestObject()->room->roomID; - } - } + $activeRequest = RequestHandler::getInstance()->getActiveRequest(); + if ($activeRequest && $activeRequest->getRequestObject() instanceof RoomPage) { + $this->activeRoomID = $activeRequest->getRequestObject()->room->roomID; + } + } - /** - * Sets the active room ID. - */ - public function setActiveRoomID($activeRoomID) { - $this->activeRoomID = $activeRoomID; - } + /** + * Sets the active room ID. + */ + public function setActiveRoomID($activeRoomID) + { + $this->activeRoomID = $activeRoomID; + } - /** - * Returns the active room ID. - * - * @return int - */ - public function getActiveRoomID() { - return $this->activeRoomID; - } + /** + * Returns the active room ID. + * + * @return int + */ + public function getActiveRoomID() + { + return $this->activeRoomID; + } - /** - * @inheritDoc - */ - public function hasLink() { - return true; - } + /** + * @inheritDoc + */ + public function hasLink() + { + return true; + } - /** - * @inheritDoc - */ - public function getLink() { - return \wcf\system\request\LinkHandler::getInstance()->getLink('RoomList', [ 'application' => 'chat' ]); - } + /** + * @inheritDoc + */ + public function getLink() + { + return LinkHandler::getInstance()->getLink('RoomList', [ + 'application' => 'chat', + ]); + } - /** - * @inheritDoc - */ - protected function getObjectList() { - return new \chat\data\room\RoomList(); - } + /** + * @inheritDoc + */ + protected function getObjectList() + { + return new RoomList(); + } - /** - * @inheritDoc - */ - protected function getTemplate() { - $templateName = 'boxRoomList'; - if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') { - $templateName = 'boxRoomListSidebar'; - } + /** + * @inheritDoc + */ + protected function getTemplate() + { + $templateName = 'boxRoomList'; + if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') { + $templateName = 'boxRoomListSidebar'; + } - return WCF::getTPL()->fetch($templateName, 'chat', [ 'boxRoomList' => $this->objectList - , 'boxID' => $this->getBox()->boxID - , 'activeRoomID' => $this->activeRoomID ?: 0 - ], true); - } + return WCF::getTPL()->fetch($templateName, 'chat', [ + 'boxRoomList' => $this->objectList, + 'boxID' => $this->getBox()->boxID, + 'activeRoomID' => $this->activeRoomID ?: 0, + ], true); + } - /** - * @inheritDoc - */ - public function hasContent() { - if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') { - parent::hasContent(); + /** + * @inheritDoc + */ + public function hasContent() + { + if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') { + parent::hasContent(); - foreach ($this->objectList as $room) { - if ($room->canSee()) return true; - } + foreach ($this->objectList as $room) { + if ($room->canSee()) { + return true; + } + } - return false; - } - else { - return \chat\data\room\Room::canSeeAny(); - } - } + return false; + } else { + return Room::canSeeAny(); + } + } } diff --git a/files/lib/system/cache/builder/CommandCacheBuilder.class.php b/files/lib/system/cache/builder/CommandCacheBuilder.class.php index eb07a26..7d03ff8 100644 --- a/files/lib/system/cache/builder/CommandCacheBuilder.class.php +++ b/files/lib/system/cache/builder/CommandCacheBuilder.class.php @@ -1,6 +1,7 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. @@ -14,39 +15,46 @@ namespace chat\system\cache\builder; -use \wcf\system\WCF; +use chat\data\command\CommandList; +use wcf\system\cache\builder\AbstractCacheBuilder; +use wcf\system\WCF; /** * Caches all chat commands. */ -class CommandCacheBuilder extends \wcf\system\cache\builder\AbstractCacheBuilder { - /** - * @see \wcf\system\cache\AbstractCacheBuilder::rebuild() - */ - public function rebuild(array $parameters) { - $data = [ 'commands' => [ ] - , 'triggers' => [ ] - , 'packages' => [ ] - ]; +class CommandCacheBuilder extends AbstractCacheBuilder +{ + /** + * @inheritDoc + */ + public function rebuild(array $parameters) + { + $data = [ + 'commands' => [ ], + 'triggers' => [ ], + 'packages' => [ ], + ]; - $commandList = new \chat\data\command\CommandList(); - $commandList->sqlOrderBy = 'command.commandID'; - $commandList->readObjects(); + $commandList = new CommandList(); + $commandList->sqlOrderBy = 'command.commandID'; + $commandList->readObjects(); - $data['commands'] = $commandList->getObjects(); + $data['commands'] = $commandList->getObjects(); - foreach ($data['commands'] as $command) { - if (!isset($data['packages'][$command->packageID])) $data['packages'][$command->packageID] = [ ]; - $data['packages'][$command->packageID][$command->identifier] = $command; - } + foreach ($data['commands'] as $command) { + if (!isset($data['packages'][$command->packageID])) { + $data['packages'][$command->packageID] = [ ]; + } + $data['packages'][$command->packageID][$command->identifier] = $command; + } - $sql = "SELECT * - FROM chat1_command_trigger"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute(); + $sql = "SELECT * + FROM chat1_command_trigger"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute(); - $data['triggers'] = $statement->fetchMap('commandTrigger', 'commandID'); + $data['triggers'] = $statement->fetchMap('commandTrigger', 'commandID'); - return $data; - } + return $data; + } } diff --git a/files/lib/system/cache/builder/PermissionCacheBuilder.class.php b/files/lib/system/cache/builder/PermissionCacheBuilder.class.php index 5866328..15ebb55 100644 --- a/files/lib/system/cache/builder/PermissionCacheBuilder.class.php +++ b/files/lib/system/cache/builder/PermissionCacheBuilder.class.php @@ -1,7 +1,8 @@ <?php + /** - * Copyright (C) 2010-2021 Tim Düsterhus - * Copyright (C) 2010-2021 Woltlab GmbH + * Copyright (C) 2010-2022 Tim Düsterhus + * Copyright (C) 2010-2022 Woltlab GmbH * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,42 +21,45 @@ namespace chat\system\cache\builder; -use \wcf\system\acl\ACLHandler; -use \wcf\system\WCF; +use wcf\system\acl\ACLHandler; +use wcf\system\cache\builder\AbstractCacheBuilder; +use wcf\system\database\util\PreparedStatementConditionBuilder; +use wcf\system\WCF; /** * Caches the chat permissions for a combination of user groups. */ -class PermissionCacheBuilder extends \wcf\system\cache\builder\AbstractCacheBuilder { - /** - * @inheritDoc - */ - public function rebuild(array $parameters) { - $data = [ ]; +class PermissionCacheBuilder extends AbstractCacheBuilder +{ + /** + * @inheritDoc + */ + public function rebuild(array $parameters) + { + $data = [ ]; - if (!empty($parameters)) { - $conditionBuilder = new \wcf\system\database\util\PreparedStatementConditionBuilder(); - $conditionBuilder->add('acl_option.objectTypeID = ?', [ ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room') ]); - $conditionBuilder->add('option_to_group.groupID IN (?)', [ $parameters ]); - $sql = "SELECT option_to_group.objectID AS roomID, - option_to_group.optionValue, - acl_option.optionName AS permission - FROM wcf1_acl_option acl_option - INNER JOIN wcf1_acl_option_to_group option_to_group - ON option_to_group.optionID = acl_option.optionID - ".$conditionBuilder; - $statement = WCF::getDB()->prepare($sql); - $statement->execute($conditionBuilder->getParameters()); - while (($row = $statement->fetchArray())) { - if (!isset($data[$row['roomID']][$row['permission']])) { - $data[$row['roomID']][$row['permission']] = $row['optionValue']; - } - else { - $data[$row['roomID']][$row['permission']] = $row['optionValue'] || $data[$row['roomID']][$row['permission']]; - } - } - } + if (!empty($parameters)) { + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('acl_option.objectTypeID = ?', [ ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room') ]); + $conditionBuilder->add('option_to_group.groupID IN (?)', [ $parameters ]); + $sql = "SELECT option_to_group.objectID AS roomID, + option_to_group.optionValue, + acl_option.optionName AS permission + FROM wcf1_acl_option acl_option + INNER JOIN wcf1_acl_option_to_group option_to_group + ON option_to_group.optionID = acl_option.optionID + {$conditionBuilder}"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute($conditionBuilder->getParameters()); + while (($row = $statement->fetchArray())) { + if (!isset($data[$row['roomID']][$row['permission']])) { + $data[$row['roomID']][$row['permission']] = $row['optionValue']; + } else { + $data[$row['roomID']][$row['permission']] = $row['optionValue'] || $data[$row['roomID']][$row['permission']]; + } + } + } - return $data; - } + return $data; + } } diff --git a/files/lib/system/cache/builder/RoomCacheBuilder.class.php b/files/lib/system/cache/builder/RoomCacheBuilder.class.php index 4384c6f..c33f03b 100644 --- a/files/lib/system/cache/builder/RoomCacheBuilder.class.php +++ b/files/lib/system/cache/builder/RoomCacheBuilder.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,18 +15,23 @@ namespace chat\system\cache\builder; +use chat\data\room\RoomList; +use wcf\system\cache\builder\AbstractCacheBuilder; + /** * Caches all chat rooms. */ -class RoomCacheBuilder extends \wcf\system\cache\builder\AbstractCacheBuilder { - /** - * @inheritDoc - */ - public function rebuild(array $parameters) { - $roomList = new \chat\data\room\RoomList(); - $roomList->sqlOrderBy = "room.position"; - $roomList->readObjects(); +class RoomCacheBuilder extends AbstractCacheBuilder +{ + /** + * @inheritDoc + */ + public function rebuild(array $parameters) + { + $roomList = new RoomList(); + $roomList->sqlOrderBy = "room.position"; + $roomList->readObjects(); - return $roomList->getObjects(); - } + return $roomList->getObjects(); + } } diff --git a/files/lib/system/cache/runtime/UserRuntimeCache.class.php b/files/lib/system/cache/runtime/UserRuntimeCache.class.php index 267ae2b..7195778 100644 --- a/files/lib/system/cache/runtime/UserRuntimeCache.class.php +++ b/files/lib/system/cache/runtime/UserRuntimeCache.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,12 +15,16 @@ namespace chat\system\cache\runtime; +use chat\data\user\UserList as ChatUserList; +use wcf\system\cache\runtime\AbstractRuntimeCache; + /** * Runtime cache implementation for chat users. */ -class UserRuntimeCache extends \wcf\system\cache\runtime\AbstractRuntimeCache { - /** - * @inheritDoc - */ - protected $listClassName = \chat\data\user\UserList::class; +class UserRuntimeCache extends AbstractRuntimeCache +{ + /** + * @inheritDoc + */ + protected $listClassName = ChatUserList::class; } diff --git a/files/lib/system/command/AbstractCommand.class.php b/files/lib/system/command/AbstractCommand.class.php index 3682b49..6d467e4 100644 --- a/files/lib/system/command/AbstractCommand.class.php +++ b/files/lib/system/command/AbstractCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,64 +15,76 @@ namespace chat\system\command; -use \chat\data\room\Room; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\UserInputException; +use chat\data\command\Command; +use chat\data\room\Room; +use wcf\data\DatabaseObjectDecorator; +use wcf\data\IDatabaseObjectProcessor; +use wcf\data\object\type\ObjectTypeCache; +use wcf\data\user\UserProfile; +use wcf\system\exception\UserInputException; /** * Default implemention for command processors. */ -abstract class AbstractCommand extends \wcf\data\DatabaseObjectDecorator implements ICommand - , \wcf\data\IDatabaseObjectProcessor { - /** - * @inheritDoc - */ - protected static $baseClass = \chat\data\command\Command::class; +abstract class AbstractCommand extends DatabaseObjectDecorator implements + ICommand, + IDatabaseObjectProcessor +{ + /** + * @inheritDoc + */ + protected static $baseClass = Command::class; - /** - * @inheritDoc - */ - public function isAvailable(Room $room, UserProfile $user = null) { - return true; - } + /** + * @inheritDoc + */ + public function isAvailable(Room $room, ?UserProfile $user = null) + { + return true; + } - /** - * @inheritDoc - */ - public function allowWithoutTrigger() { - return false; - } + /** + * @inheritDoc + */ + public function allowWithoutTrigger() + { + return false; + } - /** - * Returns the object type ID for the given message type. - * - * @param string - * @return int - */ - public function getMessageObjectTypeID($objectType) { - $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', $objectType); + /** + * Returns the object type ID for the given message type. + * + * @param string + * @return int + */ + public function getMessageObjectTypeID($objectType) + { + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.messageType', + $objectType + ); - if (!$objectType) { - throw new \LogicException('Missing object type'); - } + if (!$objectType) { + throw new \LogicException('Missing object type'); + } - return $objectTypeID; - } + return $objectTypeID; + } - /** - * Ensures that the given parameter exists in the parameter array and - * throws otherwise. - * - * @param array $parameters - * @param string $key - * @return mixed The value. - */ - public function assertParameter($parameters, $key) { - if (array_key_exists($key, $parameters)) { - return $parameters[$key]; - } + /** + * Ensures that the given parameter exists in the parameter array and + * throws otherwise. + * + * @param array $parameters + * @param string $key + * @return mixed The value. + */ + public function assertParameter($parameters, $key) + { + if (\array_key_exists($key, $parameters)) { + return $parameters[$key]; + } - throw new UserInputException('message'); - } + throw new UserInputException('message'); + } } diff --git a/files/lib/system/command/AbstractInputProcessedCommand.class.php b/files/lib/system/command/AbstractInputProcessedCommand.class.php index cd582a1..eb18f9f 100644 --- a/files/lib/system/command/AbstractInputProcessedCommand.class.php +++ b/files/lib/system/command/AbstractInputProcessedCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,71 +15,114 @@ namespace chat\system\command; -use \wcf\system\exception\UserInputException; -use \wcf\system\bbcode\BBCodeHandler; -use \wcf\system\message\censorship\Censorship; -use \wcf\system\WCF; +use wcf\data\DatabaseObject; +use wcf\system\bbcode\BBCodeHandler; +use wcf\system\exception\UserInputException; +use wcf\system\html\input\HtmlInputProcessor; +use wcf\system\message\censorship\Censorship; +use wcf\system\WCF; /** * Represents a command that processes the input using HtmlInputProcessor. */ -abstract class AbstractInputProcessedCommand extends AbstractCommand { - /** - * HtmlInputProcessor to use. - * @var \wcf\system\html\input\HtmlInputProcessor - */ - protected $processor = null; +abstract class AbstractInputProcessedCommand extends AbstractCommand +{ + /** + * HtmlInputProcessor to use. + * @var \wcf\system\html\input\HtmlInputProcessor + */ + protected $processor; - /** - * The text processed last. - * @var string - */ - private $text = null; + /** + * The text processed last. + * @var string + */ + private $text; - public function __construct(\wcf\data\DatabaseObject $object) { - parent::__construct($object); + public function __construct(DatabaseObject $object) + { + parent::__construct($object); - $this->processor = new \wcf\system\html\input\HtmlInputProcessor(); - $this->setDisallowedBBCodes(); - } + $this->processor = new HtmlInputProcessor(); + $this->setDisallowedBBCodes(); + } - private function setDisallowedBBCodes() { - BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(',', WCF::getSession()->getPermission('user.chat.disallowedBBCodes'))); - } + private function setDisallowedBBCodes() + { + BBCodeHandler::getInstance()->setDisallowedBBCodes(\explode( + ',', + WCF::getSession()->getPermission('user.chat.disallowedBBCodes') + )); + } - public function setText($text) { - if ($this->text === $text) return; + public function setText($text) + { + if ($this->text === $text) { + return; + } - $this->text = $text; - $this->setDisallowedBBCodes(); - $this->processor->process($text, 'be.bastelstu.chat.message', 0); - } + $this->text = $text; + $this->setDisallowedBBCodes(); + $this->processor->process( + $text, + 'be.bastelstu.chat.message', + 0 + ); + } - public function validateText() { - if ($this->processor->appearsToBeEmpty()) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.global.form.error.empty')); - } + public function validateText() + { + if ($this->processor->appearsToBeEmpty()) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable('wcf.global.form.error.empty') + ); + } - $message = $this->processor->getTextContent(); + $message = $this->processor->getTextContent(); - // validate message length - if (mb_strlen($message) > CHAT_MAX_LENGTH) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.tooLong', [ 'maxTextLength' => CHAT_MAX_LENGTH ])); - } + // validate message length + if (\mb_strlen($message) > CHAT_MAX_LENGTH) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'wcf.message.error.tooLong', + [ + 'maxTextLength' => CHAT_MAX_LENGTH, + ] + ) + ); + } - // search for disallowed bbcodes - $this->setDisallowedBBCodes(); - $disallowedBBCodes = $this->processor->validate(); - if (!empty($disallowedBBCodes)) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.disallowedBBCodes', [ 'disallowedBBCodes' => $disallowedBBCodes ])); - } + // search for disallowed bbcodes + $this->setDisallowedBBCodes(); + $disallowedBBCodes = $this->processor->validate(); + if (!empty($disallowedBBCodes)) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'wcf.message.error.disallowedBBCodes', + [ + 'disallowedBBCodes' => $disallowedBBCodes, + ] + ) + ); + } - // search for censored words - if (ENABLE_CENSORSHIP) { - $result = Censorship::getInstance()->test($message); - if ($result) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.censoredWordsFound', [ 'censoredWords' => $result ])); - } - } - } + // search for censored words + if (ENABLE_CENSORSHIP) { + $result = Censorship::getInstance()->test($message); + if ($result) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'wcf.message.error.censoredWordsFound', + [ + 'censoredWords' => $result, + ] + ) + ); + } + } + } } diff --git a/files/lib/system/command/AbstractSuspensionCommand.class.php b/files/lib/system/command/AbstractSuspensionCommand.class.php index 81da020..2e1549a 100644 --- a/files/lib/system/command/AbstractSuspensionCommand.class.php +++ b/files/lib/system/command/AbstractSuspensionCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,157 +15,192 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\room\Room; -use \chat\data\suspension\Suspension; -use \chat\data\suspension\SuspensionAction; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\UserInputException; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\room\Room; +use chat\data\suspension\Suspension; +use chat\data\suspension\SuspensionAction; +use chat\data\user\User as ChatUser; +use wcf\data\object\type\ObjectTypeCache; +use wcf\data\user\UserProfile; +use wcf\system\exception\UserInputException; +use wcf\system\WCF; /** * Represents a command that creates suspensions */ -abstract class AbstractSuspensionCommand extends AbstractCommand { - use TNeedsUser; +abstract class AbstractSuspensionCommand extends AbstractCommand +{ + use TNeedsUser; - /** - * Returns the name of the object type for this suspension. - * - * @return string - */ - abstract public function getObjectTypeName(); + /** + * Returns the name of the object type for this suspension. + * + * @return string + */ + abstract public function getObjectTypeName(); - /** - * Checks the permissions to execute this command. - * Throws if necessary. - * - * @see \chat\system\command\ICommand::validate() - */ - abstract protected function checkPermissions($parameters, Room $room, UserProfile $user); + /** + * Checks the permissions to execute this command. + * Throws if necessary. + * + * @see \chat\system\command\ICommand::validate() + */ + abstract protected function checkPermissions($parameters, Room $room, UserProfile $user); - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $this->assertParameter($parameters, 'username'); - $this->assertParameter($parameters, 'globally'); - $this->assertParameter($parameters, 'duration'); - $this->assertParameter($parameters, 'reason'); + $this->assertParameter($parameters, 'username'); + $this->assertParameter($parameters, 'globally'); + $this->assertParameter($parameters, 'duration'); + $this->assertParameter($parameters, 'reason'); - $this->assertUser($parameters['username']); - if ($parameters['duration'] !== null && $parameters['duration'] < TIME_NOW) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.datePast')); - } - if (!empty($parameters['reason']) && mb_strlen($parameters['reason']) > 100) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.tooLong', [ 'maxTextLength' => 250 ])); - } - $this->checkPermissions($parameters, $room, $user); + $this->assertUser($parameters['username']); + if ($parameters['duration'] !== null && $parameters['duration'] < TIME_NOW) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable('chat.error.datePast') + ); + } + if (!empty($parameters['reason']) && \mb_strlen($parameters['reason']) > 100) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'wcf.message.error.tooLong', + [ + 'maxTextLength' => 250, + ] + ) + ); + } + $this->checkPermissions($parameters, $room, $user); - $test = new Suspension(null, $this->getSuspensionData($parameters, $room, $user)); - if (!$test->isActive()) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.suspension.noEffect')); - } - } + $test = new Suspension(null, $this->getSuspensionData($parameters, $room, $user)); + if (!$test->isActive()) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable('chat.error.suspension.noEffect') + ); + } + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $data = $this->getSuspensionData($parameters, $room, $user); - $test = new Suspension(null, $data); - if (!$test->isActive()) { - return; - } + $data = $this->getSuspensionData($parameters, $room, $user); + $test = new Suspension(null, $data); + if (!$test->isActive()) { + return; + } - WCF::getDB()->beginTransaction(); - $suspension = (new SuspensionAction([ ], 'create', [ 'data' => $data ]))->executeAction()['returnValues']; + WCF::getDB()->beginTransaction(); + $suspension = (new SuspensionAction( + [ ], + 'create', + [ + 'data' => $data, + ] + ))->executeAction()['returnValues']; - $this->afterCreate($suspension, $parameters, $room, $user); - WCF::getDB()->commitTransaction(); - } + $this->afterCreate($suspension, $parameters, $room, $user); + WCF::getDB()->commitTransaction(); + } - /** - * Creates chat messages informing about the suspension. - * - * @param \chat\data\suspension\Suspension $suspension - * @param mixed[] $parameters - * @param \chat\data\room\Room $room - * @param \wcf\data\user\UserProfile $user - */ - protected function afterCreate(Suspension $suspension, $parameters, Room $room, UserProfile $user) { - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.suspend'); - $target = $suspension->getUser(); + /** + * Creates chat messages informing about the suspension. + * + * @param mixed[] $parameters + */ + protected function afterCreate(Suspension $suspension, $parameters, Room $room, UserProfile $user) + { + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.suspend'); + $target = $suspension->getUser(); - if ($suspension->getRoom() === null) { - $roomIDs = array_map(function (Room $room) use ($user) { - return $room->roomID; - }, (new \chat\data\user\User($target))->getRooms()); - $roomIDs[] = $room->roomID; - } - else { - $roomIDs = [ $suspension->getRoom()->roomID ]; - } + if ($suspension->getRoom() === null) { + $roomIDs = \array_map(static function (Room $room) { + return $room->roomID; + }, (new ChatUser($target))->getRooms()); + $roomIDs[] = $room->roomID; + } else { + $roomIDs = [ $suspension->getRoom()->roomID ]; + } - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'suspension' => $suspension - , 'roomIDs' => $roomIDs - , 'globally' => $this->isGlobally($parameters) - , 'target' => [ 'userID' => $target->userID - , 'username' => $target->username - ] - ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction(); - } + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'suspension' => $suspension, + 'roomIDs' => $roomIDs, + 'globally' => $this->isGlobally($parameters), + 'target' => [ + 'userID' => $target->userID, + 'username' => $target->username, + ], + ]), + ], + 'updateTimestamp' => true, + ] + ))->executeAction(); + } - /** - * Returns the database fields. - * - * @param mixed[] $parameters - * @param \chat\data\room\Room $room - * @param \wcf\data\user\UserProfile $user - * @return mixed[] - */ - protected function getSuspensionData($parameters, Room $room, UserProfile $user = null) { - $target = $this->getUser($parameters['username']); - $globally = $this->isGlobally($parameters); - $expires = $parameters['duration']; - $reason = $parameters['reason'] ?: ''; + /** + * Returns the database fields. + * + * @param mixed[] $parameters + * @return mixed[] + */ + protected function getSuspensionData($parameters, Room $room, ?UserProfile $user = null) + { + $target = $this->getUser($parameters['username']); + $globally = $this->isGlobally($parameters); + $expires = $parameters['duration']; + $reason = $parameters['reason'] ?: ''; - $roomID = $globally ? null : $room->roomID; - $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.suspension', $this->getObjectTypeName()); + $roomID = $globally ? null : $room->roomID; + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.suspension', + $this->getObjectTypeName() + ); - return [ 'time' => TIME_NOW - , 'expires' => $expires - , 'roomID' => $roomID - , 'userID' => $target->userID - , 'objectTypeID' => $objectTypeID - , 'reason' => $reason - , 'judgeID' => $user->userID - , 'judge' => $user->username - ]; - } + return [ + 'time' => TIME_NOW, + 'expires' => $expires, + 'roomID' => $roomID, + 'userID' => $target->userID, + 'objectTypeID' => $objectTypeID, + 'reason' => $reason, + 'judgeID' => $user->userID, + 'judge' => $user->username, + ]; + } - /** - * Returns whether a global suspension was requested. - * - * @param mixed[] $parameters - * @return boolean - */ - protected function isGlobally($parameters) { - return $parameters['globally'] === true; - } + /** + * Returns whether a global suspension was requested. + * + * @param mixed[] $parameters + * @return boolean + */ + protected function isGlobally($parameters) + { + return $parameters['globally'] === true; + } } diff --git a/files/lib/system/command/AbstractUnsuspensionCommand.class.php b/files/lib/system/command/AbstractUnsuspensionCommand.class.php index eeb1fea..7b83bed 100644 --- a/files/lib/system/command/AbstractUnsuspensionCommand.class.php +++ b/files/lib/system/command/AbstractUnsuspensionCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,149 +15,172 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\room\Room; -use \chat\data\suspension\Suspension; -use \chat\data\suspension\SuspensionAction; -use \chat\data\suspension\SuspensionList; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\UserInputException; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\room\Room; +use chat\data\suspension\Suspension; +use chat\data\suspension\SuspensionAction; +use chat\data\suspension\SuspensionList; +use chat\data\user\User as ChatUser; +use wcf\data\object\type\ObjectTypeCache; +use wcf\data\user\UserProfile; +use wcf\system\exception\UserInputException; +use wcf\system\WCF; /** * Represents a command that revokes suspensions */ -abstract class AbstractUnsuspensionCommand extends AbstractCommand { - use TNeedsUser; +abstract class AbstractUnsuspensionCommand extends AbstractCommand +{ + use TNeedsUser; - /** - * Returns the name of the object type for this suspension. - * - * @return string - */ - abstract public function getObjectTypeName(); + /** + * Returns the name of the object type for this suspension. + * + * @return string + */ + abstract public function getObjectTypeName(); - /** - * Checks the permissions to execute this command. - * Throws if necessary. - * - * @see \chat\system\command\ICommand::validate() - */ - abstract protected function checkPermissions($parameters, Room $room, UserProfile $user); + /** + * Checks the permissions to execute this command. + * Throws if necessary. + * + * @see \chat\system\command\ICommand::validate() + */ + abstract protected function checkPermissions($parameters, Room $room, UserProfile $user); - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $this->assertParameter($parameters, 'username'); - $this->assertParameter($parameters, 'globally'); + $this->assertParameter($parameters, 'username'); + $this->assertParameter($parameters, 'globally'); - $this->assertUser($parameters['username']); + $this->assertUser($parameters['username']); - $suspensions = $this->getSuspensionData($parameters, $room, $user); - if (empty($suspensions)) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.suspension.remove.empty')); - } - } + $suspensions = $this->getSuspensionData($parameters, $room, $user); + if (empty($suspensions)) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable('chat.error.suspension.remove.empty') + ); + } + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $suspensions = $this->getSuspensionData($parameters, $room, $user); + $suspensions = $this->getSuspensionData($parameters, $room, $user); - WCF::getDB()->beginTransaction(); - (new SuspensionAction($suspensions, 'revoke', [ ]))->executeAction(); - $this->afterCreate($suspensions, $parameters, $room, $user); - WCF::getDB()->commitTransaction(); - } + WCF::getDB()->beginTransaction(); + (new SuspensionAction( + $suspensions, + 'revoke', + [ ] + ))->executeAction(); + $this->afterCreate($suspensions, $parameters, $room, $user); + WCF::getDB()->commitTransaction(); + } - /** - * Creates chat messages informing about the removed suspensions. - * - * @param \chat\data\suspension\Suspension[] $suspension - * @param mixed[] $parameters - * @param \chat\data\room\Room $room - * @param \wcf\data\user\UserProfile $user - */ - protected function afterCreate($suspensions, $parameters, Room $room, UserProfile $user) { - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.unsuspend'); - $target = $this->getUser($parameters['username']); - if ($this->isGlobally($parameters)) { - $roomIDs = array_map(function (Room $room) use ($user) { - return $room->roomID; - }, (new \chat\data\user\User($target))->getRooms()); - $roomIDs[] = $room->roomID; - } - else { - $roomIDs = [ $room->roomID ]; - } + /** + * Creates chat messages informing about the removed suspensions. + * + * @param \chat\data\suspension\Suspension[] $suspension + * @param mixed[] $parameters + */ + protected function afterCreate($suspensions, $parameters, Room $room, UserProfile $user) + { + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.unsuspend'); + $target = $this->getUser($parameters['username']); + if ($this->isGlobally($parameters)) { + $roomIDs = \array_map(static function (Room $room) { + return $room->roomID; + }, (new ChatUser($target))->getRooms()); + $roomIDs[] = $room->roomID; + } else { + $roomIDs = [ + $room->roomID, + ]; + } - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'objectType' => $this->getObjectTypeName() - , 'roomIDs' => $roomIDs - , 'globally' => $this->isGlobally($parameters) - , 'target' => [ 'userID' => $target->userID - , 'username' => $target->username - ] - ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction(); - } + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'objectType' => $this->getObjectTypeName(), + 'roomIDs' => $roomIDs, + 'globally' => $this->isGlobally($parameters), + 'target' => [ + 'userID' => $target->userID, + 'username' => $target->username, + ], + ]), + ], + 'updateTimestamp' => true, + ] + ))->executeAction(); + } - /** - * Returns the active suspensions. - * - * @param mixed[] $parameters - * @param \chat\data\room\Room $room - * @param \wcf\data\user\UserProfile $user - * @return mixed[] - */ - protected function getSuspensionData($parameters, Room $room, UserProfile $user = null) { - $target = $this->getUser($parameters['username']); + /** + * Returns the active suspensions. + * + * @param mixed[] $parameters + * @return mixed[] + */ + protected function getSuspensionData($parameters, Room $room, ?UserProfile $user = null) + { + $target = $this->getUser($parameters['username']); - $roomID = $this->isGlobally($parameters) ? null : $room->roomID; - $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.suspension', $this->getObjectTypeName()); + $roomID = $this->isGlobally($parameters) ? null : $room->roomID; + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.suspension', + $this->getObjectTypeName() + ); - $suspensionList = new SuspensionList(); + $suspensionList = new SuspensionList(); - $suspensionList->getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]); - $suspensionList->getConditionBuilder()->add('revoked IS NULL'); - $suspensionList->getConditionBuilder()->add('userID = ?', [ $target->userID ]); - $suspensionList->getConditionBuilder()->add('objectTypeID = ?', [ $objectTypeID ]); - if ($roomID === null) { - $suspensionList->getConditionBuilder()->add('roomID IS NULL'); - } - else { - $suspensionList->getConditionBuilder()->add('roomID = ?', [ $room->roomID ]); - } + $suspensionList->getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]); + $suspensionList->getConditionBuilder()->add('revoked IS NULL'); + $suspensionList->getConditionBuilder()->add('userID = ?', [ $target->userID ]); + $suspensionList->getConditionBuilder()->add('objectTypeID = ?', [ $objectTypeID ]); + if ($roomID === null) { + $suspensionList->getConditionBuilder()->add('roomID IS NULL'); + } else { + $suspensionList->getConditionBuilder()->add('roomID = ?', [ $room->roomID ]); + } - $suspensionList->readObjects(); + $suspensionList->readObjects(); - return array_filter($suspensionList->getObjects(), function (Suspension $suspension) { - return $suspension->isActive(); - }); - } + return \array_filter($suspensionList->getObjects(), static function (Suspension $suspension) { + return $suspension->isActive(); + }); + } - /** - * Returns whether a global suspension removal was requested. - * - * @param mixed[] $parameters - * @return boolean - */ - protected function isGlobally($parameters) { - return $parameters['globally'] === true; - } + /** + * Returns whether a global suspension removal was requested. + * + * @param mixed[] $parameters + * @return boolean + */ + protected function isGlobally($parameters) + { + return $parameters['globally'] === true; + } } diff --git a/files/lib/system/command/AwayCommand.class.php b/files/lib/system/command/AwayCommand.class.php index c3c6f16..c81949b 100644 --- a/files/lib/system/command/AwayCommand.class.php +++ b/files/lib/system/command/AwayCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,74 +15,99 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\exception\UserInputException; -use \wcf\system\message\censorship\Censorship; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\room\Room; +use chat\data\user\User as ChatUser; +use wcf\data\user\UserEditor; +use wcf\data\user\UserProfile; +use wcf\system\exception\UserInputException; +use wcf\system\message\censorship\Censorship; +use wcf\system\WCF; /** * The away command marks the user as being away. */ -class AwayCommand extends AbstractCommand implements ICommand { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Away'; - } +class AwayCommand extends AbstractCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Away'; + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $reason = $this->assertParameter($parameters, 'reason'); + $reason = $this->assertParameter($parameters, 'reason'); - // search for censored words - if (ENABLE_CENSORSHIP) { - $result = Censorship::getInstance()->test($reason); - if ($result) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.censoredWordsFound', [ 'censoredWords' => $result ])); - } - } - } + // search for censored words + if (ENABLE_CENSORSHIP) { + $result = Censorship::getInstance()->test($reason); + if ($result) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'wcf.message.error.censoredWordsFound', + [ + 'censoredWords' => $result, + ] + ) + ); + } + } + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $reason = $this->assertParameter($parameters, 'reason'); + $reason = $this->assertParameter($parameters, 'reason'); - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.away'); - $rooms = array_map(function (Room $room) use ($user) { - return [ 'roomID' => $room->roomID - , 'isSilent' => !$room->canWritePublicly($user) - ]; - }, (new \chat\data\user\User($user->getDecoratedObject()))->getRooms()); + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.away'); + $rooms = \array_map(static function (Room $room) use ($user) { + return [ + 'roomID' => $room->roomID, + 'isSilent' => !$room->canWritePublicly($user), + ]; + }, (new ChatUser($user->getDecoratedObject()))->getRooms()); - WCF::getDB()->beginTransaction(); - $editor = new \wcf\data\user\UserEditor($user->getDecoratedObject()); - $editor->update([ 'chatAway' => $reason ]); + WCF::getDB()->beginTransaction(); + $editor = new UserEditor($user->getDecoratedObject()); + $editor->update([ + 'chatAway' => $reason, + ]); - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'message' => $reason - , 'rooms' => array_values($rooms) - ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction(); - WCF::getDB()->commitTransaction(); - } + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'message' => $reason, + 'rooms' => \array_values($rooms), + ]), + ], + 'updateTimestamp' => true, + ] + ))->executeAction(); + WCF::getDB()->commitTransaction(); + } } diff --git a/files/lib/system/command/BackCommand.class.php b/files/lib/system/command/BackCommand.class.php index 02c9671..1abd6e9 100644 --- a/files/lib/system/command/BackCommand.class.php +++ b/files/lib/system/command/BackCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,67 +15,89 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\room\Room; +use chat\data\user\User as ChatUser; +use wcf\data\user\UserEditor; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\WCF; /** * The back command marks the user as being back. */ -class BackCommand extends AbstractCommand implements ICommand { - /** - * @inheritDoc - */ - public function allowWithoutTrigger() { - return true; - } +class BackCommand extends AbstractCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function allowWithoutTrigger() + { + return true; + } - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Back'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Back'; + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - if ($user->chatAway === null) throw new PermissionDeniedException(); - } + if ($user->chatAway === null) { + throw new PermissionDeniedException(); + } + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.back'); - $rooms = array_map(function (Room $room) use ($user) { - return [ 'roomID' => $room->roomID - , 'isSilent' => !$room->canWritePublicly($user) - ]; - }, (new \chat\data\user\User($user->getDecoratedObject()))->getRooms()); + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.back'); + $rooms = \array_map(static function (Room $room) use ($user) { + return [ + 'roomID' => $room->roomID, + 'isSilent' => !$room->canWritePublicly($user), + ]; + }, (new ChatUser($user->getDecoratedObject()))->getRooms()); - WCF::getDB()->beginTransaction(); - $editor = new \wcf\data\user\UserEditor($user->getDecoratedObject()); - $editor->update([ 'chatAway' => null ]); + WCF::getDB()->beginTransaction(); + $editor = new UserEditor($user->getDecoratedObject()); + $editor->update([ + 'chatAway' => null, + ]); - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'rooms' => array_values($rooms) ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction(); - WCF::getDB()->commitTransaction(); - } + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'rooms' => \array_values($rooms), + ]), + ], + 'updateTimestamp' => true, + ] + ))->executeAction(); + WCF::getDB()->commitTransaction(); + } } diff --git a/files/lib/system/command/BanCommand.class.php b/files/lib/system/command/BanCommand.class.php index ab037c0..8d169ab 100644 --- a/files/lib/system/command/BanCommand.class.php +++ b/files/lib/system/command/BanCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,81 +15,98 @@ namespace chat\system\command; -use \chat\data\room\Room; -use \chat\data\suspension\Suspension; -use \chat\data\suspension\SuspensionAction; -use \chat\system\permission\PermissionHandler; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\room\Room; +use chat\data\room\RoomAction; +use chat\data\suspension\Suspension; +use chat\data\user\User as ChatUser; +use chat\system\permission\PermissionHandler; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\exception\UserInputException; +use wcf\system\WCF; /** * The ban command creates a new be.bastelstu.chat.suspension.ban suspension. */ -class BanCommand extends AbstractSuspensionCommand implements ICommand { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Ban'; - } +class BanCommand extends AbstractSuspensionCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Ban'; + } - /** - * @inheritDoc - */ - public function isAvailable(Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); - return $user->getPermission('mod.chat.canBan') || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); - } + /** + * @inheritDoc + */ + public function isAvailable(Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - /** - * @inheritDoc - */ - public function getObjectTypeName() { - return 'be.bastelstu.chat.suspension.ban'; - } + return $user->getPermission('mod.chat.canBan') || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); + } - /** - * @inheritDoc - */ - protected function checkPermissions($parameters, Room $room, UserProfile $user) { - $permission = $user->getPermission('mod.chat.canBan'); + /** + * @inheritDoc + */ + public function getObjectTypeName() + { + return 'be.bastelstu.chat.suspension.ban'; + } - if (!$this->isGlobally($parameters)) { - $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); - } + /** + * @inheritDoc + */ + protected function checkPermissions($parameters, Room $room, UserProfile $user) + { + $permission = $user->getPermission('mod.chat.canBan'); - if (!$permission) throw new PermissionDeniedException(); - } + if (!$this->isGlobally($parameters)) { + $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); + } - /** - * @inheritDoc - */ - protected function afterCreate(Suspension $suspension, $parameters, Room $room, UserProfile $user) { - parent::afterCreate($suspension, $parameters, $room, $user); + if (!$permission) { + throw new PermissionDeniedException(); + } + } - $user = new \chat\data\user\User($suspension->getUser()); - $rooms = [ ]; - if ($suspension->getRoom() === null) { - $rooms = $user->getRooms(); - } - else { - if ($user->isInRoom($suspension->getRoom())) { - $rooms = [ $suspension->getRoom() ]; - } - } + /** + * @inheritDoc + */ + protected function afterCreate(Suspension $suspension, $parameters, Room $room, UserProfile $user) + { + parent::afterCreate($suspension, $parameters, $room, $user); - foreach ($rooms as $room) { - $parameters = [ 'user' => $suspension->getUser() - , 'roomID' => $room->roomID - ]; - try { - (new \chat\data\room\RoomAction([ ], 'leave', $parameters))->executeAction(); - } - catch (UserInputException $e) { - // User already left - } - } - } + $user = new ChatUser($suspension->getUser()); + $rooms = [ ]; + if ($suspension->getRoom() === null) { + $rooms = $user->getRooms(); + } else { + if ($user->isInRoom($suspension->getRoom())) { + $rooms = [ + $suspension->getRoom(), + ]; + } + } + + foreach ($rooms as $room) { + $parameters = [ + 'user' => $suspension->getUser(), + 'roomID' => $room->roomID, + ]; + try { + (new RoomAction( + [ ], + 'leave', + $parameters + ))->executeAction(); + } catch (UserInputException $e) { + // User already left + } + } + } } diff --git a/files/lib/system/command/BroadcastCommand.class.php b/files/lib/system/command/BroadcastCommand.class.php index 9fcca7a..74afb0b 100644 --- a/files/lib/system/command/BroadcastCommand.class.php +++ b/files/lib/system/command/BroadcastCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,72 +15,94 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\message\MessageEditor; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\message\MessageEditor; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\message\embedded\object\MessageEmbeddedObjectManager; +use wcf\system\WCF; /** * BroadcastCommand sends a broadcast into all channels. */ -class BroadcastCommand extends AbstractInputProcessedCommand implements ICommand { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Broadcast'; - } +class BroadcastCommand extends AbstractInputProcessedCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Broadcast'; + } - /** - * @inheritDoc - */ - public function isAvailable(Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); - return $user->getPermission('mod.chat.canBroadcast'); - } + /** + * @inheritDoc + */ + public function isAvailable(Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + return $user->getPermission('mod.chat.canBroadcast'); + } - if (!$user->getPermission('mod.chat.canBroadcast')) throw new PermissionDeniedException(); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $this->setText($this->assertParameter($parameters, 'text')); - $this->validateText(); - } + if (!$user->getPermission('mod.chat.canBroadcast')) { + throw new PermissionDeniedException(); + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + $this->setText($this->assertParameter($parameters, 'text')); + $this->validateText(); + } - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.broadcast'); - $this->setText($this->assertParameter($parameters, 'text')); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - WCF::getDB()->beginTransaction(); - $message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'message' => $this->processor->getHtml() ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction()['returnValues']; + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.broadcast'); + $this->setText($this->assertParameter($parameters, 'text')); - $this->processor->setObjectID($message->messageID); - if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { - (new MessageEditor($message))->update([ - 'hasEmbeddedObjects' => 1 - ]); - } - WCF::getDB()->commitTransaction(); - } + WCF::getDB()->beginTransaction(); + $message = (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'message' => $this->processor->getHtml(), + ]), + ], + 'updateTimestamp' => true, + ] + ) + )->executeAction()['returnValues']; + + $this->processor->setObjectID($message->messageID); + if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { + (new MessageEditor($message))->update([ + 'hasEmbeddedObjects' => 1, + ]); + } + WCF::getDB()->commitTransaction(); + } } diff --git a/files/lib/system/command/ColorCommand.class.php b/files/lib/system/command/ColorCommand.class.php index 54be362..797ea84 100644 --- a/files/lib/system/command/ColorCommand.class.php +++ b/files/lib/system/command/ColorCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,272 +15,312 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\exception\UserInputException; -use \wcf\system\WCF; -use \wcf\util\StringUtil; +use chat\data\message\MessageAction; +use chat\data\room\Room; +use wcf\data\DatabaseObject; +use wcf\data\user\UserEditor; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\exception\UserInputException; +use wcf\system\Regex; +use wcf\system\WCF; +use wcf\util\StringUtil; /** * The color command allows a user to set a color for their username */ -class ColorCommand extends AbstractCommand implements ICommand { - /** - * Regular expression matching RGB values in hexadecimal notation - * @var \wcf\system\Regex - */ - protected $colorRegex = null; +class ColorCommand extends AbstractCommand implements ICommand +{ + /** + * Regular expression matching RGB values in hexadecimal notation + * @var \wcf\system\Regex + */ + protected $colorRegex; - public function __construct(\wcf\data\DatabaseObject $object) { - parent::__construct($object); + public function __construct(DatabaseObject $object) + { + parent::__construct($object); - $this->colorRegex = new \wcf\system\Regex('^#?([a-f0-9]{6})$', \wcf\system\Regex::CASE_INSENSITIVE); - } + $this->colorRegex = new Regex('^#?([a-f0-9]{6})$', Regex::CASE_INSENSITIVE); + } - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Color'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Color'; + } - /** - * Map CSS color names to hexcodes. - * See: https://www.w3.org/TR/css3-color/#svg-color - * - * @var int[] - */ - public static $colors = [ - 'aliceblue' => 0xF0F8FF, - 'antiquewhite' => 0xFAEBD7, - 'aqua' => 0x00FFFF, - 'aquamarine' => 0x7FFFD4, - 'azure' => 0xF0FFFF, - 'beige' => 0xF5F5DC, - 'bisque' => 0xFFE4C4, - 'black' => 0x000000, - 'blanchedalmond' => 0xFFEBCD, - 'blue' => 0x0000FF, - 'bluescreenblue' => 0x0000AA, - 'blueviolet' => 0x8A2BE2, - 'brown' => 0xA52A2A, - 'burlywood' => 0xDEB887, - 'cadetblue' => 0x5F9EA0, - 'chartreuse' => 0x7FFF00, - 'chocolate' => 0xD2691E, - 'coral' => 0xFF7F50, - 'cornflowerblue' => 0x6495ED, - 'cornsilk' => 0xFFF8DC, - 'crimson' => 0xDC143C, - 'cyan' => 0x00FFFF, - 'darkblue' => 0x00008B, - 'darkcyan' => 0x008B8B, - 'darkgoldenrod' => 0xB8860B, - 'darkgray' => 0xA9A9A9, - 'darkgrey' => 0xA9A9A9, - 'darkgreen' => 0x006400, - 'darkkhaki' => 0xBDB76B, - 'darkmagenta' => 0x8B008B, - 'darkolivegreen' => 0x556B2F, - 'darkorange' => 0xFF8C00, - 'darkorchid' => 0x9932CC, - 'darkred' => 0x8B0000, - 'darksalmon' => 0xE9967A, - 'darkseagreen' => 0x8FBC8F, - 'darkslateblue' => 0x483D8B, - 'darkslategray' => 0x2F4F4F, - 'darkslategrey' => 0x2F4F4F, - 'darkturquoise' => 0x00CED1, - 'darkviolet' => 0x9400D3, - 'deeppink' => 0xFF1493, - 'deepskyblue' => 0x00BFFF, - 'dimgray' => 0x696969, - 'dimgrey' => 0x696969, - 'dodgerblue' => 0x1E90FF, - 'firebrick' => 0xB22222, - 'floralwhite' => 0xFFFAF0, - 'forestgreen' => 0x228B22, - 'fuchsia' => 0xFF00FF, - 'gainsboro' => 0xDCDCDC, - 'ghostwhite' => 0xF8F8FF, - 'gold' => 0xFFD700, - 'goldenrod' => 0xDAA520, - 'gray' => 0x808080, - 'grey' => 0x808080, - 'green' => 0x008000, - 'greenyellow' => 0xADFF2F, - 'honeydew' => 0xF0FFF0, - 'hotpink' => 0xFF69B4, - 'indianred' => 0xCD5C5C, - 'indigo' => 0x4B0082, - 'ivory' => 0xFFFFF0, - 'khaki' => 0xF0E68C, - 'lavender' => 0xE6E6FA, - 'lavenderblush' => 0xFFF0F5, - 'lawngreen' => 0x7CFC00, - 'lemonchiffon' => 0xFFFACD, - 'lightblue' => 0xADD8E6, - 'lightcoral' => 0xF08080, - 'lightcyan' => 0xE0FFFF, - 'lightgoldenrodyellow' => 0xFAFAD2, - 'lightgray' => 0xD3D3D3, - 'lightgrey' => 0xD3D3D3, - 'lightgreen' => 0x90EE90, - 'lightpink' => 0xFFB6C1, - 'lightsalmon' => 0xFFA07A, - 'lightseagreen' => 0x20B2AA, - 'lightskyblue' => 0x87CEFA, - 'lightslategray' => 0x778899, - 'lightslategrey' => 0x778899, - 'lightsteelblue' => 0xB0C4DE, - 'lightyellow' => 0xFFFFE0, - 'lime' => 0x00FF00, - 'limegreen' => 0x32CD32, - 'linen' => 0xFAF0E6, - 'magenta' => 0xFF00FF, - 'maroon' => 0x800000, - 'mediumaquamarine' => 0x66CDAA, - 'mediumblue' => 0x0000CD, - 'mediumorchid' => 0xBA55D3, - 'mediumpurple' => 0x9370D8, - 'mediumseagreen' => 0x3CB371, - 'mediumslateblue' => 0x7B68EE, - 'mediumspringgreen' => 0x00FA9A, - 'mediumturquoise' => 0x48D1CC, - 'mediumvioletred' => 0xC71585, - 'midnightblue' => 0x191970, - 'mintcream' => 0xF5FFFA, - 'mistyrose' => 0xFFE4E1, - 'moccasin' => 0xFFE4B5, - 'navajowhite' => 0xFFDEAD, - 'navy' => 0x000080, - 'oldlace' => 0xFDF5E6, - 'olive' => 0x808000, - 'olivedrab' => 0x6B8E23, - 'orange' => 0xFFA500, - 'orangered' => 0xFF4500, - 'orchid' => 0xDA70D6, - 'oxford' => 0xF02D, // looks like green - 'palegoldenrod' => 0xEEE8AA, - 'palegreen' => 0x98FB98, - 'paleturquoise' => 0xAFEEEE, - 'palevioletred' => 0xD87093, - 'papayawhip' => 0xFFEFD5, - 'peachpuff' => 0xFFDAB9, - 'peru' => 0xCD853F, - 'pink' => 0xFFC0CB, - 'plum' => 0xDDA0DD, - 'powderblue' => 0xB0E0E6, - 'purple' => 0x800080, - 'red' => 0xFF0000, - 'rosybrown' => 0xBC8F8F, - 'royalblue' => 0x4169E1, - 'saddlebrown' => 0x8B4513, - 'sadwin' => 0x2067B2, - 'salmon' => 0xFA8072, - 'sandybrown' => 0xF4A460, - 'seagreen' => 0x2E8B57, - 'seashell' => 0xFFF5EE, - 'sienna' => 0xA0522D, - 'silver' => 0xC0C0C0, - 'skyblue' => 0x87CEEB, - 'slateblue' => 0x6A5ACD, - 'slategray' => 0x708090, - 'slategrey' => 0x708090, - 'snow' => 0xFFFAFA, - 'springgreen' => 0x00FF7F, - 'steelblue' => 0x4682B4, - 'tan' => 0xD2B48C, - 'teal' => 0x008080, - 'thistle' => 0xD8BFD8, - 'tomato' => 0xFF6347, - 'turquoise' => 0x40E0D0, - 'violet' => 0xEE82EE, - 'wheat' => 0xF5DEB3, - 'white' => 0xFFFFFF, - 'whitesmoke' => 0xF5F5F5, - 'yellow' => 0xFFFF00, - 'yellowgreen' => 0x9ACD32 - ]; + /** + * Map CSS color names to hexcodes. + * See: https://www.w3.org/TR/css3-color/#svg-color + * + * @var int[] + */ + public static $colors = [ + 'aliceblue' => 0xF0F8FF, + 'antiquewhite' => 0xFAEBD7, + 'aqua' => 0x00FFFF, + 'aquamarine' => 0x7FFFD4, + 'azure' => 0xF0FFFF, + 'beige' => 0xF5F5DC, + 'bisque' => 0xFFE4C4, + 'black' => 0x000000, + 'blanchedalmond' => 0xFFEBCD, + 'blue' => 0x0000FF, + 'bluescreenblue' => 0x0000AA, + 'blueviolet' => 0x8A2BE2, + 'brown' => 0xA52A2A, + 'burlywood' => 0xDEB887, + 'cadetblue' => 0x5F9EA0, + 'chartreuse' => 0x7FFF00, + 'chocolate' => 0xD2691E, + 'coral' => 0xFF7F50, + 'cornflowerblue' => 0x6495ED, + 'cornsilk' => 0xFFF8DC, + 'crimson' => 0xDC143C, + 'cyan' => 0x00FFFF, + 'darkblue' => 0x00008B, + 'darkcyan' => 0x008B8B, + 'darkgoldenrod' => 0xB8860B, + 'darkgray' => 0xA9A9A9, + 'darkgrey' => 0xA9A9A9, + 'darkgreen' => 0x006400, + 'darkkhaki' => 0xBDB76B, + 'darkmagenta' => 0x8B008B, + 'darkolivegreen' => 0x556B2F, + 'darkorange' => 0xFF8C00, + 'darkorchid' => 0x9932CC, + 'darkred' => 0x8B0000, + 'darksalmon' => 0xE9967A, + 'darkseagreen' => 0x8FBC8F, + 'darkslateblue' => 0x483D8B, + 'darkslategray' => 0x2F4F4F, + 'darkslategrey' => 0x2F4F4F, + 'darkturquoise' => 0x00CED1, + 'darkviolet' => 0x9400D3, + 'deeppink' => 0xFF1493, + 'deepskyblue' => 0x00BFFF, + 'dimgray' => 0x696969, + 'dimgrey' => 0x696969, + 'dodgerblue' => 0x1E90FF, + 'firebrick' => 0xB22222, + 'floralwhite' => 0xFFFAF0, + 'forestgreen' => 0x228B22, + 'fuchsia' => 0xFF00FF, + 'gainsboro' => 0xDCDCDC, + 'ghostwhite' => 0xF8F8FF, + 'gold' => 0xFFD700, + 'goldenrod' => 0xDAA520, + 'gray' => 0x808080, + 'grey' => 0x808080, + 'green' => 0x008000, + 'greenyellow' => 0xADFF2F, + 'honeydew' => 0xF0FFF0, + 'hotpink' => 0xFF69B4, + 'indianred' => 0xCD5C5C, + 'indigo' => 0x4B0082, + 'ivory' => 0xFFFFF0, + 'khaki' => 0xF0E68C, + 'lavender' => 0xE6E6FA, + 'lavenderblush' => 0xFFF0F5, + 'lawngreen' => 0x7CFC00, + 'lemonchiffon' => 0xFFFACD, + 'lightblue' => 0xADD8E6, + 'lightcoral' => 0xF08080, + 'lightcyan' => 0xE0FFFF, + 'lightgoldenrodyellow' => 0xFAFAD2, + 'lightgray' => 0xD3D3D3, + 'lightgrey' => 0xD3D3D3, + 'lightgreen' => 0x90EE90, + 'lightpink' => 0xFFB6C1, + 'lightsalmon' => 0xFFA07A, + 'lightseagreen' => 0x20B2AA, + 'lightskyblue' => 0x87CEFA, + 'lightslategray' => 0x778899, + 'lightslategrey' => 0x778899, + 'lightsteelblue' => 0xB0C4DE, + 'lightyellow' => 0xFFFFE0, + 'lime' => 0x00FF00, + 'limegreen' => 0x32CD32, + 'linen' => 0xFAF0E6, + 'magenta' => 0xFF00FF, + 'maroon' => 0x800000, + 'mediumaquamarine' => 0x66CDAA, + 'mediumblue' => 0x0000CD, + 'mediumorchid' => 0xBA55D3, + 'mediumpurple' => 0x9370D8, + 'mediumseagreen' => 0x3CB371, + 'mediumslateblue' => 0x7B68EE, + 'mediumspringgreen' => 0x00FA9A, + 'mediumturquoise' => 0x48D1CC, + 'mediumvioletred' => 0xC71585, + 'midnightblue' => 0x191970, + 'mintcream' => 0xF5FFFA, + 'mistyrose' => 0xFFE4E1, + 'moccasin' => 0xFFE4B5, + 'navajowhite' => 0xFFDEAD, + 'navy' => 0x000080, + 'oldlace' => 0xFDF5E6, + 'olive' => 0x808000, + 'olivedrab' => 0x6B8E23, + 'orange' => 0xFFA500, + 'orangered' => 0xFF4500, + 'orchid' => 0xDA70D6, + 'oxford' => 0xF02D, // looks like green + 'palegoldenrod' => 0xEEE8AA, + 'palegreen' => 0x98FB98, + 'paleturquoise' => 0xAFEEEE, + 'palevioletred' => 0xD87093, + 'papayawhip' => 0xFFEFD5, + 'peachpuff' => 0xFFDAB9, + 'peru' => 0xCD853F, + 'pink' => 0xFFC0CB, + 'plum' => 0xDDA0DD, + 'powderblue' => 0xB0E0E6, + 'purple' => 0x800080, + 'red' => 0xFF0000, + 'rosybrown' => 0xBC8F8F, + 'royalblue' => 0x4169E1, + 'saddlebrown' => 0x8B4513, + 'sadwin' => 0x2067B2, + 'salmon' => 0xFA8072, + 'sandybrown' => 0xF4A460, + 'seagreen' => 0x2E8B57, + 'seashell' => 0xFFF5EE, + 'sienna' => 0xA0522D, + 'silver' => 0xC0C0C0, + 'skyblue' => 0x87CEEB, + 'slateblue' => 0x6A5ACD, + 'slategray' => 0x708090, + 'slategrey' => 0x708090, + 'snow' => 0xFFFAFA, + 'springgreen' => 0x00FF7F, + 'steelblue' => 0x4682B4, + 'tan' => 0xD2B48C, + 'teal' => 0x008080, + 'thistle' => 0xD8BFD8, + 'tomato' => 0xFF6347, + 'turquoise' => 0x40E0D0, + 'violet' => 0xEE82EE, + 'wheat' => 0xF5DEB3, + 'white' => 0xFFFFFF, + 'whitesmoke' => 0xF5F5F5, + 'yellow' => 0xFFFF00, + 'yellowgreen' => 0x9ACD32, + ]; - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - if (!$user->getPermission('user.chat.canSetColor')) throw new PermissionDeniedException(); + if (!$user->getPermission('user.chat.canSetColor')) { + throw new PermissionDeniedException(); + } - foreach ($parameters as $parameter) { - $value = StringUtil::trim($this->assertParameter($parameter, 'value')); - $valid = true; + foreach ($parameters as $parameter) { + $value = StringUtil::trim($this->assertParameter($parameter, 'value')); + $valid = true; - switch ($this->assertParameter($parameter, 'type')) { - case 'hex': - if (!$this->colorRegex->match($value)) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.invalidColor', [ 'color' => $value ])); - } - break; - case 'word': - if (!isset(self::$colors[$value])) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.invalidColor', [ 'color' => $value ])); - } - break; + switch ($this->assertParameter($parameter, 'type')) { + case 'hex': + if (!$this->colorRegex->match($value)) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'chat.error.invalidColor', + [ + 'color' => $value, + ] + ) + ); + } + break; + case 'word': + if (!isset(self::$colors[$value])) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'chat.error.invalidColor', + [ + 'color' => $value, + ] + ) + ); + } + break; - default: - throw new UserInputException('message'); - } - } - } + default: + throw new UserInputException('message'); + } + } + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.color'); - $colors = [ ]; + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.color'); + $colors = [ ]; - if (!isset($parameters[1])) $parameters[1] = $parameters[0]; + if (!isset($parameters[1])) { + $parameters[1] = $parameters[0]; + } - foreach ($parameters as $key => $parameter) { - $value = StringUtil::trim($this->assertParameter($parameter, 'value')); + foreach ($parameters as $key => $parameter) { + $value = StringUtil::trim($this->assertParameter($parameter, 'value')); - switch ($this->assertParameter($parameter, 'type')) { - case 'hex': - $colors[$key] = hexdec($value); - break; - case 'word': - if (!isset(self::$colors[$value])) throw new UserInputException('message'); - $colors[$key] = self::$colors[$value]; - break; - default: - throw new UserInputException('message'); - } - } + switch ($this->assertParameter($parameter, 'type')) { + case 'hex': + $colors[$key] = \hexdec($value); + break; + case 'word': + if (!isset(self::$colors[$value])) { + throw new UserInputException('message'); + } + $colors[$key] = self::$colors[$value]; + break; + default: + throw new UserInputException('message'); + } + } - WCF::getDB()->beginTransaction(); - $editor = new \wcf\data\user\UserEditor($user->getDecoratedObject()); - $editor->update([ 'chatColor1' => $colors[0] - , 'chatColor2' => $colors[1] - ]); + WCF::getDB()->beginTransaction(); + $editor = new UserEditor($user->getDecoratedObject()); + $editor->update([ + 'chatColor1' => $colors[0], + 'chatColor2' => $colors[1], + ]); - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'color1' => $colors[0] - , 'color2' => $colors[1] - ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction(); - WCF::getDB()->commitTransaction(); - } + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'color1' => $colors[0], + 'color2' => $colors[1], + ]), + ], + 'updateTimestamp' => true, + ] + ))->executeAction(); + WCF::getDB()->commitTransaction(); + } } diff --git a/files/lib/system/command/ICommand.class.php b/files/lib/system/command/ICommand.class.php index f41c035..8a842b3 100644 --- a/files/lib/system/command/ICommand.class.php +++ b/files/lib/system/command/ICommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,63 +15,64 @@ namespace chat\system\command; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\room\Room; +use wcf\data\user\UserProfile; /** * Interface for Command processors. */ -interface ICommand { - /** - * Returns whether the command can be used even when - * no trigger is configured for it. - * - * @return boolean - */ - public function allowWithoutTrigger(); +interface ICommand +{ + /** + * Returns whether the command can be used even when + * no trigger is configured for it. + * + * @return boolean + */ + public function allowWithoutTrigger(); - /** - * Returns the name of the JavaScript module. - * - * @return string - */ - public function getJavaScriptModuleName(); + /** + * Returns the name of the JavaScript module. + * + * @return string + */ + public function getJavaScriptModuleName(); - /** - * Returns whether this command theoretically is available - * in the given room, for the given user. - * If no user is given the active user should be assumed. - * - * The return value sets a flag for the JavaScript to - * consume. You still need to validate() this as well! - * - * @param Room $room - * @param UserProfile $user - * @return boolean - */ - public function isAvailable(Room $room, UserProfile $user = null); + /** + * Returns whether this command theoretically is available + * in the given room, for the given user. + * If no user is given the active user should be assumed. + * + * The return value sets a flag for the JavaScript to + * consume. You still need to validate() this as well! + * + * @param Room $room + * @param UserProfile $user + * @return boolean + */ + public function isAvailable(Room $room, ?UserProfile $user = null); - /** - * Validates the execution of the command with the given parameters - * in the given room for the given user. - * If no user is given the active user should be assumed. - * This method must throw if the command may not be executed in this form. - * - * @param mixed $parameters - * @param Room $room - * @param UserProfile $user - */ - public function validate($parameters, Room $room, UserProfile $user = null); + /** + * Validates the execution of the command with the given parameters + * in the given room for the given user. + * If no user is given the active user should be assumed. + * This method must throw if the command may not be executed in this form. + * + * @param mixed $parameters + * @param Room $room + * @param UserProfile $user + */ + public function validate($parameters, Room $room, ?UserProfile $user = null); - /** - * Executes the command with the given parameters in the given room in - * the context of the given user. - * If no user is given the active user should be assumed. - * This method must throw if the command may not be executed in this form. - * - * @param mixed $parameters - * @param Room $room - * @param UserProfile $user - */ - public function execute($parameters, Room $room, UserProfile $user = null); + /** + * Executes the command with the given parameters in the given room in + * the context of the given user. + * If no user is given the active user should be assumed. + * This method must throw if the command may not be executed in this form. + * + * @param mixed $parameters + * @param Room $room + * @param UserProfile $user + */ + public function execute($parameters, Room $room, ?UserProfile $user = null); } diff --git a/files/lib/system/command/InfoCommand.class.php b/files/lib/system/command/InfoCommand.class.php index 16588aa..c79f941 100644 --- a/files/lib/system/command/InfoCommand.class.php +++ b/files/lib/system/command/InfoCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,75 +15,91 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\room\Room; -use \chat\data\room\RoomCache; -use \wcf\data\user\User; -use \wcf\data\user\UserProfile; +use chat\data\message\MessageAction; +use chat\data\room\Room; +use chat\data\room\RoomCache; +use chat\data\user\User as ChatUser; +use wcf\data\user\User; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * The info command shows information about a single user. */ -class InfoCommand extends AbstractCommand implements ICommand { - use TNeedsUser; +class InfoCommand extends AbstractCommand implements ICommand +{ + use TNeedsUser; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Info'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Info'; + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $this->assertUser($this->assertParameter($parameters, 'username')); - } + $this->assertUser($this->assertParameter($parameters, 'username')); + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.info'); - $target = new \chat\data\user\User($this->getUser($this->assertParameter($parameters, 'username'))); - $rooms = array_values(array_map(function ($assoc) { - $room = RoomCache::getInstance()->getRoom($assoc['roomID']); + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.info'); + $target = new ChatUser($this->getUser($this->assertParameter($parameters, 'username'))); + $rooms = \array_values(\array_map(static function ($assoc) { + $room = RoomCache::getInstance()->getRoom($assoc['roomID']); - return [ 'title' => (string) $room - , 'roomID' => $assoc['roomID'] - , 'lastPush' => $assoc['lastPush'] - , 'lastPull' => $assoc['lastPull'] - , 'active' => $assoc['active'] - , 'link' => $room->getLink() - ]; - }, array_filter($target->getRoomAssociations(), function ($assoc) { - return RoomCache::getInstance()->getRoom($assoc['roomID'])->canSee(); - }))); + return [ + 'title' => (string)$room, + 'roomID' => $assoc['roomID'], + 'lastPush' => $assoc['lastPush'], + 'lastPull' => $assoc['lastPull'], + 'active' => $assoc['active'], + 'link' => $room->getLink(), + ]; + }, \array_filter($target->getRoomAssociations(), static function ($assoc) { + return RoomCache::getInstance()->getRoom($assoc['roomID'])->canSee(); + }))); - $payload = [ 'data' => [ 'rooms' => $rooms - , 'away' => $target->chatAway - , 'user' => $target - ] - , 'caller' => $user - ]; + $payload = [ + 'data' => [ + 'rooms' => $rooms, + 'away' => $target->chatAway, + 'user' => $target, + ], 'caller' => $user, + ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'execute', $payload); + EventHandler::getInstance()->fireAction($this, 'execute', $payload); - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize($payload['data']) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction(); - } + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize($payload['data']), + ], 'updateTimestamp' => true, + ] + ))->executeAction(); + } } diff --git a/files/lib/system/command/MeCommand.class.php b/files/lib/system/command/MeCommand.class.php index 8dd793b..e08a44f 100644 --- a/files/lib/system/command/MeCommand.class.php +++ b/files/lib/system/command/MeCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,71 +15,106 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\exception\UserInputException; -use \wcf\system\message\censorship\Censorship; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\exception\UserInputException; +use wcf\system\message\censorship\Censorship; +use wcf\system\WCF; /** * MeCommand represents an action message. */ -class MeCommand extends AbstractCommand implements ICommand { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Me'; - } +class MeCommand extends AbstractCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Me'; + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - if (!$room->canWritePublicly($user)) throw new PermissionDeniedException(); + if (!$room->canWritePublicly($user)) { + throw new PermissionDeniedException(); + } - $text = $this->assertParameter($parameters, 'text'); + $text = $this->assertParameter($parameters, 'text'); - if (mb_strlen($text) === 0) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.global.form.error.empty')); - } + if (\mb_strlen($text) === 0) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable('wcf.global.form.error.empty') + ); + } - // validate message length - if (mb_strlen($text) > CHAT_MAX_LENGTH) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.tooLong', [ 'maxTextLength' => CHAT_MAX_LENGTH ])); - } + // validate message length + if (\mb_strlen($text) > CHAT_MAX_LENGTH) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'wcf.message.error.tooLong', + [ + 'maxTextLength' => CHAT_MAX_LENGTH, + ] + ) + ); + } - // search for censored words - if (ENABLE_CENSORSHIP) { - $result = Censorship::getInstance()->test($text); - if ($result) { - throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.censoredWordsFound', [ 'censoredWords' => $result ])); - } - } - } + // search for censored words + if (ENABLE_CENSORSHIP) { + $result = Censorship::getInstance()->test($text); + if ($result) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'wcf.message.error.censoredWordsFound', + [ + 'censoredWords' => $result, + ] + ) + ); + } + } + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.me'); - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'message' => $this->assertParameter($parameters, 'text') ]) - ] - , 'updateTimestamp' => true - , 'grantPoints' => true - ] - ) - )->executeAction(); - } + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.me'); + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'message' => $this->assertParameter($parameters, 'text'), + ]), + ], + 'updateTimestamp' => true, + 'grantPoints' => true, + ] + ))->executeAction(); + } } diff --git a/files/lib/system/command/MuteCommand.class.php b/files/lib/system/command/MuteCommand.class.php index 49ffb3c..9e3905f 100644 --- a/files/lib/system/command/MuteCommand.class.php +++ b/files/lib/system/command/MuteCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,50 +15,58 @@ namespace chat\system\command; -use \chat\data\room\Room; -use \chat\data\suspension\SuspensionAction; -use \chat\system\permission\PermissionHandler; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\room\Room; +use chat\system\permission\PermissionHandler; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\WCF; /** * The mute command creates a new be.bastelstu.chat.suspension.mute suspension. */ -class MuteCommand extends AbstractSuspensionCommand implements ICommand { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Mute'; - } +class MuteCommand extends AbstractSuspensionCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Mute'; + } - /** - * @inheritDoc - */ - public function isAvailable(Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); - return $user->getPermission('mod.chat.canMute') || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); - } + /** + * @inheritDoc + */ + public function isAvailable(Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - /** - * @inheritDoc - */ - public function getObjectTypeName() { - return 'be.bastelstu.chat.suspension.mute'; - } + return $user->getPermission('mod.chat.canMute') || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); + } - /** - * @inheritDoc - */ - protected function checkPermissions($parameters, Room $room, UserProfile $user) { - $permission = $user->getPermission('mod.chat.canMute'); + /** + * @inheritDoc + */ + public function getObjectTypeName() + { + return 'be.bastelstu.chat.suspension.mute'; + } - if (!$this->isGlobally($parameters)) { - $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); - } + /** + * @inheritDoc + */ + protected function checkPermissions($parameters, Room $room, UserProfile $user) + { + $permission = $user->getPermission('mod.chat.canMute'); - if (!$permission) throw new PermissionDeniedException(); - } + if (!$this->isGlobally($parameters)) { + $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); + } + + if (!$permission) { + throw new PermissionDeniedException(); + } + } } diff --git a/files/lib/system/command/PlainCommand.class.php b/files/lib/system/command/PlainCommand.class.php index 32568d5..bae0387 100644 --- a/files/lib/system/command/PlainCommand.class.php +++ b/files/lib/system/command/PlainCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,72 +15,90 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\message\MessageEditor; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\message\MessageEditor; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\message\embedded\object\MessageEmbeddedObjectManager; +use wcf\system\WCF; /** * The plain command creates a normal chat message */ -class PlainCommand extends AbstractInputProcessedCommand implements ICommand { - /** - * @inheritDoc - */ - public function allowWithoutTrigger() { - return true; - } +class PlainCommand extends AbstractInputProcessedCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function allowWithoutTrigger() + { + return true; + } - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Plain'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Plain'; + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - if (!$room->canWritePublicly($user)) throw new PermissionDeniedException(); + if (!$room->canWritePublicly($user)) { + throw new PermissionDeniedException(); + } - $this->setText($this->assertParameter($parameters, 'text')); - $this->validateText(); - } + $this->setText($this->assertParameter($parameters, 'text')); + $this->validateText(); + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.plain'); - $this->setText($this->assertParameter($parameters, 'text')); - - WCF::getDB()->beginTransaction(); - $message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'message' => $this->processor->getHtml() ]) - ] - , 'updateTimestamp' => true - , 'grantPoints' => true - ] - ) - )->executeAction()['returnValues']; + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.plain'); + $this->setText($this->assertParameter($parameters, 'text')); - $this->processor->setObjectID($message->messageID); - if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { - (new MessageEditor($message))->update([ - 'hasEmbeddedObjects' => 1 - ]); - } - WCF::getDB()->commitTransaction(); - } + WCF::getDB()->beginTransaction(); + $message = (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'message' => $this->processor->getHtml(), + ]), + ], + 'updateTimestamp' => true, + 'grantPoints' => true, + ] + ))->executeAction()['returnValues']; + + $this->processor->setObjectID($message->messageID); + if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { + (new MessageEditor($message))->update([ + 'hasEmbeddedObjects' => 1, + ]); + } + WCF::getDB()->commitTransaction(); + } } diff --git a/files/lib/system/command/TNeedsUser.class.php b/files/lib/system/command/TNeedsUser.class.php index c5ef25d..f318677 100644 --- a/files/lib/system/command/TNeedsUser.class.php +++ b/files/lib/system/command/TNeedsUser.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,40 +15,53 @@ namespace chat\system\command; -use \wcf\data\user\User; -use \wcf\system\exception\UserInputException; -use \wcf\system\WCF; +use wcf\data\user\User; +use wcf\system\exception\UserInputException; +use wcf\system\WCF; /** * Adds helpful functions for commands that operate on a user. */ -trait TNeedsUser { - /** - * Returns the user with the given username. - * - * @param string $username - * @return \wcf\data\user\User - */ - protected function getUser($username) { - static $cache = [ ]; - if (!isset($cache[$username])) { - $cache[$username] = User::getUserByUsername($username); - } +trait TNeedsUser +{ + /** + * Returns the user with the given username. + * + * @param string $username + * @return \wcf\data\user\User + */ + protected function getUser($username) + { + static $cache = [ ]; + if (!isset($cache[$username])) { + $cache[$username] = User::getUserByUsername($username); + } - return $cache[$username]; - } + return $cache[$username]; + } - /** - * Checks whether the given username is valid and throws otherwise. - * - * @param string $username - * @return \wcf\data\user\User - */ - protected function assertUser($username) { - $user = $this->getUser($username); + /** + * Checks whether the given username is valid and throws otherwise. + * + * @param string $username + * @return \wcf\data\user\User + */ + protected function assertUser($username) + { + $user = $this->getUser($username); - if (!$user->userID) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.userNotFound', [ 'username' => $username ])); + if (!$user->userID) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'chat.error.userNotFound', + [ + 'username' => $username, + ] + ) + ); + } - return $user; - } + return $user; + } } diff --git a/files/lib/system/command/TeamCommand.class.php b/files/lib/system/command/TeamCommand.class.php index 2dcf07d..96104c6 100644 --- a/files/lib/system/command/TeamCommand.class.php +++ b/files/lib/system/command/TeamCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,73 +15,92 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\message\MessageEditor; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\exception\UserInputException; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\message\MessageEditor; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\message\embedded\object\MessageEmbeddedObjectManager; +use wcf\system\WCF; /** * TeamCommand sends a broadcast to all team members. */ -class TeamCommand extends AbstractInputProcessedCommand implements ICommand { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Team'; - } +class TeamCommand extends AbstractInputProcessedCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Team'; + } - /** - * @inheritDoc - */ - public function isAvailable(Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); - return $user->getPermission('mod.chat.canTeam'); - } + /** + * @inheritDoc + */ + public function isAvailable(Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + return $user->getPermission('mod.chat.canTeam'); + } - if (!$user->getPermission('mod.chat.canTeam')) throw new PermissionDeniedException(); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $this->setText($this->assertParameter($parameters, 'text')); - $this->validateText(); - } + if (!$user->getPermission('mod.chat.canTeam')) { + throw new PermissionDeniedException(); + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + $this->setText($this->assertParameter($parameters, 'text')); + $this->validateText(); + } - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.team'); - $this->setText($this->assertParameter($parameters, 'text')); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - WCF::getDB()->beginTransaction(); - $message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'message' => $this->processor->getHtml() ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction()['returnValues']; + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.team'); + $this->setText($this->assertParameter($parameters, 'text')); - $this->processor->setObjectID($message->messageID); - if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { - (new MessageEditor($message))->update([ - 'hasEmbeddedObjects' => 1 - ]); - } - WCF::getDB()->commitTransaction(); - } + WCF::getDB()->beginTransaction(); + $message = (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'message' => $this->processor->getHtml(), + ]), + ], 'updateTimestamp' => true, + ] + ))->executeAction()['returnValues']; + + $this->processor->setObjectID($message->messageID); + if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { + (new MessageEditor($message))->update([ + 'hasEmbeddedObjects' => 1, + ]); + } + WCF::getDB()->commitTransaction(); + } } diff --git a/files/lib/system/command/TemproomCommand.class.php b/files/lib/system/command/TemproomCommand.class.php index e20f5b4..bf6e491 100644 --- a/files/lib/system/command/TemproomCommand.class.php +++ b/files/lib/system/command/TemproomCommand.class.php @@ -1,6 +1,7 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. @@ -14,123 +15,187 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\exception\UserInputException; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\room\Room; +use chat\data\room\RoomAction; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\exception\UserInputException; +use wcf\system\WCF; /** * The temproom command allows a user to manage temporary rooms. */ -class TemproomCommand extends AbstractCommand implements ICommand { - use TNeedsUser; +class TemproomCommand extends AbstractCommand implements ICommand +{ + use TNeedsUser; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Temproom'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Temproom'; + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - switch ($this->assertParameter($parameters, 'type')) { - case 'create': - if (!$user->getPermission('user.chat.canTemproom')) throw new PermissionDeniedException(); - break; - case 'invite': - if (!$room->isTemporary) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.notInTemproom')); - if ($room->ownerID !== $user->userID) throw new PermissionDeniedException(); + switch ($this->assertParameter($parameters, 'type')) { + case 'create': + if (!$user->getPermission('user.chat.canTemproom')) { + throw new PermissionDeniedException(); + } + break; + case 'invite': + if (!$room->isTemporary) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable('chat.error.notInTemproom') + ); + } + if ($room->ownerID !== $user->userID) { + throw new PermissionDeniedException(); + } - $recipient = new UserProfile($this->assertUser($this->assertParameter($parameters, 'username'))); - if ($recipient->isIgnoredUser($user->userID)) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.userIgnoresYou', [ 'user' => $recipient ])); - break; - case 'delete': - if (!$room->isTemporary) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.notInTemproom')); - if ($room->ownerID !== $user->userID) throw new PermissionDeniedException(); - break; - default: - throw new UserInputException('message'); - } - } + $recipient = new UserProfile($this->assertUser($this->assertParameter($parameters, 'username'))); + if ($recipient->isIgnoredUser($user->userID)) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'chat.error.userIgnoresYou', + [ + 'user' => $recipient, + ] + ) + ); + } + break; + case 'delete': + if (!$room->isTemporary) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'chat.error.notInTemproom' + ) + ); + } + if ($room->ownerID !== $user->userID) { + throw new PermissionDeniedException(); + } + break; + default: + throw new UserInputException('message'); + } + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - switch ($this->assertParameter($parameters, 'type')) { - case 'create': - $fields = [ 'title' => WCF::getLanguage()->getDynamicVariable('chat.room.temporary.blueprint', [ 'user' => $user ]) - , 'topic' => '' - , 'position' => 999 - , 'isTemporary' => true - , 'ownerID' => $user->userID - ]; + switch ($this->assertParameter($parameters, 'type')) { + case 'create': + $fields = [ + 'title' => WCF::getLanguage()->getDynamicVariable( + 'chat.room.temporary.blueprint', + [ + 'user' => $user, + ] + ), + 'topic' => '', + 'position' => 999, + 'isTemporary' => true, + 'ownerID' => $user->userID, + ]; - WCF::getDB()->beginTransaction(); - // create room - $tempRoom = (new \chat\data\room\RoomAction([], 'create', [ 'data' => $fields ]))->executeAction()['returnValues']; - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.temproomCreated'); - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'room' => $tempRoom ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction(); - WCF::getDB()->commitTransaction(); - return; - case 'invite': - $recipient = $this->getUser($this->assertParameter($parameters, 'username')); - WCF::getDB()->beginTransaction(); - try { - $sql = "INSERT INTO chat1_room_temporary_invite - (userID, roomID) - VALUES (?, ?)"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ $recipient->userID, $room->roomID ]); - } - catch (\wcf\system\database\DatabaseException $e) { - WCF::getDB()->rollBackTransaction(); - // Duplicate key errors don't cause harm. - if ((string) $e->getCode() !== '23000') throw $e; - return; - } + WCF::getDB()->beginTransaction(); + // create room + $tempRoom = (new RoomAction([], 'create', [ + 'data' => $fields, + ]))->executeAction()['returnValues']; + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.temproomCreated'); + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'room' => $tempRoom, + ]), + ], 'updateTimestamp' => true, + ] + ))->executeAction(); + WCF::getDB()->commitTransaction(); - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.temproomInvited'); - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'recipient' => $recipient->userID - , 'recipientName' => $recipient->username - ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction(); - WCF::getDB()->commitTransaction(); + return; + case 'invite': + $recipient = $this->getUser($this->assertParameter($parameters, 'username')); + WCF::getDB()->beginTransaction(); + try { + $sql = "INSERT INTO chat1_room_temporary_invite + (userID, roomID) + VALUES (?, ?)"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ $recipient->userID, $room->roomID ]); + } catch (\wcf\system\database\DatabaseException $e) { + WCF::getDB()->rollBackTransaction(); + // Duplicate key errors don't cause harm. + if ((string)$e->getCode() !== '23000') { + throw $e; + } - return; - case 'delete': - (new \chat\data\room\RoomAction([ $room ], 'delete'))->executeAction(); - return; - default: - throw new UserInputException('message'); - } - } + return; + } + + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.temproomInvited'); + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'recipient' => $recipient->userID, + 'recipientName' => $recipient->username, + ]), + ], + 'updateTimestamp' => true, + ] + ))->executeAction(); + WCF::getDB()->commitTransaction(); + + return; + case 'delete': + (new RoomAction( + [ + $room, + ], + 'delete' + ))->executeAction(); + + return; + default: + throw new UserInputException('message'); + } + } } diff --git a/files/lib/system/command/UnbanCommand.class.php b/files/lib/system/command/UnbanCommand.class.php index 9e71c39..c23a3ad 100644 --- a/files/lib/system/command/UnbanCommand.class.php +++ b/files/lib/system/command/UnbanCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,51 +15,59 @@ namespace chat\system\command; -use \chat\data\room\Room; -use \chat\data\suspension\Suspension; -use \chat\data\suspension\SuspensionAction; -use \chat\system\permission\PermissionHandler; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\room\Room; +use chat\data\suspension\Suspension; +use chat\system\permission\PermissionHandler; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\WCF; /** * The unban command revokes a new be.bastelstu.chat.suspension.ban suspension. */ -class UnbanCommand extends AbstractUnsuspensionCommand implements ICommand { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Unban'; - } +class UnbanCommand extends AbstractUnsuspensionCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Unban'; + } - /** - * @inheritDoc - */ - public function isAvailable(Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); - return $user->getPermission('mod.chat.canBan') || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); - } + /** + * @inheritDoc + */ + public function isAvailable(Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - /** - * @inheritDoc - */ - public function getObjectTypeName() { - return 'be.bastelstu.chat.suspension.ban'; - } + return $user->getPermission('mod.chat.canBan') || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); + } - /** - * @inheritDoc - */ - protected function checkPermissions($parameters, Room $room, UserProfile $user) { - $permission = $user->getPermission('mod.chat.canBan'); + /** + * @inheritDoc + */ + public function getObjectTypeName() + { + return 'be.bastelstu.chat.suspension.ban'; + } - if (!$this->isGlobally($parameters)) { - $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); - } + /** + * @inheritDoc + */ + protected function checkPermissions($parameters, Room $room, UserProfile $user) + { + $permission = $user->getPermission('mod.chat.canBan'); - if (!$permission) throw new PermissionDeniedException(); - } + if (!$this->isGlobally($parameters)) { + $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); + } + + if (!$permission) { + throw new PermissionDeniedException(); + } + } } diff --git a/files/lib/system/command/UnmuteCommand.class.php b/files/lib/system/command/UnmuteCommand.class.php index 8927c68..6481906 100644 --- a/files/lib/system/command/UnmuteCommand.class.php +++ b/files/lib/system/command/UnmuteCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,50 +15,58 @@ namespace chat\system\command; -use \chat\data\room\Room; -use \chat\data\suspension\SuspensionAction; -use \chat\system\permission\PermissionHandler; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\room\Room; +use chat\system\permission\PermissionHandler; +use wcf\data\user\UserProfile; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\WCF; /** * The unmute command revokes a new be.bastelstu.chat.suspension.mute suspension. */ -class UnmuteCommand extends AbstractUnsuspensionCommand implements ICommand { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Unmute'; - } +class UnmuteCommand extends AbstractUnsuspensionCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Unmute'; + } - /** - * @inheritDoc - */ - public function isAvailable(Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(WCF::getUser()); - return $user->getPermission('mod.chat.canMute') || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); - } + /** + * @inheritDoc + */ + public function isAvailable(Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - /** - * @inheritDoc - */ - public function getObjectTypeName() { - return 'be.bastelstu.chat.suspension.mute'; - } + return $user->getPermission('mod.chat.canMute') || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); + } - /** - * @inheritDoc - */ - protected function checkPermissions($parameters, Room $room, UserProfile $user) { - $permission = $user->getPermission('mod.chat.canMute'); + /** + * @inheritDoc + */ + public function getObjectTypeName() + { + return 'be.bastelstu.chat.suspension.mute'; + } - if (!$this->isGlobally($parameters)) { - $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); - } + /** + * @inheritDoc + */ + protected function checkPermissions($parameters, Room $room, UserProfile $user) + { + $permission = $user->getPermission('mod.chat.canMute'); - if (!$permission) throw new PermissionDeniedException(); - } + if (!$this->isGlobally($parameters)) { + $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); + } + + if (!$permission) { + throw new PermissionDeniedException(); + } + } } diff --git a/files/lib/system/command/WhereCommand.class.php b/files/lib/system/command/WhereCommand.class.php index 4b961f6..ea504b1 100644 --- a/files/lib/system/command/WhereCommand.class.php +++ b/files/lib/system/command/WhereCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,61 +15,75 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\room\Room; -use \wcf\data\user\User; -use \wcf\data\user\UserProfile; +use chat\data\message\MessageAction; +use chat\data\room\Room; +use chat\data\room\RoomList; +use chat\data\user\User as ChatUser; +use wcf\data\user\UserProfile; +use wcf\system\WCF; /** * The where command shows the distribution of users among * the different chat rooms. */ -class WhereCommand extends AbstractCommand implements ICommand { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Where'; - } +class WhereCommand extends AbstractCommand implements ICommand +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Where'; + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); - } + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.where'); - $roomList = new \chat\data\room\RoomList(); - $roomList->readObjects(); - $rooms = array_map(function (Room $room) { - $users = array_map(function (\chat\data\user\User $user) { - return $user->jsonSerialize(); - }, $room->getUsers()); + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.where'); + $roomList = new RoomList(); + $roomList->readObjects(); + $rooms = \array_map(static function (Room $room) { + $users = \array_map(static function (ChatUser $user) { + return $user->jsonSerialize(); + }, $room->getUsers()); - return [ 'roomID' => $room->roomID - , 'users' => array_values($users) - ]; - }, array_filter($roomList->getObjects(), function (Room $room) { - return $room->canSee(); - })); + return [ + 'roomID' => $room->roomID, + 'users' => \array_values($users), + ]; + }, \array_filter($roomList->getObjects(), static function (Room $room) { + return $room->canSee(); + })); - (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize($rooms) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction(); - } + (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize($rooms), + ], 'updateTimestamp' => true, + ] + ))->executeAction(); + } } diff --git a/files/lib/system/command/WhisperCommand.class.php b/files/lib/system/command/WhisperCommand.class.php index a188b3c..45c7fce 100644 --- a/files/lib/system/command/WhisperCommand.class.php +++ b/files/lib/system/command/WhisperCommand.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,72 +15,96 @@ namespace chat\system\command; -use \chat\data\message\MessageAction; -use \chat\data\message\MessageEditor; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; -use \wcf\system\exception\UserInputException; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\message\MessageEditor; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\exception\UserInputException; +use wcf\system\message\embedded\object\MessageEmbeddedObjectManager; +use wcf\system\WCF; /** * The whisper command creates a private message * between two chat users. */ -class WhisperCommand extends AbstractInputProcessedCommand implements ICommand { - use TNeedsUser; +class WhisperCommand extends AbstractInputProcessedCommand implements ICommand +{ + use TNeedsUser; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/Command/Whisper'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/Command/Whisper'; + } - /** - * @inheritDoc - */ - public function validate($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function validate($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $recipient = new UserProfile($this->assertUser($this->assertParameter($parameters, 'username'))); - if ($recipient->isIgnoredUser($user->userID)) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.userIgnoresYou', [ 'user' => $recipient ])); + $recipient = new UserProfile($this->assertUser($this->assertParameter($parameters, 'username'))); + if ($recipient->isIgnoredUser($user->userID)) { + throw new UserInputException( + 'message', + WCF::getLanguage()->getDynamicVariable( + 'chat.error.userIgnoresYou', + [ + 'user' => $recipient, + ] + ) + ); + } - $this->setText($this->assertParameter($parameters, 'text')); - $this->validateText(); - } + $this->setText($this->assertParameter($parameters, 'text')); + $this->validateText(); + } - /** - * @inheritDoc - */ - public function execute($parameters, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function execute($parameters, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.whisper'); - $recipient = $this->assertUser($this->assertParameter($parameters, 'username')); - $this->setText($this->assertParameter($parameters, 'text')); + $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.whisper'); + $recipient = $this->assertUser($this->assertParameter($parameters, 'username')); + $this->setText($this->assertParameter($parameters, 'text')); - WCF::getDB()->beginTransaction(); - $message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID - , 'userID' => $user->userID - , 'username' => $user->username - , 'time' => TIME_NOW - , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'message' => $this->processor->getHtml() - , 'recipient' => $recipient->userID - , 'recipientName' => $recipient->username - ]) - ] - , 'updateTimestamp' => true - ] - ) - )->executeAction()['returnValues']; + WCF::getDB()->beginTransaction(); + $message = (new MessageAction( + [ ], + 'create', + [ + 'data' => [ + 'roomID' => $room->roomID, + 'userID' => $user->userID, + 'username' => $user->username, + 'time' => TIME_NOW, + 'objectTypeID' => $objectTypeID, + 'payload' => \serialize([ + 'message' => $this->processor->getHtml(), + 'recipient' => $recipient->userID, + 'recipientName' => $recipient->username, + ]), + ], + 'updateTimestamp' => true, + ] + ))->executeAction()['returnValues']; - $this->processor->setObjectID($message->messageID); - if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { - (new MessageEditor($message))->update([ - 'hasEmbeddedObjects' => 1 - ]); - } - WCF::getDB()->commitTransaction(); - } + $this->processor->setObjectID($message->messageID); + if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { + (new MessageEditor($message))->update([ + 'hasEmbeddedObjects' => 1, + ]); + } + WCF::getDB()->commitTransaction(); + } } diff --git a/files/lib/system/condition/room/RoomFilledCondition.class.php b/files/lib/system/condition/room/RoomFilledCondition.class.php index a780d2c..29ac60f 100644 --- a/files/lib/system/condition/room/RoomFilledCondition.class.php +++ b/files/lib/system/condition/room/RoomFilledCondition.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,33 +15,36 @@ namespace chat\system\condition\room; -use \chat\data\room\RoomList; -use \wcf\data\DatabaseObject; -use \wcf\data\DatabaseObjectList; -use \wcf\system\exception\SystemException; +use chat\data\room\RoomList; +use wcf\data\DatabaseObjectList; +use wcf\system\condition\AbstractCheckboxCondition; +use wcf\system\condition\IObjectListCondition; +use wcf\system\exception\ParentClassException; /** * Condition implementation for rooms to only include non-empty rooms in lists. */ -class RoomFilledCondition extends \wcf\system\condition\AbstractCheckboxCondition implements \wcf\system\condition\IObjectListCondition { - /** - * @inheritDoc - */ - protected $fieldName = 'chatRoomIsFilled'; +class RoomFilledCondition extends AbstractCheckboxCondition implements IObjectListCondition +{ + /** + * @inheritDoc + */ + protected $fieldName = 'chatRoomIsFilled'; - /** - * @inheritDoc - */ - protected $label = 'chat.room.condition.isFilled'; + /** + * @inheritDoc + */ + protected $label = 'chat.room.condition.isFilled'; - /** - * @inheritDoc - */ - public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { - if (!($objectList instanceof RoomList)) { - throw new \wcf\system\exception\ParentClassException(get_class($objectList), RoomList::class); - } + /** + * @inheritDoc + */ + public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) + { + if (!($objectList instanceof RoomList)) { + throw new ParentClassException(\get_class($objectList), RoomList::class); + } - $objectList->getConditionBuilder()->add("EXISTS (SELECT 1 FROM chat".WCF_N."_room_to_user r2u WHERE r2u.roomID = room.roomID AND active = ?)", [ 1 ]); - } + $objectList->getConditionBuilder()->add("EXISTS (SELECT 1 FROM chat" . WCF_N . "_room_to_user r2u WHERE r2u.roomID = room.roomID AND active = ?)", [ 1 ]); + } } diff --git a/files/lib/system/event/listener/HourlyCleanUpCronjobExecuteChatCleanUpListener.class.php b/files/lib/system/event/listener/HourlyCleanUpCronjobExecuteChatCleanUpListener.class.php index 3fc240f..122c680 100644 --- a/files/lib/system/event/listener/HourlyCleanUpCronjobExecuteChatCleanUpListener.class.php +++ b/files/lib/system/event/listener/HourlyCleanUpCronjobExecuteChatCleanUpListener.class.php @@ -1,6 +1,7 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. @@ -14,27 +15,35 @@ namespace chat\system\event\listener; -use \wcf\system\WCF; +use chat\data\message\MessageAction; +use chat\data\user\UserAction as ChatUserAction; +use wcf\system\event\listener\IParameterizedEventListener; +use wcf\system\WCF; /** * Vaporizes unneeded data. */ -class HourlyCleanUpCronjobExecuteChatCleanUpListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - (new \chat\data\message\MessageAction([ ], 'prune'))->executeAction(); - (new \chat\data\user\UserAction([], 'clearDeadSessions'))->executeAction(); +class HourlyCleanUpCronjobExecuteChatCleanUpListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + (new MessageAction([ ], 'prune'))->executeAction(); + (new ChatUserAction([ ], 'clearDeadSessions'))->executeAction(); - $sql = "UPDATE chat1_room_to_user - SET active = ? - WHERE (roomID, userID) NOT IN (SELECT roomID, userID FROM chat1_session) - AND active = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ 0, 1 ]); - if ($statement->getAffectedRows()) { - \wcf\functions\exception\logThrowable(new \Exception('Unreachable')); - } - } + $sql = "UPDATE chat1_room_to_user + SET active = ? + WHERE (roomID, userID) NOT IN ( + SELECT roomID, userID + FROM chat1_session + ) + AND active = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ 0, 1 ]); + if ($statement->getAffectedRows()) { + \wcf\functions\exception\logThrowable(new \Exception('Unreachable')); + } + } } diff --git a/files/lib/system/event/listener/HourlyCleanUpCronjobExecuteTemproomListener.class.php b/files/lib/system/event/listener/HourlyCleanUpCronjobExecuteTemproomListener.class.php index 7b4a251..d5f8df9 100644 --- a/files/lib/system/event/listener/HourlyCleanUpCronjobExecuteTemproomListener.class.php +++ b/files/lib/system/event/listener/HourlyCleanUpCronjobExecuteTemproomListener.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,30 +15,38 @@ namespace chat\system\event\listener; -use \wcf\system\WCF; +use chat\data\room\RoomAction; +use chat\data\room\RoomList; +use wcf\system\event\listener\IParameterizedEventListener; +use wcf\system\WCF; /** * Removes empty temporary rooms. */ -class HourlyCleanUpCronjobExecuteTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - $roomList = new \chat\data\room\RoomList(); - $roomList->getConditionBuilder()->add('isTemporary = ?', [ 1 ]); - $roomList->readObjects(); +class HourlyCleanUpCronjobExecuteTemproomListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + $roomList = new RoomList(); + $roomList->getConditionBuilder()->add('isTemporary = ?', [ 1 ]); + $roomList->readObjects(); - $toDelete = [ ]; - WCF::getDB()->beginTransaction(); - foreach ($roomList as $room) { - if (count($room->getUsers()) === 0) { - $toDelete[] = $room; - } - } - if (!empty($toDelete)) { - (new \chat\data\room\RoomAction($toDelete, 'delete'))->executeAction(); - } - WCF::getDB()->commitTransaction(); - } + $toDelete = [ ]; + WCF::getDB()->beginTransaction(); + foreach ($roomList as $room) { + if (\count($room->getUsers()) === 0) { + $toDelete[] = $room; + } + } + if (!empty($toDelete)) { + (new RoomAction( + $toDelete, + 'delete' + ))->executeAction(); + } + WCF::getDB()->commitTransaction(); + } } diff --git a/files/lib/system/event/listener/InfoCommandSuspensionsListener.class.php b/files/lib/system/event/listener/InfoCommandSuspensionsListener.class.php index c2e4aeb..18d270d 100644 --- a/files/lib/system/event/listener/InfoCommandSuspensionsListener.class.php +++ b/files/lib/system/event/listener/InfoCommandSuspensionsListener.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,48 +15,52 @@ namespace chat\system\event\listener; -use \chat\data\suspension\Suspension; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\system\WCF; +use chat\data\room\RoomCache; +use chat\data\suspension\Suspension; +use chat\data\suspension\SuspensionList; +use wcf\system\event\listener\IParameterizedEventListener; /** * Fetches information about the users suspensions */ -class InfoCommandSuspensionsListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - if (!$parameters['caller']->getPermission('admin.chat.canManageSuspensions')) { - return; - } +class InfoCommandSuspensionsListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + if (!$parameters['caller']->getPermission('admin.chat.canManageSuspensions')) { + return; + } - $target = $parameters['data']['user']; + $target = $parameters['data']['user']; - $parameters['data']['suspensions'] = [ ]; + $parameters['data']['suspensions'] = [ ]; - $suspensionList = new \chat\data\suspension\SuspensionList(); - $suspensionList->getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]); - $suspensionList->getConditionBuilder()->add('revoked IS NULL'); - $suspensionList->getConditionBuilder()->add('userID = ?', [ $target->userID ]); - $suspensionList->sqlOrderBy = 'expires ASC, time ASC'; - $suspensionList->readObjects(); + $suspensionList = new SuspensionList(); + $suspensionList->getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]); + $suspensionList->getConditionBuilder()->add('revoked IS NULL'); + $suspensionList->getConditionBuilder()->add('userID = ?', [ $target->userID ]); + $suspensionList->sqlOrderBy = 'expires ASC, time ASC'; + $suspensionList->readObjects(); - $suspensions = array_filter($suspensionList->getObjects(), function (Suspension $suspension) { - return $suspension->isActive(); - }); + $suspensions = \array_filter($suspensionList->getObjects(), static function (Suspension $suspension) { + return $suspension->isActive(); + }); - $parameters['data']['suspensions'] = array_values(array_map(function ($suspension) { - $room = \chat\data\room\RoomCache::getInstance()->getRoom($suspension->roomID); + $parameters['data']['suspensions'] = \array_values(\array_map(static function ($suspension) { + $room = RoomCache::getInstance()->getRoom($suspension->roomID); - $suspension = $suspension->jsonSerialize(); - if ($room) { - $suspension['room'] = [ 'title' => $room->getTitle() - , 'link' => $room->getLink() - ]; - } + $suspension = $suspension->jsonSerialize(); + if ($room) { + $suspension['room'] = [ + 'title' => $room->getTitle(), + 'link' => $room->getLink(), + ]; + } - return $suspension; - }, $suspensions)); - } + return $suspension; + }, $suspensions)); + } } diff --git a/files/lib/system/event/listener/RoomActionGetUsersModeratorListener.class.php b/files/lib/system/event/listener/RoomActionGetUsersModeratorListener.class.php index 38e17da..cd2a452 100644 --- a/files/lib/system/event/listener/RoomActionGetUsersModeratorListener.class.php +++ b/files/lib/system/event/listener/RoomActionGetUsersModeratorListener.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,31 +15,37 @@ namespace chat\system\event\listener; -use \chat\data\command\CommandCache; -use \wcf\system\cache\runtime\UserProfileRuntimeCache; +use chat\data\command\CommandCache; +use wcf\data\package\PackageCache; +use wcf\system\cache\runtime\UserProfileRuntimeCache; +use wcf\system\event\listener\IParameterizedEventListener; /** - * Adds moderator permissiosn to the user object. + * Adds moderator permissions to the user object. */ -class RoomActionGetUsersModeratorListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$users) { - $room = $eventObj->getObjects()[0]->getDecoratedObject(); +class RoomActionGetUsersModeratorListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$users) + { + $room = $eventObj->getObjects()[0]->getDecoratedObject(); - $package = \wcf\data\package\PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat'); - $muteCommand = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'mute')->getProcessor(); - $banCommand = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'ban')->getProcessor(); + $package = PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat'); + $muteCommand = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'mute')->getProcessor(); + $banCommand = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'ban')->getProcessor(); - $users = array_map(function (array $user) use ($room, $muteCommand, $banCommand) { - $userProfile = UserProfileRuntimeCache::getInstance()->getObject($user['userID']); - if (!isset($user['permissions'])) $user['permissions'] = []; + $users = \array_map(static function (array $user) use ($room, $muteCommand, $banCommand) { + $userProfile = UserProfileRuntimeCache::getInstance()->getObject($user['userID']); + if (!isset($user['permissions'])) { + $user['permissions'] = []; + } - $user['permissions']['canMute'] = $muteCommand->isAvailable($room, $userProfile); - $user['permissions']['canBan'] = $banCommand->isAvailable($room, $userProfile); + $user['permissions']['canMute'] = $muteCommand->isAvailable($room, $userProfile); + $user['permissions']['canBan'] = $banCommand->isAvailable($room, $userProfile); - return $user; - }, $users); - } + return $user; + }, $users); + } } diff --git a/files/lib/system/event/listener/RoomCanJoinBanListener.class.php b/files/lib/system/event/listener/RoomCanJoinBanListener.class.php index 19d4b7e..10de3aa 100644 --- a/files/lib/system/event/listener/RoomCanJoinBanListener.class.php +++ b/files/lib/system/event/listener/RoomCanJoinBanListener.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,25 +15,39 @@ namespace chat\system\event\listener; -use \chat\data\suspension\Suspension; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\suspension\Suspension; +use wcf\data\object\type\ObjectTypeCache; +use wcf\system\event\listener\IParameterizedEventListener; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\WCF; /** * Denies access to banned users. */ -class RoomCanJoinBanListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.suspension', 'be.bastelstu.chat.suspension.ban'); - if (!$objectTypeID) throw new \LogicException('Unreachable'); +class RoomCanJoinBanListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.suspension', + 'be.bastelstu.chat.suspension.ban' + ); + if (!$objectTypeID) { + throw new \LogicException('Unreachable'); + } - $suspensions = Suspension::getActiveSuspensionsByTriple($objectTypeID, $parameters['user']->getDecoratedObject(), $eventObj); - if (!empty($suspensions)) { - $parameters['result'] = new PermissionDeniedException(WCF::getLanguage()->getDynamicVariable('chat.suspension.info.be.bastelstu.chat.suspension.ban')); - } - } + $suspensions = Suspension::getActiveSuspensionsByTriple( + $objectTypeID, + $parameters['user']->getDecoratedObject(), + $eventObj + ); + if (!empty($suspensions)) { + $parameters['result'] = new PermissionDeniedException( + WCF::getLanguage()->getDynamicVariable('chat.suspension.info.be.bastelstu.chat.suspension.ban') + ); + } + } } diff --git a/files/lib/system/event/listener/RoomCanJoinUserLimitListener.class.php b/files/lib/system/event/listener/RoomCanJoinUserLimitListener.class.php index 699e660..f821a59 100644 --- a/files/lib/system/event/listener/RoomCanJoinUserLimitListener.class.php +++ b/files/lib/system/event/listener/RoomCanJoinUserLimitListener.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,29 +15,43 @@ namespace chat\system\event\listener; -use \chat\system\permission\PermissionHandler; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\user\User as ChatUser; +use chat\system\permission\PermissionHandler; +use wcf\system\event\listener\IParameterizedEventListener; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\WCF; /** * Denies access when room is full. */ -class RoomCanJoinUserLimitListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - if ($eventObj->userLimit === 0) return; +class RoomCanJoinUserLimitListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + if ($eventObj->userLimit === 0) { + return; + } - $users = $eventObj->getUsers(); - if (count($users) < $eventObj->userLimit) return; + $users = $eventObj->getUsers(); + if (\count($users) < $eventObj->userLimit) { + return; + } - $user = new \chat\data\user\User($parameters['user']->getDecoratedObject()); - if ($user->isInRoom($eventObj)) return; + $user = new ChatUser($parameters['user']->getDecoratedObject()); + if ($user->isInRoom($eventObj)) { + return; + } - $canIgnoreLimit = PermissionHandler::get($parameters['user'])->getPermission($eventObj, 'mod.canIgnoreUserLimit'); - if ($canIgnoreLimit) return; + $canIgnoreLimit = PermissionHandler::get($parameters['user'])->getPermission($eventObj, 'mod.canIgnoreUserLimit'); + if ($canIgnoreLimit) { + return; + } - $parameters['result'] = new PermissionDeniedException(WCF::getLanguage()->get('chat.error.roomFull')); - } + $parameters['result'] = new PermissionDeniedException( + WCF::getLanguage()->get('chat.error.roomFull') + ); + } } diff --git a/files/lib/system/event/listener/RoomCanSeeTemproomListener.class.php b/files/lib/system/event/listener/RoomCanSeeTemproomListener.class.php index cedfd65..780d2c6 100644 --- a/files/lib/system/event/listener/RoomCanSeeTemproomListener.class.php +++ b/files/lib/system/event/listener/RoomCanSeeTemproomListener.class.php @@ -1,6 +1,7 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. @@ -14,31 +15,43 @@ namespace chat\system\event\listener; -use \chat\system\permission\PermissionHandler; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\user\User as ChatUser; +use wcf\system\event\listener\IParameterizedEventListener; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\WCF; /** * Denies access to temporary rooms, unless invited. */ -class RoomCanSeeTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - if (!$eventObj->isTemporary) return; +class RoomCanSeeTemproomListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + if (!$eventObj->isTemporary) { + return; + } - $user = new \chat\data\user\User($parameters['user']->getDecoratedObject()); - if ($eventObj->ownerID === $user->userID) return; + $user = new ChatUser($parameters['user']->getDecoratedObject()); + if ($eventObj->ownerID === $user->userID) { + return; + } - $sql = "SELECT COUNT(*) - FROM chat1_room_temporary_invite - WHERE userID = ? - AND roomID = ?"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ $user->userID, $eventObj->roomID ]); - if ($statement->fetchSingleColumn() > 0) return; + $sql = "SELECT COUNT(*) + FROM chat1_room_temporary_invite + WHERE userID = ? + AND roomID = ?"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ + $user->userID, + $eventObj->roomID, + ]); + if ($statement->fetchSingleColumn() > 0) { + return; + } - $parameters['result'] = new PermissionDeniedException(); - } + $parameters['result'] = new PermissionDeniedException(); + } } diff --git a/files/lib/system/event/listener/RoomCanWritePubliclyMuteListener.class.php b/files/lib/system/event/listener/RoomCanWritePubliclyMuteListener.class.php index 75b92b6..1d2f491 100644 --- a/files/lib/system/event/listener/RoomCanWritePubliclyMuteListener.class.php +++ b/files/lib/system/event/listener/RoomCanWritePubliclyMuteListener.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,25 +15,39 @@ namespace chat\system\event\listener; -use \chat\data\suspension\Suspension; -use \wcf\data\object\type\ObjectTypeCache; -use \wcf\system\exception\PermissionDeniedException; -use \wcf\system\WCF; +use chat\data\suspension\Suspension; +use wcf\data\object\type\ObjectTypeCache; +use wcf\system\event\listener\IParameterizedEventListener; +use wcf\system\exception\PermissionDeniedException; +use wcf\system\WCF; /** * Denies access to muted users. */ -class RoomCanWritePubliclyMuteListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.suspension', 'be.bastelstu.chat.suspension.mute'); - if (!$objectTypeID) throw new \LogicException('Unreachable'); +class RoomCanWritePubliclyMuteListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName( + 'be.bastelstu.chat.suspension', + 'be.bastelstu.chat.suspension.mute' + ); + if (!$objectTypeID) { + throw new \LogicException('Unreachable'); + } - $suspensions = Suspension::getActiveSuspensionsByTriple($objectTypeID, $parameters['user']->getDecoratedObject(), $eventObj); - if (!empty($suspensions)) { - $parameters['result'] = new PermissionDeniedException(WCF::getLanguage()->getDynamicVariable('chat.suspension.info.be.bastelstu.chat.suspension.mute')); - } - } + $suspensions = Suspension::getActiveSuspensionsByTriple( + $objectTypeID, + $parameters['user']->getDecoratedObject(), + $eventObj + ); + if (!empty($suspensions)) { + $parameters['result'] = new PermissionDeniedException( + WCF::getLanguage()->getDynamicVariable('chat.suspension.info.be.bastelstu.chat.suspension.mute') + ); + } + } } diff --git a/files/lib/system/event/listener/RoomEditFormTemproomListener.class.php b/files/lib/system/event/listener/RoomEditFormTemproomListener.class.php index 0ee22a8..eb8c85a 100644 --- a/files/lib/system/event/listener/RoomEditFormTemproomListener.class.php +++ b/files/lib/system/event/listener/RoomEditFormTemproomListener.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,16 +15,21 @@ namespace chat\system\event\listener; +use wcf\system\event\listener\IParameterizedEventListener; +use wcf\system\exception\PermissionDeniedException; + /** * Disallow editing of temprooms in ACP. */ -class RoomEditFormTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - if ($eventObj->room->isTemporary) { - throw new \wcf\system\exception\PermissionDeniedException(); - } - } +class RoomEditFormTemproomListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + if ($eventObj->room->isTemporary) { + throw new PermissionDeniedException(); + } + } } diff --git a/files/lib/system/event/listener/RoomListPageTemproomListener.class.php b/files/lib/system/event/listener/RoomListPageTemproomListener.class.php index 974486f..b659e78 100644 --- a/files/lib/system/event/listener/RoomListPageTemproomListener.class.php +++ b/files/lib/system/event/listener/RoomListPageTemproomListener.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,14 +15,18 @@ namespace chat\system\event\listener; +use wcf\system\event\listener\IParameterizedEventListener; + /** * Hides temprooms in ACP. */ -class RoomListPageTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - $eventObj->objectList->getConditionBuilder()->add('isTemporary = ?', [ 0 ]); - } +class RoomListPageTemproomListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + $eventObj->objectList->getConditionBuilder()->add('isTemporary = ?', [ 0 ]); + } } diff --git a/files/lib/system/event/listener/SuspensionListPageTemproomListener.class.php b/files/lib/system/event/listener/SuspensionListPageTemproomListener.class.php index 493a115..8b5d8f8 100644 --- a/files/lib/system/event/listener/SuspensionListPageTemproomListener.class.php +++ b/files/lib/system/event/listener/SuspensionListPageTemproomListener.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,18 +15,21 @@ namespace chat\system\event\listener; -use \chat\data\room\Room; +use chat\data\room\Room; +use wcf\system\event\listener\IParameterizedEventListener; /** * Hides temprooms in ACP. */ -class SuspensionListPageTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { - /** - * @see \wcf\system\event\listener\IParameterizedEventListener::execute() - */ - public function execute($eventObj, $className, $eventName, array &$parameters) { - $eventObj->availableRooms = array_filter($eventObj->availableRooms, function (Room $room) { - return !$room->isTemporary; - }); - } +class SuspensionListPageTemproomListener implements IParameterizedEventListener +{ + /** + * @inheritDoc + */ + public function execute($eventObj, $className, $eventName, array &$parameters) + { + $eventObj->availableRooms = \array_filter($eventObj->availableRooms, static function (Room $room) { + return !$room->isTemporary; + }); + } } diff --git a/files/lib/system/message/type/AttachmentMessageType.class.php b/files/lib/system/message/type/AttachmentMessageType.class.php index 9517c5f..a9b22a2 100644 --- a/files/lib/system/message/type/AttachmentMessageType.class.php +++ b/files/lib/system/message/type/AttachmentMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,65 +15,89 @@ namespace chat\system\message\type; +use chat\data\message\Message; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\html\output\HtmlOutputProcessor; +use wcf\system\WCF; + /** * AttachmentMessageType represents a message with an attached file. */ -class AttachmentMessageType implements IMessageType, IDeletableMessageType { - use TCanSeeInSameRoom; +class AttachmentMessageType implements IMessageType, IDeletableMessageType +{ + use TCanSeeInSameRoom; - /** - * HtmlOutputProcessor to use. - * @var \wcf\system\html\output\HtmlOutputProcessor - */ - protected $processor = null; + /** + * HtmlOutputProcessor to use. + * @var \wcf\system\html\output\HtmlOutputProcessor + */ + protected $processor; - public function __construct() { - $this->processor = new \wcf\system\html\output\HtmlOutputProcessor(); - } + public function __construct() + { + $this->processor = new HtmlOutputProcessor(); + } - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Plain'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Plain'; + } - /** - * @inheritDoc - */ - public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canDelete(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - return $user->getPermission('mod.chat.canDelete'); - } + return $user->getPermission('mod.chat.canDelete'); + } - /** - * @see \chat\system\message\type\IMessageType::getPayload() - */ - public function getPayload(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function getPayload(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $payload = $message->payload; - $payload['formattedMessage'] = null; - $payload['plaintextMessage'] = null; + $payload = $message->payload; + $payload['formattedMessage'] = null; + $payload['plaintextMessage'] = null; - $parameters = [ 'message' => $message - , 'user' => $user - , 'payload' => $payload - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); + $parameters = [ + 'message' => $message, + 'user' => $user, + 'payload' => $payload, + ]; + EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); - if ($parameters['payload']['formattedMessage'] === null) { - $this->processor->setOutputType('text/html'); - $this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); - $parameters['payload']['formattedMessage'] = $this->processor->getHtml(); - } - if ($parameters['payload']['plaintextMessage'] === null) { - $this->processor->setOutputType('text/plain'); - $this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); - $parameters['payload']['plaintextMessage'] = $this->processor->getHtml(); - } + if ($parameters['payload']['formattedMessage'] === null) { + $this->processor->setOutputType('text/html'); + $this->processor->process( + $parameters['payload']['message'], + 'be.bastelstu.chat.message', + $message->messageID + ); + $parameters['payload']['formattedMessage'] = $this->processor->getHtml(); + } + if ($parameters['payload']['plaintextMessage'] === null) { + $this->processor->setOutputType('text/plain'); + $this->processor->process( + $parameters['payload']['message'], + 'be.bastelstu.chat.message', + $message->messageID + ); + $parameters['payload']['plaintextMessage'] = $this->processor->getHtml(); + } - return $parameters['payload']; - } + return $parameters['payload']; + } } diff --git a/files/lib/system/message/type/AwayMessageType.class.php b/files/lib/system/message/type/AwayMessageType.class.php index 3fb3acd..989185a 100644 --- a/files/lib/system/message/type/AwayMessageType.class.php +++ b/files/lib/system/message/type/AwayMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,67 +15,80 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * AwayMessageType represents a notice that a user now is away from chat. */ -class AwayMessageType implements IMessageType { - use TDefaultPayload; +class AwayMessageType implements IMessageType +{ + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Away'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Away'; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $roomIDs = array_map(function ($item) { - return $item['roomID']; - }, $message->payload['rooms']); + $roomIDs = \array_map(static function ($item) { + return $item['roomID']; + }, $message->payload['rooms']); - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => in_array($room->roomID, $roomIDs, true) - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => \in_array($room->roomID, $roomIDs, true), + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $roomIDs = array_map(function ($item) { - return $item['roomID']; - }, $message->payload['rooms']); + $roomIDs = \array_map(static function ($item) { + return $item['roomID']; + }, $message->payload['rooms']); - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => in_array($room->roomID, $roomIDs, true) - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => \in_array($room->roomID, $roomIDs, true), + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - return false; - } + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + return false; + } } diff --git a/files/lib/system/message/type/BackMessageType.class.php b/files/lib/system/message/type/BackMessageType.class.php index 3176542..b2087b4 100644 --- a/files/lib/system/message/type/BackMessageType.class.php +++ b/files/lib/system/message/type/BackMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,67 +15,80 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * BackMessageType represents a notice that a user now is now back. */ -class BackMessageType implements IMessageType { - use TDefaultPayload; +class BackMessageType implements IMessageType +{ + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Back'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Back'; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $roomIDs = array_map(function ($item) { - return $item['roomID']; - }, $message->payload['rooms']); + $roomIDs = \array_map(static function ($item) { + return $item['roomID']; + }, $message->payload['rooms']); - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => in_array($room->roomID, $roomIDs, true) - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => \in_array($room->roomID, $roomIDs, true), + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $roomIDs = array_map(function ($item) { - return $item['roomID']; - }, $message->payload['rooms']); + $roomIDs = \array_map(static function ($item) { + return $item['roomID']; + }, $message->payload['rooms']); - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => in_array($room->roomID, $roomIDs, true) - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => \in_array($room->roomID, $roomIDs, true), + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - return false; - } + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + return false; + } } diff --git a/files/lib/system/message/type/BroadcastMessageType.class.php b/files/lib/system/message/type/BroadcastMessageType.class.php index 96b1431..f4c0c44 100644 --- a/files/lib/system/message/type/BroadcastMessageType.class.php +++ b/files/lib/system/message/type/BroadcastMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,76 +15,94 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\html\output\HtmlOutputProcessor; +use wcf\system\WCF; /** * BroadcastMessageType represents a broadcasted message. */ -class BroadcastMessageType extends PlainMessageType { - /** - * HtmlOutputProcessor to use. - * @var \wcf\system\html\output\HtmlOutputProcessor - */ - protected $processor = null; +class BroadcastMessageType extends PlainMessageType +{ + /** + * HtmlOutputProcessor to use. + * @var \wcf\system\html\output\HtmlOutputProcessor + */ + protected $processor; - public function __construct() { - $this->processor = new \wcf\system\html\output\HtmlOutputProcessor(); - } + public function __construct() + { + $this->processor = new HtmlOutputProcessor(); + } - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Broadcast'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Broadcast'; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => true - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => true, + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => true - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => true, + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @inheritDoc - */ - public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canDelete(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - return $user->getPermission('mod.chat.canDelete'); - } + return $user->getPermission('mod.chat.canDelete'); + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - return false; - } + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + return false; + } } diff --git a/files/lib/system/message/type/ChatUpdateMessageType.class.php b/files/lib/system/message/type/ChatUpdateMessageType.class.php index 7a2eb8f..e74a8a1 100644 --- a/files/lib/system/message/type/ChatUpdateMessageType.class.php +++ b/files/lib/system/message/type/ChatUpdateMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,41 +15,46 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; /** * ChatUpdateMessageType informs the chat about a back end update. */ -class ChatUpdateMessageType implements IMessageType { - use TDefaultPayload; +class ChatUpdateMessageType implements IMessageType +{ + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/ChatUpdate'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/ChatUpdate'; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - return true; - } + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + return true; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - return true; - } + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + return true; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - return false; - } + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + return false; + } } diff --git a/files/lib/system/message/type/ColorMessageType.class.php b/files/lib/system/message/type/ColorMessageType.class.php index 7a8cb36..19fd48a 100644 --- a/files/lib/system/message/type/ColorMessageType.class.php +++ b/files/lib/system/message/type/ColorMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,50 +15,60 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * ColorMessageType represents a color message. */ -class ColorMessageType implements IMessageType { - use TDefaultPayload; +class ColorMessageType implements IMessageType +{ + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Color'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Color'; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => true - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => true, + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - return false; - } + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + return false; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - return false; - } + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + return false; + } } diff --git a/files/lib/system/message/type/IDeletableMessageType.class.php b/files/lib/system/message/type/IDeletableMessageType.class.php index 54310e0..25e0cf7 100644 --- a/files/lib/system/message/type/IDeletableMessageType.class.php +++ b/files/lib/system/message/type/IDeletableMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,20 +15,21 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use wcf\data\user\UserProfile; /** * An IDeletableMessageType defines that the implementing message type supports message deletion. */ -interface IDeletableMessageType extends IMessageType { - /** - * Returns whether the given user may delete the given message. If no - * user is given the active user should be assumed. - * - * @param Message $message - * @param UserProfile $user - * @return boolean - */ - public function canDelete(Message $message, UserProfile $user = null); +interface IDeletableMessageType extends IMessageType +{ + /** + * Returns whether the given user may delete the given message. If no + * user is given the active user should be assumed. + * + * @param Message $message + * @param UserProfile $user + * @return boolean + */ + public function canDelete(Message $message, ?UserProfile $user = null); } diff --git a/files/lib/system/message/type/IMessageType.class.php b/files/lib/system/message/type/IMessageType.class.php index 2f444c4..38f8b67 100644 --- a/files/lib/system/message/type/IMessageType.class.php +++ b/files/lib/system/message/type/IMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,61 +15,62 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; /** * An IMessageType defines how a message of a certain type is acted upon. */ -interface IMessageType { - /** - * Returns the name of the JavaScript module. - * - * @return string - */ - public function getJavaScriptModuleName(); +interface IMessageType +{ + /** + * Returns the name of the JavaScript module. + * + * @return string + */ + public function getJavaScriptModuleName(); - /** - * Returns whether the given user may see the given message. If no - * user is given the active user should be assumed. - * - * @param Message $message - * @param Room $room - * @param UserProfile $user - * @return boolean - */ - public function canSee(Message $message, Room $room, UserProfile $user = null); + /** + * Returns whether the given user may see the given message. If no + * user is given the active user should be assumed. + * + * @param Message $message + * @param Room $room + * @param UserProfile $user + * @return boolean + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null); - /** - * Returns whether the given user may see the given message in the - * protocol. If no user is given the active user should be assumed. - * - * @param Message $message - * @param Room $room - * @param UserProfile $user - * @return boolean - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null); + /** + * Returns whether the given user may see the given message in the + * protocol. If no user is given the active user should be assumed. + * + * @param Message $message + * @param Room $room + * @param UserProfile $user + * @return boolean + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null); - /** - * Returns a filtered / extended version of the message payload. If no - * user is given the active user should be assumed. - * - * @param Message $message - * @param UserProfile $user - * @return array - */ - public function getPayload(Message $message, UserProfile $user = null); + /** + * Returns a filtered / extended version of the message payload. If no + * user is given the active user should be assumed. + * + * @param Message $message + * @param UserProfile $user + * @return array + */ + public function getPayload(Message $message, ?UserProfile $user = null); - /** - * Returns whether this message type supports fast select of applicable messages: - * If this method returns true messages with this message type will only be selected - * if the room ID matches. If this method returns false messages will always be selected - * and filtered afterwards using canSee(). Returning false is useful e.g. for broadcasts. - * - * You SHOULD return true whenever possible, for performance reasons. You MUST only return - * true if canSee() would return false if the given $room is not equal to the $message's room. - */ - public function supportsFastSelect(); + /** + * Returns whether this message type supports fast select of applicable messages: + * If this method returns true messages with this message type will only be selected + * if the room ID matches. If this method returns false messages will always be selected + * and filtered afterwards using canSee(). Returning false is useful e.g. for broadcasts. + * + * You SHOULD return true whenever possible, for performance reasons. You MUST only return + * true if canSee() would return false if the given $room is not equal to the $message's room. + */ + public function supportsFastSelect(); } diff --git a/files/lib/system/message/type/InfoMessageType.class.php b/files/lib/system/message/type/InfoMessageType.class.php index a8c329e..d76b2d3 100644 --- a/files/lib/system/message/type/InfoMessageType.class.php +++ b/files/lib/system/message/type/InfoMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -17,14 +18,16 @@ /** * InfoMessageType represents the reply to InfoCommand. */ -class InfoMessageType implements IMessageType { - use TCanSeeCreator; - use TDefaultPayload; +class InfoMessageType implements IMessageType +{ + use TCanSeeCreator; + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Info'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Info'; + } } diff --git a/files/lib/system/message/type/JoinMessageType.class.php b/files/lib/system/message/type/JoinMessageType.class.php index 87e2018..1561604 100644 --- a/files/lib/system/message/type/JoinMessageType.class.php +++ b/files/lib/system/message/type/JoinMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -17,14 +18,16 @@ /** * JoinMessageType represents a join message. */ -class JoinMessageType implements IMessageType { - use TCanSeeInSameRoom; - use TDefaultPayload; +class JoinMessageType implements IMessageType +{ + use TCanSeeInSameRoom; + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Join'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Join'; + } } diff --git a/files/lib/system/message/type/LeaveMessageType.class.php b/files/lib/system/message/type/LeaveMessageType.class.php index c3452ae..081b7b1 100644 --- a/files/lib/system/message/type/LeaveMessageType.class.php +++ b/files/lib/system/message/type/LeaveMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -17,14 +18,16 @@ /** * LeaveMessageType represents a leave message. */ -class LeaveMessageType implements IMessageType { - use TCanSeeInSameRoom; - use TDefaultPayload; +class LeaveMessageType implements IMessageType +{ + use TCanSeeInSameRoom; + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Leave'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Leave'; + } } diff --git a/files/lib/system/message/type/MeMessageType.class.php b/files/lib/system/message/type/MeMessageType.class.php index 141fc26..9c868a4 100644 --- a/files/lib/system/message/type/MeMessageType.class.php +++ b/files/lib/system/message/type/MeMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,26 +15,35 @@ namespace chat\system\message\type; +use chat\data\message\Message; +use wcf\data\user\UserProfile; +use wcf\system\WCF; + /** * MeMessageType represents an action message. */ -class MeMessageType implements IMessageType, IDeletableMessageType { - use TCanSeeInSameRoom; - use TDefaultPayload; +class MeMessageType implements IMessageType, IDeletableMessageType +{ + use TCanSeeInSameRoom; + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Me'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Me'; + } - /** - * @inheritDoc - */ - public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canDelete(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - return $user->getPermission('mod.chat.canDelete'); - } + return $user->getPermission('mod.chat.canDelete'); + } } diff --git a/files/lib/system/message/type/PlainMessageType.class.php b/files/lib/system/message/type/PlainMessageType.class.php index 7e6a08a..2448000 100644 --- a/files/lib/system/message/type/PlainMessageType.class.php +++ b/files/lib/system/message/type/PlainMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,65 +15,89 @@ namespace chat\system\message\type; +use chat\data\message\Message; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\html\output\HtmlOutputProcessor; +use wcf\system\WCF; + /** * PlainMessageType represents a normal message. */ -class PlainMessageType implements IMessageType, IDeletableMessageType { - use TCanSeeInSameRoom; +class PlainMessageType implements IMessageType, IDeletableMessageType +{ + use TCanSeeInSameRoom; - /** - * HtmlOutputProcessor to use. - * @var \wcf\system\html\output\HtmlOutputProcessor - */ - protected $processor = null; + /** + * HtmlOutputProcessor to use. + * @var \wcf\system\html\output\HtmlOutputProcessor + */ + protected $processor; - public function __construct() { - $this->processor = new \wcf\system\html\output\HtmlOutputProcessor(); - } + public function __construct() + { + $this->processor = new HtmlOutputProcessor(); + } - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Plain'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Plain'; + } - /** - * @inheritDoc - */ - public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canDelete(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - return $user->getPermission('mod.chat.canDelete'); - } + return $user->getPermission('mod.chat.canDelete'); + } - /** - * @see \chat\system\message\type\IMessageType::getPayload() - */ - public function getPayload(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function getPayload(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $payload = $message->payload; - $payload['formattedMessage'] = null; - $payload['plaintextMessage'] = null; + $payload = $message->payload; + $payload['formattedMessage'] = null; + $payload['plaintextMessage'] = null; - $parameters = [ 'message' => $message - , 'user' => $user - , 'payload' => $payload - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); + $parameters = [ + 'message' => $message, + 'user' => $user, + 'payload' => $payload, + ]; + EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); - if ($parameters['payload']['formattedMessage'] === null) { - $this->processor->setOutputType('text/html'); - $this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); - $parameters['payload']['formattedMessage'] = $this->processor->getHtml(); - } - if ($parameters['payload']['plaintextMessage'] === null) { - $this->processor->setOutputType('text/plain'); - $this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); - $parameters['payload']['plaintextMessage'] = $this->processor->getHtml(); - } + if ($parameters['payload']['formattedMessage'] === null) { + $this->processor->setOutputType('text/html'); + $this->processor->process( + $parameters['payload']['message'], + 'be.bastelstu.chat.message', + $message->messageID + ); + $parameters['payload']['formattedMessage'] = $this->processor->getHtml(); + } + if ($parameters['payload']['plaintextMessage'] === null) { + $this->processor->setOutputType('text/plain'); + $this->processor->process( + $parameters['payload']['message'], + 'be.bastelstu.chat.message', + $message->messageID + ); + $parameters['payload']['plaintextMessage'] = $this->processor->getHtml(); + } - return $parameters['payload']; - } + return $parameters['payload']; + } } diff --git a/files/lib/system/message/type/SuspendMessageType.class.php b/files/lib/system/message/type/SuspendMessageType.class.php index 531cb1e..168c8d1 100644 --- a/files/lib/system/message/type/SuspendMessageType.class.php +++ b/files/lib/system/message/type/SuspendMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,75 +15,92 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * SuspendMessageType informs about suspensions. */ -class SuspendMessageType implements IMessageType { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Suspend'; - } +class SuspendMessageType implements IMessageType +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Suspend'; + } - /** - * @see \chat\system\message\type\IMessageType::getPayload() - */ - public function getPayload(Message $message, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function getPayload(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $payload = $message->payload; - unset($payload['roomIDs']); + $payload = $message->payload; + unset($payload['roomIDs']); - $parameters = [ 'message' => $message - , 'user' => $user - , 'payload' => $payload - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); + $parameters = [ + 'message' => $message, + 'user' => $user, + 'payload' => $payload, + ]; + EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); - return $parameters['payload']; - } + return $parameters['payload']; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => in_array($room->roomID, $message->payload['roomIDs'], true) - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => \in_array($room->roomID, $message->payload['roomIDs'], true), + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => in_array($room->roomID, $message->payload['roomIDs'], true) - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => \in_array($room->roomID, $message->payload['roomIDs'], true), + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - return false; - } + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + return false; + } } diff --git a/files/lib/system/message/type/TCanSeeCreator.class.php b/files/lib/system/message/type/TCanSeeCreator.class.php index 3dd3bea..81e423a 100644 --- a/files/lib/system/message/type/TCanSeeCreator.class.php +++ b/files/lib/system/message/type/TCanSeeCreator.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,54 +15,68 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * Adds a default canSee implementation that checks whether the message was created by the user and * whether the message belongs to the user's active room. */ -trait TCanSeeCreator { - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); +trait TCanSeeCreator +{ + /** + * @see \chat\system\message\type\IMessageType::canSee() + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => $user->userID === $message->userID && $message->getRoom()->roomID === $room->roomID - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => $user->userID === $message->userID && $message->getRoom()->roomID === $room->roomID, + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @see \chat\system\message\type\IMessageType::canSeeInLog() + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => false - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => false, + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - $parameters = [ 'result' => true ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); + /** + * @see \chat\system\message\type\IMessageType::supportsFastSelect() + */ + public function supportsFastSelect() + { + $parameters = [ + 'result' => true, + ]; + EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); - return $parameters['result']; - } + return $parameters['result']; + } } diff --git a/files/lib/system/message/type/TCanSeeInSameRoom.class.php b/files/lib/system/message/type/TCanSeeInSameRoom.class.php index 13385ec..6f3172e 100644 --- a/files/lib/system/message/type/TCanSeeInSameRoom.class.php +++ b/files/lib/system/message/type/TCanSeeInSameRoom.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,53 +15,67 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * Adds a default canSee implementation that checks whether the message belongs to the user's active room. */ -trait TCanSeeInSameRoom { - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); +trait TCanSeeInSameRoom +{ + /** + * @see \chat\system\message\type\IMessageType::canSee() + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => $message->getRoom()->roomID === $room->roomID - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => $message->getRoom()->roomID === $room->roomID, + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @see \chat\system\message\type\IMessageType::canSeeInLog() + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => $message->getRoom()->roomID === $room->roomID - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => $message->getRoom()->roomID === $room->roomID, + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - $parameters = [ 'result' => true ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); + /** + * @see \chat\system\message\type\IMessageType::supportsFastSelect() + */ + public function supportsFastSelect() + { + $parameters = [ + 'result' => true, + ]; + EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); - return $parameters['result']; - } + return $parameters['result']; + } } diff --git a/files/lib/system/message/type/TDefaultPayload.class.php b/files/lib/system/message/type/TDefaultPayload.class.php index 42e1451..5e368e1 100644 --- a/files/lib/system/message/type/TDefaultPayload.class.php +++ b/files/lib/system/message/type/TDefaultPayload.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,24 +15,34 @@ namespace chat\system\message\type; +use chat\data\message\Message; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; + /** * Default implementation for 'getPayload'. */ -trait TDefaultPayload { - /** - * @see \chat\system\message\type\IMessageType::getPayload() - */ - public function getPayload(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); +trait TDefaultPayload +{ + /** + * @see \chat\system\message\type\IMessageType::getPayload() + */ + public function getPayload(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $payload = $message->payload; + $payload = $message->payload; - $parameters = [ 'message' => $message - , 'user' => $user - , 'payload' => $payload - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); + $parameters = [ + 'message' => $message, + 'user' => $user, + 'payload' => $payload, + ]; + EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); - return $parameters['payload']; - } + return $parameters['payload']; + } } diff --git a/files/lib/system/message/type/TeamMessageType.class.php b/files/lib/system/message/type/TeamMessageType.class.php index 645fe1b..55b16f8 100644 --- a/files/lib/system/message/type/TeamMessageType.class.php +++ b/files/lib/system/message/type/TeamMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,76 +15,94 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\html\output\HtmlOutputProcessor; +use wcf\system\WCF; /** * TeamMessageType represents a team internal message. */ -class TeamMessageType extends PlainMessageType { - /** - * HtmlOutputProcessor to use. - * @var \wcf\system\html\output\HtmlOutputProcessor - */ - protected $processor = null; +class TeamMessageType extends PlainMessageType +{ + /** + * HtmlOutputProcessor to use. + * @var \wcf\system\html\output\HtmlOutputProcessor + */ + protected $processor; - public function __construct() { - $this->processor = new \wcf\system\html\output\HtmlOutputProcessor(); - } + public function __construct() + { + $this->processor = new HtmlOutputProcessor(); + } - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Team'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Team'; + } - /** - * @inheritDoc - */ - public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canDelete(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - return $user->getPermission('mod.chat.canDelete'); - } + return $user->getPermission('mod.chat.canDelete'); + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => $user->getPermission('mod.chat.canTeam') - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => $user->getPermission('mod.chat.canTeam'), + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => $user->getPermission('mod.chat.canTeam') - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => $user->getPermission('mod.chat.canTeam'), + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - return false; - } + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + return false; + } } diff --git a/files/lib/system/message/type/TemproomCreatedMessageType.class.php b/files/lib/system/message/type/TemproomCreatedMessageType.class.php index e557719..029e883 100644 --- a/files/lib/system/message/type/TemproomCreatedMessageType.class.php +++ b/files/lib/system/message/type/TemproomCreatedMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -17,14 +18,16 @@ /** * TemproomCreatedMessageType informs a user that a temporary room was created. */ -class TemproomCreatedMessageType implements IMessageType { - use TCanSeeCreator; - use TDefaultPayload; +class TemproomCreatedMessageType implements IMessageType +{ + use TCanSeeCreator; + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/TemproomCreated'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/TemproomCreated'; + } } diff --git a/files/lib/system/message/type/TemproomInvitedMessageType.class.php b/files/lib/system/message/type/TemproomInvitedMessageType.class.php index 89e65ee..6b67923 100644 --- a/files/lib/system/message/type/TemproomInvitedMessageType.class.php +++ b/files/lib/system/message/type/TemproomInvitedMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,82 +15,102 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * TemproomInvitedMessageType informs a user that they were invited to a temporary room. */ -class TemproomInvitedMessageType implements IMessageType { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/TemproomInvited'; - } +class TemproomInvitedMessageType implements IMessageType +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/TemproomInvited'; + } - /** - * @inheritDoc - */ - public function getPayload(Message $message, UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function getPayload(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $payload = $message->payload; - $room = $message->getRoom(); - $payload['room'] = [ 'roomID' => $room->roomID - , 'title' => $room->title - , 'link' => $room->getLink() - ]; + $payload = $message->payload; + $room = $message->getRoom(); + $payload['room'] = [ + 'roomID' => $room->roomID, + 'title' => $room->title, + 'link' => $room->getLink(), + ]; - $parameters = [ 'message' => $message - , 'user' => $user - , 'payload' => $payload - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); + $parameters = [ + 'message' => $message, + 'user' => $user, + 'payload' => $payload, + ]; + EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); - return $parameters['payload']; - } + return $parameters['payload']; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => $user->userID === $message->userID || $user->userID === $message->payload['recipient'] - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => $user->userID === $message->userID || $user->userID === $message->payload['recipient'], + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => false - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => false, + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - $parameters = [ 'result' => false ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + $parameters = [ + 'result' => false, + ]; + EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); - return $parameters['result']; - } + return $parameters['result']; + } } diff --git a/files/lib/system/message/type/TombstoneMessageType.class.php b/files/lib/system/message/type/TombstoneMessageType.class.php index 3567070..24429dc 100644 --- a/files/lib/system/message/type/TombstoneMessageType.class.php +++ b/files/lib/system/message/type/TombstoneMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,50 +15,60 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * TombstoneMessageType marks a different message as dead. */ -class TombstoneMessageType implements IMessageType { - use TDefaultPayload; +class TombstoneMessageType implements IMessageType +{ + use TDefaultPayload; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Tombstone'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Tombstone'; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => true - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => true, + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - return false; - } + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + return false; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - return false; - } + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + return false; + } } diff --git a/files/lib/system/message/type/UnsuspendMessageType.class.php b/files/lib/system/message/type/UnsuspendMessageType.class.php index bda6c55..d31f3bf 100644 --- a/files/lib/system/message/type/UnsuspendMessageType.class.php +++ b/files/lib/system/message/type/UnsuspendMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,75 +15,92 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * UnsuspendMessageType informs about removed suspensions. */ -class UnsuspendMessageType implements IMessageType { - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Unsuspend'; - } +class UnsuspendMessageType implements IMessageType +{ + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Unsuspend'; + } - /** - * @see \chat\system\message\type\IMessageType::getPayload() - */ - public function getPayload(Message $message, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function getPayload(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $payload = $message->payload; - unset($payload['roomIDs']); + $payload = $message->payload; + unset($payload['roomIDs']); - $parameters = [ 'message' => $message - , 'user' => $user - , 'payload' => $payload - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); + $parameters = [ + 'message' => $message, + 'user' => $user, + 'payload' => $payload, + ]; + EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); - return $parameters['payload']; - } + return $parameters['payload']; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => in_array($room->roomID, $message->payload['roomIDs'], true) - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => \in_array($room->roomID, $message->payload['roomIDs'], true), + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => in_array($room->roomID, $message->payload['roomIDs'], true) - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => \in_array($room->roomID, $message->payload['roomIDs'], true), + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - return false; - } + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + return false; + } } diff --git a/files/lib/system/message/type/WhereMessageType.class.php b/files/lib/system/message/type/WhereMessageType.class.php index 238695c..497a0d7 100644 --- a/files/lib/system/message/type/WhereMessageType.class.php +++ b/files/lib/system/message/type/WhereMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,45 +15,55 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\RoomCache; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\RoomCache; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\WCF; /** * WhereMessageType represents the reply to WhereCommand. */ -class WhereMessageType implements IMessageType { - use TCanSeeCreator; +class WhereMessageType implements IMessageType +{ + use TCanSeeCreator; - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Where'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Where'; + } - /** - * @inheritDoc - */ - public function getPayload(Message $message, UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function getPayload(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $payload = $message->payload; - $payload = array_map(function ($item) { - $room = RoomCache::getInstance()->getRoom($item['roomID']); - $item['room'] = [ 'roomID' => $room->roomID - , 'title' => $room->title - , 'link' => $room->getLink() - ]; - return $item; - }, $payload); + $payload = $message->payload; + $payload = \array_map(static function ($item) { + $room = RoomCache::getInstance()->getRoom($item['roomID']); + $item['room'] = [ + 'roomID' => $room->roomID, + 'title' => $room->title, + 'link' => $room->getLink(), + ]; - $parameters = [ 'message' => $message - , 'user' => $user - , 'payload' => $payload - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); + return $item; + }, $payload); - return $parameters['payload']; - } + $parameters = [ + 'message' => $message, + 'user' => $user, + 'payload' => $payload, + ]; + EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); + + return $parameters['payload']; + } } diff --git a/files/lib/system/message/type/WhisperMessageType.class.php b/files/lib/system/message/type/WhisperMessageType.class.php index b80ce86..7fdde75 100644 --- a/files/lib/system/message/type/WhisperMessageType.class.php +++ b/files/lib/system/message/type/WhisperMessageType.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,100 +15,129 @@ namespace chat\system\message\type; -use \chat\data\message\Message; -use \chat\data\room\Room; -use \wcf\data\user\UserProfile; +use chat\data\message\Message; +use chat\data\room\Room; +use wcf\data\user\UserProfile; +use wcf\system\event\EventHandler; +use wcf\system\html\output\HtmlOutputProcessor; +use wcf\system\WCF; /** * WhisperMessageType represents a whispered message. */ -class WhisperMessageType implements IMessageType { - /** - * HtmlOutputProcessor to use. - * @var \wcf\system\html\output\HtmlOutputProcessor - */ - protected $processor = null; +class WhisperMessageType implements IMessageType +{ + /** + * HtmlOutputProcessor to use. + * @var \wcf\system\html\output\HtmlOutputProcessor + */ + protected $processor; - public function __construct() { - $this->processor = new \wcf\system\html\output\HtmlOutputProcessor(); - } + public function __construct() + { + $this->processor = new HtmlOutputProcessor(); + } - /** - * @inheritDoc - */ - public function getJavaScriptModuleName() { - return 'Bastelstu.be/Chat/MessageType/Whisper'; - } + /** + * @inheritDoc + */ + public function getJavaScriptModuleName() + { + return 'Bastelstu.be/Chat/MessageType/Whisper'; + } - /** - * @see \chat\system\message\type\IMessageType::getPayload() - */ - public function getPayload(Message $message, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function getPayload(Message $message, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $payload = $message->payload; - $payload['formattedMessage'] = null; - $payload['plaintextMessage'] = null; + $payload = $message->payload; + $payload['formattedMessage'] = null; + $payload['plaintextMessage'] = null; - $parameters = [ 'message' => $message - , 'user' => $user - , 'payload' => $payload - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); + $parameters = [ + 'message' => $message, + 'user' => $user, + 'payload' => $payload, + ]; + EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); - if ($parameters['payload']['formattedMessage'] === null) { - $this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); - $parameters['payload']['formattedMessage'] = $this->processor->getHtml(); - } + if ($parameters['payload']['formattedMessage'] === null) { + $this->processor->process( + $parameters['payload']['message'], + 'be.bastelstu.chat.message', + $message->messageID + ); + $parameters['payload']['formattedMessage'] = $this->processor->getHtml(); + } - if ($parameters['payload']['plaintextMessage'] === null) { - $this->processor->setOutputType('text/plain'); - $this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); - $parameters['payload']['plaintextMessage'] = $this->processor->getHtml(); - } + if ($parameters['payload']['plaintextMessage'] === null) { + $this->processor->setOutputType('text/plain'); + $this->processor->process( + $parameters['payload']['message'], + 'be.bastelstu.chat.message', + $message->messageID + ); + $parameters['payload']['plaintextMessage'] = $this->processor->getHtml(); + } - return $parameters['payload']; - } + return $parameters['payload']; + } - /** - * @see \chat\system\message\type\IMessageType::canSee() - */ - public function canSee(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSee(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => $user->userID === $message->userID || $user->userID === $message->payload['recipient'] - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => $user->userID === $message->userID || $user->userID === $message->payload['recipient'], + ]; + EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see \chat\system\message\type\IMessageType::canSeeInLog() - */ - public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { - if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); + /** + * @inheritDoc + */ + public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } - $parameters = [ 'message' => $message - , 'room' => $room - , 'user' => $user - , 'canSee' => false - ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); + $parameters = [ + 'message' => $message, + 'room' => $room, + 'user' => $user, + 'canSee' => false, + ]; + EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); - return $parameters['canSee']; - } + return $parameters['canSee']; + } - /** - * @see»\chat\system\message\type\IMessageType::supportsFastSelect() - */ - public function supportsFastSelect() { - $parameters = [ 'result' => false ]; - \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); + /** + * @inheritDoc + */ + public function supportsFastSelect() + { + $parameters = [ + 'result' => false, + ]; + EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); - return $parameters['result']; - } + return $parameters['result']; + } } diff --git a/files/lib/system/page/handler/LogPageHandler.class.php b/files/lib/system/page/handler/LogPageHandler.class.php index 9f98be0..ab63e73 100644 --- a/files/lib/system/page/handler/LogPageHandler.class.php +++ b/files/lib/system/page/handler/LogPageHandler.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,52 +15,85 @@ namespace chat\system\page\handler; -use \chat\data\room\RoomCache; -use \wcf\system\request\LinkHandler; -use \wcf\system\WCF; +use chat\data\room\RoomCache; +use wcf\data\page\Page; +use wcf\data\user\online\UserOnline; +use wcf\system\page\handler\AbstractLookupPageHandler; +use wcf\system\page\handler\IOnlineLocationPageHandler; +use wcf\system\page\handler\TOnlineLocationPageHandler; +use wcf\system\request\LinkHandler; +use wcf\system\WCF; /** * Allows to choose a room in the menu item management. */ -class LogPageHandler extends \wcf\system\page\handler\AbstractLookupPageHandler implements \wcf\system\page\handler\IOnlineLocationPageHandler { - use TRoomPageHandler; - use \wcf\system\page\handler\TOnlineLocationPageHandler; +class LogPageHandler extends AbstractLookupPageHandler implements IOnlineLocationPageHandler +{ + use TRoomPageHandler; + use TOnlineLocationPageHandler; - /** - * @inheritDoc - */ - public function getLink($objectID) { - $room = RoomCache::getInstance()->getRoom($objectID); - if ($room === null) throw new \InvalidArgumentException('Invalid room ID given'); + /** + * @inheritDoc + */ + public function getLink($objectID) + { + $room = RoomCache::getInstance()->getRoom($objectID); + if ($room === null) { + throw new \InvalidArgumentException('Invalid room ID given'); + } - $link = LinkHandler::getInstance()->getLink('Log', [ 'application' => 'chat' - , 'object' => $room - ]); - return $link; - } + return LinkHandler::getInstance()->getLink( + 'Log', + [ + 'application' => 'chat', + 'object' => $room, + ] + ); + } - /** - * @inheritDoc - */ - public function isVisible($objectID = null) { - if (!WCF::getUser()->userID) return false; + /** + * @inheritDoc + */ + public function isVisible($objectID = null) + { + if (!WCF::getUser()->userID) { + return false; + } - if ($objectID === null) throw new \InvalidArgumentException('Invalid room ID given'); - $room = RoomCache::getInstance()->getRoom($objectID); - if ($room === null) throw new \InvalidArgumentException('Invalid room ID given'); + if ($objectID === null) { + throw new \InvalidArgumentException('Invalid room ID given'); + } + $room = RoomCache::getInstance()->getRoom($objectID); + if ($room === null) { + throw new \InvalidArgumentException('Invalid room ID given'); + } - return $room->canSee() && $room->canSeeLog(); - } + return $room->canSee() && $room->canSeeLog(); + } - /** - * @inheritDoc - */ - public function getOnlineLocation(\wcf\data\page\Page $page, \wcf\data\user\online\UserOnline $user) { - if ($user->pageObjectID === null) return ''; - $room = RoomCache::getInstance()->getRoom($user->pageObjectID); - if ($room === null) return ''; - if (!$room->canSeeLog()) return ''; + /** + * @inheritDoc + */ + public function getOnlineLocation(Page $page, UserOnline $user) + { + if ($user->pageObjectID === null) { + return ''; + } - return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, [ 'room' => $room ]); - } + $room = RoomCache::getInstance()->getRoom($user->pageObjectID); + + if ($room === null) { + return ''; + } + if (!$room->canSeeLog()) { + return ''; + } + + return WCF::getLanguage()->getDynamicVariable( + 'wcf.page.onlineLocation.' . $page->identifier, + [ + 'room' => $room, + ] + ); + } } diff --git a/files/lib/system/page/handler/RoomListPageHandler.class.php b/files/lib/system/page/handler/RoomListPageHandler.class.php index 562b0f5..2501fcf 100644 --- a/files/lib/system/page/handler/RoomListPageHandler.class.php +++ b/files/lib/system/page/handler/RoomListPageHandler.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,34 +15,39 @@ namespace chat\system\page\handler; -use \chat\data\room\Room; -use \chat\data\room\RoomCache; -use \wcf\system\WCF; +use chat\data\room\Room; +use chat\data\room\RoomCache; +use wcf\system\page\handler\AbstractMenuPageHandler; /** * Shows the number of chatters in the RoomList menu item. */ -class RoomListPageHandler extends \wcf\system\page\handler\AbstractMenuPageHandler { - /** - * @inheritDoc - */ - public function getOutstandingItemCount($objectID = null) { - $rooms = RoomCache::getInstance()->getRooms(); - $users = array_map(function (Room $room) { - return array_keys($room->getUsers()); - }, array_filter($rooms, function (Room $room) { - return $room->canSee(); - })); +class RoomListPageHandler extends AbstractMenuPageHandler +{ + /** + * @inheritDoc + */ + public function getOutstandingItemCount($objectID = null) + { + $rooms = RoomCache::getInstance()->getRooms(); + $users = \array_map(static function (Room $room) { + return \array_keys($room->getUsers()); + }, \array_filter($rooms, static function (Room $room) { + return $room->canSee(); + })); - if (empty($users)) return 0; + if (empty($users)) { + return 0; + } - return count(array_unique(call_user_func_array('array_merge', $users))); - } + return \count(\array_unique(\call_user_func_array('array_merge', $users))); + } - /** - * @inheritDoc - */ - public function isVisible($objectID = null) { - return Room::canSeeAny(); - } + /** + * @inheritDoc + */ + public function isVisible($objectID = null) + { + return Room::canSeeAny(); + } } diff --git a/files/lib/system/page/handler/RoomPageHandler.class.php b/files/lib/system/page/handler/RoomPageHandler.class.php index c309d53..8e3e52e 100644 --- a/files/lib/system/page/handler/RoomPageHandler.class.php +++ b/files/lib/system/page/handler/RoomPageHandler.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 2 @@ -14,55 +15,86 @@ namespace chat\system\page\handler; -use \chat\data\room\RoomCache; -use \wcf\system\WCF; +use chat\data\room\RoomCache; +use wcf\data\page\Page; +use wcf\data\user\online\UserOnline; +use wcf\system\page\handler\AbstractLookupPageHandler; +use wcf\system\page\handler\IOnlineLocationPageHandler; +use wcf\system\page\handler\TOnlineLocationPageHandler; +use wcf\system\WCF; /** * Allows to choose a room in the menu item management. */ -class RoomPageHandler extends \wcf\system\page\handler\AbstractLookupPageHandler implements \wcf\system\page\handler\IOnlineLocationPageHandler { - use TRoomPageHandler; - use \wcf\system\page\handler\TOnlineLocationPageHandler; +class RoomPageHandler extends AbstractLookupPageHandler implements IOnlineLocationPageHandler +{ + use TRoomPageHandler; + use TOnlineLocationPageHandler; - /** - * @inheritDoc - */ - public function getOutstandingItemCount($objectID = null) { - return count(RoomCache::getInstance()->getRoom($objectID)->getUsers()); - } + /** + * @inheritDoc + */ + public function getOutstandingItemCount($objectID = null) + { + return \count(RoomCache::getInstance()->getRoom($objectID)->getUsers()); + } - /** - * @inheritDoc - */ - public function getLink($objectID) { - $room = RoomCache::getInstance()->getRoom($objectID); - if ($room === null) throw new \InvalidArgumentException('Invalid room ID given'); + /** + * @inheritDoc + */ + public function getLink($objectID) + { + $room = RoomCache::getInstance()->getRoom($objectID); + if ($room === null) { + throw new \InvalidArgumentException('Invalid room ID given'); + } - return $room->getLink(); - } + return $room->getLink(); + } - /** - * @inheritDoc - */ - public function isVisible($objectID = null) { - if (!WCF::getUser()->userID) return false; + /** + * @inheritDoc + */ + public function isVisible($objectID = null) + { + if (!WCF::getUser()->userID) { + return false; + } - if ($objectID === null) throw new \InvalidArgumentException('Invalid room ID given'); - $room = RoomCache::getInstance()->getRoom($objectID); - if ($room === null) throw new \InvalidArgumentException('Invalid room ID given'); + if ($objectID === null) { + throw new \InvalidArgumentException('Invalid room ID given'); + } - return $room->canSee(); - } + $room = RoomCache::getInstance()->getRoom($objectID); + if ($room === null) { + throw new \InvalidArgumentException('Invalid room ID given'); + } - /** - * @inheritDoc - */ - public function getOnlineLocation(\wcf\data\page\Page $page, \wcf\data\user\online\UserOnline $user) { - if ($user->pageObjectID === null) return ''; - $room = RoomCache::getInstance()->getRoom($user->pageObjectID); - if ($room === null) return ''; - if (!$room->canSee()) return ''; + return $room->canSee(); + } - return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, [ 'room' => $room ]); - } + /** + * @inheritDoc + */ + public function getOnlineLocation(Page $page, UserOnline $user) + { + if ($user->pageObjectID === null) { + return ''; + } + + $room = RoomCache::getInstance()->getRoom($user->pageObjectID); + if ($room === null) { + return ''; + } + if (!$room->canSee()) { + return ''; + } + + return WCF::getLanguage()->getDynamicVariable( + 'wcf.page.onlineLocation.' . $page->identifier, + [ + 'room' => $room, + ] + ); + } } diff --git a/files/lib/system/page/handler/TRoomPageHandler.class.php b/files/lib/system/page/handler/TRoomPageHandler.class.php index e1bac8c..011f92a 100644 --- a/files/lib/system/page/handler/TRoomPageHandler.class.php +++ b/files/lib/system/page/handler/TRoomPageHandler.class.php @@ -1,6 +1,7 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. @@ -14,60 +15,67 @@ namespace chat\system\page\handler; -use \chat\data\room\RoomCache; -use \wcf\system\request\LinkHandler; -use \wcf\system\WCF; +use chat\data\room\RoomCache; +use wcf\system\WCF; /** * Default implementations for page handlers of * pages that operate on a specific chat room. */ -trait TRoomPageHandler { - /** - * @inheritDoc - */ - public function isValid($objectID) { - $room = RoomCache::getInstance()->getRoom($objectID); +trait TRoomPageHandler +{ + /** + * @inheritDoc + */ + public function isValid($objectID) + { + $room = RoomCache::getInstance()->getRoom($objectID); - return $room !== null; - } + return $room !== null; + } - /** - * @inheritDoc - */ - public function lookup($searchString) { - $sql = "(SELECT ('chat.room.room' || roomID || '.title') AS languageItem - FROM chat1_room - WHERE title LIKE ? - ) - UNION - (SELECT languageItem - FROM wcf1_language_item - WHERE languageItemValue LIKE ? - AND languageItem LIKE ? - AND languageID = ? - )"; - $statement = WCF::getDB()->prepare($sql); - $statement->execute([ '%'.$searchString.'%' - , '%'.$searchString.'%' - , 'chat.room.room%.title' - , WCF::getLanguage()->languageID - ]); + /** + * @inheritDoc + */ + public function lookup($searchString) + { + $sql = "(SELECT ('chat.room.room' || roomID || '.title') AS languageItem + FROM chat1_room + WHERE title LIKE ? + ) + UNION + (SELECT languageItem + FROM wcf1_language_item + WHERE languageItemValue LIKE ? + AND languageItem LIKE ? + AND languageID = ? + )"; + $statement = WCF::getDB()->prepare($sql); + $statement->execute([ + '%' . $searchString . '%', + '%' . $searchString . '%', + 'chat.room.room%.title', + WCF::getLanguage()->languageID, + ]); - $results = [ ]; - while (($row = $statement->fetchArray())) { - $roomID = preg_replace('/chat\.room\.room(\d+)\.title/', '\1', $row['languageItem']); - $room = RoomCache::getInstance()->getRoom($roomID); - if (!$room) continue; + $results = [ ]; + while (($row = $statement->fetchArray())) { + $roomID = \preg_replace('/chat\.room\.room(\d+)\.title/', '\1', $row['languageItem']); + $room = RoomCache::getInstance()->getRoom($roomID); - $results[] = [ 'title' => $room->getTitle() - , 'description' => $room->getTopic() - , 'link' => $room->getLink() - , 'objectID' => $room->roomID - , 'image' => 'fa-comments-o' - ]; - } + if (!$room) { + continue; + } - return $results; - } + $results[] = [ + 'title' => $room->getTitle(), + 'description' => $room->getTopic(), + 'link' => $room->getLink(), + 'objectID' => $room->roomID, + 'image' => 'fa-comments-o', + ]; + } + + return $results; + } } diff --git a/files/lib/system/permission/PermissionHandler.class.php b/files/lib/system/permission/PermissionHandler.class.php index 6529fa2..70c2174 100644 --- a/files/lib/system/permission/PermissionHandler.class.php +++ b/files/lib/system/permission/PermissionHandler.class.php @@ -1,7 +1,8 @@ <?php + /** - * Copyright (C) 2010-2021 Tim Düsterhus - * Copyright (C) 2010-2021 Woltlab GmbH + * Copyright (C) 2010-2022 Tim Düsterhus + * Copyright (C) 2010-2022 Woltlab GmbH * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,114 +21,136 @@ namespace chat\system\permission; -use \wcf\system\acl\ACLHandler; -use \wcf\system\user\storage\UserStorageHandler; -use \wcf\system\WCF; +use chat\data\room\Room; +use chat\system\cache\builder\PermissionCacheBuilder; +use wcf\data\user\UserProfile; +use wcf\system\acl\ACLHandler; +use wcf\system\database\util\PreparedStatementConditionBuilder; +use wcf\system\user\storage\UserStorageHandler; +use wcf\system\WCF; /** * Handles chat permissions. */ -class PermissionHandler { - /** - * permissions set for the given user - * @var boolean[] - */ - protected $chatPermissions = [ ]; +class PermissionHandler +{ + /** + * permissions set for the given user + * @var boolean[] + */ + protected $chatPermissions = [ ]; - /** - * given user decorated in a user profile - * @var \wcf\data\user\UserProfile - */ - protected $user = null; + /** + * given user decorated in a user profile + * @var \wcf\data\user\UserProfile + */ + protected $user; - /** - * Cache of PermissionHandlers. - * @var \chat\system\permission\PermissionHandler[] - */ - protected static $cache = [ ]; + /** + * Cache of PermissionHandlers. + * @var \chat\system\permission\PermissionHandler[] + */ + protected static $cache = [ ]; - public function __construct(\wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); - $this->user = $user; + public function __construct(?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } + $this->user = $user; - $this->chatPermissions = \chat\system\cache\builder\PermissionCacheBuilder::getInstance()->getData($user->getGroupIDs()); + $this->chatPermissions = PermissionCacheBuilder::getInstance()->getData($user->getGroupIDs()); - // get user permissions - if ($user->userID) { - $ush = UserStorageHandler::getInstance(); + // get user permissions + if ($user->userID) { + $ush = UserStorageHandler::getInstance(); - // get ids - $data = $ush->getField('chatUserPermissions', $user->userID); + // get ids + $data = $ush->getField('chatUserPermissions', $user->userID); - // cache does not exist or is outdated - if ($data === null) { - $userPermissions = [ ]; + // cache does not exist or is outdated + if ($data === null) { + $userPermissions = [ ]; - $conditionBuilder = new \wcf\system\database\util\PreparedStatementConditionBuilder(); - $conditionBuilder->add('acl_option.objectTypeID = ?', [ ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room') ]); - $conditionBuilder->add('option_to_user.userID = ?', [ $user->userID ]); - $sql = "SELECT option_to_user.objectID AS roomID, - option_to_user.optionValue, - acl_option.optionName AS permission - FROM wcf1_acl_option acl_option - INNER JOIN wcf1_acl_option_to_user option_to_user - ON option_to_user.optionID = acl_option.optionID - ".$conditionBuilder; - $statement = WCF::getDB()->prepare($sql); - $statement->execute($conditionBuilder->getParameters()); - while (($row = $statement->fetchArray())) { - $userPermissions[$row['roomID']][$row['permission']] = $row['optionValue']; - } + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('acl_option.objectTypeID = ?', [ ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room') ]); + $conditionBuilder->add('option_to_user.userID = ?', [ $user->userID ]); + $sql = "SELECT option_to_user.objectID AS roomID, + option_to_user.optionValue, + acl_option.optionName AS permission + FROM wcf1_acl_option acl_option + INNER JOIN wcf1_acl_option_to_user option_to_user + ON option_to_user.optionID = acl_option.optionID + " . $conditionBuilder; + $statement = WCF::getDB()->prepare($sql); + $statement->execute($conditionBuilder->getParameters()); + while (($row = $statement->fetchArray())) { + $userPermissions[$row['roomID']][$row['permission']] = $row['optionValue']; + } - // update cache - $ush->update($user->userID, 'chatUserPermissions', serialize($userPermissions)); - } - else { - $userPermissions = unserialize($data); - } + // update cache + $ush->update($user->userID, 'chatUserPermissions', \serialize($userPermissions)); + } else { + $userPermissions = \unserialize($data); + } - foreach ($userPermissions as $roomID => $permissions) { - foreach ($permissions as $name => $value) { - $this->chatPermissions[$roomID][$name] = $value; - } - } - } - } + foreach ($userPermissions as $roomID => $permissions) { + foreach ($permissions as $name => $value) { + $this->chatPermissions[$roomID][$name] = $value; + } + } + } + } - public static function get(\wcf\data\user\UserProfile $user = null) { - if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); - if (!isset(static::$cache[$user->userID])) { - static::$cache[$user->userID] = new static($user); - } + public static function get(?UserProfile $user = null) + { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } + if (!isset(static::$cache[$user->userID])) { + static::$cache[$user->userID] = new static($user); + } - return static::$cache[$user->userID]; - } + return static::$cache[$user->userID]; + } - /** - * Fetches the given permission for the given room - * - * @param \chat\data\room\Room $room - * @param string $permission - * @return boolean - */ - public function getPermission(\chat\data\room\Room $room, $permission) { - $groupPermission = str_replace([ 'user.', 'mod.' ], [ 'user.chat.', 'mod.chat.' ], $permission); + /** + * Fetches the given permission for the given room + * + * @param string $permission + * @return boolean + */ + public function getPermission(Room $room, $permission) + { + $groupPermission = \str_replace( + [ + 'user.', + 'mod.', + ], + [ + 'user.chat.', + 'mod.chat.', + ], + $permission + ); - if (method_exists($this->user, 'getNeverPermission') && $this->user->getNeverPermission($groupPermission)) { - return false; - } + if (\method_exists($this->user, 'getNeverPermission') && $this->user->getNeverPermission($groupPermission)) { + return false; + } - if (!isset($this->chatPermissions[$room->roomID][$permission])) { - return $this->user->getPermission($groupPermission); - } - return (boolean) $this->chatPermissions[$room->roomID][$permission]; - } + if (!isset($this->chatPermissions[$room->roomID][$permission])) { + return $this->user->getPermission($groupPermission); + } - /** - * Clears the cache. - */ - public static function resetCache() { - UserStorageHandler::getInstance()->resetAll('chatUserPermissions'); - \chat\system\cache\builder\PermissionCacheBuilder::getInstance()->reset(); - } + return (bool)$this->chatPermissions[$room->roomID][$permission]; + } + + /** + * Clears the cache. + */ + public static function resetCache() + { + UserStorageHandler::getInstance()->resetAll('chatUserPermissions'); + PermissionCacheBuilder::getInstance()->reset(); + } } diff --git a/files/lib/system/suspension/BanSuspension.class.php b/files/lib/system/suspension/BanSuspension.class.php index 94b3fd9..106bb07 100644 --- a/files/lib/system/suspension/BanSuspension.class.php +++ b/files/lib/system/suspension/BanSuspension.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,35 +15,39 @@ namespace chat\system\suspension; -use \chat\data\suspension\Suspension; -use \chat\system\permission\PermissionHandler; -use \wcf\data\user\UserProfile; +use chat\data\suspension\Suspension; +use chat\system\permission\PermissionHandler; +use wcf\data\user\UserProfile; /** * BanSuspension removes join privileges. */ -class BanSuspension implements ISuspension { - /** - * @inheritDoc - */ - public function hasEffect(Suspension $suspension) { - $user = new UserProfile($suspension->getUser()); - $room = $suspension->getRoom(); +class BanSuspension implements ISuspension +{ + /** + * @inheritDoc + */ + public function hasEffect(Suspension $suspension) + { + $user = new UserProfile($suspension->getUser()); + $room = $suspension->getRoom(); - if ($user->getPermission('mod.chat.canBan')) { - return false; - } - if ($room !== null) { - if (PermissionHandler::get($user)->getPermission($room, 'mod.canBan') || PermissionHandler::get($user)->getPermission($room, 'mod.canIgnoreBan')) { - return false; - } - } - else { - if ($user->getPermission('mod.chat.canIgnoreBan')) { - return false; - } - } + if ($user->getPermission('mod.chat.canBan')) { + return false; + } + if ($room !== null) { + if ( + PermissionHandler::get($user)->getPermission($room, 'mod.canBan') + || PermissionHandler::get($user)->getPermission($room, 'mod.canIgnoreBan') + ) { + return false; + } + } else { + if ($user->getPermission('mod.chat.canIgnoreBan')) { + return false; + } + } - return true; - } + return true; + } } diff --git a/files/lib/system/suspension/ISuspension.class.php b/files/lib/system/suspension/ISuspension.class.php index 6000bc8..12f65c9 100644 --- a/files/lib/system/suspension/ISuspension.class.php +++ b/files/lib/system/suspension/ISuspension.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,18 +15,17 @@ namespace chat\system\suspension; -use \chat\data\suspension\Suspension; -use \wcf\data\user\UserProfile; +use chat\data\suspension\Suspension; /** * An ISuspension defines how a suspension of a certain type is acted upon. */ -interface ISuspension { - /** - * Returns whether the suspension actually has an effect. - * - * @param \chat\data\suspension\Suspension $suspension - * @return bool - */ - public function hasEffect(Suspension $suspension); +interface ISuspension +{ + /** + * Returns whether the suspension actually has an effect. + * + * @return bool + */ + public function hasEffect(Suspension $suspension); } diff --git a/files/lib/system/suspension/MuteSuspension.class.php b/files/lib/system/suspension/MuteSuspension.class.php index 0ac959b..c18c455 100644 --- a/files/lib/system/suspension/MuteSuspension.class.php +++ b/files/lib/system/suspension/MuteSuspension.class.php @@ -1,11 +1,12 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. * - * Change Date: 2025-03-05 + * Change Date: 2026-03-04 * * On the date above, in accordance with the Business Source * License, use of this software will be governed by version 3 @@ -14,35 +15,39 @@ namespace chat\system\suspension; -use \chat\data\suspension\Suspension; -use \chat\system\permission\PermissionHandler; -use \wcf\data\user\UserProfile; +use chat\data\suspension\Suspension; +use chat\system\permission\PermissionHandler; +use wcf\data\user\UserProfile; /** * MuteSuspension removes write privileges. */ -class MuteSuspension implements ISuspension { - /** - * @inheritDoc - */ - public function hasEffect(Suspension $suspension) { - $user = new UserProfile($suspension->getUser()); - $room = $suspension->getRoom(); +class MuteSuspension implements ISuspension +{ + /** + * @inheritDoc + */ + public function hasEffect(Suspension $suspension) + { + $user = new UserProfile($suspension->getUser()); + $room = $suspension->getRoom(); - if ($user->getPermission('mod.chat.canMute')) { - return false; - } - if ($room !== null) { - if (PermissionHandler::get($user)->getPermission($room, 'mod.canMute') || PermissionHandler::get($user)->getPermission($room, 'mod.canIgnoreMute')) { - return false; - } - } - else { - if ($user->getPermission('mod.chat.canIgnoreMute')) { - return false; - } - } + if ($user->getPermission('mod.chat.canMute')) { + return false; + } + if ($room !== null) { + if ( + PermissionHandler::get($user)->getPermission($room, 'mod.canMute') + || PermissionHandler::get($user)->getPermission($room, 'mod.canIgnoreMute') + ) { + return false; + } + } else { + if ($user->getPermission('mod.chat.canIgnoreMute')) { + return false; + } + } - return true; - } + return true; + } } diff --git a/files_wcf/lib/system/package/plugin/ChatCommandPackageInstallationPlugin.class.php b/files_wcf/lib/system/package/plugin/ChatCommandPackageInstallationPlugin.class.php index d1b235f..05adfca 100644 --- a/files_wcf/lib/system/package/plugin/ChatCommandPackageInstallationPlugin.class.php +++ b/files_wcf/lib/system/package/plugin/ChatCommandPackageInstallationPlugin.class.php @@ -1,6 +1,7 @@ <?php + /* - * Copyright (c) 2010-2021 Tim Düsterhus. + * Copyright (c) 2010-2022 Tim Düsterhus. * * Use of this software is governed by the Business Source License * included in the LICENSE file. @@ -14,159 +15,173 @@ namespace wcf\system\package\plugin; -use \wcf\system\exception\SystemException; -use \wcf\system\WCF; +use chat\data\command\CommandEditor; +use chat\system\command\ICommand; +use wcf\system\devtools\pip\IIdempotentPackageInstallationPlugin; +use wcf\system\exception\SystemException; +use wcf\system\WCF; /** * Installs, updates and deletes chat commands. */ -class ChatCommandPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin implements \wcf\system\devtools\pip\IIdempotentPackageInstallationPlugin { - /** - * @inheritDoc - */ - public $className = \chat\data\command\CommandEditor::class; +class ChatCommandPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin implements IIdempotentPackageInstallationPlugin +{ + /** + * @inheritDoc + */ + public $className = CommandEditor::class; - /** - * @inheritDoc - */ - public $application = 'chat'; + /** + * @inheritDoc + */ + public $application = 'chat'; - /** - * Removing this and relying on table name guessing breaks uninstallation - * as the application autoloader is unavailable there. - * - * @inheritDoc - */ - public $tableName = 'command'; + /** + * Removing this and relying on table name guessing breaks uninstallation + * as the application autoloader is unavailable there. + * + * @inheritDoc + */ + public $tableName = 'command'; - /** - * @inheritDoc - */ - protected function handleDelete(array $items) { - $sql = "DELETE FROM ".$this->application.WCF_N."_".$this->tableName." - WHERE packageID = ? - AND identifier = ?"; - $statement = WCF::getDB()->prepare($sql); + /** + * @inheritDoc + */ + protected function handleDelete(array $items) + { + $sql = "DELETE FROM {$this->application}" . WCF_N . "_{$this->tableName} + WHERE packageID = ? + AND identifier = ?"; + $statement = WCF::getDB()->prepare($sql); - WCF::getDB()->beginTransaction(); - foreach ($items as $item) { - $statement->execute([ - $this->installation->getPackageID(), - $item['attributes']['name'] - ]); - } - WCF::getDB()->commitTransaction(); - } + WCF::getDB()->beginTransaction(); + foreach ($items as $item) { + $statement->execute([ + $this->installation->getPackageID(), + $item['attributes']['name'], + ]); + } + WCF::getDB()->commitTransaction(); + } - /** - * @inheritDoc - */ - protected function getElement(\DOMXPath $xpath, array &$elements, \DOMElement $element) { - $nodeValue = $element->nodeValue; + /** + * @inheritDoc + */ + protected function getElement(\DOMXPath $xpath, array &$elements, \DOMElement $element) + { + $nodeValue = $element->nodeValue; - if ($element->tagName === 'triggers') { - $nodeValue = [ ]; - $triggers = $xpath->query('child::*', $element); + if ($element->tagName === 'triggers') { + $nodeValue = [ ]; + $triggers = $xpath->query('child::*', $element); - foreach ($triggers as $trigger) { - $nodeValue[] = $trigger->nodeValue; - } - } + foreach ($triggers as $trigger) { + $nodeValue[] = $trigger->nodeValue; + } + } - $elements[$element->tagName] = $nodeValue; - } + $elements[$element->tagName] = $nodeValue; + } - /** - * @inheritDoc - */ - protected function prepareImport(array $data) { - return [ - 'identifier' => $data['attributes']['name'], - 'className' => $data['elements']['classname'], - 'triggers' => isset($data['elements']['triggers']) ? $data['elements']['triggers'] : [ ] - ]; - } + /** + * @inheritDoc + */ + protected function prepareImport(array $data) + { + return [ + 'identifier' => $data['attributes']['name'], + 'className' => $data['elements']['classname'], + 'triggers' => $data['elements']['triggers'] ?? [ ], + ]; + } - /** - * @inheritDoc - */ - protected function validateImport(array $data) { - if ($data['identifier'] === '') { - throw new SystemException('Command identifier (name attribute) may not be empty'); - } - if (!class_exists($data['className'])) { - throw new SystemException("'".$data['className']."' does not exist."); - } - if (!\wcf\util\ClassUtil::isInstanceOf($data['className'], \chat\system\command\ICommand::class)) { - throw new SystemException("'".$data['className']."' does not implement '\chat\system\command\ICommand.'"); - } - } + /** + * @inheritDoc + */ + protected function validateImport(array $data) + { + if ($data['identifier'] === '') { + throw new SystemException('Command identifier (name attribute) may not be empty'); + } + if (!\class_exists($data['className'])) { + throw new SystemException("'" . $data['className'] . "' does not exist."); + } + if (!\wcf\util\ClassUtil::isInstanceOf($data['className'], ICommand::class)) { + throw new SystemException("'" . $data['className'] . "' does not implement '\\chat\\system\\command\\ICommand.'"); + } + } - /** - * @inheritDoc - */ - protected function findExistingItem(array $data) { - $sql = "SELECT * - FROM ".$this->application.WCF_N."_".$this->tableName." - WHERE packageID = ? - AND identifier = ?"; - $parameters = [ - $this->installation->getPackageID(), - $data['identifier'] - ]; + /** + * @inheritDoc + */ + protected function findExistingItem(array $data) + { + $sql = "SELECT * + FROM {$this->application}" . WCF_N . "_{$this->tableName} + WHERE packageID = ? + AND identifier = ?"; + $parameters = [ + $this->installation->getPackageID(), + $data['identifier'], + ]; - return [ - 'sql' => $sql, - 'parameters' => $parameters - ]; - } + return [ + 'sql' => $sql, + 'parameters' => $parameters, + ]; + } - /** - * @inheritDoc - */ - protected function import(array $row, array $data) { - $triggers = $data['triggers']; - unset($data['triggers']); + /** + * @inheritDoc + */ + protected function import(array $row, array $data) + { + $triggers = $data['triggers']; + unset($data['triggers']); - $result = parent::import($row, $data); + $result = parent::import($row, $data); - if (empty($row)) { - // import initial triggers - $sql = "INSERT INTO ".$this->application.WCF_N."_command_trigger (commandTrigger, commandID) - VALUES (?, ?)"; - $statement = WCF::getDB()->prepare($sql); + if (empty($row)) { + // import initial triggers + $sql = "INSERT INTO {$this->application}" . WCF_N . "_command_trigger + (commandTrigger, commandID) + VALUES (?, ?)"; + $statement = WCF::getDB()->prepare($sql); - try { - WCF::getDB()->beginTransaction(); + try { + WCF::getDB()->beginTransaction(); - foreach ($triggers as $trigger) { - try { - $statement->execute(array( - $trigger, - $result->commandID - )); - } - catch (\wcf\system\database\DatabaseException $e) { - // Duplicate key errors don't cause harm. - if ((string) $e->getCode() !== '23000') throw $e; - } - } + foreach ($triggers as $trigger) { + try { + $statement->execute([ + $trigger, + $result->commandID, + ]); + } catch (\wcf\system\database\DatabaseException $e) { + // Duplicate key errors don't cause harm. + if ((string)$e->getCode() !== '23000') { + throw $e; + } + } + } - WCF::getDB()->commitTransaction(); - } - catch (\Exception $e) { - WCF::getDB()->rollBackTransaction(); - throw $e; - } - } + WCF::getDB()->commitTransaction(); + } catch (\Exception $e) { + WCF::getDB()->rollBackTransaction(); + throw $e; + } + } - return $result; - } + return $result; + } - /** - * @inheritDoc - */ - public static function getSyncDependencies() { - return [ 'file' ]; - } + /** + * @inheritDoc + */ + public static function getSyncDependencies() + { + return [ + 'file', + ]; + } }