Posts Tagged ‘vbulletin’

vBulletin word replacement

Saturday, January 31st, 2009

After looking for a simple plugin to replace some words with HTML code for vBulletin I decided to just figure it out and do it on my own. I don’t know a lot about vBulletin, other than how to use it, but I am pretty good with PHP. To start with I looked at the file “showthread.php”. I tried a couple of things in it but nothing worked the way that I wanted it to. I looked around a bit more and started working with the file “class_bbcode.php”. This file does the BB code conversion for vBulletin. After a few tries I found a good spot to insert a snippet of code.

To do this modification open the file class_bbcode.php and find the method “parse”. In my version of vBulletin it is on line 244.  At the end of that method there is a section of code:

if (!empty($parsedtext))
{
if ($parsedhasimages)
{
return $this->handle_bbcode_img($parsedtext, $dobbimagecode, $parsedhasimages);
}
else
{
return $parsedtext;
}
}
else
{
return $this->do_parse($text, $dohtml, $dosmilies, $dobbcode, $dobbimagecode, $donl2br, $cachable);
}

Just after the line “if (!empty($parsedtext)){” add a string replacement function:

$parsedtext = str_ireplace('someword', 'newword', $parsedtext);

Now when you view the post in your vBulletin forum anywhere the word “someword” appears, it will be replaced with “newword”.