You are here

function xbbcode_settings_handlers in Extensible BBCode 5

Same name and namespace in other branches
  1. 8 xbbcode.admin.inc \xbbcode_settings_handlers()
  2. 6 xbbcode.admin.inc \xbbcode_settings_handlers()
  3. 7 xbbcode.admin.inc \xbbcode_settings_handlers()
1 string reference to 'xbbcode_settings_handlers'
xbbcode_menu in ./xbbcode.module

File

./xbbcode-settings.php, line 167

Code

function xbbcode_settings_handlers($format = -1, $format_name = 'Global') {
  $tags = _xbbcode_get_handlers();

  /* check for format-specific settings */
  if ($format != -1) {
    $use_format = db_result(db_query("SELECT COUNT(*) FROM {xbbcode_handlers} WHERE format=%d", $format));
  }
  $use_format = $use_format ? $format : -1;
  $res = db_query("SELECT name, module, enabled, weight FROM {xbbcode_handlers} WHERE format = %d ORDER BY weight, name", $use_format);
  while ($row = db_fetch_object($res)) {
    $defaults[$row->name] = $row;
  }
  $handlers = array();
  foreach ($tags as $tag) {
    $handlers[$tag['name']][$tag['module']] = $tag['module'];
  }
  ksort($handlers);

  // sort them alphabetically.
  $form = array(
    'global' => array(),
    'tags' => array(),
    '#tree' => TRUE,
  );
  $form['format'] = array(
    '#type' => 'value',
    '#value' => $format,
  );
  $form['format_name'] = array(
    '#type' => 'value',
    '#value' => $format_name,
  );
  if ($use_format != $format) {
    $form['global'] = array(
      '#type' => 'item',
      '#weight' => -10,
      '#value' => t("You are changing the settings for !format for the first time. Until you save them, " . "changes to the global settings will affect !format as well, but not afterward. " . "You can later reset these format-specific settings to the global configuration."),
    );
  }
  else {
    if ($format == -1 && _xbbcode_list_formats()) {
      $form['global'] = array(
        '#type' => 'item',
        '#weight' => -1,
        '#value' => t("You are changing the global settings. These values will be used for any future format " . "that uses the XBBCode filter, as well as all existing formats whose settings haven't been " . "modified."),
      );
    }
  }
  foreach ($handlers as $name => $handler) {
    $form['tags'][$name] = array(
      '#type' => 'fieldset',
      '#title' => "[{$name}]",
    );
    $form['tags'][$name]['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t("Enabled"),
      '#default_value' => $defaults[$name]->enabled,
    );
    if (count($handler) > 1) {
      $form['tags'][$name]['module'] = array(
        '#type' => 'select',
        '#title' => t("Handled by Module"),
        '#options' => $handler,
        '#default_value' => $defaults[$name]->module,
      );
    }
    else {

      /* unfortunately, we now need two form elements, one for sending and one for showing. */
      $form['tags'][$name]['handler'] = array(
        '#type' => 'item',
        '#title' => t("Handled by Module"),
        '#value' => current($handler),
      );
      $form['tags'][$name]['module'] = array(
        '#type' => 'value',
        '#title' => t("Handled by Module"),
        '#value' => current($handler),
      );
    }
    $form['tags'][$name]['weight'] = array(
      '#type' => 'weight',
      '#title' => t("Weight"),
      '#delta' => 5,
      '#default_value' => $defaults[$name]->weight,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#name' => 'op',
    '#value' => t('Save changes'),
  );
  if ($use_format != -1) {
    $form['restore'] = array(
      '#type' => 'submit',
      '#name' => 'op',
      '#value' => t('Restore global values'),
    );
  }
  return $form;
}