query("OPTIMIZE TABLE `" .$wpdb->options. "`"); } /* * ############################ * ######## INTERNAL ######## * ############################ */ /** * Initialization of the internal variables * * @since 2.4 * @change 2.7.0 */ private static function _init_internal_vars() { self::$_base = plugin_basename(__FILE__); $salt = defined( 'NONCE_SALT' ) ? NONCE_SALT : ABSPATH; self::$_salt = substr( sha1( $salt ), 0, 10 ); self::$defaults = array( 'options' => array( // General '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' => array(), 'bbcode_check' => 1, // Advanced 'flag_spam' => 1, 'email_notify' => 0, 'no_notice' => 0, 'cronjob_enable' => 0, 'cronjob_interval' => 0, 'ignore_filter' => 0, 'ignore_type' => 0, 'reasons_enable' => 0, 'ignore_reasons' => array(), ), 'reasons' => array( 'css' => esc_attr__( 'Honeypot', 'antispam-bee' ), 'time' => esc_attr__( 'Comment time', 'antispam-bee' ), 'empty' => esc_attr__( 'Empty Data', 'antispam-bee' ), 'server' => esc_attr__( 'Fake IP', 'antispam-bee' ), 'localdb' => esc_attr__( 'Local DB Spam', 'antispam-bee' ), 'country' => esc_attr__( 'Country Check', 'antispam-bee' ), 'bbcode' => esc_attr__( 'BBCode', 'antispam-bee' ), 'lang' => esc_attr__( 'Comment Language', 'antispam-bee' ), 'regexp' => esc_attr__( 'Regular Expression', 'antispam-bee' ), ) ); } /** * Check and return an array key * * @since 2.4.2 * @change 2.4.2 * * @param array $array Array with values * @param string $key Name of the key * @return mixed Value of the requested key */ public static function get_key($array, $key) { if ( empty($array) or empty($key) or empty($array[$key]) ) { return null; } return $array[$key]; } /** * Localization of the admin pages * * @since 0.1 * @change 2.4 * * @param string $page Mark the page * @return boolean TRUE on success */ 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; } } /** * Integration of the localization file * * @since 0.1 * @change 2.4 */ public static function load_plugin_lang() { load_plugin_textdomain( 'antispam-bee' ); } /** * Add the link to the settings * * @since 1.1 * @change 1.1 */ public static function init_action_links($data) { // Rights? 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') ), esc_attr__('Settings', 'antispam-bee') ) ) ); } /** * Meta links of the plugin * * @since 0.1 * @change 2.6.2 * * @param array $input Existing links * @param string $file Current page * @return array $data Modified links */ public static function init_row_meta($input, $file) { // Rights if ( $file != self::$_base ) { return $input; } return array_merge( $input, array( '' . esc_html__( 'Donate', 'antispam-bee' ) . '', '' . esc_html__( 'Support', 'antispam-bee' ) . '', ) ); } /* * ############################ * ####### RESOURCES ######## * ############################ */ /** * Registration of resources (CSS & JS) * * @since 1.6 * @change 2.4.5 */ public static function init_plugin_sources() { // Read information $plugin = get_plugin_data(__FILE__); // Integrate JS wp_register_script( 'ab_script', plugins_url('js/scripts.min.js', __FILE__), array('jquery'), $plugin['Version'] ); // Integrate CSS wp_register_style( 'ab_style', plugins_url('css/styles.min.css', __FILE__), array( 'dashicons' ), $plugin['Version'] ); } /** * Initialization of the option page * * @since 0.1 * @change 2.4.3 */ public static function add_sidebar_menu() { // Create menu $page = add_options_page( 'Antispam Bee', 'Antispam Bee', 'manage_options', 'antispam_bee', array( 'Antispam_Bee_GUI', 'options_page' ) ); // Integrate JS add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'add_options_script' ) ); // Integrate CSS add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'add_options_style' ) ); // Load PHP add_action( 'load-' .$page, array( __CLASS__, 'init_options_page' ) ); } /** * Initialization of JavaScript * * @since 1.6 * @change 2.4 */ public static function add_options_script() { wp_enqueue_script('ab_script'); } /** * Initialization of Stylesheets * * @since 1.6 * @change 2.4 */ public static function add_options_style() { wp_enqueue_style('ab_style'); } /** * Integration of the GUI * * @since 2.4 * @change 2.4 */ public static function init_options_page() { require_once( dirname(__FILE__). '/inc/gui.class.php' ); } /* * ############################ * ####### DASHBOARD ######## * ############################ */ /** * Display the spam counter on the dashboard * * @since 0.1 * @change 2.6.5 * * @param array $items Initial array with dashboard items * @return array $items Merged 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[] = '' . esc_html( sprintf( __( '%d Blocked', 'antispam-bee' ), self::_get_spam_count() ) ) . ''; return $items; } /** * Initialize the dashboard chart * * @since 1.9 * @change 2.5.6 */ public static function add_dashboard_chart() { // Filter if ( ! current_user_can( 'publish_posts' ) || ! self::get_option( 'dashboard_chart' ) ) { return; } // Add Widget wp_add_dashboard_widget( 'ab_widget', 'Antispam Bee', array( __CLASS__, 'show_spam_chart' ) ); // Load CSS 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__); // Embed scripts wp_enqueue_script( 'raphael', plugins_url( 'js/raphael.min.js', __FILE__ ), array(), '2.1.0', true ); wp_enqueue_script( 'ab-raphael', plugins_url( 'js/raphael.helper.min.js', __FILE__ ), array( 'raphael' ), $plugin['Version'], true ); wp_enqueue_script( 'ab_chart_js', plugins_url( 'js/dashboard.min.js', __FILE__ ), array( 'jquery', 'ab-raphael' ), $plugin['Version'], true ); } /** * 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 .= "