/*
Plugin Name: Antispam Bee
Text Domain: antispam_bee
Domain Path: /lang
Description: Easy and extremely productive spam-fighting plugin with many sophisticated solutions. Includes protection again trackback spam.
Author: Sergej Müller
Author URI: http://wpseo.de
Plugin URI: http://antispambee.com
Version: 2.4.2
*/
/* Sicherheitsabfrage */
if ( !class_exists('WP') ) {
die();
}
/**
* Antispam_Bee
*
* @since 0.1
* @change 2.4
*/
class Antispam_Bee {
/* Init */
public static $short;
public static $default;
private static $base;
private static $secret;
private static $reason;
/**
* "Konstruktor" der Klasse
*
* @since 0.1
* @change 2.4.2
*/
public static function init()
{
/* AJAX & Co. */
if ( (defined('DOING_AJAX') && DOING_AJAX) or (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) ) {
return;
}
/* Initialisierung */
self::_init_internal_vars();
/* Cronjob */
if ( defined('DOING_CRON') ) {
add_action(
'antispam_bee_daily_cronjob',
array(
__CLASS__,
'start_daily_cronjob'
)
);
/* Admin */
} elseif ( is_admin() ) {
/* Menü */
add_action(
'admin_menu',
array(
__CLASS__,
'add_sidebar_menu'
)
);
/* Dashboard */
if ( self::_current_page('dashboard') ) {
add_action(
'init',
array(
__CLASS__,
'load_plugin_lang'
)
);
add_action(
'right_now_discussion_table_end',
array(
__CLASS__,
'add_dashboard_count'
)
);
add_action(
'wp_dashboard_setup',
array(
__CLASS__,
'add_dashboard_chart'
)
);
/* Plugins */
} else if ( self::_current_page('plugins') ) {
add_action(
'init',
array(
__CLASS__,
'load_plugin_lang'
)
);
add_filter(
'plugin_row_meta',
array(
__CLASS__,
'init_row_meta'
),
10,
2
);
add_filter(
'plugin_action_links_' .self::$base,
array(
__CLASS__,
'init_action_links'
)
);
/* Optionen */
} else if ( self::_current_page('options') ) {
add_action(
'admin_init',
array(
__CLASS__,
'load_plugin_lang'
)
);
add_action(
'admin_init',
array(
__CLASS__,
'init_plugin_sources'
)
);
} else if ( self::_current_page('admin-post') ) {
require_once( dirname(__FILE__). '/inc/gui.class.php' );
add_action(
'admin_post_ab_save_changes',
array(
'Antispam_Bee_GUI',
'save_changes'
)
);
}
/* Frontend */
} else {
add_action(
'template_redirect',
array(
__CLASS__,
'prepare_comment_field'
)
);
add_action(
'init',
array(
__CLASS__,
'precheck_incoming_request'
)
);
add_action(
'preprocess_comment',
array(
__CLASS__,
'handle_incoming_request'
),
1
);
add_action(
'antispam_bee_count',
array(
__CLASS__,
'the_spam_count'
)
);
}
}
############################
######## INSTALL #########
############################
/**
* Aktion bei der Aktivierung des Plugins
*
* @since 0.1
* @change 2.4
*/
public static function activate()
{
/* Option anlegen */
add_option(
self::$short,
array(),
'',
'no'
);
/* Cron aktivieren */
if ( self::get_option('cronjob_enable') ) {
self::init_scheduled_hook();
}
}
/**
* Aktion bei der Deaktivierung des Plugins
*
* @since 0.1
* @change 2.4
*/
public static function deactivate()
{
self::clear_scheduled_hook();
}
/**
* Aktion beim Löschen des Plugins
*
* @since 2.4
* @change 2.4
*/
public static function uninstall()
{
/* Global */
global $wpdb;
/* Remove settings */
delete_option('antispam_bee');
/* Clean DB */
$wpdb->query("OPTIMIZE TABLE `" .$wpdb->options. "`");
}
############################
######### INTERN #########
############################
/**
* Initialisierung der internen Variablen
*
* @since 2.4
* @change 2.4
*/
private static function _init_internal_vars()
{
self::$base = plugin_basename(__FILE__);
self::$short = 'antispam_bee';
self::$secret = substr(md5(get_bloginfo('url')), 0, 5). '-comment';
self::$default = array(
'options' => array(
/* Allgemein */
'advanced_check' => 1,
'spam_ip' => 1,
'already_commented' => 1,
'ignore_pings' => 0,
'always_allowed' => 0,
'dashboard_chart' => 1,
'dashboard_count' => 0,
/* Filter */
'country_code' => 0,
'country_black' => '',
'country_white' => '',
'translate_api' => 0,
'translate_lang' => '',
'honey_pot' => 0,
'honey_key' => '',
/* Erweitert */
'flag_spam' => 1,
'email_notify' => 1,
'no_notice' => 1,
'cronjob_enable' => 0,
'cronjob_interval' => 0,
'ignore_filter' => 0,
'ignore_type' => 0,
'ignore_reasons' => array(),
/* Tab */
'tab_index' => 0
),
'reasons' => array(
'css' => 'CSS Hack',
'empty' => 'Empty Data',
'server' => 'Server IP',
'spamip' => 'Spam IP',
'country' => 'Country Check',
'honey' => 'Honey Pot',
'lang' => 'Comment Language'
)
);
}
/**
* Prüfung und Rückgabe eines Array-Keys
*
* @since 2.4.2
* @change 2.4.2
*
* @param array $array Array mit Werten
* @param string $key Name des Keys
* @return mixed Wert des angeforderten Keys
*/
public static function get_key($array, $key)
{
if ( empty($array) or empty($key) or empty($array[$key]) ) {
return null;
}
return $array[$key];
}
/**
* Lokalisierung der Admin-Seiten
*
* @since 0.1
* @change 2.4
*
* @param string $page Kennzeichnung der Seite
* @return boolean TRUE Bei Erfolg
*/
private static function _current_page($page)
{
switch ($page) {
case 'dashboard':
return ( empty($GLOBALS['pagenow']) or ( !empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'index.php' ) );
case 'options':
return ( !empty($_REQUEST['page']) && $_REQUEST['page'] == self::$short );
case 'plugins':
return ( !empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'plugins.php' );
case 'admin-post':
return ( !empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'admin-post.php' );
default:
return false;
}
}
/**
* Einbindung der Sprachdatei
*
* @since 0.1
* @change 2.4
*/
public static function load_plugin_lang()
{
load_plugin_textdomain(
self::$short,
false,
'antispam-bee/lang'
);
}
/**
* Hinzufügen des Links zu den Einstellungen
*
* @since 1.1
* @change 1.1
*/
public static function init_action_links($data)
{
/* Rechte? */
if ( !current_user_can('manage_options') ) {
return $data;
}
return array_merge(
$data,
array(
sprintf(
'%s',
add_query_arg(
array(
'page' => self::$short
),
admin_url('options-general.php')
),
__('Settings')
)
)
);
}
/**
* Meta-Links des Plugins
*
* @since 0.1
* @change 2.4
*
* @param array $data Bereits vorhandene Links
* @param string $page Aktuelle Seite
* @return array $data Modifizierte Links
*/
public static function init_row_meta($data, $page)
{
/* Rechte */
if ( $page != self::$base ) {
return $data;
}
return array_merge(
$data,
array(
'Plugin flattern',
'Auf Google+ folgen'
)
);
}
############################
####### RESSOURCEN #######
############################
/**
* Registrierung von Ressourcen (CSS & JS)
*
* @since 1.6
* @change 2.4
*/
public static function init_plugin_sources()
{
/* Infos auslesen */
$plugin = get_plugin_data(__FILE__);
/* JS einbinden */
wp_register_script(
'ab_script',
plugins_url('js/script.js', __FILE__),
array('jquery', 'jquery-ui-core', 'jquery-ui-tabs'),
$plugin['Version']
);
/* CSS einbinden */
wp_register_style(
'ab_style',
plugins_url('css/style.css', __FILE__),
array(),
$plugin['Version']
);
}
/**
* Initialisierung der Optionsseite
*
* @since 0.1
* @change 2.4
*/
public static function add_sidebar_menu()
{
/* Menü anlegen */
$page = add_options_page(
'Antispam Bee',
'
Antispam Bee',
'manage_options',
self::$short,
array(
'Antispam_Bee_GUI',
'options_page'
)
);
/* JS einbinden */
add_action(
'admin_print_scripts-' . $page,
array(
__CLASS__,
'add_options_script'
)
);
/* CSS einbinden */
add_action(
'admin_print_styles-' . $page,
array(
__CLASS__,
'add_options_style'
)
);
/* PHP laden */
add_action(
'load-' .$page,
array(
__CLASS__,
'init_options_page'
)
);
}
/**
* Initialisierung von JavaScript
*
* @since 1.6
* @change 2.4
*/
public static function add_options_script()
{
wp_enqueue_script('ab_script');
}
/**
* Initialisierung von Stylesheets
*
* @since 1.6
* @change 2.4
*/
public static function add_options_style()
{
wp_enqueue_style('ab_style');
}
/**
* Einbindung der GUI
*
* @since 2.4
* @change 2.4
*/
public static function init_options_page()
{
require_once( dirname(__FILE__). '/inc/gui.class.php' );
}
############################
####### DASHBOARD ########
############################
/**
* Anzeige des Spam-Counters auf dem Dashboard
*
* @since 0.1
* @change 2.4
*/
public static function add_dashboard_count()
{
/* Aktiv? */
if ( !self::get_option('dashboard_count') ) {
return;
}
/* Ausgabe */
echo sprintf(
'