View Full Version : Calling PHP in BBCode
Milez
04-24-2009, 03:18 AM
I wrote a script that will output a stock quote and I want to make it work with vB's BBcode system. The problem is I cannot make MSFT replace to some PHP as it only allows HTML.
I can see other developers have gotten around this somehow as they are including javascript etc in their BBcode replacements. I plan to release this mod to the public. Can anyone offer some help?
Dismounted
04-24-2009, 10:46 AM
Look in class_bbcode.php, more specifically, at the end of this file. You will see a hook that allows you to "create" a BB code handler and define your own callback.
Milez
04-25-2009, 08:32 AM
Sorry I do not see this hook. What is its name?
Dismounted
04-25-2009, 10:24 AM
I did not mean literally "at the end"... bbcode_fetch_tags
Gargi
07-15-2009, 04:59 AM
Hmmm... I just wanted to insert a new bbcode calling some php functions but it won't parse.
I created a new plugin at bbcode_fetch_tags
$tag_list['option']['hwelt'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_hwelt_callback',
'strip_empty' => true
);
if(!function_exists('handle_bbcode_hwelt_callback' ))
{
function handle_bbcode_hwelt_callback(&$parser, $value, $option)
{
echo "Hallo Welt, ich hei?e".$value."!";
return $parsed;
}
}
A
Dieter
won't parse that way. So I also added a second plugin at bbcode_create:
if ($this->is_wysiwyg())
{
$this->unparsed_tags[] = 'hwelt';
}
But same result: nothing.
Any idea what's wrong with it?
cu
Gargi
Dismounted
07-15-2009, 06:40 AM
The BB code parser is expecting an "option" (e.g. [TAG=OPTION]), instead of $tag_list['option']['hwelt'], try $tag_list['no_option']['hwelt'].
Gargi
07-15-2009, 09:05 AM
The same thing. Activating or not activating (no matter what) the bbcode_create it also will result into an error while clicking onto the submut reply button. A created tag befor activating the pluging and refreshing the post will make the whole string disappear in the posting. Also if I will only parse
echo $value;
Still something wrong with it but I can't see what.
cu
Gargi
Edit:
Next try
$tag_list['no_option']['hwelt'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_hwelt_callback',
'strip_empty' => true
);
if(!function_exists('handle_bbcode_hwelt_callback' ))
{
function handle_bbcode_hwelt_callback($value)
{
/* return $parsed; */
return "Hallo Welt ".$value;
}
}
Works a bit better. This delivers using
Dieter
just
Hallo Welt
The Tag itself is parsing, but no php parsing I guess and the missing value.
cu
Gargi
--------------- Added 1247654019 at 1247654019 ---------------
One step further:
$tag_list['no_option']['hwelt'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_hwelt_callback',
'strip_empty' => true
);
if(!function_exists('handle_bbcode_hwelt_callback' ))
{
function handle_bbcode_hwelt_callback(&$parsed, $value)
{
return "Hello world, my name is ".$value."!";
return $parsed;
}
}
This will deliver a
Hello world, my name is Dieter!
So far so good. But how to integrate the php code? As I see the echo comand won't work but the return. So I think I have to place the php code elsewhere. But where?
cu
Gargi
Dismounted
07-15-2009, 09:46 AM
So far so good. But how to integrate the php code? As I see the echo comand won't work but the return. So I think I have to place the php code elsewhere. But where?
Wait a sec - I don't think I understand the problem you are having. Could you explain a little clearer? You seem you have it outputting correctly...
Gargi
07-15-2009, 10:00 AM
I want to parse some php code using a bbcode tag. Maybe another example with options:
Tag: count
Parameter a Name, Option a number.
e.g: Gargi
While parsing the number should be added to another value. Output maybe:
Hello this is Gargi,
my number is 10
So I try it with a plugin bbcode_fetch_tags:
$tag_list['option']['count'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_count_callback',
'strip_empty' => true
);
if(!function_exists('handle_bbcode_count_callback' ))
{
function handle_bbcode_count_callback(&$parsed, $value, $option)
{
$result = 7 + $option;
return "Hello this is ".$value.",<br />";
return "my number is ".$result;
return $parsed;
}
}
This will just result in
Hello this is Gargi,
and nothing more. I also only added this plugin and nothing more. Is there anything else to do for it (another plugin) or where do I have to place the php code to be executed correctly?
cu
Gargi
Link14716
07-15-2009, 10:10 AM
Once a function has returned something, the function stops executing and the script continues from there. Thus, the two returns below the first do nothing as they will never be executed.
Use this:
$tag_list['option']['count'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_count_callback',
'strip_empty' => true
);
if(!function_exists('handle_bbcode_count_callback' ))
{
function handle_bbcode_count_callback(&$parsed, $value, $option)
{
$result = 7 + $option;
return "Hello this is ".$value.",<br /> my number is ".$result;
}
}
Gargi
07-15-2009, 10:39 AM
php basics, I see :D
Thanks for that hint! Also works with the if / else and so on.
$tag_list['option']['count'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_count_callback',
'strip_empty' => true
);
if(!function_exists('handle_bbcode_count_callback' ))
{
function handle_bbcode_count_callback(&$parsed, $value, $option)
{
if ( $option > 5 )
{
$result = 7 + $option;
return "Hello this is ".$value.",<br />my number is ".$result;
}
else
{
$result = 1 + $option;
return "Hello this is ".$value.",<br />my number is ".$result;
}
}
}
Now I just have to find out how to use otpion and no_option in order to get two different outputs.
cu
Gargi
Dismounted
07-15-2009, 10:47 AM
Now I just have to find out how to use otpion and no_option in order to get two different outputs.
Just use two different functions.
Gargi
07-15-2009, 11:14 AM
Jeppa. That did the trick:
$tag_list['option']['trace'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_trace_callback',
'strip_empty' => true
);
$tag_list['no_option']['trace'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_trace_callback2',
'strip_empty' => true
);
if(!function_exists('handle_bbcode_trace_callback' ))
{
function handle_bbcode_trace_callback(&$parsed, $value, $option)
{
if ( $option > 5 )
{
$result = 7 + $option;
return "Hello this is ".$value.",<br />my number is ".$result;
}
else
{
$result = 1 + $option;
return "Hello this is ".$value.",<br />my number is ".$result;
}
}
}
if(!function_exists('handle_bbcode_trace_callback2 '))
{
function handle_bbcode_trace_callback2(&$parsed, $value, $option)
{
return "Hello this is ".$value."!";
}
}
From here all gates are open now ;) Thanks for your help!
cu
Gargi
Gargi
07-16-2009, 10:13 PM
Nice thing is, that this way I'm able to use multiple options devided maybe by a ";" .
value
$tag_list['option']['XYZ'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_XYZ_callback',
'strip_empty' => true
);
if(!function_exists('handle_bbcode_XYZ_callback'))
{
function handle_bbcode_XYZ_callback(&$parsed, $value, $option)
{
$split = explode(";", $option);
return $split[0]."<br />".$split[1];
}
}
Very handy if you need some more variables for a function.
cu
Gargi
1Unreal
07-17-2009, 02:01 AM
Someone should write a tutorial on this, it was really hard to work out how to do it the first time.
Gargi
07-19-2009, 06:12 PM
Someone should write a tutorial on this, it was really hard to work out how to do it the first time.
Since english is not my mothertongue it will be hard work to write an english tutorial. But I'll trie it and will post it here. But give me some extra time to do it :)
cu
Gargi
Jhonnyf
08-04-2009, 11:09 AM
Work fine, but, How about Switch Standard and Avanced editor? o Preview Message.. this is Parsed but not restore to BBCODE original form
ragtek
08-04-2009, 12:51 PM
I think you would also need a plugin at bbcode_create hook if ($this->is_wysiwyg())
{
$this->unparsed_tags[] = 'xyz';
}
xyz = your tag;)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.