NP_SpamCheck is a framework for SpamChecking.
That means it doesn’t check if something is spam by itself but it uses the files in the subdirectory sc/, that should be relative to the nucleus plugin directory (don’t forget to create this when uploading the plugin!) to check if something is spam.
It checks all comment’s posted using the “comment”, “referer” and the “ip”-type SC, but it can be used as well from other plugins.
By scrolling down you can find:
| NP_SpamCheck | |
|---|---|
| Version: | 1.1.1 |
| Author: | Legolas |
| Development topic: | http://forum.nucleuscms.org/viewtopic.php?t=9022 |
SC: A file containing a spamchecking function to be used by SpamChecker. These files should be uploaded to the sc/ subdirectory relative to the nucleus plugins directory.
SpamChecker Plugin: see SC
Like all plugins you copy and paste the code (which can be found under “Code”) in a file called NP_SpamCheck.php and upload that file to your plugin directory, after that you need to create a directory called “sc” in you plugins directory. In this directory you can put all your SC’s. After you’ve done this you can go on using the normal plugin install method: Going to the Administrator Panel and installing it using the plugin install function on the plugins page.
NP_SpamCheck will run all “comment”-type, “ip”-type and “referer”-type SC’s whenever someone post’s a comment.
The “comment”-type SC’s can do logical checks on the given postername and text, the “referer”-type SC’s can check the refering URL and the “ip”-type will check the IP of the poster. If one of the SC’s returns true the posting will be stopped.
SpamCheck can also be used from other plugins, more on that can be found under using “Calling SpamCheck from your plugin”.
Note: SpamCheck won’t do checks if the user is a logged in member.
<?php // // NP_SpamCheck // By: Legolas // WWW: http://www.legolasweb.nl // Email: legolas@legolasweb.nl // // Released under GNU GPL // // Sub syntax: // In directory sc/ (relative to plugin dir) // Filename: SC.[name].php // // Functions: // string SCType_[name](void) // Must return check type // bool SC_[name](* relative to checktype *) // // Actual Checktypes: // ip // string $ip // comment // string $body, string $poster // referer // string $url // class NP_SpamCheck extends NucleusPlugin { // name of plugin function getName() { return 'SpamCheck'; } // author of plugin function getAuthor() { return 'Legolas (Stas Verberkt)'; } // an URL to the plugin website function getURL() { return 'http://www.legolasweb.nl/'; } // version of the plugin function getVersion() { return '1.1.1'; } // a description to be shown on the installed plugins listing function getDescription() { return "This should be the ultimate anty spam solution, let\'s hope that it works =P."; } function getEventList() { return array('PreAddComment', 'SpamCheck'); } function install() { $this->createOption("hook", "Check comments for spam on posting?", "yesno", "no"); } function supportsFeature ($what) { switch ($what) { case 'SqlTablePrefix': return 1; default: return 0; } } function event_SpamCheck(&$data) { global $DIR_PLUGINS, $member; if ($data["spamcheck"]["result"] == true) { return false; } if ($member->isLoggedIn()) { return false; } $type = "post"; if (isset($data["spamcheck"]["type"])) { $type = $data["spamcheck"]["type"]; } switch ($type) { default: case "comment": if (!isset($data["spamcheck"]["body"]) || !isset($data["spamcheck"]["author"])) { return false; } $comment = $data["spamcheck"]["body"]; $poster = $data["spamcheck"]["author"]; $type = "comment"; break; case "ip": if (!isset($data["spamcheck"]["ip"])) { return false; } $ip = $data["spamcheck"]["ip"]; $type = "ip"; break; case "referer": if (!isset($data["spamcheck"]["url"])) { return false; } $url = $data["spamcheck"]["url"]; $type = "referer"; break; } $filters_dir = $DIR_PLUGINS . "sc/"; $filters = array(); $handle = opendir($filters_dir); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (substr(strtolower($file), 0, 3) == "sc." && substr(strtolower($file), -4) == ".php") { $filters[] = $file; } } } closedir($handle); $spam = false; foreach ($filters as $filter) { include_once($filters_dir . "/" . $filter); $filter_name = substr($filter, 3, -4); $functype = null; if (function_exists("SCType_" . $filter_name)) { $functype = call_user_func("SCType_" . $filter_name); } if (function_exists("SC_" . $filter_name) && $functype == $type) { switch ($functype) { default: case "comment": $spam = call_user_func("SC_" . $filter_name, $comment, $poster); break; case "ip": $spam = call_user_func("SC_" . $filter_name, $ip); break; case "referer": $spam = call_user_func("SC_" . $filter_name, $url); break; } } if ($spam == true) { $data["spamcheck"]["result"] = true; return true; } } return false; } function event_PreAddComment(&$data) { global $DIR_PLUGINS, $member; if ($this->getOption("hook") == "no") { return true; } if ($member->isLoggedIn()) { return true; } $poster = $data['comment']['user']; $comment = $data['comment']['body']; $ip = $data['comment']['ip']; $referer = serverVar("HTTP_REFERER"); $spamcheck = array("type" => "comment", "user" => $poster, "body" => $comment); $param = array("spamcheck" => &$spamcheck); $this->event_SpamCheck($param); if (isset($spamcheck["result"]) && $spamcheck["result"] == true) { header("Location: " . createItemLink($data['comment']['itemid'])); exit(); } $spamcheck = array("type" => "ip", "ip" => $ip); $param = array("spamcheck" => &$spamcheck); $this->event_SpamCheck($param); if (isset($spamcheck["result"]) && $spamcheck["result"] == true) { header("Location: " . createItemLink($data['comment']['itemid'])); exit(); } $spamcheck = array("type" => "referer", "url" => $referer); $param = array("spamcheck" => &$spamcheck); $this->event_SpamCheck($param); if (isset($spamcheck["result"]) && $spamcheck["result"] == true) { header("Location: " . createItemLink($data['comment']['itemid'])); exit(); } return true; } } ?>
Here are some tutorials for people that want to create an SC or want to use SpamCheck from their plugins.
For more information it’s a good idea to look at the SpamCheck API.
SC’s are the SpamCheck’s check functions. These files should be located in the directory sc/, which should be relative to plugin directory.
SC’s should be named like this: SC.[name].php
Every SC should have these functions:
string SCType_[name](void)
Return: the type of the SC
bool SC_[name](* relative to checktype *)
Return: true on spam and otherwise false
The parameters to use (and the order) can be found in the list beneath this one.
The now available SC-Types are:
comment
Parameters: string $comment, string $poster
Use: Checks if a post is spam.
ip
Parameters: string $ip
Use: Checks if a IP is known as a spammer
referer
Parameters: string $url
Use: Checks if a refering URL is suspicious
You can call SpamCheck from your plugin by using a function like this:
<?php global $manager; if ($manager->pluginInstalled('NP_SpamCheck')) { $spamcheck = array ('type' => 'comment', 'author' => 'poster', 'body' => 'post', 'return' => false); $manager->notify('SpamCheck', array("spamcheck" => &$spamcheck))); if (isset($spamcheck['result']) && $spamcheck['result'] == true) { // It's spam =( } } ?>
Please note that if you don’t want to do a “post”-type check you should change the $spamcheck array to the type of check your using. The check-types are listed under “Creating SC’s” together with the parameters they use, beside the parameters listed there you need to include the type (and return) parameter(s) also when you call the SpamCheck event.
Here are the Spam control functions
This is really simple, you just upload the sc file to the sc/ subdirectory of your nucleus plugins directory.
Note: If you add a SC please create a page called sc:[name] and place a link in this table.
| “comment”-type SC’s | |
|---|---|
| SC.SpamRater.php | Legolas’ SpamRater |
| “referer”-type SC’s | |
| SC.PostReferer.php | PostReferer |
| “ip”-type SC’s | |