Browse files

initial release

  • Loading branch information...
0 parents commit d85c9e4d04b649eed0c42b7139f25377863bd337 @arminrosu committed Sep 3, 2011
Showing with 148 additions and 0 deletions.
  1. +23 −0 README.md
  2. +125 −0 stopforumspam.php
23 README.md
@@ -0,0 +1,23 @@
+# StopForumSpam.com - PHP Lib
+
+A PHP wrapper class for the API available at [stopforumspam.com](http://www.stopforumspam.com/usage). An API key is required only for updating the spam database. Uses the JSON interface internally.
+
+## Examples
+
+### Check if user has been recorded as a spammer
+
+ $sfs = new StopForumSpam();
+ $args = array('email' => 'email@example.com', 'ip' => '192.168.1.1', 'username' => 'JohnDoe');
+ $spamcheck = $sfs->is_spammer( $args );
+
+### Get datailed data for suspected spammer
+
+This is the data, as returned by StopForumSpam.com, without parsing.
+
+ $sfs = new StopForumSpam();
+ $args = array('email' => 'email@example.com', 'ip' => '192.168.1.1', 'username' => 'JohnDoe');
+ $user = $sfs->get( $args );
+
+## License
+
+Licensend under the [BSD 3-Clause License](http://www.opensource.org/licenses/BSD-3-Clause).
125 stopforumspam.php
@@ -0,0 +1,125 @@
+<?php
+/**
+ * @StopForumSpam
+ *
+ * Wrapper class for stopforumspam.com API. Uses json internally.
+ *
+ * @author Armin Rosu
+ * @copyright 2011, Armin Rosu
+ * @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
+ * @link http://www.stopforumspam.com/usage API Reference
+ * @version 0.1
+ */
+
+ class StopForumSpam
+ {
+ /**
+ * The API key.
+ *
+ * @var string
+ */
+ private $api_key;
+
+ /**
+ * The base url, for tha API/
+ *
+ * @var string
+ */
+ private $endpoint = 'http://www.stopforumspam.com/';
+
+
+ /**
+ * Constructor.
+ *
+ * @param string $api_key Your API Key, optional (unless adding to database).
+ */
+ public function __construct( $api_key = null ) {
+ // store variables
+ $this->api_key = $api_key;
+ }
+
+ /**
+ * Add to the database
+ *
+ * @param array $args associative array containing email, ip, username and optionally, evidence
+ * e.g. $args = array('email' => 'user@example.com', 'ip_addr' => '8.8.8.8', 'username' => 'Spammer?', 'evidence' => 'My favourite website http://www.example.com' );
+ * @return boolean Was the update succesfull or not.
+ */
+ public function add( $args )
+ {
+ // should check first if not already in database
+
+ // add api key
+ $args['api_key'] = $this->api_key;
+
+ // url to poll
+ $url = $this->endpoint.'add.php?'.http_build_query($args, '', '&');
+
+ // execute
+ $response = file_get_contents($url);
+
+ return (false == $response ? false : true);
+ }
+
+ /**
+ * Get record from spammers database.
+ *
+ * @param array $args associative array containing either one (or all) of these: username / email / ip.
+ * e.g. $args = array('email' => 'user@example.com', 'ip' => '8.8.8.8', 'username' => 'Spammer?' );
+ * @return object Response.
+ */
+ public function get( $args )
+ {
+ // should check first if not already in database
+
+ // url to poll
+ $url = $this->endpoint.'api?f=json&'.http_build_query($args, '', '&');
+
+ //
+ return $this->poll_json( $url );
+ }
+
+ /**
+ * Check if either details correspond to a known spammer. Checking for username is discouraged.
+ *
+ * @param array $args associative array containing either one (or all) of these: username / email / ip
+ * e.g. $args = array('email' => 'user@example.com', 'ip' => '8.8.8.8', 'username' => 'Spammer?' );
+ * @return boolean
+ */
+ public function is_spammer( $args )
+ {
+ // poll database
+ $record = $this->get( $args );
+
+ // give the benefit of the doubt
+ $spammer = false;
+
+ // parse database record
+ foreach( $record as $datapoint )
+ {
+ // not 'success' datapoint AND spammer
+ if ( isset($datapoint->appears) && $datapoint->appears == true)
+ {
+ $spammer = true;
+ }
+ }
+
+ return $spammer;
+ }
+
+ /**
+ * Get json and decode. Currently used for polling the database, but hoping for future
+ * json response support, when adding.
+ *
+ * @param string $url The url to get
+ * @return object Response.
+ */
+ protected static function poll_json( $url )
+ {
+ $json = file_get_contents( $url );
+ $object = json_decode($json);
+
+ return $object;
+ }
+ }
+ ?>

0 comments on commit d85c9e4

Please sign in to comment.