Plugin Directory

Changeset 3125336


Ignore:
Timestamp:
07/25/2024 01:54:26 PM (19 months ago)
Author:
simpleform
Message:

refactor: code rewritten following the coding standards
fix: general errors

Location:
simpleform-akismet
Files:
53 added
7 edited

Legend:

Unmodified
Added
Removed
  • simpleform-akismet/trunk/README.txt

    r2712284 r3125336  
    11=== SimpleForm Akismet ===
    2 Contributors: simpleform
    3 Donate link: https://wpsform.com/
    4 Tags: contact form, spam manager, akismet, anti-spam, simpleform addon, spam, form
    5 Requires at least: 5.6
    6 Tested up to: 5.9
    7 Requires PHP: 5.6
    8 Stable tag: 1.1.2
     2Contributors: simpleform, gianpic
     3Donate link: paypal.me/simpleformdonation
     4Tags: contact form, spam manager, akismet, anti-spam, simpleform addon
     5Requires at least: 5.9
     6Tested up to: 6.6
     7Requires PHP: 7.4
     8Stable tag: 1.2.0
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    6060== Changelog ==
    6161
     62= 1.2.0 (25 July 2024) =
     63* Changed: code refactoring
     64* Added: compatibility with SimpleForm 2.2.0 version
     65* Fixed: general errors
     66
    6267= 1.1.2 (20 April 2022) =
    6368* Added: compatibility with SimpleForm 2.1.7 version
     
    7681== Demo ==
    7782 
    78 You don’t know SimpleForm yet? Check out our [Demo](https://wpsform.com/demo/) and find out how it works.
     83You don’t know SimpleForm yet? Check out our [Demo]() and find out how it works.
  • simpleform-akismet/trunk/admin/index.php

    r2459305 r3125336  
    1 <?php // Silence is golden
     1<?php
     2/**
     3 * Silence is golden.
     4 *
     5 * @package SimpleForm Akismet/admin
     6 */
  • simpleform-akismet/trunk/admin/js/admin.js

    r2537256 r3125336  
     1/**
     2 * JavaScript code delegated to the backend functionality of the plugin.
     3 *
     4 * @package SimpleForm Akismet
     5 * @subpackage SimpleForm Akismet/admin
     6 */
     7
    18(function( $ ) {
    29    'use strict';
    3    
    4      $( window ).load(function() {
    510
    6        $("#akismet").on("click", function() {
    7          if($(this).prop('checked') == true) {
    8            $('.trakismet').removeClass('unseen');
    9            $('#tdakismet').removeClass('last');
    10            if( $('#blocked-message').prop('checked') == true){
    11                $('.trspammark').addClass('unseen');
    12                $('#tdakismetaction').addClass('last');
    13            }
    14            else {
    15                $('.trspammark').removeClass('unseen');
    16                $('#tdakismetaction').removeClass('last');
    17            }           
    18          }
    19          else {
    20            $('.trakismet').addClass('unseen');
    21            $('#tdakismet').addClass('last');
    22          }
    23        });
    24        
    25        $("#blocked-message").on("click", function() {
    26          if($(this).prop('checked') == true) {
    27              $('.trspammark').addClass('unseen');
    28              $('#tdakismetaction').addClass('last');
    29          }
    30          else {
    31              $('.trspammark').removeClass('unseen');
    32              $('#tdakismetaction').removeClass('last');
    33          }
    34        });
    35        
    36        $("#flagged-message").on("click", function() {
    37          if($(this).prop('checked') == true) {
    38              $('.trspammark').removeClass('unseen');
    39              $('#tdakismetaction').removeClass('last');
    40          }
    41          else {
    42              $('.trspammark').addClass('unseen');
    43              $('#tdakismetaction').addClass('last');
    44          }
    45        });
     11    $( window ).on(
     12        'load',
     13        function() {
    4614
    47        $("#blocked-message").on("click", function() { $('#akismet-action-notes').addClass('invisible'); });
    48        $("#flagged-message").on("click", function() { $('#akismet-action-notes').removeClass('invisible'); });
     15            $( '#akismet' ).on(
     16                'click',
     17                function() {
     18                    if ( $( this ).prop( 'checked' ) == true ) {
     19                        $( '.trakismet' ).removeClass( 'unseen' );
     20                        $( '#tdakismet' ).removeClass( 'last' );
     21                        if ( $( '#blocked-message' ).prop( 'checked' ) == true ) {
     22                            $( '.trspammark' ).addClass( 'unseen' );
     23                            $( '#tdakismetaction' ).addClass( 'last' );
     24                        } else {
     25                            $( '.trspammark' ).removeClass( 'unseen' );
     26                            $( '#tdakismetaction' ).removeClass( 'last' );
     27                        }
     28                    } else {
     29                        $( '.trakismet' ).addClass( 'unseen' );
     30                        $( '#tdakismet' ).addClass( 'last' );
     31                    }
     32                }
     33            );
    4934
    50      });
     35            $( '#blocked-message' ).on(
     36                'click',
     37                function() {
     38                    $( '#akismet_action_notes' ).addClass( 'invisible' );
     39                    if ( $( this ).prop( 'checked' ) == true ) {
     40                        $( '.trspammark' ).addClass( 'unseen' );
     41                        $( '#tdakismetaction' ).addClass( 'last' );
     42                    } else {
     43                        $( '.trspammark' ).removeClass( 'unseen' );
     44                        $( '#tdakismetaction' ).removeClass( 'last' );
     45                    }
     46                }
     47            );
     48
     49            $( '#flagged-message' ).on(
     50                'click',
     51                function() {
     52                    $( '#akismet_action_notes' ).removeClass( 'invisible' );
     53                    if ( $( this ).prop( 'checked' ) == true ) {
     54                        $( '.trspammark' ).removeClass( 'unseen' );
     55                        $( '#tdakismetaction' ).removeClass( 'last' );
     56                    } else {
     57                        $( '.trspammark' ).addClass( 'unseen' );
     58                        $( '#tdakismetaction' ).addClass( 'last' );
     59                    }
     60                }
     61            );
     62
     63        }
     64    );
    5165
    5266})( jQuery );
  • simpleform-akismet/trunk/includes/index.php

    r2459305 r3125336  
    1 <?php // Silence is golden
     1<?php
     2/**
     3 * Silence is golden.
     4 *
     5 * @package SimpleForm Akismet/includes
     6 */
  • simpleform-akismet/trunk/index.php

    r2459305 r3125336  
    1 <?php // Silence is golden
     1<?php
     2/**
     3 * Silence is golden.
     4 *
     5 * @package SimpleForm Akismet
     6 */
  • simpleform-akismet/trunk/simpleform-akismet.php

    r2712284 r3125336  
    11<?php
    2 
    32/**
    43 *
    5  * Plugin Name:  SimpleForm Akismet
    6  * Description:  Do you get junk emails through your form? This SimpleForm addon helps prevent spam submission. To work properly you need an Akismet API Key.
    7  * Version:      1.1.2
    8  * Author:       WPSForm Team
    9  * Author URI:   https://wpsform.com
    10  * License:      GPL-2.0+
    11  * License URI:  http://www.gnu.org/licenses/gpl-2.0.txt
    12  * Text Domain:  simpleform-akismet
    13  * Domain Path:  /languages
     4 * Plugin Name:       SimpleForm Akismet
     5 * Description:       Do you get junk emails through your form? This SimpleForm addon helps prevent spam submission. To work properly you need an Akismet API Key.
     6 * Version:           1.2.0
     7 * Requires at least: 5.9
     8 * Requires PHP:      7.4
     9 * Author:            SimpleForm Team
     10 * License:           GPL-2.0+
     11 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     12 * Text Domain:       simpleform-akismet
     13 * Requires Plugins:  simpleform
    1414 *
     15 * @package           SimpleForm Akismet
    1516 */
    1617
    17 if ( ! defined( 'WPINC' ) ) { die; }
     18defined( 'WPINC' ) || exit;
    1819
    1920/**
    2021 * Plugin constants.
    2122 *
    22  * @since    1.0
     23 * @since 1.0.0
    2324 */
    24  
    25 define( 'SIMPLEFORM_AKISMET_NAME', 'SimpleForm Akismet' ); 
    26 define( 'SIMPLEFORM_AKISMET_VERSION', '1.1.2' );
    27 define( 'SIMPLEFORM_AKISMET_DB_VERSION', '1.1.2' );
     25
     26define( 'SIMPLEFORM_AKISMET_NAME', 'SimpleForm Akismet' );
     27define( 'SIMPLEFORM_AKISMET_VERSION', '1.2.0' );
     28define( 'SIMPLEFORM_AKISMET_DB_VERSION', '1.2.0' );
    2829define( 'SIMPLEFORM_AKISMET_BASENAME', plugin_basename( __FILE__ ) );
    2930define( 'SIMPLEFORM_AKISMET_PATH', plugin_dir_path( __FILE__ ) );
    30 if ( ! defined('SIMPLEFORM_VERSION_REQUIRED') ) { define( 'SFORM_VERSION_REQUIRED', '2.1.7' ); }
     31if ( ! defined( 'SIMPLEFORM_VERSION_REQUIRED' ) ) {
     32    define( 'SIMPLEFORM_VERSION_REQUIRED', '2.2.0' );
     33}
    3134
    3235/**
    3336 * The code that runs during plugin activation.
    3437 *
    35  * @since    1.0
     38 * @since 1.0.0
     39 *
     40 * @param bool $network_wide Whether to enable the plugin for all sites in the network
     41 *                           or just the current site. Multisite only. Default false.
     42 *
     43 * @return void
    3644 */
    37  
    38 function activate_simpleform_akismet($network_wide) {
    39     require_once plugin_dir_path( __FILE__ ) . 'includes/class-activator.php';
    40     SimpleForm_Akismet_Activator::activate($network_wide);
     45function activate_simpleform_akismet( $network_wide ) {
     46    require_once plugin_dir_path( __FILE__ ) . 'includes/class-simpleform-akismet-activator.php';
     47    SimpleForm_Akismet_Activator::activate( $network_wide );
    4148}
    4249
    43 /** 
    44  * Change settings when a new site into a network is created.
     50/**
     51 * Edit settings when a new site into a network is created.
    4552 *
    46  * @since    1.0
    47  */
    48 
    49 function simpleform_akismet_on_create_blog($params) {
    50     require_once plugin_dir_path( __FILE__ ) . 'includes/class-activator.php';
    51     SimpleForm_Akismet_Activator::on_create_blog($params);
     53 * @since 1.0.0
     54 *
     55 * @param WP_Site $new_site New site object.
     56 *
     57 * @return void
     58 */
     59function simpleform_akismet_network( $new_site ) {
     60    require_once plugin_dir_path( __FILE__ ) . 'includes/class-simpleform-akismet-activator.php';
     61    SimpleForm_Akismet_Activator::on_create_blog( $new_site );
    5262}
    5363
    54 add_action( 'wp_insert_site', 'simpleform_akismet_on_create_blog');
     64add_action( 'wp_insert_site', 'simpleform_akismet_network' );
    5565
    5666/**
    5767 * The code that runs during plugin deactivation.
    5868 *
    59  * @since    1.0
     69 * @since 1.0.0
     70 *
     71 * @return void
    6072 */
    61  
    6273function deactivate_simpleform_akismet() {
    63     require_once plugin_dir_path( __FILE__ ) . 'includes/class-deactivator.php';
     74    require_once plugin_dir_path( __FILE__ ) . 'includes/class-simpleform-akismet-deactivator.php';
    6475    SimpleForm_Akismet_Deactivator::deactivate();
    6576}
     
    7182 * The core plugin class.
    7283 *
    73  * @since    1.0
     84 * @since 1.0.0
    7485 */
    75  
    76 require plugin_dir_path( __FILE__ ) . '/includes/class-core.php';
     86
     87require plugin_dir_path( __FILE__ ) . '/includes/class-simpleform-akismet.php';
    7788
    7889/**
    7990 * Begins execution of the plugin.
    8091 *
    81  * @since    1.0
     92 * @since 1.0.0
     93 *
     94 * @return void
    8295 */
    83  
    84 function run_SimpleForm_Akismet() {
     96function run_simpleform_akismet() {
    8597
    8698    $plugin = new SimpleForm_Akismet();
    8799    $plugin->run();
    88 
    89100}
    90101
    91 run_SimpleForm_Akismet();
     102run_simpleform_akismet();
  • simpleform-akismet/trunk/uninstall.php

    r2508855 r3125336  
    11<?php
    2 
    32/**
    4  * Fired when the plugin is uninstalled.
     3 * File delegated to the uninstalling the plugin.
    54 *
    6  * @since      1.0
     5 * @package SimpleForm Akismet
    76 */
    87
    9 // Prevent direct access. Exit if file is not called by WordPress.
    10 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    11     exit;
     8defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
     9
     10// Detect the simpleform plugin installation.
     11$plugin_file = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR . '/simpleform/simpleform.php' : '';
     12
     13if ( file_exists( $plugin_file ) ) {
     14
     15    global $wpdb;
     16
     17    if ( ! is_multisite() ) {
     18
     19        $settings = (array) get_option( 'sform_settings', array() );
     20
     21        // Detect the parent plugin activation.
     22        if ( $settings ) {
     23
     24            if ( isset( $settings['deletion_data'] ) && $settings['deletion_data'] ) {
     25
     26                $submissions_table = $wpdb->prefix . 'sform_submissions';
     27                $wpdb->query( "ALTER TABLE {$submissions_table} DROP COLUMN spam_parameters" ); // phpcs:ignore
     28
     29            }
     30
     31            $addon_settings = array(
     32                'akismet'        => $settings['akismet'],
     33                'akismet_action' => $settings['akismet_action'],
     34                'spam_mark'      => $settings['spam_mark'],
     35                'akismet_error'  => $settings['akismet_error'],
     36            );
     37
     38            $new_settings = array_diff_key( $settings, $addon_settings );
     39            update_option( 'sform_settings', $new_settings );
     40
     41            $shortcodes_table = $wpdb->prefix . 'sform_shortcodes';
     42
     43            if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $shortcodes_table ) ) === $shortcodes_table ) { // phpcs:ignore         
     44
     45                $forms = $wpdb->get_col( "SELECT id FROM {$wpdb->prefix}sform_shortcodes WHERE id != '1'" ); // phpcs:ignore
     46
     47                foreach ( $forms as $form ) {
     48
     49                    $form_settings = (array) get_option( 'sform_' . $form . '_settings', array() );
     50
     51                    if ( $form_settings ) {
     52
     53                        $addon_settings = array(
     54                            'akismet'        => $form_settings['akismet'],
     55                            'akismet_action' => $form_settings['akismet_action'],
     56                            'spam_mark'      => $form_settings['spam_mark'],
     57                            'akismet_error'  => $form_settings['akismet_error'],
     58                        );
     59
     60                        $new_form_settings = array_diff_key( $form_settings, $addon_settings );
     61                        update_option( 'sform_' . $form . '_settings', $new_form_settings );
     62
     63                    }
     64                }
     65            }
     66        }
     67
     68        delete_option( 'sform_aks_db_version' );
     69
     70    } else {
     71
     72        $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); // phpcs:ignore
     73        $original_blog_id = get_current_blog_id();
     74
     75        foreach ( $blog_ids as $blogid ) {
     76
     77            switch_to_blog( $blogid );
     78            $settings = (array) get_option( 'sform_settings', array() );
     79
     80            // Detect the parent plugin activation.
     81            if ( $settings ) {
     82
     83                if ( isset( $settings['deletion_data'] ) && $settings['deletion_data'] ) {
     84
     85                    $submissions_table = $wpdb->prefix . 'sform_submissions';
     86                    $wpdb->query( "ALTER TABLE {$submissions_table} DROP COLUMN spam_parameters" ); // phpcs:ignore
     87
     88                }
     89
     90                $addon_settings = array(
     91                    'akismet'        => $settings['akismet'],
     92                    'akismet_action' => $settings['akismet_action'],
     93                    'spam_mark'      => $settings['spam_mark'],
     94                    'akismet_error'  => $settings['akismet_error'],
     95                );
     96
     97                $new_settings = array_diff_key( $settings, $addon_settings );
     98                update_option( 'sform_settings', $new_settings );
     99
     100                $shortcodes_table = $wpdb->prefix . 'sform_shortcodes';
     101
     102                if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $shortcodes_table ) ) === $shortcodes_table ) { // phpcs:ignore         
     103
     104                    $forms = $wpdb->get_col( "SELECT id FROM {$wpdb->prefix}sform_shortcodes WHERE id != '1'" ); // phpcs:ignore
     105
     106                    foreach ( $forms as $form ) {
     107
     108                        $form_settings = (array) get_option( 'sform_' . $form . '_settings', array() );
     109
     110                        if ( $form_settings ) {
     111
     112                            $addon_settings = array(
     113                                'akismet'        => $form_settings['akismet'],
     114                                'akismet_action' => $form_settings['akismet_action'],
     115                                'spam_mark'      => $form_settings['spam_mark'],
     116                                'akismet_error'  => $form_settings['akismet_error'],
     117                            );
     118
     119                            $new_form_settings = array_diff_key( $form_settings, $addon_settings );
     120                            update_option( 'sform_' . $form . '_settings', $new_form_settings );
     121
     122                        }
     123                    }
     124                }
     125            }
     126
     127            delete_option( 'sform_aks_db_version' );
     128
     129        }
     130
     131        switch_to_blog( $original_blog_id );
     132
     133    }
     134} else {
     135
     136    global $wpdb;
     137    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'sform_submissions' ); // phpcs:ignore
     138    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'sform_shortcodes' ); // phpcs:ignore
     139    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'sform\_%'" ); // phpcs:ignore
     140    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'sform\-%'" ); // phpcs:ignore
     141    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '%\_sform\_%'" ); // phpcs:ignore
     142
    12143}
    13 
    14 // Detect core plugin
    15 $plugin_file = 'simpleform/simpleform.php';
    16 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
    17 
    18  if ( !is_multisite() )  {
    19   $settings = get_option('sform_settings');
    20   if ( $settings ) {
    21   if ( isset( $settings['deletion_data'] ) && esc_attr($settings['deletion_data']) == 'true' ) {
    22   global $wpdb;
    23   $prefix = $wpdb->prefix;
    24   $submissions_table = $prefix . 'sform_submissions';
    25   $wpdb->query("ALTER TABLE $submissions_table DROP COLUMN spam_parameters");
    26   $sform_addon_settings = array( 'akismet' => $settings['akismet'], 'akismet_action' => $settings['akismet_action'], 'spam_mark' => $settings['spam_mark'], 'akismet_error' => $settings['akismet_error'] );
    27   $sform_core_settings = array_diff_key($settings,$sform_addon_settings);
    28   update_option('sform_settings', $sform_core_settings);
    29   $shortcodes_table = $wpdb->prefix . 'sform_shortcodes';
    30   $ids = $wpdb->get_col("SELECT id FROM `$shortcodes_table` WHERE id != '1'"); 
    31   if ( $ids ) {
    32     foreach ( $ids as $id ) {
    33     $form_settings = get_option('sform_'.$id.'_settings');
    34     if ( $form_settings != false ) {
    35        $form_settings_nv = array_diff_key($form_settings,$sform_addon_settings);
    36        update_option('sform_'.$id.'_settings', $form_settings_nv);
    37     }
    38     }
    39   }
    40   }
    41   }
    42   else {
    43    global $wpdb;
    44    $prefix = $wpdb->prefix;
    45    $submissions_table = $prefix . 'sform_submissions';
    46    $wpdb->query("ALTER TABLE $submissions_table DROP COLUMN spam_parameters");   
    47   } 
    48   delete_option( 'sform_aks_db_version' );
    49   }
    50  else {
    51     global $wpdb;
    52     $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
    53     $original_blog_id = get_current_blog_id();
    54     foreach ( $blog_ids as $blog_id ) {
    55       switch_to_blog( $blog_id );
    56       $settings = get_option('sform_settings');
    57       if ( $settings ) {
    58         if ( isset( $settings['deletion_data'] ) && esc_attr($settings['deletion_data']) == 'true' ) {
    59         $prefix = $wpdb->prefix;
    60         $submissions_table = $prefix . 'sform_submissions';
    61         $wpdb->query("ALTER TABLE $submissions_table DROP spam_parameters");   
    62         $sform_addon_settings = array( 'akismet' => $settings['akismet'], 'akismet_action' => $settings['akismet_action'], 'akismet_error' => $settings['akismet_error'] );
    63         $sform_core_settings = array_diff_key($settings,$sform_addon_settings);
    64         update_option('sform_settings', $sform_core_settings);
    65         $shortcodes_table = $wpdb->prefix . 'sform_shortcodes';
    66         $ids = $wpdb->get_col("SELECT id FROM `$shortcodes_table` WHERE id != '1'");   
    67         if ( $ids ) {
    68         foreach ( $ids as $id ) {
    69         $form_settings = get_option('sform_'.$id.'_settings');
    70         if ( $form_settings != false ) {
    71         $form_settings_nv = array_diff_key($form_settings,$sform_addon_settings);
    72         update_option('sform_'.$id.'_settings', $form_settings_nv);
    73         }
    74         }
    75         }
    76         }
    77       }
    78       else {
    79         $prefix = $wpdb->prefix;
    80         $submissions_table = $prefix . 'sform_submissions';
    81         $wpdb->query("ALTER TABLE $submissions_table DROP spam_parameters");   
    82       } 
    83       delete_option( 'sform_aks_db_version' );
    84     }
    85     switch_to_blog( $original_blog_id );
    86  }
    87 }
    88 else {
    89   global $wpdb;
    90   $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'sform_submissions' );
    91   $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'sform\_%'" );
    92   $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'sform\-%'" );
    93   $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '%\_sform\_%'" );
    94 }
Note: See TracChangeset for help on using the changeset viewer.