* Author URI: http://www.actsupport.com * Text Domain: act-stop-spam * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * */ // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) exit; if ( !class_exists( 'Act_Stop_Spam' ) ) : final class Act_Stop_Spam { /** * * @var string */ private $Act_api_url="http://www.stopforumspam.com/api"; public $version = '1.1'; /** * @var string * Note that it should match the Text Domain file header in this file */ public $Act_Plugin = 'act-stop-spam'; /** * @var Act Stop Spam The single instance of the class * @since 1.0 */ protected static $_instance = null; /** * Cloning is forbidden. * * @since 1.0 */ public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'act-stop-spam' ), $this->version ); } /** * Unserializing instances of this class is forbidden. * * @since 1.0 */ public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'act-stop-spam' ), $this->version ); } /** * Constructor. * * @param string $api_url. */ public function __construct( $api_url = null ) { define('ACT_PLUGIN_STOPSPAM',$this->Act_Plugin); if(!empty($api_url)) $this->Act_api_url = $api_url; $this->includes(); $this->Act_setup(); /* * Register hooks that are fired when the plugin is activated * When the plugin is deleted, the uninstall.php file is loaded. */ register_activation_hook( __FILE__, array( 'ACT_STOP_SPAM_Install', 'activate' ) ); register_deactivation_hook( __FILE__, array( 'ACT_STOP_SPAM_Install', 'deactivate' ) ); } /** * Main Act Stop Spam Instance * @since 1.0 */ public static function instance() { if ( is_null( self::$_instance ) ) { self::$_instance = new self(); } return self::$_instance; } /** * Stop Forum Spam Donation Link to support StopForumSpam.com. * @access private * @version 1.0 * @since 1.0 */ public function act_stop_spam_links($links="", $file="") { if($file=="") $file=$this->Act_Plugin; if ($file == plugin_basename(__FILE__)) { $links[] = 'StopForumSpam.com Donate'; } return $links; } /** * Act menu Setup for the Act Stop Spam * @access private * @version 1.0 * @since 1.0 */ private function Act_setup(){ add_filter('plugin_row_meta', array( $this, 'act_stop_spam_links' ),10,2); add_action('admin_menu', array( &$this, 'admin_menu' ) ); add_filter('act_stop_spam_settings', array( $this, 'get_settings') ); } /** * Includes installation class for the Act Stop Spam * @access private * @version 1.0 * @since 1.0 */ private function includes() { include_once( 'includes/class-act-install.php' ); } /** * Renders and handles the options page for the Act Stop Spam * @access public * @version 1.0 * @since 1.0 */ public function admin_options() { if (! current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } $actstop_settings=$this->get_settings(); $actstopspam_confidence =$actstop_settings['ACT_STOP_SPAM_CONFIDANCE']; $actstopspam_BlockMessage =$actstop_settings['ACT_STOP_SPAM_MESSAGE']; if ( isset( $_POST['ActStopSpamUpdate'] ) ) { $actstopspam_confidence = $_POST['actstopspam_confidence']; $actstopspam_BlockMessage = $_POST['actstopspam_BlockMessage']; $settings=array(); $settings['ACT_STOP_SPAM_CONFIDANCE']=$actstopspam_confidence ; $settings['ACT_STOP_SPAM_MESSAGE']=$actstopspam_BlockMessage; $status =$this->update_settings( $settings ); }else{ $status =true; } if ( file_exists( plugin_dir_path( __FILE__ ).'act-stop-spam-options.php' ) ) { include_once( 'act-stop-spam-options.php' ); } } /** * @access private * @param IpAddress * @return string * @since 1.0 */ private function Client_Address(){ $ipaddress=$_SERVER["HTTP_CLIENT_IP"]?$_SERVER["HTTP_CLIENT_IP"]:($_SERVER["HTTP_X_FORWARDED_FOR"]?$_SERVER["HTTP_X_FORWARDED_FOR"]:$_SERVER["REMOTE_ADDR"]); return $ipaddress; } /** * @access public * @param none * @return none * @since 1.0 */ public function act_stop_spam(){ global $wpdb; $GuestIp = $this->Client_Address(); $JsonLink = $this->Act_api_url."?&ip=".urlencode($GuestIp)."&f=json"; if(function_exists('file_get_contents')){ //Version 1.1 try{ $JsonData = json_decode(file_get_contents($JsonLink)); } catch(Exception $e){ $error=$e; } }elseif(function_exists('curl_init')){ try{ $JsonData=json_decode(url_get_contents($JsonLink)); } catch(Exception $e){ $error=$e; } } if(isset($JsonData)&&$JsonData->success==1){ $Appears=$JsonData->ip->appears; $actstop_option=get_option(ACT_STOP_SPAM_KEY); if($Appears==1&&$JsonData->ip->confidence>=$actstop_option['ACT_STOP_SPAM_CONFIDANCE']){ $act_stop_spam_message=$actstop_option['ACT_STOP_SPAM_MESSAGE']; if(empty($act_stop_spam_message)) $act_stop_spam_message="Your public IP address is blacklisted in stopforumspam.com"; echo '