Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
CrossrefNlm30CitationSchemaFilter.inc.php
1 <?php
2 
23 import('lib.pkp.plugins.metadata.nlm30.filter.Nlm30CitationSchemaFilter');
24 import('lib.pkp.classes.filter.EmailFilterSetting');
25 
26 define('CROSSREF_WEBSERVICE_URL', 'http://www.crossref.org/openurl/');
27 
33  function CrossrefNlm30CitationSchemaFilter($filterGroup) {
34  $this->setDisplayName('CrossRef');
35 
36  // Instantiate the settings of this filter
37  $emailSetting = new EmailFilterSetting('email',
38  'metadata.filters.crossref.settings.email.displayName',
39  'metadata.filters.crossref.settings.email.validationMessage');
40  $this->addSetting($emailSetting);
41 
42  parent::Nlm30CitationSchemaFilter(
43  $filterGroup,
44  array(
45  NLM30_PUBLICATION_TYPE_JOURNAL,
46  NLM30_PUBLICATION_TYPE_CONFPROC,
47  NLM30_PUBLICATION_TYPE_BOOK,
48  NLM30_PUBLICATION_TYPE_THESIS
49  )
50  );
51  }
52 
53 
54  //
55  // Getters and Setters
56  //
61  function setEmail($email) {
62  $this->setData('email', $email);
63  }
64 
69  function getEmail() {
70  return $this->getData('email');
71  }
72 
73 
74  //
75  // Implement template methods from PersistableFilter
76  //
80  function getClassName() {
81  return 'lib.pkp.plugins.citationLookup.crossref.filter.CrossrefNlm30CitationSchemaFilter';
82  }
83 
84 
85  //
86  // Implement template methods from Filter
87  //
93  function &process(&$citationDescription) {
94  $nullVar = null;
95 
96  $email = $this->getEmail();
97  assert(!empty($email));
98  $searchParams = array(
99  'pid' => $email,
100  'noredirect' => 'true',
101  'format' => 'unixref'
102  );
103 
104  $doi = $citationDescription->getStatement('pub-id[@pub-id-type="doi"]');
105  if (!empty($doi)) {
106  // Directly look up the DOI with OpenURL 0.1.
107  $searchParams['id'] = 'doi:'.$doi;
108  } else {
109  // Use OpenURL meta-data to search for the entry.
110  if (is_null($openurl10Metadata = $this->_prepareOpenurl10Search($citationDescription))) return $nullVar;
111  $searchParams += $openurl10Metadata;
112  }
113 
114  // Call the CrossRef web service
115  if (is_null($resultXml =& $this->callWebService(CROSSREF_WEBSERVICE_URL, $searchParams, XSL_TRANSFORMER_DOCTYPE_STRING)) || String::substr(trim($resultXml), 0, 6) == '<html>') return $nullVar;
116 
117  // Remove default name spaces from XML as CrossRef doesn't
118  // set them reliably and element names are unique anyway.
119  $resultXml = String::regexp_replace('/ xmlns="[^"]+"/', '', $resultXml);
120 
121  // Transform and process the web service result
122  if (is_null($metadata =& $this->transformWebServiceResults($resultXml, dirname(__FILE__).DIRECTORY_SEPARATOR.'crossref.xsl'))) return $nullVar;
123 
124  return $this->getNlm30CitationDescriptionFromMetadataArray($metadata);
125  }
126 
127 
128  //
129  // Private methods
130  //
136  function &_prepareOpenurl10Search(&$citationDescription) {
137  $nullVar = null;
138 
139  // Crosswalk to OpenURL.
140  import('lib.pkp.plugins.metadata.nlm30.filter.Nlm30CitationSchemaOpenurl10CrosswalkFilter');
141  $nlm30Openurl10Filter = new Nlm30CitationSchemaOpenurl10CrosswalkFilter();
142  if (is_null($openurl10Citation =& $nlm30Openurl10Filter->execute($citationDescription))) return $nullVar;
143 
144  // Prepare the search.
145  $searchParams = array(
146  'url_ver' => 'Z39.88-2004'
147  );
148 
149  // Configure the meta-data schema.
150  $openurl10CitationSchema =& $openurl10Citation->getMetadataSchema();
151  switch(true) {
152  case is_a($openurl10CitationSchema, 'Openurl10JournalSchema'):
153  $searchParams['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:journal';
154  break;
155 
156  case is_a($openurl10CitationSchema, 'Openurl10BookSchema'):
157  $searchParams['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:book';
158  break;
159 
160  case is_a($openurl10CitationSchema, 'Openurl10DissertationSchema'):
161  $searchParams['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:dissertation';
162  break;
163 
164  default:
165  assert(false);
166  }
167 
168  // Add all OpenURL meta-data to the search parameters.
169  // FIXME: Implement a looping search like for other lookup services.
170  $searchProperties = array(
171  'aufirst', 'aulast', 'btitle', 'jtitle', 'atitle', 'issn',
172  'artnum', 'date', 'volume', 'issue', 'spage', 'epage'
173  );
174  foreach ($searchProperties as $property) {
175  if ($openurl10Citation->hasStatement($property)) {
176  $searchParams['rft.'.$property] = $openurl10Citation->getStatement($property);
177  }
178  }
179 
180  return $searchParams;
181  }
182 }
183 ?>
static substr($string, $start, $length=false)
Definition: String.inc.php:187
Filter that uses the Crossref web service to identify a DOI and corresponding meta-data for a given N...
static regexp_replace($pattern, $replacement, $subject, $limit=-1)
Definition: String.inc.php:377
setDisplayName($displayName)
Definition: Filter.inc.php:140
& transformWebServiceResults(&$xmlResult, $xslFileName)
& getData($key, $locale=null)
Filter that converts from NLM citation to OpenURL schemas.
setData($key, $value, $locale=null)
Abstract base class for all filters that transform NLM citation metadata descriptions.
Class that describes a configurable filter setting which must be an email.
& getNlm30CitationDescriptionFromMetadataArray(&$metadataArray)
& callWebService($url, &$params, $returnType=XSL_TRANSFORMER_DOCTYPE_DOM, $method= 'GET')