From: Marcel Werk Date: Tue, 4 Jun 2024 12:51:07 +0000 (+0200) Subject: Make use of the new spam check event X-Git-Tag: 6.1.0_Alpha_1~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=75d5a609e2add0b7836334e928fd338dbd2a4715;p=GitHub%2FWoltLab%2Fcom.woltlab.wcf.conversation.git Make use of the new spam check event --- diff --git a/files/lib/data/conversation/message/ConversationMessageAction.class.php b/files/lib/data/conversation/message/ConversationMessageAction.class.php index 05a3704..3f5cf5c 100644 --- a/files/lib/data/conversation/message/ConversationMessageAction.class.php +++ b/files/lib/data/conversation/message/ConversationMessageAction.class.php @@ -11,6 +11,7 @@ use wcf\data\IAttachmentMessageQuickReplyAction; use wcf\data\IMessageInlineEditorAction; use wcf\data\IMessageQuoteAction; use wcf\data\smiley\SmileyCache; +use wcf\event\message\MessageSpamChecking; use wcf\system\attachment\AttachmentHandler; use wcf\system\bbcode\BBCodeHandler; use wcf\system\conversation\ConversationHandler; @@ -305,6 +306,10 @@ class ConversationMessageAction extends AbstractDatabaseObjectAction implements WCF::getSession()->getPermission('user.message.disallowedBBCodes') )); QuickReplyManager::getInstance()->validateParameters($this, $this->parameters, Conversation::class); + + if ($this->messageIsProbablySpam()) { + throw new PermissionDeniedException(); + } } /** @@ -421,6 +426,10 @@ class ConversationMessageAction extends AbstractDatabaseObjectAction implements $this->conversation, $this->getHtmlInputProcessor($this->parameters['data']['message'], $this->message->messageID) ); + + if ($this->messageIsProbablySpam()) { + throw new PermissionDeniedException(); + } } /** @@ -723,4 +732,21 @@ class ConversationMessageAction extends AbstractDatabaseObjectAction implements return $this->htmlInputProcessor; } + + /** + * This method triggers the event for the spam check and returns the result. + * + * @since 6.1 + */ + protected function messageIsProbablySpam(): bool + { + $event = new MessageSpamChecking( + $this->htmlInputProcessor, + WCF::getUser()->userID ? WCF::getUser() : null, + UserUtil::getIpAddress() + ); + EventHandler::getInstance()->fire($event); + + return $event->defaultPrevented(); + } } diff --git a/files/lib/form/ConversationAddForm.class.php b/files/lib/form/ConversationAddForm.class.php index ffd4778..f4723f5 100644 --- a/files/lib/form/ConversationAddForm.class.php +++ b/files/lib/form/ConversationAddForm.class.php @@ -256,6 +256,10 @@ class ConversationAddForm extends MessageForm } parent::validate(); + + if ($this->messageIsProbablySpam()) { + throw new PermissionDeniedException(); + } } /**