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
 public function build_submit_ham_request_test()
 {
     $comment = $this->_make_comment();
     $request = akismet::_build_request("submit-ham", $comment);
     $expected = "POST /1.1/submit-ham HTTP/1.0\r\n" . "Host: TEST_KEY.rest.akismet.com\r\n" . "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" . "Content-Length: 645\r\n" . "User-Agent: Gallery/3 | Akismet/1\r\n\r\n" . "HTTP_ACCEPT=http_accept&HTTP_ACCEPT_ENCODING=http_accept_encoding&" . "HTTP_ACCEPT_LANGUAGE=http_accept_language&HTTP_CONNECTION=http_connection&" . "HTTP_HOST=http_host&HTTP_USER_AGENT=http_user_agent&" . "QUERY_STRING=query_string&REMOTE_ADDR=remote_addr&" . "REMOTE_HOST=remote_host&REMOTE_PORT=remote_port&" . "SERVER_HTTP_ACCEPT_CHARSET=http_accept_charset&blog=http%3A%2F%2F.%2F&" . "comment_author=John+Doe&comment_author_email=john%40gallery2.org&" . "comment_author_url=http%3A%2F%2Fgallery2.org&comment_content=This+is+a+comment&" . "comment_type=comment&permalink=http%3A%2F%2F.%2Findex.php%2Fcomments%2F{$comment->id}&" . "referrer=http_referer&user_agent=http_user_agent&user_ip=remote_addr";
     $this->assert_equal($expected, $request);
 }
Exemplo n.º 3
0
 static function install()
 {
     $version = module::get_version("akismet");
     if ($version == 0) {
         module::set_version("akismet", 1);
     }
     akismet::check_config();
 }
Exemplo n.º 4
0
  static function comment_updated($comment) {
    if (!module::get_var("akismet", "api_key")) {
      return;
    }

    if ($comment->original("state") != "spam" && $comment->state == "spam") {
      akismet::submit_spam($new);
    } else if ($comment->original("state") == "spam" && $comment->state != "spam") {
      akismet::submit_ham($new);
    }
  }
Exemplo n.º 5
0
 static function comment_updated($original, $new)
 {
     if (!module::get_var("akismet", "api_key")) {
         return;
     }
     if ($original->state != "spam" && $new->state == "spam") {
         akismet::submit_spam($new);
     } else {
         if ($original->state == "spam" && $new->state != "spam") {
             akismet::submit_ham($new);
         }
     }
 }
Exemplo n.º 6
0
 public function index()
 {
     $form = akismet::get_configure_form();
     if (request::method() == "post") {
         // @todo move the "post" handler part of this code into a separate function
         access::verify_csrf();
         $valid = $form->validate();
         if ($valid) {
             $new_key = $form->configure_akismet->api_key->value;
             if ($new_key && !akismet::validate_key($new_key)) {
                 $form->configure_akismet->api_key->add_error("invalid", 1);
                 $valid = false;
             }
         }
         if ($valid) {
             $old_key = module::get_var("akismet", "api_key");
             if ($old_key && !$new_key) {
                 message::success(t("Your Akismet key has been cleared."));
             } else {
                 if ($old_key && $new_key && $old_key != $new_key) {
                     message::success(t("Your Akismet key has been changed."));
                 } else {
                     if (!$old_key && $new_key) {
                         message::success(t("Your Akismet key has been saved."));
                     }
                 }
             }
             log::success("akismet", t("Akismet key changed to {$new_key}"));
             module::set_var("akismet", "api_key", $new_key);
             akismet::check_config();
             url::redirect("admin/akismet");
         } else {
             $valid_key = false;
         }
     } else {
         $valid_key = module::get_var("akismet", "api_key") ? 1 : 0;
     }
     akismet::check_config();
     $view = new Admin_View("admin.html");
     $view->content = new View("admin_akismet.html");
     $view->content->valid_key = $valid_key;
     $view->content->form = $form;
     print $view;
 }
Exemplo n.º 7
0
 static function activate()
 {
     akismet::check_config();
 }
Exemplo n.º 8
0
 public function gui($url)
 {
     $blog =& $this->core->blog;
     $ak_key = $blog->settings->ak_key;
     $ak_verified = null;
     if (isset($_POST['ak_key'])) {
         try {
             $ak_key = $_POST['ak_key'];
             $blog->settings->setNameSpace('akismet');
             $blog->settings->put('ak_key', $ak_key, 'string');
             http::redirect($url . '&up=1');
         } catch (Exception $e) {
             $this->core->error->add($e->getMessage());
         }
     }
     if ($blog->settings->ak_key) {
         try {
             $ak = new akismet($blog->url, $blog->settings->ak_key);
             $ak_verified = $ak->verify();
         } catch (Exception $e) {
             $this->core->error->add($e->getMessage());
         }
     }
     $res = '<form action="' . html::escapeURL($url) . '" method="post">' . '<p><label class="classic">' . __('Akismet API key:') . ' ' . form::field('ak_key', 12, 128, $ak_key) . '</label>';
     if ($ak_verified !== null) {
         if ($ak_verified) {
             $res .= ' <img src="images/check-on.png" alt="" /> ' . __('API key verified');
         } else {
             $res .= ' <img src="images/check-off.png" alt="" /> ' . __('API key not verified');
         }
     }
     $res .= '</p>';
     $res .= '<p><a href="http://wordpress.com/api-keys/">' . __('Get your own API key') . '</a></p>' . '<p><input type="submit" value="' . __('save') . '" />' . $this->core->formNonce() . '</p>' . '</form>';
     return $res;
 }
Exemplo n.º 9
0
 private static function _add_comment()
 {
     srand(time());
     $photos = ORM::factory("item")->where("type", "photo")->find_all()->as_array();
     $users = ORM::factory("user")->find_all()->as_array();
     if (empty($photos)) {
         return;
     }
     if (module::is_active("akismet")) {
         akismet::$test_mode = 1;
     }
     $photo = $photos[array_rand($photos)];
     $author = $users[array_rand($users)];
     $guest_name = ucfirst(self::_random_phrase(rand(1, 3)));
     $guest_email = sprintf("%s@%s.com", self::_random_phrase(1), self::_random_phrase(1));
     $guest_url = sprintf("http://www.%s.com", self::_random_phrase(1));
     comment::create($photo, $author, self::_random_phrase(rand(8, 500)), $guest_name, $guest_email, $guest_url);
 }
Exemplo n.º 10
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');
     }
 }
Exemplo n.º 11
0
 function add_comments($count)
 {
     srand(time());
     $photos = ORM::factory("item")->where("type", "photo")->find_all()->as_array();
     $users = ORM::factory("user")->find_all()->as_array();
     if (empty($photos)) {
         url::redirect("scaffold");
     }
     if (module::is_active("akismet")) {
         akismet::$test_mode = 1;
     }
     for ($i = 0; $i < $count; $i++) {
         $photo = $photos[array_rand($photos)];
         $author = $users[array_rand($users)];
         $guest_name = ucfirst($this->random_phrase(rand(1, 3)));
         $guest_email = sprintf("%s@%s.com", $this->random_phrase(1), $this->random_phrase(1));
         $guest_url = sprintf("http://www.%s.com", $this->random_phrase(1));
         comment::create($photo, $author, $this->random_phrase(rand(8, 500)), $guest_name, $guest_email, $guest_url);
     }
     url::redirect("scaffold");
 }
Exemplo n.º 12
0
 public function gui($url)
 {
     $blog =& $this->core->blog;
     $blog->settings->addNamespace('akismet');
     $ak_key = $blog->settings->akismet->ak_key;
     $ak_verified = null;
     if (isset($_POST['ak_key'])) {
         try {
             $ak_key = $_POST['ak_key'];
             $blog->settings->akismet->put('ak_key', $ak_key, 'string');
             dcPage::addSuccessNotice(__('Filter configuration have been successfully saved.'));
             http::redirect($url);
         } catch (Exception $e) {
             $this->core->error->add($e->getMessage());
         }
     }
     if ($blog->settings->akismet->ak_key) {
         try {
             $ak = new akismet($blog->url, $blog->settings->akismet->ak_key);
             $ak_verified = $ak->verify();
         } catch (Exception $e) {
             $this->core->error->add($e->getMessage());
         }
     }
     $res = dcPage::notices();
     $res .= '<form action="' . html::escapeURL($url) . '" method="post" class="fieldset">' . '<p><label for="ak_key" class="classic">' . __('Akismet API key:') . '</label> ' . form::field('ak_key', 12, 128, $ak_key);
     if ($ak_verified !== null) {
         if ($ak_verified) {
             $res .= ' <img src="images/check-on.png" alt="" /> ' . __('API key verified');
         } else {
             $res .= ' <img src="images/check-off.png" alt="" /> ' . __('API key not verified');
         }
     }
     $res .= '</p>';
     $res .= '<p><a href="http://akismet.com/">' . __('Get your own API key') . '</a></p>' . '<p><input type="submit" value="' . __('Save') . '" />' . $this->core->formNonce() . '</p>' . '</form>';
     return $res;
 }