From df59e43b290802d5a3f22ea9ab03d4629b17cc5f Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Mon, 5 Jun 2017 12:03:11 +0200 Subject: [PATCH] Config array restructured --- inc/statifyblacklist.class.php | 56 ++++---- inc/statifyblacklist_admin.class.php | 26 ++-- inc/statifyblacklist_system.class.php | 34 ++++- test/StatifyBlacklistTest.php | 184 ++++++++++++++------------ views/settings_page.php | 90 +++++++------ 5 files changed, 220 insertions(+), 170 deletions(-) diff --git a/inc/statifyblacklist.class.php b/inc/statifyblacklist.class.php index 05da829..33b1b38 100644 --- a/inc/statifyblacklist.class.php +++ b/inc/statifyblacklist.class.php @@ -57,7 +57,7 @@ class StatifyBlacklist { self::$multisite = ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ); /* Add Filter to statify hook if enabled */ - if ( self::$_options['active_referer'] != 0 ) { + if ( self::$_options['referer']['active'] != 0 ) { add_filter( 'statify_skip_tracking', array( 'StatifyBlacklist', 'apply_blacklist_filter' ) ); } @@ -85,7 +85,7 @@ class StatifyBlacklist { /* CronJob to clean up database */ if ( defined( 'DOING_CRON' ) && DOING_CRON ) { - if ( self::$_options['cron_referer'] == 1 || self::$_options['cron_target'] == 1 ) { + if ( self::$_options['referer']['cron'] == 1 || self::$_options['target']['cron'] == 1 ) { add_action( 'statify_cleanup', array( 'StatifyBlacklist_Admin', 'cleanup_database' ) ); } } @@ -115,17 +115,23 @@ class StatifyBlacklist { */ protected static function defaultOptions() { return array( - 'active_referer' => 0, - 'cron_referer' => 0, - 'referer' => array(), - 'referer_regexp' => 0, - 'active_target' => 0, - 'cron_target' => 0, - 'target' => array(), - 'target_regexp' => 0, - 'active_ip' => 0, - 'ip' => array(), - 'version' => self::VERSION_MAIN + 'referer' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array() + ), + 'target' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array() + ), + 'ip' => array( + 'active' => 0, + 'blacklist' => array() + ), + 'version' => self::VERSION_MAIN ); } @@ -139,14 +145,14 @@ class StatifyBlacklist { */ public static function apply_blacklist_filter() { /* Referer blacklist */ - if ( isset( self::$_options['active_referer'] ) && self::$_options['active_referer'] != 0 ) { + if ( isset( self::$_options['referer']['active'] ) && self::$_options['referer']['active'] != 0 ) { /* Regular Expression filtering since 1.3.0 */ - if ( isset( self::$_options['referer_regexp'] ) && self::$_options['referer_regexp'] > 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 = '/' . implode( "|", array_keys( self::$_options['referer']['blacklist'] ) ) . '/'; + if ( self::$_options['referer']['regexp'] == 2 ) { $regexp .= 'i'; } @@ -158,7 +164,7 @@ class StatifyBlacklist { $referer = strtolower( ( isset( $_SERVER['HTTP_REFERER'] ) ? parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ) : '' ) ); /* Get blacklist */ - $blacklist = self::$_options['referer']; + $blacklist = self::$_options['referer']['blacklist']; /* Check blacklist */ if ( isset( $blacklist[ $referer ] ) ) { @@ -168,14 +174,14 @@ class StatifyBlacklist { } /* Target blacklist (since 1.4.0) */ - if ( isset( self::$_options['active_target'] ) && self::$_options['active_target'] != 0 ) { + if ( isset( self::$_options['target']['active'] ) && self::$_options['target']['active'] != 0 ) { /* Regular Expression filtering since 1.3.0 */ - if ( isset( self::$_options['target_regexp'] ) && self::$_options['target_regexp'] > 0 ) { + if ( isset( self::$_options['target']['regexp'] ) && self::$_options['target']['regexp'] > 0 ) { /* Get full referer string */ $target = ( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '/' ); /* Merge given regular expressions into one */ - $regexp = '/' . implode( "|", array_keys( self::$_options['target'] ) ) . '/'; - if ( self::$_options['target_regexp'] == 2 ) { + $regexp = '/' . implode( "|", array_keys( self::$_options['target']['blacklist'] ) ) . '/'; + if ( self::$_options['target']['regexp'] == 2 ) { $regexp .= 'i'; } @@ -186,7 +192,7 @@ class StatifyBlacklist { /* Extract target page */ $target = ( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '/' ); /* Get blacklist */ - $blacklist = self::$_options['target']; + $blacklist = self::$_options['target']['blacklist']; /* Check blacklist */ if ( isset( $blacklist[ $target ] ) ) { return true; @@ -195,9 +201,9 @@ class StatifyBlacklist { } /* IP blacklist (since 1.4.0) */ - if ( isset ( self::$_options['active_ip'] ) && self::$_options['active_ip'] != 0 ) { + if ( isset ( self::$_options['ip']['active'] ) && self::$_options['ip']['active'] != 0 ) { if ( ( $ip = self::getIP() ) !== false ) { - foreach ( self::$_options['ip'] as $net ) { + foreach ( self::$_options['ip']['blacklist'] as $net ) { if ( self::cidrMatch( $ip, $net ) ) { return true; } diff --git a/inc/statifyblacklist_admin.class.php b/inc/statifyblacklist_admin.class.php index 541478d..f927076 100644 --- a/inc/statifyblacklist_admin.class.php +++ b/inc/statifyblacklist_admin.class.php @@ -22,15 +22,15 @@ 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']; - if ( $options['referer_regexp'] == 0 ) { + $givenReferer = $options['referer']['blacklist']; + if ( $options['referer']['regexp'] == 0 ) { $sanitizedReferer = self::sanitizeURLs( $givenReferer ); } else { $sanitizedReferer = $givenReferer; } /* Sanitize IPs and Subnets and remove empty inputs */ - $givenIP = $options['ip']; + $givenIP = $options['ip']['blacklist']; $sanitizedIP = self::sanitizeIPs( $givenIP ); /* Abort on errors */ @@ -132,8 +132,8 @@ class StatifyBlacklist_Admin extends StatifyBlacklist { } if ( defined( 'DOING_CRON' ) && DOING_CRON ) { - $cleanRef = ( self::$_options['cron_referer'] == 1 ); - $cleanTrg = ( self::$_options['cron_target'] == 1 ); + $cleanRef = ( self::$_options['referer']['cron'] == 1 ); + $cleanTrg = ( self::$_options['target']['cron'] == 1 ); } else { $cleanRef = true; $cleanTrg = true; @@ -141,12 +141,12 @@ class StatifyBlacklist_Admin extends StatifyBlacklist { if ( $cleanRef ) { - 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 */ - $refererRegexp = implode( "|", array_keys( self::$_options['referer'] ) ); + $refererRegexp = implode( "|", array_keys( self::$_options['referer']['blacklist'] ) ); } else { /* Sanitize URLs */ - $referer = self::sanitizeURLs( self::$_options['referer'] ); + $referer = self::sanitizeURLs( self::$_options['referer']['blacklist'] ); /* Build filter regexp */ $refererRegexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) ); @@ -154,12 +154,12 @@ class StatifyBlacklist_Admin extends StatifyBlacklist { } if ( $cleanTrg ) { - 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 */ - $targetRegexp = implode( "|", array_keys( self::$_options['target'] ) ); + $targetRegexp = implode( "|", array_keys( self::$_options['target']['blacklist'] ) ); } else { /* Build filter regexp */ - $targetRegexp = str_replace( '.', '\.', implode( '|', array_flip( self::$_options['target'] ) ) ); + $targetRegexp = str_replace( '.', '\.', implode( '|', array_flip( self::$_options['target']['blacklist'] ) ) ); } } @@ -171,14 +171,14 @@ class StatifyBlacklist_Admin extends StatifyBlacklist { if ( ! empty( $refererRegexp ) ) { $wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->statify` WHERE " - . ( ( self::$_options['referer_regexp'] == 1 ) ? " BINARY " : "" ) + . ( ( self::$_options['referer']['regexp'] == 1 ) ? " BINARY " : "" ) . "referrer REGEXP %s", $refererRegexp ) ); } if ( ! empty( $targetRegexp ) ) { $wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->statify` WHERE " - . ( ( self::$_options['target_regexp'] == 1 ) ? " BINARY " : "" ) + . ( ( self::$_options['target']['regexp'] == 1 ) ? " BINARY " : "" ) . "target REGEXP %s", $targetRegexp ) ); } diff --git a/inc/statifyblacklist_system.class.php b/inc/statifyblacklist_system.class.php index 4fd443b..832c6ab 100644 --- a/inc/statifyblacklist_system.class.php +++ b/inc/statifyblacklist_system.class.php @@ -97,8 +97,38 @@ class StatifyBlacklist_System extends StatifyBlacklist { } } - /* Version not set (pre 1.3.0) or older than current major release */ - if ( ! isset( self::$_options['version'] ) || self::$_options['version'] < self::VERSION_MAIN ) { + /* Version not set (pre 1.3.0) or older than 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'] + ), + 'target' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array() + ), + 'ip' => array( + 'active' => 0, + 'blacklist' => array() + ), + 'version' => 1.4 + ); + 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 ); + } + self::update_options(); + } + + /* Version older than current major release */ + if ( self::$_options['version'] < self::VERSION_MAIN ) { /* Merge default options with current config, assuming only additive changes */ $options = array_merge( self::defaultOptions(), self::$_options ); $options['version'] = self::VERSION_MAIN; diff --git a/test/StatifyBlacklistTest.php b/test/StatifyBlacklistTest.php index 39e3a41..c619f47 100644 --- a/test/StatifyBlacklistTest.php +++ b/test/StatifyBlacklistTest.php @@ -20,15 +20,26 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { public function testRefererFilter() { /* Prepare Options: 2 blacklisted domains, disabled */ StatifyBlacklist::$_options = array( - 'active_referer' => 0, - 'cron_referer' => 0, - 'referer' => array( - 'example.com' => 0, - 'example.net' => 1 + 'referer' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array( + 'example.com' => 0, + 'example.net' => 1 + ) ), - 'active_ip' => 0, - 'ip' => array(), - 'version' => StatifyBlacklist::VERSION_MAIN + 'target' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array() + ), + 'ip' => array( + 'active' => 0, + 'blacklist' => array() + ), + 'version' => StatifyBlacklist::VERSION_MAIN ); /* No multisite */ @@ -48,7 +59,7 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { $this->assertNull( StatifyBlacklist::apply_blacklist_filter() ); /* Activate filter and run tests again */ - StatifyBlacklist::$_options['active_referer'] = 1; + StatifyBlacklist::$_options['referer']['active'] = 1; unset( $_SERVER['HTTP_REFERER'] ); $this->assertNull( StatifyBlacklist::apply_blacklist_filter() ); @@ -69,14 +80,26 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { public function testRefererRegexFilter() { /* Prepare Options: 2 regular expressions */ StatifyBlacklist::$_options = array( - 'active_referer' => 1, - 'cron_referer' => 0, - 'referer' => array( - 'example.[a-z]+' => 0, - 'test' => 1 + 'referer' => array( + 'active' => 1, + 'cron' => 0, + 'regexp' => 1, + 'blacklist' => array( + 'example.[a-z]+' => 0, + 'test' => 1 + ) ), - 'referer_regexp' => 1, - 'version' => 1.3 + 'target' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array() + ), + 'ip' => array( + 'active' => 0, + 'blacklist' => array() + ), + 'version' => StatifyBlacklist::VERSION_MAIN ); /* No multisite */ @@ -102,7 +125,7 @@ class StatifyBlacklistTest 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() ); } @@ -132,17 +155,24 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { $optionsUpdated = get_option( 'statify-blacklist' ); /* Verify size against default options (no junk left) */ - $this->assertEquals( 11, sizeof( $optionsUpdated ) ); + $this->assertEquals( 4, sizeof( $optionsUpdated ) ); + $this->assertEquals( 4, sizeof( $optionsUpdated['referer'] ) ); + $this->assertEquals( 4, sizeof( $optionsUpdated['target'] ) ); + $this->assertEquals( 2, sizeof( $optionsUpdated['ip'] ) ); /* Verify that original attributes are unchanged */ - $this->assertEquals( $options13['active_referer'], $optionsUpdated['active_referer'] ); - $this->assertEquals( $options13['cron_referer'], $optionsUpdated['cron_referer'] ); - $this->assertEquals( $options13['referer'], $optionsUpdated['referer'] ); - $this->assertEquals( $options13['referer_regexp'], $optionsUpdated['referer_regexp'] ); + $this->assertEquals( $options13['active_referer'], $optionsUpdated['referer']['active'] ); + $this->assertEquals( $options13['cron_referer'], $optionsUpdated['referer']['cron'] ); + $this->assertEquals( $options13['referer'], $optionsUpdated['referer']['blacklist'] ); + $this->assertEquals( $options13['referer_regexp'], $optionsUpdated['referer']['regexp'] ); - /* Verify that new attributes are present in config */ - $this->assertEquals( 0, $optionsUpdated['active_ip'] ); - $this->assertEquals( array(), $optionsUpdated['ip'] ); + /* Verify that new attributes are present in config and filled with default values (disabled, empty) */ + $this->assertEquals( 0, $optionsUpdated['target']['active'] ); + $this->assertEquals( 0, $optionsUpdated['target']['cron'] ); + $this->assertEquals( 0, $optionsUpdated['target']['regexp'] ); + $this->assertEquals( array(), $optionsUpdated['target']['blacklist'] ); + $this->assertEquals( 0, $optionsUpdated['ip']['active'] ); + $this->assertEquals( array(), $optionsUpdated['ip']['blacklist'] ); /* Verify that version number has changed to current release */ $this->assertEquals( StatifyBlacklist::VERSION_MAIN, $optionsUpdated['version'] ); @@ -242,15 +272,26 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { public function testIPFilter() { /* Prepare Options: 2 blacklisted IPs, disabled */ StatifyBlacklist::$_options = array( - 'active_referer' => 0, - 'cron_referer' => 0, - 'referer' => array(), - 'active_ip' => 0, - 'ip' => array( - '192.0.2.123', - '2001:db8:a0b:12f0::1' + 'referer' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array() ), - 'version' => StatifyBlacklist::VERSION_MAIN + 'target' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array() + ), + 'ip' => array( + 'active' => 0, + 'blacklist' => array( + '192.0.2.123', + '2001:db8:a0b:12f0::1' + ) + ), + 'version' => StatifyBlacklist::VERSION_MAIN ); /* No multisite */ @@ -260,7 +301,7 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { $_SERVER['REMOTE_ADDR'] = '192.0.2.123'; $this->assertNull( StatifyBlacklist::apply_blacklist_filter() ); /* Activate filter */ - StatifyBlacklist::$_options['active_ip'] = 1; + StatifyBlacklist::$_options['ip']['active'] = 1; $this->assertTrue( StatifyBlacklist::apply_blacklist_filter() ); /* Try matching v6 address */ $_SERVER['REMOTE_ADDR'] = '2001:db8:a0b:12f0::1'; @@ -271,7 +312,7 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { $_SERVER['REMOTE_ADDR'] = '2001:db8:a0b:12f0::2'; $this->assertNull( StatifyBlacklist::apply_blacklist_filter() ); /* Subnet matching */ - StatifyBlacklist::$_options['ip'] = array( + StatifyBlacklist::$_options['ip']['blacklist'] = array( '192.0.2.0/25', '2001:db8:a0b:12f0::/96' ); @@ -301,23 +342,26 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { public function testTargetFilter() { /* Prepare Options: 2 blacklisted domains, disabled */ StatifyBlacklist::$_options = array( - 'active_referer' => 0, - 'cron_referer' => 0, - 'referer' => array( - 'example.com' => 0, - 'example.net' => 1 + 'referer' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array() ), - 'referer_regexp' => 0, - 'active_target' => 0, - 'cron_target' => 0, - 'target' => array( - '/excluded/page/' => 0, - '/?page_id=3' => 1 + 'target' => array( + 'active' => 0, + 'cron' => 0, + 'regexp' => 0, + 'blacklist' => array( + '/excluded/page/' => 0, + '/?page_id=3' => 1 + ) ), - 'target_regexp' => 0, - 'active_ip' => 0, - 'ip' => array(), - 'version' => StatifyBlacklist::VERSION_MAIN + 'ip' => array( + 'active' => 0, + 'blacklist' => array() + ), + 'version' => StatifyBlacklist::VERSION_MAIN ); /* No multisite */ @@ -340,7 +384,7 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { $this->assertNull( StatifyBlacklist::apply_blacklist_filter() ); /* Activate filter and run tests again */ - StatifyBlacklist::$_options['active_target'] = 1; + StatifyBlacklist::$_options['target']['active'] = 1; unset( $_SERVER['REQUEST_URI'] ); $this->assertNull( StatifyBlacklist::apply_blacklist_filter() ); @@ -364,43 +408,7 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase { * Test target filter using regular expressions. */ public function testTargetRegexFilter() { - /* 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, - 'version' => 1.3 - ); - - /* No multisite */ - StatifyBlacklist::$multisite = false; - - /* No referer */ - unset( $_SERVER['HTTP_REFERER'] ); - $this->assertNull( StatifyBlacklist::apply_blacklist_filter() ); - /* Non-blacklisted referer */ - $_SERVER['HTTP_REFERER'] = 'http://not.evil'; - $this->assertNull( 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->assertNull( StatifyBlacklist::apply_blacklist_filter() ); - - /* Set RegExp filter to case insensitive */ - StatifyBlacklist::$_options['referer_regexp'] = 2; - $this->assertTrue( StatifyBlacklist::apply_blacklist_filter() ); + // TODO } } diff --git a/views/settings_page.php b/views/settings_page.php index 8cdbe2a..bd57901 100755 --- a/views/settings_page.php +++ b/views/settings_page.php @@ -18,40 +18,46 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) { StatifyBlacklist_Admin::cleanup_database(); } else { /* Extract referer array */ - if ( empty( trim( $_POST['statifyblacklist']['referer'] ) ) ) { + if ( empty( trim( $_POST['statifyblacklist']['referer']['blacklist'] ) ) ) { $referer = array(); } else { - $referer = explode( "\r\n", $_POST['statifyblacklist']['referer'] ); + $referer = explode( "\r\n", $_POST['statifyblacklist']['referer']['blacklist'] ); } /* Extract target array */ - if ( empty( trim( $_POST['statifyblacklist']['target'] ) ) ) { + if ( empty( trim( $_POST['statifyblacklist']['target']['blacklist'] ) ) ) { $target = array(); } else { - $target = explode( "\r\n", str_replace( '\\\\', '\\', $_POST['statifyblacklist']['target'] ) ); + $target = explode( "\r\n", str_replace( '\\\\', '\\', $_POST['statifyblacklist']['target']['blacklist'] ) ); } /* Extract IP array */ - if ( empty( trim( $_POST['statifyblacklist']['ip'] ) ) ) { + if ( empty( trim( $_POST['statifyblacklist']['ip']['blacklist'] ) ) ) { $ip = array(); } else { - $ip = explode( "\r\n", $_POST['statifyblacklist']['ip'] ); + $ip = explode( "\r\n", $_POST['statifyblacklist']['ip']['blacklist'] ); } /* 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'], - 'active_target' => (int) @$_POST['statifyblacklist']['active_target'], - 'cron_target' => (int) @$_POST['statifyblacklist']['cron_target'], - 'target' => array_flip( $target ), - 'target_regexp' => (int) @$_POST['statifyblacklist']['target_regexp'], - 'active_ip' => (int) @$_POST['statifyblacklist']['active_ip'], - 'ip' => $ip, - 'version' => StatifyBlacklist::VERSION_MAIN + 'referer' => array( + 'active' => (int) @$_POST['statifyblacklist']['referer']['active'], + 'cron' => (int) @$_POST['statifyblacklist']['referer']['cron'], + 'regexp' => (int) @$_POST['statifyblacklist']['referer']['regexp'], + 'blacklist' => array_flip( $referer ) + ), + 'target' => array( + 'active' => (int) @$_POST['statifyblacklist']['target']['active'], + 'cron' => (int) @$_POST['statifyblacklist']['target']['cron'], + 'regexp' => (int) @$_POST['statifyblacklist']['target']['regexp'], + 'blacklist' => array_flip( $target ) + ), + 'ip' => array( + 'active' => (int) @$_POST['statifyblacklist']['ip']['active'], + 'blacklist' => $ip + ), + 'version' => StatifyBlacklist::VERSION_MAIN ) ); @@ -96,16 +102,16 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {