From e1f59e2c6634e983cf084d23373d8eebfb383143 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Fri, 9 Jun 2017 18:50:11 +0200 Subject: [PATCH] Make data directory configurable --- README.md | 4 ++-- index.php | 7 ++++--- oai2config.php | 4 ++++ oai2server.php | 6 +++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 65195b3..99c3cce 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ Installation 1. Deploy all the files to a webserver. -2. Put the records into the data/ directory (or create a symlink named "data" pointing to your records). Each record has to be a separate XML file with its identifier as filename (i.e. 12345678.xml). +2. Edit oai2config.php and adjust the settings according to your preferences. -3. Edit oai2config.php and adjust the settings according to your preferences. +3. Put the records into the specified data directory. Each record has to be a separate XML file with its identifier as filename (i.e. 12345678.xml). 4. Congratulations! Now you are running an OAI-PMH 2.0 compatible data provider. diff --git a/index.php b/index.php index 3eaa45c..8c25a21 100644 --- a/index.php +++ b/index.php @@ -27,7 +27,7 @@ require_once('oai2server.php'); $records = array(); $timestamps = array(); -$files = glob('data/*.xml'); +$files = glob(rtrim($config['dataDirectory'], '/').'/*.xml'); foreach($files as $file) { $records[pathinfo($file, PATHINFO_FILENAME)] = $file; $timestamps[filemtime($file)][] = pathinfo($file, PATHINFO_FILENAME); @@ -40,10 +40,11 @@ ksort($timestamps); reset($timestamps); // Get current base URL +$baseURL = $_SERVER['HTTP_HOST'].parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { - $baseURL = 'https://'.$_SERVER['HTTP_HOST'].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); + $baseURL = 'https://'.$baseURL; } else { - $baseURL = 'http://'.$_SERVER['HTTP_HOST'].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); + $baseURL = 'http://'.$baseURL; } // Build the Identify response diff --git a/oai2config.php b/oai2config.php index edaad70..a3e0053 100644 --- a/oai2config.php +++ b/oai2config.php @@ -37,6 +37,10 @@ $config['metadataFormat'] = 'oai_dc'; $config['metadataSchema'] = 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd'; $config['metadataNamespace'] = 'http://www.openarchives.org/OAI/2.0/oai_dc/'; +// Directory containing the records +// (Make sure the given path is readable) +$config['dataDirectory'] = 'data/'; + // Maximum number of records to return before giving a resumption token $config['maxRecords'] = 100; diff --git a/oai2server.php b/oai2server.php index 18c7ce4..fd5c7ac 100644 --- a/oai2server.php +++ b/oai2server.php @@ -68,8 +68,8 @@ class OAI2Server { $errorResponse = new OAI2XMLResponse($this->uri, $this->verb, $this->args); $oai_node = $errorResponse->doc->documentElement; foreach($this->errors as $e) { - $node = $errorResponse->addChild($oai_node,"error",$e->getMessage()); - $node->setAttribute("code",$e->getOAI2Code()); + $node = $errorResponse->addChild($oai_node, 'error', $e->getMessage()); + $node->setAttribute('code', $e->getOAI2Code()); } return $errorResponse->doc; } @@ -248,7 +248,7 @@ class OAI2Server { list($usec, $sec) = explode(' ', microtime()); $token = ((int)($usec*1000) + (int)($sec*1000)); $fp = fopen ($this->token_prefix.$token, 'w'); - if($fp==false) { + if($fp == false) { exit('Cannot write resumption token. Writing permission needs to be changed.'); } $values = array(