query("OPTIMIZE TABLE `" .$wpdb->options. "`"); } ############################ ######### INTERN ######### ############################ /** * Initialisierung der internen Variablen * * @since 2.4 * @change 2.6.5 */ private static function _init_internal_vars() { self::$_base = plugin_basename(__FILE__); self::$_secret = substr(md5(get_bloginfo('url')), 0, 5). '-comment'; self::$defaults = array( 'options' => array( /* Allgemein */ 'advanced_check' => 1, 'regexp_check' => 1, 'spam_ip' => 1, 'already_commented' => 1, 'gravatar_check' => 0, 'time_check' => 0, 'ignore_pings' => 0, 'always_allowed' => 0, 'dashboard_chart' => 0, 'dashboard_count' => 0, /* Filter */ 'country_code' => 0, 'country_black' => '', 'country_white' => '', 'translate_api' => 0, 'translate_lang' => '', 'dnsbl_check' => 0, 'bbcode_check' => 1, /* Erweitert */ 'flag_spam' => 1, 'email_notify' => 1, 'no_notice' => 0, 'cronjob_enable' => 0, 'cronjob_interval' => 0, 'ignore_filter' => 0, 'ignore_type' => 0, 'reasons_enable' => 0, 'ignore_reasons' => array() ), 'reasons' => array( 'css' => 'CSS Hack', 'time' => 'Comment time', 'empty' => 'Empty Data', 'server' => 'Fake IP', 'localdb' => 'Local DB Spam', 'country' => 'Country Check', 'dnsbl' => 'DNSBL Spam', 'bbcode' => 'BBCode', 'lang' => 'Comment Language', 'regexp' => 'RegExp' ) ); } /** * 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($_GET['page']) && $_GET['page'] == 'antispam_bee' ); case 'plugins': return ( !empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'plugins.php' ); case 'admin-post': return ( !empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'admin-post.php' ); case 'edit-comments': return ( !empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'edit-comments.php' ); default: return false; } } /** * Einbindung der Sprachdatei * * @since 0.1 * @change 2.4 */ public static function load_plugin_lang() { load_plugin_textdomain( 'antispam_bee', 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' => 'antispam_bee' ), admin_url('options-general.php') ), __('Settings') ) ) ); } /** * Meta-Links des Plugins * * @since 0.1 * @change 2.6.2 * * @param array $input Bereits vorhandene Links * @param string $file Aktuelle Seite * @return array $data Modifizierte Links */ public static function init_row_meta($input, $file) { /* Rechte */ if ( $file != self::$_base ) { return $input; } return array_merge( $input, array( 'PayPal', 'Flattr' ) ); } ############################ ####### RESSOURCEN ####### ############################ /** * Registrierung von Ressourcen (CSS & JS) * * @since 1.6 * @change 2.4.5 */ public static function init_plugin_sources() { /* Infos auslesen */ $plugin = get_plugin_data(__FILE__); /* JS einbinden */ wp_register_script( 'ab_script', plugins_url('js/scripts.min.js', __FILE__), array('jquery'), $plugin['Version'] ); /* CSS einbinden */ wp_register_style( 'ab_style', plugins_url('css/styles.min.css', __FILE__), array(), $plugin['Version'] ); } /** * Initialisierung der Optionsseite * * @since 0.1 * @change 2.4.3 */ public static function add_sidebar_menu() { /* Menü anlegen */ $page = add_options_page( 'Antispam Bee', 'Antispam Bee', 'manage_options', 'antispam_bee', 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.6.5 * * @param array $items Array with dashboard items * @return array $items Array with dashboard items */ public static function add_dashboard_count( $items = array() ) { /* Skip */ if ( ! current_user_can('manage_options') OR ! self::get_option('dashboard_count') ) { return $items; } /* Icon styling */ echo ''; /* Right now item */ $items[] = sprintf( '%s %s', add_query_arg( array( 'page' => 'antispam_bee' ), admin_url('options-general.php') ), esc_html( self::_get_spam_count() ), esc_html__('Blocked', 'antispam_bee') ); return $items; } /** * Initialisierung des Dashboard-Chart * * @since 1.9 * @change 2.5.6 */ public static function add_dashboard_chart() { /* Filter */ if ( ! current_user_can('publish_posts') OR ! self::get_option('dashboard_chart') ) { return; } /* Widget hinzufügen */ wp_add_dashboard_widget( 'ab_widget', 'Antispam Bee', array( __CLASS__, 'show_spam_chart' ) ); /* JS laden */ add_action( 'wp_print_scripts', array( __CLASS__, 'add_dashboard_script' ) ); /* CSS laden */ add_action( 'admin_head', array( __CLASS__, 'add_dashboard_style' ) ); } /** * Print dashboard styles * * @since 1.9.0 * @change 2.5.8 */ public static function add_dashboard_style() { /* Get plugin data */ $plugin = get_plugin_data(__FILE__); /* Register styles */ wp_register_style( 'ab_chart', plugins_url('css/dashboard.min.css', __FILE__), array(), $plugin['Version'] ); /* Embed styles */ wp_print_styles('ab_chart'); } /** * Print dashboard scripts * * @since 1.9.0 * @change 2.5.8 */ public static function add_dashboard_script() { /* Get stats */ if ( ! self::get_option('daily_stats') ) { return; } /* Get plugin data */ $plugin = get_plugin_data(__FILE__); /* Register scripts */ wp_register_script( 'sm_raphael_js', plugins_url('js/raphael.min.js', __FILE__), array(), $plugin['Version'], true ); wp_register_script( 'sm_raphael_helper', plugins_url('js/raphael.helper.min.js', __FILE__), array(), $plugin['Version'], true ); wp_register_script( 'ab_chart_js', plugins_url('js/dashboard.min.js', __FILE__), array('jquery'), $plugin['Version'], true ); /* Embed scripts */ wp_enqueue_script('sm_raphael_js'); wp_enqueue_script('sm_raphael_helper'); wp_enqueue_script('ab_chart_js'); } /** * Print dashboard html * * @since 1.9.0 * @change 2.5.8 */ public static function show_spam_chart() { /* Get stats */ $items = (array)self::get_option('daily_stats'); /* Emty array? */ if ( empty($items) ) { echo sprintf( '
%s
| " .$date. " | \n"; } $html .= "
|---|
| " .(int) $count. " | \n"; } $html .= "