MyBB Community Forums

Full Version: Adding BBCode
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I am running a web site for a gaming guild (for Warhammer Online), and one thing the members are asking for is the ability to 'link' to items in posts. The website WarDB has what seems to be a great guide for doing this here:

http://www.wardb.com/syndication.aspx

And they have instructions for doing this for many popular BB systems, but not MyBB. I have spent many hours searching these forums and attempting different ways to do this, but have found none that work yet.

If anyone could help point me in the right direction I would be most appreciative.
Edit your templates to put in the Javascript. Open your theme, and then edit "Ungrouped Templates". Edit "headerinclude" and put in the <script type="text/javascript" src="http://www.wardb.com/js/extooltips.js"></script> after the rest of the javascripts.

Then go into "Configuration" in your ACP. On the left, select "MyCode", then on the tabs, select "Add New MyCode". Enter the following:

Title: Item
Description: Warhammer Details
Regular Expression: \[item\](.*?)\[/item\]
Replacement: <a href="http://www.wardb.com/quest.aspx?id=$1">????</a>

and leave the rest. You can replace the ???? with custom text, or put in $1 to leave the ID number. I didn't have much time to check out the installation guides but that's the "light" version of installing this...

To use, put something like [item]idnumber[/item]...
Very helpful, thank you! I was close in my attempts but your explanation points out where I was missing some things. I will try this as soon as I get a free moment and let you know how it works out.

Thanks again!
Works great!

Does the script line have to be in the headerinclude template or could I put it as the first line in the "Replacement" section of the MyCode entry? The advantage of doing so would be that this would work in every theme present and future with no need to alter the templates.
(2008-10-24, 03:28 PM)Tom.M Wrote: [ -> ]Regular Expression: \[item\](.*?)\[/item\]
Replacement: <a href="http://www.wardb.com/quest.aspx?id=$1">????</a>
If the item id is always a number, you should only match digits so people can't inject other HTML in there.

For example...
\[item\]([0-9]+?)\[/item\]

(haven't tested)

(2008-10-24, 03:48 PM)Tiscan Wrote: [ -> ]Does the script line have to be in the headerinclude template or could I put it as the first line in the "Replacement" section of the MyCode entry? The advantage of doing so would be that this would work in every theme present and future with no need to alter the templates.

The site you linked says to put it in the head section, so I would leave it there yes.
Ack! Yea the ID is always a number so restricting it as you propose above is a very good idea. I am sure someone would eventually use it to inject HTML otherwise.

Thanks. Smile
BTW your regex example from above worked, no problem. Smile