|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Onoi\Remi\CrossRef; |
|
4
|
|
|
|
|
5
|
|
|
use Onoi\Remi\FilteredHttpResponseParser; |
|
6
|
|
|
use Onoi\Remi\FilteredRecord; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @license GNU GPL v2+ |
|
10
|
|
|
* @since 0.1 |
|
11
|
|
|
* |
|
12
|
|
|
* @author mwjames |
|
13
|
|
|
*/ |
|
14
|
|
|
class CrossRefFilteredHttpResponseParser extends FilteredHttpResponseParser { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @see http://crosscite.org/cn/ |
|
18
|
|
|
*/ |
|
19
|
|
|
const CROSSREF_CONTENT_API = "https://dx.doi.org/"; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @since 0.1 |
|
23
|
|
|
* |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
*/ |
|
26
|
4 |
|
public function getRawResponseById( $doi ) { |
|
27
|
4 |
|
return $this->requestResponseFor( $doi ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @since 0.1 |
|
32
|
|
|
* |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
*/ |
|
35
|
6 |
|
public function doFilterResponseById( $doi ) { |
|
36
|
|
|
|
|
37
|
6 |
|
$json = json_decode( |
|
38
|
6 |
|
$this->requestResponseFor( $doi ), |
|
39
|
|
|
true |
|
40
|
6 |
|
); |
|
41
|
|
|
|
|
42
|
6 |
|
if ( $this->httpRequest->getLastError() !== '' ) { |
|
43
|
1 |
|
return $this->addMessage( array( 'onoi-remi-request-error', $this->httpRequest->getLastError(), $doi ) ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
5 |
|
if ( $json === null || $json === array() ) { |
|
47
|
2 |
|
return $this->addMessage( array( 'onoi-remi-response-empty', $doi ) ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
4 |
|
$this->doProcessCiteproc( $json ); |
|
51
|
|
|
|
|
52
|
4 |
|
$this->filteredRecord->set( 'retrieved-from', self::CROSSREF_CONTENT_API ); |
|
53
|
4 |
|
} |
|
54
|
|
|
|
|
55
|
4 |
|
private function doProcessCiteproc( $json ) { |
|
56
|
|
|
|
|
57
|
4 |
|
$crossRefCiteprocJsonProcessor = new CrossRefCiteprocJsonProcessor( |
|
58
|
4 |
|
$this->getFilteredRecord() |
|
59
|
4 |
|
); |
|
60
|
|
|
|
|
61
|
4 |
|
$crossRefCiteprocJsonProcessor->doProcess( $json ); |
|
62
|
4 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param string $doi |
|
66
|
|
|
* |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
6 |
|
private function requestResponseFor( $doi ) { |
|
70
|
|
|
|
|
71
|
6 |
|
$this->httpRequest->setOption( CURLOPT_FOLLOWLOCATION, true ); |
|
72
|
|
|
|
|
73
|
6 |
|
$this->httpRequest->setOption( CURLOPT_RETURNTRANSFER, true ); |
|
74
|
6 |
|
$this->httpRequest->setOption( CURLOPT_FAILONERROR, true ); |
|
75
|
6 |
|
$this->httpRequest->setOption( CURLOPT_SSL_VERIFYPEER, false ); |
|
76
|
|
|
|
|
77
|
6 |
|
$this->httpRequest->setOption( CURLOPT_URL, self::CROSSREF_CONTENT_API . $doi ); |
|
78
|
|
|
|
|
79
|
6 |
|
$this->httpRequest->setOption( CURLOPT_HTTPHEADER, array( |
|
80
|
6 |
|
'Accept: application/vnd.citationstyles.csl+json', |
|
81
|
|
|
'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' |
|
82
|
6 |
|
) ); |
|
83
|
|
|
|
|
84
|
6 |
|
return $this->httpRequest->execute(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|