-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an event for the spam check in message forms
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
wcfsetup/install/files/lib/event/message/MessageSpamChecking.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace wcf\event\message; | ||
|
||
use wcf\data\user\User; | ||
use wcf\event\IInterruptableEvent; | ||
use wcf\event\TInterruptableEvent; | ||
use wcf\system\html\input\HtmlInputProcessor; | ||
|
||
/** | ||
* Indicates that a new message by a user is currently validated. If this event is interrupted, | ||
* the message is considered to be spam. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.1 | ||
*/ | ||
final class MessageSpamChecking implements IInterruptableEvent | ||
{ | ||
use TInterruptableEvent; | ||
|
||
public function __construct( | ||
public readonly HtmlInputProcessor $processor, | ||
public readonly ?User $user = null, | ||
public readonly string $ipAddress = '', | ||
public readonly string $subject = '', | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
wcfsetup/install/files/lib/system/event/listener/MessageSpamCheckingSfsListener.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace wcf\system\event\listener; | ||
|
||
use wcf\data\blacklist\entry\BlacklistEntry; | ||
use wcf\event\message\MessageSpamChecking; | ||
use wcf\system\cache\runtime\UserProfileRuntimeCache; | ||
|
||
/** | ||
* Checks for spam messages using data from Stop Forum Spam. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.1 | ||
*/ | ||
final class MessageSpamCheckingSfsListener | ||
{ | ||
public function __invoke(MessageSpamChecking $event): void | ||
{ | ||
if (!\BLACKLIST_SFS_ENABLE) { | ||
return; | ||
} | ||
|
||
if ($event->user !== null) { | ||
// Skip spam check for admins and moderators | ||
$userProfile = UserProfileRuntimeCache::getInstance()->getObject($event->user->userID); | ||
if ( | ||
$userProfile->getPermission('admin.general.canUseAcp') | ||
|| $userProfile->getPermission('mod.general.canUseModeration') | ||
) { | ||
return; | ||
} | ||
} | ||
|
||
if (BlacklistEntry::getMatches( | ||
$event->user ? $event->user->username : '', | ||
$event->user ? $event->user->email : '', | ||
$event->ipAddress, | ||
) !== []) { | ||
$event->preventDefault(); | ||
} | ||
} | ||
} |