Code coverage for /20080809/modules/search/search.pages.inc

Line #Times calledCode
1
<?php
2
// $Id: search.pages.inc,v 1.5 2008/04/14 17:48:41 dries Exp $
3
4
/**
5
 * @file
6
 * User page callbacks for the search module.
7
 */
8
9
/**
10
 * Menu callback; presents the search form and/or search results.
11
 */
126
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
164
  if (!isset($_POST['form_id'])) {
173
    if ($type == '') {
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.
210
      drupal_goto('search/node');
220
    }
23
243
    $keys = search_get_keys();
25
    // Only perform search if there is non-whitespace search term:
263
    $results = '';
273
    if (trim($keys)) {
28
      // Log the search keys:
291
      watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type'
=> module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE,
l(t('results'), 'search/' . $type . '/' . $keys));
30
31
      // Collect the search results:
321
      $results = search_data($keys, $type);
33
341
      if ($results) {
350
        $results = theme('box', t('Search results'), $results);
360
      }
37
      else {
381
        $results = theme('box', t('Your search yielded no results'),
search_help('search#noresults', drupal_help_arg()));
39
      }
401
    }
41
42
    // Construct the search form.
433
    $output = drupal_get_form('search_form', NULL, $keys, $type);
443
    $output .= $results;
45
463
    return $output;
470
  }
48
491
  return drupal_get_form('search_form', NULL, empty($keys) ? '' : $keys,
$type);
500
}
51
52
/**
53
 * Process variables for search-results.tpl.php.
54
 *
55
 * The $variables array contains the following arguments:
56
 * - $results
57
 * - $type
58
 *
59
 * @see search-results.tpl.php
60
 */
616
function template_preprocess_search_results(&$variables) {
620
  $variables['search_results'] = '';
630
  foreach ($variables['results'] as $result) {
640
    $variables['search_results'] .= theme('search_result', $result,
$variables['type']);
650
  }
660
  $variables['pager'] = theme('pager', NULL, 10, 0);
67
  // Provide alternate search results template.
680
  $variables['template_files'][] = 'search-results-' . $variables['type'];
690
}
70
71
/**
72
 * Process variables for search-result.tpl.php.
73
 *
74
 * The $variables array contains the following arguments:
75
 * - $result
76
 * - $type
77
 *
78
 * @see search-result.tpl.php
79
 */
806
function template_preprocess_search_result(&$variables) {
810
  $result = $variables['result'];
820
  $variables['url'] = check_url($result['link']);
830
  $variables['title'] = check_plain($result['title']);
84
850
  $info = array();
860
  if (!empty($result['type'])) {
870
    $info['type'] = check_plain($result['type']);
880
  }
890
  if (!empty($result['user'])) {
900
    $info['user'] = $result['user'];
910
  }
920
  if (!empty($result['date'])) {
930
    $info['date'] = format_date($result['date'], 'small');
940
  }
950
  if (isset($result['extra']) && is_array($result['extra'])) {
960
    $info = array_merge($info, $result['extra']);
970
  }
98
  // Check for existence. User search does not include snippets.
990
  $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] :
'';
100
  // Provide separated and grouped meta information..
1010
  $variables['info_split'] = $info;
1020
  $variables['info'] = implode(' - ', $info);
103
  // Provide alternate search result template.
1040
  $variables['template_files'][] = 'search-result-' . $variables['type'];
1050
}
106
107
/**
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.
112
 */
1136
function search_form_validate($form, &$form_state) {
1141
  form_set_value($form['basic']['inline']['processed_keys'],
trim($form_state['values']['keys']), $form_state);
1151
}
116
117
/**
118
 * Process a search form submission.
119
 */
1206
function search_form_submit($form, &$form_state) {
1211
  $keys = $form_state['values']['processed_keys'];
1221
  if ($keys == '') {
1230
    form_set_error('keys', t('Please enter some keywords.'));
124
    // Fall through to the drupal_goto() call.
1250
  }
126
1271
  $type = $form_state['values']['module'] ? $form_state['values']['module']
: 'node';
1281
  $form_state['redirect'] = 'search/' . $type . '/' . $keys;
1291
  return;
1300
}
1316