Plugin Directory

Changeset 1540189


Ignore:
Timestamp:
11/24/2016 10:24:36 PM (9 years ago)
Author:
eugenbobrowski
Message:

Commit version 1.4

Location:
antispam/trunk
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • antispam/trunk/comments-antispam.php

    r1426913 r1540189  
    77Plugin Name: Antispam
    88Plugin URI: http://wordpress.org/plugins/antispam/
    9 Description: Antispam hack form comment form
     9Description: Anti-spam check the robots by behavior. No captcha. Antispam let robots do so as a human can't do.
    1010Author: Eugen Bobrowski
    11 Version: 1.3
     11Version: 1.4
    1212Author URI: http://atf.li/
    1313*/
     
    1616
    1717if (is_admin()) {
    18     class Antispam_Admin
    19     {
    20         protected static $instance;
    21 
    22         private function __construct()
    23         {
    24             add_action('admin_bar_menu', array($this, 'show_spam_count'), 99);
    25             add_action('admin_print_styles', array($this, 'style'));
    26             return true;
    27         }
    28 
    29         public static function get_instance()
    30         {
    31             if (null === self::$instance) {
    32                 self::$instance = new self();
    33             }
    34             return self::$instance;
    35         }
    36 
    37         public function show_spam_count($wp_admin_bar)
    38         {
    39             $wp_admin_bar->add_node(array(
    40                 "id" => "antispam-plugin",
    41                 "title" => "Antispam:",
    42                 "parent" => "comments",
    43             ));
    44 
    45             $wp_admin_bar->add_node(array(
    46                 "id" => "antispam-plugin-counter",
    47                 "title" =>  get_option('spams_detected', 0) . ' rejected',
    48                 "parent" => "antispam-plugin",
    49             ));
    50 
    51             $wp_admin_bar->add_node(array(
    52                 'id' => 'antispam-github',
    53                 'href' => 'https://github.com/EugenBobrowski/antispam/issues',
    54                 "title" => 'Create Issue on GitHub',
    55                 "parent" => "antispam-plugin",
    56             ));
    57 
    58 
    59         }
    60 
    61         public function style()
    62         {
    63             ?>
    64             <style>
    65                 #wp-admin-bar-antispam-plugin > .ab-item:before {
    66                     content: "\f332" !important;
    67                     top: 4px;
    68                 }
    69             </style><?php
    70         }
    71     }
    72 
    73     if (apply_filters('antispam_counter', true))
    74         Antispam_Admin::get_instance();
     18    include_once 'admin/admin.php';
     19    include_once 'admin/install.php';
     20    add_action('plugins_loaded', array('Antispam_Activator', 'db_check'));
     21    register_activation_hook( __FILE__, array('Antispam_Activator', 'db_check') );
    7522} else {
    7623    class Antispam
     
    7825
    7926        protected static $instance;
     27        private $secret;
    8028        private $nonce;
    8129        private $localize_object;
     
    8432        private function __construct()
    8533        {
    86 
    87 //          add_filter('pre_comment_on_post', array($this, 'verify_spam'));
    88 
    89             $this->nonce = hash('md5', ABSPATH);
     34            $this->secret = apply_filters('antispam_s', ABSPATH);
     35
     36            $this->nonce = hash('md5', $this->secret);
    9037
    9138            $this->localize_object = 'veritas';
     
    9643                    //protect method (replace | add )
    9744                    'method' => 'add',
     45                    'request_method' => 'post',
    9846                    //parent to copy and hide
    9947                    'parent' => '.comment-form-comment',
     48                    'author' => 'author',
     49                    'email' => 'email',
    10050                ),
     51                's' => array(
     52                    //protect method (replace | add )
     53                    'method' => 'add',
     54                    'request_method' => 'get',
     55                    //parent to copy and hide
     56                    'parent' => 'label',
     57                ),
     58
    10159            ));
    10260
     
    10462                $this->fields[$name]['ha'] = hash('md5', ABSPATH . $name);
    10563            }
    106 
    107             add_filter('init', array($this, 'verify_spam'));
     64//          add_filter('pre_comment_on_post', array($this, 'verify_spam'));
     65            add_filter('init', array($this, 'verify_spam'), 1);
    10866            add_action('wp_print_scripts', array($this, 'localize'));
    10967            add_filter('print_footer_scripts', array($this, 'javascript'));
     
    12886        public function localize()
    12987        {
    130 
    131 
    13288            wp_enqueue_script('jquery');
    13389            wp_localize_script('jquery', $this->localize_object, $this->fields);
     
    203159        public function verify_spam($commentdata)
    204160        {
     161
    205162            foreach ($this->fields as $name => $field) {
    206163                if (
    207                     ('replace' == $field['method'] && isset($_POST['comment']) && !isset($_POST[$field['ha']]))
    208                     ||
    209                     ('add' == $field['method'] && !empty($_POST['comment']))
     164                (('replace' == $field['method'] && isset($_REQUEST[$name]) && !isset($_REQUEST[$field['ha']]))
     165                ||
     166                ('add' == $field['method'] && !empty($_REQUEST[$name])))
     167                && !isset($_COOKIE['antispam_verified'])
    210168                ) {
    211                     $this->die_die_die();
    212 
    213                 } elseif (isset($_POST[$field['ha']])) {
    214                     $_POST['comment'] = $_POST[$field['ha']];
     169                    $this->die_die_die($field);
     170                } elseif (isset($_REQUEST[$field['ha']]) && 'post' == $field['request_method']) {
     171                    $_POST[$name] = $_POST[$field['ha']];
     172                } elseif (isset($_REQUEST[$field['ha']]) && 'get' == $field['request_method']) {
     173                    setcookie('antispam_verified', 'asd', time() + 60, '/');
     174                    $_GET[$name] = $_GET[$field['ha']];
     175                    wp_redirect(site_url('?s='.$_GET[$field['ha']])); exit;
    215176                }
    216177            }
     
    220181        }
    221182
    222         public function die_die_die()
    223         {
     183        public function log_spam($field = array()) {
     184
     185            $spamdata = array(
     186                'spam_date' => current_time( 'mysql' ),
     187                'spam_IP' => '',
     188                'spam_email' => '',
     189                'spam_author' => '',
     190            );
     191
     192
     193            $spamdata['spam_IP'] = $_SERVER['REMOTE_ADDR'];
     194            $spamdata['spam_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $spamdata['spam_IP'] );
     195
     196            if (isset($field['author']) && isset($_POST[$field['author']])) $spamdata['spam_author'] = sanitize_text_field($_POST[$field['author']]);
     197            elseif (isset($_POST['author'])) $spamdata['spam_author'] = sanitize_text_field($_POST['author']);
     198
     199            if (isset($field['email']) && isset($_POST[$field['email']])) $spamdata['spam_email'] = sanitize_text_field($_POST[$field['email']]);
     200            elseif (isset($_POST['email'])) $spamdata['spam_email'] = sanitize_text_field($_POST['email']);
     201
     202            global $wpdb;
     203            $table = $wpdb->prefix . 'comments_antispam_log';
     204
     205            $wpdb->insert($table, $spamdata);
     206
     207        }
     208
     209        public function die_die_die($field)
     210        {
     211            $this->log_spam($field);
    224212            $spam_detected = get_option('spams_detected', 0);
    225213            $spam_detected++;
     
    228216        }
    229217
    230 
    231218    }
    232219
  • antispam/trunk/readme.txt

    r1426913 r1540189  
    33Tags: comments, spam, antispam, anti-spam, anti spam, comment spam, spam comments
    44Requires at least: 3.2
    5 Tested up to: 4.5.2
    6 Stable tag: 1.3
     5Tested up to: 4.6.1
     6Stable tag: 1.4
    77License: GPLv2 or later
    88
     
    1313Antispam let robots do so as a human can't do.
    1414
    15 Features include:
     15= Features include: =
    1616
    1717* No captcha
     18* Statistic
    1819
    1920GitHub: https://github.com/EugenBobrowski/antispam
     
    25261, 2, 3: You're done!
    2627
     28== Screenshots ==
    2729
     301. Spam comment is rejected
     312. Antispam statistic page
    2832
    2933== Changelog ==
Note: See TracChangeset for help on using the changeset viewer.