From 10ff87621b064b46c13882c376def8a51b31befe Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 7 Jan 2009 19:51:53 +0000 Subject: The SpamFilter module is superceded by the Akismet module. --- .../spam_filter/controllers/admin_spam_filter.php | 106 --------------- modules/spam_filter/helpers/spam_filter.php | 33 ----- .../spam_filter/helpers/spam_filter_installer.php | 33 ----- modules/spam_filter/helpers/spam_filter_menu.php | 28 ---- modules/spam_filter/libraries/SpamFilter.php | 100 -------------- modules/spam_filter/libraries/drivers/Akismet.php | 151 --------------------- modules/spam_filter/libraries/drivers/Mollom.php | 83 ----------- .../spam_filter/libraries/drivers/SpamFilter.php | 52 ------- modules/spam_filter/module.info | 3 - modules/spam_filter/tests/Akismet_Driver_Test.php | 112 --------------- .../spam_filter/tests/SpamFilter_Helper_Test.php | 32 ----- .../spam_filter/views/admin_spam_filter.html.php | 48 ------- .../views/admin_spam_filter_akismet.html.php | 12 -- .../views/admin_spam_filter_mollom.html.php | 19 --- 14 files changed, 812 deletions(-) delete mode 100644 modules/spam_filter/controllers/admin_spam_filter.php delete mode 100644 modules/spam_filter/helpers/spam_filter.php delete mode 100644 modules/spam_filter/helpers/spam_filter_installer.php delete mode 100644 modules/spam_filter/helpers/spam_filter_menu.php delete mode 100644 modules/spam_filter/libraries/SpamFilter.php delete mode 100644 modules/spam_filter/libraries/drivers/Akismet.php delete mode 100644 modules/spam_filter/libraries/drivers/Mollom.php delete mode 100644 modules/spam_filter/libraries/drivers/SpamFilter.php delete mode 100644 modules/spam_filter/module.info delete mode 100644 modules/spam_filter/tests/Akismet_Driver_Test.php delete mode 100644 modules/spam_filter/tests/SpamFilter_Helper_Test.php delete mode 100644 modules/spam_filter/views/admin_spam_filter.html.php delete mode 100644 modules/spam_filter/views/admin_spam_filter_akismet.html.php delete mode 100644 modules/spam_filter/views/admin_spam_filter_mollom.html.php diff --git a/modules/spam_filter/controllers/admin_spam_filter.php b/modules/spam_filter/controllers/admin_spam_filter.php deleted file mode 100644 index 30492a12..00000000 --- a/modules/spam_filter/controllers/admin_spam_filter.php +++ /dev/null @@ -1,106 +0,0 @@ -content = $this->get_edit_form(); - - print $view; - } - - public function get_edit_form($driver_name=null, $post=null) { - $form = new View("admin_spam_filter.html"); - - $drivers = spam_filter::get_driver_names(); - $current_driver = empty($driver_name) ? module::get_var("spam_filter", "driver") : $driver_name; - $current_driver = !empty($current_driver) ? $current_driver : $drivers[0]; - - $selected = 0; - $driver_options = array(); - foreach ($drivers as $idx => $driver) { - if ($driver == $current_driver) { - $selected = $idx; - } - $driver_options[] = array("name" => $driver, "selected" => $driver == $current_driver); - } - $form->drivers = $driver_options; - - $form->filter_data = empty($selected) ? "" : - SpamFilter::instance($current_driver)->get_admin_fields($post); - - return $form; - } - - public function edit() { - $selected = Input::instance()->post("drivers"); - $drivers = spam_filter::get_driver_names(); - $driver_name = $drivers[$selected]; - - if (!empty($selected)) { - $post = new Validation($_POST); - SpamFilter::instance($driver_name)->get_validation_rules($post); - if ($post->validate()) { - module::set_var("spam_filter", "driver", $drivers[$selected]); - SpamFilter::instance($driver_name)->set_api_data($post); - - log::success("spam_filter", _("Spam Filter configured")); - message::success(_("Spam Filter configured")); - print json_encode( - array("result" => "success", - "location" => url::site("admin/spam_filter"))); - } else { - $form = $this->get_edit_form($driver_name, $post); - print json_encode( - array("result" => "error", - "form" => $form->__toString())); - - } - } else { - $form = $this->get_edit_form(); - print json_encode( - array("result" => "continue", - "form" => $form->__toString())); - } - } - - public function callback() { - $driver_name = Input::instance()->post("driver"); - - $selected = $this->_get_selected_index($driver_name); - if (!empty($selected)) { - print SpamFilter::instance($driver_name)->get_admin_fields(); - } else { - print ""; - } - } - - public function _get_selected_index($driver_name) { - $drivers = spam_filter::get_driver_names(); - - $selected = 0; - foreach ($drivers as $idx => $driver) { - if ($driver == $driver_name) { - $selected = $idx; - } - } - - return $selected; - } -} \ No newline at end of file diff --git a/modules/spam_filter/helpers/spam_filter.php b/modules/spam_filter/helpers/spam_filter.php deleted file mode 100644 index 2531392b..00000000 --- a/modules/spam_filter/helpers/spam_filter.php +++ /dev/null @@ -1,33 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("spam_filter") - ->label(_("Spam Filtering")) - ->url(url::site("admin/spam_filter"))); - } -} diff --git a/modules/spam_filter/libraries/SpamFilter.php b/modules/spam_filter/libraries/SpamFilter.php deleted file mode 100644 index 3485bf75..00000000 --- a/modules/spam_filter/libraries/SpamFilter.php +++ /dev/null @@ -1,100 +0,0 @@ -driver = new $driver(); - - // Validate the driver - if (!($this->driver instanceof SpamFilter_Driver)) { - throw new Exception("@todo SPAM FILTER DRIVER NOT IMPLEMENTED"); - } - } - - public function check_comment($comment) { - $this->_is_initialized(); - - $is_valid = $this->driver->check_comment($comment); - $comment->state = $is_valid ? "published" : "spam"; - return $is_valid; - } - - public function submit_spam($comment) { - $this->_is_initialized(); - - return $this->driver->submit_spam($comment); - } - - public function submit_ham($comment) { - $this->_is_initialized(); - - return $this->driver->submit_ham($comment); - } - - public function get_statistics() { - $this->_is_initialized(); - return $this->driver->get_statistics(); - } - - public function get_admin_fields($post=null) { - return $this->driver->get_admin_fields($post); - } - - public function get_validation_rules($post) { - $this->driver->get_validation_rules($post); - } - - public function set_api_data($post) { - $this->driver->set_api_data($post); - module::set_var("spam_filter", "key_verified", true); - } - - private function _is_initialized() { - $key_verified = module::get_var("spam_filter", "key_verified", null); - if (empty($key_verified)) { - throw new Exception("@todo SPAM FILTER NOT INITIALIZED"); - } - } -} - diff --git a/modules/spam_filter/libraries/drivers/Akismet.php b/modules/spam_filter/libraries/drivers/Akismet.php deleted file mode 100644 index 67b4a88d..00000000 --- a/modules/spam_filter/libraries/drivers/Akismet.php +++ /dev/null @@ -1,151 +0,0 @@ -_build_request("comment-check", $comment); - $response = $this->_http_post($this->_get_host_url(), $request); - - Kohana::log("debug", print_r($response, 1)); - if ($response["body"][0] != "true" && $response["body"][0] != "false") { - Kohana::log("alert", $response["body"][0]); - } - return $response["body"][0] == "true"; - } - - public function submit_spam($comment) { - $request = $this->_build_request("submit-spam", $comment); - $response = $this->_http_post($this->_get_host_url(), $request); - if ($response["body"][0] != "true" && $response["body"][0] != "false") { - Kohana::log("alert", $response["body"][0]); - } - return $response["body"][0] == "true"; - } - - public function submit_ham($comment) { - $request = $this->_build_request("submit-ham", $comment); - $response = $this->_http_post($this->_get_host_url(), $request); - if ($response["body"][0] != "true" && $response["body"][0] != "false") { - Kohana::log("alert", $response["body"][0]); - } - return $response["body"][0] == "true"; - } - - public function get_statistics() { - throw new Exception("@todo GET_STATISTICS NOT SUPPORTED"); - } - - public function get_admin_fields($post) { - $view = new View("admin_spam_filter_akismet.html"); - $view->api_key = empty($post) ? module::get_var("spam_filter", "api_key") : - $post->api_key; - - $view->errors = $post ? $post->errors() : null; - return $view; - } - - public function get_validation_rules($post) { - $post->add_rules("api_key", "required"); - $post->add_callbacks("api_key", array($this, "validate_key")); - } - - public function validate_key(Validation $post, $field) { - $request = $this->_build_verify_request($post->api_key); - $response = $this->_http_post("rest.akismet.com", $request); - Kohana::log("debug", print_r($response, 1)); - if ("valid" != $response["body"][0]) { - $post->add_error("api_key", "invalid"); - Kohana::log("alert", "Failed to verify Akismet Key:\n" . print_r($response["headers"], 1)); - } - } - - public function _build_verify_request($api_key) { - $base_url = url::base(true, true); - $query_string = "key={$api_key}&blog=$base_url"; - - $http_request = "POST /1.1/verify-key HTTP/1.0\r\n"; - $http_request .= "Host: rest.akismet.com\r\n"; - $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n"; - $http_request .= "Content-Length: " . strlen($query_string) . "\r\n"; - $http_request .= "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n"; - $http_request .= "\r\n"; - $http_request .= $query_string; - - return $http_request; - } - - public function set_api_data($post) { - module::set_var("spam_filter", "api_key", $post->api_key); - } - - public function _build_request($function, $comment) { - $comment_data = array(); - $comment_data["user_ip"] = $comment->ip_addr; - $comment_data["permalink"] = url::site("comments/{$comment->id}"); - $comment_data["blog"] = url::base(true, true); - $comment_data["user_agent"] = $comment->user_agent; - $comment_data["referrer"] = $_SERVER["HTTP_REFERER"]; - $comment_data["comment_type"] = "comment"; - $comment_data["comment_author"] = $comment->author; - $comment_data["comment_author_email"] = $comment->email; - $comment_data["comment_author_url"] = str_replace(array("http://", "https://"), "", $comment->url); - $comment_data["comment_content"] = $comment->text; - - foreach($_SERVER as $key => $value) { - if(in_array($key, self::$white_list)) { - $comment_data[$key] = $value; - } - } - - $query_string = array(); - foreach($comment_data as $key => $data) { - if(!is_array($data)) { -// $query_string .= $key . "=" . urlencode(stripslashes($data)) . "&"; - $query_string[] = "$key=" . urlencode($data); - } - } - $query_string = join("&", $query_string); - - $host = $this->_get_host_url(); - $http_request = "POST /1.1/$function HTTP/1.0\r\n"; - $http_request .= "Host: $host\r\n"; - $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n"; - $http_request .= "Content-Length: " . strlen($query_string) . "\r\n"; - $http_request .= "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n"; - $http_request .= "\r\n"; - $http_request .= $query_string; - - Kohana::log("debug", $http_request); - - return $http_request; - } - - private function _get_host_url() { - $api_key = module::get_var("spam_filter", "api_key"); - return "$api_key.rest.akismet.com"; - } -} diff --git a/modules/spam_filter/libraries/drivers/Mollom.php b/modules/spam_filter/libraries/drivers/Mollom.php deleted file mode 100644 index 6887a1be..00000000 --- a/modules/spam_filter/libraries/drivers/Mollom.php +++ /dev/null @@ -1,83 +0,0 @@ -private_key = empty($post) ? module::get_var("spam_filter", "private_key") : - $post->private_key; - $view->public_key = empty($post) ? module::get_var("spam_filter", "public_key") : - $post->private_key; - - $view->errors = $post ? $post->errors() : null; - return $view; - } - - public function get_validation_rules($post) { - $post->add_rules("private_key", "required"); - $post->add_rules("public_key", "required"); - $post->add_callbacks("private_key", array($this, "validate_key")); - } - - public function validate_key(Validation $array, $field) { - // @todo verify key values - Kohana::log("debug", "Mollom::validate_key"); - Kohana::log("debug", print_r($array, 1)); - Kohana::log("debug", "field: $field"); - } - - public function set_api_data($post) { - module::set_var("spam_filter", "private_key", $post->private_key); - module::set_var("spam_filter", "public_key", $post->public_key); - } - - private function _build_request($function, $host, $comment_data) { - return ""; - } - - public function _retrieve_serverList() { - $server_list = module::get_var("spam_filter", "server_list"); - if (empty($server_list)) { - $servers = array("http://xmlrpc1.mollom.com", "http://xmlrpc2.mollom.com", "http://xmlrpc1.mollom.com"); - foreach (array("http://xmlrpc1.mollom.com", "http://xmlrpc2.mollom.com", "http://xmlrpc1.mollom.com") as $server) { - $result = xmlrpc($server . "/1.0"); - if (!xmplrpc_errno()) { - module::set_var("spam_filter", "server_list", $result); - $server_list = $result; - } - } - } - return $server_list; - } -} diff --git a/modules/spam_filter/libraries/drivers/SpamFilter.php b/modules/spam_filter/libraries/drivers/SpamFilter.php deleted file mode 100644 index 6ece0dd4..00000000 --- a/modules/spam_filter/libraries/drivers/SpamFilter.php +++ /dev/null @@ -1,52 +0,0 @@ - $headers, "body" => $body); - } else { - throw new Exception("@todo CONNECTION TO SPAM SERVICE FAILED"); - } - return $response; - } -} \ No newline at end of file diff --git a/modules/spam_filter/module.info b/modules/spam_filter/module.info deleted file mode 100644 index c31f794c..00000000 --- a/modules/spam_filter/module.info +++ /dev/null @@ -1,3 +0,0 @@ -name = Spam Filter -description = Protect your gallery from unwanted and annoying comments -version = 1 diff --git a/modules/spam_filter/tests/Akismet_Driver_Test.php b/modules/spam_filter/tests/Akismet_Driver_Test.php deleted file mode 100644 index d5f5ee95..00000000 --- a/modules/spam_filter/tests/Akismet_Driver_Test.php +++ /dev/null @@ -1,112 +0,0 @@ -_ip_address = Input::instance()->ip_address; - $this->_user_agent = Kohana::$user_agent; - - Input::instance()->ip_address = "1.1.1.1"; - Kohana::$user_agent = "Gallery3 Unit Test"; - - $this->_driver = new Akismet_Driver(); - $this->_comment = comment::create("John Doe", "John@gallery.com", "This is a comment", 0, "http://gallery.com"); - $this->_api_key = module::get_var("spam_filter", "api_key"); - if (empty($this->_api_key)) { - $chars = "0123456789abcdefghijklmnopqrstuvwxyz"; - for ($i = 0; $i < 10; $i++) { - $this->_api_key .= $chars[mt_rand(0, 36)]; - } - module::set_var("spam_filter", "api_key", $this->_api_key); - } - } - - public function teardown() { - Input::instance()->ip_address = $this->_ip_address; - Kohana::$user_agent = $this->_user_agent; - } - - public function build_verify_key_request_test() { - $request = $this->_driver->_build_verify_request($this->_api_key); - $data = "key={$this->_api_key}&blog=http://./"; - $data_length = strlen($data); - $expected = "POST /1.1/verify-key HTTP/1.0\r\n" . - "Host: rest.akismet.com\r\n" . - "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" . - "Content-Length: {$data_length}\r\n" . - "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n" . - "\r\n$data"; - $this->assert_equal($expected, $request); - } - - public function build_check_comment_request_test() { - $request = $this->_driver->_build_request("comment-check", $this->_comment); - $data = "user_ip=1.1.1.1&permalink=http%3A%2F%2F.%2Findex.php%2Fcomments%2F2&blog=http%3A%2F%2F.%2F" . - "&user_agent=Gallery3+Unit+Test&referrer=&comment_type=comment&comment_author=John+Doe" . - "&comment_author_email=John%40gallery.com&comment_author_url=http%3A%2F%2Fgallery.com" . - "&comment_content=This+is+a+comment&"; - $data_length = strlen($data); - $expected = "POST /1.1/comment-check HTTP/1.0\r\n" . - "Host: {$this->_api_key}.rest.akismet.com\r\n" . - "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" . - "Content-Length: {$data_length}\r\n" . - "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n" . - "\r\n$data"; - $this->assert_equal($expected, $request); - } - - public function build_submit_spam_request_test() { - $request = $this->_driver->_build_request("submit-spam", $this->_comment); - $data = "user_ip=1.1.1.1&permalink=http%3A%2F%2F.%2Findex.php%2Fcomments%2F3&blog=http%3A%2F%2F.%2F" . - "&user_agent=Gallery3+Unit+Test&referrer=&comment_type=comment&comment_author=John+Doe" . - "&comment_author_email=John%40gallery.com&comment_author_url=http%3A%2F%2Fgallery.com" . - "&comment_content=This+is+a+comment&"; - $data_length = strlen($data); - $expected = "POST /1.1/submit-spam HTTP/1.0\r\n" . - "Host: {$this->_api_key}.rest.akismet.com\r\n" . - "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" . - "Content-Length: {$data_length}\r\n" . - "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n" . - "\r\n$data"; - $this->assert_equal($expected, $request); - } - - public function build_submit_ham_equest_test() { - $request = $this->_driver->_build_request("submit-ham", $this->_comment); - $data = "user_ip=1.1.1.1&permalink=http%3A%2F%2F.%2Findex.php%2Fcomments%2F4&blog=http%3A%2F%2F.%2F" . - "&user_agent=Gallery3+Unit+Test&referrer=&comment_type=comment&comment_author=John+Doe" . - "&comment_author_email=John%40gallery.com&comment_author_url=http%3A%2F%2Fgallery.com" . - "&comment_content=This+is+a+comment&"; - $data_length = strlen($data); - $expected = "POST /1.1/submit-ham HTTP/1.0\r\n" . - "Host: {$this->_api_key}.rest.akismet.com\r\n" . - "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" . - "Content-Length: {$data_length}\r\n" . - "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n" . - "\r\n$data"; - $this->assert_equal($expected, $request); - } -} - diff --git a/modules/spam_filter/tests/SpamFilter_Helper_Test.php b/modules/spam_filter/tests/SpamFilter_Helper_Test.php deleted file mode 100644 index 7f6bf5c0..00000000 --- a/modules/spam_filter/tests/SpamFilter_Helper_Test.php +++ /dev/null @@ -1,32 +0,0 @@ -assert_equal($expected, spam_filter::get_driver_names()); - } -} \ No newline at end of file diff --git a/modules/spam_filter/views/admin_spam_filter.html.php b/modules/spam_filter/views/admin_spam_filter.html.php deleted file mode 100644 index 80ea02b8..00000000 --- a/modules/spam_filter/views/admin_spam_filter.html.php +++ /dev/null @@ -1,48 +0,0 @@ - - -
" method="post" class="form"> - -
- -
    -
  • - - -
  • -
    - -
    -
  • - -
  • -
-
-
diff --git a/modules/spam_filter/views/admin_spam_filter_akismet.html.php b/modules/spam_filter/views/admin_spam_filter_akismet.html.php deleted file mode 100644 index 9d826b56..00000000 --- a/modules/spam_filter/views/admin_spam_filter_akismet.html.php +++ /dev/null @@ -1,12 +0,0 @@ - -
  • class="gError" > - - - -

    - - -

    - -

  • - diff --git a/modules/spam_filter/views/admin_spam_filter_mollom.html.php b/modules/spam_filter/views/admin_spam_filter_mollom.html.php deleted file mode 100644 index 63f603fb..00000000 --- a/modules/spam_filter/views/admin_spam_filter_mollom.html.php +++ /dev/null @@ -1,19 +0,0 @@ - -
  • class="gError" > - - - -

    - - -

    - -

  • -
  • class="gError" > - - - -

    - -

  • - -- cgit v1.2.3