You are here

function highlight_process in Highlight 6

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

Takes input text and a key and replaces all instances of the key in the text with highlight code

1 call to highlight_process()
highlight_filter in ./highlight.module
Implementation of hook_filter

File

./highlight.module, line 251

Code

function highlight_process($text, $keys = '') {

  //  static $replace_text, $use_css;
  //  $replace_text = variable_get('hl_replace', '<strong id="keyword" class="highlight">$1</strong>');
  $use_js = variable_get('hl_use_js', true);
  $use_css = variable_get('hl_use_css', true);
  $use_anchor = variable_get('hl_use_anchor', true);

  // add css to header
  if ($use_css) {
    highlight_set_css();
  }
  if ($use_js) {
    drupal_add_js('misc/jquery.js');
    drupal_add_js(drupal_get_path('module', 'highlight') . '/js/jquery.highlight.js', 'module');
    foreach ($keys as $key) {

      //      drupal_add_js('alert("'.$key.'")', 'inline');
      drupal_add_js('$("*").highlight("' . $key . '")', 'inline', 'footer');
    }
  }
  else {
    foreach ($keys as $key) {
      $replacement[] = str_replace("\$1", " " . $key . " ", '<span class="highlight">$1</span>');
    }
    $text = str_ireplace($keys, $replacement, $text);

    //TODO: no case sensitive now.
  }

  /*TODO
    if ($use_anchor) {
      drupal_add_js('window.location="#keyword";', 'inline', 'footer');
    }
  */
  return $text;
}