diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-01-07 19:50:27 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-01-07 19:50:27 +0000 |
commit | f8802d438a7d3db3809f9b29e7cc41986ae2617d (patch) | |
tree | e905d59661419ef1b16a70b40ea8a67da76809b4 /modules/akismet | |
parent | 01dcbbcda5a4630cec6a1bbee052ef108e291a5d (diff) |
Properly handle the case where the akismet backend doesn't return a true/false
value. Add phpdoc.
Diffstat (limited to 'modules/akismet')
-rw-r--r-- | modules/akismet/helpers/akismet.php | 33 | ||||
-rw-r--r-- | modules/akismet/helpers/akismet_event.php | 14 |
2 files changed, 40 insertions, 7 deletions
diff --git a/modules/akismet/helpers/akismet.php b/modules/akismet/helpers/akismet.php index 7dbbe98e..132b9206 100644 --- a/modules/akismet/helpers/akismet.php +++ b/modules/akismet/helpers/akismet.php @@ -35,24 +35,47 @@ class akismet_Core { return $form; } + /** + * Check a comment against Akismet and return "spam", "ham" or "unknown". + * @param Comment_Model $comment A comment to check + * @return $string "spam", "ham" or "unknown" + */ public static function check_comment($comment) { $request = self::_build_request("comment-check", $comment); $response = self::_http_post($request); - return "true" == $response->body[0]; + $answer = $response->body[0]; + if ($answer == "true") { + return "spam"; + } else if ($answer == "false") { + return "ham"; + } else { + return "unknown"; + } } + /** + * Tell Akismet that this comment is spam + * @param Comment_Model $comment A comment to check + */ public static function submit_spam($comment) { $request = self::_build_request("submit-spam", $comment); - $response = self::_http_post($request); - return "true" == $response->body[0]; + self::_http_post($request); } + /** + * Tell Akismet that this comment is ham + * @param Comment_Model $comment A comment to check + */ public static function submit_ham($comment) { $request = self::_build_request("submit-ham", $comment); - $response = self::_http_post($request); - return "true" == $response->body[0]; + self::_http_post($request); } + /** + * Check an API Key against Akismet to make sure that it's valid + * @param string $api_key the API key + * @return boolean + */ public static function validate_key($api_key) { $request = self::_build_verify_request($api_key); $response = self::_http_post($request, "rest.akismet.com"); diff --git a/modules/akismet/helpers/akismet_event.php b/modules/akismet/helpers/akismet_event.php index bc4e895a..8f530faa 100644 --- a/modules/akismet/helpers/akismet_event.php +++ b/modules/akismet/helpers/akismet_event.php @@ -19,9 +19,19 @@ */ class akismet_event_Core { public static function comment_created($comment) { - if (akismet::check_comment($comment)) { + switch(akismet::check_comment($comment)) { + case "spam": $comment->state = "spam"; - $comment->save(); + break; + + case "ham": + $comment->state = "published"; + break; + + case "unknown": + $comment->state = "unpublished"; + break; } + $comment->save(); } } |