Skip to content

Commit

Permalink
Make messages from the contact form available to the spam checking
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntimeX committed Jun 1, 2024
1 parent 38cc47a commit 9334f30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class ContactFormSpamChecking implements IInterruptableEvent
public function __construct(
public readonly string $email,
public readonly string $ipAddress,
public readonly array $messages,
) {
}
}
21 changes: 21 additions & 0 deletions wcfsetup/install/files/lib/form/ContactForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace wcf\form;

use wcf\data\contact\option\ContactOption;
use wcf\data\contact\option\ContactOptionAction;
use wcf\data\contact\recipient\ContactRecipientList;
use wcf\event\page\ContactFormSpamChecking;
Expand Down Expand Up @@ -170,9 +171,29 @@ public function validate()
}
}

$this->handleSpamCheck();
}

private function handleSpamCheck(): void
{
$messages = [];
foreach ($this->optionHandler->getOptions() as $option) {
$object = $option['object'];
\assert($object instanceof ContactOption);
if (!$object->isMessage || !$object->getOptionValue()) {
continue;
}

$messages[] = $object->getOptionValue();
if ($object->optionType === 'date' && !$object->getOptionValue()) {
continue;
}
}

$spamCheckEvent = new ContactFormSpamChecking(
$this->email,
UserUtil::getIpAddress(),
$messages,
);
EventHandler::getInstance()->fire($spamCheckEvent);
if ($spamCheckEvent->defaultPrevented()) {
Expand Down

0 comments on commit 9334f30

Please sign in to comment.