Пример #1
0
 public function interceptQuery(Varien_Event_Observer $observer)
 {
     if (isset($_GET['close_notice'])) {
         $config = new Mage_Core_Model_Config();
         $config->saveConfig('general/cleantalk/show_notice', 0, 'default', 0);
         Mage::app()->cleanCache();
         header('Location: .');
         die;
     }
     if (isset($_GET['get_auto_key'])) {
         Mage::getSingleton('core/session', array('name' => 'adminhtml'));
         if (Mage::getSingleton('admin/session')->isLoggedIn()) {
             require_once 'lib/cleantalk.class.php';
             $admin_email = Mage::getStoreConfig('trans_email/ident_general/email');
             $site = $_SERVER['HTTP_HOST'];
             $result = getAutoKey($admin_email, $site, 'magento');
             if ($result) {
                 $result = json_decode($result, true);
                 if (isset($result['data']) && is_array($result['data'])) {
                     $result = $result['data'];
                 } else {
                     if (isset($result['error_no'])) {
                         header('Location: ?cleantalk_message=' . $result['error_message']);
                         die;
                     }
                 }
                 if (isset($result['auth_key'])) {
                     Mage::app()->cleanCache();
                     $config = new Mage_Core_Model_Config();
                     $config->saveConfig('general/cleantalk/api_key', $result['auth_key'], 'default', 0);
                     Cleantalk_Antispam_Model_Observer::CleantalkTestMessage($result['auth_key']);
                 }
                 header('Location: .');
                 die;
             }
         }
     }
     if (isset($_POST['groups']['cleantalk']['fields']['api_key']['value'])) {
         $new_key = $_POST['groups']['cleantalk']['fields']['api_key']['value'];
         $old_key = Mage::getStoreConfig('general/cleantalk/api_key');
         if ($old_key != $new_key && $new_key != '') {
             Cleantalk_Antispam_Model_Observer::CleantalkTestMessage($new_key);
         }
     }
     //Mage::getSingleton('core/session', array('name'=>'adminhtml')); //Was here already
     if (isset($_COOKIE['adminhtml'])) {
         $key = Mage::getStoreConfig('general/cleantalk/api_key');
         $last_checked = intval(Mage::getStoreConfig('general/cleantalk/last_checked'));
         $last_status = intval(Mage::getStoreConfig('general/cleantalk/is_paid'));
         $new_checked = time();
         if ($key != '') {
             $new_status = $last_status;
             if ($new_checked - $last_checked > 3600) {
                 require_once 'lib/cleantalk.class.php';
                 $url = 'https://api.cleantalk.org';
                 $dt = array('auth_key' => $key, 'method_name' => 'get_account_status');
                 $result = sendRawRequest($url, $dt, false);
                 if ($result !== null) {
                     $result = json_decode($result);
                     if (isset($result->data) && isset($result->data->paid)) {
                         $new_status = intval($result->data->paid);
                         if ($last_status != 1 && $new_status == 1) {
                             $config = new Mage_Core_Model_Config();
                             $config->saveConfig('general/cleantalk/is_paid', '1', 'default', 0);
                             $config->saveConfig('general/cleantalk/show_notice', '1', 'default', 0);
                             Mage::app()->cleanCache();
                         }
                     }
                 }
                 $config = new Mage_Core_Model_Config();
                 $config->saveConfig('general/cleantalk/last_checked', $new_checked, 'default', 0);
             }
         }
     }
     if (!isset($_COOKIE['adminhtml']) && sizeof($_POST) > 0 && strpos($_SERVER['REQUEST_URI'], 'login') === false && strpos($_SERVER['REQUEST_URI'], 'forgotpassword') === false) {
         $isCustomForms = Mage::getStoreConfig('general/cleantalk/custom_forms');
         if ($isCustomForms == 1) {
             $ct_fields = Cleantalk_Antispam_Model_Observer::cleantalkGetFields($_POST);
             //Additional conditions for OneStepCheckut extension
             if ($ct_fields['email'] !== null) {
                 if ($_SERVER['REQUEST_URI'] == "/onestepcheckout/ajax/saveFormValues/" || $_SERVER['REQUEST_URI'] == "/onestepcheckout/ajax/saveAddress/" || $_SERVER['REQUEST_URI'] == "/onestepcheckout/ajax/saveShippingMethod/") {
                     break;
                 }
                 $aMessage = array();
                 $aMessage['type'] = 'comment';
                 $aMessage['sender_email'] = $ct_fields['email'] ? $ct_fields['email'] : null;
                 $aMessage['sender_nickname'] = $ct_fields['nickname'] ? $ct_fields['nickname'] : '';
                 $aMessage['message_title'] = '';
                 $aMessage['message_body'] = $ct_fields['message'] ? $ct_fields['message'] : '';
                 $aMessage['example_title'] = '';
                 $aMessage['example_body'] = '';
                 $aMessage['example_comments'] = '';
                 $model = Mage::getModel('antispam/api');
                 $aResult = $model->CheckSpam($aMessage, FALSE);
                 if (isset($aResult) && is_array($aResult)) {
                     if ($aResult['errno'] == 0) {
                         if ($aResult['allow'] == 0) {
                             if (preg_match("//u", $aResult['ct_result_comment'])) {
                                 $comment_str = preg_replace('/^[^\\*]*?\\*\\*\\*|\\*\\*\\*[^\\*]*?$/iu', '', $aResult['ct_result_comment']);
                                 $comment_str = preg_replace('/<[^<>]*>/iu', '', $comment_str);
                             } else {
                                 $comment_str = preg_replace('/^[^\\*]*?\\*\\*\\*|\\*\\*\\*[^\\*]*?$/i', '', $aResult['ct_result_comment']);
                                 $comment_str = preg_replace('/<[^<>]*>/i', '', $comment_str);
                             }
                             //Onestepcheckout fix
                             if ($_SERVER['REQUEST_URI'] == "/onestepcheckout/ajax/placeOrder/") {
                                 echo '{"success":false,"messages":["Spam protection by CleanTalk: ' . $comment_str . '"],"is_hosted_pro":false}';
                                 die;
                             } else {
                                 Mage::getModel('antispam/api')->CleantalkDie($comment_str);
                                 die;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
/**
 * Admin action 'admin_init' - Add the admin settings and such
 */
function ct_admin_init()
{
    global $ct_server_timeout, $show_ct_notice_autokey, $ct_notice_autokey_label, $ct_notice_autokey_value, $show_ct_notice_renew, $ct_notice_renew_label, $show_ct_notice_trial, $ct_notice_trial_label, $show_ct_notice_online, $ct_notice_online_label, $renew_notice_showtime, $trial_notice_showtime, $ct_plugin_name, $ct_options, $ct_data, $trial_notice_check_timeout, $account_notice_check_timeout, $ct_user_token_label, $cleantalk_plugin_version, $notice_check_timeout;
    $ct_options = ct_get_options();
    $ct_data = ct_get_data();
    $current_version = @trim($ct_data['current_version']);
    if ($current_version != $cleantalk_plugin_version) {
        $ct_data['current_version'] = $cleantalk_plugin_version;
        update_option('cleantalk_data', $ct_data);
        $ct_base_call_result = ct_base_call(array('message' => 'This message is a test to check the connection to the CleanTalk servers. ', 'example' => null, 'sender_email' => '*****@*****.**', 'sender_nickname' => 'CleanTalk', 'post_info' => '', 'checkjs' => 1));
    }
    if (isset($_POST['option_page']) && $_POST['option_page'] == 'cleantalk_settings' && isset($_POST['cleantalk_settings']['apikey'])) {
        $ct_options['apikey'] = $_POST['cleantalk_settings']['apikey'];
        update_option('cleantalk_settings', $ct_options);
        $ct_base_call_result = ct_base_call(array('message' => 'This message is a test to check the connection to the CleanTalk servers. ', 'example' => null, 'sender_email' => '*****@*****.**', 'sender_nickname' => 'CleanTalk', 'post_info' => '', 'checkjs' => 1));
    }
    if (@isset($_POST['cleantalk_settings']['spam_firewall']) && $_POST['cleantalk_settings']['spam_firewall'] == 1) {
        cleantalk_update_sfw();
    }
    /*$show_ct_notice_trial = false;
    	if (isset($_COOKIE[$ct_notice_trial_label]))
    	{
    		if ($_COOKIE[$ct_notice_trial_label] == 1)
    		{
    			$show_ct_notice_trial = true;
    		}
    	}
    	$show_ct_notice_renew = false;
    	if (isset($_COOKIE[$ct_notice_renew_label]))
    	{
    		if ($_COOKIE[$ct_notice_renew_label] == 1)
    		{
    			$show_ct_notice_renew = true;
    		}
    	}*/
    $show_ct_notice_autokey = false;
    if (isset($_COOKIE[$ct_notice_autokey_label]) && !empty($_COOKIE[$ct_notice_autokey_label])) {
        if (!empty($_COOKIE[$ct_notice_autokey_label])) {
            $show_ct_notice_autokey = true;
            $ct_notice_autokey_value = base64_decode($_COOKIE[$ct_notice_autokey_label]);
            setcookie($ct_notice_autokey_label, '', 1, '/');
        }
    }
    if (isset($_POST['get_apikey_auto'])) {
        $email = get_option('admin_email');
        $website = parse_url(get_option('siteurl'), PHP_URL_HOST);
        $platform = 'wordpress';
        if (!function_exists('getAutoKey')) {
            require_once 'cleantalk.class.php';
        }
        $result = getAutoKey($email, $website, $platform);
        if ($result) {
            $ct_data['next_account_status_check'] = 0;
            update_option('cleantalk_data', $ct_data);
            $result = json_decode($result, true);
            if (isset($result['data']) && is_array($result['data'])) {
                $result = $result['data'];
            }
            if (isset($result['user_token'])) {
                $ct_data['user_token'] = $result['user_token'];
                update_option('cleantalk_data', $ct_data);
            }
            if (isset($result['auth_key']) && !empty($result['auth_key'])) {
                $_POST['cleantalk_settings']['apikey'] = $result['auth_key'];
                $ct_options['apikey'] = $result['auth_key'];
                update_option('cleantalk_settings', $ct_options);
                /*$ct_base_call_result = ct_base_call(array(
                			'message' => 'CleanTalk setup test',
                			'example' => null,
                			'sender_email' => '*****@*****.**',
                			'sender_nickname' => 'CleanTalk',
                			'post_info' => '',
                			'checkjs' => 1
                		));	*/
            } else {
                setcookie($ct_notice_autokey_label, (string) base64_encode($result['error_message']), 0, '/');
            }
        } else {
            setcookie($ct_notice_autokey_label, (string) base64_encode(sprintf(__('Unable to connect to %s.', 'cleantalk'), 'api.cleantalk.org')), 0, '/');
        }
    }
    if (time() > $ct_data['next_account_status_check'] || isset($_POST['cleantalk_settings']['apikey'])) {
        $result = false;
        //if (true)
        //{
        if (!function_exists('noticePaidTill')) {
            require_once 'cleantalk.class.php';
        }
        if (@isset($_POST['cleantalk_settings']['apikey'])) {
            $result = noticePaidTill($_POST['cleantalk_settings']['apikey']);
        } else {
            $result = noticePaidTill($ct_options['apikey']);
        }
        if ($result) {
            $result = json_decode($result, true);
            if (isset($result['data']) && is_array($result['data'])) {
                $result = $result['data'];
            }
            if (isset($result['spam_count'])) {
                $ct_data['admin_blocked'] = $result['spam_count'];
            }
            if (isset($result['show_notice'])) {
                if ($result['show_notice'] == 1 && isset($result['trial']) && $result['trial'] == 1) {
                    $notice_check_timeout = $trial_notice_check_timeout;
                    $show_ct_notice_trial = true;
                    $ct_data['show_ct_notice_trial'] = 1;
                }
                if ($result['show_notice'] == 1 && isset($result['renew']) && $result['renew'] == 1) {
                    $notice_check_timeout = $account_notice_check_timeout;
                    $show_ct_notice_renew = true;
                    $ct_data['show_ct_notice_renew'] = 1;
                }
                if ($result['show_notice'] == 0) {
                    $notice_check_timeout = $account_notice_check_timeout;
                    $ct_data['show_ct_notice_trial'] = 0;
                    $ct_data['show_ct_notice_renew'] = 0;
                }
            }
            if (isset($result['user_token'])) {
                $ct_data['user_token'] = $result['user_token'];
            }
        }
        // Save next status request time
        $ct_data['next_account_status_check'] = time() + 86400;
        update_option('cleantalk_data', $ct_data);
        //}
        /*if ($result)
        		{
        			if($show_ct_notice_trial == true)
        			{
        				setcookie($ct_notice_trial_label, (string) $show_ct_notice_trial, strtotime("+$trial_notice_showtime minutes"), '/');
        			}
        			if($show_ct_notice_renew == true)
        			{
        				setcookie($ct_notice_renew_label, (string) $show_ct_notice_renew, strtotime("+$renew_notice_showtime minutes"), '/');
        			}
        		}*/
    }
    $show_ct_notice_online = '';
    if (isset($_COOKIE[$ct_notice_online_label])) {
        if ($_COOKIE[$ct_notice_online_label] === 'BAD_KEY') {
            $show_ct_notice_online = 'N';
        } else {
            if (time() - $_COOKIE[$ct_notice_online_label] <= 5) {
                $show_ct_notice_online = 'Y';
            }
        }
    }
    //ct_init_session();
    if (stripos($_SERVER['REQUEST_URI'], 'options.php') !== false || stripos($_SERVER['REQUEST_URI'], 'options-general.php') !== false || stripos($_SERVER['REQUEST_URI'], 'network/settings.php') !== false) {
        if (isset($ct_data['testing_failed']) && $ct_data['testing_failed'] == 1) {
            $buttons_html = '	
	<style type="text/css">
	#ct_button_check_comments, #ct_button_check_users {background: #999999;}
			
			';
        } else {
            $buttons_html = '
	<style type="text/css">
	#ct_button_check_comments, #ct_button_check_users {background: #69dd69;}
			
			';
        }
        $buttons_html .= '
	#ct_button_check_comments, #ct_button_check_users  {padding: 10px; color: #fff; border:0 none;
		cursor:pointer;
		-webkit-border-radius: 5px;
		border-radius: 5px; 
		font-size: 12pt;
		text-decoration:none;
		margin-bottom:5px;
		display:inline-block;
	}
	
	#ct_stats_banner
	{
		padding: 0px; 
		color: #000; 
		/*border:2px solid #e5e5e5;*/
		font-size: 10pt;
		text-decoration:none;
		margin-bottom:5px;
		display:inline-block;
	}
	</style>';
        if (isset($ct_data['testing_failed']) && $ct_data['testing_failed'] == 1) {
            /*$buttons_html.='<a href="#" id="ct_button_check_comments" onclick="alert('."'".__('Feature is disabled, because testing of access key is failed!', 'cleantalk')."'".')">'.__('Check comments', 'cleantalk').'</a>
            	<a href="#" id="ct_button_check_users" onclick="alert('."'".__('Feature is disabled, because testing of access key is failed!', 'cleantalk')."'".')">'.__('Check users', 'cleantalk').'</a><div class="clear"></div>';*/
        } else {
            /*$buttons_html.='<a href="edit-comments.php?page=ct_check_spam&do_check=1" style="font-size:10pt;font-weight:400;">'.__('Check comments', 'cleantalk').'</a><br />
            	<a href="users.php?page=ct_check_users&do_check=1" style="font-size:10pt;font-weight:400;">'.__('Check users', 'cleantalk').'</a><div class="clear"></div>';*/
        }
        register_setting('cleantalk_settings', 'cleantalk_settings', 'ct_settings_validate');
        add_settings_section('cleantalk_settings_main', __($ct_plugin_name, 'cleantalk'), 'ct_section_settings_main', 'cleantalk');
        add_settings_section('cleantalk_settings_state', "<hr>" . __('Protection is active', 'cleantalk'), 'ct_section_settings_state', 'cleantalk');
        //add_settings_section('cleantalk_settings_autodel', "<hr>", 'ct_section_settings_autodel', 'cleantalk');
        add_settings_section('cleantalk_settings_banner', "<hr></h3>", '', 'cleantalk');
        add_settings_section('cleantalk_settings_anti_spam', "<a href='#' style='text-decoration:underline;font-size:10pt;font-weight:400;'>" . __('Advanced settings', 'cleantalk') . "</a>", 'ct_section_settings_anti_spam', 'cleantalk');
        if (!defined('CLEANTALK_ACCESS_KEY')) {
            add_settings_field('cleantalk_apikey', __('Access key', 'cleantalk'), 'ct_input_apikey', 'cleantalk', 'cleantalk_settings_main');
        } else {
            add_settings_field('cleantalk_apikey', '', 'ct_input_apikey', 'cleantalk', 'cleantalk_settings_main');
        }
        add_settings_field('cleantalk_remove_old_spam', __('Automatically delete spam comments', 'cleantalk'), 'ct_input_remove_old_spam', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_registrations_test', __('Registration forms', 'cleantalk'), 'ct_input_registrations_test', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_comments_test', __('Comments form', 'cleantalk'), 'ct_input_comments_test', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_contact_forms_test', __('Contact forms', 'cleantalk'), 'ct_input_contact_forms_test', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_general_contact_forms_test', __('Custom contact forms', 'cleantalk'), 'ct_input_general_contact_forms_test', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_general_postdata_test', __('Check all post data', 'cleantalk'), 'ct_input_general_postdata_test', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_show_adminbar', __('Show statistics in admin bar', 'cleantalk'), 'ct_input_show_adminbar', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_use_ajax', __('Use AJAX for JavaScript check', 'cleantalk'), 'ct_input_use_ajax', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_check_external', __('Protect external forms', 'cleantalk'), 'ct_input_check_external', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_check_comments_number', __("Don't check comments", 'cleantalk'), 'ct_input_check_comments_number', 'cleantalk', 'cleantalk_settings_anti_spam');
        //add_settings_field('cleantalk_check_messages_number', __("Don't check messages", 'cleantalk'), 'ct_input_check_messages_number', 'cleantalk', 'cleantalk_settings_anti_spam');
        add_settings_field('cleantalk_spam_firewall', __('', 'cleantalk'), 'ct_input_spam_firewall', 'cleantalk', 'cleantalk_settings_banner');
        add_settings_field('cleantalk_collect_details', __('Collect details about browsers', 'cleantalk'), 'ct_input_collect_details', 'cleantalk', 'cleantalk_settings_banner');
        add_settings_field('cleantalk_show_link', __('', 'cleantalk'), 'ct_input_show_link', 'cleantalk', 'cleantalk_settings_banner');
    }
}
/**
 * Admin action 'admin_init' - Add the admin settings and such
 */
function ct_admin_init()
{
    global $ct_server_timeout, $show_ct_notice_autokey, $ct_notice_autokey_label, $ct_notice_autokey_value, $show_ct_notice_renew, $ct_notice_renew_label, $show_ct_notice_trial, $ct_notice_trial_label, $show_ct_notice_online, $ct_notice_online_label, $renew_notice_showtime, $trial_notice_showtime, $ct_plugin_name, $ct_options, $ct_data, $trial_notice_check_timeout, $account_notice_check_timeout, $ct_user_token_label, $cleantalk_plugin_version, $notice_check_timeout;
    //$ct_options = ct_get_options();
    //$ct_data = ct_get_data();
    $current_version = @trim($ct_data['current_version']);
    if ($current_version != $cleantalk_plugin_version) {
        $ct_data['current_version'] = $cleantalk_plugin_version;
        update_option('cleantalk_data', $ct_data);
        $ct_base_call_result = ct_base_call(array('message' => 'CleanTalk connection test', 'example' => null, 'sender_email' => '*****@*****.**', 'sender_nickname' => 'CleanTalk', 'post_info' => '', 'checkjs' => 1));
    }
    if (isset($_POST['option_page']) && $_POST['option_page'] == 'cleantalk_settings') {
        $ct_base_call_result = ct_base_call(array('message' => 'CleanTalk connection test', 'example' => null, 'sender_email' => '*****@*****.**', 'sender_nickname' => 'CleanTalk', 'post_info' => '', 'checkjs' => 1));
    }
    $show_ct_notice_trial = false;
    if (isset($_COOKIE[$ct_notice_trial_label])) {
        if ($_COOKIE[$ct_notice_trial_label] == 1) {
            $show_ct_notice_trial = true;
        }
    }
    $show_ct_notice_renew = false;
    if (isset($_COOKIE[$ct_notice_renew_label])) {
        if ($_COOKIE[$ct_notice_renew_label] == 1) {
            $show_ct_notice_renew = true;
        }
    }
    $show_ct_notice_autokey = false;
    if (isset($_COOKIE[$ct_notice_autokey_label]) && !empty($_COOKIE[$ct_notice_autokey_label])) {
        if (!empty($_COOKIE[$ct_notice_autokey_label])) {
            $show_ct_notice_autokey = true;
            $ct_notice_autokey_value = base64_decode($_COOKIE[$ct_notice_autokey_label]);
            setcookie($ct_notice_autokey_label, '', 1, '/');
        }
    }
    if (isset($_POST['get_apikey_auto'])) {
        $email = get_option('admin_email');
        $website = parse_url(get_option('siteurl'), PHP_URL_HOST);
        $platform = 'wordpress';
        $result = getAutoKey($email, $website, $platform);
        if ($result) {
            $result = json_decode($result, true);
            if (isset($result['data']) && is_array($result['data'])) {
                $result = $result['data'];
            }
            if (isset($result['user_token'])) {
                $ct_data['user_token'] = $result['user_token'];
                update_option('cleantalk_data', $ct_data);
            }
            if (isset($result['auth_key']) && !empty($result['auth_key'])) {
                $_POST['cleantalk_settings']['apikey'] = $result['auth_key'];
                $ct_options['apikey'] = $result['auth_key'];
                update_option('cleantalk_settings', $ct_options);
                $ct_base_call_result = ct_base_call(array('message' => 'CleanTalk connection test', 'example' => null, 'sender_email' => '*****@*****.**', 'sender_nickname' => 'CleanTalk', 'post_info' => '', 'checkjs' => 1));
            } else {
                setcookie($ct_notice_autokey_label, (string) base64_encode($result['error_message']), 0, '/');
            }
        } else {
            setcookie($ct_notice_autokey_label, (string) base64_encode(sprintf(__('Unable to connect to %s.', 'cleantalk'), 'api.cleantalk.org')), 0, '/');
        }
    }
    if (time() > $ct_data['next_account_status_check'] || isset($_POST['option_page']) && $_POST['option_page'] == 'cleantalk_settings' && $ct_options['apikey'] != $_POST['cleantalk_settings']['apikey']) {
        $result = false;
        if (function_exists('curl_init') && function_exists('json_decode') && ct_valid_key($ct_options['apikey'])) {
            if (@isset($_POST['cleantalk_settings']['apikey'])) {
                $result = noticePaidTill($_POST['cleantalk_settings']['apikey']);
            } else {
                $result = noticePaidTill($ct_options['apikey']);
            }
            if ($result) {
                $result = json_decode($result, true);
                if (isset($result['data']) && is_array($result['data'])) {
                    $result = $result['data'];
                }
                if (isset($result['show_notice'])) {
                    if ($result['show_notice'] == 1 && isset($result['trial']) && $result['trial'] == 1) {
                        $notice_check_timeout = $trial_notice_check_timeout;
                        $show_ct_notice_trial = true;
                    }
                    if ($result['show_notice'] == 1 && isset($result['renew']) && $result['renew'] == 1) {
                        $notice_check_timeout = $account_notice_check_timeout;
                        $show_ct_notice_renew = true;
                    }
                    if ($result['show_notice'] == 0) {
                        $notice_check_timeout = $account_notice_check_timeout;
                    }
                }
                if (isset($result['user_token'])) {
                    $ct_data['user_token'] = $result['user_token'];
                }
            }
            // Save next status request time
            $ct_data['next_account_status_check'] = strtotime("+{$notice_check_timeout} hours", time());
            update_option('cleantalk_data', $ct_data);
        }
        if ($result) {
            if ($show_ct_notice_trial == true) {
                setcookie($ct_notice_trial_label, (string) $show_ct_notice_trial, strtotime("+{$trial_notice_showtime} minutes"), '/');
            }
            if ($show_ct_notice_renew == true) {
                setcookie($ct_notice_renew_label, (string) $show_ct_notice_renew, strtotime("+{$renew_notice_showtime} minutes"), '/');
            }
        }
    }
    $show_ct_notice_online = '';
    if (isset($_COOKIE[$ct_notice_online_label])) {
        if ($_COOKIE[$ct_notice_online_label] === 'BAD_KEY') {
            $show_ct_notice_online = 'N';
        } else {
            if (time() - $_COOKIE[$ct_notice_online_label] <= 5) {
                $show_ct_notice_online = 'Y';
            }
        }
    }
    ct_init_session();
    if (isset($ct_data['testing_failed']) && $ct_data['testing_failed'] == 1) {
        $buttons_html = '	
<style type="text/css">
#ct_button_check_comments, #ct_button_check_users {background: #999999;}
    	
    	';
    } else {
        $buttons_html = '
<style type="text/css">
#ct_button_check_comments, #ct_button_check_users {background: #69dd69;}
    	
    	';
    }
    $buttons_html .= '
#ct_button_check_comments, #ct_button_check_users  {padding: 10px; color: #fff; border:0 none;
    cursor:pointer;
    -webkit-border-radius: 5px;
    border-radius: 5px; 
    font-size: 12pt;
    text-decoration:none;
    margin-bottom:5px;
    display:inline-block;
}
</style>';
    if (isset($ct_data['testing_failed']) && $ct_data['testing_failed'] == 1) {
        $buttons_html .= '<a href="#" id="ct_button_check_comments" onclick="alert(' . "'" . __('Feature is disabled, because testing of access key is failed!', 'cleantalk') . "'" . ')">' . __('Check comments', 'cleantalk') . '</a>
<a href="#" id="ct_button_check_users" onclick="alert(' . "'" . __('Feature is disabled, because testing of access key is failed!', 'cleantalk') . "'" . ')">' . __('Check users', 'cleantalk') . '</a><div class="clear"></div>';
    } else {
        $buttons_html .= '<a href="edit-comments.php?page=ct_check_spam&do_check=1" id="ct_button_check_comments">' . __('Check comments', 'cleantalk') . '</a>
<a href="users.php?page=ct_check_users&do_check=1" id="ct_button_check_users">' . __('Check users', 'cleantalk') . '</a><div class="clear"></div>';
    }
    register_setting('cleantalk_settings', 'cleantalk_settings', 'ct_settings_validate');
    add_settings_section('cleantalk_settings_main', __($ct_plugin_name, 'cleantalk'), 'ct_section_settings_main', 'cleantalk');
    add_settings_section('cleantalk_settings_state', "<hr>" . __('Protection is active for:', 'cleantalk'), 'ct_section_settings_state', 'cleantalk');
    //add_settings_section('cleantalk_settings_autodel', "<hr>", 'ct_section_settings_autodel', 'cleantalk');
    add_settings_section('cleantalk_settings_anti_spam', "<hr>Check existing comments and users <br /><br />{$buttons_html}<hr>" . __('Advanced settings', 'cleantalk'), 'ct_section_settings_anti_spam', 'cleantalk');
    add_settings_field('cleantalk_apikey', __('Access key', 'cleantalk'), 'ct_input_apikey', 'cleantalk', 'cleantalk_settings_main');
    add_settings_field('cleantalk_remove_old_spam', __('Automatically delete spam comments', 'cleantalk'), 'ct_input_remove_old_spam', 'cleantalk', 'cleantalk_settings_anti_spam');
    add_settings_field('cleantalk_registrations_test', __('Registration forms', 'cleantalk'), 'ct_input_registrations_test', 'cleantalk', 'cleantalk_settings_anti_spam');
    add_settings_field('cleantalk_comments_test', __('Comments form', 'cleantalk'), 'ct_input_comments_test', 'cleantalk', 'cleantalk_settings_anti_spam');
    add_settings_field('cleantalk_contact_forms_test', __('Contact forms', 'cleantalk'), 'ct_input_contact_forms_test', 'cleantalk', 'cleantalk_settings_anti_spam');
    add_settings_field('cleantalk_general_contact_forms_test', __('Custom contact forms', 'cleantalk'), 'ct_input_general_contact_forms_test', 'cleantalk', 'cleantalk_settings_anti_spam');
    add_settings_field('cleantalk_general_postdata_test', __('Check all post data', 'cleantalk'), 'ct_input_general_postdata_test', 'cleantalk', 'cleantalk_settings_anti_spam');
    add_settings_field('cleantalk_show_adminbar', __('Show statistics in admin bar', 'cleantalk'), 'ct_input_show_adminbar', 'cleantalk', 'cleantalk_settings_anti_spam');
    add_settings_field('cleantalk_use_ajax', __('Use AJAX for JavaScript check', 'cleantalk'), 'ct_input_use_ajax', 'cleantalk', 'cleantalk_settings_anti_spam');
    add_settings_field('cleantalk_check_external', __('Protect external forms', 'cleantalk'), 'ct_input_check_external', 'cleantalk', 'cleantalk_settings_anti_spam');
}