\n"; $result .= "\n"; return $result; } function ValidateCaptcha($captchaId, $privateKey) { global $ADSCAPTCHA_API, $_POST, $_SERVER; $host = $ADSCAPTCHA_API; $path = "/Validate.aspx"; $data = "CaptchaId=" . $captchaId . "&PrivateKey=" . $privateKey . "&ChallengeCode=" . $_POST['adscaptcha_challenge_field'] . "&UserResponse=" . $_POST['adscaptcha_response_field'] . "&RemoteAddress=" . $_SERVER["REMOTE_ADDR"]; $result = HttpPost($host, $path, $data); return $result; } function FixEncoding($str) { $curr_encoding = mb_detect_encoding($str) ; if($curr_encoding == "UTF-8" && mb_check_encoding($str,"UTF-8")) { return $str; } else { return utf8_encode($str); } } function HttpPost($host, $path, $data, $port = 80) { $data = FixEncoding($data); $http_request = "POST $path HTTP/1.0\r\n"; $http_request .= "Host: $host\r\n"; $http_request .= "Content-Type: application/x-www-form-urlencoded\r\n"; $http_request .= "Content-Length: " . strlen($data) . "\r\n"; $http_request .= "\r\n"; $http_request .= $data; $response = ''; if (($fs = @fsockopen($host, $port, $errno, $errstr, 10)) == false) { die ('Could not open socket! ' . $errstr); } fwrite($fs, $http_request); while (!feof($fs)) $response .= fgets($fs, 1160); fclose($fs); $response = explode("\r\n\r\n", $response, 2); return $response[1]; } // ------------------- // // Registration form // // ------------------- // // Display the AdsCaptcha challenge on the registration form function display_adscaptcha_registration() { global $adscaptchaOptions; $captchaId = ($adscaptchaOptions['adscaptcha_registration_captcha_id'] == null ? $adscaptchaOptions['adscaptcha_captcha_id'] : $adscaptchaOptions['adscaptcha_registration_captcha_id']); $publicKey = $adscaptchaOptions['adscaptcha_public_key']; echo(getCaptcha($captchaId, $publicKey)); } // Check the AdsCaptcha challenge on the registration form function validate_adscaptcha_registration($errors) { global $adscaptchaOptions, $ADSCAPTCHA_API; if (empty($_POST['adscaptcha_response_field'])) { $errors->add('error_blank', $adscaptchaOptions['adscaptcha_message_blank']); return $errors; } $captchaId = ($adscaptchaOptions['adscaptcha_registration_captcha_id'] == null ? $adscaptchaOptions['adscaptcha_captcha_id'] : $adscaptchaOptions['adscaptcha_registration_captcha_id']); $privateKey = $adscaptchaOptions['adscaptcha_private_key']; $result = ValidateCaptcha($captchaId, $privateKey); if ($result != "true") { $errors->add('error_incorrect', $adscaptchaOptions['adscaptcha_message_incorrect']); return $errors; } return $errors; } // If registration CAPTCHA is enabled, hook it! if ($adscaptchaOptions['adscaptcha_registration_enable']) { add_action('register_form', 'display_adscaptcha_registration'); add_filter('registration_errors', 'validate_adscaptcha_registration'); } // -------------- // // Comment form // // -------------- // define ("ADSCAPTCHA_WP_HASH", "c567eba78ca8798c89087230589a989"); $adscaptcha_error = ''; function adscaptcha_wp_hash($key) { global $adscaptchaOptions; if (function_exists('wp_hash')) return wp_hash(ADSCAPTCHA_WP_HASH . $key); else return md5(ADSCAPTCHA_WP_HASH . $adscaptchaOptions['adscaptcha_private_key'] . $key); } // Display the AdsCaptcha challenge on the comment form function display_adscaptcha_comment() { global $adscaptchaOptions; if (!$adscaptchaOptions['adscaptcha_comment_enable']) return; if (is_user_logged_in() && $adscaptchaOptions['adscaptcha_comment_hide']) { if (current_user_can($adscaptchaOptions['adscaptcha_comment_hide_permission_level'])) { return; } } if ($_GET['rerror'] == 'adscaptcha_message_blank') echo "
" . str_replace("\'", "'", $adscaptchaOptions['adscaptcha_message_blank']) . "
"; if ($_GET['rerror'] == 'adscaptcha_message_incorrect') echo "" . str_replace("\'", "'", $adscaptchaOptions['adscaptcha_message_incorrect']) . "
"; $captchaId = ($adscaptchaOptions['adscaptcha_comment_captcha_id'] == null ? $adscaptchaOptions['adscaptcha_captcha_id'] : $adscaptchaOptions['adscaptcha_comment_captcha_id']); $publicKey = $adscaptchaOptions['adscaptcha_public_key']; echo(getCaptcha($captchaId, $publicKey)); if ($adscaptchaOptions['adscaptcha_comment_rearrange']) { echo(""); } } function validate_adscaptcha_comment($comment_data) { global $user_ID, $adscaptchaOptions, $adscaptcha_error; if (!$adscaptchaOptions['adscaptcha_comment_enable']) return $comment_data; if (is_user_logged_in() && $adscaptchaOptions['adscaptcha_comment_hide']) { if (current_user_can($adscaptchaOptions['adscaptcha_comment_hide_permission_level'])) { return $comment_data; } } if ($comment_data['comment_type'] == '') { if (empty($_POST['adscaptcha_response_field'])) { $adscaptcha_error = 'adscaptcha_message_blank'; add_filter('pre_comment_approved', create_function('$a', 'return \'spam\';')); return $comment_data; } $captchaId = ($adscaptchaOptions['adscaptcha_comment_captcha_id'] == null ? $adscaptchaOptions['adscaptcha_captcha_id'] : $adscaptchaOptions['adscaptcha_comment_captcha_id']); $privateKey = $adscaptchaOptions['adscaptcha_private_key']; if (ValidateCaptcha($captchaId, $privateKey) == "true") { return $comment_data; } else { $adscaptcha_error = 'adscaptcha_message_incorrect'; add_filter('pre_comment_approved', create_function('$a', 'return \'spam\';')); return $comment_data; } } return $comment_data; } function adscaptcha_comment_post_redirect($location, $comment) { global $adscaptcha_error; if($adscaptcha_error != '') { $location = substr($location, 0,strrpos($location, '#')) . ((strrpos($location, "?") === false) ? "?" : "&") . 'rcommentid=' . $comment->comment_ID . '&rerror=' . $adscaptcha_error . '&rchash=' . adscaptcha_wp_hash ($comment->comment_ID). '#commentform'; } return $location; } function adscaptcha_wp_saved_comment() { if (!is_single() && !is_page()) return; if ($_GET['rcommentid'] && $_GET['rchash'] == adscaptcha_wp_hash ($_GET['rcommentid'])) { $comment = get_comment($_GET['rcommentid']); $com = preg_replace('/([\\/\(\)\+\;\'\"])/e','\'%\'.dechex(ord(\'$1\'))', $comment->comment_content); $com = preg_replace('/\\r\\n/m', '\\\n', $com); wp_delete_comment($comment->comment_ID); } } // If comment CAPTCHA is enabled, hook it! if ($adscaptchaOptions['adscaptcha_comment_enable']) { add_action('comment_form', 'display_adscaptcha_comment'); add_filter('wp_head', 'adscaptcha_wp_saved_comment', 0); add_filter('preprocess_comment', 'validate_adscaptcha_comment', 0); add_filter('comment_post_redirect', 'adscaptcha_comment_post_redirect', 0, 2); } // ---------------- // // Administration // // ---------------- // function adscaptcha_permissions_dropdown($select_name, $checked_value="") { $permissions = array ( 'All registered users' => 'read', 'Edit posts' => 'edit_posts', 'Publish Posts' => 'publish_posts', 'Moderate Comments' => 'moderate_comments', 'Administer site' => 'level_10' ); echo '"; } // Add a link to the configuration options in the WordPress options menu function add_adscaptcha_settings_page() { add_options_page('AdsCaptcha', 'AdsCaptcha', 8, __FILE__, 'adscaptcha_settings_page'); } // Display AdsCaptcha settings page function adscaptcha_settings_page() { $adscaptchaOptionsArray = array( 'adscaptcha_public_key' => '', 'adscaptcha_private_key' => '', 'adscaptcha_captcha_id' => '', 'adscaptcha_registration_enable' => true, 'adscaptcha_registration_captcha_id' => '', 'adscaptcha_comment_enable' => true, 'adscaptcha_comment_captcha_id' => '', 'adscaptcha_comment_hide' => true, 'adscaptcha_comment_hide_permission_level' => 'read', 'adscaptcha_comment_rearrange' => false, 'adscaptcha_message_blank' => 'ERROR: Please complete the CAPTCHA.', 'adscaptcha_message_incorrect' => 'ERROR: The CAPTCHA was incorrect.'); add_option('adscaptcha_options', $adscaptchaOptionsArray); if (isset($_POST[ 'submit' ])) { $adscaptchaOptionsArray['adscaptcha_public_key'] = trim($_POST['adscaptcha_public_key']); $adscaptchaOptionsArray['adscaptcha_private_key'] = trim($_POST['adscaptcha_private_key']); $adscaptchaOptionsArray['adscaptcha_captcha_id'] = trim($_POST['adscaptcha_captcha_id']); $adscaptchaOptionsArray['adscaptcha_registration_enable'] = trim($_POST['adscaptcha_registration_enable']); $adscaptchaOptionsArray['adscaptcha_registration_captcha_id'] = trim($_POST['adscaptcha_registration_captcha_id']); $adscaptchaOptionsArray['adscaptcha_comment_enable'] = trim($_POST['adscaptcha_comment_enable']); $adscaptchaOptionsArray['adscaptcha_comment_captcha_id'] = trim($_POST['adscaptcha_comment_captcha_id']); $adscaptchaOptionsArray['adscaptcha_comment_hide'] = trim($_POST['adscaptcha_comment_hide']); $adscaptchaOptionsArray['adscaptcha_comment_hide_permission_level'] = trim($_POST['adscaptcha_comment_hide_permission_level']); $adscaptchaOptionsArray['adscaptcha_comment_rearrange'] = trim($_POST['adscaptcha_comment_rearrange']); $adscaptchaOptionsArray['adscaptcha_message_blank'] = trim(str_replace("\'", "'", $_POST['adscaptcha_message_blank'])); $adscaptchaOptionsArray['adscaptcha_message_incorrect'] = trim(str_replace("\'", "'", $_POST['adscaptcha_message_incorrect'])); update_option('adscaptcha_options', $adscaptchaOptionsArray); } $adscaptchaOptions = get_option('adscaptcha_options'); ?>
AdsCaptcha is a free CAPTCHA service that generates income while blocking spam on your website!
For more details, visit the AdsCaptcha website.
AdsCaptcha is not active. You must enter your AdsCaptcha API keys for it to work.
"; } add_action('admin_notices', 'adscaptcha_warning'); return; } ?>