You are here

function biblio_db_search in Bibliography Module 6

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

Return value

unknown_type

1 call to biblio_db_search()
biblio_get_user_pubs in ./biblio.pages.inc
1 string reference to 'biblio_db_search'
biblio_menu in ./biblio.module
Implementation of hook_menu().

File

./biblio.pages.inc, line 28

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 ($query_info['rss']['feed']) {
    biblio_filter_feed($query_info['query'], $query_info['query_terms'], $query_info['rss']);
  }
  else {

    //$count = db_result(db_query($query_info['count_query'],$query_info['query_terms']));
    $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);
  }
}