You are here

function _biblio_bibtex_export in Bibliography Module 7.2

Same name and namespace in other branches
  1. 6.2 modules/bibtexParse/biblio_bibtex.module \_biblio_bibtex_export()
  2. 7 modules/bibtexParse/biblio_bibtex.module \_biblio_bibtex_export()

Export data in bibtex format.

Parameters

$result: a database result set pointer

Return value

none

2 calls to _biblio_bibtex_export()
BiblioImportExportUnitTest::testBiblioNodeExport in tests/import.export.test
biblio_bibtex_biblio_export in modules/bibtexParse/biblio_bibtex.module

File

modules/bibtexParse/biblio_bibtex.module, line 339

Code

function _biblio_bibtex_export($biblio) {
  static $converter = NULL;
  $bibtex = '';
  $type = "article";
  $journal = $series = $booktitle = $school = $organization = $institution = NULL;
  $type = _biblio_bibtex_type_map($biblio->publication_type);
  $wrapper = biblio_wrapper($biblio);
  switch ($biblio->publication_type) {
    case 'book':
      $series = $wrapper->biblio_title_secondary
        ->value();
      $organization = $wrapper->biblio_publisher
        ->value();
      break;
    case 'book_chapter':
    case 'conference_paper':
      $booktitle = $wrapper->biblio_title_secondary
        ->value();
      $organization = $wrapper->biblio_publisher
        ->value();
      $series = $wrapper->biblio_title_tertiary
        ->value();
      break;
    case 'thesis':
      $school = $wrapper->biblio_publisher
        ->value();
      $wrapper->biblio_publisher = NULL;
      if (stripos($wrapper->biblio_type_of_work
        ->value(), 'masters')) {
        $type = "mastersthesis";
      }
      break;
    case 'report':
      $institution = $wrapper->biblio_publisher
        ->value();
      $wrapper->biblio_publisher = NULL;
      break;
    case 'journal_article':
    default:
      $journal = $wrapper->biblio_title_secondary
        ->value();
      break;
  }
  $bibtex .= '@' . $type . ' {';
  $bibtex .= $wrapper->biblio_citekey
    ->value() ? $wrapper->biblio_citekey
    ->value() : "";
  $bibtex .= _biblio_bibtex_format_entry('title', $wrapper->biblio_title
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('journal', $journal);
  $bibtex .= _biblio_bibtex_format_entry('booktitle', $booktitle);
  $bibtex .= _biblio_bibtex_format_entry('series', $series);
  $bibtex .= _biblio_bibtex_format_entry('volume', $wrapper->biblio_volume
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('number', $wrapper->biblio_number
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('year', $wrapper->biblio_year
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('note', $wrapper->biblio_notes
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('month', $wrapper->biblio_date
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('pages', $wrapper->biblio_pages
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('publisher', $wrapper->biblio_publisher
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('school', $school);
  $bibtex .= _biblio_bibtex_format_entry('organization', $organization);
  $bibtex .= _biblio_bibtex_format_entry('institution', $institution);
  $bibtex .= _biblio_bibtex_format_entry('type', $wrapper->biblio_type_of_work
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('edition', $wrapper->biblio_edition
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('chapter', $wrapper->biblio_section
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('address', $wrapper->biblio_place_published
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('abstract', $wrapper->biblio_abst_e
    ->value());
  $kw_array = array();
  foreach ($wrapper->biblio_keywords as $term) {
    $kw_array[] = $term->name
      ->value();
  }
  if (!empty($kw_array)) {
    $kw_array = array_unique($kw_array);
    $bibtex .= _biblio_bibtex_format_entry('keywords', implode(', ', $kw_array));
  }
  $bibtex .= _biblio_bibtex_format_entry('isbn', $wrapper->biblio_isbn
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('issn', $wrapper->biblio_issn
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('doi', $wrapper->biblio_doi
    ->value());
  $bibtex .= _biblio_bibtex_format_entry('url', $wrapper->biblio_url
    ->value());
  if (!empty($biblio->upload) && count($biblio->upload['und']) && user_access('view uploaded files')) {
    foreach ($biblio->upload['und'] as $file) {
      $attachments[] = file_create_url($file['uri']);
    }
    $bibtex .= _biblio_bibtex_format_entry('attachments', implode(' , ', $attachments));
  }
  $a = $e = $authors = array();
  if ($authors = biblio_get_contributors($biblio)) {
    foreach ($authors as $auth) {
      $a[] = trim($auth['name']);
    }
  }

  // if ($authors = biblio_get_contributor_category($wrapper->biblio_contributors, 2)) {
  //   foreach ($authors as $auth) $e[] = trim($auth['name']);
  // }
  $a = implode(' and ', $a);
  $e = implode(' and ', $e);
  if (!empty($a)) {
    $bibtex .= _biblio_bibtex_format_entry('author', $a);
  }
  if (!empty($e)) {
    $bibtex .= _biblio_bibtex_format_entry('editor', $e);
  }
  $bibtex .= "\n}\n";

  //now convert any special characters to the latex equivelents...
  if (!isset($converter)) {
    module_load_include('php', 'biblio_bibtex', 'PARSEENTRIES');
    include_once drupal_get_path('module', 'biblio_bibtex') . '/transtab_unicode_bibtex.inc.php';
    $converter = new PARSEENTRIES();
  }
  $bibtex = $converter
    ->searchReplaceText(_biblio_bibtex_get_transtab(), $bibtex, FALSE);
  return $bibtex;
}