From 8c11d197a049446907a8ca2ef3d274562fae081c Mon Sep 17 00:00:00 2001 From: Robert Kehl Date: Sat, 21 Mar 2015 23:42:00 +0100 Subject: [PATCH 1/2] fixed word boundary by using \b instead ([\W\s]?) --- text-obfuscator.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/text-obfuscator.php b/text-obfuscator.php index 086ba4f..fbca346 100644 --- a/text-obfuscator.php +++ b/text-obfuscator.php @@ -308,11 +308,12 @@ function obfuscator_build_replacement_elements( $replacementItem ) { $caseModifier = 'i'; } if ( 'part' == $replacementItem['scope'] ) { - return array( 'token' => '/'.preg_quote( $replacementItem['token'], '/' ).'/'.$caseModifier, - 'value' => $replacementItem['value'] ); + $boundary = '\b'; } else { - return array( 'token' => '/([\W\s]?)'.preg_quote( $replacementItem['token'], '/' ).'([\W\s]+)/'.$caseModifier, - 'value' => '\\1'.$replacementItem['value'].'\\2' ); + $boundary = ''; + } + return array( 'token' => '/'.$boundary.preg_quote( $replacementItem['token'], '/' ).$boundary.'/'.$caseModifier, + 'value' => $replacementItem['value'] ); } } else { return false; @@ -382,4 +383,4 @@ function obfuscator_filter_input( $content, $content_type = 'posts' ) { function obfuscator_filter_input_content( $content ) { return obfuscator_filter_input( $content, 'posts' ); } function obfuscator_filter_input_title( $content ) { return obfuscator_filter_input( $content, 'titles' ); } function obfuscator_filter_input_excerpt( $content ) { return obfuscator_filter_input( $content, 'excerpts' ); } -function obfuscator_filter_input_comment( $content ) { return obfuscator_filter_input( $content, 'comments' ); } \ No newline at end of file +function obfuscator_filter_input_comment( $content ) { return obfuscator_filter_input( $content, 'comments' ); } From fc7f35946d8ae067043f9e462c6a818827733b32 Mon Sep 17 00:00:00 2001 From: Robert Kehl Date: Sun, 22 Mar 2015 01:49:16 +0100 Subject: [PATCH 2/2] added RegEx support, missing checks for faulty REs --- text-obfuscator.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/text-obfuscator.php b/text-obfuscator.php index fbca346..21dda9c 100644 --- a/text-obfuscator.php +++ b/text-obfuscator.php @@ -128,6 +128,7 @@ function obfuscator_sanitize_options( $data ) { 'scope' => ( isset( $replacementPair['scope'] ) && ( 'part' == $replacementPair['scope'] ) ) ? 'part' : 'full', 'case' => ( isset( $replacementPair['case'] ) && ( 'insensitive' == $replacementPair['case'] ) ) ? 'insensitive' : 'sensitive', 'type' => ( isset( $replacementPair['type'] ) && ( 'post' == $replacementPair['type'] || 'page' == $replacementPair['type'] ) ) ? $replacementPair['type'] : 'all', + 'regex' => ( isset( $replacementPair['regex'] ) ) ? true : false, 'value' => ( isset( $replacementPair['blank'] ) ) ? '' : $replacementPair['value'], 'blank' => ( isset( $replacementPair['blank'] ) ) ? true : false, 'location' => ( isset( $replacementPair['location'] ) && ( 'pre' == $replacementPair['location'] ) ) ? 'pre' : 'post', @@ -204,10 +205,12 @@ function obfuscator_admin_page() {

Text Obfuscator admin

Your replacement rules have been updated.

Output rules will apply immediately, input rules will apply to any data saved from now on.

'; } ?>

Add the term you want replacing into 'Match' and the text you want that term changing to in the 'Replace' box. Select when you want the replacement to take place and check the boxes to select which bits of content you want the filter to apply to. To remove a rule simply delete the match string for that line; if it's a display filter the original text will appear, if it's a save filter the replaced text will remain.

+

To use regular expressions in 'Match', check the box in the column labeled 'RegEx'. Backreferences to match patterns surrounded by braces () work in 'Replace' with RegEx on, otherwise your input in 'Match' gets quoted, so that using regular expressions has no effect. You may than match for '*super*', which would not work when using regular expressions. To learn more about regular expressions, visit php.net.

+ @@ -252,6 +255,7 @@ function obfuscator_admin_page() { ?> +
MatchRegEx Replace Content Title style="margin-top: 18px;" /> style="width: 220px;" />
'/'.$boundary.preg_quote( $replacementItem['token'], '/' ).$boundary.'/'.$caseModifier, - 'value' => $replacementItem['value'] ); + if ( 'part' != $replacementItem['scope'] ) { + $replacement = '\b'.$replacement.'\b'; } + $replacement = '/'.$replacement.'/'; + if ( 'insensitive' == $replacementItem['case'] ) { + $replacement = $replacement.'i'; + } + return array( 'token' => $replacement, + 'value' => $replacementItem['value'] ); } else { return false; }