Advertisement:

Author Topic: Highlight Search Keywords  (Read 14103 times)

Offline Nathaniel

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,117
  • Gender: Male
    • Verbtest.com
Highlight Search Keywords
« on: June 16, 2008, 03:32:22 PM »
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
« Last Edit: June 16, 2011, 02:34:28 AM by Nathaniel »
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.

Offline Nathaniel

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,117
  • Gender: Male
    • Verbtest.com
Re: Highlight Search Keywords
« Reply #1 on: September 12, 2008, 04:55:46 AM »
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.

Offline ElectricSquid

  • Full Member
  • ***
  • Posts: 498
  • Gender: Male
  • Forging a forum with blood, sweat, and steel
    • RedneckFabrication.com ...rebuilding the world with Scrap Steel, Duct Tape, & Bailing Wire
Re: Highlight Search Keywords
« Reply #2 on: September 14, 2009, 08:53:44 PM »
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.
« Last Edit: September 15, 2009, 04:47:15 PM by ∑£ℓ¢†®¡¢ §ợų¡đ »

Offline Nathaniel

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,117
  • Gender: Male
    • Verbtest.com
Re: Highlight Search Keywords
« Reply #3 on: September 15, 2009, 02:15:15 AM »
Search for this code (Subs.php and Search.php):
Code: [Select]
<span style=\"background-color:".$color.";font-weight:bold;\">\$1</span>
Replace with this code:
Code: [Select]
<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.

Offline ElectricSquid

  • Full Member
  • ***
  • Posts: 498
  • Gender: Male
  • Forging a forum with blood, sweat, and steel
    • RedneckFabrication.com ...rebuilding the world with Scrap Steel, Duct Tape, & Bailing Wire
Re: Highlight Search Keywords
« Reply #4 on: September 15, 2009, 01:38:15 PM »
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.
« Last Edit: September 15, 2009, 01:42:01 PM by ∑£ℓ¢†®¡¢ §ợų¡đ »

Offline ElectricSquid

  • Full Member
  • ***
  • Posts: 498
  • Gender: Male
  • Forging a forum with blood, sweat, and steel
    • RedneckFabrication.com ...rebuilding the world with Scrap Steel, Duct Tape, & Bailing Wire
Re: Highlight Search Keywords
« Reply #5 on: September 15, 2009, 05:00:34 PM »
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)
Code: [Select]

        <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.
« Last Edit: September 15, 2009, 05:09:33 PM by ∑£ℓ¢†®¡¢ §ợų¡đ »

Offline Nathaniel

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,117
  • Gender: Male
    • Verbtest.com
Re: Highlight Search Keywords
« Reply #6 on: September 15, 2009, 08:34:23 PM »
You should simply be able to call the 'highlighter' function, like in the code below.

Code: [Select]
       <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.

Offline ElectricSquid

  • Full Member
  • ***
  • Posts: 498
  • Gender: Male
  • Forging a forum with blood, sweat, and steel
    • RedneckFabrication.com ...rebuilding the world with Scrap Steel, Duct Tape, & Bailing Wire
Re: Highlight Search Keywords
« Reply #7 on: September 15, 2009, 09:15:45 PM »
I think I just learned something ;D

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

Thanks a lot!!

Offline ElectricSquid

  • Full Member
  • ***
  • Posts: 498
  • Gender: Male
  • Forging a forum with blood, sweat, and steel
    • RedneckFabrication.com ...rebuilding the world with Scrap Steel, Duct Tape, & Bailing Wire
Re: Highlight Search Keywords
« Reply #8 on: September 15, 2009, 09:25:44 PM »
That didn't work.
The text shows up, but there's no highlighting/color change.

R.Bourne

  • Guest
Re: Highlight Search Keywords
« Reply #9 on: September 28, 2009, 04:23:53 PM »
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.
« Last Edit: September 28, 2009, 08:43:41 PM by R.Bourne »

Offline ElectricSquid

  • Full Member
  • ***
  • Posts: 498
  • Gender: Male
  • Forging a forum with blood, sweat, and steel
    • RedneckFabrication.com ...rebuilding the world with Scrap Steel, Duct Tape, & Bailing Wire
Re: Highlight Search Keywords
« Reply #10 on: September 30, 2009, 02:43:51 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!!

Offline Nathaniel

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,117
  • Gender: Male
    • Verbtest.com
Re: Highlight Search Keywords
« Reply #11 on: November 18, 2009, 10:48:05 PM »
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.

Offline karanima

  • Semi-Newbie
  • *
  • Posts: 88
Re: Highlight Search Keywords
« Reply #12 on: January 01, 2010, 10:29:25 AM »
in forum Turkish "I" letter write a blank page when

Offline Nathaniel

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,117
  • Gender: Male
    • Verbtest.com
Re: Highlight Search Keywords
« Reply #13 on: January 01, 2010, 09:17:04 PM »
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.

Offline karanima

  • Semi-Newbie
  • *
  • Posts: 88
Re: Highlight Search Keywords
« Reply #14 on: January 06, 2010, 10:28:29 AM »
search "ı"  letters white page
 turkish forum

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

Offline rickmastfan67

  • Jr. Member
  • **
  • Posts: 105
  • Gender: Male
    • @rickmastfan67 on Twitter
Re: Highlight Search Keywords
« Reply #15 on: February 07, 2010, 06:18:31 PM »
Will this be updated to work with 1.1.11?  Thanks. :)

Offline Eclipse16V

  • Sophist Member
  • *****
  • Posts: 1,070
  • Gender: Male
  • Tornado Map
    • Eclipse16V on Facebook
    • @Eclipse16V on Twitter
    • Tornado Map
Re: Highlight Search Keywords
« Reply #16 on: March 15, 2010, 02:21:03 AM »
Nice Mod

Please update it for SMF 2.0RC3  ;)

Thanks
I worked with:
SMF 2 in German

My Shop:
Das Lieschen

Offline Bruno36

  • Full Member
  • ***
  • Posts: 570
  • Gender: Male
    • Scooter Chinois 4T
Re: Highlight Search Keywords
« Reply #17 on: March 26, 2010, 05:53:28 AM »
Hello!

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

Offline Nathaniel

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,117
  • Gender: Male
    • Verbtest.com
Re: Highlight Search Keywords
« Reply #18 on: May 27, 2010, 06:17:17 AM »
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.

Offline lorth

  • Jr. Member
  • **
  • Posts: 150
Re: Highlight Search Keywords
« Reply #19 on: June 15, 2011, 02:10:30 PM »
works like a charm on 1.1.14  (v1.23 of the mod)

thanks for this really nice mod!  :)

Offline dougiefresh

  • SMF Hero
  • ******
  • Posts: 2,749
  • Mod King
    • XPtsp.com Community
Re: Highlight Search Keywords
« Reply #20 on: June 15, 2011, 03:02:55 PM »
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!

Offline snooks

  • Jr. Member
  • **
  • Posts: 201
    • Bradfordsnooker
Re: Highlight Search Keywords
« Reply #21 on: June 15, 2011, 03:20:08 PM »
Nice thanks confirm 2 gold np on install  ;)

Offline Nathaniel

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,117
  • Gender: Male
    • Verbtest.com
Re: Highlight Search Keywords
« Reply #22 on: June 16, 2011, 02:35:32 AM »
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.

Offline btechnix

  • Newbie
  • *
  • Posts: 8
Re: Highlight Search Keywords
« Reply #23 on: June 18, 2016, 03:31:43 AM »
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":
Quote
8192: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
Fichier: .../htdocs/forum/Sources/Search.php
Ligne: 2115
and
Quote
8192: 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:
Code: [Select]
   $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:
Code: [Select]
         $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:
Code: [Select]
               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

Online vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 20,462
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Highlight Search Keywords
« Reply #24 on: August 05, 2018, 11:33:23 AM »
I did these changes to get it working on new versions of PHP

Subs.php
Find
Code: [Select]
$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
Code: [Select]
$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
Code: [Select]
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