keep refactoring

This commit is contained in:
Daniel Neis 2013-05-12 00:18:36 +00:00
parent 1b51e1ced6
commit 49c64da4e5
5 changed files with 266 additions and 378 deletions

View File

@ -23,12 +23,10 @@ $METADATAFORMATS = array (
'rif' => array('metadataPrefix'=>'rif',
'schema'=>'http://services.ands.org.au/sandbox/orca/schemata/registryObjects.xsd',
'metadataNamespace'=>'http://ands.org.au/standards/rif-cs/registryObjects/',
'myhandler'=>'record_rif.php'
),
'oai_dc' => array('metadataPrefix'=>'oai_dc',
'schema'=>'http://www.openarchives.org/OAI/2.0/oai_dc.xsd',
'metadataNamespace'=>'http://www.openarchives.org/OAI/2.0/oai_dc/',
'myhandler'=>'record_dc.php',
'record_prefix'=>'dc',
'record_namespace' => 'http://purl.org/dc/elements/1.1/'
)

148
oai2.php
View File

@ -11,32 +11,15 @@
* - 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.
*/
/**
* An array for collecting erros which can be reported later. It will be checked before a new action is taken.
*/
$errors = array();
/**
* Supported attributes associate to verbs.
*/
$attribs = array ('from', 'identifier', 'metadataPrefix', 'set', 'resumptionToken', 'until');
if (in_array($_SERVER['REQUEST_METHOD'],array('GET','POST'))) {
$args = $_REQUEST;
@ -45,6 +28,7 @@ if (in_array($_SERVER['REQUEST_METHOD'],array('GET','POST'))) {
}
require_once('oaidp-util.php');
// Always using htmlentities() function to encodes the HTML entities submitted by others.
// No one can be trusted.
foreach ($args as $key => $val) {
@ -57,6 +41,7 @@ if (!empty($errors)) {
oai_exit();
}
$attribs = array ('from', 'identifier', 'metadataPrefix', 'set', 'resumptionToken', 'until');
foreach($attribs as $val) {
unset($$val);
}
@ -79,105 +64,36 @@ if (isset($compression) && is_array($compression)) {
}
}
if (SHOW_QUERY_ERROR) {
echo "Args:\n"; print_r($args);
}
require_once('oai2server.php');
/**
* Identifier settings. It needs to have proper values to reflect the settings of the data provider.
* Is MUST be declared in this order
*
* - $identifyResponse['repositoryName'] : compulsory. A human readable name for the repository;
* - $identifyResponse['baseURL'] : compulsory. The base URL of the repository;
* - $identifyResponse['protocolVersion'] : compulsory. The version of the OAI-PMH supported by the repository;
* - $identifyResponse['earliestDatestamp'] : compulsory. A UTCdatetime that is the guaranteed lower limit of all datestamps recording changes, modifications, or deletions in the repository. A repository must not use datestamps lower than the one specified by the content of the earliestDatestamp element. earliestDatestamp must be expressed at the finest granularity supported by the repository.
* - $identifyResponse['deletedRecord'] : the manner in which the repository supports the notion of deleted records. Legitimate values are no ; transient ; persistent with meanings defined in the section on deletion.
* - $identifyResponse['granularity'] : the finest harvesting granularity supported by the repository. The legitimate values are YYYY-MM-DD and YYYY-MM-DDThh:mm:ssZ with meanings as defined in ISO8601.
*
*/
$identifyResponse = array();
$identifyResponse["repositoryName"] = 'Moodle Neis';
$identifyResponse["baseURL"] = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
$identifyResponse["protocolVersion"] = '2.0';
$identifyResponse['adminEmail'] = 'danielneis@gmail.com';
$identifyResponse["earliestDatestamp"] = '2013-01-01T12:00:00Z';
$identifyResponse["deletedRecord"] = 'no'; // How your repository handles deletions
// no: The repository does not maintain status about deletions.
// It MUST NOT reveal a deleted status.
// persistent: The repository persistently keeps track about deletions
// with no time limit. It MUST consistently reveal the status
// of a deleted record over time.
// transient: The repository does not guarantee that a list of deletions is
// maintained. It MAY reveal a deleted status for records.
$identifyResponse["granularity"] = 'YYYY-MM-DDThh:mm:ssZ';
if (isset($args['verb'])) {
$repositoryIdentifier = 'dev2.moodle.ufsc.br.';
require_once('oai2server.php');
$oai2 = new OAI2Server($args);
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)) {
$outputObj = $oai2->identify($show_identifier, $repositoryIdentifier, $delimiter, $sampleIdentifier);
}
break;
case 'ListMetadataFormats':
$checkList = array("ops"=>array("identifier"));
checkArgs($args, $checkList);
if (empty($errors)) {
$outputObj = $oai2->listMetadataFormats();
}
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)) {
$outputObj = $oai2->listSets($SETS);
}
break;
case 'GetRecord':
$checkList = array("required"=>array("metadataPrefix","identifier"));
checkArgs($args, $checkList);
if (empty($errors)) {
$outputObj = $oai2->getRecord();
}
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)) {
$outputObj = $oai2->listRecords($SETS);
}
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();
}
$oai2 = new OAI2Server($args, $repositoryIdentifier, $identifyResponse);

View File

@ -1,8 +1,93 @@
<?php
/*
* - 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.
*/
class OAI2Server {
function __construct($args) {
public $errors = array();
/*
* @param $delimiter = ':'; should not be changed. Only useful when NODE description is included in the response to Identifier
*/
function __construct($args, $repositoryIdentifier, $identifyResponse,
$delimiter = ':', $sampleIdentifier = false, $show_identifier = false) {
$this->args = $args;
$this->repositoryIdentier = $repositoryIdentifier;
$this->identifyResponse = $identifyResponse;
$this->respond();
}
private function respond() {
if (!isset($this->args['verb']) || empty($this->args['verb'])) {
$this->errors[] = oai_error('noVerb');
} else {
switch ($this->args['verb']) {
case 'Identify':
// we never use compression in Identify
$compress = FALSE;
$this->outputObj = $this->identify();
break;
case 'ListMetadataFormats':
$this->outputObj = $this->listMetadataFormats();
break;
case 'ListSets':
$this->outputObj = $this->listSets();
break;
case 'ListIdentifiers':
case 'ListRecords':
$this->outputObj = $this->listRecords();
break;
case 'GetRecord':
$this->outputObj = $this->getRecord();
break;
default:
// we never use compression with errors
$compress = FALSE;
$this->errors[] = oai_error('badVerb', $this->args['verb']);
}
}
if (empty($this->errors)) {
$this->display();
} else {
$this->errorResponse();
}
}
function errorResponse() {
$e = new ANDS_Error_XML($this->args,$this->errors);
header(CONTENT_TYPE);
$e->display();
exit();
}
function display() {
if (isset($this->outputObj)) {
if ($compress) {
ob_start('ob_gzhandler');
}
header(CONTENT_TYPE);
$this->outputObj->display();
if ($compress) {
ob_end_flush();
}
} else {
exit("Nothing to output. May be a bug.");
}
}
/**
@ -13,10 +98,17 @@ class OAI2Server {
* http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm for details
*/
public function identify($show_identifier, $repositoryIdentifier, $delimiter, $sampleIdentifier) {
global $identifyResponse;
if (count($this->args) > 1) {
foreach($args as $key => $val) {
if(strcmp($key,"verb")!=0) {
$this->errors[] = oai_error('badArgument', $key, $val);
}
}
}
$outputObj = new ANDS_Response_XML($this->args);
foreach($identifyResponse as $key => $val) {
foreach($this->identifyResponse as $key => $val) {
$outputObj->add2_verbNode($key, $val);
}
@ -28,7 +120,7 @@ class OAI2Server {
// As they will not be changed, using string for simplicity.
$output = '';
if ($show_identifier && $repositoryIdentifier && $delimiter && $sampleIdentifier) {
if ($this->show_identifier && $this->repositoryIdentifier && $this->delimiter && $this->sampleIdentifier) {
$output .=
' <description>
<oai-identifier xmlns="http://www.openarchives.org/OAI/2.0/oai-identifier"
@ -137,6 +229,9 @@ class OAI2Server {
public function listMetadataFormats() {
global $DSN, $DB_USER, $DB_PASSWD, $METADATAFORMATS, $SQL;
$checkList = array("ops"=>array("identifier"));
$this->checkArgs($checkList);
// Create a PDO object
try {
$db = new PDO($DSN, $DB_USER, $DB_PASSWD);
@ -156,12 +251,12 @@ class OAI2Server {
echo "Query: $query<br />\n";
die($db->errorInfo());
} else {
$errors[] = oai_error('idDoesNotExist','', $identifier);
$this->errors[] = oai_error('idDoesNotExist','', $identifier);
}
} else {
$record = $res->fetch();
if($record===false) {
$errors[] = oai_error('idDoesNotExist', '', $identifier);
$this->errors[] = oai_error('idDoesNotExist', '', $identifier);
} else {
$mf = explode(",",$record[$SQL['metadataPrefix']]);
}
@ -169,8 +264,8 @@ class OAI2Server {
}
//break and clean up on error
if (!empty($errors)) {
oai_exit();
if (!empty($this->errors)) {
$this->errorResponse();
}
$outputObj = new ANDS_Response_XML($this->args);
@ -184,8 +279,8 @@ class OAI2Server {
$this->addMetedataFormat($outputObj,$key, $val);
}
} else { // a very unlikely event
$errors[] = oai_error('noMetadataFormats');
oai_exit();
$this->errors[] = oai_error('noMetadataFormats');
$this->errorResponse();
}
return $outputObj;
@ -197,7 +292,16 @@ class OAI2Server {
* Lists what sets are available to records in the system.
* This variable is filled in config-sets.php
*/
public function listSets($sets) {
public function listSets() {
global $SETS;
$sets = $SETS;
if (isset($this->args['resumptionToken']) && count($this->args) > 2) {
$this->errors[] = oai_error('exclusiveArgument');
}
$checkList = array("ops"=>array("resumptionToken"));
$this->checkArgs($checkList);
if (is_array($sets)) {
$outputObj = new ANDS_Response_XML($this->args);
@ -215,7 +319,7 @@ class OAI2Server {
}
}
} else {
$errors[] = oai_error('noSetHierarchy');
$this->errors[] = oai_error('noSetHierarchy');
oai_exit();
}
return $outputObj;
@ -233,12 +337,13 @@ class OAI2Server {
public function getRecord() {
global $METADATAFORMATS, $DSN, $DB_USER, $DB_PASSWD, $SQL;
$checkList = array("required"=>array("metadataPrefix","identifier"));
$this->checkArgs($checkList);
$metadataPrefix = $this->args['metadataPrefix'];
// myhandler is a php file which will be included to generate metadata node.
// $inc_record = $METADATAFORMATS[$metadataPrefix]['myhandler'];
if (!isset($METADATAFORMATS[$metadataPrefix])) {
$errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix);
$this->errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix);
}
// Create a PDO object
@ -254,18 +359,18 @@ class OAI2Server {
$res = $db->query($query);
if ($res===false) {
$errors[] = oai_error('idDoesNotExist', '', $identifier);
$this->errors[] = oai_error('idDoesNotExist', '', $identifier);
} elseif (!$res->rowCount()) { // based on PHP manual, it might only work for some DBs
$errors[] = oai_error('idDoesNotExist', '', $identifier);
$this->errors[] = oai_error('idDoesNotExist', '', $identifier);
}
if (!empty($errors)) {
if (!empty($this->errors)) {
oai_exit();
}
$record = $res->fetch(PDO::FETCH_ASSOC);
if ($record===false) {
$errors[] = oai_error('idDoesNotExist', '', $identifier);
$this->errors[] = oai_error('idDoesNotExist', '', $identifier);
}
$identifier = $record[$SQL['identifier']];;
@ -273,7 +378,7 @@ class OAI2Server {
$datestamp = formatDatestamp($record[$SQL['datestamp']]);
$status_deleted = (isset($record[$SQL['deleted']]) && ($record[$SQL['deleted']] == 'true') &&
($deletedRecord == 'transient' || $deletedRecord == 'persistent'));
($this->identifyResponse['deletedRecord'] == 'transient' || $this->identifyResponse['deletedRecord'] == 'persistent'));
$outputObj = new ANDS_Response_XML($this->args);
$cur_record = $outputObj->create_record();
@ -296,17 +401,29 @@ class OAI2Server {
* - Otherwise, set up a query with conditions such as: 'metadataPrefix', 'from', 'until', 'set'.
* Only 'metadataPrefix' is compulsory. All conditions are accessible through global array variable <B>$args</B> by keywords.
*/
public function listRecords($sets) {
global $SQL, $METADATAFORMATS, $DSN, $DB_USER, $DB_PASSWD;
public function listRecords() {
global $SQL, $METADATAFORMATS, $DSN, $DB_USER, $DB_PASSWD, $SETS;
$sets = $SETS;
if(isset($this->args['resumptionToken'])) {
if (count($this->args) > 2) {
$this->errors[] = oai_error('exclusiveArgument');
}
$checkList = array("ops"=>array("resumptionToken"));
} else {
$checkList = array("required"=>array("metadataPrefix"),"ops"=>array("from","until","set"));
}
$this->checkArgs($checkList);
// Resume previous session?
if (isset($this->args['resumptionToken'])) {
if (!file_exists(TOKEN_PREFIX.$this->args['resumptionToken'])) {
$errors[] = oai_error('badResumptionToken', '', $this->args['resumptionToken']);
$this->errors[] = oai_error('badResumptionToken', '', $this->args['resumptionToken']);
} else {
$readings = readResumToken(TOKEN_PREFIX.$this->args['resumptionToken']);
if ($readings == false) {
$errors[] = oai_error('badResumptionToken', '', $this->args['resumptionToken']);
$this->errors[] = oai_error('badResumptionToken', '', $this->args['resumptionToken']);
} else {
list($deliveredrecords, $extquery, $metadataPrefix) = $readings;
}
@ -331,46 +448,45 @@ class OAI2Server {
if (is_array($sets)) {
$extquery .= setQuery($this->args['set']);
} else {
$errors[] = oai_error('noSetHierarchy');
$this->errors[] = oai_error('noSetHierarchy');
}
}
}
if (!isset($METADATAFORMATS[$metadataPrefix])) {
$errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix);
$this->errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix);
}
if (!empty($errors)) {
oai_exit();
if (!empty($this->errors)) {
$this->errorResponse();
}
// Create a PDO object
try {
$db = new PDO($DSN, $DB_USER, $DB_PASSWD);
} catch (PDOException $e) {
exit('Connection failed: ' . $e->getMessage());
}
$query = selectallQuery($metadataPrefix) . $extquery;
$res = $db->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$r = $res->execute();
if ($r===false) {
$this->errors[] = oai_error('noRecordsMatch');
} else {
// Create a PDO object
try {
$db = new PDO($DSN, $DB_USER, $DB_PASSWD);
} catch (PDOException $e) {
exit('Connection failed: ' . $e->getMessage());
}
$query = selectallQuery($metadataPrefix) . $extquery;
$res = $db->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$r = $res->execute();
$r = $res->setFetchMode(PDO::FETCH_ASSOC);
if ($r===false) {
$errors[] = oai_error('noRecordsMatch');
} else {
$r = $res->setFetchMode(PDO::FETCH_ASSOC);
if ($r===false) {
exit("FetchMode is not supported");
}
$num_rows = rowCount($metadataPrefix, $extquery, $db);
if ($num_rows==0) {
$errors[] = oai_error('noRecordsMatch');
}
exit("FetchMode is not supported");
}
$num_rows = rowCount($metadataPrefix, $extquery, $db);
if ($num_rows==0) {
$this->errors[] = oai_error('noRecordsMatch');
}
}
if (!empty($errors)) {
oai_exit();
if (!empty($this->errors)) {
$this->errorResponse();
}
// Will we need a new ResumptionToken?
@ -415,11 +531,9 @@ class OAI2Server {
$datestamp = formatDatestamp($record[$SQL['datestamp']]);
$setspec = $record[$SQL['set']];
// debug_var_dump('record', $record);
$status_deleted = (isset($record[$SQL['deleted']]) && ($record[$SQL['deleted']] === true) &&
($deletedRecord == 'transient' || $deletedRecord == 'persistent'));
($this->identifyResponse['deletedRecord'] == 'transient' || $this->identifyResponse['deletedRecord'] == 'persistent'));
//debug_var_dump('status_deleted', $status_deleted);
if($this->args['verb']=='ListRecords') {
$cur_record = $outputObj->create_record();
$cur_header = $outputObj->create_header($identifier, $datestamp,$setspec,$cur_record);
@ -501,4 +615,68 @@ class OAI2Server {
}
}
}
/** Check if provided correct arguments for a request.
*
* Only number of parameters is checked.
* metadataPrefix has to be checked before it is used.
* set has to be checked before it is used.
* resumptionToken has to be checked before it is used.
* from and until can easily checked here because no extra information
* is needed.
*/
private function checkArgs($checkList) {
global $METADATAFORMATS;
// "verb" has been checked before, no further check is needed
$verb = $this->args["verb"];
$test_args = $this->args;
unset($test_args["verb"]);
if(isset($checkList['required'])) {
for($i = 0; $i < count($checkList["required"]); $i++) {
if(isset($test_args[$checkList['required'][$i]])==false) {
$this->errors[] = oai_error('missingArgument', $checkList["required"][$i]);
} else {
// if metadataPrefix is set, it is in required section
if(isset($test_args['metadataPrefix'])) {
$metadataPrefix = $test_args['metadataPrefix'];
// Check if the format is supported, it has enough infor (an array), last if a handle has been defined.
if (!array_key_exists($metadataPrefix, $METADATAFORMATS) ||
!(is_array($METADATAFORMATS[$metadataPrefix]) ||
!isset($METADATAFORMATS[$metadataPrefix]['myhandler']))) {
$this->errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix);
}
}
unset($test_args[$checkList["required"][$i]]);
}
}
}
if (!empty($this->errors)) return;
// check to see if there is unwanted
foreach($test_args as $key => $val) {
if(!in_array($key, $checkList["ops"])) {
$this->errors[] = oai_error('badArgument', $key, $val);
}
switch ($key) {
case 'from':
case 'until':
if(!checkDateFormat($val)) {
$this->errors[] = oai_error('badGranularity', $key, $val);
}
break;
case 'resumptionToken':
// only check for expairation
if((int)$val+TOKEN_VALID < time())
$this->errors[] = oai_error('badResumptionToken');
break;
}
}
}
}

View File

@ -1,21 +1,10 @@
<?php
/**
* \file
* \brief Configuration file of current data provider.
* brief Configuration file of current data provider.
*
* This is the configuration file for the PHP OAI Data Provider.
* Please read through the WHOLE file, there are several things, that
* need to be adjusted.
*
* The response may may be compressed for better performace:
* - Compression : a compression encoding supported by the repository. The recommended values are those defined for the Content-Encoding header in Section 14.11 of RFC 2616 describing HTTP 1.1. A compression element should not be included for the identity encoding, which is implied.
*
* Some other used variables:
*
* - <b>$repositoryIdentifier</b> : For a data provider there is only one. For repositories to comply with the oai
* format it has to be unique identifiers for items records. Basically using domainname will be fine.
* See: http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm.
*
* The rest of settings will not normally need to be adjusted. Read source code for details.
*/
@ -39,73 +28,10 @@ define('SHOW_QUERY_ERROR',FALSE);
// If everything is running ok, you should use this
define('CONTENT_TYPE', 'Content-Type: text/xml');
/**
* Identifier settings. It needs to have proper values to reflect the settings of the data provider.
*
* - $identifyResponse['repositoryName'] : compulsory. A human readable name for the repository;
* - $identifyResponse['baseURL'] : compulsory. The base URL of the repository;
* - $identifyResponse['protocolVersion'] : compulsory. The version of the OAI-PMH supported by the repository;
* - $identifyResponse['earliestDatestamp'] : compulsory. A UTCdatetime that is the guaranteed lower limit of all datestamps recording changes, modifications, or deletions in the repository. A repository must not use datestamps lower than the one specified by the content of the earliestDatestamp element. earliestDatestamp must be expressed at the finest granularity supported by the repository.
* - $identifyResponse['deletedRecord'] : the manner in which the repository supports the notion of deleted records. Legitimate values are no ; transient ; persistent with meanings defined in the section on deletion.
* - $identifyResponse['granularity'] : the finest harvesting granularity supported by the repository. The legitimate values are YYYY-MM-DD and YYYY-MM-DDThh:mm:ssZ with meanings as defined in ISO8601.
*
*/
$identifyResponse = array();
// MUST (only one)
// please adjust
$identifyResponse["repositoryName"] = 'Moodle Neis';
// For ANDS to harvest of RIF-CS, originatingSource is plantaccelerator.org.au
// $dataSource = "plantaccelerator.org.au";
define('DATASOURCE','dev2.moodle.ufsc.br');
// do not change
define('MY_URI','http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']);
// You can use a static URI as well.
// $baseURL = "http://my.server.org/oai/oai2.php";
$identifyResponse["baseURL"] = MY_URI;
// do not change
$identifyResponse["protocolVersion"] = '2.0';
// must exist before earliestDatestamp
$identifyResponse['adminEmail'] = 'danielneis@gmail.com';
// MUST (only one)
// the earliest datestamp in your repository,
// please adjust
// Only date is needed even later it will be formatted according to the granularity.
$identifyResponse["earliestDatestamp"] = '2013-01-01T12:00:00Z';
// How your repository handles deletions
// no: The repository does not maintain status about deletions.
// It MUST NOT reveal a deleted status.
// persistent: The repository persistently keeps track about deletions
// with no time limit. It MUST consistently reveal the status
// of a deleted record over time.
// transient: The repository does not guarantee that a list of deletions is
// maintained. It MAY reveal a deleted status for records.
//
// If your database keeps track of deleted records change accordingly.
// Currently if $record['deleted'] is set to 'true', $status_deleted is set.
// Some lines in listidentifiers.php, listrecords.php, getrecords.php
// must be changed to fit the condition for your database.
$identifyResponse["deletedRecord"] = 'no';
$deletedRecord = $identifyResponse["deletedRecord"]; // a shorthand for checking the configuration of Deleted Records
// MAY (only one)
//granularity is days
//$granularity = 'YYYY-MM-DD';
// granularity is seconds
$identifyResponse["granularity"] = 'YYYY-MM-DDThh:mm:ssZ';
// this is appended if your granularity is seconds.
// do not change
if (strcmp($identifyResponse["granularity"],'YYYY-MM-DDThh:mm:ssZ')==0) {
// $identifyResponse["earliestDatestamp"] = $identifyResponse["earliestDatestamp"].'T00:00:00Z';
}
/** Compression methods supported. Optional (multiple). Default: null.
*
* Currently only gzip is supported (you need output buffering turned on,
@ -121,24 +47,12 @@ $compression = null;
// see: http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm
// Basically use domainname
// please adjust
$repositoryIdentifier = 'dev2.moodle.ufsc.br.';
// For RIF-CS, especially with ANDS, each registryObject much has a group for the ownership of data.
// For detail please see ANDS guide on its web site. Each data provider should have only one REG_OBJ_GROUP
// for this purpose.
define('REG_OBJ_GROUP','Something agreed on');
// If Identifier needs to show NODE description. It is defined in identify.php
// You may include details about your community and friends (other
// data-providers).
// Please check identify.php for other possible containers
// in the Identify response
$show_identifier = false;
// MUST (only one)
// should not be changed. Only useful when NODE description is included in the response to Identifier
$delimiter = ':';
/** Maximum mumber of the records to deliver
* (verb is ListRecords)
* If there are more records to deliver

View File

@ -6,105 +6,6 @@
* A collection of functions used.
*/
/** Dump information of a varible for debugging,
* only works when SHOW_QUERY_ERROR is true.
* \param $var_name Type: string Name of variable is being debugded
* \param $var Type: mix Any type of varibles used in PHP
* \see SHOW_QUERY_ERROR in oaidp-config.php
*/
function debug_var_dump($var_name, $var) {
if (SHOW_QUERY_ERROR) {
echo "Dumping \${$var_name}: \n";
var_dump($var)."\n";
}
}
/** Prints human-readable information about a variable for debugging,
* only works when SHOW_QUERY_ERROR is true.
* \param $var_name Type: string Name of variable is being debugded
* \param $var Type: mix Any type of varibles used in PHP
* \see SHOW_QUERY_ERROR in oaidp-config.php
*/
function debug_print_r($var_name, $var) {
if (SHOW_QUERY_ERROR) {
echo "Printing \${$var_name}: \n";
print_r($var)."\n";
}
}
/** Prints a message for debugging,
* only works when SHOW_QUERY_ERROR is true.
* PHP function print_r can be used to construct message with <i>return</i> parameter sets to true.
* \param $msg Type: string Message needs to be shown
* \see SHOW_QUERY_ERROR in oaidp-config.php
*/
function debug_message($msg) {
if (SHOW_QUERY_ERROR) {
echo $msg,"\n";
}
}
/** Check if provided correct arguments for a request.
*
* Only number of parameters is checked.
* metadataPrefix has to be checked before it is used.
* set has to be checked before it is used.
* resumptionToken has to be checked before it is used.
* from and until can easily checked here because no extra information
* is needed.
*/
function checkArgs($args, $checkList) {
global $errors, $METADATAFORMATS;
// "verb" has been checked before, no further check is needed
unset($args["verb"]);
if(isset($checkList['required'])) {
for($i = 0; $i < count($checkList["required"]); $i++) {
if(isset($args[$checkList['required'][$i]])==false) {
$errors[] = oai_error('missingArgument', $checkList["required"][$i]);
} else {
// if metadataPrefix is set, it is in required section
if(isset($args['metadataPrefix'])) {
$metadataPrefix = $args['metadataPrefix'];
// Check if the format is supported, it has enough infor (an array), last if a handle has been defined.
if (!array_key_exists($metadataPrefix, $METADATAFORMATS) ||
!(is_array($METADATAFORMATS[$metadataPrefix]) ||
!isset($METADATAFORMATS[$metadataPrefix]['myhandler']))) {
$errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix);
}
}
unset($args[$checkList["required"][$i]]);
}
}
}
if (!empty($errors)) return;
// check to see if there is unwanted
foreach($args as $key => $val) {
if(!in_array($key, $checkList["ops"])) {
$errors[] = oai_error('badArgument', $key, $val);
}
switch ($key) {
case 'from':
case 'until':
if(!checkDateFormat($val)) {
$errors[] = oai_error('badGranularity', $key, $val);
}
break;
case 'resumptionToken':
// only check for expairation
if((int)$val+TOKEN_VALID < time())
$errors[] = oai_error('badResumptionToken');
break;
}
}
}
/** Validates an identifier. The pattern is: '/^[-a-z\.0-9]+$/i' which means
* it accepts -, letters and numbers.
* Used only by function <B>oai_error</B> code idDoesNotExist.
@ -158,25 +59,6 @@ function prepare_set_names() {
return $a;
}
/** Finish a request when there is an error: send back errors. */
function oai_exit() {
// global $CONTENT_TYPE;
header(CONTENT_TYPE);
global $args,$errors,$compress;
$e = new ANDS_Error_XML($args,$errors);
if ($compress) {
ob_start('ob_gzhandler');
}
$e->display();
if ($compress) {
ob_end_flush();
}
exit();
}
// ResumToken section
/** Generate a string based on the current Unix timestamp in microseconds for creating resumToken file name. */
function get_token() {