Please'. ' update!'; if (version_compare($wp_version, "3.0", "<")) { exit($exit_msg); } define("CONFIDENT_API_SERVER", "http://captcha.confidenttechnologies.com/"); define("LIBRARY_VERSION", "20100610_WORDPRESS"); /** * Display a warning if the PHP installation is to old. * To be removed later on when PHP4 is completely dead. */ function PHP4_Check($globaloptions=true) { if (version_compare(PHP_VERSION, '5.0.0', '<')){ $errormessage=__('WARNING: You appear to be using PHP4, PHP5 or newer is'. ' required for this plugin to work.'); if ($globaloptions) { echo ""; echo " "; echo "".$errormessage.""; echo ""; } else { echo ""; echo " "; echo "".$errormessage.""; echo ""; } } } // Checks for presence of the cURL extension. function CURL_Check() { $errormessage=__('WARNING: The PHP extention cURL is required for this'. ' plugin'); if (!in_array ('curl', get_loaded_extensions())) { echo ""; echo " "; echo "".$errormessage.""; echo ""; } } //sane version of ip address function function getIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // to check ip is pass from proxy $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } ///////////////////////////////////////////////////////// /* Confident PHP Libraries */ //////////////////////////////////////////////////////// function call($url, $method = "POST", $params = null) { $ch = curl_init(); if (strtolower($method) == 'post') { curl_setopt($ch, CURLOPT_POST, true); if ($params) { curl_setopt($ch, CURLOPT_POSTFIELDS, $params); } } elseif (strtolower($method) == 'get') { if ($params) { $url .= '?' . http_build_query($params); } } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $body = curl_exec($ch); $response = array( 'status' => curl_getinfo($ch, CURLINFO_HTTP_CODE), 'body' => $body, ); if ($body === false) { $response['error'] = curl_error($ch); //trigger_error($response['error'], E_USER_WARNING); } curl_close($ch); return $response; } function create_captcha($options) { $params = $options; $params['headers'] = Array('Content-Type' => 'application/x-www-form-urlencoded'); $response = call(CONFIDENT_API_SERVER."/captcha", 'POST', $params); if ($response['status'] == 200) { return $response['body']; } else { return "create_captcha failed with error code ". $response['status'] ."."; } } function check_captcha($code, $captcha_id, $options) { $params = Array( 'api_username' => $options['api_username'], 'api_password' => $options['api_password'], 'customer_id' => $options['customer_id'], 'site_id' => $options['site_id'], 'code' => $code, ); $response = call(CONFIDENT_API_SERVER."/captcha/$captcha_id", 'POST', $params); return $response; // if ($response['status']==200 && $response['body']=="True") { // return true; // } // return false; // } function check_credentials($options) { $params = Array( 'api_username' => $options['api_username'], 'api_password' => $options['api_password'], 'customer_id' => $options['customer_id'], 'site_id' => $options['site_id'], 'library_version' => LIBRARY_VERSION ); $response = call(CONFIDENT_API_SERVER."/check_credentials", 'GET', $params); if ($response['status']==200) { return true; } return false; } ////////////////////////////////////////// /* end confident captcha libraries */ ////////////////////////////////////////// // Avoid name collisions. if (!class_exists('WPConfidentCaptcha')) : class WPConfidentCaptcha { // name for our options in the DB var $db_option = 'WPConfidentCaptcha_options'; // the plugin URL var $plugin_url; // path to store the cache file var $cache_path; // Initialize WordPress hooks function WPConfidentCaptcha() { $this->plugin_url = trailingslashit( WP_PLUGIN_URL.'/'. dirname(plugin_basename(__FILE__))); $this->cache_path = ABSPATH .'wp-content/'; // admin_menu hook add_action('admin_menu', array(&$this, 'admin_menu')); //add filters or actions //add_filter('wp_authenticate_user',''); add_action('comment_form_after_fields', array(&$this, 'comment_form_captcha')); add_action('comment_post', array(&$this, 'comment_post')); add_action('login_form', array(&$this, 'login_form_captcha')); add_action('user_register', array(&$this, 'user_register_captcha')); add_filter('register_form',array(&$this, 'register_form_captcha')); add_action('wp_print_scripts', array(&$this, 'scripts_action')); add_action('init', array(&$this, 'init_jquery')); } function admin_menu() { add_options_page('ConfiedentCaptcha Options', 'ConfidentCAPTCHA', 8, basename(__FILE__), array(&$this, 'handle_options')); } // handle plugin options function get_options() { // default values $options = array('customer_id' => '', 'site_id' => '', 'api_username' => '', 'api_password' => ''); // get saved options $saved = get_option($this->db_option); // assign them if (!empty($saved)) { foreach ($saved as $key => $option) $options[$key] = $option; } // update the options if necessary if ($saved != $options){ update_option($this->db_option, $options); } //get my ipaddr in real time $options['ip_addr'] = getIpAddr(); //get user agent string in real time $options['user_agent'] = $_SERVER['HTTP_USER_AGENT']; //return the options return $options; } // handle the options page function handle_options() { $options = $this->get_options(); if (isset($_POST['submitted'])) { //TODO add check_credentials here //check_captcha($options); $options = array(); $options['customer_id'] = $_POST['customer_id']; $options['site_id'] = $_POST['site_id']; $options['api_username'] = $_POST['api_username']; $options['api_password'] = $_POST['api_password']; $options['comments'] = $_POST['comments']; $options['login'] = $_POST['login']; $options['register'] = $_POST['register']; update_option($this->db_option, $options); $localopts = $this->get_options(); echo '

Plugin settings '.$localopts[1]. ' saved.

'; } $layout = $options['layout']; $customer_id = $options['customer_id']; $site_id= $options['site_id']; $api_username = $options['api_username']; $api_password = $options['api_password']; $comments = $options['comments'] == 'on' ? 'checked' : ''; $login = $options['login'] == 'on' ? 'checked' : ''; $register = $options['register'] == 'on' ? 'checked' : ''; // URL for form submit, equals our current page $action_url = $_SERVER['REQUEST_URI']; include('confidentcaptcha-options.php'); } // Set up everything function install() { // set default options $this->get_options(); } function init_jquery() { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'http://code.jquery.com/jquery-1.4.2.min.js'); wp_enqueue_script('jquery'); } function scripts_action() { echo ''; } function check_credentials_admin() { $options = $this->get_options(); $cred_check = check_credentials($options); if ($cred_check == false) { ?>
You need to enter the correct values below for this plugin to work.
get_options(); session_start(); $code = $_POST['code']; $captcha_id = $_POST['captcha_id']; //TODO get these values from the form $captcha_response = check_captcha($code, $captcha_id, $options); global $user_ID; //skip if user is logged in if($user_ID) { return $id; } //skip if captcha passes if ($captcha_response == True) { return $id; } ?>
Your CAPTCHA check didn't pass. Sorry.
get_options(); // If its registered user, no need CAPTCHA if( $user_ID ) { ?>
Registered users do not need to go through CAPTCHA test.
You must pass the CAPTCHA test for this comment to post.
get_options(); if ($options['register']) { echo create_captcha($options); } } function login_form_captcha($content) { //TODO Check if API credentials are valid and fail gracefully $options = $this->get_options(); if ($options['login']) { echo create_captcha($options); } } } else : exit("Class ConfidentCaptcha already declared!"); endif; if (class_exists('WPConfidentCaptcha')) : $WPConfidentCaptcha = new WPConfidentCaptcha(); if (isset($WPConfidentCaptcha)) { register_activation_hook(__FILE__, array(&$WPConfidentCaptcha, 'install')); } endif;