akismet_admin_warnings

Definition:
function akismet_admin_warnings() {}

Defined filters

  • akismet_spam_count_incr
    apply_filters('akismet_spam_count_incr', 1)
  • akismet_spam_count_incr
    apply_filters('akismet_spam_count_incr', 1)

Defined actions

  • akismet_spam_caught
    do_action( 'akismet_spam_caught' );

Source code

function akismet_admin_warnings() {

	global $wpcom_api_key;

	if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) {

		function akismet_warning() {

			echo "

			<div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet is almost ready.')."</strong> ".sprintf(__('You must <a href="%1$s">enter your Akismet API key</a> for it to work.'), "plugins.php?page=akismet-key-config")."</p></div>

			";

		}

		add_action('admin_notices', 'akismet_warning');

		return;

	} elseif ( get_option('akismet_connectivity_time') && empty($_POST) && is_admin() && !akismet_server_connectivity_ok() ) {

		function akismet_warning() {

			echo "

			<div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet has detected a problem.')."</strong> ".sprintf(__('A server or network problem is preventing Akismet from working correctly.  <a href="%1$s">Click here for more information</a> about how to fix the problem.'), "plugins.php?page=akismet-key-config")."</p></div>

			";

		}

		add_action('admin_notices', 'akismet_warning');

		return;

	}

}



function akismet_get_host($host) {

	// if all servers are accessible, just return the host name.

	// if not, return an IP that was known to be accessible at the last check.

	if ( akismet_server_connectivity_ok() ) {

		return $host;

	} else {

		$ips = akismet_get_server_connectivity();

		// a firewall may be blocking access to some Akismet IPs

		if ( count($ips) > 0 && count(array_filter($ips)) < count($ips) ) {

			// use DNS to get current IPs, but exclude any known to be unreachable

			$dns = (array)gethostbynamel( rtrim($host, '.') . '.' );

			$dns = array_filter($dns);

			foreach ( $dns as $ip ) {

				if ( array_key_exists( $ip, $ips ) && empty( $ips[$ip] ) )

					unset($dns[$ip]);

			}

			// return a random IP from those available

			if ( count($dns) )

				return $dns[ array_rand($dns) ];

			

		}

	}

	// if all else fails try the host name

	return $host;

}



// return a comma-separated list of role names for the given user

function akismet_get_user_roles($user_id ) {

	$roles = false;

	

	if ( !class_exists('WP_User') )

		return false;

	

	if ( $user_id > 0 ) {

		$comment_user = new WP_User($user_id);

		if ( isset($comment_user->roles) )

			$roles = join(',', $comment_user->roles);

	}

	

	return $roles;

}



// Returns array with headers in $response[0] and body in $response[1]

function akismet_http_post($request, $host, $path, $port = 80, $ip=null) {

	global $wp_version;

	

	$akismet_version = constant('AKISMET_VERSION');



	$http_request  = "POST $path HTTP/1.0\r\n";

	$http_request .= "Host: $host\r\n";

	$http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";

	$http_request .= "Content-Length: " . strlen($request) . "\r\n";

	$http_request .= "User-Agent: WordPress/$wp_version | Akismet/$akismet_version\r\n";

	$http_request .= "\r\n";

	$http_request .= $request;

	

	$http_host = $host;

	// use a specific IP if provided - needed by akismet_check_server_connectivity()

	if ( $ip && long2ip(ip2long($ip)) ) {

		$http_host = $ip;

	} else {

		$http_host = akismet_get_host($host);

	}



	$response = '';

	if( false != ( $fs = @fsockopen($http_host, $port, $errno, $errstr, 10) ) ) {

		fwrite($fs, $http_request);



		while ( !feof($fs) )

			$response .= fgets($fs, 1160); // One TCP-IP packet

		fclose($fs);

		$response = explode("\r\n\r\n", $response, 2);

	}

	return $response;

}



// filter handler used to return a spam result to pre_comment_approved

function akismet_result_spam( $approved ) {

	// bump the counter here instead of when the filter is added to reduce the possibility of overcounting

	if ( $incr = apply_filters('akismet_spam_count_incr', 1) )

		update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );

	return 'spam';

}



function akismet_auto_check_comment( $commentdata ) {

	global $akismet_api_host, $akismet_api_port;



	$comment = $commentdata;

	$comment['user_ip']    = $_SERVER['REMOTE_ADDR'];

	$comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];

	$comment['referrer']   = $_SERVER['HTTP_REFERER'];

	$comment['blog']       = get_option('home');

	$comment['blog_lang']  = get_locale();

	$comment['blog_charset'] = get_option('blog_charset');

	$comment['permalink']  = get_permalink($comment['comment_post_ID']);

	

	$comment['user_role'] = akismet_get_user_roles($comment['user_ID']);



	$ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );



	foreach ( $_SERVER as $key => $value )

		if ( !in_array( $key, $ignore ) && is_string($value) )

			$comment["$key"] = $value;

		else

			$comment["$key"] = '';



	$query_string = '';

	foreach ( $comment as $key => $data )

		$query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';



	$response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);

	$commentdata['akismet_result'] = $response[1];

	if ( 'true' == $response[1] ) {

		// akismet_spam_count will be incremented later by akismet_result_spam()

		add_filter('pre_comment_approved', 'akismet_result_spam');



		do_action( 'akismet_spam_caught' );



		$post = get_post( $comment['comment_post_ID'] );

		$last_updated = strtotime( $post->post_modified_gmt );

		$diff = time() - $last_updated;

		$diff = $diff / 86400;

		

		if ( $post->post_type == 'post' && $diff > 30 && get_option( 'akismet_discard_month' ) == 'true' && empty($comment['user_ID']) ) {

			// akismet_result_spam() won't be called so bump the counter here

			if ( $incr = apply_filters('akismet_spam_count_incr', 1) )

409

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: