2013-05-07 19:48:37 +02:00
|
|
|
<?php
|
2013-05-12 02:18:36 +02:00
|
|
|
/**
|
2017-05-12 18:13:53 +02:00
|
|
|
* Simple OAI-PMH 2.0 Data Provider
|
2017-05-13 12:08:11 +02:00
|
|
|
* Copyright (C) 2005 Heinrich Stamerjohanns <stamer@uni-oldenburg.de>
|
|
|
|
* Copyright (C) 2011 Jianfeng Li <jianfeng.li@adelaide.edu.au>
|
2017-05-12 18:13:53 +02:00
|
|
|
* Copyright (C) 2013 Daniel Neis Araujo <danielneis@gmail.com>
|
|
|
|
* Copyright (C) 2017 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
2013-05-12 02:18:36 +02:00
|
|
|
*
|
2017-05-12 18:13:53 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-05-12 02:18:36 +02:00
|
|
|
*
|
2017-05-12 18:13:53 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-05-12 02:18:36 +02:00
|
|
|
*/
|
|
|
|
|
2017-05-12 18:13:53 +02:00
|
|
|
require_once('oai2config.php');
|
|
|
|
require_once('oai2server.php');
|
2013-05-14 21:46:15 +02:00
|
|
|
|
2017-05-12 18:13:53 +02:00
|
|
|
// Get all available records and their respective timestamps
|
|
|
|
$records = array();
|
|
|
|
$timestamps = array();
|
|
|
|
|
|
|
|
$files = glob('data/*.xml');
|
|
|
|
foreach($files as $file) {
|
|
|
|
$records[pathinfo($file, PATHINFO_FILENAME)] = $file;
|
|
|
|
$timestamps[filemtime($file)][] = pathinfo($file, PATHINFO_FILENAME);
|
|
|
|
};
|
2013-05-14 05:54:50 +02:00
|
|
|
|
2017-05-12 18:13:53 +02:00
|
|
|
ksort($records);
|
|
|
|
reset($records);
|
2013-05-14 05:54:50 +02:00
|
|
|
|
2017-05-12 18:13:53 +02:00
|
|
|
ksort($timestamps);
|
|
|
|
reset($timestamps);
|
2013-05-14 05:54:50 +02:00
|
|
|
|
2017-05-21 20:01:51 +02:00
|
|
|
// Get current base URL
|
|
|
|
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
|
|
|
|
$baseURL = 'https://'.$_SERVER['HTTP_HOST'].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
|
|
|
|
} else {
|
|
|
|
$baseURL = 'http://'.$_SERVER['HTTP_HOST'].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
|
|
|
|
}
|
|
|
|
|
2017-05-12 18:13:53 +02:00
|
|
|
// Build the Identify response
|
|
|
|
$identifyResponse = array(
|
|
|
|
'repositoryName' => $config['repositoryName'],
|
2017-05-21 20:01:51 +02:00
|
|
|
'baseURL' => $baseURL,
|
2017-05-12 18:13:53 +02:00
|
|
|
'protocolVersion' => '2.0',
|
|
|
|
'adminEmail' => $config['adminEmail'],
|
|
|
|
'earliestDatestamp' => gmdate('Y-m-d\TH:i:s\Z', key($timestamps)),
|
|
|
|
'deletedRecord' => 'no',
|
|
|
|
'granularity' => 'YYYY-MM-DDThh:mm:ssZ'
|
|
|
|
);
|
|
|
|
|
|
|
|
$oai2 = new OAI2Server(
|
2017-05-21 20:01:51 +02:00
|
|
|
$baseURL,
|
2017-05-12 18:13:53 +02:00
|
|
|
$_GET,
|
|
|
|
$identifyResponse,
|
|
|
|
array(
|
|
|
|
'GetRecord' =>
|
|
|
|
function($identifier, $metadataPrefix) {
|
2017-05-13 12:21:26 +02:00
|
|
|
global $records;
|
2017-05-12 18:13:53 +02:00
|
|
|
if (empty($records[$identifier])) {
|
|
|
|
return array();
|
|
|
|
} else {
|
|
|
|
return array(
|
|
|
|
'identifier' => $identifier,
|
|
|
|
'timestamp' => filemtime($records[$identifier]),
|
|
|
|
'metadata' => $records[$identifier]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'ListRecords' =>
|
|
|
|
function($metadataPrefix, $from = null, $until = null, $count = false, $deliveredRecords = 0, $maxItems = 100) {
|
2017-05-13 12:21:26 +02:00
|
|
|
global $records, $timestamps;
|
2017-05-12 18:13:53 +02:00
|
|
|
$resultSet = array();
|
|
|
|
foreach($timestamps as $timestamp => $identifiers) {
|
|
|
|
if ((is_null($from) || $timestamp >= $from) && (is_null($until) || $timestamp <= $until)) {
|
|
|
|
foreach($identifiers as $identifier) {
|
|
|
|
$resultSet[] = array(
|
|
|
|
'identifier' => $identifier,
|
|
|
|
'timestamp' => filemtime($records[$identifier]),
|
|
|
|
'metadata' => $records[$identifier]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($count) {
|
|
|
|
return count($resultSet);
|
|
|
|
} else {
|
|
|
|
return array_slice($resultSet, $deliveredRecords, $maxItems);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'ListMetadataFormats' =>
|
|
|
|
function($identifier = '') {
|
2017-05-13 12:21:26 +02:00
|
|
|
global $config;
|
|
|
|
if (!empty($identifier) && empty($records[$identifier])) {
|
2017-05-12 18:13:53 +02:00
|
|
|
throw new OAI2Exception('idDoesNotExist');
|
|
|
|
} else {
|
|
|
|
return array(
|
2017-05-13 12:08:11 +02:00
|
|
|
$config['metadataFormat'] => array(
|
2017-05-12 18:13:53 +02:00
|
|
|
'schema'=> $config['metadataSchema'],
|
2017-05-13 12:21:26 +02:00
|
|
|
'namespace' => $config['metadataNamespace']
|
2017-05-12 18:13:53 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
),
|
|
|
|
$config
|
2013-05-14 05:54:50 +02:00
|
|
|
);
|
2013-05-15 02:56:52 +02:00
|
|
|
|
|
|
|
$response = $oai2->response();
|
2017-05-12 18:13:53 +02:00
|
|
|
|
2013-05-15 02:56:52 +02:00
|
|
|
if (isset($return)) {
|
2017-05-12 18:13:53 +02:00
|
|
|
return $response;
|
2013-05-15 02:56:52 +02:00
|
|
|
} else {
|
2017-05-12 18:13:53 +02:00
|
|
|
$response->formatOutput = true;
|
|
|
|
$response->preserveWhiteSpace = false;
|
|
|
|
header('Content-Type: text/xml');
|
|
|
|
echo $response->saveXML();
|
2013-05-15 02:56:52 +02:00
|
|
|
}
|