Make messages from the contact form available to the spam checking
authorMarcel Werk <burntime@woltlab.com>
Sat, 1 Jun 2024 11:11:06 +0000 (13:11 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sat, 1 Jun 2024 11:11:06 +0000 (13:11 +0200)
wcfsetup/install/files/lib/event/page/ContactFormSpamChecking.class.php
wcfsetup/install/files/lib/form/ContactForm.class.php

index 718329b249609f21a05815aa283d8fc34ea10286..b744442090b7ca98d840fda5c5da505919ca3274 100644 (file)
@@ -21,6 +21,7 @@ final class ContactFormSpamChecking implements IInterruptableEvent
     public function __construct(
         public readonly string $email,
         public readonly string $ipAddress,
+        public readonly array $messages,
     ) {
     }
 }
index 6a8fda89669755f9ef7e82f05024524fca092e9a..3e3547bc51c74fbfab882257957c34ca87bb3f7d 100644 (file)
@@ -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;
@@ -170,9 +171,29 @@ class ContactForm extends AbstractCaptchaForm
             }
         }
 
+        $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()) {