The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Process post text replacements, abbreviations, fake BBCODE's Details »» | |||||||||||||||||||||||||||
Process post text replacements, abbreviations, fake BBCODE's
Developer Last Online: Mar 2007
Generalized Word or Text Replacer For User Inputs (Posts, etc.)
Version .2: Replace, remove, define abbreviations, define fake bbcodes. Requires 1 small mod and adds 1 new function. No queries. (Please, do not suggest that replacement variables can do this. See below.) Allows an administrator to define the following sorts of replacements for posts, titles, and all other user input fields: conservative => montague Replace. Transform any word match, preserving case in the replacement. as in Conservative=>Montague, CONSERVATIVE=>MONTAGUE. uglytext => Removal. Completely remove any occurrence. Like all others you define, can be specified to match word only or any occurrence. .us => http://our.domain.com Abbreviation. If defined as a word match, it would work for " .us " or " .us/subdir", but not for "him.us" or ".use". [h1] => [ size=4][ color=navy][ i] [/h1] => [ /i][ /color][ /size] Abbreviation. New BBCODES :cheeky:: Abbreviation for something more complicated. (Do not add the spaces after the open ['s. I used just to show these codes in this post.) Usage for these is as you'd expect: [h1]Some Heading[/h1] Modifications Required This hack requires 2 changes to one file, functions.php: * 1 function modification (a few new lines) * 1 new function How It Works The Admin adds replacement definitions using the same field as for censorship: AdminCP>vBulletin Options>Censorship Options. No change is require on the AdminCP side. On the user code side, the function that now does censorship is modified to support these new replacements. Replacement will take place anywhere that normal censorship takes place. Replacements should be defined in the AdminCP censorship field BEFORE plain censorship. See small attached image, where the first 5 lines are replacements and the rest of plain censorship. Defining Replacements Instead of simple censorship words or strings, rules are added to the censorship field in AdminCP in the same place that you currently add words to be censored. You add rules are of the form: FIND_SPEC=REPLACEMENT where REPLACEMENT is optionable. There are two types of rules: (1) string match (2) word match. his=her STRING MATCH, CASE INSENSITIVE. Find any occurrence of the characters "his"{oldword}=newword WORD MATCH, CASE INSENSITIVE. Replace any occurrences of "oldword" withPreserving Upper Or Lower Case (using "=="): Either type of match supports the feature of case preservation: matching the case of the found text in the replacement text. Use "==" instead of "=" to specify that case should be preserved. Example: {oldword}==newword Search is case insensitive, but replacement preserves case. This would matcholdword==newword Same as above, but matches are string matches rather than word matches.Removing Words or Text: If no replacement text is specified, as in "uglychars= ", then the match is simply removed from the user's input. This is an alternative to the censorship replacement by *'s. Abbreviations: Another possible use is for abbreviations. For example, one could define the word ".us" as a shorthand for the site url by using the following rule: {.us}=http://www.our-domain.comwhich would match ".us" only as a word, as in ".us/forum" or "go to .us site.", but not "foo.us" or ".use". Fake BBCODE: You can define an abbreviation that looks like a bbcode. This allows an administrator to define pseudo-bbcode's. You can also use bbcode's in the replacement. As you might expect, "{[red]}=REPLACEMENT" will match [red] as if it were a word and "[red]=REPLACEMENT" will match any occurrence. Disallowed characters in replacements: The following characters are not permitted in replacement text: & ampersand, % percent, < less than, > greater than, ` backquote, \ backslash Installation Instructions 1. You should include the text of the attached file (a new PHP function) in functions.php, just before the fetch_censored_text would be appropriate. 2. In the function fetch_censored_text in functions.php, find this line: Code:
if (substr($censorword, 0, 2) == '\\{') Code:
if (strpos($censorword, '=') !== false) { $text = fetch_censored_text_replacer($text, $censorword); } else if (substr($censorword, 0, 2) == '\\{') You can set "$TEST_USERIDS" in the attached function to your own USERID for testing, so that this mod will not take affect for other users. Then, when you are satisfied and you want to release it, you can set this value back to empty by removing the userid that you added. I have set it to userid "1" (one) in the attachment. This mod is beta as I have have only tested it on my board, and while I am satisfied with the results, I would not call the testing extensive. Cautionary Notes The vB implementation of censored words will match "com" when it is surrounded by any non-letter. Therefore, the censored word input "{com}" will match twice in this phrase, producing the result shown: Well, 3com is not exactly a .com company. translates to: Well, 3*** is not exactly a .*** company. This same matching implmentation is used by this mod in order to be compatible with vB. Note that Admin's need to be careful about using translations that will match common words or strings. Remember that translation will take place everywhere that censorship takes place, including of course user profiles and signatures. Editpost Bug -- Bad Preview editpost.php does not display previews properly when bbcode abbreviations are used. In editpost.php, censorship is done after bbcode parsing, unlike newthread.php and newreply.php, where previewing works fine for bbcode abbreviations. BTW, the same bug is why URL's are not processed in the preview when you edit a post. I entered vB bugid: 3301. A note concerning replacement variables Replacement variables do not have the same flexibility as this mod. Also, I believe they are style specific. More importantly, replacement variables do replacements on ALL output sent to the user, which is often very dangerous. If you defined a replacement variable for "shat", it would replace it everywhere, including in www.shattered.com and HTML and javascript and style sheets... well you get the idea. Cheers, C.C Show Your Support
|
Comments |
#2
|
||||
|
||||
interesting addition
|
#3
|
|||
|
|||
Something struck me last night that I forgot to mention. Since the things in the censorship field are processed in the order they are defined, all replacements should be defined before all plain censorship.
This ensures that the final version of the post, title, etc. is subjected to ordinary censorship. Attachment shows AdminCP>vBulletin Options>Censorship Options field with censorship defined AFTER replacements (the first 5 lines). Cheers |
#4
|
|||
|
|||
*** RESOLVED
I missplaced one of the replacement variables. Quote:
|
#5
|
||||
|
||||
Very nice!
I've been looking for someone to create this hack! |
#6
|
||||
|
||||
Time to move this one out of beta ... it workd great!
|
#7
|
|||
|
|||
Thanks! This is just what I needed!
|
#8
|
|||
|
|||
Very nice.. any thoughts on really hacking it up to allow spaces in both the search and replace text? It'd be nice to replace on phrases as well.
|
#9
|
|||
|
|||
this is the worst hack, in the history of mankind. ever hear of preg_match... lol
|
#10
|
||||
|
||||
wow why insult someone elses hack like that?
|
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|