You are here

function _xbbcode_get_tags in Extensible BBCode 6

Same name and namespace in other branches
  1. 5 xbbcode-misc.php \_xbbcode_get_tags()
2 calls to _xbbcode_get_tags()
xbbcode_get_filter in ./xbbcode.inc
xbbcode_settings_handlers_form in ./xbbcode.admin.inc

File

./xbbcode.inc, line 23

Code

function _xbbcode_get_tags($format = 0, $settings = FALSE) {
  static $defaults = array(
    'replacewith' => '',
    'description' => '',
    'sample' => '',
    'multiarg' => FALSE,
    'dynamic' => FALSE,
    'selfclosing' => FALSE,
  );
  static $cache;
  if (!$settings && !isset($cache[$format]) && ($data = cache_get('xbbcode_tags_' . $format))) {
    $cache[$format] = unserialize($data->data);
    return $cache[$format];
  }

  /* check for format-specific settings */
  $res = db_query("SELECT name, module, weight, enabled FROM {xbbcode_handlers} WHERE format IN (0, %d) ORDER BY format, weight, name ", $format);
  $handlers = array();
  while ($row = db_fetch_array($res)) {
    $handlers[$row['name']] = $row;
  }
  foreach ($handlers as $tag => $handler) {
    if (!$handler['enabled']) {
      unset($handlers[$tag]);
    }
  }
  $cache[$format] = array();
  foreach ($handlers as $name => $handler) {
    $tag = (array) $handler;
    $tag += (array) module_invoke($handler['module'], 'xbbcode', 'info', $name);
    $tag += (array) $defaults;
    $cache[$format][$name] = $tag;
  }
  if ($settings) {
    return $cache[$format];
  }
  cache_set('xbbcode_tags_' . $format, serialize($cache[$format]), 'cache', CACHE_PERMANENT);
  return $cache[$format];
}