示例#1
0
文件: akismet.php 项目: RainGrid/site
function gwolle_gb_akismet($entry, $action)
{
    $actions = array('comment-check', 'submit-ham', 'submit-spam');
    if (!in_array($action, $actions)) {
        return false;
    }
    $akismet_active = get_option('gwolle_gb-akismet-active', 'false');
    if ($akismet_active != 'true') {
        // Akismet is not active, so we don't do anything
        return false;
    }
    if (is_callable(array('Akismet', 'get_api_key'))) {
        // Akismet v3.0+
        $api_key = (bool) Akismet::get_api_key();
    } else {
        if (function_exists('akismet_get_key')) {
            $api_key = (bool) akismet_get_key();
        }
    }
    if (!$api_key) {
        // No api key, no glory
        return false;
    }
    if (!is_object($entry)) {
        // No object, no fuss
        return false;
    }
    $comment = array();
    $comment['comment_author'] = $entry->get_author_name();
    $comment['comment_author_email'] = $entry->get_author_email();
    $comment['comment_author_origin'] = $entry->get_author_origin();
    $comment['comment_author_url'] = $entry->get_author_website();
    $comment['comment_content'] = gwolle_gb_bbcode_strip($entry->get_content());
    $comment['blog'] = get_option('home');
    $comment['blog_lang'] = get_locale();
    $comment['blog_charset'] = get_option('blog_charset');
    $comment['user_ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']);
    $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
    if (isset($_SERVER['HTTP_REFERER'])) {
        $comment['referrer'] = $_SERVER['HTTP_REFERER'];
    }
    // http://blog.akismet.com/2012/06/19/pro-tip-tell-us-your-comment_type/
    $comment['comment_type'] = 'comment';
    $permalink = get_permalink(get_the_ID());
    if ($permalink) {
        $comment['permalink'] = $permalink;
    }
    $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW');
    foreach ($_SERVER as $key => $value) {
        if (!in_array($key, (array) $ignore)) {
            $comment["{$key}"] = $value;
        }
    }
    // Send the thing to the Akismet service
    return gwolle_gb_akismet_entry_check($comment, $action);
}
示例#2
0
 /**
  * is_enable
  * @return string APIキー
  */
 private function is_enable()
 {
     if (is_callable(array('Akismet', 'get_api_key'))) {
         return Akismet::get_api_key();
     }
     if (function_exists('akismet_get_key')) {
         return akismet_get_key();
     }
     return false;
 }
 public static function get_api_key()
 {
     if (is_callable(array('Akismet', 'get_api_key'))) {
         // Akismet v3.0+
         return (bool) Akismet::get_api_key();
     }
     if (function_exists('akismet_get_key')) {
         return (bool) akismet_get_key();
     }
     return false;
 }
 protected function is_akismet_available()
 {
     if (!class_exists('Akismet')) {
         return false;
     }
     $api_key = Akismet::get_api_key();
     if (empty($api_key)) {
         return false;
     }
     return true;
 }
示例#5
0
function wpcf7_akismet_is_available()
{
    if (is_callable(array('Akismet', 'get_api_key'))) {
        // Akismet v3.0+
        return (bool) Akismet::get_api_key();
    }
    if (function_exists('akismet_get_key')) {
        return (bool) akismet_get_key();
    }
    return false;
}
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;
}
示例#7
0
function akismet_get_key()
{
    _deprecated_function(__FUNCTION__, '3.0', 'Akismet::get_api_key()');
    return Akismet::get_api_key();
}
示例#8
0
<div class="wrap">
	<h2><?php 
esc_html_e('Akismet Stats', 'akismet');
if (!isset($hide_settings_link)) {
    ?>
 <a
			href="<?php 
    echo esc_url(Akismet_Admin::get_page_url());
    ?>
"
			class="add-new-h2"><?php 
    esc_html_e('Settings', 'akismet');
    ?>
</a><?php 
}
?>
</h2>
	<iframe
		src="<?php 
echo esc_url(sprintf('//akismet.com/web/1.0/user-stats.php?blog=%s&api_key=%s&locale=%s', urlencode(get_bloginfo('url')), Akismet::get_api_key(), get_locale()));
?>
"
		width="100%" height="2500px" frameborder="0" id="akismet-stats-frame"></iframe>
</div>
示例#9
0
function akismet_get_key()
{
    return Akismet::get_api_key();
}
	<div class="option-description">
		<strong><?php 
    esc_html_e('Manually enter an API key', 'akismet');
    ?>
</strong>
		<p><?php 
    esc_html_e('If you already know your API key.', 'akismet');
    ?>
</p>
	</div>
	<form action="<?php 
    echo esc_url(Akismet_Admin::get_page_url());
    ?>
" method="post" id="akismet-enter-api-key" class="right">
		<input id="key" name="key" type="text" size="15" value="<?php 
    echo esc_attr(Akismet::get_api_key());
    ?>
" class="regular-text code">
		<input type="hidden" name="action" value="enter-key">
		<?php 
    wp_nonce_field(Akismet_Admin::NONCE);
    ?>
		<input type="submit" name="submit" id="submit" class="button button-secondary" value="<?php 
    esc_attr_e('Use this key', 'akismet');
    ?>
">
	</form>
</div><?php 
}
?>
</div>
示例#11
0
=======
<div class="wrap">

	<h2><?php esc_html_e( 'Akismet' , 'akismet');?></h2>

	<div class="have-key">

		<?php if ( $stat_totals && isset( $stat_totals['all'] ) && (int) $stat_totals['all']->spam > 0 ) : ?>

			<div class="new-snapshot stats">

				<span style="float:right;margin:10px 15px -5px 0px">
					<a href="<?php echo esc_url( Akismet_Admin::get_page_url( 'stats' ) ); ?>" class=""><?php esc_html_e( 'Summaries' , 'akismet');?></a>
				</span>

				<iframe allowtransparency="true" scrolling="no" frameborder="0" style="width: 100%; height: 215px; overflow: hidden;" src="<?php printf( '//akismet.com/web/1.0/snapshot.php?blog=%s&api_key=%s&height=180&locale=%s', urlencode( get_bloginfo('url') ), Akismet::get_api_key(), get_locale() );?>"></iframe>
				<ul>
					<li>
						<h3><?php esc_html_e( 'Past six months' , 'akismet');?></h3>
						<span><?php echo number_format( $stat_totals['6-months']->spam );?></span>
						<?php esc_html_e( 'Spam blocked' , 'akismet');?>
					</li>
					<li>
						<h3><?php esc_html_e( 'All time' , 'akismet');?></h3>
						<span><?php echo number_format( $stat_totals['all']->spam );?></span>
						<?php esc_html_e( 'Spam blocked' , 'akismet');?>
					</li>
					<li>
						<h3><?php esc_html_e( 'Accuracy' , 'akismet');?></h3>
						<span><?php echo $stat_totals['all']->accuracy; ?>%</span>
						<?php printf(
示例#12
0
 /**
  * Check if akismet is available
  *
  * ## OPTIONS
  *
  * ## EXAMPLES
  *
  *     wp ametu akismet
  *
  * @synopsis
  */
 public function akismet()
 {
     try {
         if (!class_exists('Akismet')) {
             throw new \Exception('Akismet is not installed.');
         }
         if (!($key = \Akismet::get_api_key())) {
             throw new \Exception('Akismet API key is not set.');
         }
         if ('valid' !== \Akismet::verify_key($key)) {
             throw new \Exception('Akismet API key is invalid.');
         }
         static::s('Akismet is available!');
     } catch (\Exception $e) {
         static::e($e->getMessage());
     }
 }
 /**
  * Is Akismet registered and active?
  *
  * @since 4.3.0
  *
  * @return bool|WP_Error True if Akismet is active and registered. Otherwise, a WP_Error instance with the corresponding error.
  */
 private function akismet_is_active_and_registered()
 {
     if (!file_exists(WP_PLUGIN_DIR . '/akismet/class.akismet.php')) {
         return new WP_Error('not_installed', esc_html__('Please install Akismet.', 'jetpack'), array('status' => 400));
     }
     if (!class_exists('Akismet')) {
         return new WP_Error('not_active', esc_html__('Please activate Akismet.', 'jetpack'), array('status' => 400));
     }
     // What about if Akismet is put in a sub-directory or maybe in mu-plugins?
     require_once WP_PLUGIN_DIR . '/akismet/class.akismet.php';
     require_once WP_PLUGIN_DIR . '/akismet/class.akismet-admin.php';
     $akismet_key = Akismet::verify_key(Akismet::get_api_key());
     if (!$akismet_key || 'invalid' === $akismet_key || 'failed' === $akismet_key) {
         return new WP_Error('invalid_key', esc_html__('Invalid Akismet key. Please contact support.', 'jetpack'), array('status' => 400));
     }
     return true;
 }
示例#14
0
/**
 * Check post for spam, if spam then hold it for moderation.
 * @param  integer $post_id Post id.
 */
function ap_check_spam($post_id)
{
    // Return if akisment is not enabled.
    if (!class_exists('Akismet') || is_super_admin()) {
        return;
    }
    $post = get_post($post_id);
    // Set default arguments to pass.
    $defaults = array('blog' => home_url('/'), 'user_ip' => get_post_meta($post->ID, 'create_ip', true), 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'permalink' => get_permalink($post->ID), 'comment_type' => 'forum-post', 'comment_author' => get_the_author_meta('nicename', $post->post_author), 'comment_author_email' => get_the_author_meta('user_email', $post->post_author), 'comment_author_url' => get_the_author_meta('url', $post->post_author), 'comment_content' => $post->post_content);
    $akismet_ua = sprintf('WordPress/%s | Akismet/%s', $GLOBALS['wp_version'], constant('AKISMET_VERSION'));
    $akismet_ua = apply_filters('akismet_ua', $akismet_ua);
    $content_length = strlen($request);
    $api_key = Akismet::get_api_key();
    $host = Akismet::API_HOST;
    if (!empty($api_key)) {
        $host = $api_key . '.' . $host;
    }
    $http_host = $host;
    // Use a specific IP if provided.
    // Needed by Akismet_Admin::check_server_connectivity().
    if ($ip && long2ip(ip2long($ip))) {
        $http_host = $ip;
    }
    $http_args = array('body' => $defaults, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'Host' => $host, 'User-Agent' => $akismet_ua), 'httpversion' => '1.0', 'timeout' => 15);
    $akismet_url = $http_akismet_url = "http://{$http_host}/1.1/comment-check";
    /**
     * Try SSL first; if that fails, try without it and don't try it again for a while.
     */
    $ssl = $ssl_failed = false;
    // Check if SSL requests were disabled fewer than X hours ago.
    $ssl_disabled = get_option('akismet_ssl_disabled');
    if ($ssl_disabled && $ssl_disabled < time() - 60 * 60 * 24) {
        // 24 hours
        $ssl_disabled = false;
        delete_option('akismet_ssl_disabled');
    } else {
        if ($ssl_disabled) {
            do_action('akismet_ssl_disabled');
        }
    }
    if (!$ssl_disabled && function_exists('wp_http_supports') && ($ssl = wp_http_supports(array('ssl')))) {
        $akismet_url = set_url_scheme($akismet_url, 'https');
    }
    $response = wp_remote_post($akismet_url, $http_args);
    Akismet::log(compact('akismet_url', 'http_args', 'response'));
    if ($ssl && is_wp_error($response)) {
        // Intermittent connection problems may cause the first HTTPS
        // request to fail and subsequent HTTP requests to succeed randomly.
        // Retry the HTTPS request once before disabling SSL for a time.
        $response = wp_remote_post($akismet_url, $http_args);
        Akismet::log(compact('akismet_url', 'http_args', 'response'));
        if (is_wp_error($response)) {
            $ssl_failed = true;
            // Try the request again without SSL.
            $response = wp_remote_post($http_akismet_url, $http_args);
            Akismet::log(compact('http_akismet_url', 'http_args', 'response'));
        }
    }
    if (is_wp_error($response)) {
        return array('', '');
    }
    if ($ssl_failed) {
        // The request failed when using SSL but succeeded without it. Disable SSL for future requests.
        update_option('akismet_ssl_disabled', time());
        do_action('akismet_https_disabled');
    }
    if ($response['body']) {
        wp_update_post(array('ID' => $post_id, 'post_status' => 'moderate'));
    }
}
 /**
  * Get number of spam messages blocked by Akismet.
  *
  * @since 4.1.0
  *
  * @param WP_REST_Request $data {
  *     Array of parameters received by request.
  *
  *     @type string $date Date range to restrict results to.
  * }
  *
  * @return int|string Number of spam blocked by Akismet. Otherwise, an error message.
  */
 public static function akismet_get_stats_data(WP_REST_Request $data)
 {
     if (!is_wp_error($status = self::akismet_is_active_and_registered())) {
         return rest_ensure_response(Akismet_Admin::get_stats(Akismet::get_api_key()));
     } else {
         return $status->get_error_code();
     }
 }
示例#16
0
    ?>

			<div class="new-snapshot stats">

				<span style="float:right;margin:10px 15px -5px 0px">
					<a href="<?php 
    echo esc_url(Akismet_Admin::get_page_url('stats'));
    ?>
" class=""><?php 
    esc_html_e('Summaries', 'akismet');
    ?>
</a>
				</span>

				<iframe allowtransparency="true" scrolling="no" frameborder="0" style="width: 100%; height: 215px; overflow: hidden;" src="<?php 
    printf('//akismet.com/web/1.0/snapshot.php?blog=%s&api_key=%s&height=180&locale=%s', urlencode(get_bloginfo('url')), Akismet::get_api_key(), get_locale());
    ?>
"></iframe>
				<ul>
					<li>
						<h3><?php 
    esc_html_e('Past six months', 'akismet');
    ?>
</h3>
						<span><?php 
    echo number_format($stat_totals['6-months']->spam);
    ?>
</span>
						<?php 
    echo esc_html(_n('Spam blocked', 'Spam blocked', $stat_totals['6-months']->spam, 'akismet'));
    ?>
示例#17
0
<<<<<<< HEAD
<<<<<<< HEAD
<div class="wrap">
	<h2><?php esc_html_e( 'Akismet Stats' , 'akismet');?><?php if ( !isset( $hide_settings_link ) ): ?> <a href="<?php echo esc_url( Akismet_Admin::get_page_url() );?>" class="add-new-h2"><?php esc_html_e( 'Settings' , 'akismet');?></a><?php endif;?></h2> 
	<iframe src="<?php echo esc_url( sprintf( '//akismet.com/web/1.0/user-stats.php?blog=%s&api_key=%s&locale=%s', urlencode( get_bloginfo('url') ), Akismet::get_api_key(), get_locale() ) ); ?>" width="100%" height="2500px" frameborder="0" id="akismet-stats-frame"></iframe>
=======
<div class="wrap">
	<h2><?php esc_html_e( 'Akismet Stats' , 'akismet');?><?php if ( !isset( $hide_settings_link ) ): ?> <a href="<?php echo esc_url( Akismet_Admin::get_page_url() );?>" class="add-new-h2"><?php esc_html_e( 'Settings' , 'akismet');?></a><?php endif;?></h2> 
	<iframe src="<?php echo esc_url( sprintf( '//akismet.com/web/1.0/user-stats.php?blog=%s&api_key=%s&locale=%s', urlencode( get_bloginfo('url') ), Akismet::get_api_key(), get_locale() ) ); ?>" width="100%" height="2500px" frameborder="0" id="akismet-stats-frame"></iframe>
>>>>>>> b875702c9c06ab5012e52ff4337439b03918f453
=======
<div class="wrap">
	<h2><?php esc_html_e( 'Akismet Stats' , 'akismet');?><?php if ( !isset( $hide_settings_link ) ): ?> <a href="<?php echo esc_url( Akismet_Admin::get_page_url() );?>" class="add-new-h2"><?php esc_html_e( 'Settings' , 'akismet');?></a><?php endif;?></h2> 
	<iframe src="<?php echo esc_url( sprintf( '//akismet.com/web/1.0/user-stats.php?blog=%s&api_key=%s&locale=%s', urlencode( get_bloginfo('url') ), Akismet::get_api_key(), get_locale() ) ); ?>" width="100%" height="2500px" frameborder="0" id="akismet-stats-frame"></iframe>
>>>>>>> b875702c9c06ab5012e52ff4337439b03918f453
</div>
 public static function display_notice()
 {
     global $hook_suffix;
     if (in_array($hook_suffix, array('jetpack_page_akismet-key-config', 'settings_page_akismet-key-config', 'edit-comments.php')) && (int) get_option('akismet_alert_code') > 0) {
         self::display_alert();
     } elseif ($hook_suffix == 'plugins.php' && !Akismet::get_api_key()) {
         self::display_api_key_warning();
     } elseif ($hook_suffix == 'edit-comments.php' && wp_next_scheduled('akismet_schedule_cron_recheck')) {
         self::display_spam_check_warning();
     } elseif (in_array($hook_suffix, array('jetpack_page_akismet-key-config', 'settings_page_akismet-key-config')) && Akismet::get_api_key()) {
         self::display_status();
     }
 }
 /**
  * Verify the $_POST using Akismet
  *
  * @filter akismet_comment_nonce
  * @link http://akismet.com/development/api/#comment-check
  * @uses akismet_init()
  * @uses akismet_auto_check_comment()
  *
  */
 function akismetCheck($Contact)
 {
     global $akismet_api_host, $akismet_api_port;
     // Disable using a filter
     if (apply_filters('disable_constant_contact_akismet', false)) {
         return true;
     }
     // Akismet not activated
     if (!class_exists('Akismet')) {
         do_action('ctct_activity', 'The Akismet class does not exist. Please upgrade to Version 3+ of Akismet.');
         return true;
     }
     $key = Akismet::get_api_key();
     if (empty($key)) {
         do_action('ctct_activity', 'Empty Akismet API key. Not processing.');
         return true;
     }
     /** Disable nonce verification */
     add_filter('akismet_comment_nonce', function () {
         return 'inactive';
     });
     ob_start();
     $comment_data = array('user_ID' => get_current_user_id(), 'comment_post_ID' => isset($_POST['cc_referral_post_id']) ? intval($_POST['cc_referral_post_id']) : NULL, 'comment_author' => $Contact->get('name'), 'comment_author_email' => $Contact->get('email'), 'is_test' => apply_filters('constant_contact_akismet_is_test', false));
     $check = Akismet::auto_check_comment($comment_data);
     ob_clean();
     if (empty($check) || empty($check['akismet_result'])) {
         do_action('ctct_activity', 'There was an issue with Akismet: the response was invalid.', $check);
     } else {
         switch ($check['akismet_result']) {
             case 'true':
                 do_action('ctct_activity', __('Akismet caught this entry as spam'), $check);
                 return new WP_Error('akismet', __('Your entry was flagged as spam.'), $check);
                 break;
             case 'false':
                 do_action('ctct_activity', __('Akismet cleared this comment'), $check);
                 break;
             default:
                 do_action('ctct_error', sprintf(__('Akismet was unable to check this entry (response: %s), will automatically retry again later.'), substr($check['akismet_result'], 0, 50)), $check);
         }
     }
     return true;
 }