function _biblio_ris_import in Bibliography Module 7.2
Same name and namespace in other branches
- 6.2 modules/RIS/biblio_ris.module \_biblio_ris_import()
- 7 modules/RIS/biblio_ris.module \_biblio_ris_import()
1 call to _biblio_ris_import()
- biblio_ris_biblio_import in modules/
RIS/ biblio_ris.module
File
- modules/
RIS/ biblio_ris.module, line 225
Code
function _biblio_ris_import($file, $terms = array(), $batch = FALSE, $session_id = NULL) {
module_load_include('inc', 'biblio', 'includes/biblio.fields');
ini_set('auto_detect_line_endings', true);
if (!($fp = fopen($file->uri, "r"))) {
drupal_set_message(t("Could not open RIS input file for reading."), 'error');
return;
}
$tag = '';
$bids = array();
$dups = array();
$unmapped = array();
$biblio = new stdClass();
while (!feof($fp)) {
$line = fgets($fp);
$line_len = strlen($line);
if ($line_len > 3) {
$start = strpos($line, ' -');
// There could be some unprintables at the beginning of the line so fine the location of the %
if ($start !== FALSE) {
$tag = drupal_substr($line, $start - 2, 2);
$data = trim(drupal_substr($line, $start + 3));
}
else {
$data = $line;
}
}
if ($line_len > 3 && !empty($tag)) {
// if this is not a blank line
if ($tag == 'ER') {
if (!empty($biblio)) {
$biblio->biblio_ris_md5 = md5(serialize($biblio));
if (empty($biblio->biblio_title)) {
$biblio->biblio_title = t("Untitled");
}
if (!($dup = biblio_ris_check_md5($biblio->biblio_ris_md5))) {
$biblio_old = $biblio;
$biblio = biblio_create($biblio_old->biblio_type, (array) $biblio_old);
$biblio->biblio_keywords = $biblio_old->biblio_keywords;
biblio_save_node($biblio, $terms, $batch, $session_id);
if (!empty($biblio->bid)) {
$bids[] = $biblio->bid;
}
}
else {
$dups[] = $dup;
}
}
$biblio = new stdClass();
$biblio->biblio_contributors = array();
}
else {
_biblio_ris_parse_line($tag, $data, $biblio, $unmapped);
}
}
}
// end while
fclose($fp);
if (!empty($unmapped)) {
$ignored_tags = array_unique($unmapped);
$message = t("The following elements were ignored because they do not map to any biblio fields: ");
$message .= implode(', ', $ignored_tags);
if (user_access('administer biblio')) {
$message .= '. ' . t('Click !url if you wish to check the field mapping', array(
'!url' => l(t('here'), 'admin/config/content/biblio/iomap/edit/ris'),
));
}
drupal_set_message($message, 'warning');
}
return array(
$nids,
$dups,
);
}