/** * Determine if this field is spam or not * * @return boolean */ public function getIsSpam() { // Prevent multiple API calls if ($this->isSpam !== null) { return $this->isSpam; } // Check bypass permission $permission = Config::inst()->get('AkismetSpamProtector', 'bypass_permission'); if ($permission && Permission::check($permission)) { return false; } // if the user has logged and there's no force check on member $bypassMember = Config::inst()->get('AkismetSpamProtector', 'bypass_members'); if ($bypassMember && Member::currentUser()) { return false; } // Map input fields to spam fields $mappedData = $this->getSpamMappedData(); $content = isset($mappedData['body']) ? $mappedData['body'] : null; $author = isset($mappedData['authorName']) ? $mappedData['authorName'] : null; $email = isset($mappedData['authorMail']) ? $mappedData['authorMail'] : null; $url = isset($mappedData['authorUrl']) ? $mappedData['authorUrl'] : null; // Check result $api = AkismetSpamProtector::api(); $this->isSpam = $api && $api->isSpam($content, $author, $email, $url); return $this->isSpam; }
/** * This function first gets values from mapped fields and then check these values against * Mollom web service and then notify callback object with the spam checking result. * @return boolean - true when Mollom confirms that the submission is ham (not spam) * - false when Mollom confirms that the submission is spam * - false when Mollom say 'unsure'. * In this case, 'mollom_captcha_requested' session is set to true * so that Field() knows it's time to display captcha */ public function validate($validator) { // Check that, if necessary, the user has given permission to check for spam $requireConfirmation = Config::inst()->get('AkismetSpamProtector', 'require_confirmation'); if ($requireConfirmation && !$this->Value()) { $validator->validationError($this->name, _t('AkismetField.NOTIFICATIONREQUIRED', 'You must give consent to submit this content to spam detection'), "error"); return false; } // Check bypass permission $permission = Config::inst()->get('AkismetSpamProtector', 'bypass_permission'); if ($permission && Permission::check($permission)) { return true; } // if the user has logged and there's no force check on member $bypassMember = Config::inst()->get('AkismetSpamProtector', 'bypass_members'); if ($bypassMember && Member::currentUser()) { return true; } // Map input fields to spam fields $mappedData = $this->getSpamMappedData(); $content = isset($mappedData['body']) ? $mappedData['body'] : null; $author = isset($mappedData['authorName']) ? $mappedData['authorName'] : null; $email = isset($mappedData['authorMail']) ? $mappedData['authorMail'] : null; $url = isset($mappedData['authorUrl']) ? $mappedData['authorUrl'] : null; // Check result $isSpam = AkismetSpamProtector::api()->isSpam($content, $author, $email, $url); if (!$isSpam) { return true; } // Mark as spam $validator->validationError($this->name, _t('AkismetField.SPAM', "Your submission has been rejected because it was treated as spam."), "error"); return false; }