Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Beta Releases

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

Quote:
Originally Posted by eva01_
wow why insult someone elses hack like that?
because a simple preg_match would do this whole hack, and so much more.
Reply With Quote
  #13  
Old 03-14-2005, 10:14 AM
MrToasty MrToasty is offline
 
Join Date: May 2004
Location: Adelaide AU
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

less words, more code... preg_match me...
Reply With Quote
  #14  
Old 05-04-2005, 03:31 AM
granpa yum granpa yum is offline
 
Join Date: Aug 2004
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this wont work for me, when i do it i get the error "
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /public_html/forums/includes/functions.php on line 2119"

any ideas
Reply With Quote
  #15  
Old 05-04-2005, 02:10 PM
psoexplorer psoexplorer is offline
 
Join Date: Sep 2003
Posts: 80
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice little hack! How do I change whole phrases though?
Reply With Quote
  #16  
Old 06-17-2005, 10:50 AM
CarCdr CarCdr is offline
 
Join Date: Apr 2004
Posts: 242
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by pimpery
this is the worst hack, in the history of mankind. ever hear of preg_match... lol
LOL.
Reply With Quote
  #17  
Old 07-18-2005, 03:36 PM
husain's Avatar
husain husain is offline
 
Join Date: Feb 2005
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is exactly what I was looking for. Is it still in beta?
Reply With Quote
  #18  
Old 07-23-2006, 05:18 PM
Bison's Avatar
Bison Bison is offline
 
Join Date: Jun 2002
Location: Virginia Beach, Virginia
Posts: 522
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It would be nice is one of you Smart Guys could update this hack to work with vB 3.5
Reply With Quote
  #19  
Old 03-02-2007, 09:28 PM
jeepinator jeepinator is offline
 
Join Date: Dec 2004
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

^ Yes please.
Reply With Quote
  #20  
Old 03-14-2007, 01:50 AM
tokosan's Avatar
tokosan tokosan is offline
 
Join Date: Dec 2005
Location: Atlanta
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

cool man, thanks for makin this much needed mod.

i'm going to get my friend, who knows what a computer is, to install this when he gets on.
Reply With Quote
  #21  
Old 10-29-2007, 04:18 AM
vgevolution vgevolution is offline
 
Join Date: Nov 2006
Location: Beyond the Looking Glass
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just applied this hack in 3.6.8. So far, it seems to work fine. It would be nice to be able to replace using spaces as well, but that could be a tough one. Perhaps the built-in filter will be upgraded someday?
Reply With Quote
Reply

Thread Tools

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 03:16 PM.


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.11799 seconds
  • Memory Usage 2,311KB
  • Queries Executed 25 (?)
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
  • (2)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
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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