Config array restructured

This commit is contained in:
Stefan Kalscheuer 2017-06-05 12:03:11 +02:00
parent 152a800a4a
commit df59e43b29
5 changed files with 220 additions and 170 deletions

View File

@ -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,16 +115,22 @@ 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(),
'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;
}

View File

@ -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 )
);
}

View File

@ -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;

View File

@ -20,14 +20,25 @@ 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(
'active' => 0,
'cron' => 0,
'regexp' => 0,
'blacklist' => array(
'example.com' => 0,
'example.net' => 1
)
),
'target' => array(
'active' => 0,
'cron' => 0,
'regexp' => 0,
'blacklist' => array()
),
'ip' => array(
'active' => 0,
'blacklist' => array()
),
'active_ip' => 0,
'ip' => array(),
'version' => StatifyBlacklist::VERSION_MAIN
);
@ -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(
'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,13 +272,24 @@ 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,
'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(
'192.0.2.123',
'2001:db8:a0b:12f0::1'
)
),
'version' => StatifyBlacklist::VERSION_MAIN
);
@ -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,22 +342,25 @@ 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
'active' => 0,
'cron' => 0,
'regexp' => 0,
'blacklist' => array()
),
'referer_regexp' => 0,
'active_target' => 0,
'cron_target' => 0,
'target' => array(
'active' => 0,
'cron' => 0,
'regexp' => 0,
'blacklist' => array(
'/excluded/page/' => 0,
'/?page_id=3' => 1
)
),
'ip' => array(
'active' => 0,
'blacklist' => array()
),
'target_regexp' => 0,
'active_ip' => 0,
'ip' => array(),
'version' => StatifyBlacklist::VERSION_MAIN
);
@ -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
}
}

View File

@ -18,39 +18,45 @@ 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,
'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'] ) ) {
<ul style="list-style: none;">
<li>
<label for="statify-blacklist_active_referer">
<input type="checkbox" name="statifyblacklist[active_referer]"
<input type="checkbox" name="statifyblacklist[referer][active]"
id="statifyblacklist_active_referer"
value="1" <?php checked( StatifyBlacklist::$_options['active_referer'], 1 ); ?> />
value="1" <?php checked( StatifyBlacklist::$_options['referer']['active'], 1 ); ?> />
<?php esc_html_e( 'Activate live fiter', '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 ); ?> />
<input type="checkbox" name="statifyblacklist[referer][cron]" id="statifyblacklist_cron_referer"
value="1" <?php checked( StatifyBlacklist::$_options['referer']['cron'], 1 ); ?> />
<?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?>
<small>(<?php esc_html_e( 'Clean database periodically in background', 'statify-blacklist' ); ?>
)
@ -116,14 +122,14 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
<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 ); ?>>
<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 ); ?>>
<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 ); ?>>
<option value="2" <?php selected( StatifyBlacklist::$_options['referer']['regexp'], 2 ); ?>>
<?php esc_html_e( 'Case-insensitive', 'statify-blacklist' ); ?>
</option>
</select>
@ -136,11 +142,11 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
<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
<textarea cols="40" rows="5" name="statifyblacklist[referer][blacklist]" id="statify-blacklist_referer"><?php
if ( isset( $statifyBlacklistUpdateResult['referer'] ) ) {
print esc_html( implode( "\r\n", array_keys( $statifyBlacklistUpdateResult['referer'] ) ) );
} else {
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['referer'] ) ) );
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['referer']['blacklist'] ) ) );
}
?></textarea>
<br/>
@ -158,16 +164,16 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
<ul style="list-style: none;">
<li>
<label for="statify-blacklist_active_target">
<input type="checkbox" name="statifyblacklist[active_target]"
<input type="checkbox" name="statifyblacklist[target][active]"
id="statifyblacklist_active_target"
value="1" <?php checked( StatifyBlacklist::$_options['active_target'], 1 ); ?> />
value="1" <?php checked( StatifyBlacklist::$_options['target']['active'], 1 ); ?> />
<?php esc_html_e( 'Activate live fiter', 'statify-blacklist' ); ?>
</label>
</li>
<li>
<label for="statify-blacklist_cron_target">
<input type="checkbox" name="statifyblacklist[cron_target]" id="statifyblacklist_cron_target"
value="1" <?php checked( StatifyBlacklist::$_options['cron_target'], 1 ); ?> />
<input type="checkbox" name="statifyblacklist[target][cron]" id="statifyblacklist_cron_target"
value="1" <?php checked( StatifyBlacklist::$_options['target']['cron'], 1 ); ?> />
<?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?>
<small>(<?php esc_html_e( 'Clean database periodically in background', 'statify-blacklist' ); ?>
)
@ -178,14 +184,14 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
<label for="statify-blacklist_target_regexp">
<?php esc_html_e( 'Use regular expressions', 'statify-blacklist' ); ?>:
<br/>
<select name="statifyblacklist[target_regexp]" id="statifyblacklist_target_regexp">
<option value="0" <?php selected( StatifyBlacklist::$_options['target_regexp'], 0 ); ?>>
<select name="statifyblacklist[target][regexp]" id="statifyblacklist_target_regexp">
<option value="0" <?php selected( StatifyBlacklist::$_options['target']['regexp'], 0 ); ?>>
<?php esc_html_e( 'Disabled', 'statify-blacklist' ); ?>
</option>
<option value="1" <?php selected( StatifyBlacklist::$_options['target_regexp'], 1 ); ?>>
<option value="1" <?php selected( StatifyBlacklist::$_options['target']['regexp'], 1 ); ?>>
<?php esc_html_e( 'Case-sensitive', 'statify-blacklist' ); ?>
</option>
<option value="2" <?php selected( StatifyBlacklist::$_options['target_regexp'], 2 ); ?>>
<option value="2" <?php selected( StatifyBlacklist::$_options['target']['regexp'], 2 ); ?>>
<?php esc_html_e( 'Case-insensitive', 'statify-blacklist' ); ?>
</option>
</select>
@ -198,11 +204,11 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
<li>
<label for="statify-blacklist_target">
<?php esc_html_e( 'Target blacklist:', 'statify-blacklist' ); ?><br/>
<textarea cols="40" rows="5" name="statifyblacklist[target]" id="statify-blacklist_target"><?php
<textarea cols="40" rows="5" name="statifyblacklist[target][blacklist]" id="statify-blacklist_target"><?php
if ( isset( $statifyBlacklistUpdateResult['target'] ) ) {
print esc_html( implode( "\r\n", array_keys( $statifyBlacklistUpdateResult['target'] ) ) );
} else {
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['target'] ) ) );
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['target']['blacklist'] ) ) );
}
?></textarea>
<br/>
@ -221,8 +227,8 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
<ul style="list-style: none;">
<li>
<label for="statify-blacklist_active_ip">
<input type="checkbox" name="statifyblacklist[active_ip]" id="statifyblacklist_active_ip"
value="1" <?php checked( StatifyBlacklist::$_options['active_ip'], 1 ); ?> />
<input type="checkbox" name="statifyblacklist[ip][active]" id="statifyblacklist_active_ip"
value="1" <?php checked( StatifyBlacklist::$_options['ip']['active'], 1 ); ?> />
<?php esc_html_e( 'Activate live fiter', 'statify-blacklist' ); ?>
</label>
</li>
@ -235,11 +241,11 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
<li>
<label for="statify-blacklist_ip">
<?php esc_html_e( 'IP blacklist:', 'statify-blacklist' ); ?><br/>
<textarea cols="40" rows="5" name="statifyblacklist[ip]" id="statify-blacklist_ip"><?php
<textarea cols="40" rows="5" name="statifyblacklist[ip][blacklist]" id="statify-blacklist_ip"><?php
if ( isset( $statifyBlacklistUpdateResult['ip'] ) ) {
print esc_html( $_POST['statifyblacklist']['ip'] );
print esc_html( $_POST['statifyblacklist']['ip']['blacklist'] );
} else {
print esc_html( implode( "\r\n", StatifyBlacklist::$_options['ip'] ) );
print esc_html( implode( "\r\n", StatifyBlacklist::$_options['ip']['blacklist'] ) );
}
?></textarea>
<br/>