[pLog-svn] r5800 - in plugins/branches/lifetype-1.2/akismet: . class/action class/security
pwestbro at devel.lifetype.net
pwestbro at devel.lifetype.net
Sun Aug 5 22:42:53 EDT 2007
Author: pwestbro
Date: 2007-08-05 22:42:53 -0400 (Sun, 05 Aug 2007)
New Revision: 5800
Modified:
plugins/branches/lifetype-1.2/akismet/class/action/pluginakismetsubmitcommentaction.class.php
plugins/branches/lifetype-1.2/akismet/class/action/pluginakismetupdateconfigaction.class.php
plugins/branches/lifetype-1.2/akismet/class/security/Akismet.class.php
plugins/branches/lifetype-1.2/akismet/class/security/akismetfilter.class.php
plugins/branches/lifetype-1.2/akismet/pluginakismet.class.php
Log:
Upgraded to version 0.3.3 of the Akismet php class
This version doesn't use exceptions to deal with errors, so special error
handlers don't have to be installed.
Modified: plugins/branches/lifetype-1.2/akismet/class/action/pluginakismetsubmitcommentaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/akismet/class/action/pluginakismetsubmitcommentaction.class.php 2007-08-05 21:07:04 UTC (rev 5799)
+++ plugins/branches/lifetype-1.2/akismet/class/action/pluginakismetsubmitcommentaction.class.php 2007-08-06 02:42:53 UTC (rev 5800)
@@ -14,8 +14,6 @@
* Action that shows a list of all the comments for a given post
*/
- $akismetError2 = false;
-
class PluginAkismetSubmitCommentAction extends AdminAction
{
@@ -65,8 +63,6 @@
*/
function _submitComments()
{
- global $akismetError2;
-
$comments = new ArticleComments();
$errorMessage = "";
$successMessage = "";
@@ -89,6 +85,8 @@
$article = null;
}
+ $errorsOccured = false;
+
// loop through the comments and remove them
foreach( $this->_commentIds as $commentId ) {
@@ -107,36 +105,35 @@
$blogSettings = $this->_blogInfo->getSettings();
$apiKey = $blogSettings->getValue( "plugin_akismet_api_key" );
+
+ $akismetComment = Array();
+ if ( $comment->getUserName() != "" )
+ $akismetComment['author'] = $comment->getUserName();
- set_error_handler('_akismetFilterSubmitErrorHandler');
-
- $akismet = new Akismet($rg->blogLink(), $apiKey);
+ if ( $comment->getUserEmail() != "" )
+ $akismetComment['email'] = $comment->getUserEmail();
+ $akismetComment['website'] = $comment->getUserUrl();
+ $akismetComment['body'] = $comment->getText();
+
- if ( $akismetError2 == true ) {
- restore_error_handler();
-
+ lt_include( PLOG_CLASS_PATH."class/dao/article.class.php");
+ $commentArticle = $comment->getArticle();
+ $akismetComment['permalink'] = $rg->postPermalink($commentArticle);
+
+ $akismet = new Akismet($rg->blogLink(), $apiKey, $akismetComment);
+
+
+ if ( $akismet->errorsExist() == true ) {
+
+ $errorsOccured = true;
continue;
}
- if ( $comment->getUserName() != "" )
- $akismet->setAuthor($comment->getUserName());
-
- if ( $comment->getUserEmail() != "" )
- $akismet->setAuthorEmail($comment->getUserEmail());
- $akismet->setAuthorURL($comment->getUserUrl());
- $akismet->setContent($comment->getText());
- $akismet->setType("comment");
-
- lt_include( PLOG_CLASS_PATH."class/dao/article.class.php");
-
- $commentArticle = $comment->getArticle();
-
- $akismet->setPermalink( $rg->postPermalink($commentArticle) );
-
$akismet->submitSpam();
- restore_error_handler();
+ $errorsOccured = $akismet->errorsExist();
+
}
}
@@ -146,7 +143,7 @@
else
$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $article ));
- if ( $akismetError2 == true ) {
+ if ( $errorsOccured == true ) {
$this->_view->setErrorMessage( $this->_locale->pr("akismet_failed_submit_spam") );
} else {
$this->_view->setSuccessMessage( $this->_locale->pr("akismet_sucess_submit_spam") );
@@ -158,15 +155,5 @@
}
}
- /**
- * This error handler temporarily overloads the LifeType one
- * occurs.
- */
- function _akismetFilterSubmitErrorHandler( $errorCode, $errorString )
- {
- global $akismetError2;
-
- $akismetError2 = true;
- }
?>
\ No newline at end of file
Modified: plugins/branches/lifetype-1.2/akismet/class/action/pluginakismetupdateconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/akismet/class/action/pluginakismetupdateconfigaction.class.php 2007-08-05 21:07:04 UTC (rev 5799)
+++ plugins/branches/lifetype-1.2/akismet/class/action/pluginakismetupdateconfigaction.class.php 2007-08-06 02:42:53 UTC (rev 5800)
@@ -21,8 +21,6 @@
lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
lt_include( PLOG_CLASS_PATH."plugins/akismet/class/view/pluginakismetconfigview.class.php" );
- $apiKeyValid = true;
-
class PluginAkismetUpdateConfigAction extends AdminAction
{
@@ -65,11 +63,10 @@
// Check the API key to see if it is valid
lt_include( PLOG_CLASS_PATH."plugins/akismet/class/security/Akismet.class.php" );
- set_error_handler('_akismetErrorHandler');
- $akismet = new Akismet($rg->blogLink(), $this->_apiKey);
- restore_error_handler();
+ $dummyComment = Array();
+ $akismet = new Akismet($rg->blogLink(), $this->_apiKey, $dummyComment);
- if ( $apiKeyValid == false )
+ if ( $akismet->errorsExist() )
{
$this->_view = new PluginAkismetConfigView( $this->_blogInfo );
$this->_view->setErrorMessage( $this->_locale->tr("akismet_invalid_api_key"));
@@ -121,15 +118,4 @@
}
}
- /**
- * This error handler temporarily overloads the LifeType one
- * occurs.
- */
- function _akismetErrorHandler( $errorCode, $errorString )
- {
- global $apiKeyValid;
-
- $apiKeyValid = false;
- }
-
?>
Modified: plugins/branches/lifetype-1.2/akismet/class/security/Akismet.class.php
===================================================================
--- plugins/branches/lifetype-1.2/akismet/class/security/Akismet.class.php 2007-08-05 21:07:04 UTC (rev 5799)
+++ plugins/branches/lifetype-1.2/akismet/class/security/Akismet.class.php 2007-08-06 02:42:53 UTC (rev 5800)
@@ -1,371 +1,355 @@
<?php
/**
- * Akismet anti-comment spam service
+ * 01.26.2006 12:29:28est
+ *
+ * Akismet PHP4 class
+ *
+ * <b>Usage</b>
+ * <code>
+ * $comment = array(
+ * 'author' => 'viagra-test-123',
+ * 'email' => 'test at example.com',
+ * 'website' => 'http://www.example.com/',
+ * 'body' => 'This is a test comment',
+ * 'permalink' => 'http://yourdomain.com/yourblogpost.url',
+ * );
*
- * The class in this package allows use of the {@link http://akismet.com Akismet} anti-comment spam service in any PHP5 application.
+ * $akismet = new Akismet('http://www.yourdomain.com/', 'YOUR_WORDPRESS_API_KEY', $comment);
*
- * This service performs a number of checks on submitted data and returns whether or not the data is likely to be spam.
- *
- * Please note that in order to use this class, you must have a vaild {@link http://wordpress.com/api-keys/ WordPress API key}. They are free for non/small-profit types and getting one will only take a couple of minutes.
- *
- * For commercial use, please {@link http://akismet.com/commercial/ visit the Akismet commercial licensing page}.
- *
- * Please be aware that this class is PHP5 only. Attempts to run it under PHP4 will most likely fail.
- *
- * See the Akismet class documentation page linked to below for usage information.
- *
- * @package Akismet
- * @author Alex Potsides, {@link http://www.achingbrain.net http://www.achingbrain.net}, Bret Kuhns {@link http://www.miphp.net}
- * @version 0.1
- * @copyright Alex Potsides, {@link http://www.achingbrain.net http://www.achingbrain.net}
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
+ * if($akismet->isError()) {
+ * echo"Couldn't connected to Akismet server!";
+ * } else {
+ * if($akismet->isSpam()) {
+ * echo"Spam detected";
+ * } else {
+ * echo"yay, no spam!";
+ * }
+ * }
+ * </code>
+ *
+ * @author Bret Kuhns {@link www.miphp.net}
+ * @link http://www.miphp.net/blog/view/php4_akismet_class/
+ * @version 0.3.3
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-/**
- * The Akismet PHP4 Class
- *
- * This class takes the functionality from the Akismet WordPress plugin written by {@link http://photomatt.net/ Matt Mullenweg} and allows it to be integrated into any PHP5 application or website.
- *
- * The original plugin is {@link http://akismet.com/download/ available on the Akismet website}.
- *
- * <b>Usage:</b>
- * <code>
- * $akismet = new Akismet('http://www.example.com/blog/', 'aoeu1aoue');
- * $akismet->setCommentAuthor($name);
- * $akismet->setCommentAuthorEmail($email);
- * $akismet->setCommentAuthorURL($url);
- * $akismet->setCommentContent($comment);
- * $akismet->setPermalink('http://www.example.com/blog/alex/someurl/');
- * if($akismet->isCommentSpam())
- * // store the comment but mark it as spam (in case of a mis-diagnosis)
- * else
- * // store the comment normally
- * </code>
- *
- * @package akismet
- * @name Akismet
- * @version 0.2
- * @author Alex Potsides (converted to PHP4 by Bret Kuhns)
- * @link http://www.achingbrain.net/
- */
-class Akismet {
- var $version = '0.2';
- var $wordPressAPIKey;
- var $blogURL;
- var $comment;
- var $apiPort;
- var $akismetServer;
- var $akismetVersion;
- // This prevents some potentially sensitive information from being sent accross the wire.
- var $ignore = array(
- 'HTTP_COOKIE',
- 'HTTP_X_FORWARDED_FOR',
- 'HTTP_X_FORWARDED_HOST',
- 'HTTP_MAX_FORWARDS',
- 'HTTP_X_FORWARDED_SERVER',
- 'REDIRECT_STATUS',
- 'SERVER_PORT',
- 'PATH',
- 'DOCUMENT_ROOT',
- 'SERVER_ADMIN',
- 'QUERY_STRING',
- 'PHP_SELF',
- 'argv',
- 'argc'
- );
+// Error constants
+define("AKISMET_SERVER_NOT_FOUND", 0);
+define("AKISMET_RESPONSE_FAILED", 1);
+define("AKISMET_INVALID_KEY", 2);
- /**
- * @throws Exception An exception is thrown if your API key is invalid.
- * @param string Your WordPress API key.
- * @param string $blogURL The URL of your blog.
- */
- function Akismet($blogURL, $wordPressAPIKey) {
- $this->blogURL = $blogURL;
- $this->wordPressAPIKey = $wordPressAPIKey;
- // Set some default values
- $this->apiPort = 80;
- $this->akismetServer = 'rest.akismet.com';
- $this->akismetVersion = '1.1';
- // Start to populate the comment data
- $this->comment['blog'] = $blogURL;
- $this->comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
- $this->comment['referrer'] = $_SERVER['HTTP_REFERER'];
-
- // This is necessary if the server PHP5 is running on has been set up to run PHP4 and
- // PHP5 concurently and is actually running through a separate proxy al a these instructions:
- // http://www.schlitt.info/applications/blog/archives/83_How_to_run_PHP4_and_PHP_5_parallel.html
- // and http://wiki.coggeshall.org/37.html
- // Otherwise the user_ip appears as the IP address of the PHP4 server passing the requests to the
- // PHP5 one...
- $this->comment['user_ip'] = $_SERVER['REMOTE_ADDR'] != getenv('SERVER_ADDR') ? $_SERVER['REMOTE_ADDR'] : getenv('HTTP_X_FORWARDED_FOR');
-
- // Check to see if the key is valid
- $response = $this->http_post('key=' . $this->wordPressAPIKey . '&blog=' . $this->blogURL, $this->akismetServer, '/' . $this->akismetVersion . '/verify-key');
-
- if($response[1] != 'valid') {
- // Whoops, no it's not. Throw an exception as we can't proceed without a valid API key.
- trigger_error('Invalid API key. Please obtain one from http://wordpress.com/api-keys/', E_USER_ERROR);
- // set a boolean indicating that the ket is not valid, in case the above didn't
- // throw an exception
- $this->valid_key = false;
- }
- }
-
- function http_post($request, $host, $path) {
- $http_request =
- "POST " . $path . " HTTP/1.1\r\n" .
- "Host: " . $host . "\r\n" .
- "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" .
- "Content-Length: " . strlen($request) . "\r\n" .
- "User-Agent: Akismet PHP5 Class " . $this->version . " | Akismet/1.11\r\n" .
- "\r\n" .
- $request
- ;
-
- $socketWriteRead = new SocketWriteRead($host, $this->apiPort, $http_request);
- $socketWriteRead->send();
-
- return explode("\r\n\r\n", $socketWriteRead->getResponse(), 2);
- }
-
- // Formats the data for transmission echo $sql;
- function getQueryString() {
- foreach($_SERVER as $key => $value) {
- if(!in_array($key, $this->ignore)) {
- if($key == 'REMOTE_ADDR') {
- $this->comment[$key] = $this->comment['user_ip'];
- } else {
- $this->comment[$key] = $value;
- }
- }
- }
-
- $query_string = '';
-
- foreach($this->comment as $key => $data) {
- $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
- }
-
- return $query_string;
- }
-
+// Base class to assist in error handling between Akismet classes
+class AkismetObject {
+ var $errors = array();
+
+
/**
- * Tests for spam.
+ * Add a new error to the errors array in the object
*
- * Uses the web service provided by {@link http://www.akismet.com Akismet} to see whether or not the submitted comment is spam. Returns a boolean value.
- *
- * @return bool True if the comment is spam, false if not
- */
- function isSpam() {
- $response = $this->http_post($this->getQueryString(), $this->wordPressAPIKey . '.rest.akismet.com', '/' . $this->akismetVersion . '/comment-check');
-
- return ($response[1] == 'true');
+ * @param String $name A name (array key) for the error
+ * @param String $string The error message
+ * @return void
+ */
+ // Set an error in the object
+ function setError($name, $message) {
+ $this->errors[$name] = $message;
}
+
/**
- * Submit spam that is incorrectly tagged as ham.
+ * Return a specific error message from the errors array
*
- * Using this function will make you a good citizen as it helps Akismet to learn from its mistakes. This will improve the service for everybody.
+ * @param String $name The name of the error you want
+ * @return mixed Returns a String if the error exists, a false boolean if it does not exist
*/
- function submitSpam() {
- $this->http_post($this->getQueryString(), $this->wordPressAPIKey . '.' . $this->akismetServer, '/' . $this->akismetVersion . '/submit-spam');
+ function getError($name) {
+ if($this->isError($name)) {
+ return $this->errors[$name];
+ } else {
+ return false;
+ }
}
-
+
+
/**
- * Submit ham that is incorrectly tagged as spam.
+ * Return all errors in the object
*
- * Using this function will make you a good citizen as it helps Akismet to learn from its mistakes. This will improve the service for everybody.
- */
- function submitHam() {
- $this->http_post($this->getQueryString(), $this->wordPressAPIKey . '.' . $this->akismetServer, '/' . $this->akismetVersion . '/submit-ham');
+ * @return String[]
+ */
+ function getErrors() {
+ return (array)$this->errors;
}
-
+
+
/**
- * To override the user IP address when submitting spam/ham later on
+ * Check if a certain error exists
*
- * @param string $userip An IP address. Optional.
- */
- function setUserIP($userip) {
- $this->comment['user_ip'] = $userip;
+ * @param String $name The name of the error you want
+ * @return boolean
+ */
+ function isError($name) {
+ return isset($this->errors[$name]);
}
-
+
+
/**
- * To override the referring page when submitting spam/ham later on
+ * Check if any errors exist
*
- * @param string $referrer The referring page. Optional.
+ * @return boolean
*/
- function setReferrer($referrer) {
- $this->comment['referrer'] = $referrer;
+ function errorsExist() {
+ return (count($this->errors) > 0);
}
+
+
+}
- /**
- * A permanent URL referencing the blog post the comment was submitted to.
- *
- * @param string $permalink The URL. Optional.
- */
- function setPermalink($permalink) {
- $this->comment['permalink'] = $permalink;
- }
- /**
- * The type of comment being submitted.
- *
- * May be blank, comment, trackback, pingback, or a made up value like "registration" or "wiki".
- */
- function setType($commentType) {
- $this->comment['comment_type'] = $commentType;
- }
- /**
- * The name that the author submitted with the comment.
- */
- function setAuthor($commentAuthor) {
- $this->comment['comment_author'] = $commentAuthor;
- }
- /**
- * The email address that the author submitted with the comment.
- *
- * The address is assumed to be valid.
- */
- function setAuthorEmail($authorEmail) {
- $this->comment['comment_author_email'] = $authorEmail;
- }
- /**
- * The URL that the author submitted with the comment.
- */
- function setAuthorURL($authorURL) {
- $this->comment['comment_author_url'] = $authorURL;
+// Used by the Akismet class to communicate with the Akismet service
+class AkismetHttpClient extends AkismetObject {
+ var $akismetVersion = '1.1';
+ var $con;
+ var $host;
+ var $port;
+ var $apiKey;
+ var $blogUrl;
+ var $errors = array();
+
+
+ // Constructor
+ function AkismetHttpClient($host, $blogUrl, $apiKey, $port = 80) {
+ $this->host = $host;
+ $this->port = $port;
+ $this->blogUrl = $blogUrl;
+ $this->apiKey = $apiKey;
}
+
+
+ // Use the connection active in $con to get a response from the server and return that response
+ function getResponse($request, $path, $type = "post", $responseLength = 1160) {
+ $this->_connect();
+
+ if($this->con && !$this->isError(AKISMET_SERVER_NOT_FOUND)) {
+ $request =
+ strToUpper($type)." /{$this->akismetVersion}/$path HTTP/1.1\r\n" .
+ "Host: ".((!empty($this->apiKey)) ? $this->apiKey."." : null)."{$this->host}\r\n" .
+ "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" .
+ "Content-Length: ".strlen($request)."\r\n" .
+ "User-Agent: Akismet PHP4 Class\r\n" .
+ "\r\n" .
+ $request
+ ;
+ $response = "";
- /**
- * The comment's body text.
- */
- function setContent($commentBody) {
- $this->comment['comment_content'] = $commentBody;
- }
+ @fwrite($this->con, $request);
- /**
- * Defaults to 80
- */
- function setAPIPort($apiPort) {
- $this->apiPort = $apiPort;
+ while(!feof($this->con)) {
+ $response .= @fgets($this->con, $responseLength);
+ }
+
+ $response = explode("\r\n\r\n", $response, 2);
+ return $response[1];
+ } else {
+ $this->setError(AKISMET_RESPONSE_FAILED, "The response could not be retrieved.");
+ }
+
+ $this->_disconnect();
}
+
+
+ // Connect to the Akismet server and store that connection in the instance variable $con
+ function _connect() {
+ if(!($this->con = @fsockopen($this->host, $this->port))) {
+ $this->setError(AKISMET_SERVER_NOT_FOUND, "Could not connect to akismet server.");
+ }
+ }
+
+
+ // Close the connection to the Akismet server
+ function _disconnect() {
+ @fclose($this->con);
+ }
+
+
+}
+
+
+
+
+// The controlling class. This is the ONLY class the user should instantiate in
+// order to use the Akismet service!
+class Akismet extends AkismetObject {
+ var $apiPort = 80;
+ var $akismetServer = 'rest.akismet.com';
+ var $akismetVersion = '1.1';
+ var $http;
+
+ var $ignore = array(
+ 'HTTP_COOKIE',
+ 'HTTP_X_FORWARDED_FOR',
+ 'HTTP_X_FORWARDED_HOST',
+ 'HTTP_MAX_FORWARDS',
+ 'HTTP_X_FORWARDED_SERVER',
+ 'REDIRECT_STATUS',
+ 'SERVER_PORT',
+ 'PATH',
+ 'DOCUMENT_ROOT',
+ 'SERVER_ADMIN',
+ 'QUERY_STRING',
+ 'PHP_SELF',
+ 'argv'
+ );
+
+ var $blogUrl = "";
+ var $apiKey = "";
+ var $comment = array();
+
+
/**
- * Defaults to rest.akismet.com
+ * Constructor
+ *
+ * Set instance variables, connect to Akismet, and check API key
+ *
+ * @param String $blogUrl The URL to your own blog
+ * @param String $apiKey Your wordpress API key
+ * @param String[] $comment A formatted comment array to be examined by the Akismet service
*/
- function setAkismetServer($akismetServer) {
- $this->akismetServer = $akismetServer;
+ function Akismet($blogUrl, $apiKey, $comment) {
+ $this->blogUrl = $blogUrl;
+ $this->apiKey = $apiKey;
+
+ // Populate the comment array with information needed by Akismet
+ $this->comment = $comment;
+ $this->_formatCommentArray();
+
+ if(!isset($this->comment['user_ip'])) {
+ $this->comment['user_ip'] = ($_SERVER['REMOTE_ADDR'] != getenv('SERVER_ADDR')) ? $_SERVER['REMOTE_ADDR'] : getenv('HTTP_X_FORWARDED_FOR');
+ }
+ if(!isset($this->comment['user_agent'])) {
+ $this->comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
+ }
+ if(!isset($this->comment['referrer'])) {
+ $this->comment['referrer'] = $_SERVER['HTTP_REFERER'];
+ }
+ $this->comment['blog'] = $blogUrl;
+
+ // Connect to the Akismet server and populate errors if they exist
+ $this->http = new AkismetHttpClient($this->akismetServer, $blogUrl, $apiKey);
+ if($this->http->errorsExist()) {
+ $this->errors = array_merge($this->errors, $this->http->getErrors());
+ }
+
+ // Check if the API key is valid
+ if(!$this->_isValidApiKey($apiKey)) {
+ $this->setError(AKISMET_INVALID_KEY, "Your Akismet API key is not valid.");
+ }
}
-
+
+
/**
- * Defaults to '1.1'
+ * Query the Akismet and determine if the comment is spam or not
+ *
+ * @return boolean
*/
- function setAkismetVersion($akismetVersion) {
- $this->akismetVersion = $akismetVersion;
+ function isSpam() {
+ $response = $this->http->getResponse($this->_getQueryString(), 'comment-check');
+
+ return ($response == "true");
}
-}
-
-
-/**
- * Utility class used by Akismet
- *
- * This class is used by Akismet to do the actual sending and receiving of data. It opens a connection to a remote host, sends some data and the reads the response and makes it available to the calling program.
- *
- * The code that makes up this class originates in the Akismet WordPress plugin, which is {@link http://akismet.com/download/ available on the Akismet website}.
- *
- * N.B. It is not necessary to call this class directly to use the Akismet class. This is included here mainly out of a sense of completeness.
- *
- * @package akismet
- * @name SocketWriteRead
- * @version 0.1
- * @author Alex Potsides
- * @link http://www.achingbrain.net/
- */
-class SocketWriteRead {
- var $host;
- var $port;
- var $request;
- var $response;
- var $responseLength;
- var $errorNumber;
- var $errorString;
-
+
+
/**
- * @param string $host The host to send/receive data.
- * @param int $port The port on the remote host.
- * @param string $request The data to send.
- * @param int $responseLength The amount of data to read. Defaults to 1160 bytes.
+ * Submit this comment as an unchecked spam to the Akismet server
+ *
+ * @return void
*/
- function SocketWriteRead($host, $port, $request, $responseLength = 1160) {
- $this->host = $host;
- $this->port = $port;
- $this->request = $request;
- $this->responseLength = $responseLength;
- $this->errorNumber = 0;
- $this->errorString = '';
+ function submitSpam() {
+ $this->http->getResponse($this->_getQueryString(), 'submit-spam');
}
-
+
+
/**
- * Sends the data to the remote host.
+ * Submit a false-positive comment as "ham" to the Akismet server
*
- * @throws An exception is thrown if a connection cannot be made to the remote host.
+ * @return void
*/
- function send() {
- $this->response = '';
-
- $fs = fsockopen($this->host, $this->port, $this->errorNumber, $this->errorString, 3);
-
- if($this->errorNumber != 0) {
- trigger_error('Error connecting to host: ' . $this->host . ' Error number: ' . $this->errorNumber . ' Error message: ' . $this->errorString, E_USER_ERROR);
- }
-
- if($fs !== false) {
- @fwrite($fs, $this->request);
-
- while(!feof($fs)) {
- $this->response .= fgets($fs, $this->responseLength);
- }
-
- fclose($fs);
- }
+ function submitHam() {
+ $this->http->getResponse($this->_getQueryString(), 'submit-ham');
}
-
+
+
/**
- * Returns the server response text
+ * Check with the Akismet server to determine if the API key is valid
*
- * @return string
+ * @access Protected
+ * @param String $key The Wordpress API key passed from the constructor argument
+ * @return boolean
*/
- function getResponse() {
- return $this->response;
+ function _isValidApiKey($key) {
+ $keyCheck = $this->http->getResponse("key=".$this->apiKey."&blog=".$this->blogUrl, 'verify-key');
+
+ return ($keyCheck == "valid");
}
-
+
+
/**
- * Returns the error number
+ * Format the comment array in accordance to the Akismet API
*
- * If there was no error, 0 will be returned.
- *
- * @return int
+ * @access Protected
+ * @return void
*/
- function getErrorNumner() {
- return $this->errorNumber;
+ function _formatCommentArray() {
+ $format = array(
+ 'type' => 'comment_type',
+ 'author' => 'comment_author',
+ 'email' => 'comment_author_email',
+ 'website' => 'comment_author_url',
+ 'body' => 'comment_content'
+ );
+
+ foreach($format as $short => $long) {
+ if(isset($this->comment[$short])) {
+ $this->comment[$long] = $this->comment[$short];
+ unset($this->comment[$short]);
+ }
+ }
}
-
+
+
/**
- * Returns the error string
+ * Build a query string for use with HTTP requests
*
- * If there was no error, an empty string will be returned.
- *
- * @return string
+ * @access Protected
+ * @return String
*/
- function getErrorString() {
- return $this->errorString;
+ function _getQueryString() {
+ foreach($_SERVER as $key => $value) {
+ if(!in_array($key, $this->ignore)) {
+ if($key == 'REMOTE_ADDR') {
+ $this->comment[$key] = $this->comment['user_ip'];
+ } else {
+ $this->comment[$key] = $value;
+ }
+ }
+ }
+
+ $query_string = '';
+
+ foreach($this->comment as $key => $data) {
+ $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
+ }
+
+ return $query_string;
}
+
+
}
?>
\ No newline at end of file
Modified: plugins/branches/lifetype-1.2/akismet/class/security/akismetfilter.class.php
===================================================================
--- plugins/branches/lifetype-1.2/akismet/class/security/akismetfilter.class.php 2007-08-05 21:07:04 UTC (rev 5799)
+++ plugins/branches/lifetype-1.2/akismet/class/security/akismetfilter.class.php 2007-08-06 02:42:53 UTC (rev 5800)
@@ -21,8 +21,6 @@
lt_include( PLOG_CLASS_PATH."class/security/pipelinefilter.class.php" );
- $akismetError = false;
-
// custom error code that will be returned to the pipeline whenever an
// error is found... Be careful so as to not to have two different modules
// use the same code!!
@@ -38,10 +36,6 @@
function filter()
{
- global $akismetError;
-
- $akismetError = false;
-
// get some info
$blogInfo = $this->_pipelineRequest->getBlogInfo();
$request = $this->_pipelineRequest->getHttpRequest();
@@ -65,46 +59,48 @@
// if this is already rejected, there is no reason to do anything here
if ( $this->_pipelineRequest->getRejectedState() )
return new PipelineResult();
-
+
+ $akismetComment = Array();
+
// text and topic of the comment/trackback
$isTrackback = ($request->getValue( "op" ) == "AddTrackback");
if( $isTrackback ) {
- $commentText = $request->getValue( "excerpt" );
- $commentTopic = $request->getValue( "title" );
+ $akismetComment['body'] = $request->getValue( "excerpt" );
+
$articleId = $request->getValue( "id" );
// that's all we can get from a trackback...
- $userName = "";
- $userUrl = $request->getValue( "url" );
- $userEmail = "";
- $commentType = "trackback";
+ $akismetComment['website'] = $request->getValue( "url" );
+ $akismetComment['type'] = "trackback";
}
else {
// or else let's assume that we're dealing with a comment
- $commentText = $request->getValue( "commentText" );
- $commentTopic = $request->getValue( "commentTopic" );
- $userName = $request->getValue( "userName" );
- $userEmail = $request->getValue( "userEmail" );
- $userUrl = $request->getValue( "userUrl" );
+ $akismetComment['body'] = $request->getValue( "commentText" );
+ $akismetComment['author'] = $request->getValue( "userName" );
+ $akismetComment['email'] = $request->getValue( "userEmail" );
+ $akismetComment['website'] = $request->getValue( "userUrl" );
$articleId = $request->getValue( "articleId" );
- $commentType = "comment";
-
+ $akismetComment['type'] = "comment";
}
$rg = $blogInfo->getBlogRequestGenerator();
+ lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php");
+ // articles object
+ $articles = new Articles;
+ $article = $articles->getArticle( $articleId );
+
+ $akismetComment['permalink'] = $rg->postPermalink($article);
+
+
lt_include( PLOG_CLASS_PATH."plugins/akismet/class/security/Akismet.class.php" );
$apiKey = $blogSettings->getValue( "plugin_akismet_api_key" );
- set_error_handler('_akismetFilterErrorHandler');
- $akismet = new Akismet($rg->blogLink(), $apiKey);
+ $akismet = new Akismet($rg->blogLink(), $apiKey, $akismetComment);
- if ( $akismetError == true ) {
-
- restore_error_handler();
-
+ if ( $akismet->errorsExist() == true ) {
// Some error happened. Don't block this message
// Most likely this is becuase the api key is wrong.
$result = new PipelineResult( true );
@@ -112,32 +108,15 @@
return $result;
}
- if ( $userName != "" )
- $akismet->setAuthor($userName);
-
- if ( $userEmail != "" )
- $akismet->setAuthorEmail($userEmail);
- $akismet->setAuthorURL($userUrl);
- $akismet->setContent($commentText);
- $akismet->setType($commentType);
- lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php");
- // articles object
- $articles = new Articles;
- $article = $articles->getArticle( $articleId );
-
- $akismet->setPermalink( $rg->postPermalink($article) );
-
if($akismet->isSpam()) {
- restore_error_handler();
$locale = $blogInfo->getLocale();
$result = new PipelineResult( false, AKISMET_SPAM, $locale->tr("error_comment_spam_throw_away") );
return $result;
}
- restore_error_handler();
// if everything went fine, we can say so by returning
// a positive PipelineResult object
@@ -148,15 +127,4 @@
}
- /**
- * This error handler temporarily overloads the LifeType one
- * occurs.
- */
- function _akismetFilterErrorHandler( $errorCode, $errorString )
- {
- global $akismetError;
-
- $akismetError = true;
- }
-
?>
Modified: plugins/branches/lifetype-1.2/akismet/pluginakismet.class.php
===================================================================
--- plugins/branches/lifetype-1.2/akismet/pluginakismet.class.php 2007-08-05 21:07:04 UTC (rev 5799)
+++ plugins/branches/lifetype-1.2/akismet/pluginakismet.class.php 2007-08-06 02:42:53 UTC (rev 5800)
@@ -32,7 +32,7 @@
$this->desc = "Akismet checks your comments against the Akismet web serivce to see if they look like spam or not.";
$this->author = "Paul Westbrook (Akismet php library provided by <a href=\"http://miphp.net/blog/view/php4_akismet_class\">Bret Kuhns</a>)";
$this->locales = Array( "en_UK" );
- $this->version = "20070731";
+ $this->version = "20070805";
if( $source == "admin" )
$this->initAdmin();
More information about the pLog-svn
mailing list