diff --git a/inc/statifyblacklist-admin.class.php b/inc/class-statifyblacklist-admin.php
similarity index 79%
rename from inc/statifyblacklist-admin.class.php
rename to inc/class-statifyblacklist-admin.php
index 2b819e4..f436f23 100644
--- a/inc/statifyblacklist-admin.class.php
+++ b/inc/class-statifyblacklist-admin.php
@@ -10,7 +10,7 @@
*/
// Quit.
-defined( 'ABSPATH' ) or exit;
+defined( 'ABSPATH' ) || exit;
/**
* Statify Blacklist admin configuration.
@@ -29,22 +29,26 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
public static function update_options( $options = null ) {
if ( isset( $options ) && current_user_can( 'manage_options' ) ) {
// Sanitize URLs and remove empty inputs.
- $givenReferer = $options['referer']['blacklist'];
+ $given_referer = $options['referer']['blacklist'];
if ( 0 === $options['referer']['regexp'] ) {
- $sanitizedReferer = self::sanitizeURLs( $givenReferer );
+ $sanitized_referer = self::sanitizeURLs( $given_referer );
} else {
- $sanitizedReferer = $givenReferer;
+ $sanitized_referer = $given_referer;
}
// Sanitize IPs and Subnets and remove empty inputs.
- $givenIP = $options['ip']['blacklist'];
- $sanitizedIP = self::sanitizeIPs( $givenIP );
+ $given_ip = $options['ip']['blacklist'];
+ $sanitized_ip = self::sanitizeIPs( $given_ip );
// Abort on errors.
- if ( ! empty( array_diff( array_keys( $givenReferer ), array_keys( $sanitizedReferer ) ) ) ) {
- return array( 'referer' => $sanitizedReferer );
- } elseif ( ! empty( array_diff( $givenIP, $sanitizedIP ) ) ) {
- return array( 'ip' => array_diff( $givenIP, $sanitizedIP ) );
+ if ( ! empty( array_diff( array_keys( $given_referer ), array_keys( $sanitized_referer ) ) ) ) {
+ return array(
+ 'referer' => $sanitized_referer,
+ );
+ } elseif ( ! empty( array_diff( $given_ip, $sanitized_ip ) ) ) {
+ return array(
+ 'ip' => array_diff( $given_ip, $sanitized_ip ),
+ );
}
// Update database on success.
@@ -150,58 +154,60 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
}
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
- $cleanRef = ( 1 === self::$_options['referer']['cron'] );
- $cleanTrg = ( 1 === self::$_options['target']['cron'] );
+ $clean_ref = ( 1 === self::$_options['referer']['cron'] );
+ $clean_trg = ( 1 === self::$_options['target']['cron'] );
} else {
- $cleanRef = true;
- $cleanTrg = true;
+ $clean_ref = true;
+ $clean_trg = true;
}
- if ( $cleanRef ) {
+ if ( $clean_ref ) {
if ( isset( self::$_options['referer']['regexp'] ) && self::$_options['referer']['regexp'] > 0 ) {
// Merge given regular expressions into one.
- $refererRegexp = implode( '|', array_keys( self::$_options['referer']['blacklist'] ) );
+ $referer_regexp = implode( '|', array_keys( self::$_options['referer']['blacklist'] ) );
} else {
// Sanitize URLs.
$referer = self::sanitizeURLs( self::$_options['referer']['blacklist'] );
// Build filter regexp.
- $refererRegexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) );
+ $referer_regexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) );
}
}
- if ( $cleanTrg ) {
+ if ( $clean_trg ) {
if ( isset( self::$_options['target']['regexp'] ) && self::$_options['target']['regexp'] > 0 ) {
// Merge given regular expressions into one.
- $targetRegexp = implode( '|', array_keys( self::$_options['target']['blacklist'] ) );
+ $target_regexp = implode( '|', array_keys( self::$_options['target']['blacklist'] ) );
} else {
// Build filter regexp.
- $targetRegexp = str_replace( '.', '\.', implode( '|', array_flip( self::$_options['target']['blacklist'] ) ) );
+ $target_regexp = str_replace( '.', '\.', implode( '|', array_flip( self::$_options['target']['blacklist'] ) ) );
}
}
- if ( ! empty( $refererRegexp ) || ! empty( $targetRegexp ) ) {
+ if ( ! empty( $referer_regexp ) || ! empty( $target_regexp ) ) {
global $wpdb;
// Execute filter on database.
- if ( ! empty( $refererRegexp ) ) {
+ // @codingStandardsIgnoreStart These statements prouce warnings, rework in future release (TODO).
+ if ( ! empty( $referer_regexp ) ) {
$wpdb->query(
$wpdb->prepare(
"DELETE FROM `$wpdb->statify` WHERE "
. ( ( 1 === self::$_options['referer']['regexp'] ) ? ' BINARY ' : '' )
- . 'referrer REGEXP %s', $refererRegexp
+ . 'referrer REGEXP %s', $referer_regexp
)
);
}
- if ( ! empty( $targetRegexp ) ) {
+ if ( ! empty( $target_regexp ) ) {
$wpdb->query(
$wpdb->prepare(
"DELETE FROM `$wpdb->statify` WHERE "
. ( ( 1 === self::$_options['target']['regexp'] ) ? ' BINARY ' : '' )
- . 'target REGEXP %s', $targetRegexp
+ . 'target REGEXP %s', $target_regexp
)
);
}
+ // @codingStandardsIgnoreEnd
// Optimize DB.
$wpdb->query( "OPTIMIZE TABLE `$wpdb->statify`" );
diff --git a/inc/statifyblacklist-system.class.php b/inc/class-statifyblacklist-system.php
similarity index 94%
rename from inc/statifyblacklist-system.class.php
rename to inc/class-statifyblacklist-system.php
index 9ec589b..7dac2f0 100644
--- a/inc/statifyblacklist-system.class.php
+++ b/inc/class-statifyblacklist-system.php
@@ -10,7 +10,7 @@
*/
// Quit.
-defined( 'ABSPATH' ) or exit;
+defined( 'ABSPATH' ) || exit;
/**
* Statify Blacklist system configuration.
@@ -32,7 +32,8 @@ class StatifyBlacklist_System extends StatifyBlacklist {
if ( function_exists( 'get_sites' ) ) {
$sites = get_sites();
} elseif ( function_exists( 'wp_get_sites' ) ) {
- $sites = wp_get_sites(); // Legacy support for WP < 4.6.
+ // @codingStandardsIgnoreLine Legacy support for WP < 4.6.
+ $sites = wp_get_sites();
} else {
return;
}
@@ -67,7 +68,8 @@ class StatifyBlacklist_System extends StatifyBlacklist {
if ( function_exists( 'get_sites' ) ) {
$sites = get_sites();
} elseif ( function_exists( 'wp_get_sites' ) ) {
- $sites = wp_get_sites(); // Legacy support for WP < 4.6.
+ // @codingStandardsIgnoreLine Legacy support for WP < 4.6.
+ $sites = wp_get_sites();
} else {
return;
}
diff --git a/inc/statifyblacklist.class.php b/inc/class-statifyblacklist.php
similarity index 91%
rename from inc/statifyblacklist.class.php
rename to inc/class-statifyblacklist.php
index 0a2144d..3b2a7b2 100644
--- a/inc/statifyblacklist.class.php
+++ b/inc/class-statifyblacklist.php
@@ -9,7 +9,7 @@
*/
// Quit.
-defined( 'ABSPATH' ) or exit;
+defined( 'ABSPATH' ) || exit;
/**
* Statify Blacklist.
@@ -58,7 +58,7 @@ class StatifyBlacklist {
*/
public function __construct() {
// Skip on autosave or AJAX.
- if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) or ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
+ if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
return;
}
@@ -223,7 +223,8 @@ class StatifyBlacklist {
// IP blacklist (since 1.4.0).
if ( isset( self::$_options['ip']['active'] ) && 0 !== self::$_options['ip']['active'] ) {
- if ( false !== ( $ip = self::get_ip() ) ) {
+ $ip = self::get_ip();
+ if ( false !== ( $ip ) ) {
foreach ( self::$_options['ip']['blacklist'] as $net ) {
if ( self::cidr_match( $ip, $net ) ) {
return true;
@@ -247,14 +248,15 @@ class StatifyBlacklist {
*/
private static function get_ip() {
foreach (
+
+ /*
+ * There are more fields, that could possibly be checked, but we only consider the most common for now:
+ * HTTP_CLIENT_IP, HTTP_X_REAL_IP, HTTP_X_FORWARDED_FOR, HTTP_X_FORWARDED,
+ * HTTP_X_CLUSTER_CLIENT_IP, HTTP_FORWARDED_FOR, HTTP_FORWARDED, REMOTE_ADDR
+ */
array(
- // 'HTTP_CLIENT_IP',
'HTTP_X_REAL_IP',
'HTTP_X_FORWARDED_FOR',
- // 'HTTP_X_FORWARDED',
- // 'HTTP_X_CLUSTER_CLIENT_IP',
- // 'HTTP_FORWARDED_FOR',
- // 'HTTP_FORWARDED',
'REMOTE_ADDR',
) as $k
) {
@@ -303,18 +305,19 @@ class StatifyBlacklist {
$mask = 128;
}
- $bytesAddr = unpack( 'n*', inet_pton( $base ) );
- $bytesTest = unpack( 'n*', inet_pton( $ip ) );
+ $bytes_addr = unpack( 'n*', inet_pton( $base ) );
+ $bytes_est = unpack( 'n*', inet_pton( $ip ) );
- if ( ! $bytesAddr || ! $bytesTest ) {
+ if ( ! $bytes_addr || ! $bytes_est ) {
return false;
}
- for ( $i = 1, $ceil = ceil( $mask / 16 ); $i <= $ceil; ++ $i ) {
+ $ceil = ceil( $mask / 16 );
+ for ( $i = 1; $i <= $ceil; ++ $i ) {
$left = $mask - 16 * ( $i - 1 );
$left = ( $left <= 16 ) ? $left : 16;
- $maskB = ~( 0xffff >> $left ) & 0xffff;
- if ( ( $bytesAddr[ $i ] & $maskB ) !== ( $bytesTest[ $i ] & $maskB ) ) {
+ $mask_b = ~( 0xffff >> $left ) & 0xffff;
+ if ( ( $bytes_addr[ $i ] & $mask_b ) !== ( $bytes_est[ $i ] & $mask_b ) ) {
return false;
}
}
@@ -341,6 +344,6 @@ class StatifyBlacklist {
}
return ( 0 === substr_compare( sprintf( '%032b', ip2long( $ip ) ), sprintf( '%032b', ip2long( $base ) ), 0, $mask ) );
- }
+ } // End if().
}
}
diff --git a/phpcs.xml b/phpcs.xml
index 797a05d..410eb97 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -8,6 +8,7 @@
' .
- esc_html( $statifyBlacklistPostWarning );
+ esc_html( $statifyblacklist_post_warning );
print '
';
esc_html_e( 'Settings have not been saved yet.', 'statify-blacklist' );
print '
' . - esc_html( $statifyBlacklistPostSuccess ) . + esc_html( $statifyblacklist_post_success ) . '