Adding custom UBB codes is probably the easiest thing any individual user can do. It does require some knowledge of how PERL regular expressions work, or the ability to reason it out. Here's a quick rundown.
You'll need to edit two files, ubb_lib.cgi and ubb_lib_posting.cgi.
First, open ubb_lib.cgi and find the line "sub UBBCode {". This is the routine that converts a user's message into html using UBBCode rules. Here's a sample from the routine, which converts [ b][ /b] (without spaces) into
:
$_[0] refers to the whole message. =~ followed by s/ tells the compiler that it's going to search through the entire message and replace what comes next with whatever comes after that (just hold on, I know it's confusing). This is the search/replace format: s/find this string/replace with this string/extra tags;. Here's the fun part.
Between the first two "/" is what the search algorithm is going to replace. In this case, we're searching for [ b] followed by text and a closing [ /b]. You use parentheses to separate different "pieces" of a search. The first (
) says to look for [ b]; you always put a in front of brackets, because they usually denote something else in PERL (array indices). After that comes (.+?). In english, this code tells the compiler to match any sequence of characters of any length. This represents the text that you want to bold-ify. Finally comes a (), which searches for the final [ /b]. Again, a / by itself would normally denote the end of the "replace this text" part of the search, so you put a in front of it to tell the compiler to physically search for a /. So all that will find any string surrounded by [ b] [ /b]. Pretty, ain't it?
Next is the "replace with" part, which follows the second /. This one's a little easier. We start the replace-with code with a
, since we want the final text to be displayed as bold, and is the HTML way to denote bold. Following that is a $2 -- this is PERL notation for "what was found by the (.+?)" You follow with a to add the final tag.
After the "replace with" code comes extra tags that tell the search how to perform. In most cases you'll add an /isg; to your search. "i" tells the search to Ignore Case; "s" says that spaces and endlines can be used in the match; and I forget what g does. Use it anyways

.
So that little tag of code is what turns [ b]This text here [ /b] into
this text here.
But that's only half the story

. The UBB still has to know how to turn the HTML from a message back into UBBCode, for when users edit their posts. Open ubb_lib_posting.cgi to see how that's done. Find "sub reverse_ubb_code {". The code is essentially the same, only a little backwards.
In this case, we want to replace
TEXT with [ b]TEXT[ /b]. I think you can see how it does it, if you followed my previous example.
SO! How to add your own commands? You'll need to add code to both the UBBCode and reverse_ubb_code functions. I'll give you an example, using [center] to center text. Following is a general template for what to add to make your own custom commands.
So, following the template to add [center]:
In ubb_lib.cgi, we add $_[0] =~ s/([center])(.+?)([/center])/
$2/isg;
In ubb_lib_posting.cgi, we add $_[0] =~ s/(
And that's it. The toughest part is figuring how to represent what you want in HTML. Here are some things I use in my UBB:
Center: as above
Indent:
Right-justify:
Red highlighting:
Small font:
The possibilities are all but endless. Hope this somewhat helps.
[edit: stupid smilies mess up code]
[ 10-27-2001: Message edited by: Influenza ]