Your ultimate PunBB resource!
You are not logged in.
## ## ## Mod title : HighlightSearchResult ## ## Mod version : 1.0 ## Works on PunBB : 1.2.x ## Release date : 21/06/2006 ## ## ## Author : Chatissimus ## ## Description : Highlight Search words in results topics ## This mod add a highlignt BBcode balise [h][/h] ## Thus it need allow BBcode yes in admin option. ## ## ## Affected files : search.php ## viewtopic.php ## include/function.php ## include/parser.php ## ## Affects DB : no ## ## ## DISCLAIMER : Please note that "mods" are not officially supported by ## PunBB. Installation of this modification is done at your ## own risk. Backup your forum database and any and all ## applicable files before proceeding. ##
Offline
The author really did a great job with this mod. There are just a few bugs:
1. When using the wildcard character * for partial matches when performing a search, the mod tries to highlight *searchterm* instead of just searchterm (the * characters must be excluded).
2. This mod corrupts links when the search term is found in a links or [img] and [url]tags.
Here are the fixes for the above mentioned bugs:
#
#---------[ 1. OPEN ]---------------------------------------------------------
#
search.php
#
#---------[ 2. FIND (line: 64) ]---------------------------------------------
#
$sword = (isset($_GET['words'])) ? strtolower(trim($_GET['words'])) : null;
#
#---------[ 3. REPLACE WITH ]-------------------------------------------------
#
$sword = (isset($_GET['words'])) ? str_replace('*','',strtolower(trim($_GET['words']))) : null;
#
#---------[ 4. OPEN ]---------------------------------------------------------
#
include/parser.php
#
#---------[ 5. DELETE ]-------------------------------------------------------
#
if($sword != null)
{
$word_array = explode('-',$sword);
while (list($i, $word) = @each($word_array))
{
if($word != 'and' && $word != 'or' && $word != 'not')
$text = str_ireplace($word,'[h]'.$word.'[/h]',$text);
}
}
#
#---------[ 6. FIND (line: 437) ]---------------------------------------------
#
// Add paragraph tag around post, but make sure there are no empty paragraphs
$text = str_replace('<p></p>', '', '<p>'.$text.'</p>');
#
#---------[ 7. AFTER, ADD ]---------------------------------------------------
#
if($sword != null)
{
$word_array = explode('-',$sword);
while (list($i, $word) = @each($word_array))
{
if($word != 'and' && $word != 'or' && $word != 'not')
$text = preg_replace('/((<[^>]*)|' . preg_quote(strtr($word, array('\'' => ''')), '/') . ')/ie', "'\$2' == '\$1' ? stripslashes('\$1') : '<span style=\"background-color: #FFFF00; color: #000000\">\$1</span>'", $text);
}
}
#
#---------[ 8. SAVE/UPLOAD ]-------------------------------------------------
#Add-ons
1. If you would like the wildcard character * (for partial matches) to be added automatically for better search results, make the following change:
#
#---------[ 1. OPEN ]---------------------------------------------------------
#
search.php
#
#---------[ 2. FIND (line: 69) ]---------------------------------------------
#
$keywords = (isset($_GET['keywords'])) ? strtolower(trim($_GET['keywords'])) : null;
#
#---------[ 3. REPLACE WITH ]-------------------------------------------------
#
$keywords = (isset($_GET['keywords'])) ? '*'.str_replace(' ','* *',strtolower(trim($_GET['keywords']))).'*' : null;Without this modification (or if the user did not use the wildcard * character), the following results would not be found if you searched for 'chicken' for example:
chickens
chickenfeed
2. To display the entire (not truncated) versions of posts when performing a search (when selecting 'Show results as: Posts'), install the following mod I created recently:
Show user posts and topics
Last edited by Koos (2009-09-20 15:34:37)
Offline