PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/pkp/classes/citation/lookup/isbndb/IsbndbIsbnNlmCitationSchemaFilter.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 83 lines | 30 code | 14 blank | 39 comment | 3 complexity | 4ba842cd35fb97316ee376fdab7a5c27 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @file classes/citation/lookup/isbndb/IsbndbIsbnNlmCitationSchemaFilter.inc.php
  4. *
  5. * Copyright (c) 2000-2012 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class IsbndbIsbnNlmCitationSchemaFilter
  9. * @ingroup citation_lookup_isbndb
  10. *
  11. * @brief Filter that uses the ISBNdb web service to look up
  12. * an ISBN and create a NLM citation description from the result.
  13. */
  14. // $Id$
  15. import('citation.lookup.isbndb.IsbndbNlmCitationSchemaFilter');
  16. class IsbndbIsbnNlmCitationSchemaFilter extends IsbndbNlmCitationSchemaFilter {
  17. /*
  18. * Constructor
  19. * @param $apiKey string
  20. */
  21. function IsbndbIsbnNlmCitationSchemaFilter($apiKey) {
  22. parent::IsbndbNlmCitationSchemaFilter($apiKey);
  23. }
  24. //
  25. // Implement template methods from Filter
  26. //
  27. /**
  28. * @see Filter::supports()
  29. * @param $input mixed
  30. * @param $output mixed
  31. * @return boolean
  32. */
  33. function supports(&$input, &$output) {
  34. if (!$this->isValidIsbn($input)) return false;
  35. return parent::supports($input, $output, true);
  36. }
  37. /**
  38. * @see Filter::process()
  39. * @param $isbn string
  40. * @return MetadataDescription a looked up citation description
  41. * or null if the filter fails
  42. */
  43. function &process($isbn) {
  44. $nullVar = null;
  45. // Instantiate the web service request
  46. $lookupParams = array(
  47. 'access_key' => $this->getApiKey(),
  48. 'index1' => 'isbn',
  49. 'results' => 'details,authors',
  50. 'value1' => $isbn
  51. );
  52. // Call the web service
  53. if (is_null($resultDOM =& $this->callWebService(ISBNDB_WEBSERVICE_URL, $lookupParams))) return $nullVar;
  54. // Transform and pre-process the web service result
  55. if (is_null($metadata =& $this->transformWebServiceResults($resultDOM, dirname(__FILE__).DIRECTORY_SEPARATOR.'isbndb.xsl'))) return $nullVar;
  56. // Extract place and publisher from the combined entry.
  57. $metadata['publisher-loc'] = String::trimPunctuation(String::regexp_replace('/^(.+):.*/', '\1', $metadata['place-publisher']));
  58. $metadata['publisher-name'] = String::trimPunctuation(String::regexp_replace('/.*:([^,]+),?.*/', '\1', $metadata['place-publisher']));
  59. unset($metadata['place-publisher']);
  60. // Reformat the publication date
  61. $metadata['date'] = String::regexp_replace('/^[^\d{4}]+(\d{4}).*/', '\1', $metadata['date']);
  62. // Clean non-numerics from ISBN
  63. $metadata['isbn'] = String::regexp_replace('/[^\dX]*/', '', $isbn);
  64. // Set the publicationType
  65. $metadata['[@publication-type]'] = NLM_PUBLICATION_TYPE_BOOK;
  66. return $this->addMetadataArrayToNlmCitationDescription($metadata);
  67. }
  68. }
  69. ?>