remove underscore prefix from options field
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user