flush or on a template. (if google referrer, search) */ class WikiPlugin_SearchHighlight extends WikiPlugin { function getName() { return _("SearchHighlight"); } function getDescription() { return _("Hilight referred search terms."); } function getVersion() { return preg_replace("/[Revision: $]/", '', "\$Revision: 1.1 $"); } function getDefaultArguments() { return array('s' => false, 'case_exact' => false, //not yet supported 'regex' => false, //not yet supported ); } function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (empty($args['s'])) return ''; extract($args); $query = new TextSearchQuery($s, $case_exact, $regex); //$pages = $dbi->fullSearch($query); $lines = array(); $hilight_re = $query->getHighlightRegexp(); $page = $request->getPage(); return $this->showhits($page, $hilight_re); } function showhits($page, $hilight_re) { $current = $page->getCurrentRevision(); $matches = preg_grep("/$hilight_re/i", $current->getContent()); $html = array(); foreach ($matches as $line) { $line = $this->highlight_line($line, $hilight_re); $html[] = HTML::dd(HTML::small(array('class' => 'search-context'), $line)); } return $html; } function highlight_line ($line, $hilight_re) { while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) { $line = substr($line, strlen($m[0])); $html[] = $m[1]; // prematch $html[] = HTML::strong(array('class' => 'search-term'), $m[2]); // match } $html[] = $line; // postmatch return $html; } }; // $Log: not supported by cvs2svn $ // // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>