Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: karlbenson on January 06, 2008, 09:24:16 PM

Title: Highlight Search Keywords v1.1
Post by: karlbenson on January 06, 2008, 09:24:16 PM

HIGHLIGHT SEARCH KEYWORDS v1.1
By Karl Benson (http://custom.simplemachines.org/mods/index.php?action=search;author=63186)

Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=1051) | Support Topic (http://www.simplemachines.org/community/index.php?topic=215214.0) | Demo (http://www.adrevenueshare.com/index.php?topic=1.0;highlight=welcome+enjoy+simple+machines+please) | Donate (http://www.adrevenueshare.com/donate)

Compatibility
For SMF 1.1.x ONLY.

Introduction
Highlights the search terms/keywords INSIDE the topic in Google-esc variety of colors.
Keywords called from the highlight={keywords} parameter added to links.
Changes the default 'yellow' highlighter in SMF Search to use this mods multicolored one.

Features
o Multi-colored highlighter
o Full & Partial word matches
o Keywords properly sanitized
o Prevents replacing any html

Installation
Installs for SMF Default Core Theme and almost all other themes (except those with a custom Search.template.php [unlikely!])

There are NOT any language strings with this mod.

For themes other than the SMF Default Core Theme with a custom Search.template.php manual edits will be required.

Useful Links
SMF Package Parser (http://modparser.dev.dansoftaustralia.net/)
Manual Installation Of Mods (http://docs.simplemachines.org/index.php?topic=402)
How Do I Modify Files? (http://www.simplemachines.org/community/index.php?topic=24110.0)

Donate
Has this modification helped you? Support the developer by Donating (http://www.adrevenueshare.com/donate)

Support
Please use the modification thread for support with this modification.
(Please don't ask me to do the edits for you)

Changelog
1.0 - 4th January 2008
o Initial Release
1.1 - 7th January 2008
o Changed some comma concenators to dots
Title: Re: Highlight Search Keywords v1.0
Post by: Simplemachines Cowboy on January 06, 2008, 10:03:56 PM
Another excellent & useful mod!
No errors, installed fine.
Title: Re: Highlight Search Keywords v1.0
Post by: ALEJO on January 07, 2008, 04:51:30 PM
can u explain a litlle bit more what is "google-esc" and why this is better for the forum? ... thx... sorry for noobish questions ^^
Title: Re: Highlight Search Keywords v1.0
Post by: dannbass on January 07, 2008, 05:08:16 PM
@Alejo.... everything is in the introduction and features... plus you are getting nice screen shots... if you use google and use the "cached" option then you'll see why is it "google-like" because the results are highlighted.

@Karl, great mod, as always!!! I have a question...

I installed the mod manually, no trouble at all, but I had to change the "," for "." like the ?topic=', $topic['id'] for example... and got curious... could you explain me why...

Quote<div class="quoteheader" style="margin-left: 20px;"><a href="'. $scripturl. '?topic='. $topic['id']. '.msg'. $message['id']. ';highlight='.$context['highlight'].'#msg'. $message['id']. '">'. $message['subject_highlighted']. '</a> '. $txt[525]. ' '. $message['member']['link']. '</div>';

Thanks again!
Title: Re: Highlight Search Keywords v1.0
Post by: karlbenson on January 07, 2008, 06:34:01 PM
Strange.

Dots, join the string together before echoing, while Commas just send it to be echoed. (commas are therefore recommended to be used [where possible] because its faster)
Unless you got an error or issue, there shouldn't be a need to change the commas to dots.

The commas were actually are part of SMF's default code.
Title: Re: Highlight Search Keywords v1.0
Post by: dannbass on January 07, 2008, 06:38:42 PM
I got an error and my search.template when I tried the mod and it is full of dots, that's why I changed them.
Good to know then... thanks a lot!
Title: Re: Highlight Search Keywords v1.0
Post by: edi67 on January 08, 2008, 06:51:13 AM
let me try it thx
Title: Re: Highlight Search Keywords v1.0
Post by: Bulakbol on January 08, 2008, 01:32:32 PM
Another good mod from Karlbenson.
Title: Re: Highlight Search Keywords v1.0
Post by: btechnix on January 08, 2008, 03:07:58 PM
Hi
I have test this mod, wich is very interesting

but, like this:
Quote from: dannbass on January 07, 2008, 05:08:16 PM...I installed the mod manually, no trouble at all, but I had to change the "," for "." like the ?topic=', $topic['id'] for example... and got curious... could you explain me why...
I have the same, and search why:
in my case the problem is that I have installed before the mod : "DonationCoder.com SMF Search Enhancement Mod" , I have tested with an uninstall of it before, and mod Highlight run correctly.

After install mod "..SMF Search Enhancement Mod...", there are points, not comma in  my search.template

I think the reason is that mod "...Search Enhancement..." is'nt conform with standard

edit: I have just verifyed all, in fact, "...Search Enhancement..." use concatenation in a string variable ($str), and it is not echo function, in this case i suppose it's necessary to use point in place of comma
I have also maodify search.template manually, and yaour mod "Highlight Search Keywords" seems work properly.

"Sorry for my poor english, it is not my native language"

@+
Bruno
Title: Re: Highlight Search Keywords v1.0
Post by: karlbenson on January 08, 2008, 05:27:47 PM
Last night as a precautionary measure I replaced the commas in the string with dots.
1.1 - 7th January 2008
o Changed some comma concenators to dots
Title: Re: Highlight Search Keywords v1.1
Post by: aldo on January 09, 2008, 01:28:25 AM
Yeah, Great mod! I tried making this mod, but failed =P lol. Looks great ;)
Title: Re: Highlight Search Keywords v1.1
Post by: SleePy on January 09, 2008, 01:34:01 AM
echo is a language construct and thus is why it doesn't need () around it. It also accepts unlimited amount of variables passed into it. Such as a function(arg1, arg2, arg3...). It will accept all of these. When using dots it has to join together all parts of an input before it can be sent to echo, commas I don't believe it waits and just sends it out. But from how fast php phrases the code anyways, you wouldn't notice a different. Besides being slightly faster we do this because it looks a bit nicer than all those dots.

You can't use commas in a string you are setting into a variable as well.
Title: Re: Highlight Search Keywords v1.1
Post by: karlbenson on January 18, 2008, 11:46:12 PM
I have reuploaded this mod and screenshots for it.

I am in the process of doing it for ALL my other mods aswell.  Please bear with me.
Title: Re: Highlight Search Keywords v1.1
Post by: SgtMic on January 25, 2008, 12:59:20 PM
Is it safe to assume that if I want to change the 1st highlight color chosen (currently ffff66) all I would need to do is make the changes in Subs.php and Search.php? I can adjust the colors as needed in:

$colors = array('#ffff66', '#a0ffff', '#99ff99', '#ff9999', '#ff66ff', '#880000', '#00aa00', '#886800', '#004699', '#990099');



ETA: That did it. :)
Title: Re: Highlight Search Keywords v1.1
Post by: karlbenson on January 25, 2008, 02:05:08 PM
Yeah it should work.

Note, I would NOT recommend ADDING more colors NOR REMOVING any colors.
This is because the colors have the id 0 - 9 representing the 1st to 10th colors.

If you have more keywords than that, it will use the last digit to work out what color to show.
So the 15th would take the 5th color etc
Title: Re: Highlight Search Keywords v1.1
Post by: SgtMic on January 25, 2008, 03:33:19 PM
I removed the yellow and swapped it with a blue. The text in the forum is white and did not show very well with yellow highlight. So far no problems.

You have some great mods out there. Look forward to them in 2.0.
Title: Re: Highlight Search Keywords v1.1
Post by: humbleworld on February 24, 2008, 10:04:30 PM
Hello Karl,

I installed this MOD but got error and my entire website is down. I uninstalled the MOD from Admin area and got error from removal.

What shall I do so that everything associated with this MOD I can remove manually and my site will be back without any code of this MOD? I have deleted the package in cPanel but there are codes in other php files that I don't know how to remove them manually.

Thanks for the advise.
Title: Re: Highlight Search Keywords v1.1
Post by: humbleworld on February 24, 2008, 10:07:06 PM
I got this error every time I do a search in my site:

Fatal error: Call to undefined function: highlighter() in
/home/myaccount/public_html/mywebsite/Sources/Search.php on line 1575

The site is online again, only that search.php has errors caused by the "highlighter."
Title: Re: Highlight Search Keywords v1.1
Post by: karlbenson on February 24, 2008, 10:43:28 PM
The function added by the mod is missing from Search.php

Use a package parser to get the function edit
http://www.adrevenueshare.com/parser

Double check all the edits of the mod.
Title: Re: Highlight Search Keywords v1.1
Post by: humbleworld on February 25, 2008, 12:14:12 AM
Quote from: karlbenson on February 24, 2008, 10:43:28 PM
The function added by the mod is missing from Search.php

Use a package parser to get the function edit
http://www.adrevenueshare.com/parser

Double check all the edits of the mod.

Hello Karl,

I just want to remove the MOD and all its codes. I will install it next time.

My problem is that the search.php is already corrupted and causing ghost bumps in my website. Thank you, Karl.
Title: Re: Highlight Search Keywords v1.1
Post by: karlbenson on February 25, 2008, 12:27:18 AM
Double check the edits and remove or add them as necessary.
Title: Re: Highlight Search Keywords v1.1
Post by: humbleworld on February 25, 2008, 01:28:52 AM
Karl, can I just overwrite the search.php by uploading the search.php from my backup?

What are the files in SMF where I can remove trace of highlighter? I need to manually take them out as they are creating problems to my forum members.
Title: Re: Highlight Search Keywords v1.1
Post by: karlbenson on February 25, 2008, 01:35:53 PM
It would depend whether any other mods are installed.  I wouldn't recommending just replacing the search.php.

Like i said above, use the Package Parser to get the edits.

If you want to remove the mod manually, check that ALL the edits are removed in all the files.
Title: Re: Highlight Search Keywords v1.1
Post by: humbleworld on February 25, 2008, 02:04:31 PM
Hello Karl,

I followed your instruction using the Parser.

For now, the site is running well. I just did the editing stuff.

Thank you, Karl!
Title: Re: Highlight Search Keywords v1.1
Post by: Javed_dotsis365 on March 17, 2008, 02:05:56 AM
Hi Karl,

I want to install this module but I am curious how will this help the forum. Will it help in search ranking or other things?
Title: Re: Highlight Search Keywords v1.1
Post by: karlbenson on March 17, 2008, 09:51:48 AM
It won't help in terms of search rankings.

All it does it show users their search terms highlighted in the page (like Google does when you view its cache)
Title: Re: Highlight Search Keywords v1.1
Post by: humbleworld on March 19, 2008, 08:36:23 PM
Hi Karl,

I got this error in my site after removing this MOD. I have done the Parser, but still the error shows up.

8: Undefined variable: body_highlighted
File: /home/mainfolder/public_html/subfolder/Sources/Search.php
Line: 1571

Undefined variable: subject_highlighted
File: /home/mainfolder/public_html/subfolder/Sources/Search.php
Line: 1572

Here's the code from search.php line 1571 to 1573. I'm not sure if get the right line.

   $body_highlighted = preg_replace('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/ie' . ($context['utf8'] ? 'u' : ''), "'\$2' == '\$1' ? stripslashes('\$1') : '<b class=\"highlight\">\$1</b>'", $body_highlighted);
      $subject_highlighted = preg_replace('/(' . preg_quote($query, '/') . ')/i' . ($context['utf8'] ? 'u' : ''), '<b class="highlight">$1</b>', $subject_highlighted);
   }
Title: Re: Highlight Search Keywords v1.1
Post by: Nathaniel on May 30, 2008, 10:13:00 PM
Karlbenson is going to stop supporting this Mod and I am going to start supporting it, (http://www.simplemachines.org/community/index.php?topic=225192.0) I will look over the code in about two weeks and release another version of the Mod which supports SMF 2 Beta 3.1 and fixes any bugs that I can find, such as highlighting of the news bar when you open up an item which you have searched for and etc, or maybe a setting to turn that on or off.

I will probably also add a number of settings so that an admin can change some of the behaviors of this Mod, such as an extendable list of colors that will be used as well as a maybe a setting to turn the highlighting on or off.

Any comments or suggestions would be more than welcome in the next few weeks before I start the next version.

Thank you,
LHVWB