Feature #4 Regular expression filters
This commit is contained in:
@ -15,12 +15,16 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
* @param $options array New options to save
|
||||
* @return mixed array of sanitized array on errors, FALSE if there were none
|
||||
* @since 1.1.1
|
||||
* @changed 1.3.0
|
||||
*/
|
||||
public static function update_options( $options = null ) {
|
||||
if ( isset( $options ) && current_user_can( 'manage_options' ) ) {
|
||||
/* Sanitize URLs and remove empty inputs */
|
||||
$givenReferer = $options['referer'];
|
||||
$sanitizedReferer = self::sanitizeURLs( $givenReferer );
|
||||
if ($options['referer_regexp'] == 0)
|
||||
$sanitizedReferer = self::sanitizeURLs( $givenReferer );
|
||||
else
|
||||
$sanitizedReferer = $givenReferer;
|
||||
|
||||
/* Abort on errors */
|
||||
if ( ! empty( array_diff( $givenReferer, $sanitizedReferer ) ) ) {
|
||||
@ -110,7 +114,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
* Filter database for cleanup.
|
||||
*
|
||||
* @since 1.1.0
|
||||
* @changed 1.2.0
|
||||
* @changed 1.3.0
|
||||
*/
|
||||
public static function cleanup_database() {
|
||||
/* Check user permissions */
|
||||
@ -120,11 +124,20 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
/* Sanitize URLs */
|
||||
$referer = self::sanitizeURLs( self::$_options['referer'] );
|
||||
if ( isset( self::$_options['referer_regexp'] ) && self::$_options['referer_regexp'] > 0 ) {
|
||||
/* Merge given regular expressions into one */
|
||||
$refererRegexp = '/' . implode( "|", array_keys( self::$_options['referer'] ) ) . '/';
|
||||
if ( self::$_options['referer_regexp'] == 2 ) {
|
||||
$refererRegexp .= 'i';
|
||||
}
|
||||
} else {
|
||||
/* Sanitize URLs */
|
||||
$referer = self::sanitizeURLs( self::$_options['referer'] );
|
||||
|
||||
/* Build filter regexp */
|
||||
$refererRegexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) );
|
||||
}
|
||||
|
||||
/* Build filter regexp */
|
||||
$refererRegexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) );
|
||||
if ( ! empty( $refererRegexp ) ) {
|
||||
/* Execute filter on database */
|
||||
$wpdb->query(
|
||||
@ -135,7 +148,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
$wpdb->query( "OPTIMIZE TABLE `$wpdb->statify`" );
|
||||
|
||||
/* Delete transient statify data */
|
||||
delete_transient('statify_data');
|
||||
delete_transient( 'statify_data' );
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user