Frontend\Core\Engine\Model::isSpam PHP Метод

isSpam() публичный статический Метод

General method to check if something is spam
public static isSpam ( string $content, string $permaLink, string $author = null, string $email = null, string $url = null, string $type = 'comment' ) : boolean | string
$content string The content that was submitted.
$permaLink string The permanent location of the entry the comment was submitted to.
$author string Commenter's name.
$email string Commenter's email address.
$url string Commenter's URL.
$type string May be blank, comment, trackback, pingback, or a made up value like "registration".
Результат boolean | string Will return a boolean, except when we can't decide the status (unknown will be returned in that case)
    public static function isSpam($content, $permaLink, $author = null, $email = null, $url = null, $type = 'comment')
    {
        // get some settings
        $akismetKey = self::get('fork.settings')->get('Core', 'akismet_key');
        // invalid key, so we can't detect spam
        if ($akismetKey === '') {
            return false;
        }
        // create new instance
        $akismet = new Akismet($akismetKey, SITE_URL);
        // set properties
        $akismet->setTimeOut(10);
        $akismet->setUserAgent('Fork CMS/' . FORK_VERSION);
        // try it, to decide if the item is spam
        try {
            // check with Akismet if the item is spam
            return $akismet->isSpam($content, $author, $email, $url, $permaLink, $type);
        } catch (\Exception $e) {
            // in debug mode we want to see exceptions, otherwise the fallback will be triggered
            if (self::getContainer()->getParameter('kernel.debug')) {
                throw $e;
            }
            // return unknown status
            return 'unknown';
        }
    }

Usage Example

Пример #1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate required fields
         $this->frm->getField('name')->isFilled(FL::err('NameIsRequired'));
         $this->frm->getField('email')->isEmail(FL::err('EmailIsInvalid'));
         $this->frm->getField('message')->isFilled(FL::err('QuestionIsRequired'));
         if ($this->frm->isCorrect()) {
             $spamFilterEnabled = $this->get('fork.settings')->get('Faq', 'spamfilter');
             $variables['sentOn'] = time();
             $variables['name'] = $this->frm->getField('name')->getValue();
             $variables['email'] = $this->frm->getField('email')->getValue();
             $variables['message'] = $this->frm->getField('message')->getValue();
             if ($spamFilterEnabled) {
                 // if the comment is spam alter the comment status so it will appear in the spam queue
                 if (FrontendModel::isSpam($variables['message'], SITE_URL . FrontendNavigation::getURLForBlock('Faq'), $variables['name'], $variables['email'])) {
                     $this->status = 'errorSpam';
                     return;
                 }
             }
             $from = $this->get('fork.settings')->get('Core', 'mailer_from');
             $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
             $message = \Common\Mailer\Message::newInstance(sprintf(FL::getMessage('FaqOwnQuestionSubject'), $variables['name']))->setFrom(array($from['email'] => $from['name']))->setTo(array($variables['email'] => $variables['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Faq/Layout/Templates/Mails/OwnQuestion.tpl', $variables, true);
             $this->get('mailer')->send($message);
             $this->status = 'success';
         }
     }
 }
All Usage Examples Of Frontend\Core\Engine\Model::isSpam