Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: pctwo in September 07, 2006, 01:59:25 VORMITTAG

Titel: Add context to simple (quick) search
Beitrag von: pctwo in September 07, 2006, 01:59:25 VORMITTAG
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 :)
Titel: Re: Tip: add context to simple (quick) search
Beitrag von: Bigguy in September 07, 2006, 02:15:34 VORMITTAG
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. :)
Titel: Re: Tip: add context to simple (quick) search
Beitrag von: Bigguy in September 08, 2006, 06:20:20 NACHMITTAGS
I have started the package and now am in the testing phaze. I will do more tomorrow as there are some errors.
Titel: Re: Tip: add context to simple (quick) search
Beitrag von: pctwo in September 08, 2006, 07:01:51 NACHMITTAGS
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 :)
Titel: Re: Tip: add context to simple (quick) search
Beitrag von: JayBachatero in September 08, 2006, 11:55:21 NACHMITTAGS
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).
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in September 09, 2006, 02:06:45 VORMITTAG
Have you fixed your first post. ??? I will start over. I want to do it.

EDIT: unless you would like to try pctwo. ???
Titel: Re: Add context to simple (quick) search
Beitrag von: pctwo in September 09, 2006, 12:58:28 NACHMITTAGS
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
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in September 09, 2006, 01:40:13 NACHMITTAGS
I'll get on it today for you. If all goes well it might be done by tonight. (I hope) ;)
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in September 09, 2006, 07:46:10 NACHMITTAGS
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.
Titel: Re: Add context to simple (quick) search
Beitrag von: JayBachatero in September 10, 2006, 12:15:47 VORMITTAG
You can't.  Try using the board mod format instead of the .xml.
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in September 10, 2006, 12:47:48 VORMITTAG
Ok, I'll give that a shot.  Thanks Jay.
Titel: Re: Add context to simple (quick) search
Beitrag von: pctwo in September 10, 2006, 10:27:34 VORMITTAG
Zitat von: Bigguy in September 09, 2006, 07:46:10 NACHMITTAGS
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.
Titel: Re: Add context to simple (quick) search
Beitrag von: Dannii in September 10, 2006, 11:45:28 VORMITTAG
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.
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in September 10, 2006, 01:27:08 NACHMITTAGS
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. :)
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in September 11, 2006, 05:10:10 NACHMITTAGS
Ok, I have not given up just got a bit busy. I will start on this again later tonight. :)
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in September 13, 2006, 11:53:22 VORMITTAG
That one edit is still screwing me up is there another way to right that.
Titel: Re: Add context to simple (quick) search
Beitrag von: pctwo in September 13, 2006, 12:32:28 NACHMITTAGS
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.
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in September 13, 2006, 12:59:56 NACHMITTAGS
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.
Titel: Re: Add context to simple (quick) search
Beitrag von: Assistance in November 06, 2006, 05:26:01 VORMITTAG
Zitatwith 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  :-[
Titel: Re: Add context to simple (quick) search
Beitrag von: GaMerZ in Dezember 28, 2006, 04:58:26 VORMITTAG
any news on this?
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in Dezember 28, 2006, 10:38:33 VORMITTAG
No not yet. I have been a bit busy lately. I will try to get this done soon.
Titel: Re: Add context to simple (quick) search
Beitrag von: GaMerZ in Dezember 28, 2006, 12:08:56 NACHMITTAGS
sure sure thank u =)
Titel: Re: Add context to simple (quick) search
Beitrag von: jerm in Januar 30, 2007, 09:19:00 NACHMITTAGS
Was bigguy able to fix your issue?
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in Januar 31, 2007, 11:07:21 VORMITTAG
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.
Titel: Re: Add context to simple (quick) search
Beitrag von: BigMike in März 26, 2007, 02:07:01 NACHMITTAGS
This mod is very nice! Thankyou very much!
Titel: Re: Add context to simple (quick) search
Beitrag von: SMdot™ in Mai 04, 2007, 01:44:04 NACHMITTAGS
Zitat von: Bigguy in Januar 31, 2007, 11:07:21 VORMITTAG
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 =)
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in Mai 05, 2007, 12:41:51 NACHMITTAGS
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.
Titel: Re: Add context to simple (quick) search
Beitrag von: SMdot™ in Mai 05, 2007, 07:43:48 NACHMITTAGS
Zitat von: Bigguy in Mai 05, 2007, 12:41:51 NACHMITTAGS
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
Titel: Re: Add context to simple (quick) search
Beitrag von: geezmo in August 21, 2007, 01:11:02 NACHMITTAGS
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.
Titel: Re: Add context to simple (quick) search
Beitrag von: kai920 in Juni 09, 2008, 06:37:17 VORMITTAG
Has anyone used this with SMF 1.1.5?
Titel: Re: Add context to simple (quick) search
Beitrag von: Bigguy in Juni 13, 2008, 04:10:59 NACHMITTAGS
IF I find a bit of time I will see what I can do about packaging it.
Titel: Re: Add context to simple (quick) search
Beitrag von: pcigre in November 20, 2008, 09:18:11 VORMITTAG
Does it work for smf 1.1.7.?
Titel: Re: Add context to simple (quick) search
Beitrag von: pcigre in November 20, 2008, 09:36:23 VORMITTAG
Nah, it doesn't work with pretty urls mod :(
Titel: Re: Add context to simple (quick) search
Beitrag von: kyle007 in November 21, 2008, 06:47:26 VORMITTAG
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