2
// $Id: search.pages.inc,v 1.4 2007/12/06 09:51:01 goba Exp $
6
* User page callbacks for the search module.
10
* Menu callback; presents the search form and/or search results.
12
function search_view($type = 'node') {
13
// Search form submits with POST but redirects to GET. This way we can keep
14
// the search query URL clean as a whistle:
15
// search/type/keyword+keyword
16
if (!isset($_POST['form_id'])) {
18
// Note: search/node can not be a default tab because it would take on the
19
// path of its parent (search). It would prevent remembering keywords when
20
// switching tabs. This is why we drupal_goto to it from the parent instead.
21
drupal_goto('search/node');
24
$keys = search_get_keys();
25
// Only perform search if there is non-whitespace search term:
28
// Log the search keys:
29
watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));
31
// Collect the search results:
32
$results = search_data($keys, $type);
35
$results = theme('box', t('Search results'), $results);
38
$results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg()));
42
// Construct the search form.
43
$output = drupal_get_form('search_form', NULL, $keys, $type);
49
return drupal_get_form('search_form', NULL, empty($keys) ? '' : $keys, $type);
53
* Process variables for search-results.tpl.php.
55
* The $variables array contains the following arguments:
59
* @see search-results.tpl.php
61
function template_preprocess_search_results(&$variables) {
62
$variables['search_results'] = '';
63
foreach ($variables['results'] as $result) {
64
$variables['search_results'] .= theme('search_result', $result, $variables['type']);
66
$variables['pager'] = theme('pager', NULL, 10, 0);
67
// Provide alternate search results template.
68
$variables['template_files'][] = 'search-results-'. $variables['type'];
72
* Process variables for search-result.tpl.php.
74
* The $variables array contains the following arguments:
78
* @see search-result.tpl.php
80
function template_preprocess_search_result(&$variables) {
81
$result = $variables['result'];
82
$variables['url'] = check_url($result['link']);
83
$variables['title'] = check_plain($result['title']);
86
if (!empty($result['type'])) {
87
$info['type'] = check_plain($result['type']);
89
if (!empty($result['user'])) {
90
$info['user'] = $result['user'];
92
if (!empty($result['date'])) {
93
$info['date'] = format_date($result['date'], 'small');
95
if (isset($result['extra']) && is_array($result['extra'])) {
96
$info = array_merge($info, $result['extra']);
98
// Check for existence. User search does not include snippets.
99
$variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
100
// Provide separated and grouped meta information..
101
$variables['info_split'] = $info;
102
$variables['info'] = implode(' - ', $info);
103
// Provide alternate search result template.
104
$variables['template_files'][] = 'search-result-'. $variables['type'];
108
* As the search form collates keys from other modules hooked in via
109
* hook_form_alter, the validation takes place in _submit.
110
* search_form_validate() is used solely to set the 'processed_keys' form
111
* value for the basic search form.
113
function search_form_validate($form, &$form_state) {
114
form_set_value($form['basic']['inline']['processed_keys'], trim($form_state['values']['keys']), $form_state);
118
* Process a search form submission.
120
function search_form_submit($form, &$form_state) {
121
$keys = $form_state['values']['processed_keys'];
123
form_set_error('keys', t('Please enter some keywords.'));
124
// Fall through to the drupal_goto() call.
127
$type = $form_state['values']['module'] ? $form_state['values']['module'] : 'node';
128
$form_state['redirect'] = 'search/'. $type .'/'. $keys;