Php Parsen über costumized bbcode aus dem Adminbackend heraus geht ja nicht. Also legt man sich am besten ein eigenes Plugin an. Der Hook ist "bbcode_fetch_tags" . Mit den Standard bbcode hat man ja normal die Möglichkeit, zwei Variablen weiter zu geben:
value
Wenn man aber mit dem php rumhantiert, hätte man da doch hie und da gerne mehr Variablen, die man weiterleitet. Da bietet sich dann der explode dazu an. Also z.B.
value
Der Code für das Plugin wäre dann beispielsweise:
$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 "Erste Option ist ".$split[0].".<br />Die zweite ist ".$split[1];
}
}
Damit kann man dann ziemlich viel anstellen ;)
Für XYZ dann noch den gewünschten TAG
URL
cu
Gargi
Here an englisch version of my php within bbcode tutorial:
Howto parse php within bbcode
First of all you should create a new Add-on in the admin backend. Name it something like "My Modifications". Later on you can stick all your new plugins to that new Add-on.
Then create a new Plugin in the admin backend. There select as Add-on your new created Add-on "My Modifications". Hook it to bbcode_fetch_tags and give it your name.
As code there are some different possibilities:
a) Use no options
b) Use options
c) With or without options
a) No options:
A simple bbcode with php is to parse a Value into a single line:
$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."!";
}
}
Gargi
will deliver
Hello world, my name is Gargi!
In short:
$tag_list['no_option']['TAG'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_TAG_callback',
'strip_empty' => true
);
if(!function_exists('handle_bbcode_TAG_callback'))
{
function handle_bbcode_TAG_callback(&$parsed, $value)
{
Your php code
}
}
TAG : The name of your bbcode you will use later on within your editor.
no_option : This means, that no options will be used.
b) Use options:
Simply replace no_option with option and add a third variable to the function called $option. An example with a "if - else" php code:
$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;
}
}
}
Gargi
Will deliver:
Hello this is Gargi,
my number is 3
c) With or without options
This is tricky! You have to define two different funtions for the same code tag. Example:
$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."!";
}
}
It's really simple: If you are using an option, the function handle_bbcode_trace_callback will be called. If there is no option, the function handle_bbcode_trace_callback2 will handle it.
Here is a further trick to use more then one option: You just have to use a special char like ";" to devide different options:
value
Then use the explode (http://de.php.net/explode) php function to get a variable for every option. For example:
$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];
}
}
Adding an icon to the wysiwyg editor and using an options popup window
Howto add an icon to the editor:
Template: editor_toolbar_on
Search
<if condition="$vBeditTemplate['extrabuttons'] != '' ">
<td><img src="$stylevar[imgdir_editor]/separator.gif" width="6" height="20" alt="" /></td>
$vBeditTemplate[extrabuttons]
</if>
and add the new icon this way:
<if condition="$vBeditTemplate['extrabuttons'] != '' ">
<td><img src="$stylevar[imgdir_editor]/separator.gif" width="6" height="20" alt="" /></td>
$vBeditTemplate[extrabuttons]
<td><img src="$stylevar[imgdir_editor]/separator.gif" width="6" height="20" alt="" /></td>
<td><div class="imagebutton" id="{$editorid}_cmd_wrap0_BBCODE"><img src="path_to_our_editoricons/myicon.gif" width="21" height="20" alt="My_BBCODE" /></div></td>
</if>
/clientscript/vbulletin_textedit.js
To add a option popup you have to edit the vbulletin_textedit.js. Don't forget to make a backup of your original file.
a) Simple popup without a preset placeholder
Search for
switch(tagname)
{
case"CODE" :
case"HTML" :
case"PHP" :
this.apply_format("removeformat");
break
}
and change it this way:
switch(tagname)
{
case"CODE" :
case"HTML" :
case"PHP" :
this.apply_format("removeformat");
break;
case"BBCODE" :
useoption = true;
break;
}
For BBCODE you have to use your special bbcode string of cause.
b) Popup with some text as placeholder
Search:
this.wrap_tags = function(tagname, useoption, selection)
Change it to:
this.wrap_tags = function(tagname, useoption, useoption_2, selection)
Search:
switch(tagname)
{
case"CODE" :
case"HTML" :
case"PHP" :
this.apply_format("removeformat");
break
}
to:
switch(tagname)
{
case"CODE" :
case"HTML" :
case"PHP" :
this.apply_format("removeformat");
break;
case"BBCODE" :
useoption_2 = true;
break;
}
After these lines
var opentag;
if(useoption === true)
{
var option = this.show_prompt(construct_phrase(vbphrase.enter_t ag_option, ("[" + tagname + "]")), "", false);
if(option = this.verify_prompt(option))
{
opentag = "[" + tagname + '="'+option+'"]'
}
else
{
return false
}
}
add:
else if(useoption_2 === true)
{
var option = this.show_prompt(construct_phrase("Please fill in the options", ("[" + tagname + "]")), "This could be your option", false);
if(option = this.verify_prompt(option))
{
opentag = "[" + tagname + '="'+option+'"]'
}
else
{
return false
}
}
Have fun with it!
cu
Gargi
Powered by vBulletin® Version 4.1.12 Copyright ©2012 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.