forked from swordapp/swordappv2-php-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swordappentry.php
265 lines (213 loc) · 9 KB
/
swordappentry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
require_once("swordapplink.php");
require_once("utils.php");
class SWORDAPPEntry {
// The HTTP status code returned
public $sac_status;
// The XML returned by the deposit
public $sac_xml;
// The human readable status code
public $sac_statusmessage;
// The atom:id identifier
public $sac_id;
// The atom:content values
public $sac_content_src;
public $sac_content_type;
// The authors
public $sac_authors;
// The contributors
public $sac_contributors;
// The links
public $sac_links;
// The title
public $sac_title;
// The summary
public $sac_summary;
// The rights
public $sac_rights;
// The treatment
public $sac_treatment;
// The verbose description
public $sac_verbose_treatment;
// The update date
public $sac_updated;
// The packaging format used
public $sac_packaging;
// The generator
public $sac_generator;
public $sac_generator_uri;
// The user agent
public $sac_useragent;
// The noOp status
public $sac_noOp;
// Any dcterms metadata
public $sac_dcterms;
// The Edit IRI
public $sac_edit_iri;
// The SE-IRI
public $sac_se_iri;
// The Atom Statement IRI
public $sac_state_iri_atom;
// The Atom Statement IRI
public $sac_state_iri_ore;
// The Edit Media IRI
public $sac_edit_media_iri;
// Construct a new deposit response by passing in the http status code
function __construct($sac_newstatus, $sac_thexml) {
// Store the status
$this->sac_status = $sac_newstatus;
// Store the xml
$this->sac_xml = $sac_thexml;
// Store the status message
switch($this->sac_status) {
case 200:
$this->sac_statusmessage = "OK";
break;
case 201:
$this->sac_statusmessage = "Created";
break;
case 202:
$this->sac_statusmessage = "Accepted";
break;
case 400:
$this->sac_statusmessage = "Bad request";
break;
case 401:
$this->sac_statusmessage = "Unauthorized";
break;
case 403:
$this->sac_statusmessage = "Forbidden";
break;
case 412:
$this->sac_statusmessage = "Precondition failed";
break;
case 413:
$this->sac_statusmessage = "Request entity too large";
break;
case 415:
$this->sac_statusmessage = "Unsupported media type";
break;
default:
$this->sac_statusmessage = "Unknown error (status code " . $this->sac_status . ")";
break;
}
// Initalise arrays
$this->sac_authors = array();
$this->sac_contributors = array();
$this->sac_links = array();
$this->sac_dcterms = array();
// Assume noOp is false unless we change it later
$this->sac_noOp = false;
}
// Build the workspace hierarchy
function buildhierarchy($sac_dr, $sac_ns) {
// Set the default namespace
$sac_dr->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
if (!isset($sac_ns['atom'])) $sac_ns['atom'] = 'http://www.w3.org/2005/Atom';
if (!isset($sac_ns['dcterms'])) $sac_ns['dcterms'] = 'http://purl.org/dc/terms/';
// Parse the results
$this->sac_id = $sac_dr->children($sac_ns['atom'])->id;
$sac_contentbits = $sac_dr->xpath("atom:content");
if (!empty($sac_contentbits)) {
$this->sac_content_src = $sac_contentbits[0]->attributes()->src;
$this->sac_content_type = $sac_contentbits[0]->attributes()->type;
}
// Store the authors
foreach ($sac_dr->children($sac_ns['atom'])->author as $sac_author) {
$sac_theauthor = $sac_author->children($sac_ns['atom'])->name . "";
$this->sac_authors[] = $sac_theauthor;
}
// Store the contributors
foreach ($sac_dr->children($sac_ns['atom'])->contributor as $sac_contributor) {
$sac_thecontributor = $sac_contributor->children($sac_ns['atom'])->name . "";
$this->sac_contributors[] = $sac_thecontributor;
}
// Store the links
foreach ($sac_dr->xpath("atom:link") as $sac_link) {
$sac_linkobject = new SWORDAPPLink($sac_link->attributes()->rel, $sac_link->attributes()->href, $sac_link->attributes()->type);
array_push($this->sac_links, $sac_linkobject);
// Store the Edit IRI
if ($sac_linkobject->sac_linkrel == 'edit') $this->sac_edit_iri = $sac_linkobject->sac_linkhref;
// Store the SE-IRI
if ($sac_linkobject->sac_linkrel == 'http://purl.org/net/sword/terms/add') $this->sac_se_iri = $sac_linkobject->sac_linkhref;
// Store the Statement IRIs
if ($sac_linkobject->sac_linkrel == 'http://purl.org/net/sword/terms/statement') {
if (($sac_linkobject->sac_linktype == 'application/atom+xml;type=feed') ||
($sac_linkobject->sac_linktype == 'application/atom+xml; type=feed')) {
$this->sac_state_iri_atom = $sac_linkobject->sac_linkhref;
} else if ($sac_linkobject->sac_linktype == 'application/rdf+xml') {
$this->sac_state_iri_ore = $sac_linkobject->sac_linkhref;
}
}
// Store the Edit Media IRIs
if ($sac_linkobject->sac_linkrel == 'edit-media') {
$this->sac_edit_media_iri = $sac_linkobject->sac_linkhref;
}
}
// Store the title and summary
$this->sac_title = sac_clean($sac_dr->children($sac_ns['atom'])->title);
$this->sac_summary = sac_clean($sac_dr->children($sac_ns['atom'])->summary);
// Store the updated date
$this->sac_updated = $sac_dr->children($sac_ns['atom'])->updated;
// Store the rights
$this->sac_rights = sac_clean($sac_dr->children($sac_ns['atom'])->rights);
// Store the treatment
$this->sac_treatment = sac_clean($sac_dr->children($sac_ns['sword'])->treatment);
// Store the verboseDescription
$this->sac_verbose_treatment = sac_clean($sac_dr->children($sac_ns['sword'])->verboseDescription);
// Store the format namespace
$this->sac_packaging = $sac_dr->children($sac_ns['sword'])->packaging;
// Store the generator
$this->sac_generator = sac_clean($sac_dr->children($sac_ns['atom'])->generator);
$sac_gen = $sac_dr->xpath("atom:generator");
if (!empty($sac_gen)) { $this->sac_generator_uri = $sac_gen[0]->attributes()->uri; }
// Store the user agent
$this->sac_useragent = sac_clean($sac_dr->children($sac_ns['sword'])->userAgent);
// Store any embedded metadata
foreach ($sac_dr->children($sac_ns['dcterms']) as $sac_dcterm) {
if (!isset($this->sac_dcterms[$sac_dcterm->getName()])) {
$this->sac_dcterms[$sac_dcterm->getName()] = array();
}
array_push($this->sac_dcterms[$sac_dcterm->getName()], $sac_dcterm);
}
// Store the noOp status
if (strtolower((string)$sac_dr->children($sac_ns['sword'])->noOp) == 'true') {
$this->sac_noOp = true;
}
}
function toString() {
print " - ID: " . $this->sac_id . "\n";
print " - Title: " . $this->sac_title . "\n";
print " - Content: " . $this->sac_content_src ." (" . $this->sac_content_type . ")\n";
foreach ($this->sac_authors as $author) {
print " - Author: " . $author . "\n";
}
foreach ($this->sac_contributors as $contributor) {
print " - Contributor: " . $contributor . "\n";
}
foreach ($this->sac_links as $links) {
print ' - Link: rel=' . $links->sac_linkrel . ' ';
print 'href=' . $links->sac_linkhref . ' ';
if (isset($links->sac_linktype)) {
print 'type=' . $links->sac_linktype;
}
print "\n";
}
print " - Summary: " . $this->sac_summary . "\n";
print " - Updated: " . $this->sac_updated . "\n";
print " - Rights: " . $this->sac_rights . "\n";
print " - Treatment: " . $this->sac_treatment . "\n";
print " - Verbose description: " . $this->sac_verbose_treatment . "\n";
print " - Packaging: " . $this->sac_packaging . "\n";
print " - Generator: " . $this->sac_generator . " (" . $this->sac_generator_uri . ")\n";
print " - User agent: " . $this->sac_useragent . "\n";
if (!empty($this->sac_noOp)) { print " - noOp: " . $this->sac_noOp . "\n"; }
foreach ($this->sac_dcterms as $dcterm => $dcvalues) {
print ' - Dublin Core Metadata: ' . $dcterm . "\n";
foreach ($dcvalues as $dcvalue) {
print ' - ' . $dcvalue . "\n";
}
}
}
}
?>