function fu_akismet_check_submission($should_process, $layout)
{
    // Akismet is not enabled or not configured, or too old, just return the filter value
    if (!class_exists('Akismet') || !method_exists('Akismet', 'get_api_key') || !Akismet::get_api_key()) {
        return $should_process;
    }
    $content = array();
    $content['comment_author'] = isset($_POST['post_author']) ? sanitize_text_field($_POST['post_author']) : null;
    $content['comment_content'] = isset($_POST['post_content']) ? $_POST['post_content'] : null;
    // Permalink of the post with upload form, fallback to wp_get_referer()
    // Fallback is used to
    $content['permalink'] = isset($_POST['form_post_id']) ? get_permalink($_POST['form_post_id']) : wp_get_referer();
    // Set required Akismet values
    $content['user_ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
    $content['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
    $content['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
    $content['blog'] = get_option('home');
    $content['blog_lang'] = get_locale();
    $content['blog_charset'] = get_option('blog_charset');
    // Ignore these keys in POST and SERVER superglobals, add the rest to request
    // This approach is stolen from Akismet::auto_check_comment()
    $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW', 'ff', 'fu_nonce');
    foreach ($_POST as $key => $value) {
        if (!in_array($key, $ignore) && is_string($value)) {
            $content["POST_{$key}"] = $value;
        }
    }
    foreach ($_SERVER as $key => $value) {
        if (!in_array($key, $ignore) && is_string($value)) {
            $content["{$key}"] = $value;
        } else {
            $content["{$key}"] = '';
        }
    }
    // Build a query and make a request to Akismet
    $request = build_query($content);
    $response = Akismet::http_post($request, 'comment-check');
    // It's a spam
    if ($response[1] == 'true') {
        $should_process = false;
    }
    return $should_process;
}
Ejemplo n.º 2
0
function flamingo_akismet_submit($comment, $as = 'spam')
{
    global $akismet_api_host, $akismet_api_port;
    if (!flamingo_akismet_is_active()) {
        return false;
    }
    if (!in_array($as, array('spam', 'ham'))) {
        return false;
    }
    $query_string = '';
    foreach ((array) $comment as $key => $data) {
        $query_string .= $key . '=' . urlencode(wp_unslash((string) $data)) . '&';
    }
    if (is_callable(array('Akismet', 'http_post'))) {
        // Akismet v3.0+
        $response = Akismet::http_post($query_string, 'submit-' . $as);
    } else {
        $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/submit-' . $as, $akismet_api_port);
    }
    return (bool) $response[1];
}
Ejemplo n.º 3
0
function sharing_email_check_for_spam_via_akismet($data)
{
    if (!function_exists('akismet_http_post') && !method_exists('Akismet', 'http_post')) {
        return $data;
    }
    // Prepare the body_request for akismet
    $body_request = array('blog' => get_option('home'), 'permalink' => get_permalink($data['post']->ID), 'comment_type' => 'share', 'comment_author' => $data['name'], 'comment_author_email' => $data['source'], 'comment_content' => sharing_email_send_post_content($data), 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null);
    if (method_exists('Akismet', 'http_post')) {
        $body_request['user_ip'] = Akismet::get_ip_address();
        $response = Akismet::http_post(build_query($body_request), 'comment-check');
    } else {
        global $akismet_api_host, $akismet_api_port;
        $body_request['user_ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
        $response = akismet_http_post(build_query($body_request), $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
    }
    // The Response is spam lets not send the email.
    if (!empty($response) && isset($response[1]) && 'true' == trim($response[1])) {
        // 'true' is spam
        return false;
        // don't send the email
    }
    return $data;
}
 public static function api_check($params)
 {
     global $akismet_api_host, $akismet_api_port;
     /* bail if no content to check against akismet */
     if (!isset($params['comment_content'])) {
         return;
     }
     $spam = false;
     $query_string = '';
     foreach ($params as $key => $data) {
         $query_string .= $key . '=' . urlencode(wp_unslash((string) $data)) . '&';
     }
     if (is_callable(array('Akismet', 'http_post'))) {
         // Akismet v3.0+
         $response = Akismet::http_post($query_string, 'comment-check');
     } else {
         $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
     }
     /* returns true if spam else return false */
     if ('true' == $response[1]) {
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * Check entries for spam
  *
  * @return boolean true if is spam
  */
 public static function akismet($values)
 {
     $content = FrmEntriesHelper::entry_array_to_string($values);
     if (empty($content)) {
         return false;
     }
     $datas = array();
     self::parse_akismet_array($datas, $content);
     $query_string = '';
     foreach ($datas as $key => $data) {
         $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
         unset($key, $data);
     }
     $response = Akismet::http_post($query_string, 'comment-check');
     return is_array($response) && $response[1] == 'true';
 }
Ejemplo n.º 6
0
function gwolle_gb_akismet_entry_check($comment, $action)
{
    global $akismet_api_host, $akismet_api_port;
    $query_string = '';
    foreach ($comment as $key => $data) {
        if (is_array($data)) {
            continue;
        }
        $query_string .= $key . '=' . urlencode(wp_unslash((string) $data)) . '&';
    }
    if (is_callable(array('Akismet', 'http_post'))) {
        // Akismet v3.0+
        $response = Akismet::http_post($query_string, $action);
    } else {
        $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/' . $action, $akismet_api_port);
    }
    //if ( WP_DEBUG ) { echo "Akismet response: "; var_dump($response); }
    if ($action == 'comment-check' && isset($response[1]) && 'true' == $response[1]) {
        return true;
    } else {
        if ($action == 'submit-ham' && isset($response[1])) {
            return true;
        } else {
            if ($action == 'submit-spam' && isset($response[1])) {
                return true;
            } else {
                return false;
            }
        }
    }
}
Ejemplo n.º 7
0
function ll_akismet_comment_check($comment)
{
    global $akismet_api_host, $akismet_api_port;
    $spam = false;
    $query_string = http_build_query($comment);
    if (is_callable(array('Akismet', 'http_post'))) {
        // Akismet v3.0+
        $response = Akismet::http_post($query_string, 'comment-check');
    } else {
        $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
    }
    if ('true' == $response[1]) {
        $spam = true;
    }
    if ($submission = WPCF7_Submission::get_instance()) {
        $submission->akismet = array('comment' => $comment, 'spam' => $spam);
    }
    return apply_filters('ll_akismet_comment_check', $spam, $comment);
}
Ejemplo n.º 8
0
 public static function submit_spam_comment($comment_id)
 {
     global $wpdb, $current_user, $current_site;
     $comment_id = (int) $comment_id;
     $comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $comment_id));
     if (!$comment) {
         // it was deleted
         return;
     }
     if ('spam' != $comment->comment_approved) {
         return;
     }
     // use the original version stored in comment_meta if available
     $as_submitted = self::sanitize_comment_as_submitted(get_comment_meta($comment_id, 'akismet_as_submitted', true));
     if ($as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content'])) {
         $comment = (object) array_merge((array) $comment, $as_submitted);
     }
     $comment->blog = get_bloginfo('url');
     $comment->blog_lang = get_locale();
     $comment->blog_charset = get_option('blog_charset');
     $comment->permalink = get_permalink($comment->comment_post_ID);
     if (is_object($current_user)) {
         $comment->reporter = $current_user->user_login;
     }
     if (is_object($current_site)) {
         $comment->site_domain = $current_site->domain;
     }
     $comment->user_role = '';
     if (isset($comment->user_ID)) {
         $comment->user_role = Akismet::get_user_roles($comment->user_ID);
     }
     if (self::is_test_mode()) {
         $comment->is_test = 'true';
     }
     $post = get_post($comment->comment_post_ID);
     $comment->comment_post_modified_gmt = $post->post_modified_gmt;
     $response = Akismet::http_post(Akismet::build_query($comment), 'submit-spam');
     if ($comment->reporter) {
         self::update_comment_history($comment_id, '', 'report-spam');
         update_comment_meta($comment_id, 'akismet_user_result', 'true');
         update_comment_meta($comment_id, 'akismet_user', $comment->reporter);
     }
     do_action('akismet_submit_spam_comment', $comment_id, $response[1]);
 }
Ejemplo n.º 9
0
 function akismet($values)
 {
     $content = FrmEntriesHelper::entry_array_to_string($values);
     if (empty($content)) {
         return false;
     }
     $datas = array();
     $datas['blog'] = FrmAppHelper::site_url();
     $datas['user_ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']);
     $datas['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
     $datas['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
     $datas['comment_type'] = 'formidable';
     if ($permalink = get_permalink()) {
         $datas['permalink'] = $permalink;
     }
     $datas['comment_content'] = $content;
     foreach ($_SERVER as $key => $value) {
         if (!in_array($key, array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW')) && is_string($value)) {
             $datas["{$key}"] = $value;
         } else {
             $datas["{$key}"] = '';
         }
         unset($key, $value);
     }
     $query_string = '';
     foreach ($datas as $key => $data) {
         $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
         unset($key, $data);
     }
     if (is_callable('Akismet::http_post')) {
         $response = Akismet::http_post($query_string, 'comment-check');
     } else {
         global $akismet_api_host, $akismet_api_port;
         $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
     }
     return (is_array($response) and $response[1] == 'true') ? true : false;
 }
Ejemplo n.º 10
0
function akismet_http_post($request, $host, $path, $port = 80, $ip = null)
{
    $path = str_replace('/1.1/', '', $path);
    return Akismet::http_post($request, $path, $ip);
}
Ejemplo n.º 11
0
 public function http_post($request_data, $path, $ip = null)
 {
     return Akismet::http_post($request_data, $path, $ip);
 }
 /**
  * Akismet check for marking an entry as Spam/Not Spam
  *
  * @since 2.1
  * @returns bool|wp_error
  */
 protected function akismet_check($type, $id)
 {
     if (!method_exists('Akismet', 'http_post') || !function_exists('akismet_http_post')) {
         return new WP_Error('missing_akismet', 'Akismet does not appear to be installed and/or active. Entry not marked as spam.');
     }
     global $akismet_api_host, $akismet_api_port, $wpdb;
     $query_string = '';
     $api = 'spam' == $type ? 'submit-spam' : 'submit-ham';
     $akismet_data = maybe_unserialize($wpdb->get_var($wpdb->prepare("SELECT akismet FROM {$this->entries_table_name} WHERE entries_id = %d", $id)));
     foreach (array_keys($akismet_data) as $k) {
         $query_string .= $k . '=' . urlencode($akismet_data[$k]) . '&';
     }
     if (method_exists('Akismet', 'http_post')) {
         $response = Akismet::http_post($query_string, $api);
     } else {
         $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/{$api}", $akismet_api_port);
     }
     // Only return true if a response is available
     if ($response) {
         if ('Thanks for making the web a better place.' == $response[1]) {
             return true;
         }
     } else {
         return new WP_Error('unexpected_response', 'No response returned from Akismet. This could be a connectivity issue or a missing Akismet API key. Entry not marked as spam.');
     }
     return false;
 }
Ejemplo n.º 13
0
 public function is_spam($contact)
 {
     if (method_exists('Akismet', 'http_post')) {
         $comment = array('comment_author' => $contact['name'], 'comment_author_email' => $contact['email'], 'comment_content' => $contact['message'], 'comment_type' => $this->tag, 'user_ip' => preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']), 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'blog' => get_option('home'), 'blog_lang' => get_locale(), 'blog_charset' => get_option('blog_charset'));
         foreach ($_SERVER as $key => $value) {
             if ($key != 'HTTP_COOKIE' && is_string($value)) {
                 $comment[$key] = $value;
             }
         }
         $response = Akismet::http_post(Akismet::build_query($comment), 'comment-check');
         if ('true' == trim($response[1])) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 14
0
 /**
  * Check submission against Akismet
  *
  * Passes back true (it's spam) or false (it's ham)
  */
 public function akismet_check($query_string)
 {
     global $akismet_api_host, $akismet_api_port;
     $spam = false;
     if (is_callable(array('Akismet', 'http_post'))) {
         // Akismet v3.0+
         $response = Akismet::http_post($query_string, 'comment-check');
     } else {
         $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
     }
     if ('true' == $response[1]) {
         $spam = true;
     }
     return $spam;
 }
 /**
  * Akismet check
  *
  * @access protected
  * @param mixed $data
  * @return void
  */
 protected function akismet_check($data)
 {
     if (!function_exists('akismet_http_post')) {
         return false;
     }
     do_action('vfb_akismet_check', $data);
     global $akismet_api_host, $akismet_api_port;
     $query_string = '';
     $result = false;
     foreach (array_keys($data) as $k) {
         $query_string .= $k . '=' . urlencode($data[$k]) . '&';
     }
     if (method_exists('Akismet', 'http_post')) {
         $response = Akismet::http_post($query_string, 'comment-check');
     } else {
         $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
     }
     // Only return true if a response is available
     if ($response) {
         if ('true' == trim($response[1])) {
             $result = true;
         }
     }
     return $result;
 }
Ejemplo n.º 16
0
function wpcf7_akismet_comment_check($comment)
{
    global $akismet_api_host, $akismet_api_port;
    $spam = false;
    $query_string = '';
    foreach ($comment as $key => $data) {
        $query_string .= $key . '=' . urlencode(wp_unslash((string) $data)) . '&';
    }
    if (is_callable(array('Akismet', 'http_post'))) {
        // Akismet v3.0+
        $response = Akismet::http_post($query_string, 'comment-check');
    } else {
        $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
    }
    if ('true' == $response[1]) {
        $spam = true;
    }
    if ($contact_form = wpcf7_get_current_contact_form()) {
        $contact_form->akismet = array('comment' => $comment, 'spam' => $spam);
    }
    return apply_filters('wpcf7_akismet_comment_check', $spam, $comment);
}
Ejemplo n.º 17
0
 public static function mark_akismet_spam($form, $lead, $is_spam)
 {
     global $akismet_api_host, $akismet_api_port;
     $fields = self::get_akismet_fields($form, $lead);
     $as = $is_spam ? 'spam' : 'ham';
     //Submitting info to Akismet
     if (defined('AKISMET_VERSION') && AKISMET_VERSION < 3.0) {
         //Akismet versions before 3.0
         akismet_http_post($fields, $akismet_api_host, '/1.1/submit-' . $as, $akismet_api_port);
     } else {
         Akismet::http_post($fields, 'submit-' . $as);
     }
 }
Ejemplo n.º 18
0
 /**
  * check
  * @param string $akismet_author
  * @param string $akismet_author_email
  * @param string $akismet_author_url
  * @param MW_WP_Form_Data $Data
  * @return bool
  */
 public function check($akismet_author, $akismet_author_email, $akismet_author_url, $Data)
 {
     global $akismet_api_host, $akismet_api_port;
     if (!$this->is_enable()) {
         return false;
     }
     $doAkismet = false;
     $author = '';
     if ($Data->get_post_value_by_key($akismet_author)) {
         $author = $Data->get_post_value_by_key($akismet_author);
         $doAkismet = true;
     }
     $author_email = '';
     if ($Data->get_post_value_by_key($akismet_author_email)) {
         $author_email = $Data->get_post_value_by_key($akismet_author_email);
         $doAkismet = true;
     }
     $author_url = '';
     if ($Data->get_post_value_by_key($akismet_author_url)) {
         $author_url = $Data->get_post_value_by_key($akismet_author_url);
         $doAkismet = true;
     }
     if ($doAkismet) {
         $content = '';
         foreach ($Data->gets() as $key => $value) {
             $value = $Data->get($key);
             $content .= $value . "\n\n";
         }
         $permalink = get_permalink();
         $akismet = array();
         $akismet['blog'] = home_url();
         $akismet['blog_lang'] = get_locale();
         $akismet['blog_charset'] = get_option('blog_charset');
         $akismet['user_ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']);
         $akismet['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
         $akismet['referrer'] = $_SERVER['HTTP_REFERER'];
         $akismet['comment_type'] = MWF_Config::NAME;
         if ($permalink) {
             $akismet['permalink'] = $permalink;
         }
         if ($author) {
             $akismet['comment_author'] = $author;
         }
         if ($author_email) {
             $akismet['comment_author_email'] = $author_email;
         }
         if ($author_url) {
             $akismet['comment_author_url'] = $author_url;
         }
         if ($content) {
             $akismet['comment_content'] = $content;
         }
         foreach ($_SERVER as $key => $value) {
             if (!in_array($key, array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'))) {
                 $akismet[$key] = $value;
             }
         }
         $query_string = http_build_query($akismet, null, '&');
         if (is_callable(array('Akismet', 'http_post'))) {
             $response = Akismet::http_post($query_string, 'comment-check');
         } else {
             $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
         }
         $response = apply_filters('mwform_akismet_responce', $response);
         return $response[1] == 'true' ? true : false;
     }
 }
Ejemplo n.º 19
0
 static function check_akismet()
 {
     $string = '';
     // Check with Akismet, but only if Akismet is installed, activated, and has a KEY. (Recommended for spam control).
     if (self::$form_options['akismet_disable'] == 'false') {
         // per form disable feature
         // check if akismet is activated, version 2.x or 3.x
         if ((is_callable(array('Akismet', 'http_post')) || function_exists('akismet_http_post')) && get_option('wordpress_api_key')) {
             global $akismet_api_host, $akismet_api_port;
             $c['user_ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']);
             $c['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
             $c['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
             $c['blog'] = get_option('home');
             $c['blog_lang'] = get_locale();
             // default 'en_US'
             $c['blog_charset'] = get_option('blog_charset');
             $c['permalink'] = self::$form_action_url;
             $c['comment_type'] = 'contact-form';
             if (!empty(self::$email_fields['from_name'])) {
                 $c['comment_author'] = self::$email_fields['from_name'];
             }
             //$c['is_test']  = "1";  // uncomment this when testing spam detection
             //$c['comment_author']  = "viagra-test-123";  // uncomment this to test spam detection
             // or  You can just put viagra-test-123 as the name when testing the form (no need to edit this php file to test it)
             if (!empty(self::$email_fields['from_email'])) {
                 $c['comment_author_email'] = self::$email_fields['from_email'];
             }
             $c['comment_content'] = self::$email_msg;
             $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW');
             foreach ($_SERVER as $key => $value) {
                 if (!in_array($key, $ignore) && is_string($value)) {
                     $c["{$key}"] = $value;
                 } else {
                     $c["{$key}"] = '';
                 }
             }
             $query_string = '';
             foreach ($c as $key => $data) {
                 if (is_string($data)) {
                     $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
                 }
             }
             //echo "test $akismet_api_host, $akismet_api_port, $query_string"; exit;
             if (is_callable(array('Akismet', 'http_post'))) {
                 // Akismet v3.0+
                 $response = Akismet::http_post($query_string, 'comment-check');
             } else {
                 // Akismet v2.xx
                 $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
             }
             if ('true' == $response[1]) {
                 if (self::$form_options['akismet_send_anyway'] == 'false') {
                     self::$form_errors['akismet'] = self::$form_options['error_input'] != '' ? self::$form_options['error_input'] : __('Invalid Input - Spam?', 'si-contact-form');
                     global $user_ID;
                     if ($user_ID != '' && current_user_can('manage_options')) {
                         // this error only shown to WP admins
                         // show administrator a helpful message
                         self::$form_errors['akismet'] .= '<br />' . __('Akismet determined your message is spam. This can be caused by the message content, your email address, or your IP address being on the Akismet spam system. The administrator can turn off Akismet for the form on the form edit menu.', 'si-contact-form');
                     }
                 } else {
                     // Akismet says it is spam. flag the subject as spam and send anyway.
                     // XXX someday make these messages editable in settings
                     self::$akismet_spam_subject = __('Akismet: Spam', 'si-contact-form') . ' - ';
                     $string .= __('Akismet Spam Check: probably spam', 'si-contact-form') . self::$php_eol;
                     self::$email_fields['akismet'] = __('probably spam', 'si-contact-form');
                 }
             } else {
                 $string .= __('Akismet Spam Check: passed', 'si-contact-form') . self::$php_eol;
                 self::$email_fields['akismet'] = __('passed', 'si-contact-form');
             }
         }
     }
     return $string;
 }
Ejemplo n.º 20
0
function araa_registration_is_spam($data)
{
    // Is Akismet enabled?
    if (!class_exists('Akismet')) {
        return false;
    }
    $query = http_build_query(array('comment_type' => 'signup', 'comment_author' => $data['name'], 'comment_author_email' => $data['email'], 'user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'blog' => get_site_url(), 'blog_lang' => get_locale()));
    $response = Akismet::http_post($query, 'comment-check');
    $spam = is_array($response) && isset($response[1]) ? $response[1] : false;
    return $spam;
}
Ejemplo n.º 21
0
function akismet_http_post($request, $host, $path, $port = 80, $ip = null)
{
    _deprecated_function(__FUNCTION__, '3.0', 'Akismet::http_post()');
    $path = str_replace('/1.1/', '', $path);
    return Akismet::http_post($request, $path, $ip);
}
Ejemplo n.º 22
0
 /**
  * Check the email for spam
  *
  * @param $email_fields
  * @param $instance
  *
  * @return array
  */
 function spam_check($post_vars, $email_fields, $instance)
 {
     $errors = array();
     $recaptcha_config = $instance['spam']['recaptcha'];
     $use_recaptcha = $recaptcha_config['use_captcha'] && !empty($recaptcha_config['site_key']) && !empty($recaptcha_config['secret_key']);
     if ($use_recaptcha) {
         $result = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', array('body' => array('secret' => $instance['spam']['recaptcha']['secret_key'], 'response' => $post_vars['g-recaptcha-response'], 'remoteip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null)));
         if (!is_wp_error($result) && !empty($result['body'])) {
             $result = json_decode($result['body'], true);
             if (isset($result['success']) && !$result['success']) {
                 $errors['recaptcha'] = __('Error validating your Captcha response.', 'so-widgets-bundle');
             }
         }
     }
     if ($instance['spam']['akismet']['use_akismet'] && class_exists('Akismet')) {
         $comment = array();
         $message_text = array();
         foreach ($email_fields['message'] as $m) {
             $message_text[] = $m['value'];
         }
         $comment['comment_text'] = $email_fields['subject'] . "\n\n" . implode("\n\n", $message_text);
         $comment['comment_author'] = !empty($email_fields['name']) ? $email_fields['name'] : '';
         $comment['comment_author_email'] = $email_fields['email'];
         $comment['comment_post_ID'] = get_the_ID();
         $comment['comment_type'] = 'contact-form';
         $comment['user_ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
         $comment['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
         $comment['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
         $comment['blog'] = get_option('home');
         $comment['blog_lang'] = get_locale();
         $comment['blog_charset'] = get_option('blog_charset');
         // Pretend to check with Akismet
         $response = Akismet::http_post(Akismet::build_query($comment), 'comment-check');
         $is_spam = !empty($response[1]) && $response[1] == 'true';
         if ($is_spam) {
             $errors['akismet'] = __('Unfortunately our system identified your message as spam.', 'so-widgets-bundle');
         }
     }
     return $errors;
 }
 public static function verify_wpcom_key($api_key, $user_id, $token = '')
 {
     $akismet_account = Akismet::http_post(http_build_query(array('user_id' => $user_id, 'api_key' => $api_key, 'token' => $token, 'get_account_type' => 'true')), 'verify-wpcom-key');
     if (!empty($akismet_account[1])) {
         $akismet_account = json_decode($akismet_account[1]);
     }
     Akismet::log(compact('akismet_account'));
     return $akismet_account;
 }
Ejemplo n.º 24
0
 /**
  * Contact Akismet to check if this is spam or ham.
  *
  * Props to WordPress core Akismet plugin for a lot of this.
  *
  * @since 1.6.0
  *
  * @param array  $activity_data Packet of information to submit to Akismet.
  * @param string $check         "check" or "submit".
  * @param string $spam          "spam" or "ham".
  * @return array $activity_data Activity data, with Akismet data added.
  */
 public function send_akismet_request($activity_data, $check = 'check', $spam = 'spam')
 {
     $query_string = $path = '';
     $activity_data['blog'] = bp_get_option('home');
     $activity_data['blog_charset'] = bp_get_option('blog_charset');
     $activity_data['blog_lang'] = get_locale();
     $activity_data['referrer'] = $_SERVER['HTTP_REFERER'];
     $activity_data['user_agent'] = bp_core_current_user_ua();
     $activity_data['user_ip'] = bp_core_current_user_ip();
     if (Akismet::is_test_mode()) {
         $activity_data['is_test'] = 'true';
     }
     // Loop through _POST args and rekey strings.
     foreach ($_POST as $key => $value) {
         if (is_string($value) && 'cookie' != $key) {
             $activity_data['POST_' . $key] = $value;
         }
     }
     // Keys to ignore.
     $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW');
     // Loop through _SERVER args and remove whitelisted keys.
     foreach ($_SERVER as $key => $value) {
         // Key should not be ignored.
         if (!in_array($key, $ignore) && is_string($value)) {
             $activity_data[$key] = $value;
             // Key should be ignored.
         } else {
             $activity_data[$key] = '';
         }
     }
     foreach ($activity_data as $key => $data) {
         $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
     }
     if ('check' == $check) {
         $path = 'comment-check';
     } elseif ('submit' == $check) {
         $path = 'submit-' . $spam;
     }
     // Send to Akismet.
     add_filter('akismet_ua', array($this, 'buddypress_ua'));
     $response = Akismet::http_post($query_string, $path);
     remove_filter('akismet_ua', array($this, 'buddypress_ua'));
     // Get the response.
     if (!empty($response[1]) && !is_wp_error($response[1])) {
         $activity_data['bp_as_result'] = $response[1];
     } else {
         $activity_data['bp_as_result'] = false;
     }
     // Perform a daily tidy up.
     if (!wp_next_scheduled('bp_activity_akismet_delete_old_metadata')) {
         wp_schedule_event(time(), 'daily', 'bp_activity_akismet_delete_old_metadata');
     }
     return $activity_data;
 }
Ejemplo n.º 25
0
 /**
  * Submit a feedback as either spam or ham
  *
  * @param string $as Either 'spam' or 'ham'.
  * @param array $form the contact-form data
  */
 function akismet_submit($as, $form)
 {
     global $akismet_api_host, $akismet_api_port;
     if (!in_array($as, array('ham', 'spam'))) {
         return false;
     }
     $query_string = '';
     if (is_array($form)) {
         $query_string = http_build_query($form);
     }
     if (method_exists('Akismet', 'http_post')) {
         $response = Akismet::http_post($query_string, "submit-{$as}");
     } else {
         $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-{$as}", $akismet_api_port);
     }
     return trim($response[1]);
 }
Ejemplo n.º 26
0
 public function remote_check_comment($params)
 {
     $response = Akismet::http_post(_http_build_query($params, '', '&'), 'comment-check');
     return 'true' === $response[1];
 }