You are here

function xbbcode_custom_tags in Extensible BBCode 6

Same name and namespace in other branches
  1. 8 xbbcode.admin.inc \xbbcode_custom_tags()
  2. 5 xbbcode-settings.php \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.admin.inc, line 4

Code

function xbbcode_custom_tags($form_state, $name = NULL) {
  $editing_tag = !empty($name);
  $adding_tag = !empty($form_state['post']['op']) && $form_state['post']['op'] == t('Save');
  $tag = array(
    'name' => '',
    'description' => '',
    'replacewith' => '',
    'sample' => '',
  );
  if ($name) {
    $tag = xbbcode_get_custom_tag($name);
    $form['edit'] = array(
      '#type' => 'fieldset',
      '#title' => t('Editing Tag %name', array(
        '%name' => $name,
      )),
      '#collapsible' => FALSE,
    );
  }
  else {
    $tags = xbbcode_get_custom_tag();
    if (count($tags)) {
      foreach ($tags as $tag) {
        $options[$tag] = '[' . $tag . '] ' . l(t('edit'), 'admin/settings/xbbcode/tags/' . $tag . '/edit');
      }
      $tag = array(
        'name' => '',
        'description' => '',
        'replacewith' => '',
        'sample' => '',
      );
      $form['existing'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Existing Tags'),
        '#description' => t('Check these tags and click "Delete" to delete them.'),
        '#options' => $options,
      );
    }
    $form['edit'] = array(
      '#type' => 'fieldset',
      '#title' => t('Add new XBBCode tag'),
      '#collapsible' => TRUE,
      '#collapsed' => count($tags),
    );
  }
  $form['edit']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $name,
    '#field_prefix' => '[',
    '#field_suffix' => ']',
    '#required' => $editing_tag || $adding_tag,
    '#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' => $editing_tag || $adding_tag,
    '#description' => t('This will be shown on help pages'),
  );
  $form['edit']['sample'] = array(
    '#type' => 'textfield',
    '#title' => t('Sample Tag'),
    '#required' => $editing_tag || $adding_tag,
    '#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('PHP code'),
      'multiarg' => t('Multiple tag attributes'),
    ),
    '#description' => t('A selfclosing tag like [img=http://...] requires no closing tag to follow it.'),
  );
  if (!empty($tag['selfclosing'])) {
    $form['edit']['options']['#default_value'][] = 'selfclosing';
  }
  if (!empty($tag['dynamic'])) {
    $form['edit']['options']['#default_value'][] = 'dynamic';
  }
  if (!empty($tag['multiarg'])) {
    $form['edit']['options']['#default_value'][] = 'multiarg';
  }
  $form['edit']['replacewith'] = array(
    '#type' => 'textarea',
    '#title' => t('Replacement code'),
    '#default_value' => $tag['replacewith'],
    '#required' => $editing_tag || $adding_tag,
    '#description' => t('Enter the complete text that [tag]content[/tag] should be replaced with, ' . 'or PHP code that prints/returns the text.', array(
      '@url' => url('admin/help/xbbcode'),
    )),
  );
  $form['edit']['help'] = array(
    '#type' => 'markup',
    '#title' => t('Coding help'),
    '#value' => t('<p>The above field should be filled either with HTML or PHP code depending on whether your check the PHP code option.</p>
      <p>Regardless of whether you are using static HTML or dynamic PHP, the attributes and content of the tag in the processed tag will be inserted into
      your code by replacing placeholders. If you would like to assign them to a variable in PHP, you need to assign it as <code>$variable&nbsp;=&nbsp;"{placeholder}";</code></p>
      <dl>
        <dt><code>{content}</code></dt>
	<dd> will be replaced with the text between opening and closing tags, if the tag is not self-closing. E.g.: <code>[url=http://www.drupal.org]<strong>Drupal</strong>[/url]</code></dd>
        <dt><code>{option}</code></dt>
	<dd> will be replaced with the single tag attribute, if the tag does not use multiple attributes. E.g.: <code>[url=<strong>http://www.drupal.org</strong>]Drupal[/url]</code>.</dd>
	<dt>any other <code>{placeholder}</code></dt>
	<dd> will be replaced with the tag attribute of the same name, if the tag uses multiple attributes. E.g: <strong>{by}</strong> is replaced with <code>[quote&nbsp;by=<strong>Author</strong>&nbsp;date=2008]Text[/quote]</code>.</dd>
      </dl>
      <p>Note that named attributes that are not used will currently <em>not replace their placeholders</em>.</p>'),
  );
  $form['edit']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#submit' => array(
      'xbbcode_custom_tags_save_submit',
    ),
  );
  if (!empty($name) || count($tags)) {
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#submit' => array(
        'xbbcode_custom_tags_delete_submit',
      ),
    );
  }
  return $form;
}