Add akismet::$test_mode, initialize it to TEST_MODE and don't contact

akismet if it's on.  Force it on in the scaffolding so that we don't
try to run all comments we add from there through Akismet.
This commit is contained in:
Bharat Mediratta
2009-01-08 02:56:49 +00:00
parent 8bf388a6f6
commit bc36ba609d
3 changed files with 16 additions and 8 deletions
+2
View File
@@ -298,6 +298,7 @@ class Welcome_Controller extends Template_Controller {
url::redirect("welcome");
}
akismet::$test_mode = 1;
for ($i = 0; $i < $count; $i++) {
$photo = $photos[array_rand($photos)];
comment::create(
@@ -305,6 +306,7 @@ class Welcome_Controller extends Template_Controller {
"johndoe@example.com",
$this->random_phrase(rand(8, 500)), $photo->id);
}
akismet::$test_mode = 0;
url::redirect("welcome");
}
+14
View File
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class akismet_Core {
public static $test_mode = TEST_MODE;
// Lets not send everything to Akismet
private static $white_list = array(
"HTTP_USER_AGENT",
@@ -41,6 +43,10 @@ class akismet_Core {
* @return $string "spam", "ham" or "unknown"
*/
public static function check_comment($comment) {
if (akismet::$test_mode) {
return;
}
$request = self::_build_request("comment-check", $comment);
$response = self::_http_post($request);
$answer = $response->body[0];
@@ -58,6 +64,10 @@ class akismet_Core {
* @param Comment_Model $comment A comment to check
*/
public static function submit_spam($comment) {
if (akismet::$test_mode) {
return;
}
$request = self::_build_request("submit-spam", $comment);
self::_http_post($request);
}
@@ -67,6 +77,10 @@ class akismet_Core {
* @param Comment_Model $comment A comment to check
*/
public static function submit_ham($comment) {
if (akismet::$test_mode) {
return;
}
$request = self::_build_request("submit-ham", $comment);
self::_http_post($request);
}
@@ -19,10 +19,6 @@
*/
class akismet_event_Core {
public static function comment_created($comment) {
if (TEST_MODE) {
return;
}
switch(akismet::check_comment($comment)) {
case "spam":
$comment->state = "spam";
@@ -41,10 +37,6 @@ class akismet_event_Core {
}
public static function comment_changed($old, $new) {
if (TEST_MODE) {
return;
}
if ($old->state != "spam" && $new->state == "spam") {
akismet::submit_spam($new);
} else if ($old->state == "spam" && $new->state != "spam") {