You are here

function search_view in Drupal 4

Same name and namespace in other branches
  1. 5 modules/search/search.module \search_view()
  2. 6 modules/search/search.pages.inc \search_view()
  3. 7 modules/search/search.pages.inc \search_view()

Menu callback; presents the search form and/or search results.

1 string reference to 'search_view'
search_menu in modules/search.module
Implementation of hook_menu().

File

modules/search.module, line 887
Enables site-wide keyword searching.

Code

function search_view() {
  $type = arg(1);

  // Search form submits with POST but redirects to GET. This way we can keep
  // the search query URL clean as a whistle:
  // search/type/keyword+keyword
  if (!isset($_POST['edit']['form_id'])) {
    if ($type == '') {

      // Note: search/node can not be a default tab because it would take on the
      // path of its parent (search). It would prevent remembering keywords when
      // switching tabs. This is why we drupal_goto to it from the parent instead.
      drupal_goto('search/node');
    }
    $keys = search_get_keys();

    // Only perform search if there is non-whitespace search term:
    if (trim($keys)) {

      // Log the search keys:
      watchdog('search', t('Search: %keys (%type).', array(
        '%keys' => theme('placeholder', $keys),
        '%type' => module_invoke($type, 'search', 'name'),
      )), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys));

      // Collect the search results:
      $results = search_data($keys, $type);
      if ($results) {
        $results = theme('box', t('Search results'), $results);
      }
      else {
        $results = theme('box', t('Your search yielded no results'), search_help('search#noresults'));
      }
    }

    // Construct the search form.
    $output = search_form(NULL, $keys, $type);
    $output .= $results;
    return $output;
  }
  return search_form(NULL, $keys, $type);
}