Exemplo n.º 1
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;
 }