=====HighlightSearch Handler===== >>==See also :== Documentation : ""HighlightSearchHandlerInfo"" Other: SearchHighlighter, HighlightSearch, HighlightSearchWikka12 ==Works with :== Wikka 1.2>>//NOT included in any Wikka version// This is the development page for the [[HighlightSearchWikka12 | HighlightSearch]] handler version Wikka 1.2. For Wikka version 1.3.1 go [[HighlightSearchWikka131 | here]]. For Wikka version 1.3.2 go [[HighlightSearchWikka132 | here]]. Previous version for Wikka version < 1.2 is also [[HighlightSearch | available]]. ::c:: RolandStens did [[SearchHighlighter]] based on Javascript. Here is my contribution in PHP. The work is based on show.php handler and a small part of textsearchexpanded.php action. You can see this new handler in action [[http://emeraldisland.free.fr/wikka/wikka.php?wakka=HighlightSearch/highlightsearch&search=highlight | here]]. ==Installation== - Save the code block below as ##/plugins/handlers/page/highlightsearch.php## - Give it the same file permissions as the other php files in that directory ==Code== 1. New /plugins/handlers/page/highlightsearch.php file %%(php) to template; * necessary) - #312 */ //constants define('SHOW_OLD_REVISION_SOURCE', 0); # if set to 1 shows by default the source of an old revision instead of the rendered version //validate URL parameters $raw = (!empty($_GET['raw']))? (int) $this->GetSafeVar('raw', 'get') : SHOW_OLD_REVISION_SOURCE; ?> GetUser()) && ($user['doubleclickedit'] == 'N') || !$this->HasAccess('write')) ? '' : ' ondblclick="document.location=\''.$this->Href('edit', '', 'id='.$this->page['id']).'\';" '; #268 echo '>'."\n"; //TODO: move to templating class if (!$this->HasAccess('read')) { echo '

You aren\'t allowed to read this page.

'; echo "\n".''."\n"; //TODO: move to templating class } else { if (!$this->page) { echo '

This page doesn\'t exist yet. Maybe you want to create it?

'; echo ''."\n"; //TODO: move to templating class } else { if ($this->page['latest'] == 'N') { echo '
'."\n"; echo '

Revision ['.$this->page['id'].']

'."\n"; echo 'This is an old revision of '.$this->GetPageTag().' made by '.$this->page['user'].' on '.$this->page['time'].'.'."\n"; ?>
FormOpen('show', '', 'GET', '', 'left') ?>
 
FormClose(); ?> HasAccess('write')) { // added if encapsulation : in case where some pages were brutally deleted from database if ($latest = $this->LoadPage($this->tag)) { ?> FormOpen('edit') ?>
FormClose(); ?>
'."\n"; } // display page //EMERALDISLAND if (isset($_REQUEST['search']) && ($search = $_REQUEST['search'])) { $search_re = stripslashes(trim($search)); if ($search_re) { // display page with highlighted string $txt_stripped = $this->Format($this->page['body'], 'wakka'); // The evil REGEXP $pattern = '/('.$this->htmlspecialchars_ent($search_re).')(?![^<]*?>)/i'; $highlightMatch = preg_replace($pattern,'<<$1>>',$txt_stripped,-1); $matchText = str_replace(array('<<', '>>'), array('', ''), $highlightMatch); echo $matchText; } } else if ($raw == 1) { echo '
'.nl2br($this->htmlspecialchars_ent($this->page["body"], ENT_QUOTES)).'
'; } else { echo $this->Format($this->page['body'], 'wakka', 'page'); } // EMERALDISLAND ?>
GetConfigValue('hide_comments') != 1) { // load comments for this page $comments = $this->LoadComments($this->tag); // store comments display in session $tag = $this->GetPageTag(); if (!isset($_SESSION['show_comments'][$tag])) $_SESSION['show_comments'][$tag] = ($this->UserWantsComments() ? '1' : '0'); if (isset($_GET['show_comments'])) #312 { switch($_GET['show_comments']) #312 { case "0": $_SESSION['show_comments'][$tag] = 0; break; case "1": $_SESSION['show_comments'][$tag] = 1; break; } } ?>
Comments [Hide comments/form]
GetUserName(); echo '
'."\n"; foreach ($comments as $comment) { echo '
'."\n". ''.$comment['comment']."\n". "\t".'
'."\n-- "; echo ($this->LoadUser($comment['user']))? $this->Format($comment['user']) : $comment['user']; // #84 echo ' ('.$comment['time'].')'."\n"; $current_user = $this->GetUserName(); if ($this->UserIsOwner() || $current_user == $comment['user'] || ($this->config['anony_delete_own_comments'] && $current_user == $comment['user']) ) { echo $this->FormOpen("delcomment"); ?>
FormClose(); } echo "\n\t".'
'."\n"; echo '
'."\n"; } echo '
'."\n"; } // display comment form echo '
'."\n"; if ($this->HasAccess('comment')) {?> FormOpen('addcomment'); ?>
FormClose(); ?> '."\n"; } else { ?>

[]

%% 2. In textsearch.php action, change only one line : Old textsearch.php source code (line 85) : %%(php)$result_page_list .= ($i+1).". ".$this->Link($page["tag"],"
\n";%% New textsearch.php source code (line 85) : %%(php)$result_page_list .= ($i+1).". ".$this->Link($page["tag"],'highlightsearch&search='.$phrase)."
\n";%% 3. That's all ! ==Remark :== For a better integration in your wiki, you can also replace 'show' handler. - rename or save handlers/page/show.php in handlers/page/show_ref.php - copy and rename plugins/handlers/page/highlightsearch.php in handlers/page/show.php - change 'highlightsearch' by 'show' in actions/textsearch.php (step 2. above) ---- CategoryUserContributions - CategoryDevelopmentHandlers