Exemplo n.º 1
0
 public function processEventData($context)
 {
     if (!in_array('akismet', $context['event']->eParamFILTERS)) {
         return;
     }
     $mapping = $_POST['akismet'];
     if (!isset($mapping['author']) || !isset($mapping['email'])) {
         $context['messages'][] = array('akismet', false, 'Author and Email field mappings are required.');
         return;
     }
     foreach ($mapping as $key => $val) {
         if (preg_match("/^'[^']+'\$/", $val)) {
             $mapping[$key] = trim($val, "'");
         } else {
             $mapping[$key] = $context['fields'][$val];
         }
     }
     include_once EXTENSIONS . '/akismet/lib/akismet.curl.class.php';
     $comment = array('comment_type' => 'comment', 'comment_author' => $mapping['author'], 'comment_author_email' => $mapping['email'], 'comment_content' => implode($context['fields']), 'permalink' => URL . $_REQUEST['page']);
     if (isset($mapping['url']) && strlen(trim($mapping['url'])) > 0) {
         $comment['comment_author_url'] = $mapping['url'];
     }
     $akismet = new akismet($this->getWordpressApiKey(), URL);
     if (!$akismet->error) {
         $valid = !$akismet->is_spam($comment);
     }
     $context['messages'][] = array('akismet', $valid, !$valid ? 'Data was identified as spam.' : NULL);
 }
Exemplo n.º 2
0
 /**
  * @param \Box_Event $event
  */
 public function isCommentSpam($event, $comment)
 {
     $di = $event->getDi();
     $config = $di['mod_config']('Spamchecker');
     if (!isset($config['akismet_enabled']) || !$config['akismet_enabled']) {
         return false;
     }
     require_once BB_PATH_MODS . '/Spamchecker/akismet.curl.class.php';
     $akismet = new \akismet($config['akismet_api_key'], $di['config']['url']);
     if (!$akismet->valid_key()) {
         $extensionService = $di['mod_service']('Extension');
         if ($extensionService->isExtensionActive('mod', 'notification')) {
             $notificationService = $di['mod_service']('Notification');
             $notificationService->create('Akismet Key is not valid!');
         } else {
             error_log('Akismet Key is not valid!');
         }
         return false;
     }
     if ($akismet->is_spam($comment)) {
         throw new \Box_Exception('Akismet detected this message is spam');
     }
 }