MyBB Community Forums

Full Version: Creating Custom MyCode
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9
Creating Custom MyCode is quite easy once you understand how it works. Here's a quick overview on how to make Custom MyCode:

First, go to your Admin CP and then to the Message Filters, Custom MyCode, and to Add MyCode.
  • MyCode title
    • That's just the name of the MyCode, fairly simple.

  • MyCode description
    • A basic description of what the MyCode is for; what it does.

  • Regular expression
    • This gets a bit more complicated. On the page, we are given this example:

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

      You need to have the \ before the [ and ] so it will work properly. If you imagine it without the \ it looks very basic:

      [b](.*?)[/b]

      Of course, you will still need the \ back in there for it to work properly without errors, but you can add those back later before you submit it.

    • I believe (I'm not an expert on this, but it's worked for me so far) that you put the (.*?) each time you want a variable - something the user fills in when using the MyCode. So, for instance, we could have this:

      \[a\ href=(.*?) title=(.*?)\](.*?)\[/a\]

      Which would be essentially just like the links in HTML. Now, let's look at the next option:

  • Replacement
    • This is what you want the MyCode to be once the user enters it in. So, for our previous example of the links, you would enter in this:

      <a href="$1" title="$2">$3</a>

    • Basically, all you do is for each (.*?) you put in previously, you put in an incremented variable (such as $1, $2, and $3). It's actually quite simple to understand once you get the hang of it!

  • Activate MyCode
    • This lets you turn it off without deleting it.

Note: If a user is to, for instance, not enter the title in the example above, the MyCode will not work - so if you would want something where users do not have to enter said details, then you should create multiple versions of the same thing, with/without the options.
Googling for "php perl compatible regular expressions" should provide lots of info, and various tutorials. The PHP manual also has a syntax list.

A quick explanation, which should help making future BBCode additions make more sense:
  • A period means "any character". A star means "zero or more", so altogether it means "zero or more of any character".
  • A question mark means "zero or one". In the example, you'd only want to look for the pattern looking for the (X)HTML title attribute to occur only once, or not at all.
  • Parenthesis assigns whatever matches that pattern to a variable.
  • Square brackets have special meaning, so they must be escaped with an escape character, a backslash. The same applies if you want to look for a literal star, period, question mark, etc.
sunspark Wrote:Googling for "php perl compatible regular expressions" should provide lots of info, and various tutorials. The PHP manual also has a syntax list.

A quick explanation, which should help making future BBCode additions make more sense:
  • A period means "any character". A star means "zero or more", so altogether it means "zero or more of any character".
  • A question mark means "zero or one". In the example, you'd only want to look for the pattern looking for the (X)HTML title attribute to occur only once, or not at all.
  • Parenthesis assigns whatever matches that pattern to a variable.
  • Square brackets have special meaning, so they must be escaped with an escape character, a backslash. The same applies if you want to look for a literal star, period, question mark, etc.
Thanks for pointing that out Smile Like I said, I'm just basing this on experience from my use with it in 1.2's testing days, so I tried to make it as basic as possible, without too much "technical" stuff Wink
I saw the system during the beta, but didn't no how it worked thanks for clearing it up for me! Toungue
can you give an example to add mycode which play media in windowmediaplayer?
Try this :
\[media\ filename=(.*?)\](.*?)[/media\]
and

<object width="320" height="290"
classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
id="mediaplayer1">
<param name="Filename" value="$1">
<param name="AutoStart" value="True">
<param name="ShowControls" value="True">
<param name="ShowStatusBar" value="False">
<param name="ShowDisplay" value="False">
<param name="AutoRewind" value="True">
<embed
type="application/x-mplayer2"
pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/"
width="320" height="290" src="$2"
filename="$1" autostart="True"
showcontrols="True" showstatusbar="False"
showdisplay="False" autorewind="True">
</embed>
</object>

(sry for no code[code and php not show $1,$2 vars])

Example use:

[media filename=test.avi]http://example.com/movies/test.avi[/media]

I'm not tested it .
(from http://www.adobe.com/cfusion/knowledgeba...d=tn_15777)
hello,my forum before uprgrade to 1.2 use the code [wmp]link[/wmp] show window media player for mp3.video and [flash]link[/flash] for flash file
can you tell me how to recreate them in mycode admin
instruct every steps please,i'm just a newbie
thanks everyone....mybb best forum and free!
asmilewyt Wrote:hello,my forum before uprgrade to 1.2 use the code [wmp]link[/wmp] show window media player for mp3.video and [flash]link[/flash] for flash file
can you tell me how to recreate them in mycode admin
instruct every steps please,i'm just a newbie
thanks everyone....mybb best forum and free!
Check this:

WMP Tag
MyCode Title
WindowsMediaPlayer (you can use other)
MyCode Desc
WMP player (you can use other)
Regular Expression
\[wmp\](.*?)\[/wmp\]
Replacement
<OBJECT id="VIDEO" width="320" height="240"
style="position:absolute; left:0;top:0;"
CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">

<PARAM NAME="URL" VALUE="$1">
<PARAM NAME="SendPlayStateChangeEvents" VALUE="True">
<PARAM NAME="AutoStart" VALUE="True">
<PARAM name="uiMode" value="full">
<PARAM name="PlayCount" value="1">
</OBJECT>


Flash Tag

MyCode Title
Flash BBCode(you can use other)
MyCode Desc
Opening a flash file(you can use other)
Regular Expression
\[flash\](.*?)\[/flash\]
Replacement
<object width="320" height="240">
<param name="movie" value="$1">
<embed src="$1" width="320" height="240">
</embed>
</object>
thanks a lot.you're so kind!!
oh it doesn't work.just show the blank in the post
Pages: 1 2 3 4 5 6 7 8 9