MyBB Community Forums

Full Version: do extended parsing and validation on mycodes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a relatively simple mycode I want to add to my forum but I cannot figure out the best facility to do that in mybb

Basically, it's a forum based on an online game and there is a service that when you make a link to something, a javascript include in the header file generates a mouseover that shows you item information. If you've ever played World of Warcraft, it's like what happens when you mouseover an item in your bag.

Now by default you can do [url] tags to do this, but it's kind of cumbersome. For example, here is a "Marmot Steak" recipe link:

<a href="http://ffxiv.yg.com/recipe/marmot-steak">Marmot Steak</a>

And with some cumbersome bbcode, it works:

[url=http://ffxiv.yg.com/recipe/marmot-steak]Marmot Steak[/url]

Now what I want to do is make a tag, [recipe], that accomplishes the same thing. In other words, typing [recipe]Marmot Steak[/recipe], the above link would be generated. We can get 90% of the way there easily:

New mycode regular expression: \[recipe\](.*?)\[/recipe\]

Replacement: <a href="http://ffxiv.yg.com/recipe/$1">$1</a>

The only issue, of course, is that the generated link is http://ffxiv.yg.com/recipe/Marmot Steak, when it should be http://ffxiv.yg.com/recipe/marmot-steak

Try as I might, I cannot figure out a way to actually transform the input, for example:

<a href="http://ffxiv.yg.com/recipe/<?php echo urlencode($1)?>">$1</a>

doesn't get me anywhere!

Is there any way to do this transformation within the mycode editor? If not, where would be the ideal place for a plugin hook?

Thank you Smile
The best would just be a plugin period.

./inc/class_parser.php

 96      parse_message_start                               $message
 162     parse_message                                     $message
 200     parse_message_end                                 $message

I personally run off parse_message_end for my MyCode plugins. That way all the other MyCodes are already parsed.
Edit: Got it! Had some silly errors basically that kept it from working. Leaving final version here for anyone who stumbles across in a search Smile

$plugins->add_hook("parse_message_end", "ygtag");


function ygtag($message)
{
        return preg_replace("~\[(item|skill|guildleve|quest|recipe)\]([A-Za-z0-9\ ]{0,30})\[/(item|skill|guildleve|quest|recipe)\]~",
                "parseygtag",
                $message);
}

function parseygtag($replacement) {
        return "<a href='http://ffxiv.yg.com/" . $replacement[1] . "/" . str_replace(" ", "-", strtolower($replacement[2])) . "'>" . $
}
(2010-09-10, 06:26 AM)Boten Anna Wrote: [ -> ]Edit: Got it! Had some silly errors basically that kept it from working. Leaving final version here for anyone who stumbles across in a search Smile

$plugins->add_hook("parse_message_end", "ygtag");


function ygtag($message)
{
        return preg_replace("~\[(item|skill|guildleve|quest|recipe)\]([A-Za-z0-9\ ]{0,30})\[/(item|skill|guildleve|quest|recipe)\]~",
                "parseygtag",
                $message);
}

function parseygtag($replacement) {
        return "<a href='http://ffxiv.yg.com/" . $replacement[1] . "/" . str_replace(" ", "-", strtolower($replacement[2])) . "'>" . $
}

Very useful, I'm glad you shared this!