PageRenderTime 45ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/pkp/classes/citation/CitationListTokenizerFilter.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 60 lines | 19 code | 6 blank | 35 comment | 4 complexity | 323072d1e3d172e72e2290beb32cf071 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @file classes/citation/CitationListTokenizerFilter.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 CitationListTokenizerFilter
  9. * @ingroup classes_citation
  10. *
  11. * @brief Class that takes an unformatted list of citations
  12. * and returns an array of raw citation strings.
  13. */
  14. // $Id$
  15. import('filter.Filter');
  16. class CitationListTokenizerFilter extends Filter {
  17. //
  18. // Implement template methods from Filter
  19. //
  20. /**
  21. * @see Filter::supports()
  22. * @param $input mixed
  23. * @param $output mixed
  24. * @return boolean
  25. */
  26. function supports(&$input, &$output) {
  27. // Input validation
  28. if (!is_string($input)) return false;
  29. // Output validation
  30. if (is_null($output)) return true;
  31. if (!is_array($output)) return false;
  32. foreach($output as $citationString) {
  33. if (!is_string($citationString)) return false;
  34. }
  35. return true;
  36. }
  37. /**
  38. * @see Filter::process()
  39. * @param $input string
  40. * @return mixed array
  41. */
  42. function &process(&$input) {
  43. // The default implementation assumes that raw citations are
  44. // separated with line endings.
  45. // 1) Remove empty lines
  46. $input = String::regexp_replace('/[\r\n]+/s', "\n", $input);
  47. // 2) Break up at line endings
  48. $output = explode("\n", $input);
  49. // TODO: Implement more complex treatment, e.g. filtering of
  50. // number strings at the beginning of each string, etc.
  51. return $output;
  52. }
  53. }
  54. ?>