Previous Thread
Next Thread
Print Thread
Rate Thread
#50829 10/27/2001 7:57 PM
Joined: Oct 2001
Posts: 33
Junior Member
Junior Member
Offline
Joined: Oct 2001
Posts: 33
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 :
Code
code:
$_[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 smile .

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 wink . 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.

Code
code:

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.
Quote
quote:
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 ]


(Scientists) are apolitical, supposedly, like civil servants--empiricists, who only wanted things managed in a rational scientific style, the greatest good for the greatest number, which ought to be fairly simple to arrange, if people were not so trapped in emotions, religions, governments, and other mass delusional systems of that sort.
Sponsored Links
Entire Thread
Subject Posted By Posted
Some hacks I need Zedd 10/20/2001 3:13 PM
Re: Some hacks I need ak 10/21/2001 3:23 AM
Re: Some hacks I need Brett 10/21/2001 6:30 AM
Re: Some hacks I need Outback2K1 10/21/2001 9:46 AM
Re: Some hacks I need ak 10/21/2001 3:29 PM
Re: Some hacks I need Zedd 10/21/2001 5:01 PM
Re: Some hacks I need Zedd 10/21/2001 6:19 PM
Re: Some hacks I need Brett 10/21/2001 10:14 PM
Re: Some hacks I need Zedd 10/21/2001 10:21 PM
Re: Some hacks I need Outback2K1 10/22/2001 3:50 AM
Re: Some hacks I need ak 10/22/2001 4:27 AM
Re: Some hacks I need Zedd 10/22/2001 6:06 AM
Re: Some hacks I need John A. MacDonald 10/28/2001 2:23 AM
Re: Some hacks I need Influenza 10/28/2001 2:57 AM
Re: Some hacks I need Ramirez 11/02/2001 9:40 AM
Re: Some hacks I need Paule 04/07/2002 12:52 PM
Re: Some hacks I need ADWOFF 04/07/2002 10:49 PM

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Ruben Rocha
Ruben Rocha
Lutz,FL,USA
Posts: 254
Joined: January 2000
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)