Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
35b00ac485 | |||
d5a947cfbb | |||
b5a6cdf026 | |||
2f55ada8e5 | |||
57e2870904 | |||
e7e2ef639c | |||
036c1927fd | |||
25b16746b2 | |||
e80040fb7e | |||
f1e9ee0fbe | |||
ff11cdc931 | |||
993d0dd54c | |||
f8ab4214de | |||
0c9e63b7ee | |||
19644dd62b | |||
1e0659e649 | |||
bff28ce85b |
48
README.md
48
README.md
@ -1,8 +1,8 @@
|
||||
# Statify Blacklist #
|
||||
* Contributors: Stefan Kalscheuer
|
||||
* Requires at least: 3.9
|
||||
* Tested up to: 4.6
|
||||
* Stable tag: 1.1.2
|
||||
* Tested up to: 4.7
|
||||
* Stable tag: 1.3.1
|
||||
* License: GPLv3 or later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
@ -32,14 +32,52 @@ The plugin is capable of handling multisite installations.
|
||||
* Goto _Settings_ -> _Statify Blacklist_ to configure the plugin
|
||||
|
||||
### Requirements ###
|
||||
* PHP 5.2.4
|
||||
* WordPress 3.9
|
||||
* PHP 5.2.4 or above
|
||||
* WordPress 3.9 or above
|
||||
* Statify plugin installed and activated (tested up to 1.4.3)
|
||||
|
||||
## Frequently Asked Questions ##
|
||||
|
||||
### What is blocked by default? ###
|
||||
Nothing. By default all blacklists are empty and disabled. They can and have to be filled by the blog administrator.
|
||||
|
||||
A default blacklist is not provided, as the plugin itself is totally neutral. If you want to filter out referer spam,
|
||||
visitors from search engines or just "false" referers from 301 redirects only depends on you.
|
||||
|
||||
### Does the filter effect user experience? ###
|
||||
No. It only prevent's _Statify_ from tracking, nothing more or less.
|
||||
|
||||
### Does live filtering impact performance? ###
|
||||
Yes, but probalby not noticeable. Checking a single referer string against a (usually small) list should be neglectible compared to the total loading procedure.
|
||||
If this still is an issue for you, consider deactivating the filter and only run the one-time-cleanup or activate the cron job.
|
||||
|
||||
### Is any personal data collected? ###
|
||||
No. The privacy policy of _Statify_ is untouched. Data is only processed, not stored or exposed to anyone.
|
||||
|
||||
### Are regular expression filters possible? ###
|
||||
Yes, it it. Just select if you want to filter using regular expressions case sensitive or insensitive.
|
||||
|
||||
Note, that regular expression matching is significantly slower than the plain domain filter. Hence it is only recommended for asynchronous cron or manual execution and not for live filtering.
|
||||
|
||||
|
||||
## Screenshots ##
|
||||
1. Statify Blacklist settings page
|
||||
|
||||
## Changelog ##
|
||||
|
||||
### 1.3.1 / 09.12.2016 ###
|
||||
* Continue filtering if no filter applies (#6)
|
||||
|
||||
### 1.3.0 / 17.10.2016 ###
|
||||
* Regular expressions filtering implemented
|
||||
|
||||
### 1.2.1 / 10.10.2016 ###
|
||||
* Fix live filter configuration check
|
||||
|
||||
### 1.2.0 / 29.08.2016 ###
|
||||
* Switched from `in_array()` to faster `isset()` for referer checking
|
||||
* Optional cron execiton implemented
|
||||
|
||||
### 1.1.2 / 17.08.2016 ###
|
||||
* Prepared for localization
|
||||
|
||||
@ -50,4 +88,4 @@ The plugin is capable of handling multisite installations.
|
||||
* One-time execution on database
|
||||
|
||||
### 1.0.0 / 14.08.2016 ###
|
||||
* First release
|
||||
* First release
|
||||
|
@ -1,124 +1,146 @@
|
||||
<?php
|
||||
|
||||
/* Quit */
|
||||
defined('ABSPATH') OR exit;
|
||||
defined( 'ABSPATH' ) OR exit;
|
||||
|
||||
/**
|
||||
* Statify Blacklist
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class StatifyBlacklist
|
||||
{
|
||||
/**
|
||||
* Plugin options
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static $_options;
|
||||
class StatifyBlacklist {
|
||||
/**
|
||||
* Plugin options
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static $_options;
|
||||
|
||||
/**
|
||||
* Multisite Status
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static $multisite;
|
||||
/**
|
||||
* Multisite Status
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static $multisite;
|
||||
|
||||
/**
|
||||
* Class self initialize
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
new self();
|
||||
}
|
||||
/**
|
||||
* Class self initialize
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function instance() {
|
||||
new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @changed 1.1.2
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
/* Skip on autosave or AJAX */
|
||||
if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) OR (defined('DOING_AJAX') && DOING_AJAX) ) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @changed 1.2.1
|
||||
*/
|
||||
public function __construct() {
|
||||
/* Skip on autosave or AJAX */
|
||||
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) OR ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Plugin options */
|
||||
self::update_options();
|
||||
/* Plugin options */
|
||||
self::update_options();
|
||||
|
||||
/* Get multisite status */
|
||||
self::$multisite = (is_multisite() && array_key_exists(STATIFYBLACKLIST_BASE, (array)get_site_option('active_sitewide_plugins')));
|
||||
/* Get multisite status */
|
||||
self::$multisite = ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) );
|
||||
|
||||
/* Add Filter to statify hook */
|
||||
add_filter('statify_skip_tracking', array('StatifyBlacklist', 'apply_blacklist_filter'));
|
||||
/* Add Filter to statify hook if enabled */
|
||||
if ( self::$_options['active_referer'] != 0 ) {
|
||||
add_filter( 'statify_skip_tracking', array( 'StatifyBlacklist', 'apply_blacklist_filter' ) );
|
||||
}
|
||||
|
||||
/* Admin only filters */
|
||||
if (is_admin()) {
|
||||
/* Load Textdomain (only needed for backend */
|
||||
load_plugin_textdomain( 'statifyblacklist', false, STATIFYBLACKLIST_DIR.'/lang/');
|
||||
/* Admin only filters */
|
||||
if ( is_admin() ) {
|
||||
/* Load Textdomain (only needed for backend */
|
||||
load_plugin_textdomain( 'statifyblacklist', false, STATIFYBLACKLIST_DIR . '/lang/' );
|
||||
|
||||
/* Add actions */
|
||||
add_action('wpmu_new_blog', array('StatifyBlacklist_Install', 'init_site'));
|
||||
add_action('delete_blog', array('StatifyBlacklist_System', 'init_site'));
|
||||
add_filter('plugin_row_meta', array('StatifyBlacklist_Admin', 'plugin_meta_link'), 10, 2);
|
||||
/* Add actions */
|
||||
add_action( 'wpmu_new_blog', array( 'StatifyBlacklist_Install', 'init_site' ) );
|
||||
add_action( 'delete_blog', array( 'StatifyBlacklist_System', 'init_site' ) );
|
||||
add_filter( 'plugin_row_meta', array( 'StatifyBlacklist_Admin', 'plugin_meta_link' ), 10, 2 );
|
||||
|
||||
if (is_multisite()) {
|
||||
add_action('network_admin_menu', array('StatifyBlacklist_Admin', '_add_menu_page'));
|
||||
add_filter('network_admin_plugin_action_links', array('StatifyBlacklist_Admin', 'plugin_actions_links'), 10, 2);
|
||||
} else {
|
||||
add_action('admin_menu', array('StatifyBlacklist_Admin', '_add_menu_page'));
|
||||
add_filter('plugin_action_links', array('StatifyBlacklist_Admin', 'plugin_actions_links'), 10, 2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( is_multisite() ) {
|
||||
add_action( 'network_admin_menu', array( 'StatifyBlacklist_Admin', '_add_menu_page' ) );
|
||||
add_filter( 'network_admin_plugin_action_links', array(
|
||||
'StatifyBlacklist_Admin',
|
||||
'plugin_actions_links'
|
||||
), 10, 2 );
|
||||
} else {
|
||||
add_action( 'admin_menu', array( 'StatifyBlacklist_Admin', '_add_menu_page' ) );
|
||||
add_filter( 'plugin_action_links', array( 'StatifyBlacklist_Admin', 'plugin_actions_links' ), 10, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update options
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @changed 1.1.1
|
||||
*/
|
||||
public static function update_options() {
|
||||
self::$_options = wp_parse_args(
|
||||
get_option('statify-blacklist'),
|
||||
array(
|
||||
'active_referer' => 0,
|
||||
'referer' => array()
|
||||
)
|
||||
);
|
||||
}
|
||||
/* CronJob to clean up database */
|
||||
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
|
||||
if ( self::$_options['cron_referer'] == 1 ) {
|
||||
add_action( 'statify_cleanup', array( 'StatifyBlacklist_Admin', 'cleanup_database' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the blacklist filter if active
|
||||
*
|
||||
* @return TRUE if referer matches blacklist.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function apply_blacklist_filter() {
|
||||
/* Skip if blacklist is inactive */
|
||||
if (self::$_options['active_referer'] != 1) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Update options
|
||||
*
|
||||
* @param $options array New options to save
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @changed 1.1.1
|
||||
*/
|
||||
public static function update_options( $options = null ) {
|
||||
self::$_options = wp_parse_args(
|
||||
get_option( 'statify-blacklist' ),
|
||||
array(
|
||||
'active_referer' => 0,
|
||||
'cron_referer' => 0,
|
||||
'referer' => array(),
|
||||
'referer_regexp' => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/* Extract relevant domain parts */
|
||||
$referer = strtolower( ( isset($_SERVER['HTTP_REFERER']) ? parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) : '' ) );
|
||||
$referer = explode('.', $referer);
|
||||
if( count($referer) >1 )
|
||||
$referer = implode('.', array_slice($referer, -2));
|
||||
else
|
||||
$referer = implode('.', $referer);
|
||||
/**
|
||||
* Apply the blacklist filter if active
|
||||
*
|
||||
* @return TRUE if referer matches blacklist.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @changed 1.3.1
|
||||
*/
|
||||
public static function apply_blacklist_filter() {
|
||||
/* Skip if blacklist is inactive */
|
||||
if ( self::$_options['active_referer'] != 1 ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get blacklist */
|
||||
$blacklist = self::$_options['referer'];
|
||||
/* Regular Expression filtering since 1.3.0 */
|
||||
if ( isset(self::$_options['referer_regexp']) && self::$_options['referer_regexp'] > 0 ) {
|
||||
/* Get full referer string */
|
||||
$referer = ( isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '' );
|
||||
/* Merge given regular expressions into one */
|
||||
$regexp = '/' . implode( "|", array_keys( self::$_options['referer'] ) ) . '/';
|
||||
if ( self::$_options['referer_regexp'] == 2 ) {
|
||||
$regexp .= 'i';
|
||||
}
|
||||
/* Check blacklist (return NULL to continue filtering) */
|
||||
return (preg_match( $regexp, $referer) === 1) ? true : NULL;
|
||||
} else {
|
||||
/* Extract relevant domain parts */
|
||||
$referer = strtolower( ( isset( $_SERVER['HTTP_REFERER'] ) ? parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ) : '' ) );
|
||||
|
||||
/* Check blacklist */
|
||||
return in_array($referer, $blacklist);
|
||||
}
|
||||
/* Get blacklist */
|
||||
$blacklist = self::$_options['referer'];
|
||||
|
||||
/* Check blacklist (return NULL to continue filtering) */
|
||||
return isset($blacklist[ $referer]) ? true : NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,144 +1,177 @@
|
||||
<?php
|
||||
|
||||
/* Quit */
|
||||
defined('ABSPATH') OR exit;
|
||||
defined( 'ABSPATH' ) OR exit;
|
||||
|
||||
/**
|
||||
* Statify Blacklist admin configuration
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class StatifyBlacklist_Admin extends StatifyBlacklist
|
||||
{
|
||||
/**
|
||||
* Update options
|
||||
*
|
||||
* @return mixed array of sanitized array on errors, FALSE if there were none
|
||||
* @since 1.1.1
|
||||
*/
|
||||
public static function update_options($options) {
|
||||
if (isset($options) && current_user_can('manage_options')) {
|
||||
/* Sanitize URLs and remove empty inputs */
|
||||
$givenReferer = $options['referer'];
|
||||
$sanitizedReferer = self::sanitizeURLs($givenReferer);
|
||||
class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
/**
|
||||
* Update options
|
||||
*
|
||||
* @param $options array New options to save
|
||||
* @return mixed array of sanitized array on errors, FALSE if there were none
|
||||
* @since 1.1.1
|
||||
* @changed 1.3.0
|
||||
*/
|
||||
public static function update_options( $options = null ) {
|
||||
if ( isset( $options ) && current_user_can( 'manage_options' ) ) {
|
||||
/* Sanitize URLs and remove empty inputs */
|
||||
$givenReferer = $options['referer'];
|
||||
if ($options['referer_regexp'] == 0)
|
||||
$sanitizedReferer = self::sanitizeURLs( $givenReferer );
|
||||
else
|
||||
$sanitizedReferer = $givenReferer;
|
||||
|
||||
/* Abort on errors */
|
||||
if (!empty(array_diff($givenReferer, $sanitizedReferer))) {
|
||||
return $sanitizedReferer;
|
||||
}
|
||||
/* Abort on errors */
|
||||
if ( ! empty( array_diff( $givenReferer, $sanitizedReferer ) ) ) {
|
||||
return $sanitizedReferer;
|
||||
}
|
||||
|
||||
/* Update database on success */
|
||||
if ((is_multisite() && array_key_exists(STATIFYBLACKLIST_BASE, (array)get_site_option('active_sitewide_plugins'))))
|
||||
update_site_option('statify-blacklist', $options);
|
||||
else
|
||||
update_option('statify-blacklist', $options);
|
||||
}
|
||||
/* Update database on success */
|
||||
if ( ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ) ) {
|
||||
update_site_option( 'statify-blacklist', $options );
|
||||
} else {
|
||||
update_option( 'statify-blacklist', $options );
|
||||
}
|
||||
}
|
||||
|
||||
/* Refresh options */
|
||||
parent::update_options();
|
||||
/* Refresh options */
|
||||
parent::update_options( $options );
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add configuration page to admin menu
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function _add_menu_page() {
|
||||
$title = __( 'Statify Blacklist', 'statify-blacklist' );
|
||||
if (self::$multisite)
|
||||
add_submenu_page( 'settings.php', $title, $title, 'manage_network_plugins', 'statify-blacklist-settings', array('StatifyBlacklist_Admin', 'settings_page') );
|
||||
else
|
||||
add_submenu_page( 'options-general.php', $title, $title, 'manage_options', 'statify-blacklist', array('StatifyBlacklist_Admin', 'settings_page') );
|
||||
/**
|
||||
* Add configuration page to admin menu
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function _add_menu_page() {
|
||||
$title = __( 'Statify Blacklist', 'statify-blacklist' );
|
||||
if ( self::$multisite ) {
|
||||
add_submenu_page( 'settings.php', $title, $title, 'manage_network_plugins', 'statify-blacklist-settings', array(
|
||||
'StatifyBlacklist_Admin',
|
||||
'settings_page'
|
||||
) );
|
||||
} else {
|
||||
add_submenu_page( 'options-general.php', $title, $title, 'manage_options', 'statify-blacklist', array(
|
||||
'StatifyBlacklist_Admin',
|
||||
'settings_page'
|
||||
) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static function settings_page() {
|
||||
include STATIFYBLACKLIST_DIR . '/views/settings_page.php';
|
||||
}
|
||||
public static function settings_page() {
|
||||
include STATIFYBLACKLIST_DIR . '/views/settings_page.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add plugin meta links
|
||||
*
|
||||
* @param $links
|
||||
* @param $file
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function plugin_meta_link($links, $file) {
|
||||
if ($file == STATIFYBLACKLIST_BASE) {
|
||||
$links[] = '<a href="https://github.com/stklcode/statify-blacklist">GitHub</a>';
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
/**
|
||||
* Add plugin meta links
|
||||
*
|
||||
* @param $links
|
||||
* @param $file
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function plugin_meta_link( $links, $file ) {
|
||||
if ( $file == STATIFYBLACKLIST_BASE ) {
|
||||
$links[] = '<a href="https://github.com/stklcode/statify-blacklist">GitHub</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add plugin action links
|
||||
*
|
||||
* @param array $input Registered links
|
||||
* @return array Merged links
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function plugin_actions_links($links, $file) {
|
||||
$base = self::$multisite ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );
|
||||
return $links;
|
||||
}
|
||||
|
||||
if( $file == STATIFYBLACKLIST_BASE && current_user_can('manage_options') ) {
|
||||
array_unshift(
|
||||
$links,
|
||||
sprintf( '<a href="%s">%s</a>', esc_attr(add_query_arg( 'page', 'statify-blacklist', $base )), __('Settings'))
|
||||
);
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
/**
|
||||
* Add plugin action links
|
||||
*
|
||||
* @param array $input Registered links
|
||||
*
|
||||
* @return array Merged links
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function plugin_actions_links( $links, $file ) {
|
||||
$base = self::$multisite ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );
|
||||
|
||||
/**
|
||||
* Filter database for cleanup.
|
||||
*
|
||||
* @since 1.1.0
|
||||
* @changed 1.1.1
|
||||
*/
|
||||
public static function cleanup_database() {
|
||||
/* Check user permissions */
|
||||
if (!current_user_can('manage_options'))
|
||||
die(_e('Are you sure you want to do this?'));
|
||||
if ( $file == STATIFYBLACKLIST_BASE && current_user_can( 'manage_options' ) ) {
|
||||
array_unshift(
|
||||
$links,
|
||||
sprintf( '<a href="%s">%s</a>', esc_attr( add_query_arg( 'page', 'statify-blacklist', $base ) ), __( 'Settings' ) )
|
||||
);
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
return $links;
|
||||
}
|
||||
|
||||
/* Sanitize URLs */
|
||||
$referer = self::sanitizeURLs(self::$_options['referer']);
|
||||
/**
|
||||
* Filter database for cleanup.
|
||||
*
|
||||
* @since 1.1.0
|
||||
* @changed 1.3.0
|
||||
*/
|
||||
public static function cleanup_database() {
|
||||
/* Check user permissions */
|
||||
if ( ! current_user_can( 'manage_options' ) && ! ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
|
||||
die( _e( 'Are you sure you want to do this?' ) );
|
||||
}
|
||||
|
||||
/* Build filter regexp */
|
||||
$refererRegexp = str_replace('.', '\.', implode('|', $referer));
|
||||
if (!empty($refererRegexp)) {
|
||||
/* Execute filter on database */
|
||||
$wpdb->query(
|
||||
$wpdb->prepare("DELETE FROM `$wpdb->statify` WHERE referrer REGEXP %s", $refererRegexp)
|
||||
);
|
||||
global $wpdb;
|
||||
|
||||
/* Optimize DB */
|
||||
$wpdb->query("OPTIMIZE TABLE `$wpdb->statify`");
|
||||
}
|
||||
}
|
||||
if ( isset( self::$_options['referer_regexp'] ) && self::$_options['referer_regexp'] > 0 ) {
|
||||
/* Merge given regular expressions into one */
|
||||
$refererRegexp = implode( "|", array_keys( self::$_options['referer'] ) );
|
||||
} else {
|
||||
/* Sanitize URLs */
|
||||
$referer = self::sanitizeURLs( self::$_options['referer'] );
|
||||
|
||||
/* Build filter regexp */
|
||||
$refererRegexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $refererRegexp ) ) {
|
||||
/* Execute filter on database */
|
||||
$wpdb->query(
|
||||
$wpdb->prepare( "DELETE FROM `$wpdb->statify` WHERE "
|
||||
. ( ( self::$_options['referer_regexp'] == 1 ) ? " BINARY " : "" )
|
||||
. "referrer REGEXP %s", $refererRegexp )
|
||||
);
|
||||
|
||||
/* Optimize DB */
|
||||
$wpdb->query( "OPTIMIZE TABLE `$wpdb->statify`" );
|
||||
|
||||
/* Delete transient statify data */
|
||||
delete_transient( 'statify_data' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sanitize URLs and remove empty results
|
||||
* @param $urls array given array of URLs
|
||||
* @return array sanitized array
|
||||
*
|
||||
* @since 1.1.1
|
||||
*/
|
||||
private static function sanitizeURLs($urls) {
|
||||
return array_filter(
|
||||
array_map(
|
||||
function($r) {
|
||||
return preg_replace('/[^\da-z\.-]/i', '', filter_var($r, FILTER_SANITIZE_URL));
|
||||
},
|
||||
$urls
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sanitize URLs and remove empty results
|
||||
*
|
||||
* @param $urls array given array of URLs
|
||||
*
|
||||
* @return array sanitized array
|
||||
*
|
||||
* @since 1.1.1
|
||||
* @changed 1.2.0
|
||||
*/
|
||||
private static function sanitizeURLs( $urls ) {
|
||||
return array_flip(
|
||||
array_filter(
|
||||
array_map(
|
||||
function ( $r ) {
|
||||
return preg_replace( '/[^\da-z\.-]/i', '', filter_var( $r, FILTER_SANITIZE_URL ) );
|
||||
},
|
||||
array_flip( $urls )
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +1,114 @@
|
||||
<?php
|
||||
|
||||
/* Quit */
|
||||
defined('ABSPATH') OR exit;
|
||||
defined( 'ABSPATH' ) OR exit;
|
||||
|
||||
/**
|
||||
* Statify Blacklist system configuration
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class StatifyBlacklist_System extends StatifyBlacklist
|
||||
{
|
||||
/**
|
||||
* Plugin install handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param bool $network_wide Whether the plugin was activated network-wide or not.
|
||||
*/
|
||||
public static function install( $network_wide = false ) {
|
||||
global $wpdb;
|
||||
class StatifyBlacklist_System extends StatifyBlacklist {
|
||||
|
||||
// Create tables for each site in a network.
|
||||
if ( is_multisite() && $network_wide ) {
|
||||
// Todo: Use get_sites() in WordPress 4.6+
|
||||
$ids = $wpdb->get_col( "SELECT blog_id FROM `$wpdb->blogs`" );
|
||||
const VERSION_MAIN = 1.3;
|
||||
|
||||
foreach ( $ids as $site_id ) {
|
||||
switch_to_blog( $site_id );
|
||||
add_option(
|
||||
'statify-blacklist',
|
||||
array()
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Plugin install handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param bool $network_wide Whether the plugin was activated network-wide or not.
|
||||
*/
|
||||
public static function install( $network_wide = false ) {
|
||||
global $wpdb;
|
||||
|
||||
restore_current_blog();
|
||||
} else {
|
||||
add_option(
|
||||
'statify-blacklist',
|
||||
array()
|
||||
);
|
||||
}
|
||||
}
|
||||
// Create tables for each site in a network.
|
||||
if ( is_multisite() && $network_wide ) {
|
||||
// Todo: Use get_sites() in WordPress 4.6+
|
||||
$ids = $wpdb->get_col( "SELECT blog_id FROM `$wpdb->blogs`" );
|
||||
|
||||
foreach ( $ids as $site_id ) {
|
||||
switch_to_blog( $site_id );
|
||||
add_option(
|
||||
'statify-blacklist',
|
||||
array(
|
||||
'activate-referer' => 0,
|
||||
'referer' => array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
restore_current_blog();
|
||||
} else {
|
||||
add_option(
|
||||
'statify-blacklist',
|
||||
array(
|
||||
'activate-referer' => 0,
|
||||
'referer' => array()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plugin uninstall handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function uninstall() {
|
||||
global $wpdb;
|
||||
/**
|
||||
* Plugin uninstall handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function uninstall() {
|
||||
global $wpdb;
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$old = get_current_blog_id();
|
||||
if ( is_multisite() ) {
|
||||
$old = get_current_blog_id();
|
||||
|
||||
// Todo: Use get_sites() in WordPress 4.6+
|
||||
$ids = $wpdb->get_col( "SELECT blog_id FROM `$wpdb->blogs`" );
|
||||
// Todo: Use get_sites() in WordPress 4.6+
|
||||
$ids = $wpdb->get_col( "SELECT blog_id FROM `$wpdb->blogs`" );
|
||||
|
||||
foreach ( $ids as $id ) {
|
||||
switch_to_blog( $id );
|
||||
delete_option('statify-blacklist');
|
||||
}
|
||||
foreach ( $ids as $id ) {
|
||||
switch_to_blog( $id );
|
||||
delete_option( 'statify-blacklist' );
|
||||
}
|
||||
|
||||
switch_to_blog( $old );
|
||||
}
|
||||
switch_to_blog( $old );
|
||||
}
|
||||
|
||||
delete_option('statify-blacklist');
|
||||
}
|
||||
}
|
||||
delete_option( 'statify-blacklist' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upgrade plugin options.
|
||||
*
|
||||
* @since 1.2.0
|
||||
* @changed 1.3.0
|
||||
*/
|
||||
public static function upgrade() {
|
||||
self::update_options();
|
||||
/* Check if config array is not associative (pre 1.2.0) */
|
||||
if ( array_keys( self::$_options['referer'] ) === range( 0, count( self::$_options['referer'] ) - 1 ) ) {
|
||||
/* Flip referer array to make domains keys */
|
||||
$options = self::$_options;
|
||||
$options['referer'] = array_flip( self::$_options['referer'] );
|
||||
if ( ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ) ) {
|
||||
update_site_option( 'statify-blacklist', $options );
|
||||
} else {
|
||||
update_option( 'statify-blacklist', $options );
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if version is set (not before 1.3.0) */
|
||||
if ( ! isset( self::$_options['version'] ) ) {
|
||||
$options = self::$_options;
|
||||
/* Set version */
|
||||
$options['version'] = self::VERSION_MAIN;
|
||||
/* Add regular expression option (as of 1.3) */
|
||||
$options['referer_regexp'] = 0;
|
||||
if ( ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ) ) {
|
||||
update_site_option( 'statify-blacklist', $options );
|
||||
} else {
|
||||
update_option( 'statify-blacklist', $options );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,41 +8,45 @@ Author: Stefan Kalscheuer
|
||||
Author URI: https://stklcode.de
|
||||
Plugin URI: https://wordpress.org/plugins/statify-blacklist
|
||||
License: GPLv3 or later
|
||||
Version: 1.1.2
|
||||
Version: 1.3.1
|
||||
*/
|
||||
|
||||
/* Quit */
|
||||
defined('ABSPATH') OR exit;
|
||||
defined( 'ABSPATH' ) OR exit;
|
||||
|
||||
/* Constants */
|
||||
define('STATIFYBLACKLIST_FILE', __FILE__);
|
||||
define('STATIFYBLACKLIST_DIR', dirname(__FILE__));
|
||||
define('STATIFYBLACKLIST_BASE', plugin_basename(__FILE__));
|
||||
define( 'STATIFYBLACKLIST_FILE', __FILE__ );
|
||||
define( 'STATIFYBLACKLIST_DIR', dirname( __FILE__ ) );
|
||||
define( 'STATIFYBLACKLIST_BASE', plugin_basename( __FILE__ ) );
|
||||
|
||||
/* System Hooks */
|
||||
add_action('plugins_loaded', array('StatifyBlacklist', 'instance'));
|
||||
add_action( 'plugins_loaded', array( 'StatifyBlacklist', 'instance' ) );
|
||||
|
||||
register_activation_hook(STATIFYBLACKLIST_FILE, array('StatifyBlacklist_System', 'install'));
|
||||
register_activation_hook( STATIFYBLACKLIST_FILE, array( 'StatifyBlacklist_System', 'install' ) );
|
||||
|
||||
register_uninstall_hook(STATIFYBLACKLIST_FILE, array('StatifyBlacklist_System', 'uninstall'));
|
||||
register_uninstall_hook( STATIFYBLACKLIST_FILE, array( 'StatifyBlacklist_System', 'uninstall' ) );
|
||||
|
||||
/* Upgrade hook */
|
||||
register_activation_hook( STATIFYBLACKLIST_FILE, array( 'StatifyBlacklist_System', 'upgrade' ) );
|
||||
|
||||
/* Autoload */
|
||||
spl_autoload_register('statifyBlacklist_autoload');
|
||||
spl_autoload_register( 'statifyBlacklist_autoload' );
|
||||
|
||||
/**
|
||||
* Autoloader for StatifyBlacklist classes.
|
||||
*
|
||||
* @param $class
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function statifyBlacklist_autoload($class) {
|
||||
$plugin_classes = array(
|
||||
'StatifyBlacklist',
|
||||
'StatifyBlacklist_Admin',
|
||||
'StatifyBlacklist_System'
|
||||
);
|
||||
function statifyBlacklist_autoload( $class ) {
|
||||
$plugin_classes = array(
|
||||
'StatifyBlacklist',
|
||||
'StatifyBlacklist_Admin',
|
||||
'StatifyBlacklist_System'
|
||||
);
|
||||
|
||||
if (in_array($class, $plugin_classes)) {
|
||||
require_once(sprintf('%s/inc/%s.class.php', STATIFYBLACKLIST_DIR, strtolower($class)));
|
||||
}
|
||||
if ( in_array( $class, $plugin_classes ) ) {
|
||||
require_once( sprintf( '%s/inc/%s.class.php', STATIFYBLACKLIST_DIR, strtolower( $class ) ) );
|
||||
}
|
||||
}
|
||||
|
95
test/StatifyBlacklistTest.php
Normal file
95
test/StatifyBlacklistTest.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
const ABSPATH = false;
|
||||
require_once( '../inc/statifyblacklist.class.php' );
|
||||
|
||||
/**
|
||||
* Class StatifyBlacklistTest
|
||||
*
|
||||
* PHPUnit test class for StatifyBlacklist
|
||||
*/
|
||||
class StatifyBlacklistTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testFilter() {
|
||||
/* Prepare Options: 2 blacklisted domains, disabled */
|
||||
StatifyBlacklist::$_options = array(
|
||||
'active_referer' => 0,
|
||||
'cron_referer' => 0,
|
||||
'referer' => array(
|
||||
'example.com' => 0,
|
||||
'example.net' => 1
|
||||
)
|
||||
);
|
||||
|
||||
/* No multisite */
|
||||
StatifyBlacklist::$multisite = false;
|
||||
|
||||
/* No referer */
|
||||
unset( $_SERVER['HTTP_REFERER'] );
|
||||
$this->assertFalse( StatifyBlacklist::apply_blacklist_filter() );
|
||||
/* Non-blacklisted referer */
|
||||
$_SERVER['HTTP_REFERER'] = 'http://example.org';
|
||||
$this->assertFalse( StatifyBlacklist::apply_blacklist_filter() );
|
||||
/* Blacklisted referer */
|
||||
$_SERVER['HTTP_REFERER'] = 'http://example.com';
|
||||
$this->assertFalse( StatifyBlacklist::apply_blacklist_filter() );
|
||||
/* Blacklisted referer with path */
|
||||
$_SERVER['HTTP_REFERER'] = 'http://example.net/foo/bar.html';
|
||||
$this->assertFalse( StatifyBlacklist::apply_blacklist_filter() );
|
||||
|
||||
/* Activate filter and run tests again */
|
||||
StatifyBlacklist::$_options['active_referer'] = 1;
|
||||
|
||||
unset( $_SERVER['HTTP_REFERER'] );
|
||||
$this->assertFalse( StatifyBlacklist::apply_blacklist_filter() );
|
||||
|
||||
$_SERVER['HTTP_REFERER'] = 'http://example.org';
|
||||
$this->assertFalse( StatifyBlacklist::apply_blacklist_filter() );
|
||||
|
||||
$_SERVER['HTTP_REFERER'] = 'http://example.com';
|
||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||
|
||||
$_SERVER['HTTP_REFERER'] = 'http://example.net/foo/bar.html';
|
||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||
}
|
||||
|
||||
public function testRegexFilter() {
|
||||
/* Prepare Options: 2 regular expressions */
|
||||
StatifyBlacklist::$_options = array(
|
||||
'active_referer' => 1,
|
||||
'cron_referer' => 0,
|
||||
'referer' => array(
|
||||
'example.[a-z]+' => 0,
|
||||
'test' => 1
|
||||
),
|
||||
'referer_regexp' => 1
|
||||
);
|
||||
|
||||
/* No multisite */
|
||||
StatifyBlacklist::$multisite = false;
|
||||
|
||||
/* No referer */
|
||||
unset( $_SERVER['HTTP_REFERER'] );
|
||||
$this->assertFalse( StatifyBlacklist::apply_blacklist_filter() );
|
||||
/* Non-blacklisted referer */
|
||||
$_SERVER['HTTP_REFERER'] = 'http://not.evil';
|
||||
$this->assertFalse( StatifyBlacklist::apply_blacklist_filter() );
|
||||
/* Blacklisted referer */
|
||||
$_SERVER['HTTP_REFERER'] = 'http://example.com';
|
||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||
/* Blacklisted referer with path */
|
||||
$_SERVER['HTTP_REFERER'] = 'http://foobar.net/test/me';
|
||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||
/* Matching both */
|
||||
$_SERVER['HTTP_REFERER'] = 'http://example.net/test/me';
|
||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||
/* Mathinc with wrong case */
|
||||
$_SERVER['HTTP_REFERER'] = 'http://eXaMpLe.NeT/tEsT/mE';
|
||||
$this->assertFalse( StatifyBlacklist::apply_blacklist_filter() );
|
||||
|
||||
/* Set RegExp filter to case insensitive */
|
||||
StatifyBlacklist::$_options['referer_regexp'] = 2;
|
||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||
}
|
||||
|
||||
}
|
195
views/settings_page.php
Normal file → Executable file
195
views/settings_page.php
Normal file → Executable file
@ -1,94 +1,131 @@
|
||||
<?php
|
||||
|
||||
/* Quit */
|
||||
defined('ABSPATH') OR exit;
|
||||
defined( 'ABSPATH' ) OR exit;
|
||||
|
||||
/* Update plugin options */
|
||||
if ( !empty($_POST['statifyblacklist']) ) {
|
||||
/* Verify nonce */
|
||||
check_admin_referer( 'statify-blacklist-settings' );
|
||||
if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
||||
/* Verify nonce */
|
||||
check_admin_referer( 'statify-blacklist-settings' );
|
||||
|
||||
/* Check user capabilities */
|
||||
if (!current_user_can('manage_options')) {
|
||||
die(_e('Are you sure you want to do this?'));
|
||||
}
|
||||
/* Check user capabilities */
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
die( _e( 'Are you sure you want to do this?' ) );
|
||||
}
|
||||
|
||||
if (!empty($_POST['cleanUp'])) {
|
||||
/* CleanUp DB */
|
||||
StatifyBlacklist_Admin::cleanup_database();
|
||||
} else {
|
||||
/* Extract referer array */
|
||||
if (empty(trim($_POST['statifyblacklist']['referer']))) $referer = array();
|
||||
else $referer = explode("\r\n", $_POST['statifyblacklist']['referer']);
|
||||
if ( ! empty( $_POST['cleanUp'] ) ) {
|
||||
/* CleanUp DB */
|
||||
StatifyBlacklist_Admin::cleanup_database();
|
||||
} else {
|
||||
/* Extract referer array */
|
||||
if ( empty( trim( $_POST['statifyblacklist']['referer'] ) ) ) {
|
||||
$referer = array();
|
||||
} else {
|
||||
$referer = explode( "\r\n", $_POST['statifyblacklist']['referer'] );
|
||||
}
|
||||
|
||||
/* Update options (data will be sanitized) */
|
||||
$statifyBlacklistUpdateResult= StatifyBlacklist_Admin::update_options(
|
||||
array(
|
||||
'active_referer' => (int)@$_POST['statifyblacklist']['active_referer'],
|
||||
'referer' => $referer
|
||||
)
|
||||
);
|
||||
/* Update options (data will be sanitized) */
|
||||
$statifyBlacklistUpdateResult = StatifyBlacklist_Admin::update_options(
|
||||
array(
|
||||
'active_referer' => (int) @$_POST['statifyblacklist']['active_referer'],
|
||||
'cron_referer' => (int) @$_POST['statifyblacklist']['cron_referer'],
|
||||
'referer' => array_flip( $referer ),
|
||||
'referer_regexp' => (int) @$_POST['statifyblacklist']['referer_regexp']
|
||||
)
|
||||
);
|
||||
|
||||
/* Generate messages */
|
||||
if ($statifyBlacklistUpdateResult !== false) {
|
||||
$statifyBlacklistPostWarning = 'Some URLs are invalid and have been sanitized. Settings have not been saved yet.';
|
||||
} else {
|
||||
$statifyBlacklistPostSuccess = 'Settings updated successfully.';
|
||||
}
|
||||
}
|
||||
/* Generate messages */
|
||||
if ( $statifyBlacklistUpdateResult !== false ) {
|
||||
$statifyBlacklistPostWarning = 'Some URLs are invalid and have been sanitized. Settings have not been saved yet.';
|
||||
} else {
|
||||
$statifyBlacklistPostSuccess = 'Settings updated successfully.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php _e( 'Statify Blacklist', 'statify-blacklist') ?></h1>
|
||||
<?php
|
||||
if (is_plugin_inactive('statify/statify.php')) {
|
||||
print '<div class="notice notice-warning"><p>';
|
||||
esc_html_e('Statify plugin is not active.', 'statify-blacklist');
|
||||
print '</p></div>';
|
||||
}
|
||||
if (isset($statifyBlacklistPostWarning)) {
|
||||
print '<div class="notice notice-warning"><p>';
|
||||
esc_html_e($statifyBlacklistPostWarning);
|
||||
print '</p></div>';
|
||||
}
|
||||
if (isset($statifyBlacklistPostSuccess)) {
|
||||
print '<div class="notice notice-success"><p>';
|
||||
esc_html_e($statifyBlacklistPostSuccess);
|
||||
print '</p></div>';
|
||||
}
|
||||
?>
|
||||
<form action="" method="post" id="statify-blacklist-settings">
|
||||
<ul style="list-style: none;">
|
||||
<li>
|
||||
<label for="statify-blacklist_active_referer">
|
||||
<input type="checkbox" name="statifyblacklist[active_referer]" id="statifyblacklist_active_referer" value="1" <?php checked(StatifyBlacklist::$_options['active_referer'], 1); ?> />
|
||||
<?php esc_html_e('Activate referer blacklist', 'statify-blacklist'); ?>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label for="statify-blacklist_referer">
|
||||
<?php esc_html_e('Referer blacklist:', 'statify-blacklist'); ?><br />
|
||||
<textarea cols="40" rows="5" name="statifyblacklist[referer]" id="statify-blacklist_referer"><?php
|
||||
if (isset($statifyBlacklistUpdateResult) &&$statifyBlacklistUpdateResult !== false)
|
||||
print esc_html(implode("\r\n", $statifyBlacklistUpdateResult));
|
||||
else
|
||||
print esc_html(implode("\r\n", StatifyBlacklist::$_options['referer']));
|
||||
?></textarea><br />
|
||||
<small>(<?php esc_html_e('Add one domain (without subdomains) each line, e.g. example.com', 'statify-blacklist'); ?>)</small>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
<?php wp_nonce_field('statify-blacklist-settings'); ?>
|
||||
<h1><?php _e( 'Statify Blacklist', 'statify-blacklist' ) ?></h1>
|
||||
<?php
|
||||
if ( is_plugin_inactive( 'statify/statify.php' ) ) {
|
||||
print '<div class="notice notice-warning"><p>';
|
||||
esc_html_e( 'Statify plugin is not active.', 'statify-blacklist' );
|
||||
print '</p></div>';
|
||||
}
|
||||
if ( isset( $statifyBlacklistPostWarning ) ) {
|
||||
print '<div class="notice notice-warning"><p>';
|
||||
esc_html_e( $statifyBlacklistPostWarning );
|
||||
print '</p></div>';
|
||||
}
|
||||
if ( isset( $statifyBlacklistPostSuccess ) ) {
|
||||
print '<div class="notice notice-success"><p>';
|
||||
esc_html_e( $statifyBlacklistPostSuccess );
|
||||
print '</p></div>';
|
||||
}
|
||||
?>
|
||||
<form action="" method="post" id="statify-blacklist-settings">
|
||||
<ul style="list-style: none;">
|
||||
<li>
|
||||
<label for="statify-blacklist_active_referer">
|
||||
<input type="checkbox" name="statifyblacklist[active_referer]" id="statifyblacklist_active_referer"
|
||||
value="1" <?php checked( StatifyBlacklist::$_options['active_referer'], 1 ); ?> />
|
||||
<?php esc_html_e( 'Activate referer blacklist', 'statify-blacklist' ); ?>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label for="statify-blacklist_cron_referer">
|
||||
<input type="checkbox" name="statifyblacklist[cron_referer]" id="statifyblacklist_cron_referer"
|
||||
value="1" <?php checked( StatifyBlacklist::$_options['cron_referer'], 1 ); ?> />
|
||||
<?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?>
|
||||
<small>(<?php esc_html_e( 'Clean database periodically in background', 'statify-blacklist' ); ?>)</small>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label for="statify-blacklist_referer_regexp">
|
||||
<?php esc_html_e( 'Use regular expressions', 'statify-blacklist' ); ?>:
|
||||
<br />
|
||||
<select name="statifyblacklist[referer_regexp]" id="statifyblacklist_referer_regexp">
|
||||
<option value="0" <?php selected( StatifyBlacklist::$_options['referer_regexp'], 0 ); ?>>
|
||||
<?php esc_html_e( 'Disabled', 'statify-blacklist' ); ?>
|
||||
</option>
|
||||
<option value="1" <?php selected( StatifyBlacklist::$_options['referer_regexp'], 1 ); ?>>
|
||||
<?php esc_html_e( 'Case-sensitive', 'statify-blacklist' ); ?>
|
||||
</option>
|
||||
<option value="2" <?php selected( StatifyBlacklist::$_options['referer_regexp'], 2 ); ?>>
|
||||
<?php esc_html_e( 'Case-insensitive', 'statify-blacklist' ); ?>
|
||||
</option>
|
||||
</select>
|
||||
<small>(<?php esc_html_e( 'Performance slower than standard domain filter. Recommended for cron or manual execition only.', 'statify-blacklist' ); ?>)</small>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label for="statify-blacklist_referer">
|
||||
<?php esc_html_e( 'Referer blacklist:', 'statify-blacklist' ); ?><br/>
|
||||
<textarea cols="40" rows="5" name="statifyblacklist[referer]" id="statify-blacklist_referer"><?php
|
||||
if ( isset( $statifyBlacklistUpdateResult ) && $statifyBlacklistUpdateResult !== false ) {
|
||||
print esc_html( implode( "\r\n", array_keys( $statifyBlacklistUpdateResult ) ) );
|
||||
} else {
|
||||
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['referer'] ) ) );
|
||||
}
|
||||
?></textarea>
|
||||
<br />
|
||||
<small>
|
||||
(<?php esc_html_e( 'Add one domain (without subdomains) each line, e.g. example.com', 'statify-blacklist' ); ?>
|
||||
)
|
||||
</small>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
<?php wp_nonce_field( 'statify-blacklist-settings' ); ?>
|
||||
|
||||
<p class="submit">
|
||||
<input class="button-primary" type="submit" name="submit" value="<?php _e('Save Changes') ?>">
|
||||
<hr>
|
||||
<input class="button-secondary" type="submit" name="cleanUp" value="<?php esc_html_e('CleanUp Database', 'statify-blacklist') ?>"
|
||||
onclick="return confirm('Do you really want to apply filters to database? This cannot be undone.');">
|
||||
<br>
|
||||
<small><?php esc_html_e('Applies filter (even if disabled) to data stored in database. This cannot be undone!', 'statify-blacklist'); ?></small>
|
||||
</p>
|
||||
</form>
|
||||
<p class="submit">
|
||||
<input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes' ) ?>">
|
||||
<hr />
|
||||
<input class="button-secondary" type="submit" name="cleanUp"
|
||||
value="<?php esc_html_e( 'CleanUp Database', 'statify-blacklist' ) ?>"
|
||||
onclick="return confirm('Do you really want to apply filters to database? This cannot be undone.');">
|
||||
<br />
|
||||
<small><?php esc_html_e( 'Applies filter (even if disabled) to data stored in database. This cannot be undone!', 'statify-blacklist' ); ?></small>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user