1
|
<?php
|
2
|
|
3
|
defined('_JEXEC') or die('Access denied');
|
4
|
|
5
|
jimport('joomla.application.component.model');
|
6
|
jimport('joomla.http.http');
|
7
|
jimport('joomla.log.log');
|
8
|
|
9
|
// This model manages claims.
|
10
|
class OpenAireModelClaimSearch extends JModelItem {
|
11
|
const SELECTED_PROJECTS = 'selectedProjects';
|
12
|
const SELECTED_CONCEPTS = 'selectedConcepts';
|
13
|
const SELECTED_PUBLICATIONS = 'selectedPublications';
|
14
|
const SEARCH_DOI_CACHE_ID = 'search.doi';
|
15
|
const SEARCH_DATASET_CACHE_ID = 'search.datacite';
|
16
|
const SEARCH_ORCID_CACHE_ID = 'search.orcid';
|
17
|
const CLAIMED_PUBLICATIONS_CACHE_ID = 'claimed.publications';
|
18
|
const CACHE_GROUP = 'openaire.claim';
|
19
|
const CROSSREF_URL = 'http://www.crossref.org/openurl?noredirect=true&pid=antleb%40di.uoa.gr&format=unixref&id=';
|
20
|
const CROSSREF_API_DOI = 'http://api.crossref.org/works/';
|
21
|
const CROSSREF_API_KEYWORD = 'http://api.crossref.org/works?query=';
|
22
|
const DOI_SCHEME = 'doi:';
|
23
|
const DATACITE_URL = 'http://data.datacite.org/application/rdf+xml/';
|
24
|
const DATACITE_URL_KEYWORD = 'http://search.datacite.org/api?q=';
|
25
|
const DATACITE_URL_KEYWORD_REST = '&fl=doi,title,creator,publisher,created&wt=xml';
|
26
|
const DOI_URL = 'http://dx.doi.org/';
|
27
|
const ORCID_URL_PREFIX = 'http://pub.orcid.org/';
|
28
|
const ORCID_URL_PUBLICATIONS_SUFFIX = '/orcid-works';
|
29
|
const ORCID_URL_AUTHOR_SUFFIX = '/orcid-bio';
|
30
|
const HTTP_OK = 200;
|
31
|
const HTTP_NOT_FOUND = 404;
|
32
|
const DOI = 'doi';
|
33
|
const ORCID = 'orcid';
|
34
|
const DATACITE = 'datacite';
|
35
|
const RELATION = 'rels2actions';
|
36
|
const DMF = 'dmf2actions';
|
37
|
const UNDETERMINED = 'Undetermined';
|
38
|
const LOG = 'openaire';
|
39
|
//claim modes
|
40
|
const CLAIM = 'claim';
|
41
|
const CLAIMINLINE = 'claiminline';
|
42
|
const CLAIMINLINE2 = 'claiminline2';
|
43
|
|
44
|
private $cache;
|
45
|
private $http;
|
46
|
// Construct a new OpenAireModelClaimSearch.
|
47
|
// $configuration the configuration to use
|
48
|
public function __construct($configuration) {
|
49
|
parent :: __construct($configuration);
|
50
|
$this -> cache = JCache :: getInstance();
|
51
|
$this -> http = new JHttp();
|
52
|
}
|
53
|
private function _parseMultipleJsonDOIs($message){
|
54
|
$publications=array();
|
55
|
if(isset($message -> items)){
|
56
|
foreach ($message -> items as $item) {
|
57
|
$publication= $this ->_parseJsonDOI($item);
|
58
|
if($publication!==null){
|
59
|
$publications[]=$publication;
|
60
|
}
|
61
|
}
|
62
|
}
|
63
|
return $publications;
|
64
|
}
|
65
|
private function _parseJsonDOI($message) {
|
66
|
$publication = new JObject();
|
67
|
$publication -> id = isset($message -> DOI)?$message -> DOI:NULL;
|
68
|
$publication -> source = self :: DOI;
|
69
|
$publication -> url = isset($message -> URL)?$message -> URL:NULL;
|
70
|
$publication -> accessMode = NULL;
|
71
|
$publication -> datasources = array();
|
72
|
$publication -> title = (isset($message -> title) && isset($message -> title[0]))?$message -> title[0]:NULL;
|
73
|
$publication -> authors = array();
|
74
|
if(isset($message -> author)){
|
75
|
foreach ($message -> author as $author_item) {
|
76
|
$author = new JObject();
|
77
|
$author -> id = NULL;
|
78
|
$author -> lastName = isset($author_item-> family) ? trim($author_item -> family):NULL;
|
79
|
$author -> firstName = isset($author_item -> given) ? trim($author_item -> given):NULL;
|
80
|
$author -> fullName = NULL;
|
81
|
if (($author -> id != NULL) || ($author -> lastName != NULL) || ($author-> firstName != NULL) || ($author -> fullName != NULL))
|
82
|
$publication -> authors[] = $author;
|
83
|
}
|
84
|
}
|
85
|
$publication -> publisher =isset($message -> publisher)?$message -> publisher:NULL;
|
86
|
$publication -> year = (isset($message -> issued )&&isset($message -> issued -> date_parts[0]))?
|
87
|
((isset($message -> issued -> date_parts[0][0]))?$message -> issued -> date_parts[0][0]:NULL):NULL;
|
88
|
$publication -> language = NULL;
|
89
|
$publication -> projects = array();
|
90
|
$publication -> embargoEndDate = NULL;
|
91
|
$publication -> description = NULL;
|
92
|
if (($publication -> id != NULL)&&( ($publication -> url != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> year != NULL))) {
|
93
|
return $publication;
|
94
|
}
|
95
|
return NULL;
|
96
|
|
97
|
}
|
98
|
|
99
|
// Search for a dataset DOI using caching if enabled.
|
100
|
// $doi the dataset DOI to search for
|
101
|
// return a result (object) containing datasets and total
|
102
|
private function _searchDataCiteWithDoi($doi) {
|
103
|
try {
|
104
|
$request = self :: DATACITE_URL . urlencode(trim($doi));
|
105
|
JLog :: add('Requesting ' . $request, JLog :: INFO, self :: LOG);
|
106
|
$time = microtime(TRUE);
|
107
|
$response = $this -> http -> get($request);
|
108
|
JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
109
|
if ($response== NULL)
|
110
|
throw new Exception('no HTTP response');
|
111
|
/*if ($response -> code == self :: HTTP_NOT_FOUND) { // no dataset found; just return empty result
|
112
|
$result = new JObject();
|
113
|
$result -> datasets = array();
|
114
|
$result -> totalDatasets = 0;
|
115
|
JLog :: add('Retrieved 0 DataCite records in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
116
|
return $result;
|
117
|
}*/
|
118
|
if ($response -> code != self :: HTTP_OK)
|
119
|
throw new Exception('HTTP response code ' . $response -> code);
|
120
|
$document = new DOMDocument();
|
121
|
$document -> recover = TRUE;
|
122
|
if ($document -> loadXML(trim($response -> body)) == FALSE)
|
123
|
throw new Exception('invalid XML response');
|
124
|
$xpath = new DOMXPath($document);
|
125
|
if ((($descriptionNodes = $xpath -> query('/rdf:RDF/rdf:Description')) == FALSE) || (($descriptionNode = $descriptionNodes -> item(0)) == NULL))
|
126
|
throw new Exception('error parsing DataCite record');
|
127
|
if (($idNodes = $xpath -> query('./j.0:identifier', $descriptionNode)) == FALSE)
|
128
|
throw new Exception('error parsing DataCite record');
|
129
|
if (($titleNodes = $xpath -> query('./j.0:title', $descriptionNode)) == FALSE)
|
130
|
throw new Exception('error parsing DataCite record');
|
131
|
if (($authorNodes = $xpath -> query('./j.0:creator', $descriptionNode)) == FALSE)
|
132
|
throw new Exception('error parsing DataCite record');
|
133
|
if (($yearNodes = $xpath -> query('./j.0:date', $descriptionNode)) == FALSE)
|
134
|
throw new Exception('error parsing DataCite record');
|
135
|
if (($publisherNodes = $xpath -> query('./j.0:publisher', $descriptionNode)) == FALSE)
|
136
|
throw new Exception('error parsing DataCite record');
|
137
|
$dataset = new JObject();
|
138
|
$dataset -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue);
|
139
|
$dataset -> source = self :: DATACITE;
|
140
|
$dataset -> url = self :: DOI_URL . urlencode(trim($doi));
|
141
|
$dataset -> accessMode = NULL;
|
142
|
$dataset -> datasources = array();
|
143
|
$dataset -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue);
|
144
|
$dataset -> authors = array();
|
145
|
$dataset -> publisher = (($publisherNode = $publisherNodes -> item(0)) == NULL) ? NULL : trim($publisherNode -> nodeValue);
|
146
|
$dataset -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue));
|
147
|
$dataset -> language = NULL;
|
148
|
$dataset -> projects = array();
|
149
|
$dataset -> embargoEndDate = NULL;
|
150
|
$dataset -> description = NULL;
|
151
|
foreach ($authorNodes as $authorNode) {
|
152
|
$author = new JObject();
|
153
|
$author -> id = NULL;
|
154
|
$author -> lastName = NULL;
|
155
|
$author -> firstName = NULL;
|
156
|
$author -> fullName = trim($authorNode -> nodeValue);
|
157
|
if ($author -> fullName != NULL)
|
158
|
$dataset -> authors[] = $author;
|
159
|
}
|
160
|
/*$result = new JObject();
|
161
|
$result -> datasets = array();
|
162
|
$result -> totalDatasets = 0;
|
163
|
if (($dataset -> id != NULL) || ($dataset -> url != NULL) || ($dataset -> title != NULL) || ($dataset -> authors != NULL) || ($dataset -> year != NULL)) {
|
164
|
$result -> datasets[] = $dataset;
|
165
|
$result -> totalDatasets = 1;
|
166
|
}*/
|
167
|
JLog :: add('Retrieved DataCite record in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
168
|
return $dataset;
|
169
|
} catch (Exception $e) {
|
170
|
JLog :: add('Error performing DataCite search (doi: ' . $doi . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
171
|
return NULL;
|
172
|
}
|
173
|
}
|
174
|
private function _searchDataCite($doi, $page, $size) {
|
175
|
$result = new JObject();
|
176
|
$result->datasets = array();
|
177
|
$result->totalPublications = 0;
|
178
|
$result->totalDatasets = 0;
|
179
|
try {
|
180
|
$dois = explode(" ", preg_replace('/\s+/', ' ',$doi));
|
181
|
|
182
|
$unique_dois =array_slice( array_unique($dois),0,10);
|
183
|
$pattern1 = '#\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'<>])\S)+)\b#';
|
184
|
$pattern2 = '#\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'<>])[[:graph:]])+)\b#';
|
185
|
if (preg_match($pattern1, $unique_dois[0]) || preg_match($pattern2, $unique_dois[0])) {
|
186
|
if(count($dois)>10){
|
187
|
$result = new JObject();
|
188
|
$result->datasets = array();
|
189
|
$result->totalPublications = 0;
|
190
|
$result->totalDatasets = '-';
|
191
|
$result->maxDoisExceeded = true;
|
192
|
return $result;
|
193
|
}
|
194
|
JLog :: add('It;s a dataset DOI!!!!!!!!! ' . $dois[0], JLog :: INFO, self :: LOG);
|
195
|
JLog :: add('Searching for DOIs in Datacite', JLog :: INFO, self :: LOG);
|
196
|
foreach ($unique_dois as $doi_) {
|
197
|
JLog :: add('DOI::: ' . $doi_, JLog :: INFO, self :: LOG);
|
198
|
$dataset = $this->_searchDataCiteWithDoi($doi_);
|
199
|
if ($dataset != null) {
|
200
|
$result->datasets[] = $dataset;
|
201
|
}
|
202
|
}
|
203
|
}else{
|
204
|
|
205
|
JLog :: add('It;sNOOOOOOOT a dataset DOI!!!!!!!!! ' . $dois[0], JLog :: INFO, self :: LOG);
|
206
|
}
|
207
|
$result->totalDatasets = count($result->datasets);
|
208
|
if($result->totalDatasets!==0){
|
209
|
return $result;
|
210
|
}
|
211
|
$request = self :: DATACITE_URL_KEYWORD. urlencode(trim($doi)).self :: DATACITE_URL_KEYWORD_REST."&rows=".$size."&start=".($page-1)*$size;
|
212
|
JLog :: add('Requesting ' . $request, JLog :: INFO, self :: LOG);
|
213
|
$time = microtime(TRUE);
|
214
|
$response = $this -> http -> get($request);
|
215
|
JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
216
|
if ($response== NULL)
|
217
|
throw new Exception('no HTTP response');
|
218
|
if ($response -> code == self :: HTTP_NOT_FOUND) { // no dataset found; just return empty result
|
219
|
$result = new JObject();
|
220
|
//$result -> datasets = array();
|
221
|
$result -> totalDatasets = 0;
|
222
|
$result -> totalPublications = 0;
|
223
|
JLog :: add('Retrieved 0 DataCite records in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
224
|
return $result;
|
225
|
}
|
226
|
if ($response -> code != self :: HTTP_OK)
|
227
|
throw new Exception('HTTP response code ' . $response -> code);
|
228
|
$document = new DOMDocument();
|
229
|
$document -> recover = TRUE;
|
230
|
if ($document -> loadXML(trim($response -> body)) == FALSE)
|
231
|
throw new Exception('invalid XML response');
|
232
|
$xpath = new DOMXPath($document);
|
233
|
if ((($numFoundNodes = $xpath -> query('/response/result[@name = "response"]/@numFound')) == FALSE) || (($numFoundNode = $numFoundNodes -> item(0)) == NULL))
|
234
|
throw new Exception('error parsing DataCite record');
|
235
|
$numFound=((($numFoundNode)) == NULL) ? NULL : trim($numFoundNode -> nodeValue);
|
236
|
if ((($resultNodes = $xpath -> query('/response/result/doc')) == FALSE) || (($resultNode = $resultNodes -> item(0)) == NULL))
|
237
|
throw new Exception('error parsing DataCite record');
|
238
|
foreach ($resultNodes as $resultNode) {
|
239
|
if (($idNodes = $xpath -> query('./str[@name = "doi"]/text()', $resultNode)) == FALSE)
|
240
|
throw new Exception('error parsing DataCite record');
|
241
|
if (($titleNodes = $xpath -> query('./arr[@name="title"]/str/text()', $resultNode)) == FALSE)
|
242
|
throw new Exception('error parsing DataCite record');
|
243
|
if (($authorNodes = $xpath -> query('./arr[@name = "creator"]/str/text()', $resultNode)) == FALSE)
|
244
|
throw new Exception('error parsing DataCite record');
|
245
|
if (($publisherNodes = $xpath -> query('./str[@name = "publisher"]/text()', $resultNode)) == FALSE)
|
246
|
throw new Exception('error parsing DataCite record');
|
247
|
if (($yearNodes = $xpath -> query('./date[@name = "created"]/text()', $resultNode)) == FALSE)
|
248
|
throw new Exception('error parsing DataCite record');
|
249
|
$dataset = new JObject();
|
250
|
$dataset -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue);
|
251
|
$dataset -> source = self :: DATACITE;
|
252
|
$dataset -> url = self :: DOI_URL . urlencode(trim($dataset -> id));
|
253
|
$dataset -> accessMode = NULL;
|
254
|
$dataset -> datasources = array();
|
255
|
$dataset -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue);
|
256
|
$dataset -> authors = array();
|
257
|
$dataset -> publisher = (($publisherNode = $publisherNodes -> item(0)) == NULL) ? NULL : trim($publisherNode -> nodeValue);
|
258
|
$dataset -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : substr(trim($yearNode -> nodeValue),0,4);
|
259
|
$dataset -> language = NULL;
|
260
|
$dataset -> projects = array();
|
261
|
$dataset -> embargoEndDate = NULL;
|
262
|
$dataset -> description = NULL;
|
263
|
foreach ($authorNodes as $authorNode) {
|
264
|
$authorName= $authorNode -> nodeValue;
|
265
|
$author = new JObject();
|
266
|
$author -> id = NULL;
|
267
|
$author -> lastName = NULL;
|
268
|
$author -> firstName = NULL;
|
269
|
$author -> fullName = trim($authorName );
|
270
|
if ($author -> fullName != NULL)
|
271
|
$dataset -> authors[] = $author;
|
272
|
}
|
273
|
|
274
|
if (($dataset -> id != NULL) || ($dataset -> url != NULL) || ($dataset -> title != NULL) || ($dataset -> authors != NULL) || ($dataset -> year != NULL)) {
|
275
|
$result -> datasets[] = $dataset;
|
276
|
|
277
|
}
|
278
|
}
|
279
|
//
|
280
|
$result -> totalDatasets =$numFound ;
|
281
|
/* if(isset($size)&&isset($page)){
|
282
|
$result -> datasets = array_slice($result -> datasets, ($page - 1) * $size, $size);
|
283
|
}*/
|
284
|
JLog :: add('Retrieved DataCite '.count($result -> datasets).' records in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
285
|
$result -> totalPublications = 0;
|
286
|
return $result;
|
287
|
} catch (Exception $e) {
|
288
|
JLog :: add('Error performing DataCite search (doi: ' . $doi . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
289
|
$result = new JObject();
|
290
|
//$result -> datasets = array();
|
291
|
$result -> totalPublications = 0;
|
292
|
$result -> totalDatasets = 0;
|
293
|
return $result;
|
294
|
}
|
295
|
}
|
296
|
|
297
|
// Parse a journal out of a DOI record.
|
298
|
// $doi the DOI of the record
|
299
|
// $xpath the DOMXPath to parse
|
300
|
// $journalNode the journal node to start from
|
301
|
// return a result (object) containing publications and total
|
302
|
private function parseJournal($doi, $xpath, $journalNode) {
|
303
|
if (($resourceNodes = $xpath -> query('./journal_article/doi_data/resource', $journalNode)) == FALSE)
|
304
|
throw new Exception('error parsing DOI record');
|
305
|
if (($titleNodes = $xpath -> query('./journal_article/titles/title', $journalNode)) == FALSE)
|
306
|
throw new Exception('error parsing DOI record');
|
307
|
if (($contributorNodes = $xpath -> query('./journal_article/contributors', $journalNode)) == FALSE)
|
308
|
throw new Exception('error parsing DOI record');
|
309
|
if (($yearNodes = $xpath -> query('./journal_article/publication_date/year', $journalNode)) == FALSE)
|
310
|
throw new Exception('error parsing DOI record');
|
311
|
$publication = new JObject();
|
312
|
$publication -> id = $doi;
|
313
|
$publication -> source = self :: DOI;
|
314
|
$publication -> url = (($resourceNode = $resourceNodes -> item(0)) == NULL) ? NULL : trim($resourceNode -> nodeValue);
|
315
|
$publication -> accessMode = NULL;
|
316
|
$publication -> datasources = array();
|
317
|
$publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue);
|
318
|
$publication -> authors = $this -> parseContributors($xpath, $contributorNodes);
|
319
|
$publication -> publisher = NULL;
|
320
|
$publication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue));
|
321
|
$publication -> language = NULL;
|
322
|
$publication -> projects = array();
|
323
|
$publication -> embargoEndDate = NULL;
|
324
|
$publication -> description = NULL;
|
325
|
$result = new JObject();
|
326
|
$result -> publications = array();
|
327
|
$result -> totalPublications = 0;
|
328
|
if (($publication -> id != NULL) || ($publication -> url != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> year != NULL)) {
|
329
|
$result -> publications[] = $publication;
|
330
|
$result -> totalPublications = 1;
|
331
|
}
|
332
|
return $result;
|
333
|
}
|
334
|
|
335
|
// Parse a book out of a DOI record.
|
336
|
// $doi the DOI of the record
|
337
|
// $xpath the DOMXPath to parse
|
338
|
// $bookNode the book node to start from
|
339
|
// return a result (object) containing publications and total
|
340
|
private function parseBook($doi, $xpath, $bookNode) {
|
341
|
if (($bookMetadataNodes = $xpath -> query('./book_metadata', $bookNode)) == FALSE)
|
342
|
throw new Exception('error parsing DOI record');
|
343
|
if (($bookSeriesMetadataNodes = $xpath -> query('./book_series_metadata', $bookNode)) == FALSE)
|
344
|
throw new Exception('error parsing DOI record');
|
345
|
if (($bookSetMetadataNodes = $xpath -> query('./book_set_metadata', $bookNode)) == FALSE)
|
346
|
throw new Exception('error parsing DOI record');
|
347
|
if ((($metadataNode = $bookMetadataNodes -> item(0)) == NULL) && (($metadataNode = $bookSeriesMetadataNodes -> item(0)) == NULL) && (($metadataNode = $bookSetMetadataNodes -> item(0)) == NULL))
|
348
|
throw new Exception('error parsing DOI record');
|
349
|
if (($resourceNodes = $xpath -> query('./doi_data/resource', $metadataNode)) == FALSE)
|
350
|
throw new Exception('error parsing DOI record');
|
351
|
if (($titleNodes = $xpath -> query('./titles/title', $metadataNode)) == FALSE)
|
352
|
throw new Exception('error parsing DOI record');
|
353
|
if (($contributorNodes = $xpath -> query('./contributors', $metadataNode)) == FALSE)
|
354
|
throw new Exception('error parsing DOI record');
|
355
|
if (($yearNodes = $xpath -> query('./publication_date/year', $metadataNode)) == FALSE)
|
356
|
throw new Exception('error parsing DOI record');
|
357
|
$publication = new JObject();
|
358
|
$publication -> id = $doi;
|
359
|
$publication -> source = self :: DOI;
|
360
|
$publication -> url = (($resourceNode = $resourceNodes -> item(0)) == NULL) ? NULL : trim($resourceNode -> nodeValue);
|
361
|
$publication -> accessMode = NULL;
|
362
|
$publication -> datasources = array();
|
363
|
$publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue);
|
364
|
$publication -> authors = $this -> parseContributors($xpath, $contributorNodes);
|
365
|
$publication -> publisher = NULL;
|
366
|
$publication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue));
|
367
|
$publication -> language = NULL;
|
368
|
$publication -> projects = array();
|
369
|
$publication -> embargoEndDate = NULL;
|
370
|
$publication -> description = NULL;
|
371
|
$result = new JObject();
|
372
|
$result -> publications = array();
|
373
|
$result -> totalPublications = 0;
|
374
|
if (($publication -> id != NULL) || ($publication -> url != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> year != NULL)) {
|
375
|
$result -> publications[] = $publication;
|
376
|
$result -> totalPublications = 1;
|
377
|
}
|
378
|
return $result;
|
379
|
}
|
380
|
// Parse a Conference out of a DOI record.
|
381
|
// $doi the DOI of the record
|
382
|
// $xpath the DOMXPath to parse
|
383
|
// $conferenceNode the book node to start from
|
384
|
// return a result (object) containing publications and total
|
385
|
private function parseConference($doi, $xpath, $conferenceNode) {
|
386
|
|
387
|
if (($eventMetadata = $xpath -> query('./event_metadata', $conferenceNode)) == FALSE)
|
388
|
throw new Exception('error parsing DOI record');
|
389
|
if (($proceedingsMetadata = $xpath -> query('./proceedings_metadata', $conferenceNode)) == FALSE)
|
390
|
throw new Exception('error parsing DOI record');
|
391
|
if (($conferencePaperNodes = $xpath -> query('./conference_paper', $conferenceNode)) == FALSE)
|
392
|
throw new Exception('error parsing DOI record');
|
393
|
if (($resourceNodes = $xpath -> query('./conference_paper/doi_data/resource', $conferenceNode)) == FALSE)
|
394
|
throw new Exception('error parsing DOI record');
|
395
|
if (($titleNodes = $xpath -> query('./conference_paper/titles/title', $conferenceNode)) == FALSE)
|
396
|
throw new Exception('error parsing DOI record');
|
397
|
if (($contributorNodes = $xpath -> query('./conference_paper/contributors', $conferenceNode)) == FALSE)
|
398
|
throw new Exception('error parsing DOI record');
|
399
|
if (($yearNodes = $xpath -> query('./conference_paper/publication_date/year', $conferenceNode)) == FALSE)
|
400
|
throw new Exception('error parsing DOI record');
|
401
|
$publication = new JObject();
|
402
|
$publication -> id = $doi;
|
403
|
$publication -> source = self :: DOI;
|
404
|
$publication -> url = (($resourceNode = $resourceNodes -> item(0)) == NULL) ? NULL : trim($resourceNode -> nodeValue);
|
405
|
$publication -> accessMode = NULL;
|
406
|
$publication -> datasources = array();
|
407
|
$publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue);
|
408
|
$publication -> authors = $this -> parseContributors($xpath, $contributorNodes);
|
409
|
$publication -> publisher = NULL;
|
410
|
$publication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue));
|
411
|
$publication -> language = NULL;
|
412
|
$publication -> projects = array();
|
413
|
$publication -> embargoEndDate = NULL;
|
414
|
$publication -> description = NULL;
|
415
|
$result = new JObject();
|
416
|
$result -> publications = array();
|
417
|
$result -> totalPublications = 0;
|
418
|
if (($publication -> id != NULL) || ($publication -> url != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> year != NULL)) {
|
419
|
$result -> publications[] = $publication;
|
420
|
$result -> totalPublications = 1;
|
421
|
}
|
422
|
return $result;
|
423
|
}
|
424
|
// Parse contributor metadata out of a DOI record.
|
425
|
// $doi the DOI of the record
|
426
|
// $xpath the DOMXPath to parse
|
427
|
// $contributorNodes the contributor nodes to start from
|
428
|
// return authors (array)
|
429
|
private function parseContributors($xpath, $contributorNodes) {
|
430
|
$authors = array();
|
431
|
foreach ($contributorNodes as $contributorNode) {
|
432
|
if (($personNameNodes = $xpath -> query('./person_name', $contributorNode)) == FALSE)
|
433
|
throw new Exception('error parsing DOI record');
|
434
|
if (($organizationNodes = $xpath -> query('./organization', $contributorNode)) == FALSE)
|
435
|
throw new Exception('error parsing DOI record');
|
436
|
foreach ($personNameNodes as $personNameNode) {
|
437
|
if (($surnameNodes = $xpath -> query('./surname', $personNameNode)) == FALSE)
|
438
|
throw new Exception('error parsing DOI record');
|
439
|
if (($givenNameNodes = $xpath -> query('./given_name', $personNameNode)) == FALSE)
|
440
|
throw new Exception('error parsing DOI record');
|
441
|
$author = new JObject();
|
442
|
$author -> id = NULL;
|
443
|
$author -> lastName = (($surnameNode = $surnameNodes -> item(0)) == NULL) ? NULL : trim($surnameNode -> nodeValue);
|
444
|
$author -> firstName = (($givenNameNode = $givenNameNodes -> item(0)) == NULL) ? NULL : trim($givenNameNode -> nodeValue);
|
445
|
$author -> fullName = NULL;
|
446
|
if (($author -> id != NULL) || ($author -> lastName != NULL) || ($author -> firstName != NULL) || ($author -> fullName != NULL))
|
447
|
$authors[] = $author;
|
448
|
}
|
449
|
foreach ($organizationNodes as $organizationNode) {
|
450
|
$author = new JObject();
|
451
|
$author -> id = NULL;
|
452
|
$author -> lastName = NULL;
|
453
|
$author -> firstName = NULL;
|
454
|
$author -> fullName = trim($organizationNode -> nodeValue);
|
455
|
if (($author -> id != NULL) || ($author -> lastName != NULL) || ($author -> firstName != NULL) || ($author -> fullName != NULL))
|
456
|
$authors[] = $author;
|
457
|
}
|
458
|
}
|
459
|
return $authors;
|
460
|
}
|
461
|
private function _searchORCID($orcid, $page, $size) {
|
462
|
try {
|
463
|
$time = microtime(TRUE);
|
464
|
$authorRequest = self :: ORCID_URL_PREFIX . trim($orcid) . self :: ORCID_URL_AUTHOR_SUFFIX;
|
465
|
JLog :: add('Requesting ' . $authorRequest, JLog :: INFO, self :: LOG);
|
466
|
$authorResponse = $this -> http -> get($authorRequest);
|
467
|
JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s');
|
468
|
$author = new JObject();
|
469
|
$result = new JObject();
|
470
|
if ($authorResponse != NULL&&$authorResponse -> code===self :: HTTP_OK){
|
471
|
/*if ($authorResponse -> code != self :: HTTP_OK)
|
472
|
throw new Exception('HTTP response code ' . $authorResponse -> code);*/
|
473
|
$authorDocument = new DOMDocument();
|
474
|
$authorDocument -> recover = TRUE;
|
475
|
if ($authorDocument -> loadXML(trim($authorResponse -> body)) == FALSE)
|
476
|
throw new Exception('invalid XML response');
|
477
|
$authorXpath = new DOMXPath($authorDocument);
|
478
|
if ($authorXpath -> registerNamespace('orcid', $authorDocument -> lookupNamespaceUri(NULL)) == FALSE)
|
479
|
throw new Exception('error parsing ORCID bio record');
|
480
|
if (($familyNameNodes = $authorXpath -> query('/orcid:orcid-message/orcid:orcid-profile/orcid:orcid-bio/orcid:personal-details/orcid:family-name')) == FALSE)
|
481
|
throw new Exception('error parsing ORCID bio record');
|
482
|
if (($givenNamesNodes = $authorXpath -> query('/orcid:orcid-message/orcid:orcid-profile/orcid:orcid-bio/orcid:personal-details/orcid:given-names')) == FALSE)
|
483
|
throw new Exception('error parsing ORCID bio record');
|
484
|
$author -> id = $orcid;
|
485
|
$author -> lastName = (($familyNameNode = $familyNameNodes -> item(0)) == NULL) ? NULL : trim($familyNameNode -> nodeValue);
|
486
|
$author -> firstName = (($givenNamesNode = $givenNamesNodes ->item(0)) == NULL) ? NULL : trim($givenNamesNode -> nodeValue);
|
487
|
$author -> fullName = NULL;
|
488
|
}else{
|
489
|
$time = microtime(TRUE);
|
490
|
$orcid=str_replace(" ","+",$orcid);
|
491
|
//$authorRequest = 'http://pub.orcid.org/search/orcid-bio?q='. trim($orcid);
|
492
|
$authorRequest = 'http://pub.orcid.org/search/orcid-bio?defType=edismax&q='. trim($orcid)."&qf=given-name^1.0+family-name^2.0+other-names^1.0+credit-name^1.0&start=0&rows=10";
|
493
|
JLog :: add('Requesting ' . $authorRequest, JLog :: INFO, self :: LOG);
|
494
|
$authorResponse = $this -> http -> get($authorRequest);
|
495
|
JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s');
|
496
|
if ($authorResponse -> code != self :: HTTP_OK)
|
497
|
throw new Exception('HTTP response code ' . $authorResponse -> code);
|
498
|
$authorDocument = new DOMDocument();
|
499
|
$authorDocument -> recover = TRUE;
|
500
|
if ($authorDocument -> loadXML(trim($authorResponse -> body)) == FALSE)
|
501
|
throw new Exception('invalid XML response');
|
502
|
$authorXpath = new DOMXPath($authorDocument);
|
503
|
|
504
|
|
505
|
|
506
|
if ($authorXpath -> registerNamespace('orcid', $authorDocument -> lookupNamespaceUri(NULL)) == FALSE)
|
507
|
throw new Exception('error parsing ORCID bio record');
|
508
|
if (($resultNodes = $authorXpath -> query('/orcid:orcid-message/orcid:orcid-search-results/orcid:orcid-search-result')) == FALSE)
|
509
|
throw new Exception('error parsing ORCID bio record');
|
510
|
$authors = array();
|
511
|
foreach ($resultNodes as $resultNode) {
|
512
|
if (($familyNameNodes = $authorXpath -> query('./orcid:orcid-profile/orcid:orcid-bio/orcid:personal-details/orcid:family-name',$resultNode)) == FALSE)
|
513
|
throw new Exception('error parsing ORCID bio record');
|
514
|
if (($givenNamesNodes = $authorXpath -> query('./orcid:orcid-profile/orcid:orcid-bio/orcid:personal-details/orcid:given-names',$resultNode)) == FALSE)
|
515
|
throw new Exception('error parsing ORCID bio record');
|
516
|
if (($idNodes = $authorXpath -> query('./orcid:orcid-profile/orcid:orcid-identifier/orcid:path',$resultNode)) == FALSE)
|
517
|
throw new Exception('error parsing ORCID bio record');
|
518
|
if (($relevanceNodes = $authorXpath -> query('./orcid:relevancy-score',$resultNode)) == FALSE)
|
519
|
throw new Exception('error parsing ORCID bio record');
|
520
|
$tempAuthor = new JObject();
|
521
|
$tempAuthor -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue);
|
522
|
$tempAuthor -> lastName = (($familyNameNode = $familyNameNodes -> item(0)) == NULL) ? NULL : trim($familyNameNode -> nodeValue);
|
523
|
$tempAuthor -> firstName = (($givenNamesNode = $givenNamesNodes ->item(0)) == NULL) ? NULL : trim($givenNamesNode -> nodeValue);
|
524
|
$tempAuthor -> fullName = NULL;
|
525
|
$relevance = (($relevanceNode = $relevanceNodes ->item(0)) == NULL) ? NULL : trim($relevanceNode -> nodeValue);
|
526
|
$authors[] = $tempAuthor;
|
527
|
}
|
528
|
$author= $authors[0];
|
529
|
$authors = array_slice($authors, 0, 10);
|
530
|
$result ->alternativeAuthors =NULL;
|
531
|
if($page===1){
|
532
|
$result ->alternativeAuthors =$authors;
|
533
|
}
|
534
|
}
|
535
|
$publicationsRequest = self :: ORCID_URL_PREFIX . trim(((isset($author -> id)&&$author -> id!=null)?$author -> id:$orcid)) . self :: ORCID_URL_PUBLICATIONS_SUFFIX;
|
536
|
JLog :: add('Requesting ' . $publicationsRequest, JLog :: INFO, self :: LOG);
|
537
|
if (($publicationsResponse = $this -> http -> get($publicationsRequest)) == NULL)
|
538
|
throw new Exception('no HTTP response');
|
539
|
if ($publicationsResponse -> code != self :: HTTP_OK)
|
540
|
throw new Exception('HTTP response code ' . $publicationsResponse -> code);
|
541
|
$publicationsDocument = new DOMDocument();
|
542
|
$publicationsDocument -> recover = TRUE;
|
543
|
if ($publicationsDocument -> loadXML(trim($publicationsResponse -> body)) == FALSE)
|
544
|
throw new Exception('invalid XML response');
|
545
|
$publicationsXpath = new DOMXPath($publicationsDocument);
|
546
|
if ($publicationsXpath -> registerNamespace('orcid', $publicationsDocument -> lookupNamespaceUri(NULL)) == FALSE)
|
547
|
throw new Exception('error parsing ORCID works record');
|
548
|
if (($orcidWorkNodes = $publicationsXpath -> query('/orcid:orcid-message/orcid:orcid-profile/orcid:orcid-activities/orcid:orcid-works/orcid:orcid-work')) == FALSE)
|
549
|
throw new Exception('error ORCID works record');
|
550
|
|
551
|
$result -> publications = array();
|
552
|
$dois = array();
|
553
|
$i=0;
|
554
|
foreach ($orcidWorkNodes as $orcidWorkNode) {
|
555
|
$i++;
|
556
|
if($i>=($page-1)*$size +1 && $i<=$page*$size ){
|
557
|
if (($putCodeNodes = $publicationsXpath -> query('./@put-code', $orcidWorkNode)) == FALSE)
|
558
|
throw new Exception('error ORCID works record');
|
559
|
if (($urlNodes = $publicationsXpath -> query('./orcid:url', $orcidWorkNode)) == FALSE)
|
560
|
throw new Exception('error ORCID works record');
|
561
|
if (($titleNodes = $publicationsXpath -> query('./orcid:work-title/orcid:title', $orcidWorkNode)) == FALSE)
|
562
|
throw new Exception('error ORCID works record');
|
563
|
if (($yearNodes = $publicationsXpath -> query('./orcid:publication-date/orcid:year', $orcidWorkNode)) == FALSE)
|
564
|
throw new Exception('error ORCID works record');
|
565
|
if (($shortDescriptionNodes = $publicationsXpath -> query('./orcid:short-description', $orcidWorkNode)) == FALSE)
|
566
|
throw new Exception('error ORCID works record');
|
567
|
if (($doiNodes = $publicationsXpath -> query('./orcid:work-external-identifiers/orcid:work-external-identifier[orcid:work-external-identifier-type = "doi"]/orcid:work-external-identifier-id', $orcidWorkNode)) == FALSE)
|
568
|
throw new Exception('error ORCID works record');
|
569
|
$publication = new JObject();
|
570
|
$publication -> id = (($putCodeNode = $putCodeNodes -> item(0)) == NULL) ? NULL : ($author -> id . '-' . trim($putCodeNode -> nodeValue));
|
571
|
$publication -> source = self :: ORCID;
|
572
|
$publication -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue);
|
573
|
$publication -> accessMode = NULL;
|
574
|
$publication -> datasources = array();
|
575
|
$publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue);
|
576
|
$publication -> authors = array();
|
577
|
$publication -> publisher = NULL;
|
578
|
$publication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue));
|
579
|
$publication -> language = NULL;
|
580
|
$publication -> projects = array();
|
581
|
$publication -> embargoEndDate = NULL;
|
582
|
$publication -> description = (($shortDescriptionNode = $shortDescriptionNodes -> item(0)) == NULL) ? NULL : trim($shortDescriptionNode -> nodeValue);
|
583
|
if (($author -> lastName != NULL) || ($author -> firstName != NULL))
|
584
|
$publication -> authors[] = $author;
|
585
|
if ((($doiNode = $doiNodes -> item(0)) != NULL) && (($doiResult = $this -> searchSingleDOI(trim($doiNode -> nodeValue))) != NULL)) { // resolve via DOI
|
586
|
if ($publication -> url == NULL) // set URL if missing
|
587
|
$publication -> url = $doiResult -> url;
|
588
|
if ($publication -> title == NULL) // set title if missing
|
589
|
$publication -> title = $doiResult -> title;
|
590
|
|
591
|
foreach ($doiResult -> authors as $doiAuthor) { // merge authors
|
592
|
if ((count($publication -> authors) == 0) || ($doiAuthor -> id != $publication -> authors[0] -> id) || ($doiAuthor -> lastName != $publication -> authors[0] -> lastName) || ($doiAuthor -> firstName != $publication -> authors[0] -> firstName) || ($doiAuthor -> fullName != $publication -> authors[0] -> fullName))
|
593
|
$publication -> authors[] = $doiAuthor;
|
594
|
}
|
595
|
if ($publication -> year == NULL) // set year if missing
|
596
|
$publication -> year = $doiResult -> year;
|
597
|
}
|
598
|
if (($publication -> id != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> year != NULL) || ($publication -> description != NULL)){
|
599
|
if ((($doiNode = $doiNodes -> item(0)) != NULL)) { // resolve via DOI
|
600
|
$doi=trim($doiNode -> nodeValue);
|
601
|
if((strpos($doi,"DOI: ") !== false)){
|
602
|
$doi=explode("DOI: ", $doi)[1];
|
603
|
}
|
604
|
$dois[$publication -> id]=$doi;
|
605
|
}
|
606
|
$result -> publications[$publication -> id] = $publication;
|
607
|
}
|
608
|
}
|
609
|
}
|
610
|
// request to crossref via DOI
|
611
|
$resultsFromDois=$this->_searchMultipleDOIs($dois);
|
612
|
foreach ($result -> publications as $publication){
|
613
|
$doi=$dois[$publication -> id];
|
614
|
if($doi!=null&&$resultsFromDois[$doi]!=null){
|
615
|
$doiResult=$resultsFromDois[$doi];
|
616
|
|
617
|
if ($publication -> url == NULL) // set URL if missing
|
618
|
$publication -> url = $doiResult -> url;
|
619
|
if ($publication -> title == NULL) // set title if missing
|
620
|
$publication -> title = $doiResult -> title;
|
621
|
foreach ($doiResult -> authors as $doiAuthor) { // merge authors
|
622
|
if ((count($publication -> authors) == 0) || ($doiAuthor -> id != $publication -> authors[0] -> id) || ($doiAuthor -> lastName != $publication -> authors[0] -> lastName) || ($doiAuthor -> firstName != $publication -> authors[0] -> firstName) || ($doiAuthor -> fullName != $publication -> authors[0] -> fullName))
|
623
|
$publication -> authors[] = $doiAuthor;
|
624
|
}
|
625
|
if ($publication -> year == NULL) // set year if missing
|
626
|
$publication -> year = $doiResult -> year;
|
627
|
}
|
628
|
|
629
|
}
|
630
|
$result -> totalPublications = $i;
|
631
|
$result -> totalDatasets = 0;
|
632
|
$result -> author = $author;
|
633
|
JLog :: add('ORCID search retrieved ' . count($result -> publications) . ' publications in ' . (microtime(TRUE) - $time) . ' s (ORCID: ' . $orcid . ', page: ' . $page . ', size: ' . $size . ')', JLog :: INFO, self :: LOG);
|
634
|
return $result;
|
635
|
} catch (Exception $e) {
|
636
|
JLog :: add('Error performing ORCID search (ORCID: ' . $orcid . ', page: ' . $page . ', size: ' . $size . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
637
|
$result = new JObject();
|
638
|
$result -> totalPublications = 0;
|
639
|
$result -> totalDatasets = 0;
|
640
|
$result -> author = $author;
|
641
|
return $result;
|
642
|
}
|
643
|
}
|
644
|
private function _searchDOI($doi, $page, $size) {
|
645
|
try {
|
646
|
$result = new JObject();
|
647
|
$result -> publications = array();
|
648
|
$result -> totalPublications = 0;
|
649
|
$result -> totalDatasets = 0;
|
650
|
$dois = explode(" ", preg_replace('/\s+/', ' ',$doi));
|
651
|
$unique_dois =array_slice( array_unique($dois),0,10);
|
652
|
$pattern1 ='#\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'<>])\S)+)\b#';
|
653
|
$pattern2 ='#\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'<>])[[:graph:]])+)\b#';
|
654
|
if (preg_match($pattern1,$unique_dois[0])||preg_match($pattern2,$unique_dois[0])){
|
655
|
if(count($dois)>10){
|
656
|
$result = new JObject();
|
657
|
$result->publications = array();
|
658
|
$result->totalPublications = '-';
|
659
|
$result->totalDatasets = 0;
|
660
|
$result->maxDoisExceeded = true;
|
661
|
return $result;
|
662
|
}
|
663
|
JLog :: add('Searching for DOIs ' , JLog :: INFO, self :: LOG);
|
664
|
/*foreach($unique_dois as $doi_){
|
665
|
JLog :: add('DOI::: '.$doi_ , JLog :: INFO, self :: LOG);
|
666
|
$publication = $this->_searchSingleDOI($doi_);
|
667
|
if ($publication != null) {
|
668
|
$result->publications[] = $publication;
|
669
|
}
|
670
|
}*/
|
671
|
$result->publications= $this->_searchMultipleDOIs($unique_dois);
|
672
|
}
|
673
|
|
674
|
$result -> totalPublications = count( $result -> publications);
|
675
|
if($result -> totalPublications ===0){
|
676
|
//.'&rows='.$size.'&offset='.$page
|
677
|
$request = "http://api.crossref.org/works?query=" . urlencode( trim($doi))."&rows=".$size."&offset=".($page-1)*$size;
|
678
|
JLog :: add('Requesting ' . $request, JLog :: INFO, self :: LOG);
|
679
|
$time = microtime(TRUE);
|
680
|
$response = $this -> http -> get($request);
|
681
|
JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
682
|
if ($response == NULL)
|
683
|
throw new Exception('no HTTP response');
|
684
|
if ($response -> code != self :: HTTP_OK)
|
685
|
throw new Exception('HTTP response code ' . $response -> code);
|
686
|
$res = array();
|
687
|
$response= $response -> body;
|
688
|
$response=str_replace("date-parts", "date_parts",$response-> body);
|
689
|
$response=str_replace("total-results", "total_results",$response);
|
690
|
//$res = json_decode(str_replace("-", "_", $response -> body));
|
691
|
$res = json_decode($response);
|
692
|
if(isset($res -> status)&&$res -> status === "ok" && isset($res -> message)){
|
693
|
foreach($res ->message -> items as $item){
|
694
|
$publication = $this -> _parseJsonDOI($item);
|
695
|
if($publication!=null){
|
696
|
$result -> publications[] = $publication;
|
697
|
}
|
698
|
}
|
699
|
$result -> totalPublications = $res -> message ->total_results;
|
700
|
/*if(isset($size)&&isset($page)){
|
701
|
$result -> publications = array_slice($result -> publications, ($page - 1) * $size, $size);
|
702
|
}*/
|
703
|
}
|
704
|
}
|
705
|
return $result;
|
706
|
} catch (Exception $e) {
|
707
|
JLog :: add('Error performing DOI search (doi: ' . $doi . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
708
|
$result = new JObject();
|
709
|
$result -> publications = array();
|
710
|
$result -> totalPublications = 0;
|
711
|
$result -> totalDatasets = 0;
|
712
|
JLog :: add('error parsing DOI record', JLog :: INFO, self :: LOG);
|
713
|
return $result;
|
714
|
}
|
715
|
}
|
716
|
public function searchSingleDOI($doi) {
|
717
|
if ($this -> cache -> getCaching()) {
|
718
|
$cacheId = self :: SEARCH_DOI_CACHE_ID . '.' . $doi;
|
719
|
$results = $this -> cache -> get($cacheId, self :: CACHE_GROUP);
|
720
|
if ($results === FALSE) {
|
721
|
$results = $this -> _searchSingleDOI($doi);
|
722
|
if ($results !== NULL)
|
723
|
$this -> cache -> store($results, $cacheId, self :: CACHE_GROUP);
|
724
|
}
|
725
|
} else
|
726
|
$results = $this -> _searchSingleDOI($doi);
|
727
|
return $results;
|
728
|
}
|
729
|
private function _searchSingleDOI($doi) {
|
730
|
try {
|
731
|
$request = self :: CROSSREF_API_DOI . urlencode( trim($doi));
|
732
|
JLog :: add('Requesting ' . $request, JLog :: INFO, self :: LOG);
|
733
|
$time = microtime(TRUE);
|
734
|
$response = $this -> http -> get($request);
|
735
|
JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
736
|
if ($response == NULL)
|
737
|
throw new Exception('no HTTP response');
|
738
|
if ($response -> code != self :: HTTP_OK)
|
739
|
throw new Exception('HTTP response code ' . $response -> code);
|
740
|
$res = array();
|
741
|
$response= $response -> body;
|
742
|
$response=str_replace("date-parts", "date_parts",$response-> body);
|
743
|
$response=str_replace("total-results", "total_results",$response);
|
744
|
//$res = json_decode(str_replace("-", "_", $response -> body));
|
745
|
$res = json_decode($response);
|
746
|
if(isset($res -> status) && $res -> status === "ok" && isset($res -> message)){
|
747
|
$publication = $this -> _parseJsonDOI($res -> message);
|
748
|
return $publication;
|
749
|
}
|
750
|
|
751
|
} catch (Exception $e) {
|
752
|
JLog :: add('Error performing DOI search (doi: ' . $doi . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
753
|
$result = new JObject();
|
754
|
$result -> publications = array();
|
755
|
$result -> totalPublications = 0;
|
756
|
$result -> totalDatasets = 0;
|
757
|
JLog :: add('error parsing DOI record', JLog :: INFO, self :: LOG);
|
758
|
return null;
|
759
|
}
|
760
|
}
|
761
|
private function _searchMultipleDOIs($dois){
|
762
|
try {
|
763
|
$request ="http://api.crossref.org/works"."?filter=";
|
764
|
foreach($dois as $doi){
|
765
|
$request.="doi:".urlencode( trim($doi)).",";
|
766
|
}
|
767
|
JLog :: add('Requesting ' . $request, JLog :: INFO, self :: LOG);
|
768
|
$time = microtime(TRUE);
|
769
|
$response = $this -> http -> get($request);
|
770
|
JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
771
|
if ($response == NULL)
|
772
|
throw new Exception('no HTTP response');
|
773
|
if ($response -> code != self :: HTTP_OK)
|
774
|
throw new Exception('HTTP response code ' . $response -> code);
|
775
|
$res = array();
|
776
|
$response=str_replace("date-parts", "date_parts",$response-> body);
|
777
|
$response=str_replace("total-results", "total_results",$response);
|
778
|
$res = json_decode($response);
|
779
|
//$res = json_decode(str_replace("-", "_", $response -> body));
|
780
|
if(isset($res -> status) && $res -> status === "ok" && isset($res -> message)){
|
781
|
$publications = $this ->_parseMultipleJsonDOIs($res -> message);
|
782
|
return $publications;
|
783
|
}
|
784
|
|
785
|
} catch (Exception $e) {
|
786
|
JLog :: add('Error performing DOI search (doi: ' . $doi . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
787
|
$result = new JObject();
|
788
|
$result -> publications = array();
|
789
|
$result -> totalPublications = 0;
|
790
|
$result -> totalDatasets = 0;
|
791
|
JLog :: add('error parsing DOI record', JLog :: INFO, self :: LOG);
|
792
|
return null;
|
793
|
}
|
794
|
}
|
795
|
// Search for a publication DOI using caching if enabled.
|
796
|
// $doi the publication DOI to search for
|
797
|
// return an array of results
|
798
|
public function searchDOI($doi, $page, $size) {
|
799
|
if ($this -> cache -> getCaching()) {
|
800
|
$cacheId = self :: SEARCH_DOI_CACHE_ID . '.' . $doi;
|
801
|
$results = $this -> cache -> get($cacheId, self :: CACHE_GROUP);
|
802
|
if ($results === FALSE) {
|
803
|
$results = $this -> _searchDOI($doi, $page, $size);
|
804
|
if ($results !== NULL)
|
805
|
$this -> cache -> store($results, $cacheId, self :: CACHE_GROUP);
|
806
|
}
|
807
|
} else
|
808
|
$results = $this -> _searchDOI($doi, $page, $size);
|
809
|
return $results;
|
810
|
}
|
811
|
|
812
|
// Search for a dataset DOI using caching if enabled.
|
813
|
// $doi the dataset DOI to search for
|
814
|
// return a result (object) containing publications and total
|
815
|
public function searchDataCite($doi, $page, $size) {
|
816
|
if ($this -> cache -> getCaching()) {
|
817
|
$cacheId = self :: SEARCH_DATASET_CACHE_ID . '.' . $doi;
|
818
|
$results = $this -> cache -> get($cacheId, self :: CACHE_GROUP);
|
819
|
if ($results === FALSE) {
|
820
|
$results = $this -> _searchDataCite($doi, $page, $size);
|
821
|
if ($results !== NULL)
|
822
|
$this -> cache -> store($results, $cacheId, self :: CACHE_GROUP);
|
823
|
}
|
824
|
} else
|
825
|
$results = $this -> _searchDataCite($doi, $page, $size);
|
826
|
return $results;
|
827
|
}
|
828
|
|
829
|
// Search for publications in ORCID using caching if enabled.
|
830
|
// $doi the ORCID id to search for
|
831
|
// $page the result page to retrieve
|
832
|
// $size the result page size to use
|
833
|
// return a result (object) containing datasets and total
|
834
|
public function searchORCID($orcid, $page, $size) {
|
835
|
if ($this -> cache -> getCaching()) {
|
836
|
$cacheId = self :: SEARCH_ORCID_CACHE_ID . '.' . $orcid . '.' . $page . '.' . $size;
|
837
|
$results = $this -> cache -> get($cacheId, self :: CACHE_GROUP);
|
838
|
if ($results === FALSE) {
|
839
|
$results = $this -> _searchORCID($orcid, $page, $size);
|
840
|
if ($results !== NULL)
|
841
|
$this -> cache -> store($results, $cacheId, self :: CACHE_GROUP);
|
842
|
}
|
843
|
} else
|
844
|
$results = $this -> _searchORCID($orcid, $page, $size);
|
845
|
|
846
|
return $results;
|
847
|
}
|
848
|
}
|
849
|
?>
|