PunBB Resource

Your ultimate PunBB resource!

Keywords:

    (Extended)

You are not logged in.

#1 2006-06-25 22:54:27

Chatissimus
New member
From: France
Registered: 2006-03-13
Posts: 4

HighlightSearchResult 1.0

Code:

##
##
##          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.
##

Download here

Offline

 

#2 2009-03-30 12:48:21

Koos
Administrator
Registered: 2007-01-14
Posts: 525
Website

Re: HighlightSearchResult 1.0

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:

Code:

#
#---------[ 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:

Code:

#
#---------[ 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 23:34:37)

Offline

 

Board footer

Based on PunBB
© Copyright 2002–2005 Rickard Andersson

© Copyright 2004–2006 Kristoffer Jansson

User contributed files are property of their respective owners.