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

/lib/pkp/classes/citation/parser/freecite/FreeciteRawCitationNlmCitationSchemaFilter.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 76 lines | 25 code | 14 blank | 37 comment | 6 complexity | 42c0ad1a65299ec5d3699468db46a355 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @defgroup citation_parser_freecite
  4. */
  5. /**
  6. * @file classes/citation/parser/freecite/FreeciteRawCitationNlmCitationSchemaFilter.inc.php
  7. *
  8. * Copyright (c) 2000-2012 John Willinsky
  9. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  10. *
  11. * @class FreeciteRawCitationNlmCitationSchemaFilter
  12. * @ingroup citation_parser_freecite
  13. *
  14. * @brief Parsing filter implementation that uses the Freecite web service.
  15. *
  16. */
  17. // $Id$
  18. import('citation.NlmCitationSchemaFilter');
  19. define('FREECITE_WEBSERVICE', 'http://freecite.library.brown.edu/citations/create');
  20. class FreeciteRawCitationNlmCitationSchemaFilter extends NlmCitationSchemaFilter {
  21. /*
  22. * Constructor
  23. */
  24. function FreeciteRawCitationNlmCitationSchemaFilter() {
  25. parent::NlmCitationSchemaFilter();
  26. }
  27. //
  28. // Implement template methods from Filter
  29. //
  30. /**
  31. * @see Filter::supports()
  32. * @param $input mixed
  33. * @param $output mixed
  34. * @return boolean
  35. */
  36. function supports(&$input, &$output) {
  37. return parent::supports($input, $output, true);
  38. }
  39. /**
  40. * @see Filter::process()
  41. * @param $citationString string
  42. * @return MetadataDescription
  43. */
  44. function &process($citationString) {
  45. $nullVar = null;
  46. // Freecite requires a post request
  47. $postData = array('citation' => $citationString);
  48. if (is_null($resultDOM = $this->callWebService(FREECITE_WEBSERVICE, $postData, XSL_TRANSFORMER_DOCTYPE_DOM, 'POST'))) return $nullVar;
  49. // Transform the result into an array of meta-data
  50. if (is_null($metadata =& $this->transformWebServiceResults($resultDOM, dirname(__FILE__).DIRECTORY_SEPARATOR.'freecite.xsl'))) return $nullVar;
  51. // Extract a publisher from the place string if possible
  52. $metadata =& $this->fixPublisherNameAndLocation($metadata);
  53. // Convert article title to source for dissertations
  54. if (isset($metadata['[@publication-type]']) && $metadata['[@publication-type]'] == NLM_PUBLICATION_TYPE_THESIS && isset($metadata['article-title'])) {
  55. $metadata['source'] = $metadata['article-title'];
  56. unset($metadata['article-title']);
  57. }
  58. unset($metadata['raw_string']);
  59. return $this->addMetadataArrayToNlmCitationDescription($metadata);
  60. }
  61. }
  62. ?>