DTTVB
Not So New User

Joined: 18 Aug 2005
Posts: 45
Location: Thailand (GMT+7)
|
Posted: September 14th 2005, 7:08 pm Post subject: Making Your Custom BBCode |
|
|
Well, this tutorial will show how to make custom BBCodes
First, open PHPBB Root Path\includes\bbcode.php
You will find these:
| Code:
|
function bbencode_first_pass($text, $uid)
{
// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$text = " " . $text;
// [code] and [/code] for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, '');
// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
$text = bbencode_first_pass_pda($text, $uid, '[quote]', '[/quote]', '', false, '');
$text = bbencode_first_pass_pda($text, $uid, '/\[quote=(\\\".*?\\\")\]/is', '[/quote]', '', false, '', "[quote:$uid=\\1]");
// [list] and [list=x] for (un)ordered lists.
$open_tag = array();
$open_tag[0] = "[list]";
// unordered..
$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems');
$open_tag[0] = "[list=1]";
$open_tag[1] = "[list=a]";
// ordered.
$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems');
|
Well let's add a new code.
BBCode must be translated and insert to database
So [b] and [/b] would be [b:0123456789] and [/b:0123456789]
No-Variable BBCode Such as [move] (Like YaBB)
We will add this:
| Code:
|
|
$text = preg_replace("#\[move\](.*?)\[/move\]#si", "[move:$uid]\\1[/move:$uid]", $text);
|
You will see in first agrument, we will add \ before [ and ]
But I have no idea about # and #si
Second agrument:
$uid must be placed so [move] can become [move:0123456789]
\\1 is the text.
Variable BBCode Such as [align]
| Code:
|
|
$text = preg_replace("#\[align=([a-zA-Z]+)\](.*?)\[/align\]#si", "[align=\\1:$uid]\\2[/align:$uid]", $text);
|
Like the first one
Second one \\1 is first agrument
\\2 is text
But if you made 2 agrument, so
\\1 is 1st agrument \\2 is second agrument
and \\3 is text
Find this
| Code:
|
function bbencode_second_pass($text, $uid)
{
global $lang, $bbcode_tpl;
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$text = " " . $text;
// First: If there isn't a "[" and a "]" in the message, don't bother.
if (! (strpos($text, "[") && strpos($text, "]")) )
{
// Remove padding, return.
$text = substr($text, 1);
return $text;
}
// Only load the templates ONCE..
if (!defined("BBCODE_TPL_READY"))
{
// load templates from file into array.
$bbcode_tpl = load_bbcode_template();
// prepare array for use in regexps.
$bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
}
// [code] and [/code] for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);
// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
$text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text);
$text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text);
|
We must do for each open and close tag.
So... First let's see for [move]
| Code:
|
$text = str_replace("[move:$uid]", "<marquee>", $text);
$text = str_replace("[/move:$uid]", "</marquee>", $text);
|
First one is translated BBCode [move:0123456789] and [/move:0123456789]
Second one is HTML code.
| Code:
|
$text = preg_replace("/\[align=([a-zA-Z]+):$uid\]/si", "<div align=\\1>", $text);
$text = str_replace("[/align:$uid]", "</div>", $text);
|
Just like first one, but variables will be \\1 and \\2
Be sure to use "Double Quote"
Make your own protocol
| Code:
|
function make_clickable($text)
{
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $text;
|
After that line we'll add a "Flash" protocol
It goes like this: flashhttp://www.and-so-on.com/myfile.swf
Well add this
| Code:
|
|
$ret = preg_replace("#(^|[\n ])flash([\w]+?://[^ \"\n\r\t<]*)\?([0-9]+)&([0-9]+)#is", "\\1<embed src=\"\\2\" width=\\3 height=\\4>", $ret);
|
Useful Infomation http://www.php.net/preg_replace |
|