Code coverage for /20081101/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
 */
1219
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
1615
  if (!isset($_POST['form_id'])) {
1711
    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
2411
    $keys = search_get_keys();
25
    // Only perform search if there is non-whitespace search term:
2611
    $results = '';
2711
    if (trim($keys)) {
28
      // Log the search keys:
296
      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:
326
      $results = search_data($keys, $type);
33
346
      if ($results) {
353
        $results = theme('box', t('Search results'), $results);
363
      }
37
      else {
383
        $results = theme('box', t('Your search yielded no results'),
search_help('search#noresults', drupal_help_arg()));
39
      }
406
    }
41
42
    // Construct the search form.
4311
    $output = drupal_get_form('search_form', NULL, $keys, $type);
4411
    $output .= $results;
45
4611
    return $output;
470
  }
48
494
  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
 */
6119
function template_preprocess_search_results(&$variables) {
623
  $variables['search_results'] = '';
633
  foreach ($variables['results'] as $result) {
643
    $variables['search_results'] .= theme('search_result', $result,
$variables['type']);
653
  }
663
  $variables['pager'] = theme('pager', NULL, 10, 0);
67
  // Provide alternate search results template.
683
  $variables['template_files'][] = 'search-results-' . $variables['type'];
693
}
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
 */
8019
function template_preprocess_search_result(&$variables) {
813
  $result = $variables['result'];
823
  $variables['url'] = check_url($result['link']);
833
  $variables['title'] = check_plain($result['title']);
84
853
  $info = array();
863
  if (!empty($result['type'])) {
873
    $info['type'] = check_plain($result['type']);
883
  }
893
  if (!empty($result['user'])) {
903
    $info['user'] = $result['user'];
913
  }
923
  if (!empty($result['date'])) {
933
    $info['date'] = format_date($result['date'], 'small');
943
  }
953
  if (isset($result['extra']) && is_array($result['extra'])) {
963
    $info = array_merge($info, $result['extra']);
973
  }
98
  // Check for existence. User search does not include snippets.
993
  $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] :
'';
100
  // Provide separated and grouped meta information..
1013
  $variables['info_split'] = $info;
1023
  $variables['info'] = implode(' - ', $info);
103
  // Provide alternate search result template.
1043
  $variables['template_files'][] = 'search-result-' . $variables['type'];
1053
}
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
 */
11319
function search_form_validate($form, &$form_state) {
1144
  form_set_value($form['basic']['inline']['processed_keys'],
trim($form_state['values']['keys']), $form_state);
1154
}
116
117
/**
118
 * Process a search form submission.
119
 */
12019
function search_form_submit($form, &$form_state) {
1214
  $keys = $form_state['values']['processed_keys'];
1224
  if ($keys == '') {
1230
    form_set_error('keys', t('Please enter some keywords.'));
124
    // Fall through to the drupal_goto() call.
1250
  }
126
1274
  $type = $form_state['values']['module'] ? $form_state['values']['module']
: 'node';
1284
  $form_state['redirect'] = 'search/' . $type . '/' . $keys;
1294
  return;
1300
}
13119