Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: pctwo on September 07, 2006, 01:59:25 AM

Title: Add context to simple (quick) search
Post by: pctwo on September 07, 2006, 01:59:25 AM
with 1.1RC3, we can now search in a topic using the simple (quick) search.  However, the user may not realize that when he's in a board, he's searching only the board if he uses the simple search, and when he's in a topic, he's searching only that topic.  This little change (which I haven't packaged into a nice mod b/c I haven't learned how to -- newbie alert!!) will show the user what context he's searching in and allows him to change it using a <select>.  So when he's at top level, there's no option.  When he's in a board, he can search the board or all.  When he's in a topic, he can search the topic, the board, or all.  Visual mockup (I can't post attachment)


____________ (search)   [ all         ]
                        [ this board  ]
                        [ this topic  ]


File:
Themes/name/index.template.php

Find:

   // Output any remaining HTML headers. (from mods, maybe?)
   echo $context['html_headers'], '

Add after


<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function search_context_change()
{
ctx =  document.quick_search.search_context.value;
if (ctx=="topic") {
if (document.quick_search.board_) document.quick_search.board_.name="dontuse";
document.quick_search.topic_.name = "topic";
} else
if (ctx=="board") {
if (document.quick_search.topic_) document.quick_search.topic_.name="donotuse";
document.quick_search.board_.name = "brd["+document.quick_search.board_.value+"]";
} else {
if (document.quick_search.board_) document.quick_search.board_.name="dontuse";
if (document.quick_search.topic_) document.quick_search.topic_.name="donotuse";
}
}
// ]]></script>



find:


<form action="', $scripturl, '?action=search2" method="post"


change to (add name="quick_search")

<form name="quick_search" action="', $scripturl, '?action=search2" method="post"

replace block


// Search within current topic?
if (!empty($context['current_topic']))
echo '
<input type="hidden" name="topic" value="', $context['current_topic'], '" />';

// If we're on a certain board, limit it to this board ;).
elseif (!empty($context['current_board']))
echo '
<input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';


replace with


if (!empty($context['current_board']) || !empty($context['current_topic']))
{
echo '
<select onchange="javascript:search_context_change();" name="search_context">
<option value="all">', $txt['search_context_all'], '</option>';

$hidden_inputs = '';

if (!empty($context['current_board']))
{
echo '
<option value="board" ',
empty($context['current_topic'])
? 'selected="selected"' : '', '>', $txt['search_context_board'], '</option>';
$hidden_inputs .= '
<input type="hidden" id="board_" name="' .
(empty($context['current_topic']) ? 'brd[' . $context['current_board'] . ']' : 'dontuse') .
'" value="' . $context['current_board'] . '" />';
}
if (!empty($context['current_topic']))
{
echo '
<option value="topic" selected="selected">', $txt['search_context_topic'], '</option>';
$hidden_inputs .= '
<input type="hidden" id="topic_" name="topic" value="' . $context['current_topic'] . '" />';
}
echo '
</select>', $hidden_inputs;
}


almost over!  now add to themes/name/languages/index.(lang).php


$txt['search_context_board'] = 'this board';
$txt['search_context_topic'] = 'this topic';
$txt['search_context_all'] = 'all';


hope that's useful :)
Title: Re: Tip: add context to simple (quick) search
Post by: Bigguy on September 07, 2006, 02:15:34 AM
This seems real cool. I can try to package it for you if you. Not tonight cause its late but if your interested PM me. :)
Title: Re: Tip: add context to simple (quick) search
Post by: Bigguy on September 08, 2006, 06:20:20 PM
I have started the package and now am in the testing phaze. I will do more tomorrow as there are some errors.
Title: Re: Tip: add context to simple (quick) search
Post by: pctwo on September 08, 2006, 07:01:51 PM
oops, I messed up something in the original post.  I had id="quick_search" when it should've been name="quick_search".  I've tested this on Opera 9, IE 6, and Firefox 1.5.  I guess if you really want to be safe you should have both name and id :)
Title: Re: Tip: add context to simple (quick) search
Post by: JayBachatero on September 08, 2006, 11:55:21 PM
This is a nice Tip.  I was just about to suggest for you to package it up.  If you are interested take a look at Package SDK, anyone? (http://www.simplemachines.org/community/index.php?topic=20319.0).
Title: Re: Add context to simple (quick) search
Post by: Bigguy on September 09, 2006, 02:06:45 AM
Have you fixed your first post. ??? I will start over. I want to do it.

EDIT: unless you would like to try pctwo. ???
Title: Re: Add context to simple (quick) search
Post by: pctwo on September 09, 2006, 12:58:28 PM
I'll learn how one of these days, but til then, please do it.  I'm more likely to mess something up :)

thanks, Bigguy.  And by all means give yourself credit, like "___ mod by Bigguy, based on a tip by pctwo"

edit: yes my first post should now be correct
Title: Re: Add context to simple (quick) search
Post by: Bigguy on September 09, 2006, 01:40:13 PM
I'll get on it today for you. If all goes well it might be done by tonight. (I hope) ;)
Title: Re: Add context to simple (quick) search
Post by: Bigguy on September 09, 2006, 07:46:10 PM
Having some major problems with this part of the one edit:

<!-- // --><![CDATA[

I don't think This can be in the middle of the code.
Title: Re: Add context to simple (quick) search
Post by: JayBachatero on September 10, 2006, 12:15:47 AM
You can't.  Try using the board mod format instead of the .xml.
Title: Re: Add context to simple (quick) search
Post by: Bigguy on September 10, 2006, 12:47:48 AM
Ok, I'll give that a shot.  Thanks Jay.
Title: Re: Add context to simple (quick) search
Post by: pctwo on September 10, 2006, 10:27:34 AM
Quote from: Bigguy on September 09, 2006, 07:46:10 PM
Having some major problems with this part of the one edit:

<!-- // --><![CDATA[

I don't think This can be in the middle of the code.

I just copied that syntax without knowing what it does really.  what DOES it do?

Traditionally, you're supposed to wrap the entire script with <!-- --> so you don't confuse really old browsers, but that's hardly necessary nowadays.
Title: Re: Add context to simple (quick) search
Post by: Dannii on September 10, 2006, 11:45:28 AM
If your javascript has < > or & you need to put it in <![CDATA[ ]]> tags so that it is valid x(ht)ml. Javascript however won't understand that, so you need to comment it out with // tags first.
I'm not certain why the (x)html comments are needed to comment out the // though..

If you wrap the whole script in (x)html comments then moddern browsers might not run the script at all.
Title: Re: Add context to simple (quick) search
Post by: Bigguy on September 10, 2006, 01:27:08 PM
Well, making a .mod file is a bit harder I think then making a .xml file. I keep getting a modification parse error, but I'm still trying. :)
Title: Re: Add context to simple (quick) search
Post by: Bigguy on September 11, 2006, 05:10:10 PM
Ok, I have not given up just got a bit busy. I will start on this again later tonight. :)
Title: Re: Add context to simple (quick) search
Post by: Bigguy on September 13, 2006, 11:53:22 AM
That one edit is still screwing me up is there another way to right that.
Title: Re: Add context to simple (quick) search
Post by: pctwo on September 13, 2006, 12:32:28 PM
I think you can forget the cdata stuff

<script language="JavaScript" type="text/javascript"><!--

--></script>



php seems ok with it and it passes w3c validation.

I'm sorry you're having so much trouble.  I think it's harder to package this little mod up than to write it :(

P.S: I think we should change

$txt['search_context_all'] = 'all';

to

$txt['search_context_all'] = 'entire forum';

to make it clearer.
Title: Re: Add context to simple (quick) search
Post by: Bigguy on September 13, 2006, 12:59:56 PM
Ok, I'll give that a try. I have had it packaged and installed but I keep getting parse errors and I don't think I am packing that cdata stuff right so I will try it without it.
Title: Re: Add context to simple (quick) search
Post by: Assistance on November 06, 2006, 05:26:01 AM
Quotewith 1.1RC3, we can now search in a topic using the simple (quick) search.  However, the user may not realize that when he's in a board, he's searching only the board if he uses the simple search, and when he's in a topic, he's searching only that topic.

some admins may not know that aswell  :-[
Title: Re: Add context to simple (quick) search
Post by: GaMerZ on December 28, 2006, 04:58:26 AM
any news on this?
Title: Re: Add context to simple (quick) search
Post by: Bigguy on December 28, 2006, 10:38:33 AM
No not yet. I have been a bit busy lately. I will try to get this done soon.
Title: Re: Add context to simple (quick) search
Post by: GaMerZ on December 28, 2006, 12:08:56 PM
sure sure thank u =)
Title: Re: Add context to simple (quick) search
Post by: jerm on January 30, 2007, 09:19:00 PM
Was bigguy able to fix your issue?
Title: Re: Add context to simple (quick) search
Post by: Bigguy on January 31, 2007, 11:07:21 AM
This was less of a problem and more of a mod that was supposed to be packaged but I did not get to it yet.
Title: Re: Add context to simple (quick) search
Post by: BigMike on March 26, 2007, 02:07:01 PM
This mod is very nice! Thankyou very much!
Title: Re: Add context to simple (quick) search
Post by: SMdot™ on May 04, 2007, 01:44:04 PM
Quote from: Bigguy on January 31, 2007, 11:07:21 AM
This was less of a problem and more of a mod that was supposed to be packaged but I did not get to it yet.

if you can pass me what you got so far... (mod) i can make some corrections, if not for smf, just for my own site, but opposed to me starting from scratch I'd appreciate it if you could just send me what you got...  i'll keep your credits and what not on there, since I'm not really in need of self promotions at this time =)
Title: Re: Add context to simple (quick) search
Post by: Bigguy on May 05, 2007, 12:41:51 PM
Due to a hard drive failure not to long ago I have lost all my info for everything. This will have to be started over.
Title: Re: Add context to simple (quick) search
Post by: SMdot™ on May 05, 2007, 07:43:48 PM
Quote from: Bigguy on May 05, 2007, 12:41:51 PM
Due to a hard drive failure not to long ago I have lost all my info for everything. This will have to be started over.

alrighty then, no big =P
Title: Re: Add context to simple (quick) search
Post by: geezmo on August 21, 2007, 01:11:02 PM
Looking forward to this package. I have long wanted an SMF search where you can choose which one (topic, category or entire board) you want to use.
Title: Re: Add context to simple (quick) search
Post by: kai920 on June 09, 2008, 06:37:17 AM
Has anyone used this with SMF 1.1.5?
Title: Re: Add context to simple (quick) search
Post by: Bigguy on June 13, 2008, 04:10:59 PM
IF I find a bit of time I will see what I can do about packaging it.
Title: Re: Add context to simple (quick) search
Post by: pcigre on November 20, 2008, 09:18:11 AM
Does it work for smf 1.1.7.?
Title: Re: Add context to simple (quick) search
Post by: pcigre on November 20, 2008, 09:36:23 AM
Nah, it doesn't work with pretty urls mod :(
Title: Re: Add context to simple (quick) search
Post by: kyle007 on November 21, 2008, 06:47:26 AM
Yeah it works for 1.1.7, great trick,thx... ;)

I've changed it a bit to port my search field... (top right corner)

Demo :
http://forum.hardwarena.com/index.php?board=28.0