Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
CitationListTokenizerFilter.inc.php
1 <?php
2 
17 import('lib.pkp.classes.filter.Filter');
18 
24  $this->setDisplayName('Split a reference list into separate citations');
25 
26  parent::Filter('primitive::string', 'primitive::string[]');
27  }
28 
29  //
30  // Implement template methods from Filter
31  //
37  function &process(&$input) {
38  // The default implementation assumes that raw citations are
39  // separated with line endings.
40  // 1) Remove empty lines and normalize line endings.
41  $input = String::regexp_replace('/[\r\n]+/s', "\n", $input);
42  // 2) Remove trailing/leading line breaks.
43  $input = trim($input, "\n");
44  // 3) Break up at line endings.
45  if (empty($input)) {
46  $citations = array();
47  } else {
48  $citations = explode("\n", $input);
49  }
50  // 4) Remove numbers from the beginning of each citation.
51  foreach($citations as $index => $citation) {
52  $citations[$index] = String::regexp_replace('/^\s*[\[#]?[0-9]+[.)\]]?\s*/', '', $citation);
53  }
54 
55  return $citations;
56  }
57 }
58 ?>
static regexp_replace($pattern, $replacement, $subject, $limit=-1)
Definition: String.inc.php:377
setDisplayName($displayName)
Definition: Filter.inc.php:140
Class that provides the basic template for a filter. Filters are generic data processors that take in...
Definition: Filter.inc.php:78
Class that takes an unformatted list of citations and returns an array of raw citation strings...