function biblio_crossref_xml_import in Bibliography Module 6
1 call to biblio_crossref_xml_import()
- biblio_form_validate in ./
biblio.module - Implementation of hook_validate().
File
- ./
biblio.import.export.inc, line 929 - Functions that are used to import and export biblio data.
Code
function biblio_crossref_xml_import($doi, $terms = array(), $batch = FALSE, $session_id = NULL, $save = FALSE) {
global $user, $node, $save_node, $nids;
if (isset($user->biblio_crossref_pid) && !empty($user->biblio_crossref_pid) && variable_get('biblio_show_crossref_profile_form', '1')) {
$pid = $user->biblio_crossref_pid;
}
else {
$pid = variable_get('biblio_crossref_pid', '');
}
if (!empty($pid)) {
$save_node = $save;
$nids = array();
$url = 'http://www.crossref.org/openurl/?pid=' . check_plain($pid) . '&noredirect=true&format=unixref&id=doi%3A' . $doi;
$response = drupal_http_request($url);
if (!empty($response->data) && $response->code == 200) {
$xml_parser = drupal_xml_parser_create($response->data);
// use case-folding so we are sure to find the tag in
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, true);
module_load_include('inc', 'biblio', 'crossref_unixref_parser');
xml_set_element_handler($xml_parser, 'unixref_startElement', 'unixref_endElement');
xml_set_character_data_handler($xml_parser, 'unixref_characterData');
xml_parse($xml_parser, $response->data);
xml_parser_free($xml_parser);
return !empty($nids) ? $nids : array();
}
else {
drupal_set_message(t('Could not open crossref.org for XML input'), 'error');
return;
}
}
}