You are here

function _biblio_bibtex_export in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/bibtexParse/biblio_bibtex.module \_biblio_bibtex_export()
  2. 7.2 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()
BiblioImportExportWebTestCase::testBiblioNodeExport in tests/BiblioImportExportWebTestCase.test
biblio_bibtex_biblio_export in modules/bibtexParse/biblio_bibtex.module

File

modules/bibtexParse/biblio_bibtex.module, line 383

Code

function _biblio_bibtex_export($node) {
  static $converter = NULL;
  $bibtex = '';
  $type = "article";
  $journal = $series = $booktitle = $school = $organization = $institution = $howpublished = NULL;
  $type = _biblio_bibtex_type_map($node->biblio_type);
  switch ($node->biblio_type) {
    case 100:
      $series = $node->biblio_secondary_title;
      $organization = $node->biblio_publisher;
      break;
    case 101:
    case 103:
      $booktitle = $node->biblio_secondary_title;
      $organization = $node->biblio_publisher;
      $series = $node->biblio_tertiary_title;
      break;
    case 108:
      $school = $node->biblio_publisher;
      $node->biblio_publisher = NULL;
      if (stripos($node->biblio_type_of_work, 'masters')) {
        $type = "mastersthesis";
      }
      break;
    case 109:
      $institution = $node->biblio_publisher;
      $node->biblio_publisher = NULL;
      break;
    case 102:
      $journal = $node->biblio_secondary_title;
      break;
    case 129:
      $howpublished = $node->biblio_secondary_title;
      break;
  }
  $bibtex .= '@' . $type . ' {';
  $bibtex .= $node->biblio_citekey ? $node->biblio_citekey : "";
  $bibtex .= _biblio_bibtex_format_entry('title', $node->title);
  $bibtex .= _biblio_bibtex_format_entry('journal', $journal);
  $bibtex .= _biblio_bibtex_format_entry('howpublished', $howpublished);
  $bibtex .= _biblio_bibtex_format_entry('booktitle', $booktitle);
  $bibtex .= _biblio_bibtex_format_entry('series', $series);
  $bibtex .= _biblio_bibtex_format_entry('volume', $node->biblio_volume);
  $bibtex .= _biblio_bibtex_format_entry('number', $node->biblio_number);
  $bibtex .= _biblio_bibtex_format_entry('year', $node->biblio_year);
  $bibtex .= _biblio_bibtex_format_entry('note', $node->biblio_notes);
  $bibtex .= _biblio_bibtex_format_entry('month', $node->biblio_date);
  $bibtex .= _biblio_bibtex_format_entry('pages', $node->biblio_pages);
  $bibtex .= _biblio_bibtex_format_entry('publisher', $node->biblio_publisher);
  $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', $node->biblio_type_of_work);
  $bibtex .= _biblio_bibtex_format_entry('edition', $node->biblio_edition);
  $bibtex .= _biblio_bibtex_format_entry('chapter', $node->biblio_section);
  $bibtex .= _biblio_bibtex_format_entry('address', $node->biblio_place_published);
  $bibtex .= _biblio_bibtex_format_entry('abstract', $node->biblio_abst_e);
  $kw_array = array();
  if (!empty($node->terms)) {
    foreach ($node->terms as $term) {
      $kw_array[] = $term->name;
    }
  }
  if (!empty($node->biblio_keywords)) {
    foreach ($node->biblio_keywords as $term) {
      $kw_array[] = $term;
    }
  }
  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', $node->biblio_isbn);
  $bibtex .= _biblio_bibtex_format_entry('issn', $node->biblio_issn);
  $bibtex .= _biblio_bibtex_format_entry('doi', $node->biblio_doi);
  $bibtex .= _biblio_bibtex_format_entry('url', $node->biblio_url);
  if (!empty($node->upload) && count($node->upload['und']) && user_access('view uploaded files')) {
    foreach ($node->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_contributor_category($node->biblio_contributors, 1)) {
    foreach ($authors as $auth) {
      $a[] = trim($auth['name']);
    }
  }
  if ($authors = biblio_get_contributor_category($node->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;
}