From 75d5a609e2add0b7836334e928fd338dbd2a4715 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 4 Jun 2024 14:51:07 +0200 Subject: [PATCH] Make use of the new spam check event --- .../ConversationMessageAction.class.php | 26 +++++++++++++++++++ files/lib/form/ConversationAddForm.class.php | 4 +++ 2 files changed, 30 insertions(+) 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(); + } } /** -- 2.20.1