You are here

function xbbcode_filter_tips in Extensible BBCode 7

Same name and namespace in other branches
  1. 8 xbbcode.module \xbbcode_filter_tips()
  2. 5 xbbcode.module \xbbcode_filter_tips()
  3. 6 xbbcode.module \xbbcode_filter_tips()
1 string reference to 'xbbcode_filter_tips'
xbbcode_filter_info in ./xbbcode.module
Implements hook_filter_info().

File

./xbbcode.module, line 143
The main module file containing hook implementations.

Code

function xbbcode_filter_tips($filter, $format, $long) {
  module_load_include('inc', 'xbbcode');
  $filter = _xbbcode_build_filter($filter, $format);
  if (!$filter->tags) {
    return t('BBCode is enabled, but no tags are defined.');
  }
  if ($long) {
    $out = '<p>' . t('Allowed BBCode tags:') . '</p>';
    $header = array(
      t('Tag description'),
      t('You Type'),
      t('You Get'),
    );
    $rows = array();
    foreach ($filter->tags as $name => $tag) {
      $rows[] = array(
        array(
          'data' => "<strong>[{$name}]</strong><br />" . $tag->description,
          'class' => 'description',
        ),
        array(
          'data' => '<code>' . str_replace("\n", '<br />', check_plain($tag->sample)) . '</code>',
          'class' => 'type',
        ),
        array(
          'data' => $filter
            ->process($tag->sample),
          'class' => 'get',
        ),
      );
    }
    $out .= theme('table', array(
      'header' => $header,
      'rows' => $rows,
    ));
    return $out;
  }
  else {
    foreach ($filter->tags as $name => $tag) {
      $tags[$name] = '<abbr title="' . $tag->description . '">[' . $name . ']</abbr>';
    }
    return t('You may use these tags: !tags', array(
      '!tags' => implode(', ', $tags),
    ));
  }
}