• Welcome to Simple Machines Community Forum. Please login or sign up.

Highlight Search Keywords

Started by Nathaniel, June 16, 2008, 03:32:22 PM

Previous topic - Next topic

Nathaniel

June 16, 2008, 03:32:22 PM Last Edit: June 16, 2011, 02:34:28 AM by Nathaniel
Link to Mod

Highlight Search Keywords 1.24 by Nathaniel

Formerly by Kalbenson.
Overview
This mod allows you to customize the colors that you use for your search highlighting within the smf system. Its a very simple mod but a useful one because it means that you can get rid of the monotone default yellow highlighting which comes with SMF.

You can find the settings for the Mod at this locations for both versions of SMF.
'Admin' Section -> 'Forum' Subsection -> 'Search' settings area -> 'Highlight Search Keywords' tab.

If you don't set any colors in the admin settings area then this mod will make no difference to your actual highlighting, because it will automatically highlight the keywords with the default SMF yellow (color code: 'FFFF00').

SMF Version Support
This mod is officially supported for SMF 2.0 final and above only. Below is a list of available versions of this mod and the previous versions of SMF that they supported. Use them at your own risk. The mod author will not be supporting or upgrading this mod in any way for versions of SMF below 2.0 final.

Version 1.23: SMF 1.1.x and versions of SMF 2 before SMF 2 RC3.
Version 1.24: SMF 2 RC3 and above.

Donate
If this mod has helped you, then feel free to support the developer by Donating. Any amount of money is welcome.

Version Changes
v1.24 - 27 May 2010
Changed package info to work with SMF 2 RC3.
Removed official support for SMF versions below SMF 2 RC2.
Updated the Search template edits for SMF 2 RC3.

v1.23 - 19 Novermber 2009
Updated for SMF 2 RC2 compatibility.

v1.22 - 18 August 2009
Updated mod for SMF 1.1.10 compatibility - Added a workaround for the SMF version bug.

v1.21 - 12 September 2008
Updated Mod for SMF 2 Beta 4.0 and SMF 1.1.6.

v1.2 - 14 June 2008
Upgraded Mod for SMF 2 Beta.
Fixed some minor bugs.
Added a settings area to chose colors.

v1.1 - 7th January 2008
Changed some comma concenators to dots
v1.0 - 4th January 2008
Initial Release
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

Nathaniel

Version 1.21 - 12 September 2008
Updated Mod for SMF 2 Beta 4.0 and SMF 1.1.6.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

ElectricSquid

September 14, 2009, 08:53:44 PM #2 Last Edit: September 15, 2009, 04:47:15 PM by ∑£ℓ¢†®¡¢ §ợų¡đ
I already have the mod installed, but I was trying to look into the code to see if I could modify how it highlights the search terms.
On my site, due to the colorings, using a highlighted box around the search word does not work well.
I would much rather highlight the text itself instead.

Nathaniel

Search for this code (Subs.php and Search.php):
<span style=\"background-color:".$color.";font-weight:bold;\">\$1</span>

Replace with this code:
<span style=\"color:".$color.";font-weight:bold;\">\$1</span>
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

ElectricSquid

September 15, 2009, 01:38:15 PM #4 Last Edit: September 15, 2009, 01:42:01 PM by ∑£ℓ¢†®¡¢ §ợų¡đ
That worked for when a user clicks the subject in the search results and goes to the topic. In the topic, the search words text are a different color.

But on the =search2 page (the search results), the highlight is still a box around the text.


EDIT OPPS :P
I must have not saves the edit in Search.php

THANK YOU!!
It works well and looks GREAT!!
Just what I was looking for.

ElectricSquid

September 15, 2009, 05:00:34 PM #5 Last Edit: September 15, 2009, 05:09:33 PM by ∑£ℓ¢†®¡¢ §ợų¡đ
One of the things I added to my search2 page, is a header that shows what words the user has searched for.
I reused a part of the code found in the "did you mean" search form (in search.template.php) in order to get the searched words to show up.

Anyway, I would like to get the Highlight Search Keywords coding to highlight this heading, that way the user has a reference for what word is what color.

I have tried and tried for hours to get this mod to pick up on this simple header, but it has beaten me. I don't know how to do it and I could use your help, please.

Below is the code I hacked from the form to create this custom header I'm talking about
(use at your own risk everyone, even though it works, it is a total hack)


        <td class="metal_plate_top_center">

<span style="font-size: 70%;"><i>', $txt['you_searched_for'] ,':</i></span> ', $context['search_params']['search'], '

        </td>



... and for a peek at this code in action, click here [LINK] and search for something.
This code shows up on the next page (search2) at the top center of the second metal plaque.

Nathaniel

You should simply be able to call the 'highlighter' function, like in the code below.

       <td class="metal_plate_top_center">

<span style="font-size: 70%;"><i>', $txt['you_searched_for'] ,':</i></span> ', highlighter($context['search_params']['search']), '

        </td>
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

ElectricSquid

I think I just learned something ;D

So what do I call that, when you put do the highlighter( ) thing?

Thanks a lot!!

ElectricSquid

That didn't work.
The text shows up, but there's no highlighting/color change.

R.Bourne

September 28, 2009, 04:23:53 PM #9 Last Edit: September 28, 2009, 08:43:41 PM by R.Bourne
I have 1.21 installed but I cannot either uninstall the previous version nor the new version can upgrade the old one!! Any suggestion?

Please disregard. I fixed it. Great update and thank you.

ElectricSquid

Quote from: ∑£ℓ¢†®¡¢ §ợų¡đ on September 15, 2009, 09:25:44 PM
That didn't work.
The text shows up, but there's no highlighting/color change.

Yea, disregard mine too.
I'm moving on to SMF 2.0, and with it, the theme I needed this added coding for will be redone.

Thanks for your help with making the text (font) color change instead of the highlight box around it.
It looks so much better that way, and I will be looking to use that tweak again when I get SMF 2.0 up and running.

:D I just checked to see if you coded for 2.0 too
Thanks, it looks like you are keeping up with the progression of SMF!!

Nathaniel

v1.23
Updated for SMF 2 RC2 compatibility.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

karanima

in forum Turkish "I" letter write a blank page when

Nathaniel

Quote from: karanima on January 01, 2010, 10:29:25 AM
in forum Turkish "I" letter write a blank page when

Could you please try to reword your post/explain your issue differently? I am not sure what you mean.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

karanima

search "ı"  letters white page
turkish forum

ı don't speak english sorry.thank google translate :)

rickmastfan67

Will this be updated to work with 1.1.11?  Thanks. :)

Eclipse16V

Nice Mod

Please update it for SMF 2.0RC3  ;)

Thanks
I worked with:
SMF 2 in German

Shop:
SID Giessen

Bruno36

Hello!

An update to SMF 2.0rc3 is provided?
Bruno36 the French
SMF 2.0.9

Nathaniel

v1.24 - 27 May 2010
Changed package info to work with SMF 2 RC3.
Removed official support for SMF versions below SMF 2 RC2.
Updated the Search template edits for SMF 2 RC3.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

lorth

works like a charm on 1.1.14  (v1.23 of the mod)

thanks for this really nice mod!  :)

dougiefresh

Thank you for the wonderful mod!  I thought I'd let everybody know that when I updated my forum from 2.0 RC5 to 2.0 Gold, I had to reinstall all my mods.  This mod installed without issues and without emulation.  Hope this info helps someone!

snooks

Nice thanks confirm 2 gold np on install  ;)

Nathaniel

Also confirmed that this mod works for SMF 2.0 gold. Thanks for the feedback. :)
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

btechnix

Hello,

At first, thank you for this great mod, which worked perfectly until now on SMF 2.11 before migrating on PHP 5.5

With PHP 5.5 we have many deprecated errors #8192 reported in log, more than 1000 per day, due code of this mod in "search.php" and "Subs.php":
Quote8192: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
Fichier: .../htdocs/forum/Sources/Search.php
Ligne: 2115
and
Quote8192: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
Fichier: .../htdocs/forum/Sources/Subs.php
Ligne: 4583

I tried to fix it, but, I can not, because I'm not a php developer:
For exemple in subs.php at 4583 there are:
   $message = preg_replace('/((<[^>]*)|' . preg_quote(strtr($word, array('\'' => ''')), '/') . ')/ie' . ($context['utf8'] ? 'u' : ''),
         "'\$2' == '\$1' ? stripslashes('\$1') : '<span style=\"background-color:".$color.";font-weight:bold;\">\$1</span>'",
         $message);

I tried unsuccessfully this change:
         $message =
            preg_replace_callback(
               '/((<[^>]*)|' . preg_quote(strtr($word, array('\'' => ''')), '/') . ')' . ($context['utf8'] ? 'u' : ''),         
               //"'\$2' == '\$1' ? stripslashes('\$1') : '<span style=\"background-color:".$color.";font-weight:bold;\">\$1</span>'",
               function ($m) {
               return "'$m[2]' == '$m[1]' ? stripslashes($m[1]') : '<span style=\"background-color:".$color.";font-weight:bold;\">$m[1]</span>'"
               },
               $message);

I think that i have bad syntax in the second parameter , so I have changed it like this:
               return ($m[2].' == '.$m[1].' ? stripslashes('.$m[1].') : <span style=\"background-color:".$color.";font-weight:bold;\">'.$m[1].'</span>')

but this is the same situation, in twice, my changes have blocked my forum.

At this time, i can only delete logs at each time, any help was welcome
Than you

vbgamer45

I did these changes to get it working on new versions of PHP

Subs.php
Find

$message = preg_replace('/((<[^>]*)|' . preg_quote(strtr($word, array('\'' => ''')), '/') . ')/ie' . ($context['utf8'] ? 'u' : ''), "'\$2' == '\$1' ? stripslashes('\$1') : '<span style=\"background-color:".$color.";font-weight:bold;\">\$1</span>'", $message);
           

Replace with

$context['highlight_color'] = $color;
            $message = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($word, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), 'highlightmod__preg_callback', $message);




End of Sources/Subs.php
Add

function highlightmod__preg_callback($matches)
{
    global $context;
return isset($matches[2]) && $matches[2] == $matches[1] ? stripslashes($matches[1]) : '<span style="background-color:' .  $context['highlight_color'] . ';font-weight:bold;">' . $matches[1] . '</span>';
}

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Advertisement: