Resource icon

Unmaintained BbCodes & Buttons Manager - Developer manual

Tools for developers to use in callbacks

> Get thread datas (when a Bb Code is used inside a XenForo thread)
  • $parentClass->getThreadParams(); //Get all thread parameters
  • $parentClass->getThreadParam('myParam');//Get one thread parameter
Returns null if the Bb Code has not been used inside a thread

Example:
PHP:
$nodeid = $parentClass->getThreadParam('node_id');
> Get post datas (when a Bb Code is used inside a XenForo thread)
  • $parentClass->getPostParams(); //Get all current post parameters
  • $parentClass->getPostParam('myParam'); //Get one parameter of the current post
Returns null if the Bb Code has not been used inside a thread

Example:
PHP:
$post_date = $this->getPostParam('post_date');
Disclaimer: this function is using a reverse processing method to get post datas from the thread datas (see the "parser permissions" section of this addon presentation)

> Add/Remove a wrapper to a Bb Code
  • $parentClass->addWrapper('wrappingTag', 'wrapping Tag Options');
  • $parentClass->removeWrapper();
Example:
If you want to make a text container and want to automatically wrap it inside the spoiler tag of your forum:
PHP:
$parentClass->addWrapper('spoiler', 'Inside this spoiler... a magical picture !');

> Render a template with the PHP callback Method
  • $parentClass->renderCustomTemplate('templateName', $params); //params being an array
Example:
PHP:
  $template = $parentClass->renderCustomTemplate('templateName', array(
  'content' => $yourBbContent,
  'misc' => $yourMiscVariables
  ));

  if($template !== false)
  {
  return $template;
  }

  /*****
  *  The parent class variable $this->_view was null (must be a template admin)
  *  Then the $template variable returned false
  *  Let's return some direct html code
  ****/
  return "<b>Your Fallback</b>";
Important: if you render a template from a php callback, you must first cache it (see below)

> Cache one or several templates with the PHP callback Method
In this situation you can't call a direct function from your Bb Code callback. You need to create one static function for your class. It doesn't matter if your class renders one or several Bb Codes. This static function must be named "preloadTemplates". The method called (the Bb Code function use to parse it) is passed as an argument.

PHP:
public static function preloadTemplates($callbackFunction)
{
  switch($callbackFunction)
  {
  case 'parseTagBbCode1':
  return 'TemplateName_1';
  break;
  }
}

public static function parseTagBbCode1(array $tag, $bboptions, $options, $parentClass)
{
  //your own code
}
Important: no need to cache a template with the Template Callback Method. It is automatically done, unless you redirect it to another template. But don't bother you to do this. Once in the main template, you can play with conditionals and with the xen tag include.

> Buffer extra information (add/get) during the page building
The parser is called by page and not by post. This means when a Bb Code is parsed it's possible to add & stock extra information in the parent class in order to retrieve it the next time the Bb Code will be parsed in the page. Here are two functions to use this buffer: the first one is to add extra information in that buffer (all added information are sorted by tags), the second one is to get information from that buffer.
  • $parentClass->addTagExtra($infoKey, $info)
    • $info can be an array or a string
    • a third parameter exists: true/false (default is false). Its purpose to activate an "array mode". Example: $parentClass->addTagExtra($infoKey, $info, true). Once activated if each added $info will not erase the previous one, but will create an array for the $infoKey
  • $parentClass->getTagExtra($infoKey)
    • a second parameter exists. If the value of the $infoKey is an array you can match one of its element directly: $parentClass->getTagExtra($infoKey, $arrayKey)
    • As mentioned previously all information are added or extracted by tag. If you want all extra information for all the tags, use this: $parentClass->getTagExtra() (without any parameter).
For an example, please have a look at the picasa Bb Code available in this addon.

Edit 2013/12/31: returns null when nothing is found

> Get attachments parameters
  • Basic command: $parentClass->getAttachmentParams('ID');
  • Optional parameters:
    • Valid Extensions: array
      $parentClass->getAttachmentParams('ID', $validExtensions);
    • Extra Permissions: arraymade with another array with three keys:
      • 'permissions' ; optional, if not specified will use the "permissions" key of the visitor object
      • 'group'
      • 'permission'
      $parentClass->getAttachmentParams('ID', $validExtensions, $extraPerms);

      These extra permissions are a fallback when the attachment parameters don't exist, which means the attachment is not in the post but can be available in the thread or another post
    • Return: arraywith these keys:
      • 'attachment': if valid Attachment, array with attachment data (the attachment must be inside the post to get this)
      • 'validAttachment': true or false (if not authorised extension: false)
      • 'canView': true or false
      • 'url': url to the attachement
      • 'fallbackPerms': true or false
Example:
PHP:
  $validExtensions = array('gif', 'png', 'jpg', 'jpeg');
  $permsFallback[] = array('group' => 'forum', 'permission' => 'viewAttachment');
  $attachmentParams = $parentClass->getAttachmentParams($attachmentID, $validExtensions, $permsFallback);
> Get request path
  • Basic command: $parentClass->getRequestPath($optionalArgument);
  • Optional argument:
    • 'request Uri' (returns the request Uri)
    • 'fullBasePath' (returns the fullBase path)
    • 'fullUri' (returns the full Uri)
    • 'all' (returns an array with the three information)
  • Use this function if you need html anchors

> Get text direction
  • Basic command: $parentClass->getTextDirection($optionalArgument);Without an argument, it returns "ltr" or "rtl".
  • Optional argument:
    • 'align' or 'float' (returns left or right)
    • 'padding' (returns padding-left or padding-right)
    • 'margin' (returns margin-left or margin-right)
  • Use this function to adapt your Bb Code code according to the user language direction

How to use the pre-parser function?
The pre-parser function is meant to be used by developers who would want to make a database request one time for all Bb Codes (with the same tag) available in the view.

It will renderer the tree two times, one time to cache data (the extraStates will have the key 'bbmPreCacheInit') and a second time to renderer your Bb Code and get the cached data (the extraStates will have the key 'bbmPreCacheComplete'). Between these two steps, you will have to use the listener "bbm_callback_precache" to make your db request.

Once this function enabled (Bbm BbCodes Manager Options), you still need to enable the feature by Bb Codes (version 2.8.x). For Bbm Bb Codes, go the their parsing options. For XenForo default Bb Codes, see in the Bbm BbCodes Manager Options.

PHP:
  if(!empty($rendererStates['bbmPreCacheInit']))
   {
     //Cache data in an array that you can use after with the pre-parser listener (and make there your db request)
     $parentClass->pushBbmPreCacheData('myBbCodePreParserCacheDataKey', $myData);
   }
   elseif(!empty($rendererStates['bbmPreCacheComplete']))
   {
     //Get data from the pre-parser array that you would have managed in the pre-parser listener and set inside a new key
     $myDataAfterDbRequest = $this->getBbmPreCacheData('myBbCodePreParserResultsDataKey');

     if(isset($myDataAfterDbRequest[$myData]))
     {
       $value = $myDataAfterDbRequest[$myData];
     }
     else
     {
       //Fallback
       $value = $this->_getMyModel()->getXXXByData($myData);
     }
   }
   else
   {
     //Fallback
     $value = $this->_getMyModel()->getXXXByData($myData);
   }
Pastebin

PHP:
  public static function bbmPreCache(array &$preCache, array &$rendererStates)
   {
     if(empty($preCache['myBbCodePreParserCacheDataKey']))
     {
       return false;
     }

     $myData = array_unique($preCache['myBbCodePreParserCacheDataKey']);
     $myDataResults = XenForo_Model::create('XenForo_Model_XXX')->XxxByData($myData);

     $preCache['myBbCodePreParserResultsDataKey'] = $myDataResults;
   }
Pastebin
Top