Browse Source

add a second try for doi lookup in case parsing the doi makes the doi malformed

9.x-1.0
Paul Pound 8 years ago
parent
commit
10f492d040
  1. 10
      includes/doi.inc

10
includes/doi.inc

@ -20,6 +20,10 @@ function upei_roblib_ill_doi_get_data($form, $doi) {
$doi = 'Empty DOI'; $doi = 'Empty DOI';
} }
$response = upei_roblib_ill_doi_load($doi); $response = upei_roblib_ill_doi_load($doi);
if ($response->data && strpos($response->data, "Malformed DOI") !== FALSE) {
//try again without parsing the doi as sometimes parsing breaks it
$response = upei_roblib_ill_doi_load($doi, FALSE);
}
$headers = array_change_key_case($response->headers); $headers = array_change_key_case($response->headers);
if ($response->data && if ($response->data &&
strpos($headers['content-type'], 'text/html') === FALSE && strpos($headers['content-type'], 'text/html') === FALSE &&
@ -119,13 +123,15 @@ function upei_roblib_ill_doi_name_from_url($doi_url) {
* @param string $doi * @param string $doi
* A DOI to lookop. May be provided with or without the "doi:" prefix. Can * A DOI to lookop. May be provided with or without the "doi:" prefix. Can
* also pass a full DOI url (i.e, http://doi.org/10.1111/eva.12339 ). * also pass a full DOI url (i.e, http://doi.org/10.1111/eva.12339 ).
* @param bool parse
* parse the doi to remove prefix and whitespace etc.
* *
* @return object * @return object
* An object as provided by drupal_http_request(). * An object as provided by drupal_http_request().
*/ */
function upei_roblib_ill_doi_load($doi) { function upei_roblib_ill_doi_load($doi, $parse = TRUE) {
// Allows for $id to pass a DOI url string or the DOI name. // Allows for $id to pass a DOI url string or the DOI name.
$id = upei_roblib_ill_doi_name_from_url($doi); $id = $parse ? upei_roblib_ill_doi_name_from_url($doi) : $doi;
$openurl = variable_get('upei_roblib_ill_doi_openurl', 'http://www.crossref.org/openurl'); $openurl = variable_get('upei_roblib_ill_doi_openurl', 'http://www.crossref.org/openurl');
$openurl_pid = variable_get('upei_roblib_ill_doi_openurl_pid', 'user@example.com'); $openurl_pid = variable_get('upei_roblib_ill_doi_openurl_pid', 'user@example.com');
$url = url($openurl, array( $url = url($openurl, array(

Loading…
Cancel
Save