__construct(); } function __construct () { add_action ('comment_form', array(&$this, 'comment_form'), 0); add_action ('comment_post', array(&$this, 'comment_post')); add_action ('admin_menu', array(&$this, 'admin_menu')); // set unique string (makes some random strings different among websites) $this->unique_string = get_option('siteurl'); // set $dir_name $dir_name = str_replace('\\', '/', dirname(__FILE__)); $dir_name = trim(substr($dir_name, strpos($dir_name, '/plugins/')+9), '/'); // enable localization load_plugin_textdomain($this->abbr, 'wp-content/plugins/' . $dir_name . '/languages/'); $this->default_template_code = '

'; } // improves comment-form function comment_form ($form) { global $user_ID; $this->name = $this->GenerateName(); $this->answer = $this->GenerateAnswer(); $this->name2 = $this->GenerateName2(); $this->answer2 = $this->GenerateAnswer2(); // split correct answer into two parts - because of more complicated parsing for spambots $answer_len = strlen($this->answer); $answer_splitpoint = rand(1, $answer_len-1); $answer_array[0] = substr($this->answer, 0, $answer_splitpoint); $answer_array[1] = substr($this->answer, $answer_splitpoint); // for camino & seamonkey browsers (problems reported) display $ua = strtolower($_SERVER['HTTP_USER_AGENT']); // logged user don't need to be tested if ($user_ID) { ?> GetTemplateCode(); ?> } else { ?> temp_template_code)) { return $this->temp_template_code; } else { // load settings if (($_own_template_code = get_option($this->abbr . '_own_template_code')) == 1) { $_template_code = get_option($this->abbr . '_template_code'); } // get raw template code $template_code = ($_own_template_code) ? $_template_code : $this->default_template_code; // make the final template code $template_code = str_replace( array('%name%', '%answer%', '%name2%', '%answer2%'), array($this->name, $this->answer, $this->name2, $this->answer2), $template_code); // cache the code for this instance $this->temp_template_code = $template_code; return $template_code; } } // Checks user's answer function comment_post ($post_ID) { global $comment_content, $comment_type, $user_ID; $this->name = $this->GenerateName(); $this->answer = $this->GenerateAnswer(); $this->name2 = $this->GenerateName2(); $this->answer2 = $this->GenerateAnswer2(); $this->answer_yesterday = $this->GenerateAnswer('yesterday'); $user_answer = trim($_POST[$this->name]); $user_answer2 = trim($_POST[$this->name2]); $errors['empty'] = __('You didn\'t answer the antispam question, your comment was not saved. Press "Back" and answer the question.
Just to be sure that your message won\'t be lost - copy it now to the clipboard.', $this->abbr); $errors['wrong'] = __('You didn\'t answer the antispam question correctly, your comment was not saved. Press "Back" and answer the question better.
Just to be sure that your message won\'t be lost - copy it now to the clipboard.', $this->abbr); // not a trackback if ( $comment_type === '' AND !$user_ID) { // not filled if ( $user_answer == '' ) { $this->Flashback ($post_ID); wp_die($errors['empty'] .'

'. $comment_content .''); } // filled wrong elseif (($user_answer2 != $this->answer2) OR (( $user_answer != $this->answer ) AND !( date('G') == 0 AND $user_answer == $this->answer_yesterday )) ) { $this->Flashback ($post_ID); wp_die($errors['wrong'] .'

'. $comment_content .''); } } // else OK! return $post_ID; } // Well, the comment was saved already, so delete it... :( // This code was copied from "Did you pass math" plugin, thank you! function Flashback ($post_ID) { global $wpdb, $comment_count_cache; $entry_id = $_POST['comment_post_ID']; // Delete it... $wpdb->query("DELETE FROM {$wpdb->comments} WHERE comment_ID = {$post_ID}"); // Recount the comments $count = $wpdb->get_var("SELECT COUNT(*) from $wpdb->comments WHERE comment_post_id = {$entry_id} AND comment_approved = '1'"); $wpdb->query("UPDATE $wpdb->posts SET comment_count = $count WHERE ID = {$entry_id}"); $comment_count_cache[$entry_id]--; } // Correct answer changes everyday function GenerateAnswer ($par = 'today') { $time = ('yesterday' == $par) ? time()-24*3600 : time(); $day = date('j', $time); $mix = 'raven!'.$day.$this->unique_string; return substr(md5($mix),3,6); } // function GenerateAnswer2 () { return ''; } // Every installation carries different input-name function GenerateName () { $mix = 'raven?'.$this->unique_string; return 'url'. substr(md5($mix),16,4); // return 'web_site_url'; } // Every installation carries different input-name function GenerateName2 () { $mix = 'raven?'.$this->unique_string; return substr(md5($mix),0,6); } // Hook: Action: admin_menu // Descr: adds own item into menu in administration function admin_menu () { if (function_exists('add_submenu_page')) add_options_page( $this->short_name, // page title $this->short_name, // menu-item label 'manage_options', __FILE__, array (&$this, 'TheSettingsPage') ); } // Descr: own settings-page // Todo: maybe should be included from another file function TheSettingsPage () { ?>

Raven's antispam

/>

abbr); ?>

/>
/>:



%name% and %answer%.', $this->abbr); ?>