MyBB Community Forums

Full Version: [Tutorial] 7 Custom MyCodes for your forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
You can view working examples at this thread, on my forum.

7 Custom MyCodes for your Forum

Hey guys, me again, and this time I'm here to show you how to add a couple new custom Mycodes to your forum.

Ones I'll teach you to add will be:
  • Marquee Text
  • Hilighted Text
  • Module
  • Fieldset
  • Custom Spacing in between text
  • Small Capitals Text
  • Image Text Background

--------------

1. Marquee

Regular expression:
\[marquee\](.*?)\[/marquee\]

Replacement:
<marquee>$1</marquee>

2. Hilighted Text
*Users will have to specify a hex code for the hilight color desired

Regular expression:
\[hilight color=(.*?)\](.*?)\[/hilight\]

Replacement:
<span style="background-color:#$1;">$2</span>

3. Module
*This will create a 'module', following your forum theme.


Regular expression:
\[module title=(.*?)\](.*?)\[/module\]

Replacement:
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr><td class="thead"><strong>$1</strong></td></tr>
<tr><td class="trow1">
$2
</td></tr>
</table>

4. Fieldset

Regular Expression:
\[fieldset title=(.*?)\](.*?)\[/fieldset\]

Replacement:
<fieldset class="bbfieldset"><legend class="bblegend"><span style="color:#2222ac;">$1</span></legend>$2</fieldset>

5. Custom spacing in between text

Regular expression:
\[spacing pixels=(.*?)\](.*?)\[/spacing\]

Replacement:
<span style="letter-spacing:$1px;">$2</span>

6. Small Capital Letters Text

Regular Expression:
\[smallcaps\](.*?)\[/smallcaps\]

Replacement:
<span style="font-variant:small-caps;" >$1</span>

7. Image Text Background

Regular Expression:
\[textbg img=(.*?)\](.*?)\[/textbg\]

Replacement:
<span style="background-image:url('$1')" >$2</span>

----------
Usage:

Marquee:
[marquee]Text[/marquee]

[b]Hilighted Text:[/b]

[code][hilight color=Color Hex Code]Text[/hilight]

Module:

[module title=Title for your module]Content here[/module]

Fieldset:

[fieldset title=Title for your fieldset]Content here[/fieldset]

Custom spacing in between text:

[spacing pixels=Pixels you want in between letters]Text[/spacing]

[b]Small Capital Letters Text:[/b]

[code][smallcaps]Text[/smallcaps]

Image Text Background (hilighted text, just with a bg image)

[textbg img=URL TO YOUR IMAGE]Text Here.[/textbg]

You can view working examples at this thread, on my forum.

Thank you.
Great Job! I might use some of these!
I've seen a number of MyCodes where "(.*?)" expression is used. I thought it'd be about time that I suggest trying to avoid that expression where possible, as this may allow users to perform some minor HTML injection (HTML tags are automatically converted to their entities and Javascript is automatically stripped out, so luckily this isn't that big an issue).

Suggestions:
Number fields, use "([0-9]+)"
General CSS fields (may not apply to everything), use "([0-9a-zA-Z\-_ ]+)"

Hope that helps.
Anyone try this yet?
all of these is bad
and doesn't work

\[marquee\](.*?)\[/marquee\]

must be
\[marquee\](*.?)\[/marquee\]

and alot of bugs
but extra good thing for a n00b oo sorry for newbie Wink
you must learn "regulair expression" befor
Best Regards
Excuse me, they DO work, if you've checked my forum.

I just copy pasted the codes, simply.
(2009-05-14, 08:20 AM)SAFAD Wrote: [ -> ]all of these is bad
and doesn't work

\[marquee\](.*?)\[/marquee\]

must be
\[marquee\](*.?)\[/marquee\]

and alot of bugs
but extra good thing for a n00b oo sorry for newbie Wink
you must learn "regulair expression" befor
Best Regards

What bugs? Come on man.
Thanks for this Tut, nunymare, it´s very usefull



(2009-05-12, 11:23 AM)Yumi Wrote: [ -> ]I've seen a number of MyCodes where "(.*?)" expression is used. I thought it'd be about time that I suggest trying to avoid that expression where possible, as this may allow users to perform some minor HTML injection (HTML tags are automatically converted to their entities and Javascript is automatically stripped out, so luckily this isn't that big an issue).

Suggestions:
Number fields, use "([0-9]+)"
General CSS fields (may not apply to everything), use "([0-9a-zA-Z\-_ ]+)"

Hope that helps.

Thanks for the Tip Yumi Smile

I´ve got some mycode and they all still used (.*?)
Thanks!
you can for example each of the code?

with
\[hilight color=(.*?)\](.*?)\[/hilight\]

i can use
[hilight color=red]text[/hilight]
or
[hilight color=#800000]text[/hilight]
???????

How can set the background image the whole article, not just the text?
Pages: 1 2