base_name = plugin_basename(__FILE__);
$this->md5_sign = 'comment-' .substr(md5(get_bloginfo('url')), 0, 8);
if ( defined('DOING_CRON') ) {
add_action(
'antispam_bee_daily_cronjob',
array(
$this,
'exe_daily_cronjob'
)
);
} elseif ( is_admin() ) {
add_action(
'admin_menu',
array(
$this,
'init_admin_menu'
)
);
if ( $this->is_current_page('home') ) {
add_action(
'init',
array(
$this,
'load_plugin_lang'
)
);
add_action(
'admin_init',
array(
$this,
'add_plugin_sources'
)
);
} else if ( $this->is_current_page('index') ) {
add_action(
'init',
array(
$this,
'load_plugin_lang'
)
);
if ( $this->get_option('dashboard_count') ) {
if ($this->is_min_wp('3.0')) {
add_action(
'right_now_discussion_table_end',
array(
$this,
'add_discussion_table_end'
)
);
} else {
add_action(
'right_now_table_end',
array(
$this,
'add_table_end'
)
);
}
}
if ( $this->get_option('dashboard_chart') ) {
add_action(
'wp_dashboard_setup',
array(
$this,
'init_dashboard_chart'
)
);
}
} else if ( $this->is_current_page('plugins') ) {
add_action(
'init',
array(
$this,
'load_plugin_lang'
)
);
add_action(
'activate_' .$this->base_name,
array(
$this,
'init_plugin_options'
)
);
add_action(
'deactivate_' .$this->base_name,
array(
$this,
'clear_scheduled_hook'
)
);
add_action(
'admin_notices',
array(
$this,
'show_version_notice'
)
);
add_filter(
'plugin_row_meta',
array(
$this,
'init_row_meta'
),
10,
2
);
}
} else {
add_action(
'template_redirect',
array(
$this,
'replace_comment_field'
)
);
add_action(
'init',
array(
$this,
'precheck_comment_request'
)
);
add_action(
'preprocess_comment',
array(
$this,
'verify_comment_request'
),
1
);
add_action(
'antispam_bee_count',
array(
$this,
'the_spam_count'
)
);
add_filter(
'comment_notification_text',
array(
$this,
'replace_whois_link'
)
);
add_filter(
'comment_moderation_text',
array(
$this,
'replace_whois_link'
)
);
}
}
function load_plugin_lang() {
load_plugin_textdomain(
'antispam_bee',
false,
'antispam-bee/lang'
);
}
function init_row_meta($links, $file) {
if ( $this->base_name == $file ) {
return array_merge(
$links,
array(
sprintf(
'%s',
esc_html__('Flattr')
),
sprintf(
'%s',
$this->base_name,
esc_html__('Settings')
)
)
);
}
return $links;
}
function init_plugin_options() {
add_option(
'antispam_bee',
array(),
'',
'no'
);
if ($this->get_option('cronjob_enable')) {
$this->init_scheduled_hook();
}
}
function get_option($field) {
if ( !$options = wp_cache_get('antispam_bee') ) {
$options = get_option('antispam_bee');
wp_cache_set(
'antispam_bee',
$options
);
}
return @$options[$field];
}
function update_option($field, $value) {
$this->update_options(
array(
$field => $value
)
);
}
function update_options($data) {
$options = array_merge(
(array)get_option('antispam_bee'),
$data
);
update_option(
'antispam_bee',
$options
);
wp_cache_set(
'antispam_bee',
$options
);
}
function init_scheduled_hook() {
if ( !wp_next_scheduled('antispam_bee_daily_cronjob') ) {
wp_schedule_event(
time(),
'daily',
'antispam_bee_daily_cronjob'
);
}
}
function clear_scheduled_hook() {
if ( wp_next_scheduled('antispam_bee_daily_cronjob') ) {
wp_clear_scheduled_hook('antispam_bee_daily_cronjob');
}
}
function exe_daily_cronjob() {
if ( !$this->get_option('cronjob_enable') ) {
return;
}
$this->update_option(
'cronjob_timestamp',
time()
);
$this->delete_spam_comments();
}
function delete_spam_comments() {
$days = (int)$this->get_option('cronjob_interval');
if ( empty($days) ) {
return false;
}
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"DELETE FROM `$wpdb->comments` WHERE `comment_approved` = 'spam' AND SUBDATE(NOW(), %d) > comment_date_gmt",
$days
)
);
$wpdb->query("OPTIMIZE TABLE `$wpdb->comments`");
}
function init_admin_menu() {
$page = add_options_page(
'Antispam Bee',
'
Antispam Bee',
'manage_options',
__FILE__,
array(
$this,
'show_admin_menu'
)
);
add_action(
'admin_print_scripts-' . $page,
array(
$this,
'add_enqueue_script'
)
);
add_action(
'admin_print_styles-' . $page,
array(
$this,
'add_enqueue_style'
)
);
}
function add_plugin_sources() {
$data = get_plugin_data(__FILE__);
wp_register_script(
'ab_script',
plugins_url('antispam-bee/js/script.js'),
array('jquery'),
$data['Version']
);
wp_register_style(
'ab_style',
plugins_url('antispam-bee/css/style.css'),
array(),
$data['Version']
);
}
function add_enqueue_script() {
wp_enqueue_script('ab_script');
}
function add_enqueue_style() {
wp_enqueue_style('ab_style');
}
function is_min_wp($version) {
return version_compare(
$GLOBALS['wp_version'],
$version. 'alpha',
'>='
);
}
function is_min_php($version) {
return version_compare(
phpversion(),
$version,
'>='
);
}
function is_mobile() {
return strpos(TEMPLATEPATH, 'wptouch');
}
function is_current_page($page) {
switch($page) {
case 'index':
return ( empty($GLOBALS['pagenow']) or ( !empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'index.php' ) );
case 'home':
return ( !empty($_REQUEST['page']) && $_REQUEST['page'] == $this->base_name );
case 'plugins':
return ( !empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'plugins.php' );
default:
return false;
}
}
function add_table_end() {
echo sprintf(
'
Antispam Bee %s