You are here

function xbbcode_custom_tags in Extensible BBCode 5

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

File

./xbbcode-settings.php, line 4

Code

function xbbcode_custom_tags($name = '') {
  $form = array();
  if (!$name) {
    $res = db_query("SELECT name, dynamic, replacewith FROM {xbbcode_custom_tags}");
    while ($row = db_fetch_array($res)) {
      $tags[] = $row;
    }
    $form['existing'] = array(
      '#type' => 'fieldset',
      '#title' => t('Existing Tags'),
      '#description' => t('Check these tags and click "Delete" to delete them.'),
      '#collapsible' => TRUE,
      '#collapsed' => !count($tags) || $name,
    );
    if ($tags) {
      foreach ($tags as $tag) {
        $form['existing']['delete_' . $tag['name']] = array(
          '#type' => 'checkbox',
          '#title' => '[' . $tag['name'] . '] ' . l(t('edit'), 'admin/settings/xbbcode/tags/' . $tag['name']),
          '#description' => $tag['description'],
        );
      }
    }
    $form['edit'] = array(
      '#type' => 'fieldset',
      '#title' => t('Editing Tag !name', array(
        '!name' => $name,
      )),
      '#collapsible' => TRUE,
      '#collapsed' => count($tags) && !$name,
    );
    unset($tag);
  }
  else {
    $tag = db_fetch_object(db_query("SELECT * FROM {xbbcode_custom_tags} WHERE name='%s'", $name));
    $form['edit']['oldname'] = array(
      '#type' => 'hidden',
      '#value' => $name,
    );
  }
  if (!$tag) {
    $form['edit']['#title'] = t('Add new XBBCode tag');
  }
  $form['edit']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('[name]'),
    '#default_value' => $tag->name,
    '#required' => $name,
    '#maxlength' => 32,
    '#size' => 16,
    '#description' => t('The name of this tag. The name will be used in the text as [name]...[/name]. Must be alphanumeric and will automatically be converted to lowercase.'),
  );
  $form['edit']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#default_value' => $tag->description,
    '#required' => $name,
    '#description' => t('This will be shown on help pages'),
  );
  $form['edit']['sample'] = array(
    '#type' => 'textfield',
    '#title' => t('Sample Tag'),
    '#required' => $name,
    '#description' => t('Enter an example of how this tag would be used. It will be shown on the help pages.'),
    '#default_value' => $tag->sample,
  );
  $form['edit']['options'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Tag options'),
    '#options' => array(
      'selfclosing' => t('Self-closing'),
      'dynamic' => t('Use dynamic replacement'),
      'multiarg' => t('Uses multiple named arguments'),
    ),
    '#description' => t('A selfclosing tag like [img=http://...] requires no closing tag to follow it.
      For dynamic tags, the replacement text is evaluated as PHP code.'),
  );
  if ($tag->selfclosing) {
    $form['edit']['options']['#default_value'][] = 'selfclosing';
  }
  if ($tag->dynamic) {
    $form['edit']['options']['#default_value'][] = 'dynamic';
  }
  if ($tag->multiarg) {
    $form['edit']['options']['#default_value'][] = 'multiarg';
  }
  $form['edit']['replacewith'] = array(
    '#type' => 'textarea',
    '#title' => t('Replacement code'),
    '#default_value' => $tag->replacewith,
    '#required' => $name,
    '#description' => t('Enter the complete text that [tag]content[/tag] should be replaced with,
      or PHP code that returns the text. Use the ' . l("help page", "admin/help/xbbcode") . ' if necessary.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save changes'),
  );
  $form['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
  );
  return $form;
}