From 949bf9d26f27dd4c50c18967d4a33cab8a9d0cb9 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Mon, 15 Aug 2016 11:25:02 +0200 Subject: [PATCH] One-time execution added --- README.md | 19 +++++++++++---- inc/statifyblacklist_admin.class.php | 24 +++++++++++++++++-- readme.txt | 35 ++++++++++++++++++++++++++++ statifyblacklist.php | 4 ++-- views/settings_page.php | 28 +++++++++++++++------- 5 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 readme.txt diff --git a/README.md b/README.md index 93b3364..0f2586d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Statify Blacklist # * Contributors: Stefan Kalscheuer * Requires at least: 3.9 -* Tested up to: 4.5 -* Stable tag: 1.0.0 +* Tested up to: 4.5.3 +* Stable tag: 1.1.0 * License: GPLv3 or later * License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -15,9 +15,12 @@ This plugin adds customizable blacklist to Statify to allow blocking of referer ####Referer Blacklist Add a list of domains (for simplicity onl second-level, e.g. _example.com_ which blocks _everything.example.com_). +#### CleanUp Database +Filters can be applied to data stored in database after modifying filter rules or for one-time clean-up. + ### Compatibility ### -This plugin requires Statify to be installed. The extension has been tested with Statify 1.4.3 +This plugin requires Statify to be installed. The extension has been tested with Statify 1.4.2 The plugin is capable of handling multisite installations. ### Credits ### @@ -28,4 +31,12 @@ The plugin is capable of handling multisite installations. ### Requirements ### * PHP 5.2.4 -* WordPress 3.9 \ No newline at end of file +* WordPress 3.9 +* Statify plugin installed and activated (tested with 1.4.2) + +## Changelog +#### 1.1.0 / 15.08.2016 +* One-time execution on database + +#### 1.0.0 / 14.08.2016 +* First release \ No newline at end of file diff --git a/inc/statifyblacklist_admin.class.php b/inc/statifyblacklist_admin.class.php index bb8ef1f..0e16331 100644 --- a/inc/statifyblacklist_admin.class.php +++ b/inc/statifyblacklist_admin.class.php @@ -49,8 +49,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist * * @since 1.0.0 */ - public static function plugin_actions_links($links, $file) - { + public static function plugin_actions_links($links, $file) { $base = self::$multisite ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' ); if( $file == STATIFYBLACKLIST_BASE && current_user_can('manage_options') ) { @@ -61,4 +60,25 @@ class StatifyBlacklist_Admin extends StatifyBlacklist } return $links; } + + /** + * Filter database for cleanup. + * + * @since 1.1.0 + */ + public static function cleanup_database() { + global $wpdb; + + /* Build filter regexp */ + $refererRegexp = str_replace('.', '\.', implode('|', self::$_options['referer'])); + if (!empty($refererRegexp)) { + /* Execute filter on database */ + $wpdb->query( + $wpdb->prepare("DELETE FROM `$wpdb->statify` WHERE referrer REGEXP %s", $refererRegexp) + ); + } + + /* Optimize DB */ + $wpdb->query("OPTIMIZE TABLE `$wpdb->statify`"); + } } \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..a0fdfa0 --- /dev/null +++ b/readme.txt @@ -0,0 +1,35 @@ +=== Statify Blacklist === +Contributors: Stefan Kalscheuer +Tags: stats, extension, blacklist, filter +Requires at least: 3.9 +Tested up to: 4.5.3 +Stable tag: trunk +License: GPLv3 or later +License URI: https://www.gnu.org/licenses/gpl-3.0.html + +Extension for the Statify statistics plugin. Provides a customizable referer blacklist. + +== Description == +A blacklist extension for the famous [Statify](http://statify.de) Wordpress plugin. + +This plugin adds customizable blacklist to Statify to allow blocking of referer spam or internal interactions. + +== Requirements == +* PHP 5.2.4 +* WordPress 3.9 +* Statify plugin (tested with 1.4.2) + +== Installation == +1. Upload the plugin files to the `/wp-content/plugins/statify-blacklist` directory, or install the plugin through the WordPress plugins screen directly. +1. Activate the plugin through the 'Plugins' screen in WordPress +1. Use the Settings->Plugin Name screen to configure the plugin +1. (Make your instructions match the desired user flow for activating and installing your plugin. Include any steps that might be needed for explanatory purposes) + + +== Changelog == + += 1.1.0 / 15.08.2016 = +* One-time execution on database + += 1.0.0 / 14.08.2016 = +* First release diff --git a/statifyblacklist.php b/statifyblacklist.php index af5a210..af81033 100644 --- a/statifyblacklist.php +++ b/statifyblacklist.php @@ -6,9 +6,9 @@ Text Domain: statify-blacklist Domain Path: /lang Author: stklcode Author URI: https://stklcode.de -Plugin URI: https://wordpress.org/plugins/statifyRefererBlacklist +Plugin URI: https://wordpress.org/plugins/statify-blacklist License: GPLv3 or later -Version: 1.0.0 +Version: 1.1.0 */ /* Quit */ diff --git a/views/settings_page.php b/views/settings_page.php index f7b38f7..d86f407 100644 --- a/views/settings_page.php +++ b/views/settings_page.php @@ -1,13 +1,18 @@ (int)@$_POST['statifyblacklist']['active_referer'], - 'referer' => explode("\r\n", $_POST['statifyblacklist']['referer']) - ) - ); +if ( !empty($_POST['statifyblacklist']) ) { + if (!empty($_POST['cleanUp'])) { + /* CleanUp DB */ + StatifyBlacklist_Admin::cleanup_database(); + } else { + StatifyBlacklist::update_options( + array( + 'active_referer' => (int)@$_POST['statifyblacklist']['active_referer'], + 'referer' => explode("\r\n", $_POST['statifyblacklist']['referer']) + ) + ); + } } ?> @@ -33,6 +38,13 @@ if ( ! empty($_POST['statifyblacklist']) ) { -

+

+ +


+ +
+ () +