AdCaptcher account to create profiles for your websites and to administrate your captchas.
Version: 1.1
Author: razvaniacob, razvantirboaca
Author URI: http://www.adcaptcher.com
*/
/* Copyright 2008 Adcaptcher, http://www.adcaptcher.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
# ----------------------------------------------------------------
# AdCaptcher class
# ----------------------------------------------------------------
class adcaptcher {
# ------
# Version info
# ------
var $version = '1.1';
# ------
# Private Key
# ------
var $key_file = '../wp-content/plugins/adcaptcher/adcaptcherKey.txt';
# ----------------------------------------------------------------
# Constructor
# ----------------------------------------------------------------
function adcaptcher() {
if (file_exists($this->key_file)) {
add_option('adc_key', file_get_contents($this->key_file));
}
add_action("admin_menu", array("adcaptcher", "adc_submeniu"));
$this->adc_admin_warnings();
}
# ----------------------------------------------------------------
# Alert admin if key is not set
# ----------------------------------------------------------------
function adc_admin_warnings() {
global $user_ID;
if ( !$this->adc_get_key() && !isset($_POST['submit']) ) {
function adc_warning() {
if(get_admin_page_title() != 'AdCaptcher Config')
echo "
".__('Adcaptcher is almost ready.')." ".sprintf(__('You must enter your AdCaptcher key for it to work.'), "plugins.php?page=adcaptcher-key-config")."
";
}
add_action("admin_notices", array("adcaptcher", "adc_warning"));
return;
}
if ($user_ID) {
return;
} else {
$browser = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile');
add_action("comment_form", array("adcaptcher", "adc_embeded"), 9999);
add_action("wp_footer", array("adcaptcher", "adc_onsubmit"));
if($browser === false) {
add_action("comment_post", array("adcaptcher", "adc_captcha_post"));
}
}
}
# ----------------------------------------------------------------
# Add admin config link
# ----------------------------------------------------------------
function adc_submeniu() {
if ( function_exists('add_submenu_page') )
add_submenu_page('plugins.php', __('AdCaptcher Config'), __('AdCaptcher Config'), 'manage_options', 'adcaptcher-key-config', array('adcaptcher','adc_config_page'));
}
# ----------------------------------------------------------------
# Admin config page
# ----------------------------------------------------------------
function adc_config_page() {
global $adcaptcher;
if ( isset($_POST['updatekey']) ) {
if ( function_exists('current_user_can') && !current_user_can('manage_options') )
die(__('Cheatin’ uh?'));
$key = $_POST['key'];
if ( empty( $key ) ) {
$ms = 'new_key_empty';
delete_option('adc_key');
@unlink('../wp-content/plugins/adcaptcher/adcaptcherKey.txt');
} elseif ( !$adcaptcher->adc_verify_key( $key ) ) {
$ms = 'new_key_invalid';
} else {
update_option('adc_key', $key);
$ms = 'new_key_valid';
}
} else if ( isset($_POST['updateoptions']) ) {
if ( function_exists('current_user_can') && !current_user_can('manage_options') )
die(__('Cheatin’ uh?'));
$key = $adcaptcher->adc_get_key();
if ( !isset($_POST['credits']) ) {
add_option('adc_credits', 'false');
$ms = 'not_show_copyr';
} else {
delete_option('adc_credits');
$ms = 'show_copyr';
}
} else {
$key = $adcaptcher->adc_get_key();
if ( empty( $key ) ) {
$ms = '';
} elseif ( !$adcaptcher->adc_verify_key( $key ) ) {
delete_option('adc_key');
$ms = 'key_invalid';
} else {
$ms = 'key_valid';
}
}
$messages = array(
'new_key_empty' => array('class' => 'updated', 'text' => __('Your key has been cleared.')),
'new_key_valid' => array('class' => 'updated', 'text' => __('Your key has been saved. Happy blogging!')),
'new_key_invalid' => array('class' => 'error', 'text' => __('The key you entered is invalid. Please check it in the Websites section of your AdCaptcher account.')),
'key_valid' => array('class' => 'updated', 'text' => __('This key is valid.')),
'key_invalid' => array('class' => 'error', 'text' => __('The key below was previously validated but a connection to adcaptcher.com can not be established at this time. Please check your server configuration.')),
'not_show_copyr' => array('class' => 'updated', 'text' => __('Your settings has been saved.')),
'show_copyr' => array('class' => 'updated', 'text' => __('Your settings has been saved.')),
);
?>
0)
return false;
else
return true;
}
# ----------------------------------------------------------------
# Get public key
# ----------------------------------------------------------------
function adc_get_key() {
return get_option('adc_key');
}
# ----------------------------------------------------------------
# Embeded script
# ----------------------------------------------------------------
function adc_embeded($id) {
global $adcaptcher;
global $user_ID;
if( $user_ID ) {
return $id;
} else {
echo '
';
if(get_option('adc_credits') == 'false') {
echo '';
}
}
}
# ----------------------------------------------------------------
# Add onsubmit action
# ----------------------------------------------------------------
function adc_onsubmit($id) {
global $user_ID;
if( $user_ID ) {
return $id;
}
echo '';
}
# ----------------------------------------------------------------
# Validate user security code
# ----------------------------------------------------------------
function adc_captcha_post($id) {
global $user_ID;
$response = file_get_contents("http://code.adcaptcher.com/check".$_POST["kcodekey"]."/".urlencode($_POST["kcodecaptcha"]));
if($response == "INVALID") {
// action when adcaptcher is INVALID
wp_set_comment_status($id, 'delete');
echo 'The AdCaptcher error!
You need to activate JavaScript in order to submit this form. Please activate it and go back, thank you!
';
exit();
} elseif($response == "INACTIVE") {
// action when adcaptcher is INACTIVE
return $id;
} else {
// action when is everithing OK
return $id;
}
}
}
$adcaptcher = new adcaptcher;
?>