implement keyword filter for referer blacklist (closes #15)
In addition to the pre-existing normal and regular expression filters a keyword mode is added. This filter matches if the referer string contains a given keyword (case insensitive).
This commit is contained in:
@ -20,9 +20,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
const MODE_NORMAL = 0;
|
||||
const MODE_REGEX = 1;
|
||||
const MODE_REGEX_CI = 2;
|
||||
|
||||
/**
|
||||
* Initialize admin-only components of the plugin.
|
||||
@ -96,7 +93,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
'sanitized' => $sanitized_referer,
|
||||
'diff' => array_diff( $given_referer, $sanitized_referer ),
|
||||
],
|
||||
'target' => [
|
||||
'target' => [
|
||||
'sanitized' => $sanitized_target,
|
||||
'diff' => array_diff( $given_target, $sanitized_target ),
|
||||
],
|
||||
@ -334,4 +331,23 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate regular expressions, i.e. remove duplicates and empty values and validate others.
|
||||
*
|
||||
* @since 1.5.0 #13
|
||||
*
|
||||
* @param array $expressions Given pre-sanitized array of regular expressions.
|
||||
*
|
||||
* @return array Array of invalid expressions.
|
||||
*/
|
||||
private static function sanitize_regex( $expressions ) {
|
||||
return array_filter(
|
||||
$expressions,
|
||||
function ( $re ) {
|
||||
// Check of preg_match() fails (warnings suppressed).
|
||||
return false === @preg_match( $re, null );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user