function _biblio_tagged_import in Bibliography Module 6.2
Same name and namespace in other branches
- 7 modules/endnote/biblio_tagged.module \_biblio_tagged_import()
- 7.2 modules/endnote/biblio_tagged.module \_biblio_tagged_import()
Export data in tagged format.
Parameters
$result: a database result set pointer
Return value
none
1 call to _biblio_tagged_import()
- biblio_tagged_biblio_import in modules/
endnote/ biblio_tagged.module
File
- modules/
endnote/ biblio_tagged.module, line 164
Code
function _biblio_tagged_import($file, $terms = array(), $batch = FALSE, $session_id = NULL) {
ini_set('auto_detect_line_endings', true);
if (!($fp = fopen($file->filepath, "r"))) {
drupal_set_message("could not open EndNote Tagged input", 'error');
return;
}
$nids = array();
$dups = array();
$unmapped = array();
$node = NULL;
$incite = FALSE;
$node_id = NULL;
$contributors = NULL;
while (!feof($fp)) {
$line = trim(fgets($fp));
$line_len = strlen($line);
if ($line_len) {
$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);
$value = trim(drupal_substr($line, $start + 3));
}
else {
$value = $line;
}
}
if ($line_len) {
// if this is not a blank line
if (!$incite) {
$incite = TRUE;
$node = new stdClass();
//$node->biblio_contributors = array();
}
switch ($tag) {
case '%0':
$node->biblio_type = _biblio_tagged_type_map($value);
break;
case '%A':
$node->biblio_contributors[1][] = array(
'name' => $value,
'auth_type' => _biblio_get_auth_type(1, $node->biblio_type),
);
break;
case '%E':
$node->biblio_contributors[2][] = array(
'name' => $value,
'auth_type' => _biblio_get_auth_type(2, $node->biblio_type),
);
break;
case '%T':
$node->title = $value;
break;
case '%Y':
$node->biblio_contributors[3][] = array(
'name' => $value,
'auth_type' => _biblio_get_auth_type(3, $node->biblio_type),
);
break;
case '%?':
$node->biblio_contributors[4][] = array(
'name' => $value,
'auth_type' => _biblio_get_auth_type(4, $node->biblio_type),
);
break;
case '%X':
$node->biblio_abst_e .= $value;
break;
case '%Z':
$node->biblio_notes .= $value;
break;
default:
$field = _biblio_tagged_field_map($tag);
if (!empty($field)) {
$node->{$field} = $value;
}
else {
if (!in_array($tag, $unmapped)) {
$unmapped[] = $tag;
}
}
break;
}
//end switch
}
else {
$incite = FALSE;
if (!empty($node)) {
_biblio_tagged_save($node, $terms, $batch, $session_id, $nids, $dups);
$node = NULL;
}
}
// end if ($start !== false)
}
// end while
fclose($fp);
if ($incite && !empty($node)) {
// this catches the case where the file ends without a blank line at the end
_biblio_tagged_save($node, $terms, $batch, $session_id, $nids, $dups);
}
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/settings/biblio/iomap/edit/tagged'),
));
}
drupal_set_message($message, 'warning');
}
return array(
$nids,
$dups,
);
}