Adding BB codes to a Plugin

From e107 Wiki
Jump to: navigation, search

e107 Wiki: English | Русский | Deutsch | Français | Magyar | Português | Български | Česky | Nederlands | Ελληνικά | Italiano | Norske | Polska | Slovenščina | Español | Svenska | Translate: Wiki | Page

logo_wiki.png

Current Release 1.0.4 | e107.org | Download | Changelog | Forum | Plugins | Themes | RSS Feed of Latest Changes | Atom Feed of Latest Changes


How to write a plugin
Main page > I : First Aid > II : Development > III : Administration > IV : How To's > V : Plugin Writing > VI : Theming & Shortcodes


Adding bbcode to your e107 plugin is as simple as including a .bb file in your plugin folder. eg. mycode.bb (See e107_files/bbcodes for sample files). If you want to include a single tag bb code (ie [hr]) then you need to add a _ before the bbcode name (ie _hr.bb).

Any bbcodes added in a plugin are available system-wide.

There are two parameters passed to a bbcode:

Code: bbcode parameters
[bbcode=$parm]$code_text[/bbcode]
  • $parm is any text appearing after the '=' within the opening tag.
  • $code_text is the text appearing between the opening and closing bbcode tags.


The bbcode must return the HTML required to execute the task - this may take anything from a line or two up to tens or even hundreds of lines of code.

All the normal coding features, such as global variables, including files and the like, are available in the normal way.

To add a bbcode button to your textarea you need to create an e_bb.php file in your plugin folder. Here is an example of such a file:

Code: e_bb.php file example
<?php
$bb['name']		= 'mycode'; 
$bb['onclick']		= ''; 
$bb['onclick_var']	= "[mycode][/mycode]"; 
$bb['icon']		= e_PLUGIN."myplugin/images/mybutton.png"; 
$bb['helptext']		= "Insert mycode: [mycode]text here[/mycode]";
$bb['function']		= 'myFunction';   
$bb['function_var']     = $myfunction_vars;  

// append the bbcode to the default templates:
 
$BBCODE_TEMPLATE .= "{BB=mycode}"; 
$BBCODE_TEMPLATE_NEWSPOST .= "{BB=mycode}";
$BBCODE_TEMPLATE_ADMIN .= "{BB=mycode}";
$BBCODE_TEMPLATE_CPAGE .= "{BB=mycode}"; 

$eplug_bb[] = $bb;  // add to the global list - Very Important!    

?>

Explanation:

  • $bb['name']: unique name. (if a .bb file is used it should match.)
  • $bb['onclick']: defaults to the 'addhelp' function. leave blank for simple text insertion or use 'expandit' for popups.
  • $bb['onclick_var']: var sent to onclick function. eg. you could send the container ID of the div to expand if expandit is used for the $bb['onclick'] parameter.
  • $bb['icon']: path to the button.
  • $bb['helptext']: the help text to display on mouseover.
  • $bb['function']: optional function to be called at time of loading.
  • $bb['function_var']: optional vars to be sent to the function. eg. for the example above the following would be executed: myFunction($myfunction_vars);

Note: To be sure that your bbcode is registered in e107, check the Preference Viewer in admin -> database and look for your file in the pref bbcode_list. If it is not shown, run the Plugin Scan & View in admin -> database.

Technical References