Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: Mr. Pedram on February 06, 2013, 03:38:11 PM

Title: Search Topic And Board Button
Post by: Mr. Pedram on February 06, 2013, 03:38:11 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=3627)

Search Topic And Board Button v1.0
Add "Search This Topic" And "Search This Board" Button in Display.template.php and MessageIndex.template.php

Compatibility
SMF 2.0

Mod by: Mr. Pedram (http://www.simplemachines.org/community/index.php?action=profile;u=323252)

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.creativecommons.org%2Fl%2Fby-nc-nd%2F3.0%2F88x31.png&hash=8719f18c90cbd576bc578f378c0dbf23030467d6)
This mod is licensed under a CC BY-NC-ND 3.0 (http://creativecommons.org/licenses/by-nc-nd/3.0/)
Title: Re: Search Topic And Board Button
Post by: 4Kstore on February 07, 2013, 08:34:11 AM
Wow, this is a great idea...!! thanks for share
Title: Re: Search Topic And Board Button
Post by: Sudhakar Arjunan on February 08, 2013, 06:31:03 PM
Great mod, trying now.
Title: Re: Search Topic And Board Button
Post by: dimspace on February 08, 2013, 07:59:25 PM
excellent idea. why has nobody thought of this before.
Title: Re: Search Topic And Board Button
Post by: Arantor on February 08, 2013, 08:02:38 PM
Mostly because SMF does most of it out of the box?

If you're in a topic already and use the quick search, it will only search that topic (and has done since 1.0)

If you're in a board already and use the quick search, it will only search that board.

All this really does is provide a UI for functionality that's been there for 10 years.


I am also curious as to the necessity of the edit to the search template to add what looks like another 'search' button when there's already one there...
Title: Re: Search Topic And Board Button
Post by: dimspace on February 08, 2013, 08:10:04 PM
not sure why theres a search edit.

and its not working for me, just takes me to a regular search, but that could be the fault of my slightly vandalised installation.
Title: Re: Search Topic And Board Button
Post by: Mr. Pedram on February 13, 2013, 08:43:56 AM
Thanks to everyone, this mod most usefull for custom them, not default smf them, due some themes haven't "Quick Search Bar"
Title: Re: Search Topic And Board Button
Post by: LexusFTW on February 13, 2013, 01:06:51 PM
Quote from: dimspace on February 08, 2013, 08:10:04 PM
not sure why theres a search edit.

and its not working for me, just takes me to a regular search, but that could be the fault of my slightly vandalised installation.

Same for me.  Does not custom search boards.  Topic search works though.
Title: Re: Search Topic And Board Button
Post by: Mr. Pedram on February 13, 2013, 04:21:12 PM
ok you right, look like something went wrong , i'll check it.
Title: Re: Search Topic And Board Button
Post by: PierreP_whited00r_com on May 03, 2013, 04:02:54 PM
Quote from: Arantor on February 08, 2013, 08:02:38 PM

...If you're in a topic already and use the quick search, it will only search that topic (and has done since 1.0)

If you're in a board already and use the quick search, it will only search that board.

All this really does is provide a UI for functionality that's been there for 10 years.

I am also curious as to the necessity of the edit to the search template to add what looks like another 'search' button when there's already one there...

Well in our case the Quick Search opens a custom Google Search page not restricted to a given thread so that Search within a thread button is really useful so thank you Mr. Pedram for sharing!  8)

I did not test the mod yet, will report later.

To differentiate from Quick & Advanced Search I would prefer that it would say "Search Thread" or "Search This Thread". At the present:
Title: Re: Search Topic And Board Button
Post by: GL700Wing on July 25, 2018, 02:22:38 AM
Quote from: LexusFTW on February 13, 2013, 01:06:51 PM
Does not custom search boards.  Topic search works though.
I have the same issue with this mod on my forums (one of which does not have a 'Quick Search' option at the top because of the theme I am using) so today I decided to have a go at fixing it.  By making the following changes the 'Search' button displayed at the top of the Message Index will open a Search form that only searches the current board.

In ./Sources/Search.php

Find:
if (!empty($_REQUEST['topic']))
Add Before:
// Search Topic and Board Button mod.
// If $_REQUEST['board'] is set, that means we're searching just one board.
if (!empty($_REQUEST['board']))
{
$context['search_params']['board'] = (int) $_REQUEST['board'];
$context['search_params']['show_complete'] = true;
}
if (!empty($context['search_params']['board']))
{
$context['search_params']['board'] = (int) $context['search_params']['board'];

$context['search_board'] = array(
'id' => $context['search_params']['board'],
'href' => $scripturl . '?board=' . $context['search_params']['board'] . '.0',
);

$request = $smcFunc['db_query']('', '
SELECT name
FROM {db_prefix}boards
WHERE id_board = {int:search_board}
LIMIT 1',
array(
'search_board' => $context['search_params']['board'],
)
);

if ($smcFunc['db_num_rows']($request) == 0)
fatal_lang_error('topic_gone', false);

list ($context['search_board']['name']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

$context['search_board']['link'] = '<a href="' . $context['search_board']['href'] . '">' . $context['search_board']['name'] . '</a>';
}



Find:
// Ensure that brd is an array.
Add Before:
// Search Topic and Board Button mod.
// If $_REQUEST['board'] is set, that means we're searching just one board.
elseif (!empty($_REQUEST['board']))
$_REQUEST['brd'] = $_REQUEST['board'];




In ./Themes/default/Search.template.php

Find:
// If $context['search_params']['topic'] is set, that means we're searching just one topic.
Add Before:
// Search Topic and Board Button mod.
// Added code to show which board is being searched when using search button at top of board.
// If $context['search_params']['board'] is set, that means we're searching just one board.
if (!empty($context['search_params']['board']))
echo '
<p>', $txt['search_specific_board'], ' <em>&quot;', $context['search_board']['link'], '&quot;</em>.</p>
<input type="hidden" name="board" value="', $context['search_board']['id'], '" />';



Find:
if (empty($context['search_params']['topic']))
Replace With:
// Search Topic and Board Button mod.
// Added code to exclude board selection is searching from button at top of board.
//if (empty($context['search_params']['topic']))
if (empty($context['search_params']['topic']) && empty($context['search_params']['board']))



In ./Themes/default/languages/Search.english.php

Find:
$txt['search_specific_topic'] = 'Searching only posts in the topic';
Add After:
// Search Topic and Board Button mod.
$txt['search_specific_board'] = 'Searching only posts in the board';