remove underscore prefix from options field
This commit is contained in:
parent
a88a89c442
commit
84cf79fd04
@ -229,20 +229,20 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
}
|
||||
|
||||
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
|
||||
$clean_ref = ( 1 === self::$_options['referer']['cron'] );
|
||||
$clean_trg = ( 1 === self::$_options['target']['cron'] );
|
||||
$clean_ref = ( 1 === self::$options['referer']['cron'] );
|
||||
$clean_trg = ( 1 === self::$options['target']['cron'] );
|
||||
} else {
|
||||
$clean_ref = true;
|
||||
$clean_trg = true;
|
||||
}
|
||||
|
||||
if ( $clean_ref ) {
|
||||
if ( isset( self::$_options['referer']['regexp'] ) && self::$_options['referer']['regexp'] > 0 ) {
|
||||
if ( isset( self::$options['referer']['regexp'] ) && self::$options['referer']['regexp'] > 0 ) {
|
||||
// Merge given regular expressions into one.
|
||||
$referer_regexp = implode( '|', array_keys( self::$_options['referer']['blacklist'] ) );
|
||||
$referer_regexp = implode( '|', array_keys( self::$options['referer']['blacklist'] ) );
|
||||
} else {
|
||||
// Sanitize URLs.
|
||||
$referer = self::sanitize_urls( self::$_options['referer']['blacklist'] );
|
||||
$referer = self::sanitize_urls( self::$options['referer']['blacklist'] );
|
||||
|
||||
// Build filter regexp.
|
||||
$referer_regexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) );
|
||||
@ -250,12 +250,12 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
}
|
||||
|
||||
if ( $clean_trg ) {
|
||||
if ( isset( self::$_options['target']['regexp'] ) && self::$_options['target']['regexp'] > 0 ) {
|
||||
if ( isset( self::$options['target']['regexp'] ) && self::$options['target']['regexp'] > 0 ) {
|
||||
// Merge given regular expressions into one.
|
||||
$target_regexp = implode( '|', array_keys( self::$_options['target']['blacklist'] ) );
|
||||
$target_regexp = implode( '|', array_keys( self::$options['target']['blacklist'] ) );
|
||||
} else {
|
||||
// Build filter regexp.
|
||||
$target_regexp = str_replace( '.', '\.', implode( '|', array_flip( self::$_options['target']['blacklist'] ) ) );
|
||||
$target_regexp = str_replace( '.', '\.', implode( '|', array_flip( self::$options['target']['blacklist'] ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM `$wpdb->statify` WHERE "
|
||||
. ( ( 1 === self::$_options['referer']['regexp'] ) ? ' BINARY ' : '' )
|
||||
. ( ( 1 === self::$options['referer']['regexp'] ) ? ' BINARY ' : '' )
|
||||
. 'referrer REGEXP %s', $referer_regexp
|
||||
)
|
||||
);
|
||||
@ -277,7 +277,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM `$wpdb->statify` WHERE "
|
||||
. ( ( 1 === self::$_options['target']['regexp'] ) ? ' BINARY ' : '' )
|
||||
. ( ( 1 === self::$options['target']['regexp'] ) ? ' BINARY ' : '' )
|
||||
. 'target REGEXP %s', $target_regexp
|
||||
)
|
||||
);
|
||||
|
@ -134,10 +134,10 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
||||
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 ) ) {
|
||||
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'] );
|
||||
$options = self::$options;
|
||||
$options['referer'] = array_flip( self::$options['referer'] );
|
||||
if ( self::$multisite ) {
|
||||
update_site_option( 'statify-blacklist', $options );
|
||||
} else {
|
||||
@ -146,14 +146,14 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
||||
}
|
||||
|
||||
// Version not set (pre 1.3.0) or older than 1.4.
|
||||
if ( ! isset( self::$_options['version'] ) || self::$_options['version'] < 1.4 ) {
|
||||
if ( ! isset( self::$options['version'] ) || self::$options['version'] < 1.4 ) {
|
||||
// Upgrade options to new schema.
|
||||
$options = array(
|
||||
'referer' => array(
|
||||
'active' => self::$_options['active_referer'],
|
||||
'cron' => self::$_options['cron_referer'],
|
||||
'regexp' => self::$_options['referer_regexp'],
|
||||
'blacklist' => self::$_options['referer'],
|
||||
'active' => self::$options['active_referer'],
|
||||
'cron' => self::$options['cron_referer'],
|
||||
'regexp' => self::$options['referer_regexp'],
|
||||
'blacklist' => self::$options['referer'],
|
||||
),
|
||||
'target' => array(
|
||||
'active' => 0,
|
||||
@ -176,9 +176,9 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
||||
}
|
||||
|
||||
// Version older than current major release.
|
||||
if ( self::VERSION_MAIN > self::$_options['version'] ) {
|
||||
if ( self::VERSION_MAIN > self::$options['version'] ) {
|
||||
// Merge default options with current config, assuming only additive changes.
|
||||
$options = array_merge_recursive( self::default_options(), self::$_options );
|
||||
$options = array_merge_recursive( self::default_options(), self::$options );
|
||||
$options['version'] = self::VERSION_MAIN;
|
||||
if ( self::$multisite ) {
|
||||
update_site_option( 'statify-blacklist', $options );
|
||||
|
@ -61,9 +61,9 @@ class StatifyBlacklist {
|
||||
* Plugin options.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var array $_options
|
||||
* @var array $options
|
||||
*/
|
||||
public static $_options;
|
||||
public static $options;
|
||||
|
||||
/**
|
||||
* Multisite Status.
|
||||
@ -93,7 +93,7 @@ class StatifyBlacklist {
|
||||
self::update_options();
|
||||
|
||||
// Add Filter to statify hook if enabled.
|
||||
if ( 0 !== self::$_options['referer']['active'] || 0 !== self::$_options['target']['active'] || 0 !== self::$_options['ip']['active'] ) {
|
||||
if ( 0 !== self::$options['referer']['active'] || 0 !== self::$options['target']['active'] || 0 !== self::$options['ip']['active'] ) {
|
||||
add_filter( 'statify__skip_tracking', array( 'StatifyBlacklist', 'apply_blacklist_filter' ) );
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ class StatifyBlacklist {
|
||||
|
||||
// CronJob to clean up database.
|
||||
if ( defined( 'DOING_CRON' ) && DOING_CRON &&
|
||||
( 1 === self::$_options['referer']['cron'] || 1 === self::$_options['target']['cron'] ) ) {
|
||||
( 1 === self::$options['referer']['cron'] || 1 === self::$options['target']['cron'] ) ) {
|
||||
add_action( 'statify_cleanup', array( 'StatifyBlacklist_Admin', 'cleanup_database' ) );
|
||||
}
|
||||
}
|
||||
@ -125,7 +125,7 @@ class StatifyBlacklist {
|
||||
} else {
|
||||
$o = get_option( 'statify-blacklist' );
|
||||
}
|
||||
self::$_options = wp_parse_args( $o, self::default_options() );
|
||||
self::$options = wp_parse_args( $o, self::default_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,9 +166,9 @@ class StatifyBlacklist {
|
||||
*/
|
||||
public static function apply_blacklist_filter() {
|
||||
// Referer blacklist.
|
||||
if ( isset( self::$_options['referer']['active'] ) && 0 !== self::$_options['referer']['active'] ) {
|
||||
if ( isset( self::$options['referer']['active'] ) && 0 !== self::$options['referer']['active'] ) {
|
||||
// Determine filter mode.
|
||||
$mode = isset( self::$_options['referer']['regexp'] ) ? intval( self::$_options['referer']['regexp'] ) : 0;
|
||||
$mode = isset( self::$options['referer']['regexp'] ) ? intval( self::$options['referer']['regexp'] ) : 0;
|
||||
|
||||
// Get full referer string.
|
||||
$referer = wp_get_raw_referer();
|
||||
@ -183,8 +183,8 @@ class StatifyBlacklist {
|
||||
case self::MODE_REGEX_CI:
|
||||
// Merge given regular expressions into one.
|
||||
$regexp = self::regex(
|
||||
array_keys( self::$_options['referer']['blacklist'] ),
|
||||
self::MODE_REGEX_CI === self::$_options['referer']['regexp']
|
||||
array_keys( self::$options['referer']['blacklist'] ),
|
||||
self::MODE_REGEX_CI === self::$options['referer']['regexp']
|
||||
);
|
||||
|
||||
// Check blacklist (no return to continue filtering #12).
|
||||
@ -196,7 +196,7 @@ class StatifyBlacklist {
|
||||
// Keyword filter since 1.5.0 (#15).
|
||||
case self::MODE_KEYWORD:
|
||||
// Get blacklist.
|
||||
$blacklist = self::$_options['referer']['blacklist'];
|
||||
$blacklist = self::$options['referer']['blacklist'];
|
||||
|
||||
foreach ( array_keys( $blacklist ) as $keyword ) {
|
||||
if ( false !== strpos( strtolower( $referer ), strtolower( $keyword ) ) ) {
|
||||
@ -212,7 +212,7 @@ class StatifyBlacklist {
|
||||
$referer = strtolower( ( isset( $referer['host'] ) ? $referer['host'] : '' ) );
|
||||
|
||||
// Get blacklist.
|
||||
$blacklist = self::$_options['referer']['blacklist'];
|
||||
$blacklist = self::$options['referer']['blacklist'];
|
||||
|
||||
// Check blacklist.
|
||||
if ( isset( $blacklist[ $referer ] ) ) {
|
||||
@ -222,17 +222,17 @@ class StatifyBlacklist {
|
||||
}
|
||||
|
||||
// Target blacklist (since 1.4.0).
|
||||
if ( isset( self::$_options['target']['active'] ) && 0 !== self::$_options['target']['active'] ) {
|
||||
if ( isset( self::$options['target']['active'] ) && 0 !== self::$options['target']['active'] ) {
|
||||
// Regular Expression filtering since 1.3.0.
|
||||
if ( isset( self::$_options['target']['regexp'] ) && 0 < self::$_options['target']['regexp'] ) {
|
||||
if ( isset( self::$options['target']['regexp'] ) && 0 < self::$options['target']['regexp'] ) {
|
||||
// Get full referer string.
|
||||
// @codingStandardsIgnoreStart The globals are checked.
|
||||
$target = ( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '/' );
|
||||
// @codingStandardsIgnoreEnd
|
||||
// Merge given regular expressions into one.
|
||||
$regexp = self::regex(
|
||||
array_keys( self::$_options['target']['blacklist'] ),
|
||||
self::MODE_REGEX_CI === self::$_options['target']['regexp']
|
||||
array_keys( self::$options['target']['blacklist'] ),
|
||||
self::MODE_REGEX_CI === self::$options['target']['regexp']
|
||||
);
|
||||
|
||||
// Check blacklist (no return to continue filtering #12).
|
||||
@ -245,7 +245,7 @@ class StatifyBlacklist {
|
||||
$target = ( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '/' );
|
||||
// @codingStandardsIgnoreEnd
|
||||
// Get blacklist.
|
||||
$blacklist = self::$_options['target']['blacklist'];
|
||||
$blacklist = self::$options['target']['blacklist'];
|
||||
// Check blacklist.
|
||||
if ( isset( $blacklist[ $target ] ) ) {
|
||||
return true;
|
||||
@ -254,10 +254,10 @@ class StatifyBlacklist {
|
||||
}
|
||||
|
||||
// IP blacklist (since 1.4.0).
|
||||
if ( isset( self::$_options['ip']['active'] ) && 0 !== self::$_options['ip']['active'] ) {
|
||||
if ( isset( self::$options['ip']['active'] ) && 0 !== self::$options['ip']['active'] ) {
|
||||
$ip = self::get_ip();
|
||||
if ( false !== ( $ip ) ) {
|
||||
foreach ( self::$_options['ip']['blacklist'] as $net ) {
|
||||
foreach ( self::$options['ip']['blacklist'] as $net ) {
|
||||
if ( self::cidr_match( $ip, $net ) ) {
|
||||
return true;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function test_referer_filter() {
|
||||
// Prepare Options: 2 blacklisted domains, disabled.
|
||||
StatifyBlacklist::$_options = array(
|
||||
StatifyBlacklist::$options = array(
|
||||
'referer' => array(
|
||||
'active' => 0,
|
||||
'cron' => 0,
|
||||
@ -88,7 +88,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||
|
||||
// Activate filter and run tests again.
|
||||
StatifyBlacklist::$_options['referer']['active'] = 1;
|
||||
StatifyBlacklist::$options['referer']['active'] = 1;
|
||||
|
||||
unset( $_SERVER['HTTP_REFERER'] );
|
||||
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||
@ -110,7 +110,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function test_referer_regex_filter() {
|
||||
// Prepare Options: 2 regular expressions.
|
||||
StatifyBlacklist::$_options = array(
|
||||
StatifyBlacklist::$options = array(
|
||||
'referer' => array(
|
||||
'active' => 1,
|
||||
'cron' => 0,
|
||||
@ -156,7 +156,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||
|
||||
// Set RegExp filter to case insensitive.
|
||||
StatifyBlacklist::$_options['referer']['regexp'] = 2;
|
||||
StatifyBlacklist::$options['referer']['regexp'] = 2;
|
||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function test_referer_keyword_filter() {
|
||||
// Prepare Options: 2 regular expressions.
|
||||
StatifyBlacklist::$_options = array(
|
||||
StatifyBlacklist::$options = array(
|
||||
'referer' => array(
|
||||
'active' => 1,
|
||||
'cron' => 0,
|
||||
@ -415,7 +415,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function test_ip_filter() {
|
||||
// Prepare Options: 2 blacklisted IPs, disabled.
|
||||
StatifyBlacklist::$_options = array(
|
||||
StatifyBlacklist::$options = array(
|
||||
'referer' => array(
|
||||
'active' => 0,
|
||||
'cron' => 0,
|
||||
@ -445,7 +445,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
$_SERVER['REMOTE_ADDR'] = '192.0.2.123';
|
||||
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||
// Activate filter.
|
||||
StatifyBlacklist::$_options['ip']['active'] = 1;
|
||||
StatifyBlacklist::$options['ip']['active'] = 1;
|
||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||
// Try matching v6 address.
|
||||
$_SERVER['REMOTE_ADDR'] = '2001:db8:a0b:12f0::1';
|
||||
@ -456,7 +456,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
$_SERVER['REMOTE_ADDR'] = '2001:db8:a0b:12f0::2';
|
||||
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||
// Subnet matching.
|
||||
StatifyBlacklist::$_options['ip']['blacklist'] = array(
|
||||
StatifyBlacklist::$options['ip']['blacklist'] = array(
|
||||
'192.0.2.0/25',
|
||||
'2001:db8:a0b:12f0::/96',
|
||||
);
|
||||
@ -487,7 +487,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function test_target_filter() {
|
||||
// Prepare Options: 2 blacklisted domains, disabled.
|
||||
StatifyBlacklist::$_options = array(
|
||||
StatifyBlacklist::$options = array(
|
||||
'referer' => array(
|
||||
'active' => 0,
|
||||
'cron' => 0,
|
||||
@ -530,7 +530,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||
|
||||
// Activate filter and run tests again.
|
||||
StatifyBlacklist::$_options['target']['active'] = 1;
|
||||
StatifyBlacklist::$options['target']['active'] = 1;
|
||||
|
||||
unset( $_SERVER['REQUEST_URI'] );
|
||||
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||
@ -562,7 +562,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function test_combined_filters() {
|
||||
// Prepare Options: simple referer + simple target + ip.
|
||||
StatifyBlacklist::$_options = array(
|
||||
StatifyBlacklist::$options = array(
|
||||
'referer' => array(
|
||||
'active' => 1,
|
||||
'cron' => 0,
|
||||
@ -614,10 +614,10 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
$_SERVER['REMOTE_ADDR'] = '192.0.2.234';
|
||||
|
||||
// Same for RegExp filters.
|
||||
StatifyBlacklist::$_options['referer']['regexp'] = StatifyBlacklist::MODE_REGEX;
|
||||
StatifyBlacklist::$_options['referer']['blacklist'] = array( 'example\.com' => 0 );
|
||||
StatifyBlacklist::$_options['target']['regexp'] = StatifyBlacklist::MODE_REGEX;
|
||||
StatifyBlacklist::$_options['target']['blacklist'] = array( '/excluded/.*' => 0 );
|
||||
StatifyBlacklist::$options['referer']['regexp'] = StatifyBlacklist::MODE_REGEX;
|
||||
StatifyBlacklist::$options['referer']['blacklist'] = array( 'example\.com' => 0 );
|
||||
StatifyBlacklist::$options['target']['regexp'] = StatifyBlacklist::MODE_REGEX;
|
||||
StatifyBlacklist::$options['target']['blacklist'] = array( '/excluded/.*' => 0 );
|
||||
|
||||
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||
$_SERVER['HTTP_REFERER'] = 'https://example.com';
|
||||
@ -625,7 +625,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
||||
// Check case-insensitive match.
|
||||
$_SERVER['HTTP_REFERER'] = 'https://eXaMpLe.com';
|
||||
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||
StatifyBlacklist::$_options['referer']['regexp'] = StatifyBlacklist::MODE_REGEX_CI;
|
||||
StatifyBlacklist::$options['referer']['regexp'] = StatifyBlacklist::MODE_REGEX_CI;
|
||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||
$_SERVER['HTTP_REFERER'] = 'https://example.net';
|
||||
$_SERVER['REQUEST_URI'] = '/excluded/page/';
|
||||
|
Loading…
x
Reference in New Issue
Block a user