| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
function search_view($type = 'node') {
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
if (!isset($_POST['form_id'])) {
|
| 17 |
if ($type == '') {
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
drupal_goto('search/node');
|
| 22 |
}
|
| 23 |
|
| 24 |
$keys = search_get_keys();
|
| 25 |
|
| 26 |
$results = '';
|
| 27 |
if (trim($keys)) {
|
| 28 |
|
| 29 |
watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys));
|
| 30 |
|
| 31 |
|
| 32 |
$results = search_data($keys, $type);
|
| 33 |
|
| 34 |
|
| 35 |
$build['search_form'] = drupal_get_form('search_form', NULL, $keys, $type);
|
| 36 |
$build['search_results'] = array(
|
| 37 |
'#theme' => 'search_results_listing',
|
| 38 |
'#title' => empty($results) ? t('Your search yielded no results') : t('Search results'),
|
| 39 |
'#content' => empty($results) ? search_help('search#noresults', drupal_help_arg()) : $results,
|
| 40 |
|
| 41 |
|
| 42 |
return $build;
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
return drupal_get_form('search_form', NULL, empty($keys) ? '' : $keys, $type);
|
| 47 |
}
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
function theme_search_results_listing($title, $content) {
|
| 60 |
$output = '<h2 class="title">' . $title . '</h2><div>' . $content . '</div>';
|
| 61 |
return $output;
|
| 62 |
}
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
function template_preprocess_search_results(&$variables) {
|
| 74 |
$variables['search_results'] = '';
|
| 75 |
foreach ($variables['results'] as $result) {
|
| 76 |
$variables['search_results'] .= theme('search_result', $result, $variables['type']);
|
| 77 |
}
|
| 78 |
$variables['pager'] = theme('pager', NULL);
|
| 79 |
|
| 80 |
$variables['template_files'][] = 'search-results-' . $variables['type'];
|
| 81 |
}
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
function template_preprocess_search_result(&$variables) {
|
| 93 |
$result = $variables['result'];
|
| 94 |
$variables['url'] = check_url($result['link']);
|
| 95 |
$variables['title'] = check_plain($result['title']);
|
| 96 |
|
| 97 |
$info = array();
|
| 98 |
if (!empty($result['type'])) {
|
| 99 |
$info['type'] = check_plain($result['type']);
|
| 100 |
}
|
| 101 |
if (!empty($result['user'])) {
|
| 102 |
$info['user'] = $result['user'];
|
| 103 |
}
|
| 104 |
if (!empty($result['date'])) {
|
| 105 |
$info['date'] = format_date($result['date'], 'small');
|
| 106 |
}
|
| 107 |
if (isset($result['extra']) && is_array($result['extra'])) {
|
| 108 |
$info = array_merge($info, $result['extra']);
|
| 109 |
}
|
| 110 |
|
| 111 |
$variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
|
| 112 |
|
| 113 |
$variables['info_split'] = $info;
|
| 114 |
$variables['info'] = implode(' - ', $info);
|
| 115 |
|
| 116 |
$variables['template_files'][] = 'search-result-' . $variables['type'];
|
| 117 |
}
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
function search_form_validate($form, &$form_state) {
|
| 126 |
form_set_value($form['basic']['inline']['processed_keys'], trim($form_state['values']['keys']), $form_state);
|
| 127 |
}
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
function search_form_submit($form, &$form_state) {
|
| 133 |
$keys = $form_state['values']['processed_keys'];
|
| 134 |
if ($keys == '') {
|
| 135 |
form_set_error('keys', t('Please enter some keywords.'));
|
| 136 |
|
| 137 |
}
|
| 138 |
|
| 139 |
$type = $form_state['values']['module'] ? $form_state['values']['module'] : 'node';
|
| 140 |
$form_state['redirect'] = 'search/' . $type . '/' . $keys;
|
| 141 |
return;
|
| 142 |
}
|
| 143 |
|