You are here

function _biblio_bibtex_import in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/bibtexParse/biblio_bibtex.module \_biblio_bibtex_import()
  2. 7.2 modules/bibtexParse/biblio_bibtex.module \_biblio_bibtex_import()
1 call to _biblio_bibtex_import()
biblio_bibtex_biblio_import in modules/bibtexParse/biblio_bibtex.module

File

modules/bibtexParse/biblio_bibtex.module, line 253

Code

function _biblio_bibtex_import($entries, $terms = array(), $batch = FALSE, $session_id = NULL, $save = TRUE) {
  $nids = array();
  $dups = array();
  foreach ($entries as $entry) {
    $node = new stdClass();
    $node->biblio_contributors = array();
    $node->biblio_type = _biblio_bibtex_type_map($entry['bibtexEntryType'], 'import');
    switch ($entry['bibtexEntryType']) {
      case 'mastersthesis':
        $node->biblio_type_of_work = 'masters';
        break;
      case 'phdthesis':
        $node->biblio_type_of_work = 'phd';
        break;
      default:
        $node->biblio_type_of_work = NULL;
    }
    $node->biblio_type_of_work .= !empty($entry['type']) ? $entry['type'] : NULL;
    if (!empty($entry['author'])) {

      // Split on ' and '.
      $author_array = preg_split("/\\s(and|&)\\s/i", trim($entry['author']));
      foreach ($author_array as $key => $author) {

        // Discard braces as biblio uses its own heuristic to split up human names,
        // and the braces get in the way.
        $author = str_replace(array(
          '{',
          '}',
        ), array(
          '',
          '',
        ), $author);
        $node->biblio_contributors[] = array(
          'name' => $author,
          'auth_category' => 1,
          'auth_type' => _biblio_get_auth_type(1, $node->biblio_type),
        );
      }
    }
    $node->biblio_citekey = !empty($entry['bibtexCitation']) ? $entry['bibtexCitation'] : NULL;
    if (!empty($entry['editor'])) {
      $author_array = preg_split("/\\s(and|&)\\s/i", trim($entry['editor']));
      foreach ($author_array as $key => $author) {

        // Discard braces as biblio uses its own heuristic to split up human names,
        // and the braces get in the way.
        $author = str_replace(array(
          '{',
          '}',
        ), array(
          '',
          '',
        ), $author);
        $node->biblio_contributors[] = array(
          'name' => $author,
          'auth_category' => 2,
          'auth_type' => _biblio_get_auth_type(2, $node->biblio_type),
        );
      }
    }
    $node->biblio_secondary_title = !empty($entry['journal']) ? $entry['journal'] : NULL;
    if (!empty($entry['booktitle'])) {
      $node->biblio_secondary_title = $entry['booktitle'];
    }
    if (!empty($entry['series'])) {
      if (!empty($entry['booktitle'])) {
        $node->biblio_tertiary_title = $entry['series'];
      }
      else {
        $node->biblio_secondary_title = $entry['series'];
      }
    }
    $node->biblio_volume = !empty($entry['volume']) ? $entry['volume'] : NULL;
    $node->biblio_number = !empty($entry['number']) ? $entry['number'] : NULL;
    $node->biblio_year = !empty($entry['year']) ? $entry['year'] : NULL;
    $node->biblio_notes = !empty($entry['note']) ? $entry['note'] : NULL;
    $node->biblio_date = !empty($entry['month']) ? $entry['month'] : NULL;

    // From isi web of science.
    if (!empty($entry['article-number'])) {
      $node->biblio_pages = $entry['article-number'];
    }
    else {
      $node->biblio_pages = !empty($entry['pages']) ? $entry['pages'] : NULL;
    }
    $node->biblio_publisher = !empty($entry['publisher']) ? $entry['publisher'] : NULL;
    if (!empty($entry['organization'])) {
      $node->biblio_publisher = $entry['organization'];
    }
    if (!empty($entry['school'])) {
      $node->biblio_publisher = $entry['school'];
    }
    if (!empty($entry['institution'])) {
      $node->biblio_publisher = $entry['institution'];
    }
    $node->title = !empty($entry['title']) ? $entry['title'] : NULL;
    $node->biblio_edition = !empty($entry['edition']) ? $entry['edition'] : NULL;
    $node->biblio_section = !empty($entry['chapter']) ? $entry['chapter'] : NULL;
    $node->biblio_place_published = !empty($entry['address']) ? $entry['address'] : NULL;
    $node->biblio_abst_e = !empty($entry['abstract']) ? $entry['abstract'] : NULL;
    if (!empty($entry['keywords'])) {
      if (strpos($entry['keywords'], ';')) {
        $entry['keywords'] = str_replace(';', ',', $entry['keywords']);
      }
      $node->biblio_keywords = explode(',', $entry['keywords']);
    }
    $node->biblio_isbn = !empty($entry['isbn']) ? $entry['isbn'] : NULL;
    $node->biblio_issn = !empty($entry['issn']) ? $entry['issn'] : NULL;
    $node->biblio_url = !empty($entry['url']) ? $entry['url'] : NULL;
    $node->biblio_doi = !empty($entry['doi']) ? $entry['doi'] : NULL;
    if (module_exists('biblio_pm')) {
      $node->biblio_pubmed_id = !empty($entry['pmid']) ? $entry['pmid'] : NULL;
      $node->biblio_pubmed_md5 = '';
    }
    $node->biblio_bibtex_md5 = md5(serialize($node));
    $node->biblio_import_type = 'bibtex';
    if (!($dup = biblio_bibtex_check_md5($node->biblio_bibtex_md5))) {
      if ($save) {
        biblio_save_node($node, $terms, $batch, $session_id, $save);
        $nids[] = !empty($node->nid) ? $node->nid : NULL;
      }
      else {
        $nids[] = $node;
      }
    }
    else {
      $dups[] = $dup;
    }
  }
  return array(
    $nids,
    $dups,
  );
}