forked from slims/slims9_bulian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oai2.php
185 lines (153 loc) · 4.82 KB
/
oai2.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
<?php
/**
* \file oai2.php
* \brief
* OAI Data Provider command processor
*
* OAI Data Provider is not designed for human to retrieve data.
*
* This is an implementation of OAI Data Provider version 2.0.
* @see http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm
*
* It needs other files:
* - oaidp-config.php : Configuration of provider
* - oaidp-util.php : Utility functions
* - xml_creater.php : XML generating functions
* - Actions:
* - identify.php : About the provider
* - listmetadataformats.php : List supported metadata formats
* - listrecords.php : List identifiers and records
* - listsets.php : List sets
* - getrecord.php : Get a record
* - Your own implementation for providing metadata records.
*
* It also initiates:
* - PDO datbase connection object $db.
* - ANDS_XML XML document handler $outputObj.
*
* \todo <b>Remember:</b> to define your own classess for generating metadata records.
* In common cases, you have to implement your own code to act fully and correctly.
* For generic usage, you can try the ANDS_Response_XML defined in xml_creater.php.
*/
// Report all errors except E_NOTICE
// This is the default value set in php.ini
// If anything else, try them.
// error_reporting (E_ALL ^ E_NOTICE);
/**
* An array for collecting erros which can be reported later. It will be checked before a new action is taken.
*/
$errors = array();
ini_set('session.use_cookies', '0');
// key to authenticate
define('INDEX_AUTH', '1');
// required file
require 'sysconfig.inc.php';
define('OAI_LIB', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.
'lib'.DIRECTORY_SEPARATOR.
'oaipmh'.DIRECTORY_SEPARATOR);
require_once(OAI_LIB.'oaidp-config.php');
require_once(OAI_LIB.'oaidp-util.php');
require_once(OAI_LIB.'ands_tpa.php');
/**
* Supported attributes associate to verbs.
*/
$attribs = array ('from', 'identifier', 'metadataPrefix', 'set', 'resumptionToken', 'until');
if (in_array($_SERVER['REQUEST_METHOD'],array('GET','POST'))) {
$args = $_REQUEST;
} else {
$errors[] = oai_error('badRequestMethod', $_SERVER['REQUEST_METHOD']);
}
// Always using htmlentities() function to encodes the HTML entities submitted by others.
// No one can be trusted.
foreach ($args as $key => $val) {
$checking = urlencode(stripslashes($val));
if (!is_valid_attrb($checking)) {
$errors[] = oai_error('badArgument', $checking);
} else {$args[$key] = $checking; }
}
if (!empty($errors)) { oai_exit(); }
foreach($attribs as $val) {
unset($$val);
}
// Create a PDO object
$db = \SLiMS\DB::getInstance();
// For generic usage or just trying:
// require_once('xml_creater.php');
// In common cases, you have to implement your own code to act fully and correctly.
// Default, there is no compression supported
$compress = FALSE;
if (isset($compression) && is_array($compression)) {
if (in_array('gzip', $compression) && ini_get('output_buffering')) {
$compress = TRUE;
}
}
if (SHOW_QUERY_ERROR) {
echo "Args:\n"; print_r($args);
}
if (isset($args['verb'])) {
switch ($args['verb']) {
case 'Identify':
// we never use compression in Identify
$compress = FALSE;
if(count($args)>1) {
foreach($args as $key => $val) {
if(strcmp($key,"verb")!=0) {
$errors[] = oai_error('badArgument', $key, $val);
}
}
}
if (empty($errors)) include OAI_LIB.'identify.php';
break;
case 'ListMetadataFormats':
$checkList = array("ops"=>array("identifier"));
checkArgs($args, $checkList);
if (empty($errors)) include OAI_LIB.'listmetadataformats.php';
break;
case 'ListSets':
if(isset($args['resumptionToken']) && count($args) > 2) {
$errors[] = oai_error('exclusiveArgument');
}
$checkList = array("ops"=>array("resumptionToken"));
checkArgs($args, $checkList);
if (empty($errors)) include OAI_LIB.'listsets.php';
break;
case 'GetRecord':
$checkList = array("required"=>array("metadataPrefix","identifier"));
checkArgs($args, $checkList);
if (empty($errors)) include OAI_LIB.'getrecord.php';
break;
case 'ListIdentifiers':
case 'ListRecords':
if(isset($args['resumptionToken'])) {
if (count($args) > 2) {
$errors[] = oai_error('exclusiveArgument');
}
$checkList = array("ops"=>array("resumptionToken"));
} else {
$checkList = array("required"=>array("metadataPrefix"),"ops"=>array("from","until","set"));
}
checkArgs($args, $checkList);
if (empty($errors)) include OAI_LIB.'listrecords.php';
break;
default:
// we never use compression with errors
$compress = FALSE;
$errors[] = oai_error('badVerb', $args['verb']);
} /*switch */
} else {
$errors[] = oai_error('noVerb');
}
if (!empty($errors)) { oai_exit(); }
if ($compress) {
ob_start('ob_gzhandler');
}
header(CONTENT_TYPE);
if(isset($outputObj)) {
$outputObj->display();
} else {
exit("There is a bug in codes");
}
if ($compress) {
ob_end_flush();
}
?>