View previous topic :: View next topic |
Author |
Message |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Sat Dec 07, 2002 4:27 pm Post subject: [Hacks] Highlight Search String |
|
|
Hmm, did a highlight seacrh string hack as requested by my ownself http://tidakada.com/board/viewtopic.php?t=1781
There is still one bug that is broken hyperlinks if the search word so happen to be in a hyperlink. Anyone know how to fix this?
Here is the code
Find This
[php:1:f397cb07f2]
function the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
$content = get_the_content($more_link_text,$stripteaser,$more_file);
$content = convert_bbcode($content);
$content = convert_gmcode($content);
$content = convert_smilies($content);
$content = convert_chars($content, 'html');
$content = apply_filters('the_content', $content);
echo $content;
}
[/php:1:f397cb07f2]
Replace With
[php:1:f397cb07f2]
function the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
global $HTTP_GET_VARS;
$content = get_the_content($more_link_text,$stripteaser,$more_file);
if(isset($HTTP_GET_VARS["s"])) {
$s = $HTTP_GET_VARS["s"];
$word_array = explode(' ', $s);
foreach ($word_array as $word) {
$words[] = preg_quote($word, '/');
}
$highlight_words = implode('|', $words);
$content = preg_replace("/($highlight_words)/i", '<b>$1</b>', $content);
}
$content = convert_bbcode($content);
$content = convert_gmcode($content);
$content = convert_smilies($content);
$content = convert_chars($content, 'html');
$content = apply_filters('the_content', $content);
echo $content;
}
[/php:1:f397cb07f2]Any problems please reply here _________________
++ GamerZ.Per.Sg - Complex Simplicity
Last edited by GamerZ on Sun Jan 05, 2003 4:42 pm; edited 1 time in total |
|
Back to top |
|
 |
Mister44

Joined: 31 Oct 2002 Posts: 237 Location: Philadelphia, PA, USA
|
Posted: Sat Dec 07, 2002 6:57 pm Post subject: |
|
|
You can't with any efficiency. Load the searchhi.js script from kyrogenix.org and this Code: | /* based on http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */
/* Modified 20021207 to support b2's internal searching - you must have searchhi.js loaded */
function b2SearchHighlight() {
if (!document.createElement) return;
ref = window.location.href;
if (ref.indexOf('?') == -1) return;
qs = ref.substr(ref.indexOf('?')+1);
qsa = qs.split('&');
for (i=0;i<qsa.length;i++) {
qsip = qsa[i].split('=');
if (qsip.length == 1) continue;
if (qsip[0] == 's') {
words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
for (w=0;w<words.length;w++) {
highlightWord(document.getElementsByTagName("body")[0],words[w]);
}
}
}
}
window.onload = b2SearchHighlight; |
You can also get the file at http://frcooper.com/journal/b2searchhi.js |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Sun Dec 08, 2002 6:37 am Post subject: |
|
|
woot, thanks Mister, it works _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
Mister44

Joined: 31 Oct 2002 Posts: 237 Location: Philadelphia, PA, USA
|
Posted: Sun Dec 08, 2002 6:48 am Post subject: |
|
|
Praise Stuart at kryo, not me. He did all the hard stuff :) |
|
Back to top |
|
 |
dtdgoomba
Joined: 05 Aug 2002 Posts: 179 Location: Cambridge, MA
|
Posted: Mon Dec 09, 2002 3:28 am Post subject: |
|
|
So i loaded both js files. right order, searchhi then b2searchhi
http://anthony.torres.name/js/searchhi.js (the b2one is in there too), and the css as:
.searchword {
background-color: yellow;
}
in my /css/styles.css file
I do a search internally and from google and I never get my words highlighted. Can anyone help me out? |
|
Back to top |
|
 |
Mister44

Joined: 31 Oct 2002 Posts: 237 Location: Philadelphia, PA, USA
|
Posted: Mon Dec 09, 2002 5:15 am Post subject: |
|
|
Well, your searchhi.js appears to contain highlightWord and b2searchHighlight, but not googlesearchHighlight... so that at a minimum explains why those aren't being highlighted.
As for why the b2 searches arent being highlighted, try looking at the html your b2 is actually generating. Between the embedded style info and divs within tables within divs, I wouldn't be suprised if the javascript function can't figure out which DOM node to highlight.
there's no simple fix for this that I can see. |
|
Back to top |
|
 |
dtdgoomba
Joined: 05 Aug 2002 Posts: 179 Location: Cambridge, MA
|
Posted: Mon Dec 09, 2002 5:47 am Post subject: |
|
|
Thanks. I figured it had to do with all my layers and tags, but recoding it all with just css to improve my layout will have to come with more time. Thanks for taking a look though. |
|
Back to top |
|
 |
dtdgoomba
Joined: 05 Aug 2002 Posts: 179 Location: Cambridge, MA
|
Posted: Tue Dec 10, 2002 7:06 am Post subject: |
|
|
Ok, I've been playing with my code so there are no tables within the divs (in the blog only right now), but I'm pretty sure I'm going to have nested divs no matter what. Any ideas on what to change in the js so it knows where to look?
I also fixed the javascript. I had it correct originally and then tried to copy gamerz and overwrote/forgot a piece. Now it has the original searchhi.js and the b2searchhi.js parts.
http://anthony.torres.name
http://anthony.torres.name/js/astscripts.js
Thanks. |
|
Back to top |
|
 |
Mister44

Joined: 31 Oct 2002 Posts: 237 Location: Philadelphia, PA, USA
|
Posted: Tue Dec 10, 2002 7:37 am Post subject: |
|
|
Well nesting divs is reasonable. It's all reasonable if you can keep the structure straight.
Next recommendation would be to strip out as much of the inline css as possible. I'm not a CSS guru by far, but as with most things, less is more. |
|
Back to top |
|
 |
|