You are here

function xbbcode_rebuild_handlers in Extensible BBCode 6

Same name and namespace in other branches
  1. 8 xbbcode.module \xbbcode_rebuild_handlers()
  2. 7 xbbcode.module \xbbcode_rebuild_handlers()
1 call to xbbcode_rebuild_handlers()
xbbcode_menu in ./xbbcode.module

File

./xbbcode.module, line 201

Code

function xbbcode_rebuild_handlers() {
  $res = db_query('SELECT DISTINCT name FROM {xbbcode_handlers}');
  while ($row = db_fetch_array($res)) {
    $exists[$row['name']] = $row['name'];
  }
  foreach (module_implements('xbbcode') as $module) {
    $tags = (array) module_invoke($module, 'xbbcode', 'list');
    $add = array();
    foreach ($tags as $tag) {
      if (!isset($exists[$tag])) {
        $add[$tag] = $tag;
        $exists[$tag] = $tag;
      }
    }
    $arg = array();
    $val = array();
    foreach ($add as $handler) {
      $arg[] = "('%s', '%s', %d)";
      array_push($val, $handler, $module, 1);
    }
    if (count($add)) {
      db_query('INSERT INTO {xbbcode_handlers} (name, module, enabled) VALUES ' . implode(', ', $arg), $val);
      drupal_set_message(t('%module added %num BBCode tags.', array(
        '%module' => $module,
        '%num' => count($add),
      )));
    }
  }
  cache_clear_all('xbbcode', 'cache', TRUE);
}