Replacement and Censorship System

From FUDforum Wiki
Jump to: navigation, search
Info Symbol NOTE: The messages and signatures entered prior the the addition of a replace will not be affected by the newly added replace syntax. To update existing messages, use the Compact Messages control panel.

The Replacement and Censorship admin control panel allows the administrator to replace certain strings in the messages, signatures and biographies of the users with alternate text strings.

The most common use of this system is to censor certain words and phrases that the admin feels are inappropriate for the forum. It can also be used to create active text links. For example, when someone types FUDforum, to replace it with a link to fudforum.org.

FUDforum offers two syntaxes for replacing text ranging from a simple replace to a complex regular expression:

String Replace

The most basic and the easiest to use string replacement option is "String Replace". This option will allow you to specify the 'Replace' string with its alternative the 'With' string. For example, if you specify the replace string as "haystack" and it's alternative as "needle" then -

this haystack is sharp.

will be converted to:

this needle is sharp.

Perl Regex

Perl Regex will use a perl regular expression library to perform a replacement on a text or a text mask. This, although slower than str_replace, allows for much more powerful and sophisticated text manipulation.

Info Symbol NOTE: This functionality uses PHP's PECL library and utilize the preg_replace function. PHP's documentation of this function and its capabilities and syntax can be found here.

Lets say, you want to replace all words containing the string 'spoon' with 'fork'. Clearly you cannot use String Replace for this because it would not replace the entire word but only the 'spoon' part. For this purpose you need to use the power of regular expressions.

Inside the 'Replace' field we enter: the

!(\s|^)([^\s]*?)spoon([^\s]*?)(\s|$)!i

regular expression and enter

\1fork\4

as the 'With' alternative. The end result of this regex is that any word containing the string "spoon" will be replaced with "fork". Because we've added the 'i' parameter to our regex, which made it case-insensitive, so even the "SpOon" instances will be found and replaced.

Because the regular expression is generally rather complex there is no easy way FUDforum can figure out how to reverse it back, so that when the person is editing their text they can see the text that they have originally entered. Therefore you get 2 extra fields ('From post' and 'To') were you get to specify the "reverse" regex that would convert the replaced data back to its original form. Based on the previous example involving "fork" and "spoon" the conversion back strings would look like this:

From post:	!(\s|^)fork(\s|$)!
To:		spoon

Example strings

Here are some example replacement strings you may want to add to your forum:

Replace Type Replace With Description
String Replace haystack needle Replace haystack with needle.
String Replace FUDforum [url=http://fudforum.org]FUDforum[/url] Active text to turn the word FUDforum into a link.
Perl Regex /(\s|^)bcoz(\s|$)/i \1because\2 Replace bcoz with because.
Perl Regex /(\s|^)gr8(\s|$)/i \1great\2 Replace gr8 with great.
Perl Regex /(\s|^)thnx(\s|$)/i \1thank you\2 Replace thnx with thank you.
Perl Regex /(\s|^)plz(\s|$)/i \1please\2 Replace plz with please.
Perl Regex /(\s|^)cud u(\s|$)/i \1could you\2 Replace cud with could you.
Perl Regex /[A-Za-z0-9._]+@[A-Za-z0-9.]+\.[A-Za-z]{2,3}/ <private_email> Replace any email address with <private_email>.
Languages
Personal tools