diff --git a/text-obfuscator.php b/text-obfuscator.php index 086ba4f..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;" />
'/'.preg_quote( $replacementItem['token'], '/' ).'/'.$caseModifier, - 'value' => $replacementItem['value'] ); + if ( true == $replacementItem['regex'] ) { + $replacement = $replacementItem['token']; } else { - return array( 'token' => '/([\W\s]?)'.preg_quote( $replacementItem['token'], '/' ).'([\W\s]+)/'.$caseModifier, - 'value' => '\\1'.$replacementItem['value'].'\\2' ); + $replacement = preg_quote( $replacementItem['token'], '/' ); + } + 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; } @@ -382,4 +389,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' ); }