Plugin Directory

Changeset 2646847


Ignore:
Timestamp:
12/20/2021 03:10:48 PM (3 years ago)
Author:
neuropassenger
Message:

Filling time corrections, Flamingo Inbound

Location:
bs-spam-protector/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • bs-spam-protector/trunk/README.txt

    r2638554 r2646847  
    55Requires at least: 5.7.2
    66Tested up to: 5.8.2
    7 Stable tag: 1.3.4
     7Stable tag: 1.6.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1717
    1818== Changelog ==
     19
     20= 1.6.0 =
     21* SPAM Protector information is now stored in the Flamingo 'meta' column.
     22
     23= 1.5.0 =
     24* More accurate calculation of the filling time for the textarea field.
     25
     26= 1.4.0 =
     27* Setting for the time interval for filling out the form.
    1928
    2029= 1.3.4 =
  • bs-spam-protector/trunk/admin/class-bs-spam-protector-admin.php

    r2576368 r2646847  
    131131        );
    132132
     133        register_setting(
     134            'bs_spam_protector_general',
     135            'bs_spam_protector_expiration_interval'
     136        );
     137
    133138        add_settings_section(
    134139            'bs_spam_protector_general',
     
    153158            'bs_spam_protector_general'
    154159        );
     160
     161        add_settings_field(
     162            'bs_spam_protector_expiration_interval',
     163            'Expiration interval',
     164            array( $this, 'show_expiration_interval_field' ),
     165            $this->plugin_name,
     166            'bs_spam_protector_general'
     167        );
    155168    }
    156169
     
    170183    }
    171184
     185    function show_expiration_interval_field() {
     186        $expiration_interval = get_option( 'bs_spam_protector_expiration_interval' );
     187        echo "<input type='number' class='regular-text bs_spam_protector_expiration_interval' name='bs_spam_protector_expiration_interval' placeholder='12' value='" . (esc_attr( $expiration_interval ) ?? '') . "'>";
     188        echo "<p>The allowed time interval <strong>in hours</strong> between opening and submitting a form.</p>";
     189    }
     190
    172191}
  • bs-spam-protector/trunk/bs-spam-protector.php

    r2638554 r2646847  
    1616 * Plugin Name:       BS SPAM Protector
    1717 * Description:       This plugin protects Contact Form 7 from spam.
    18  * Version:           1.3.4
     18 * Version:           1.6.0
    1919 * Author:            Oleg Sokolov
    2020 * Author URI:        https://neuropassenger.ru
     
    3535 * Rename this for your plugin and update it as you release new versions.
    3636 */
    37 define( 'BS_SPAM_PROTECTOR_VERSION', '1.3.4' );
     37define( 'BS_SPAM_PROTECTOR_VERSION', '1.6.0' );
    3838
    3939/**
  • bs-spam-protector/trunk/includes/class-bs-spam-protector-activator.php

    r2549718 r2646847  
    3535        $secret_key = hash_hmac( 'sha256', $time, date( 'F', $time ) );
    3636        update_option( 'bs_spam_protector_secret_key', $secret_key );
     37        update_option( 'bs_spam_protector_expiration_interval', 12 );
    3738    }
    3839
  • bs-spam-protector/trunk/includes/class-bs-spam-protector.php

    r2576506 r2646847  
    186186        $this->loader->add_filter( 'wpcf7_spam', $plugin_public, 'is_spam_submission' );
    187187
     188        //$this->loader->add_action( 'load-flamingo_page_flamingo_inbound', $plugin_public, 'add_spam_protector_flamingo_meta_box' );
     189        $this->loader->add_filter( 'flamingo_add_inbound', $plugin_public, 'prepare_data_for_flamingo_inbound' );
     190
    188191    }
    189192
  • bs-spam-protector/trunk/public/class-bs-spam-protector-public.php

    r2638554 r2646847  
    9898
    9999        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/bs-spam-protector-public.js', array( 'jquery' ), false );
     100        $expiration_interval = get_option( 'bs_spam_protector_expiration_interval' );
    100101        wp_localize_script( $this->plugin_name, 'bs_vars', array(
    101102            'nonce'       =>  wp_create_nonce( 'cf7_bs_spam_protector' ),
    102             'expiration'  =>  time() + 60 * 120,
     103            'expiration'  =>  time() + 60 * 60 * $expiration_interval,
    103104            'ajaxUrl'     =>  admin_url( 'admin-ajax.php' ),
    104105        ) );
     
    116117            // Before sanitizing
    117118            Bs_Spam_Protector_Functions::logit(array(
    118                 'nonce'          =>  $_POST['nonce'],
     119                'nonce'         =>  $_POST['nonce'],
    119120                'form_id'       =>  $_POST['form_id'],
    120121                'expiration'    =>  $_POST['expiration'],
     
    161162
    162163    public function ajax_get_validation_meta() {
    163         $expiration = time() + 60 * 120;
     164        $expiration_interval = get_option( 'bs_spam_protector_expiration_interval' );
     165        $expiration = time() + 60 * 60 * $expiration_interval;
    164166        $nonce = wp_create_nonce( 'cf7_bs_spam_protector' );
    165167
     
    178180        $secret_key = get_option( 'bs_spam_protector_secret_key' );
    179181        $submission = WPCF7_Submission::get_instance();
    180         $container_post_id = $submission->get_meta('container_post_id');
     182        $container_post_id = $submission->get_meta( 'container_post_id' );
    181183        $log_flag = get_option( 'bs_spam_protector_log_checkbox', false );
    182184
     
    254256
    255257            // Form filled out too quickly
    256             // TODO: interval settings
    257258        } elseif ( $filling_form_time < $expected_filling_form_time ) {
    258259            $submission->add_spam_log(array(
    259260                'agent' => 'bs_spam_protector',
    260                 'reason' => "Form filled out too quickly (In " . $filling_form_time . " second(s), " . $expected_filling_form_time . " second(s) expected.)",
     261                'reason' => "Form filled out too quickly (In " . $filling_form_time . " second(s), " . $expected_filling_form_time . " second(s) expected).",
    261262            ));
    262263
     
    299300    function get_filling_form_time() {
    300301        $expiration = intval( $_POST['bs_hf_expiration'] );
    301         $start_filling_form_timestamp = $expiration - 60 * 120; // TODO: make only one setting value, search: '60 * 120* in the code
     302        $expiration_interval = get_option( 'bs_spam_protector_expiration_interval' );
     303        $start_filling_form_timestamp = $expiration - 60 * 60 * $expiration_interval;
    302304        $finish_filling_form_timestamp = time() - 2; // 2 - time for network delays
    303305
     
    327329        $posted_data = WPCF7_Submission::get_instance()->get_posted_data();
    328330        // Let's remove tech fields
    329         unset($posted_data['bs_hf_nonce']);
    330         unset($posted_data['bs_hf_expiration']);
    331         unset($posted_data['bs_hf_validation_key']);
    332         unset($posted_data['bs_hf_form_id']);
    333 
    334         $container_post_id = WPCF7_Submission::get_instance()->get_meta('container_post_id');
     331        unset( $posted_data['bs_hf_nonce'] );
     332        unset( $posted_data['bs_hf_expiration'] );
     333        unset( $posted_data['bs_hf_validation_key'] );
     334        unset( $posted_data['bs_hf_form_id'] );
    335335
    336336        foreach ( $posted_data as $field_name => $field_value ) {
     
    349349                // Separate time computation for files, because a user can pass an empty file field
    350350                case 'file':
    351                     $expected_filling_field_time = $this->get_expected_filling_time_for_file_field_type( $field_name, $container_post_id );
     351                    $expected_filling_field_time = $this->get_expected_filling_time_for_file_field_type( $field_name );
     352                    break;
     353                case 'textarea':
     354                    $expected_filling_field_time = $this->get_expected_filling_time_for_textarea_field_type( $field_name );
    352355                    break;
    353356                default:
     
    380383    }
    381384
    382     function get_expected_filling_time_for_file_field_type( $field_name, $container_post_id ) {
     385    function get_expected_filling_time_for_file_field_type( $field_name ) {
    383386        if ( ! isset( $_FILES[$field_name] ) ) {
    384387            return 0;
     
    393396    }
    394397
     398    function get_expected_filling_time_for_textarea_field_type( $field_name ) {
     399        $textarea_content = $_POST[$field_name];
     400        $content_size = mb_strlen( $textarea_content );
     401        $expected_time = round( $content_size / 10 );
     402
     403        return $expected_time;
     404    }
     405
     406    function prepare_data_for_flamingo_inbound( $args ) {
     407        // Let's save SPAM Protector fields to the meta section
     408        $args['meta']['bs_hf_nonce'] = $args['fields']['bs_hf_nonce'];
     409        $args['meta']['bs_hf_expiration'] = $args['fields']['bs_hf_expiration'];
     410        $args['meta']['bs_hf_validation_key'] = $args['fields']['bs_hf_validation_key'];
     411        $args['meta']['bs_hf_form_id'] = $args['fields']['bs_hf_form_id'];
     412
     413        $filling_form_time = $this->get_filling_form_time();
     414        $expected_filling_form_time = $this->get_min_expected_filling_form_time();
     415        $args['meta']['filling_time'] = $filling_form_time;
     416        $args['meta']['expected_filling_time'] = $expected_filling_form_time;
     417
     418        unset( $args['fields']['bs_hf_nonce'] );
     419        unset( $args['fields']['bs_hf_expiration'] );
     420        unset( $args['fields']['bs_hf_validation_key'] );
     421        unset( $args['fields']['bs_hf_form_id'] );
     422
     423        return $args;
     424    }
     425
    395426}
Note: See TracChangeset for help on using the changeset viewer.