You are here

function biblio_db_search in Bibliography Module 6.2

Same name and namespace in other branches
  1. 5 biblio.module \biblio_db_search()
  2. 6 biblio.pages.inc \biblio_db_search()

Page callback: Displays a listing of biblio type of content.

This function is responsible for generating the page that is displayed on the primary menu path of the biblio module (ie /biblio).

Return value

null|string If an rss feed is desired, there will be no return value. Otherwise, an HTML string suitable for display in a browser will be returned.

See also

biblio_menu()

1 call to biblio_db_search()
biblio_get_user_pubs in includes/biblio.pages.inc
Retrieves the publications associated with an user ID.
1 string reference to 'biblio_db_search'
biblio_menu in ./biblio.module
Implements hook_menu().

File

includes/biblio.pages.inc, line 29
Functions in the biblio module related to filtering and page generation.

Code

function biblio_db_search() {
  $arg_list = array();
  $arg_list = func_get_args();
  foreach ($_GET as $key => $value) {
    if ($key != 'q') {
      $arg_list[] = check_plain($key);
      $arg_list[] = check_plain($value);
    }
  }

  // Drupal search? It returns an array of search results. We store the nids
  // of the result nodes and make them a "where n.nid in {..}" filter.
  // After installing the filter, we can go on as usual.
  // When called manually, search takes one parameter, i.e.
  // biblio_db_search('search', 'bla blu')
  $search = array_search('search', $arg_list);
  if ($search !== FALSE) {
    $keys = $arg_list[$search + 1];

    // Special case: if search is activated via URL, i.e., biblio/search/...,
    // we reset the search session filter. Two searches are not combinable.
    $base = variable_get('biblio_base', 'biblio');
    if (preg_match('+' . $base . '/search/+', $_GET['q'])) {
      $_SESSION['biblio_filter'] = array();
    }
  }
  else {
    $keys = _get_biblio_search_filter();
  }
  if ($keys) {

    // Only search in biblio nodes. If we use a SESSION filter and have a list of
    // nids stored there, don't re-search. List is reset when submitting a new search.
    if ($search !== FALSE || !_get_biblio_search_filter('nodelist')) {
      if ($result = biblio_build_search_query($keys)) {
        $node_list = '';
        while ($nid = db_result($result)) {
          $node_list .= $nid . ",";
        }

        // No node search result. Make sure we find nothing, too. Node -1 does not exist.
        if (empty($node_list)) {
          $node_list = '-1';
        }

        // Store as SESSION filter or argument list.
        // When called as function argument it takes only one parameter, i.e.
        // biblio_db_search('search', 'bla blu') and we must insert the node
        // list inbetween.
        if ($search !== FALSE) {
          array_splice($arg_list, $search + 1, 0, $node_list);
        }
        else {
          $_SESSION['biblio_filter'] = array(
            array(
              'search',
              rtrim($node_list, ','),
              $keys,
            ),
          );
        }
      }
      else {
        $_SESSION['biblio_filter'] = array();
      }
    }
  }
  $inline = in_array('inline', $arg_list);
  $inline = in_array('profile', $arg_list) ? 'profile' : $inline;
  $query_info = biblio_build_query($arg_list);

  // If desired, prepare a listing in rss feed format which will print directly
  // to the screen with no return value.
  if ($query_info['rss']['feed']) {
    biblio_filter_feed($query_info['query'], $query_info['query_terms'], $query_info['rss']);
    return;
  }

  // Prepare an HTML formatted string for display in browser.
  $nodes = array();
  $result = pager_query($query_info['query'], variable_get('biblio_rowsperpage', 25), 0, $query_info['count_query'], $query_info['query_terms']);
  $query_info['filter_line'] = _biblio_filter_info_line($query_info['args']);
  while ($res = db_fetch_array($result)) {
    $node = node_load($res['nid']);
    foreach ($res as $key => $value) {
      if (!isset($node->{$key})) {
        $node->{$key} = $value;
      }
    }
    $nodes[] = $node;
  }
  return biblio_show_results($nodes, $query_info, $inline);
}