You are here

function _xbbcode_build_tags in Extensible BBCode 8

Same name and namespace in other branches
  1. 8.2 xbbcode.inc \_xbbcode_build_tags()
  2. 7 xbbcode.inc \_xbbcode_build_tags()

Invoke all handlers to get the tags for a certain format.

Parameters

$format_id: The name of the format for which tags should be built.

Return value

An array of tag objects, keyed by name.

1 call to _xbbcode_build_tags()
_xbbcode_build_filter in ./xbbcode.inc
Create or load a parser object.

File

./xbbcode.inc, line 63
General library of internal functions only called by this module.

Code

function _xbbcode_build_tags($format_id) {

  // First, check if the tags are in cache.
  if ($cache = cache()
    ->get("xbbcode_tags:{$format_id}")) {
    $tags = $cache->data;
  }
  else {

    // Load the database interface.
    module_load_include('inc', 'xbbcode', 'xbbcode.crud');

    // Load the preferred handlers for this text format.
    $handlers = xbbcode_handlers_load($format_id);
    $providers = array();
    foreach ($handlers as $handler) {

      // Build a list of what modules are used, and what to get from each.
      $providers[$handler->module][$handler->name] = $handler->name;
    }
    $default = array(
      'selfclosing' => FALSE,
      'nocode' => FALSE,
      'plain' => FALSE,
    );
    foreach ($providers as $module => $provides) {
      $info = module_invoke($module, 'xbbcode_info');
      foreach ($provides as $tag) {
        if (isset($info[$tag])) {
          if (!isset($info[$tag]['options'])) {
            $info[$tag]['options'] = array();
          }
          $tags[$tag] = (object) array(
            'name' => $tag,
            'description' => $info[$tag]['description'],
            'sample' => $info[$tag]['sample'],
            'options' => (object) ($info[$tag]['options'] + $default),
            'markup' => isset($info[$tag]['markup']) ? $info[$tag]['markup'] : NULL,
            'callback' => !isset($info[$tag]['markup']) ? $info[$tag]['callback'] : NULL,
          );
        }
      }
    }
    cache()
      ->set("xbbcode_tags:{$format_id}", $tags);
  }
  return $tags;
}