php-bootstrap-boilerplate / lib / akismet.php

<?php

/**
	Akismet plugin for the PHP Fat-Free Framework

	The contents of this file are subject to the terms of the GNU General
	License Version 3.0. You may not use this file except in
	compliance with the license. Any of the license terms and conditions
	can be waived if you get permission from the copyright holder.

	Copyright (c) 2009-2012 F3::Factory
	Bong Cosca <bong.cosca@yahoo.com>

		@package Akismet
		@version 2.0.13
**/

//! Akismet API adaptor
class Akismet extends Base {

	//@{ Locale-specific error/exception messages
	const
		TEXT_VerifyFail='Akismet verification failed';
	//@}

	static
		//! Akismet key verification flag
		$verified=FALSE,
		//! Verification key (NULL if unverified/invalid)
		$key=NULL;

	/**
		Akismet key verification
			@return boolean
			@param $key string
			@public
	**/
	static function verify($key) {
		$response=Web::http(
			'GET http://rest.akismet.com/1.1/verify-key',
			http_build_query(
				array(
					'key'=>$key,
					'blog'=>'http://'.$_SERVER['SERVER_NAME']
				)
			)
		);
		if (preg_match('/invalid/i',$response)) {
			trigger_error(self::TEXT_VerifyFail);
			self::$key=NULL;
		}
		else
			self::$key=$key;
		return self::$key;
	}

	/**
		Forward content for spam checking
			@return boolean
			@param $text string
			@param $author string
			@param $email string
			@param $url string
			@public
	**/
	static function check($text,$author,$email,$url) {
		$response=Web::http(
			'GET http://'.self::$key.'.rest.akismet.com/1.1/comment-check',
			http_build_query(
				array(
					'comment_content'=>$text,
					'comment_author'=>$author,
					'comment_author_email'=>$email,
					'comment_author_url'=>$url,
					'user_agent'=>$_SERVER['HTTP_USER_AGENT'],
					'referrer'=>$_SERVER['HTTP_REFERER'],
					'blog'=>'http://'.$_SERVER['SERVER_NAME'],
					'permalink'=>'http://'.$_SERVER['SERVER_NAME'].'/'.
						$_SERVER['REQUEST_URI']
				)
			)
		);
		return (boolean)$response;
	}

	/**
		Report content that was not marked as spam
			@return boolean
			@param $text string
			@param $author string
			@param $email string
			@param $url string
			@public
	**/
	static function spam($text,$author,$email,$url) {
		$response=Web::http(
			'GET http://'.self::$key.'.rest.akismet.com/1.1/submit-spam',
			http_build_query(
				array(
					'comment_content'=>$text,
					'comment_author'=>$author,
					'comment_author_email'=>$email,
					'comment_author_url'=>$url,
					'user_agent'=>$_SERVER['HTTP_USER_AGENT'],
					'referrer'=>$_SERVER['HTTP_REFERER'],
					'blog'=>'http://'.$_SERVER['SERVER_NAME'],
					'permalink'=>'http://'.$_SERVER['SERVER_NAME'].'/'.
						$_SERVER['REQUEST_URI']
				)
			)
		);
		return (boolean)$response;
	}

	/**
		Report content as a false positive
			@return boolean
			@param $text string
			@param $author string
			@param $email string
			@param $url string
			@public
	**/
	static function ham($text,$author,$email,$url) {
		$response=Web::http(
			'GET http://'.self::$key.'.rest.akismet.com/1.1/submit-ham',
			http_build_query(
				array(
					'comment_content'=>$text,
					'comment_author'=>$author,
					'comment_author_email'=>$email,
					'comment_author_url'=>$url,
					'user_agent'=>$_SERVER['HTTP_USER_AGENT'],
					'referrer'=>$_SERVER['HTTP_REFERER'],
					'blog'=>'http://'.$_SERVER['SERVER_NAME'],
					'permalink'=>'http://'.$_SERVER['SERVER_NAME'].'/'.
						$_SERVER['REQUEST_URI']
				)
			)
		);
		return (boolean)$response;
	}

}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.