00001 <?php
00002
00003
00012 function search_view($type = 'node') {
00013
00014
00015
00016 if (!isset($_POST['form_id'])) {
00017 if ($type == '') {
00018
00019
00020
00021 drupal_goto('search/node');
00022 }
00023
00024 $keys = search_get_keys();
00025
00026 $results = '';
00027 if (trim($keys)) {
00028
00029 watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys));
00030
00031
00032 $results = search_data($keys, $type);
00033
00034 if ($results) {
00035 $results = theme('box', t('Search results'), $results);
00036 }
00037 else {
00038 $results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg()));
00039 }
00040 }
00041
00042
00043 $output = drupal_get_form('search_form', NULL, $keys, $type);
00044 $output .= $results;
00045
00046 return $output;
00047 }
00048
00049 return drupal_get_form('search_form', NULL, empty($keys) ? '' : $keys, $type);
00050 }
00051
00061 function template_preprocess_search_results(&$variables) {
00062 $variables['search_results'] = '';
00063 foreach ($variables['results'] as $result) {
00064 $variables['search_results'] .= theme('search_result', $result, $variables['type']);
00065 }
00066 $variables['pager'] = theme('pager', NULL, 10, 0);
00067
00068 $variables['template_files'][] = 'search-results-' . $variables['type'];
00069 }
00070
00080 function template_preprocess_search_result(&$variables) {
00081 $result = $variables['result'];
00082 $variables['url'] = check_url($result['link']);
00083 $variables['title'] = check_plain($result['title']);
00084
00085 $info = array();
00086 if (!empty($result['type'])) {
00087 $info['type'] = check_plain($result['type']);
00088 }
00089 if (!empty($result['user'])) {
00090 $info['user'] = $result['user'];
00091 }
00092 if (!empty($result['date'])) {
00093 $info['date'] = format_date($result['date'], 'small');
00094 }
00095 if (isset($result['extra']) && is_array($result['extra'])) {
00096 $info = array_merge($info, $result['extra']);
00097 }
00098
00099 $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
00100
00101 $variables['info_split'] = $info;
00102 $variables['info'] = implode(' - ', $info);
00103
00104 $variables['template_files'][] = 'search-result-' . $variables['type'];
00105 }
00106
00113 function search_form_validate($form, &$form_state) {
00114 form_set_value($form['basic']['inline']['processed_keys'], trim($form_state['values']['keys']), $form_state);
00115 }
00116
00120 function search_form_submit($form, &$form_state) {
00121 $keys = $form_state['values']['processed_keys'];
00122 if ($keys == '') {
00123 form_set_error('keys', t('Please enter some keywords.'));
00124
00125 }
00126
00127 $type = $form_state['values']['module'] ? $form_state['values']['module'] : 'node';
00128 $form_state['redirect'] = 'search/' . $type . '/' . $keys;
00129 return;
00130 }