You are here

function biblio_contextObject in Bibliography Module 7.2

Same name and namespace in other branches
  1. 5 biblio.module \biblio_contextObject()
  2. 6.2 includes/biblio.util.inc \biblio_contextObject()
  3. 6 biblio.module \biblio_contextObject()
  4. 7 includes/biblio.util.inc \biblio_contextObject()
2 calls to biblio_contextObject()
biblio_coins in includes/biblio.util.inc
biblio_openurl in includes/biblio.theme.inc

File

includes/biblio.util.inc, line 65

Code

function biblio_contextObject($biblio) {

  // Copyright:          Matthias Steffens <mailto:refbase@extracts.de> and the file's
  //                     original author.
  // Original Author:    Richard Karnesky <mailto:karnesky@gmail.com>  //
  // Adapted for biblio: Ron Jerome
  global $base_url;
  $wrapper = biblio_wrapper($biblio);

  // The empty() function can't be given the direct return of a method, so
  // we have to set each of the methods we're going to use as a variable
  $title = $wrapper->biblio_title
    ->value();
  $secondary_title = $wrapper->biblio_title_secondary
    ->value();
  $short_title = $wrapper->biblio_short_title
    ->value();
  $tertiary_title = $wrapper->biblio_title_tertiary
    ->value();
  $issn = $wrapper->biblio_issn
    ->value();
  $isbn = $wrapper->biblio_isbn
    ->value();
  $year = $wrapper->biblio_year
    ->value();
  $volume = $wrapper->biblio_volume
    ->value();
  $issue = $wrapper->biblio_issue
    ->value();
  $pages = $wrapper->biblio_pages
    ->value();
  $publisher = $wrapper->biblio_publisher
    ->value();
  $place_published = $wrapper->biblio_place_published
    ->value();
  $doi = $wrapper->biblio_doi
    ->value();
  $i = 0;

  // $openurl_base = variable_get('biblio_baseopenurl', '');
  $co = array();

  // rfr_id
  //  $co["rfr_id"] = "info:sid/". ereg_replace("http://", "", $base_url);
  //  // genre (type)
  //  if (isset($node->biblio_type)) {
  //    if ($node->biblio_type == 102)
  //    $co["rft.genre"] = "article";
  //    elseif ($node->biblio_type == 101) $co["rft.genre"] = "bookitem";
  //    elseif ($node->biblio_type == 100) $co["rft.genre"] = "book";
  //    elseif ($node->biblio_type == "Journal") $co["rft.genre"] = "journal";
  //  }
  // atitle, btitle, title (title, publication)
  if ($biblio->publication_type == 'journal_article' || $biblio->publication_type == 'book_chapter') {
    if (!empty($title)) {
      $co["rft.atitle"] = check_plain($title);
    }
    if (!empty($secondary_title)) {
      $co["rft.title"] = check_plain($secondary_title);
      if ($biblio->publication_type == 'book_chapter') {
        $co["rft.btitle"] = check_plain($secondary_title);
      }
    }
  }
  elseif (!empty($title)) {
    $co["rft.title"] = check_plain($title);
  }
  if ($biblio->publication_type == 'book' && !empty($secondary_title)) {
    $co["rft.btitle"] = check_plain($secondary_title);
  }

  // stitle (abbrev_journal)
  if (!empty($short_title)) {
    $co["rft.stitle"] = check_plain($short_title);
  }

  // series (series_title)
  if (!empty($tertiary_title)) {
    $co["rft.series"] = check_plain($tertiary_title);
  }

  // issn
  if (!empty($issn)) {
    $co["rft.issn"] = check_plain($issn);
  }

  // isbn
  if (!empty($isbn)) {
    $co["rft.isbn"] = check_plain($isbn);
  }

  // date (year)
  if (!empty($year)) {
    $co["rft.date"] = check_plain($year);
  }

  // volume
  if (!empty($volume)) {
    $co["rft.volume"] = check_plain($volume);
  }

  // issue
  if (!empty($issue)) {
    $co["rft.issue"] = check_plain($issue);
  }

  // spage, epage, tpages (pages)
  // NOTE: lifted from modsxml.inc.php--should throw some into a new include file
  if (!empty($pages)) {
    if (preg_match("/[0-9] *- *[0-9]/", $pages)) {
      list($pagestart, $pageend) = preg_split('/\\s*[-]\\s*/', $pages);
      if ($pagestart < $pageend) {
        $co["rft.spage"] = check_plain($pagestart);
        $co["rft.epage"] = check_plain($pageend);
      }
    }
    elseif ($biblio->publication_type == 'book') {

      //"Book Whole") {
      $pagetotal = preg_replace('/^(\\d+)\\s*pp?\\.?$/', "\\1", $pages);
      $co["rft.tpages"] = check_plain($pagetotal);
    }
    else {
      $co["rft.spage"] = check_plain($pages);
    }
  }

  // @todo: get this working with new contributors implementation
  // aulast, aufirst, author (author)
  if (!empty($biblio->biblio_contributors)) {
    if (!empty($biblio->biblio_contributors[0]['lastname'])) {
      $co["rft.aulast"] = check_plain($biblio->biblio_contributors[0]['lastname']);
    }
    if (!empty($biblio->biblio_contributors[0]['firstname'])) {
      $co["rft.aufirst"] = check_plain($biblio->biblio_contributors[0]['firstname']);
    }
    elseif (!empty($biblio->biblio_contributors[0]['initials'])) {
      $co["rft.auinit"] = check_plain($biblio->biblio_contributors[0]['initials']);
    }
    for ($i = 1; $i < count($biblio->biblio_contributors); $i++) {
      $author = $biblio->biblio_contributors[$i];
      if ($author['category'] == 'primary') {
        if (!empty($author['lastname'])) {
          $au = $author['lastname'];
          if (!empty($author['firstname']) || !empty($author['initials'])) {
            $au .= ", ";
          }
        }
        if (!empty($author['firstname'])) {
          $au .= $author['firstname'];
        }
        elseif (!empty($author['initials'])) {
          $au .= $author['initials'];
        }
        if (!empty($au)) {
          $co["rft.au" . $i] = $au;
        }
      }
    }
  }

  // pub (publisher)
  if (!empty($publisher)) {
    $co["rft.pub"] = check_plain($publisher);
  }

  // place
  if (!empty($place_published)) {
    $co["rft.place"] = check_plain($place_published);
  }

  // id (doi, url)
  if (!empty($doi)) {
    $co["rft_id"] = "info:doi/" . check_plain($doi);
  }

  //  elseif (!empty($node->biblio_url)) {
  //    $co["rft_id"] = $node->biblio_url;
  //  }
  return $co;
}