123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- function search_view($module = NULL, $keys = '') {
- $info = FALSE;
- $keys = trim($keys);
-
-
- if (!$keys && !empty($_REQUEST['keys'])) {
- $keys = trim($_REQUEST['keys']);
- }
- if (!empty($module)) {
- $active_module_info = search_get_info();
- if (isset($active_module_info[$module])) {
- $info = $active_module_info[$module];
- }
- }
- if (empty($info)) {
-
-
-
- $info = search_get_default_module_info();
-
- $path = 'search/' . $info['path'];
- if ($keys) {
- $path .= '/' . $keys;
- }
- drupal_goto($path);
- }
-
- $results = array('#markup' => '');
-
-
-
-
-
- if (empty($_POST['form_id']) || ($_POST['form_id'] != 'search_form' && $_POST['form_id'] != 'search_block_form')) {
- $conditions = NULL;
- if (isset($info['conditions_callback']) && function_exists($info['conditions_callback'])) {
-
- $conditions = call_user_func($info['conditions_callback'], $keys);
- }
-
- if ($keys || !empty($conditions)) {
- if (variable_get('search_logging', TRUE)) {
-
- watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $info['title']), WATCHDOG_NOTICE, l(t('results'), 'search/' . $info['path'] . '/' . $keys));
- }
-
- $results = search_data($keys, $info['module'], $conditions);
- }
- }
-
- $build['search_form'] = drupal_get_form('search_form', NULL, $keys, $info['module']);
- $build['search_results'] = $results;
- return $build;
- }
- function template_preprocess_search_results(&$variables) {
- $variables['search_results'] = '';
- if (!empty($variables['module'])) {
- $variables['module'] = check_plain($variables['module']);
- }
- foreach ($variables['results'] as $result) {
- $variables['search_results'] .= theme('search_result', array('result' => $result, 'module' => $variables['module']));
- }
- $variables['pager'] = theme('pager', array('tags' => NULL));
- $variables['theme_hook_suggestions'][] = 'search_results__' . $variables['module'];
- }
- function template_preprocess_search_result(&$variables) {
- global $language;
- $result = $variables['result'];
- $variables['url'] = check_url($result['link']);
- $variables['title'] = check_plain($result['title']);
- if (isset($result['language']) && $result['language'] != $language->language && $result['language'] != LANGUAGE_NONE) {
- $variables['title_attributes_array']['xml:lang'] = $result['language'];
- $variables['content_attributes_array']['xml:lang'] = $result['language'];
- }
- $info = array();
- if (!empty($result['module'])) {
- $info['module'] = check_plain($result['module']);
- }
- if (!empty($result['user'])) {
- $info['user'] = $result['user'];
- }
- if (!empty($result['date'])) {
- $info['date'] = format_date($result['date'], 'short');
- }
- if (isset($result['extra']) && is_array($result['extra'])) {
- $info = array_merge($info, $result['extra']);
- }
-
- $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
-
- $variables['info_split'] = $info;
- $variables['info'] = implode(' - ', $info);
- $variables['theme_hook_suggestions'][] = 'search_result__' . $variables['module'];
- }
- function search_form_validate($form, &$form_state) {
- form_set_value($form['basic']['processed_keys'], trim($form_state['values']['keys']), $form_state);
- }
- function search_form_submit($form, &$form_state) {
- $keys = $form_state['values']['processed_keys'];
- if ($keys == '') {
- form_set_error('keys', t('Please enter some keywords.'));
-
- }
- $form_state['redirect'] = $form_state['action'] . '/' . $keys;
- }
|