You are here

function highlight_process in Highlight 5

Same name and namespace in other branches
  1. 6 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 240

Code

function highlight_process($text, $keys) {
  global $base_url;
  static $replace_text, $use_css;
  $replace_text = variable_get('hl_replace', '<strong class="highlight">%key%</strong>');
  $use_css = variable_get('sh_use_css', true);

  // add css to header
  if ($use_css) {
    highlight_set_css();
  }
  $string = basename($_SERVER['HTTP_REFERER']);

  // check if there is a type set
  if (strstr($string, "+type")) {
    $string = substr($string, 0, strpos($string, "+type"));
  }

  // replace "+" with spaces to catch all instances
  $string = str_replace("+", ",", $string);
  if ($_GET['highlight']) {
    $string .= "," . $_GET['highlight'];
  }

  // strip out any dangerous stuff
  $pattern = "/[^, a-zA-Z 0-9_\\.]/";
  $keys = preg_replace($pattern, "", $string);
  $keys = explode(",", $keys);
  foreach ($keys as $key) {
    $replacement[] = str_replace("%key%", $key, $replace_text);
  }
  $text = str_replace($keys, $replacement, $text);
  return $text;
}