Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Beta Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Process post text replacements, abbreviations, fake BBCODE's Details »»
Process post text replacements, abbreviations, fake BBCODE's
Version: 1.00, by CarCdr CarCdr is offline
Developer Last Online: Mar 2007 Show Printable Version Email this Page

Version: 3.0.0 Rating:
Released: 08-14-2004 Last Update: Never Installs: 16
Is in Beta Stage  
No support by the author.

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"
and replace it with "her". The case of letters in the replacement ("her")
is used exactly as specified. This would match 3 times in in this fragment:
"His history was this."
{oldword}=newword
WORD MATCH, CASE INSENSITIVE. Replace any occurrences of "oldword" with
"newword", using the replacement exactly as specified (it does not change
the case of any letters).
Preserving 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 match
all occurrences of the word "oldword", regardless of case, but it would attempt to
preserve case in three instances: initial capital, all uppercase, and all
lowercase. Examples translations from the the above rule would be:
Oldword => Newword
OLDWORD => NEWWORD
oldword => newword
A nuance here is that if the found text is not all lowercase, all uppercase,
or a single initial capital (e.g., OldWord), the the replacement text is
used exactly as specified in the rule. For example, the rule "{old}==New"
would use "New" as the replacement if "oLd" were matched.
oldword==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.com
which 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) == '\\{')
and add this BEFORE it (just the non-red text):
Code:
     if (strpos($censorword, '=') !== false)
          {
               $text = fetch_censored_text_replacer($text, $censorword);
          }
          else if (substr($censorword, 0, 2) == '\\{')
Restricting Access/Testing:
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

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 08-15-2004, 09:25 PM
???`S?LV?R???`'s Avatar
???`S?LV?R???` ???`S?LV?R???` is offline
 
Join Date: Aug 2003
Posts: 368
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

interesting addition
Reply With Quote
  #3  
Old 08-16-2004, 11:01 AM
CarCdr CarCdr is offline
 
Join Date: Apr 2004
Posts: 242
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #4  
Old 11-24-2004, 04:48 PM
JohnBee JohnBee is offline
 
Join Date: Oct 2004
Posts: 544
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

*** RESOLVED

I missplaced one of the replacement variables.

Quote:
im not 100% on the userid thing, will it it work?

I added the following to the censorship {++++}==sh*t
but it doesnt do anything, or did I miss something.
Reply With Quote
  #5  
Old 11-27-2004, 05:07 AM
Bison's Avatar
Bison Bison is offline
 
Join Date: Jun 2002
Location: Virginia Beach, Virginia
Posts: 522
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Very nice!
I've been looking for someone to create this hack!
Reply With Quote
  #6  
Old 12-06-2004, 02:42 AM
Bison's Avatar
Bison Bison is offline
 
Join Date: Jun 2002
Location: Virginia Beach, Virginia
Posts: 522
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Time to move this one out of beta ... it workd great!
Reply With Quote
  #7  
Old 02-26-2005, 11:52 PM
Trillian Trillian is offline
 
Join Date: Oct 2001
Location: Indonesia
Posts: 22
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks! This is just what I needed!
Reply With Quote
  #8  
Old 03-11-2005, 05:28 PM
Brains Brains is offline
 
Join Date: Sep 2003
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 03-12-2005, 12:00 AM
pimpery pimpery is offline
 
Join Date: Nov 2004
Posts: 103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this is the worst hack, in the history of mankind. ever hear of preg_match... lol
Reply With Quote
  #10  
Old 03-12-2005, 12:41 AM
eva01_'s Avatar
eva01_ eva01_ is offline
 
Join Date: Aug 2004
Location: Plymouth
Posts: 255
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

wow why insult someone elses hack like that?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:26 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06231 seconds
  • Memory Usage 2,306KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete