Plugin Directory

Changeset 3114115


Ignore:
Timestamp:
07/08/2024 09:12:35 AM (21 months ago)
Author:
hatul
Message:

v1.0 - Add support to Elementor form and contact form 7 (cf7)

Location:
en-spam
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • en-spam/trunk/README.md

    r3112188 r3114115  
    11# En Spam #
    22**Contributors:** hatul
     3
    34**Donate link:** https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4HTHWS3LGDDPJ
     5
    46**Tags:** anti-spam, antispam, block spam, bot, comment, comment spam, comments, spam, Spam Free, spambot, hebrew
     7
    58**Requires at least:** 2.0
     9
    610**Tested up to:** 6.6
    7 **Stable tag:** 0.7.2
     11
     12**Stable tag:** 1.0
    813
    914Block spam with cookies and JavaScript.
     
    1621
    1722The plugin is transparent to your visitors, only bots will be blocked.
     23
     24We protect Elementor Pro and Contact Form 7 (cf7) forms and default comments of WordPress.
    1825
    1926You can see how many spambots blocked in dashboard widget.
     
    2936
    3037## Changelog ##
     38= 1.0 =
     39* Add support to Elementor form and contact form 7 (cf7)
    3140### 0.7.2 ###
    3241* Add support to old PHP versions
  • en-spam/trunk/default.pot

    r1091706 r3114115  
    3636msgid "Blocked Spambots by En Spam"
    3737msgstr ""
     38
     39msgid "Enable JavaScript and cookies"
     40msgstr ""
  • en-spam/trunk/en-spam-he_IL.po

    r1091706 r3114115  
    3636msgid "Blocked Spambots by En Spam"
    3737msgstr "כמה בוטים en spam חסם"
     38
     39#: /srv/http/wp/wp-content/plugins/en-spam/en-spam.php:75
     40msgid "Enable JavaScript and cookies"
     41msgstr "יש לאפשר JavaScript ועוגיות"
  • en-spam/trunk/en-spam.js

    r1090570 r3114115  
    1 function setCookie(c_name,value,exdays) {
    2     var exdate=new Date();
    3     exdate.setDate(exdate.getDate() + exdays);
    4     var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()) + "; path=/";
    5     document.cookie=c_name + "=" + c_value;
     1function setCookie(cname, cvalue, exdays) {
     2    const d = new Date();
     3    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
     4    const expires = "expires=" + d.toUTCString();
     5    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
    66}
    77
    8 function getCookie(c_name) {
    9     var i,x,y,ARRcookies=document.cookie.split(";");
    10     for (i=0;i<ARRcookies.length;i++) {
    11         x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
    12         y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
    13         x=x.replace(/^\s+|\s+$/g,"");
    14             if (x==c_name) {
    15                 return unescape(y);
    16             }
    17     }
    18 }
    19 
    20 jQuery(document).ready(function( $ ) {
    21     $('#commentform').submit(function(){
    22         var hash = data.hash;
    23         if (!getCookie('wordpress_logged_in_' + hash) && !getCookie('comment_author_email_' + hash)) {
    24             setCookie('comment_author_email_' + hash, $('#email').val(), 30);
    25         }
    26     });
    27 });
     8setCookie('en_spam_validate', 1, 30);
  • en-spam/trunk/en-spam.php

    r2949086 r3114115  
    44Description: Block Spam with Cookies and JavaScript Filtering.
    55Plugin URI: http://hatul.info/en-spam
    6 Version: 0.7.3
     6Version: 1.0
    77Author: Hatul
    88Author URI: http://hatul.info
     
    1010*/
    1111
     12load_plugin_textdomain('en-spam', false, dirname( plugin_basename( __FILE__ ) ) );
     13
    1214add_filter('preprocess_comment','ens_check_comment');
    1315function ens_check_comment($comment){
    14     if ((isset($_COOKIE['comment_author_email_' . COOKIEHASH]))
    15       || (is_user_logged_in())
    16       || ($_POST['code'] == get_option('ens_code'))) {
     16    if (ens_valid_no_bot() || wp_verify_nonce($_POST['code'], 'en-spam')) {
    1717        $comment['comment_content'] = stripcslashes($comment['comment_content']);
    1818        return $comment;
     
    2222
    2323function ens_block_page(){
    24     $counter = get_option('ens_counter', 0) + 1;
    25     update_option('ens_counter', $counter);
     24    ens_count_block();
    2625
    2726    $message = sprintf(__('For to post comment, you need to enable cookies and JavaScript or to click on "%s" button in this page', 'en-spam'), __( 'Post Comment' ));
    2827    $message .= '<form method="post">';
    2928    foreach ($_POST as $name=>$value){
    30         if ($name == 'comment'){
     29        if ($name == 'comment')
    3130            $message .= sprintf('<label for="comment">%s</label><br /><textarea id="comment" name="comment">%s</textarea><br />',__('Your comment:', 'en-spam'), $value);
    32         }
    33         elseif (is_string($value)){
     31        else
    3432            $message .= sprintf('<input type="hidden" name="%s" value="%s" />', $name, stripcslashes($value));
    35         }
    3633    }
    37     $message .= sprintf('<input type="hidden" name="code" value="%s" />', get_option('ens_code'));
     34    $message .= sprintf('<input type="hidden" name="code" value="%s" />', wp_create_nonce('en-spam'));
    3835    $message .= sprintf('<input type="submit" name="submit" value="%s" />', __( 'Post Comment' ));
    3936    $message .= '</form>';
     
    4239}
    4340
    44 
    45 //random code in activation the plugin
    46 register_activation_hook(__FILE__, 'ens_init_code');
    47 function ens_init_code(){
    48     update_option('ens_code', rand(10000, 99999));
     41function ens_count_block(){
     42    $counter = get_option('ens_counter', 0) + 1;
     43    update_option('ens_counter', $counter);
    4944}
    5045
    5146add_action('wp_enqueue_scripts', 'ens_scripts');
    5247function ens_scripts() {
    53     wp_register_script('en-spam', plugins_url('en-spam.js', __FILE__), array('jquery'));
    54     wp_localize_script('en-spam', 'data', array('hash' => COOKIEHASH));
    55     wp_enqueue_script('en-spam');
     48    wp_enqueue_script('en-spam', plugins_url('en-spam.js', __FILE__));
    5649}
    5750
     
    6962}
    7063
    71 load_plugin_textdomain('en-spam', false, dirname( plugin_basename( __FILE__ ) ) );
     64function ens_valid_no_bot(){
     65    return isset($_COOKIE['comment_author_email_' . COOKIEHASH])
     66    || is_user_logged_in()
     67    || isset($_COOKIE['en_spam_validate']);
     68}
     69
     70// CF7
     71function ens_check_cf7($form, &$abort, $submission) {
     72    if (! ens_valid_no_bot()) {
     73        $abort = true;
     74        $submission->set_status( 'validation_failed' );
     75        $submission->set_response($form->filter_message(__('Enable JavaScript and cookies', 'en-spam')));
     76       
     77        ens_count_block();
     78    }
     79}
     80add_action( 'wpcf7_before_send_mail', 'ens_check_cf7', 10, 3);
     81
     82// Elementor Form
     83function ens_check_elementor_form($record, $ajax_handler) {
     84    if (! ens_valid_no_bot()){
     85        $ajax_handler->add_error('field_id', __('Enable JavaScript and cookies', 'en-spam')); // stop sending
     86        $ajax_handler->add_error_message(__('Enable JavaScript and cookies', 'en-spam'));
     87    }
     88}
     89add_action( 'elementor_pro/forms/validation', 'ens_check_elementor_form');
  • en-spam/trunk/readme.txt

    r3112188 r3114115  
    55Requires at least: 2.0
    66Tested up to: 6.6
    7 Stable tag: 0.7.2
     7Stable tag: 1.0
    88
    99Block spam with cookies and JavaScript.
     
    1212== Description ==
    1313
    14 "En Spam" blocks totally comments of bots by cookies and javascript. Bots can't use cookies and javascript and therefore will not be able to comment.
     14"En Spam" blocks totally comments and form submissions of bots by cookies and javascript. Bots can't use cookies and javascript and therefore will not be able to comment.
    1515Users that blocking cookies or Javascript can to comment after transfer in special page.
     16
     17We protect Elementor Pro and Contact Form 7 (cf7) forms and default comments of WordPress.
    1618
    1719The plugin is transparent to your visitors, only bots will be blocked.
     
    2931
    3032== Changelog ==
     33= 1.0 =
     34* Add support to Elementor form and contact form 7 (cf7)
    3135= 0.7.2 =
    3236* Add support to old PHP versions
Note: See TracChangeset for help on using the changeset viewer.