You are here

function _xbbcode_get_tags in Extensible BBCode 5

Same name and namespace in other branches
  1. 6 xbbcode.inc \_xbbcode_get_tags()
1 call to _xbbcode_get_tags()
xbbcode_get_filter in ./xbbcode-misc.php

File

./xbbcode-misc.php, line 24

Code

function _xbbcode_get_tags($format = -1) {
  static $cache;
  if (!$cache[$format] && ($data = cache_get('xbbcode_tags_' . $format))) {
    $cache[$format] = unserialize($data->data);
    return $cache[$format];
  }

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