search_view

Versions
4.6 – 5
search_view()
6 – 7
search_view($type = 'node')

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

Code

modules/search.module, line 550

<?php
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 ($_POST['edit']['keys']) {
    if ($type == '') {
      $type = 'node';
    }
    drupal_goto('search/'. urlencode($type) .'/'. urlencode($_POST['edit']['keys']));
  }
  else 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();

  if (user_access('search content')) {
    // 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/'. urlencode($type) .'/'. urlencode($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'));
      }
    }
    else if (isset($_POST['edit'])) {
      form_set_error('keys', t('Please enter some keywords.'));
    }

    // Construct the search form.
    // Note, we do this last because of the form_set_error() above.
    $output = search_form(NULL, $keys, $type);

    $output .= $results;

    print theme('page', $output);
  }
  else {
    drupal_access_denied();
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.