Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Validator for bbPress
- Plugin URI: http://reviewtrip.com/blog/stop-forum-spam-api-plugin-for-bbpress
- Description: API for http://www.stopforumspam.com/ on bbPress
- Version: 0.1.0
- Author: pnd (http://nanp-info.com)
- Author URI: http://reviewtrip.com/
- */
- add_action( 'bb_init', 'validator_registration',11); // registration
- function validator_registration() {
- if (!empty($_POST) && isset($_POST["Submit"])) { // check this first to save cpu cycles on the next check
- $location=false; $resource=array($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_FILENAME'], $_SERVER['SCRIPT_NAME']);
- foreach ($resource as $name ) {if (false!==strpos($name, '.php')) {$location=bb_find_filename($name);}}
- if ($location!="register.php") {return;} // only display on register.php and hide on profile page
- if(!validate('ip',$_SERVER['REMOTE_ADDR']) || !validate('username',$_POST["user_login"]) || !validate('email',$_POST["user_email"])) {
- bb_send_headers();
- bb_get_header();
- echo "<p align='center'><font size='+1'>".
- __("Humans only please").". ".__("If you are not a bot").", <br />
- ".__("please go back and try again").".
- </font></p><br />";
- bb_get_footer();
- exit;
- }
- }
- }
- function validate($type,$data) {
- $data=urlencode(substr(strip_tags(stripslashes($data)),0,50));
- $url = "http://www.stopforumspam.com/api?".$type."=".$data;
- // $content=file_get_contents($url); // if you don't have curl, try this instead
- $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER , TRUE); $content = curl_exec($ch); curl_close($ch);
- preg_match("/<appears>(.*?)<\/appears>/si", $content, $tmp);
- return ($tmp[1] == "yes") ? true : false;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement