Plugin Directory

Changeset 1116671


Ignore:
Timestamp:
03/20/2015 07:59:58 AM (11 years ago)
Author:
znaeff
Message:

Splitted array to 2 - options from CP and run-time data.

Location:
cleantalk-spam-protect/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cleantalk-spam-protect/trunk/cleantalk-admin.php

    r1116000 r1116671  
    2626 */
    2727function ct_admin_init() {
    28     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, $trial_notice_check_timeout, $account_notice_check_timeout, $ct_user_token_label, $ct_account_status_check;
     28    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;
    2929
    3030    $ct_options = ct_get_options();
     31    $ct_data = ct_get_data();
    3132
    3233    $show_ct_notice_trial = false;
     
    9192    }
    9293
    93     if (time() > $ct_options['next_account_status_check']) {
     94    if (time() > $ct_data['next_account_status_check']) {
    9495        $result = false;
    9596        if (function_exists('curl_init') && function_exists('json_decode') && ct_valid_key($ct_options['apikey'])) {
     
    138139               
    139140                if (isset($result['user_token'])) {
    140                     $ct_options['user_token'] = $result['user_token'];
     141                    $ct_data['user_token'] = $result['user_token'];
    141142                }
    142143            }
    143144           
    144145            // Save next status request time
    145             $ct_options['next_account_status_check'] = strtotime("+$notice_check_timeout hours", time());
    146             $ct_account_status_check = time();
    147             update_option('cleantalk_settings', $ct_options);
     146            $ct_data['next_account_status_check'] = strtotime("+$notice_check_timeout hours", time());
     147            update_option('cleantalk_data', $ct_data);
    148148        }
    149149       
     
    199199 */
    200200function ct_input_apikey() {
    201     global $ct_options, $ct_notice_online_label;
     201    global $ct_options, $ct_data, $ct_notice_online_label;
    202202   
    203203    $value = $ct_options['apikey'];
     
    222222 */
    223223function ct_input_comments_test() {
    224     global $ct_options;
     224    global $ct_options, $ct_data;
    225225   
    226226    $value = $ct_options['comments_test'];
     
    235235 */
    236236function ct_input_registrations_test() {
    237     global $ct_options;
     237    global $ct_options, $ct_data;
    238238   
    239239    $value = $ct_options['registrations_test'];
     
    248248 */
    249249function ct_input_contact_forms_test() {
    250     global $ct_options;
     250    global $ct_options, $ct_data;
    251251   
    252252    $value = $ct_options['contact_forms_test'];
     
    261261 */
    262262function ct_input_general_contact_forms_test() {
    263     global $ct_options;
     263    global $ct_options, $ct_data;
    264264   
    265265    $value = $ct_options['general_contact_forms_test'];
     
    277277 */
    278278function ct_input_remove_old_spam() {
    279     global $ct_options;
     279    global $ct_options, $ct_data;
    280280
    281281    $value = $ct_options['remove_old_spam'];
     
    335335 */
    336336function admin_notice_message(){
    337     global $show_ct_notice_trial, $show_ct_notice_renew, $show_ct_notice_online, $show_ct_notice_autokey, $ct_notice_autokey_value, $ct_plugin_name, $ct_options;
     337    global $show_ct_notice_trial, $show_ct_notice_renew, $show_ct_notice_online, $show_ct_notice_autokey, $ct_notice_autokey_value, $ct_plugin_name, $ct_options, $ct_data;
    338338
    339339    $user_token = '';
    340     if (isset($ct_options['user_token']) && $ct_options['user_token'] != '') {
    341         $user_token = '&user_token=' . $ct_options['user_token'];
     340    if (isset($ct_data['user_token']) && $ct_data['user_token'] != '') {
     341        $user_token = '&user_token=' . $ct_data['user_token'];
    342342    }
    343343
     
    397397*/
    398398function ct_valid_key($apikey = null) {
    399     global $ct_options;
     399    global $ct_options, $ct_data;
    400400    if ($apikey === null) {
    401401        $apikey = $ct_options['apikey'];
     
    533533*/
    534534function ct_update_option($option_name) {
    535     global $show_ct_notice_online, $ct_notice_online_label, $ct_notice_trial_label, $trial_notice_showtime, $ct_account_status_check, $ct_options, $ct_server_timeout;
     535    global $show_ct_notice_online, $ct_notice_online_label, $ct_notice_trial_label, $trial_notice_showtime, $ct_options, $ct_data, $ct_server_timeout;
    536536
    537537    if($option_name !== 'cleantalk_settings') {
     
    539539    }
    540540
    541     // Skip test call if the function executet during account status check
    542     if ($ct_account_status_check > 0 && time() - $ct_account_status_check < 5) {
     541    $api_key = $ct_options['apikey'];
     542    if (isset($_POST['cleantalk_settings']['apikey'])) {
     543        $api_key = trim($_POST['cleantalk_settings']['apikey']);
     544    }
     545    if (!ct_valid_key($api_key)) {
    543546        return;
    544547    }
     
    556559    $app_server_error = false;
    557560    if (function_exists('curl_init') && function_exists('json_decode')) {
    558         $api_key = $ct_options['apikey'];
    559         if (isset($_POST['cleantalk_settings']['apikey'])) {
    560             $api_key = trim($_POST['cleantalk_settings']['apikey']);
    561         }
    562        
    563         if (!ct_valid_key($api_key)) {
    564             return null;
    565         }
    566 
    567561        $url = 'https://cleantalk.org/app_notice';
    568562        $data['auth_key'] = $api_key;
  • cleantalk-spam-protect/trunk/cleantalk-common.php

    r1116005 r1116671  
    7676
    7777// Plugin's options
    78 $ct_options = null; 
    79 
    80 // Account status check last time
    81 $ct_account_status_check = 0;
     78$ct_options = null;
     79
     80// Plugin's data
     81$ct_data = null;
    8282
    8383// Post without page load
     
    132132 */
    133133function ct_base_call($params = array()) {
    134     global $wpdb, $ct_agent_version, $ct_formtime_label, $ct_options;
     134    global $wpdb, $ct_agent_version, $ct_formtime_label, $ct_options, $ct_data;
    135135
    136136    require_once('cleantalk.class.php');
     
    208208 */
    209209function get_sender_info() {
    210     global $ct_direct_post, $ct_options;
     210    global $ct_direct_post, $ct_options, $ct_data;
    211211
    212212    $php_session = session_id() != '' ? 1 : 0;
     
    284284 */
    285285function ct_get_checkjs_value($random_key = false) {
    286     global $ct_options;
     286    global $ct_options, $ct_data;
    287287
    288288    if ($random_key) {
    289         $keys = $ct_options['js_keys'];
     289        $keys = $ct_data['js_keys'];
    290290        $keys_checksum = md5(json_encode($keys));
    291291       
     
    295295
    296296            // Removing key if it's to old
    297             if (time() - $t > $ct_options['js_keys_store_days'] * 86400) {
     297            if (time() - $t > $ct_data['js_keys_store_days'] * 86400) {
    298298                unset($keys[$k]);
    299299                continue;
     
    307307       
    308308        // Get new key if the latest key is too old
    309         if (time() - $latest_key_time > $ct_options['js_key_lifetime']) {
     309        if (time() - $latest_key_time > $ct_data['js_key_lifetime']) {
    310310            $key = rand();
    311311            $keys[$key] = time();
     
    313313       
    314314        if (md5(json_encode($keys)) != $keys_checksum) {
    315             $ct_options['js_keys'] = $keys;
    316             update_option('cleantalk_settings', $ct_options);
     315            $ct_data['js_keys'] = $keys;
     316            update_option('cleantalk_data', $ct_data);
    317317        }
    318318    } else {
     
    354354        'spam_store_days' => '15', // Days before delete comments from folder Spam
    355355        'ssl_on' => 0, // Secure connection to servers
     356        'relevance_test' => 0, // Test comment for relevance
     357        'notice_api_errors' => 0, // Send API error notices to WP admin
     358    );
     359}
     360
     361/**
     362 * Inner function - Current Cleantalk data
     363 * @return  mixed[] Array of options
     364 */
     365function ct_get_data() {
     366    $data = get_option('cleantalk_data');
     367    if (!is_array($data)){
     368        $data = array();
     369    }
     370    return array_merge(ct_def_data(), (array) $data);
     371}
     372
     373/**
     374 * Inner function - Default Cleantalk data
     375 * @return  mixed[] Array of default options
     376 */
     377function ct_def_data() {
     378    return array(
    356379        'next_account_status_check' => 0, // Time label when the plugin should check account status
    357380        'user_token' => '', // User token
    358         'relevance_test' => 0, // Test comment for relevance
    359         'notice_api_errors' => 0, // Send API error notices to WP admin
    360381        'js_keys' => array(), // Keys to do JavaScript antispam test
    361382        'js_keys_store_days' => 8, // JavaScript keys store days - 8 days now
     
    389410 */
    390411function ct_feedback($hash, $message = null, $allow) {
    391     global $ct_options;
     412    global $ct_options, $ct_data;
    392413
    393414    require_once('cleantalk.class.php');
     
    426447 */
    427448function ct_send_feedback($feedback_request = null) {
    428     global $ct_options;
     449    global $ct_options, $ct_data;
    429450
    430451    if (empty($feedback_request) && isset($_SESSION['feedback_request']) && preg_match("/^[a-z0-9\;\:]+$/", $_SESSION['feedback_request'])) {
     
    468489 */
    469490function ct_do_this_hourly() {
    470     global $ct_options;
     491    global $ct_options, $ct_data;
    471492    // do something every hour
    472493
     
    474495    $ct_options = ct_get_options();
    475496
     497    if (!isset($ct_data))
     498    $ct_data = ct_get_data();
     499
    476500    delete_spam_comments();
    477501    ct_send_feedback();
     
    483507 */
    484508function delete_spam_comments() {
    485     global $pagenow, $ct_options;
     509    global $pagenow, $ct_options, $ct_data;
    486510   
    487511    if ($ct_options['remove_old_spam'] == 1) {
  • cleantalk-spam-protect/trunk/cleantalk-public.php

    r1116000 r1116671  
    66 */
    77function ct_init() {
    8     global $ct_wplp_result_label, $ct_jp_comments, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_direct_post, $ct_options;
     8    global $ct_wplp_result_label, $ct_jp_comments, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_direct_post, $ct_options, $ct_data;
    99
    1010    $ct_options = ct_get_options();
     11    $ct_data = ct_get_data();
    1112
    1213    ct_init_session();
     
    117118 */
    118119function ct_comment_form($post_id) {
    119     global $ct_options;
     120    global $ct_options, $ct_data;
    120121
    121122    if (ct_is_user_enable() === false) {
     
    214215*/
    215216function ct_frm_entries_footer_scripts($fields, $form) {
    216     global $current_user, $ct_checkjs_frm, $ct_options;
     217    global $current_user, $ct_checkjs_frm, $ct_options, $ct_data;
    217218
    218219    if ($ct_options['contact_forms_test'] == 0) {
     
    239240*/
    240241function ct_frm_validate_entry ($errors, $values) {
    241     global $wpdb, $current_user, $ct_agent_version, $ct_checkjs_frm, $ct_options;
     242    global $wpdb, $current_user, $ct_agent_version, $ct_checkjs_frm, $ct_options, $ct_data;
    242243
    243244    if ($ct_options['contact_forms_test'] == 0) {
     
    286287 */
    287288function ct_bbp_new_pre_content ($comment) {
    288     global $ct_options;
     289    global $ct_options, $ct_data;
    289290
    290291    if (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || is_user_logged_in()) {
     
    339340    // this action is called by wp-comments-post.php
    340341    // after processing WP makes redirect to post page with comment's form by GET request (see above)
    341     global $wpdb, $current_user, $comment_post_id, $ct_agent_version, $ct_comment_done, $ct_approved_request_id_label, $ct_jp_comments, $ct_options;
     342    global $wpdb, $current_user, $comment_post_id, $ct_agent_version, $ct_comment_done, $ct_approved_request_id_label, $ct_jp_comments, $ct_options, $ct_data;
    342343
    343344    if (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || $ct_comment_done) {
     
    498499 */
    499500function js_test($field_name = 'ct_checkjs', $data = null, $random_key = false) {
    500     global $ct_options;
     501    global $ct_options, $ct_data;
    501502
    502503    $checkjs = null;
     
    514515        if ($random_key) {
    515516           
    516             $keys = $ct_options['js_keys'];
     517            $keys = $ct_data['js_keys'];
    517518            if (isset($keys[$js_post_value])) {
    518519                $checkjs = 1;
     
    649650 */
    650651function ct_register_form() {
    651     global $ct_checkjs_register_form, $ct_options;
     652    global $ct_checkjs_register_form, $ct_options, $ct_data;
    652653
    653654    if ($ct_options['registrations_test'] == 0) {
     
    665666 */
    666667function ct_login_message($message) {
    667     global $errors, $ct_session_register_ok_label, $ct_options;
     668    global $errors, $ct_session_register_ok_label, $ct_options, $ct_data;
    668669
    669670    if ($ct_options['registrations_test'] != 0) {
     
    728729 */
    729730function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
    730     global $ct_agent_version, $ct_checkjs_register_form, $ct_session_request_id_label, $ct_session_register_ok_label, $bp, $ct_signup_done, $ct_formtime_label, $ct_negative_comment, $ct_options;
     731    global $ct_agent_version, $ct_checkjs_register_form, $ct_session_request_id_label, $ct_session_register_ok_label, $bp, $ct_signup_done, $ct_formtime_label, $ct_negative_comment, $ct_options, $ct_data;
    731732
    732733    // Go out if a registrered user action
     
    873874 */
    874875function ct_grunion_contact_form_field_html($r, $field_label) {
    875     global $ct_checkjs_jpcf, $ct_jpcf_patched, $ct_jpcf_fields, $ct_options;
     876    global $ct_checkjs_jpcf, $ct_jpcf_patched, $ct_jpcf_fields, $ct_options, $ct_data;
    876877
    877878    if ($ct_options['contact_forms_test'] == 1 && $ct_jpcf_patched === false && preg_match("/[text|email]/i", $r)) {
     
    896897 */
    897898function ct_contact_form_is_spam($form) {
    898     global $ct_checkjs_jpcf, $ct_options;
     899    global $ct_checkjs_jpcf, $ct_options, $ct_data;
    899900
    900901    if ($ct_options['contact_forms_test'] == 0) {
     
    958959 */
    959960function ct_wpcf7_form_elements($html) {
    960     global $wpdb, $current_user, $ct_checkjs_cf7, $ct_options;
     961    global $wpdb, $current_user, $ct_checkjs_cf7, $ct_options, $ct_data;
    961962
    962963    if ($ct_options['contact_forms_test'] == 0) {
     
    973974 */
    974975function ct_wpcf7_spam($param) {
    975     global $wpdb, $current_user, $ct_agent_version, $ct_checkjs_cf7, $ct_cf7_comment, $ct_options;
     976    global $wpdb, $current_user, $ct_agent_version, $ct_checkjs_cf7, $ct_cf7_comment, $ct_options, $ct_data;
    976977
    977978    if (WPCF7_VERSION >= '3.0.0') {
     
    10751076 */
    10761077function ct_si_contact_form_validate($form_errors = array(), $form_id_num = 0) {
    1077     global $ct_options;
     1078    global $ct_options, $ct_data;
    10781079
    10791080    if (!empty($form_errors))
     
    11511152*/
    11521153function ct_check_wplp(){
    1153     global $ct_wplp_result_label, $ct_options;
     1154    global $ct_wplp_result_label, $ct_options, $ct_data;
    11541155    if (!isset($_COOKIE[$ct_wplp_result_label])) {
    11551156        // First AJAX submit of WPLP form
     
    12121213 */
    12131214function ct_s2member_registration_test() {
    1214     global $ct_agent_version, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_options;
     1215    global $ct_agent_version, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_options, $ct_data;
    12151216   
    12161217    if ($ct_options['registrations_test'] == 0) {
Note: See TracChangeset for help on using the changeset viewer.