You are here

function bbcode_filter in Bbcode 5

File

./bbcode.module, line 17

Code

function bbcode_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(
        0 => t('BBCode'),
      );
    case 'description':
      return t('Converts BBCode to HTML.');
    case 'process':
      include_once 'bbcode-filter.inc';
      if (variable_get("bbcode_debug_{$format}", 0)) {
        $timing_start = explode(' ', microtime());
        $ret = _bbcode_filter_process($text, $format);
        $timing_stop = explode(' ', microtime());
        $elapsed = $timing_stop[1] - $timing_start[1];
        $elapsed += $timing_stop[0] - $timing_start[0];
        $ret .= '<hr />' . l('BBCode', "filter/tips/{$format}") . ' parsed on ' . date('r') . '<br />Execution time: ' . $elapsed . ' seconds.<hr />';
        return $ret;
      }
      else {
        return _bbcode_filter_process($text, $format);
      }
    case 'settings':
      $form = array();
      $form['bbcode_filter'] = array(
        '#type' => 'fieldset',
        '#title' => t('BBCode filter'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
      );
      $form['bbcode_filter']["bbcode_make_links_{$format}"] = array(
        '#type' => 'select',
        '#title' => t('Convert addresses to links'),
        '#default_value' => variable_get("bbcode_make_links_{$format}", 1),
        '#options' => array(
          t('Disabled'),
          t('Enabled'),
        ),
        '#description' => t('Turn web and e-mail addresses into clickable links. This is useful if content authors do not explicitly mark addresses as links with [url] and [email] tags.'),
      );
      $form['bbcode_filter']["bbcode_encode_mailto_{$format}"] = array(
        '#type' => 'select',
        '#title' => t('Email address encoding'),
        '#default_value' => variable_get("bbcode_encode_mailto_{$format}", 1),
        '#options' => array(
          t('Disabled'),
          t('Enabled'),
        ),
        '#description' => t('Whether to encode email addresses with javascript. With this method you will have clickable mailto links, but it will be a bit harder for spam robots to collect them.'),
      );
      $form['bbcode_filter']["bbcode_paragraph_breaks_{$format}"] = array(
        '#type' => 'select',
        '#title' => t('Smart paragraph and line breaks'),
        '#default_value' => variable_get("bbcode_paragraph_breaks_{$format}", 2),
        '#options' => array(
          t('Disabled'),
          t('Line breaks only'),
          t('Line and paragraph breaks'),
        ),
        '#description' => t('Add line and paragraph breaks to text, excluding text in preformatted code blocks. If you disable this option, you need to enable Drupal\'s "Line break converter". Don\'t use both together!'),
      );
      $form['bbcode_filter']["bbcode_debug_{$format}"] = array(
        '#type' => 'select',
        '#title' => t('Print debugging info'),
        '#default_value' => variable_get("bbcode_debug_{$format}", 0),
        '#options' => array(
          t('Disabled'),
          t('Enabled'),
        ),
        '#description' => t('Print BBCode parse date and execution time. This option should be disabled on production sites. You may need to clear the cache after changing this option.'),
      );
      return $form;
    default:
      return $text;
  }
}