-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoaipmh_target.php
177 lines (153 loc) · 5.88 KB
/
oaipmh_target.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
<?php
/**
* Handles incoming OAIPMH requests for the Library module as per the OAIPMH specification.
*
* External metadata harversters submit OAIPMH queries against this file for processing. The OAIPMH
* specification outlines a standard vocabulary for requests and responses are defined by the spec's
* XML schema, handled by Archive object. If you don't want to enable the OAIPMH functionality of
* this module you can safely remove this file, it will not affect the other functions. But it is
* probably easier just to turn off OAIPMH functionality in the module preferences (there is a
* kill switch). XML responses are assembled in a buffer and then flushed in a compressed stream.
*
* @copyright Copyright Isengard.biz 2010, distributed under GNU GPL V2 or any later version
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @since 1.0
* @author Madfish (Simon Wilkinson) <simon@isengard.biz>
* @package archive
* @version $Id$
*/
include_once 'header.php';
$xoopsOption['template_main'] = 'library_publication.html';
include_once ICMS_ROOT_PATH . '/header.php';
// check if Open Archive functionality is enabled - and kill script if it isn't
if ($libraryConfig['library_enable_archive'] == 0) {
echo _CO_LIBRARY_ARCHIVE_NOT_CONFIGURED;
exit;
} else {
// initialise
$dirty_vars = $allowed_vars = $clean_vars = array();
$verb = $identifier = $identification = $metadataPrefix = $from = $until = $set
= $resumptionToken = $identification = $getRecord = $listMetadataFormats = $listSets
= $listRecords = $badVerb = '';
////////// BEGIN INPUT SANITISATION //////////
// whitelist acceptable variables
$allowed_vars = array('verb' => 'plaintext', 'identifier' => 'plaintext',
'metadataPrefix' => 'plaintext', 'from' => 'plaintext', 'until' => 'plaintext',
'set' => 'plaintext', 'resumptionToken' => 'plaintext');
// OAIPMH spec requires support for both GET and POST requests
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$dirty_vars = $_GET;
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
$dirty_vars = $_POST;
}
// channel whitelisted variables through the validator
$clean_vars = library_validate($dirty_vars, $allowed_vars);
// extract the sanitised variables
extract($clean_vars);
////////// END INPUT SANITISATION //////////
// set up the relevant archive and handlers relevant to target object
$library_archive_handler = icms_getModuleHandler('archive',
basename(dirname(__FILE__)), 'library');
$archiveObjects = $library_archive_handler->getObjects();
// there should only be one archive object but the id may vary if deleted / recreated
// so just pull the first one from the array
$archiveObj = array_shift($archiveObjects);
// if no archive object has been created, issue a warning
if (!$archiveObj) {
echo _CO_LIBRARY_ARCHIVE_MUST_CREATE;
}
// IMPORTANT: need to disable the xoopsLogger because it breaks XML responses
$xoopsLogger->disableLogger();
// directs response to incoming requests
switch ($verb) {
// retrieve information about the archive
case "Identify":
$identify_response = $archiveObj->identify();
$identification = simplexml_load_string($identify_response);
ob_start("ob_gzhandler");
header('Content-Type: text/xml');
print $identification->asXML();
ob_end_flush();
exit();
break;
// retrieve one record
case "GetRecord":
$getRecord = simplexml_load_string($archiveObj->getRecord($identifier,
$metadataPrefix));
ob_start("ob_gzhandler");
header('Content-Type: text/xml');
print $getRecord->asXML();
ob_end_flush();
exit();
break;
// retrieves record headers, rather than full records
case "ListIdentifiers":
if (!empty($from)) {
if (strlen($from) == 10) {
$from .= 'T00:00:00Z'; // if granularity is day level, add time to avoid breaking code
}
}
if (!empty($until)) {
if (strlen($until) == 10) {
$until .= 'T00:00:00Z'; // if granularity is day level, add time to avoid breaking code
}
}
$listIdentifiers = simplexml_load_string($archiveObj->listIdentifiers($metadataPrefix,
$from, $until, $set, $resumptionToken));
ob_start("ob_gzhandler");
header('Content-Type: text/xml');
print $listIdentifiers->asXML();
ob_end_flush();
exit();
break;
// list the metadata formats available from this archive
case "ListMetadataFormats":
$listMetadataFormats = simplexml_load_string($archiveObj->listMetadataFormats($identifier));
ob_start("ob_gzhandler");
header('Content-Type: text/xml');
print $listMetadataFormats->asXML();
ob_end_flush();
exit();
break;
// retrieve multiple records from the repository
case "ListRecords":
if (!empty($from)) {
if (strlen($from) == 10) {
$from .= 'T00:00:00Z'; // if granularity is day level, add time to avoid breaking code
}
}
if (!empty($until)) {
if (strlen($until) == 10) {
$until .= 'T00:00:00Z'; // if granularity is day level, add time to avoid breaking code
}
}
$listRecords = simplexml_load_string($archiveObj->listRecords($metadataPrefix, $from,
$until, $set, $resumptionToken));
ob_start("ob_gzhandler");
header('Content-Type: text/xml');
print $listRecords->asXML();
ob_end_flush();
exit();
break;
// retrieve the set structure of this archive (sets are not implemented yet)
case "ListSets":
$listSets = simplexml_load_string($archiveObj->listSets($resumptionToken));
ob_start("ob_gzhandler");
header('Content-Type: text/xml');
print $listSets->asXML();
ob_end_flush();
exit();
break;
// if we don't know what's going on, throw badVerb error, request is illegal
default:
$badVerb = simplexml_load_string($archiveObj->BadVerb());
ob_start("ob_gzhandler");
header('Content-Type: text/xml');
print $badVerb->asXML();
ob_end_flush();
exit();
break;
}
}
$icmsTpl->assign('archive_module_home', archive_getModuleName(true, true));
include_once 'footer.php';