You are here

function highlight_filter in Highlight 6

Same name and namespace in other branches
  1. 5 highlight.module \highlight_filter()

Implementation of hook_filter

File

./highlight.module, line 158

Code

function highlight_filter($op, $delta = 0, $format = -1, $text = '') {
  $use_js = variable_get('hl_use_js', true);

  // list filters
  if ($op == 'list') {
    return array(
      0 => t('Highlight search results'),
    );
  }
  if ($op == "description") {
    return t("Highlight search terms in this content area");
  }

  // All operations besides "list" provide a $delta argument so we know which
  switch ($delta) {

    // First we define the simple string substitution filter.
    case 0:
      switch ($op) {

        // no caching
        case 'no cache':
          if ($use_js) {
            return FALSE;
          }
          else {
            return TRUE;
          }

        // describe the filter
        case 'description':
          return t('Highlights search terms in the text.');

        // We don't need the "prepare" operation for this filter, but it's required
        // to at least return the input text as-is.
        case 'prepare':
          return $text;

        // process the filter
        case 'process':
          $keywords = highlight_keywords();
          if (empty($keywords) == false) {
            return highlight_process($text, $keywords);
          }
          else {
            return $text;
          }
      }
      break;
  }
}