You are here

function biblio_show_results in Bibliography Module 5

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

File

./biblio.module, line 2113

Code

function biblio_show_results($result, $attrib = array(
  "sort" => 'year',
  'order' => 'DESC',
), $args = null, $inline = false) {
  global $pager_total_items;
  $base = variable_get('biblio_base', 'biblio');
  $style = variable_get('biblio_style', 'classic');
  theme('biblio_add_css');
  if (variable_get('biblio_rss', 0)) {
    drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="' . variable_get('site_name', 'Drupal') . ' RSS" href="' . url("{$base}/rss.xml") . '" />');
  }
  $pub_types = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid>0');
  while ($option = db_fetch_object($pub_types)) {
    $pub_type["{$option->tid}"] = $option->name;
  }
  if (!$inline) {

    // Add some links to the top of the page to change the sorting/ordering...
    if (biblio_access('export')) {
      $content .= '<div class="biblio_record_count">' . t('Found @count results', array(
        '@count' => $pager_total_items[0],
      )) . '</div><div class="biblio_export"> Export:[' . l("Tagged", "{$base}/export/tagged") . '][' . l("XML", "{$base}/export/xml") . '][' . l("BibTex", "{$base}/export/bib") . ']</div>';
    }
    else {
      $content .= '<div class="biblio_record_count">' . t('Found @count results', array(
        '@count' => $pager_total_items[0],
      )) . '</div><br />';
    }
    if (user_access('show sort links')) {
      $sort_attr = array(
        "title" => t("Click a second time to reverse the sort order"),
      );
      $sort_links = variable_get('biblio_sort_tabs', array(
        'author' => 'author',
        'title' => 'title',
        'type' => 'type',
        'year' => 'year',
      ));
      $query = NULL;
      foreach ($_GET as $key => $value) {
        if ($key != 'q' && $key != 'sort' && $key != 'order') {
          $query .= $key . '=' . $value;

          // $query will contain any addional URL query elements not related to this module
        }
      }
      if (!empty($query)) {
        $query = '&' . $query;
      }
      if (count(array_filter($sort_links))) {
        $content .= '<div class="biblio_sort">';
        $content .= t('Sort by') . ':';
        if ($sort_links['year']) {
          $order = $attrib['sort'] == 'year' ? $attrib['order'] == "desc" ? 'asc' : 'desc' : 'desc';
          $content .= "[" . l(t("Year"), $_GET['q'], $sort_attr, "sort=year&order={$order}{$query}") . "]";
        }
        if ($sort_links['title']) {
          $order = $attrib['sort'] == 'title' ? $attrib['order'] == "desc" ? 'asc' : 'desc' : 'asc';
          $content .= "[" . l(t("Title"), $_GET['q'], $sort_attr, "sort=title&order={$order}{$query}") . "]";
        }
        if ($sort_links['type']) {
          $order = $attrib['sort'] == 'type' ? $attrib['order'] == "desc" ? 'asc' : 'desc' : 'asc';
          $content .= "[" . l(t("Type"), $_GET['q'], $sort_attr, "sort=type&order={$order}{$query}") . "]";
        }
        if ($sort_links['author']) {
          $order = $attrib['sort'] == 'author' ? $attrib['order'] == "desc" ? 'asc' : 'desc' : 'asc';
          $content .= "[" . l(t("Author"), $_GET['q'], $sort_attr, "sort=author&order={$order}{$query}") . "]";
        }
        if ($sort_links['keyword']) {
          $order = $attrib['sort'] == 'keyword' ? $attrib['order'] == "desc" ? 'asc' : 'desc' : 'asc';
          $content .= "[" . l(t("Keyword"), $_GET['q'], $sort_attr, "sort=keyword&order={$order}{$query}") . "]";
        }
        $content .= "</div> ";
      }
    }
    $session =& $_SESSION['biblio_filter'];

    // if there are any filters in place, print them at the top of the list
    if (count($args)) {
      $content .= '<div class="biblio-current-filters"><b>' . t('Filters') . ': </b>';
      while ($args) {
        $type = $args[0];
        array_shift($args);
        $value = db_escape_string($args[0]);
        if ($type == 'term_id') {
          $term = taxonomy_get_term($value);
          $value = $term->name;
          $type = t("Taxonomy Term");
        }
        if ($type == 'type') {
          $value = $pub_type["{$value}"];
        }
        array_shift($args);
        $params = array(
          '%a' => $type,
          '%b' => $value,
        );
        $content .= $i++ ? t('<em> and</em> <strong>%a</strong> is <strong>%b</strong>', $params) : t('<strong>%a</strong> is <strong>%b</strong>', $params);
      }
      if ($inline != 'profile') {
        $content .= '&nbsp;&nbsp;' . l('[' . t('Clear All Filters') . ']', "{$base}/filter/clear");
        $content .= '</div>';
      }
    }
  }
  if ($inline === true) {
    print '<div class="biblio-inline">';
  }
  $_char = $_type = $_year = $name = "";
  while ($node = db_fetch_object($result)) {

    // to add links to attached files (if any)
    // we need the node->files array
    if (module_exists("upload")) {
      $node->files = upload_load($node);
    }
    if (isset($node->biblio_year) && $node->biblio_year == 9998) {
      $node->biblio_year = t("In Press");
    }
    if (isset($node->biblio_year) && $node->biblio_year == 9999) {
      $node->biblio_year = t("Submitted");
    }
    switch ($attrib['sort']) {
      case 'title':
        if (drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 1) != $_char) {
          $_char = drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 1);
          $content .= '<div class="biblio-year">' . $_char . "</div>\n";
        }
        break;
      case 'author':
        if (drupal_substr(drupal_ucfirst(ltrim($node->biblio_authors)), 0, 1) != $_char) {
          $_char = drupal_substr(drupal_ucfirst(ltrim($node->biblio_authors)), 0, 1);
          $content .= '<div class="biblio-year">' . $_char . "</div>\n";
        }
        break;
      case 'type':
        if ($node->biblio_type_name != $_type) {
          $_type = $node->biblio_type_name;

          //$name = db_result(db_query("SELECT name FROM {biblio_types} as t where t.tid=%d", $node->biblio_type)) ;
          $content .= '<div class="biblio-year">' . $_type . "</div>\n";
        }
        break;
      case 'keyword':

        // added msh 08 aug 07
        $tok = drupal_ucfirst(strtok($node->biblio_keywords, check_plain(variable_get('biblio_keyword_sep', ','))));
        if (empty($tok)) {
          $tok = t("No Keywords");
        }
        if ($tok != $name) {
          $name = $tok;
          if ($name != '') {
            $content .= '<div class="biblio-year">' . $name . "</div>\n";
          }
        }
        break;
      case 'year':
      default:
        if ($node->biblio_year != $_year) {
          $_year = $node->biblio_year;
          $content .= '<div class="biblio-year">' . $_year . "</div>\n";
        }
    }

    //end switch
    $content .= '<div class="biblio-entry">' . "\n";
    $inline_links = $inline && variable_get('inlinemode_in_links', 0) ? true : false;
    $content .= theme('biblio_list', $node, $base, $style, $inline_links);
    $content .= "</div>\n";
  }

  //end while
  $content .= theme('pager', 0, variable_get('biblio_rowsperpage', 25));
  if (!db_num_rows($result)) {
    $content .= "<h3>" . t("No items found") . "</h3>";
    if (strstr($content, "Filters:")) {
      $content .= t('!modify_link or !remove_link your filters and try again.', array(
        '!modify_link' => l(t('Modify'), "{$base}/filter"),
        '!remove_link' => l(t('remove'), "{$base}/filter/clear"),
      ));
    }
  }
  if (!$inline) {
    print theme('page', $content);
  }
  elseif ($inline == 'profile') {
    return $content;
  }
  else {
    print $content . "</div>";
  }
}