From fc28928f563b85a4489315168f5394c56decb564 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Thu, 4 May 2017 16:29:45 +0200 Subject: [PATCH] Removed OAI client and Moodle integration --- client.php | 12 ---- moodle.php | 147 ------------------------------------------------- oai2client.php | 85 ---------------------------- 3 files changed, 244 deletions(-) delete mode 100644 client.php delete mode 100644 moodle.php delete mode 100644 oai2client.php diff --git a/client.php b/client.php deleted file mode 100644 index 4fc6c1d..0000000 --- a/client.php +++ /dev/null @@ -1,12 +0,0 @@ -Identify()); -var_dump($client->ListMetadataFormats()); -var_dump($client->ListSets()); -var_dump($client->ListIdentifiers(array('metadataPrefix' => 'oai_dc'))); -var_dump($client->ListRecords(array('metadataPrefix' => 'oai_dc'))); -var_dump($client->GetRecord('aaaaa', 'oai_dc')); diff --git a/moodle.php b/moodle.php deleted file mode 100644 index 84f801e..0000000 --- a/moodle.php +++ /dev/null @@ -1,147 +0,0 @@ -fullname;; -$identifyResponse["baseURL"] = $CFG->wwwroot.'/local/oai_pmh/moodle.php'; -$identifyResponse["protocolVersion"] = '2.0'; -$identifyResponse['adminEmail'] = $adminEmail->email; -$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($uri)) { - $uri = 'test.oai_pmh'; -} -$uri = parse_url($CFG->wwwroot); -$oai2 = new OAI2Server($uri['host'], $_GET, $identifyResponse, - array( - 'ListMetadataFormats' => - function($identifier = '') { - return array('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/', - 'record_prefix'=>'dc', - 'record_namespace' => 'http://purl.org/dc/elements/1.1/')); - }, - - 'ListSets' => - function($resumptionToken = '') { - return array (array('setSpec' => 'all', 'setName' => 'All files')); - }, - - 'ListRecords' => - function($metadataPrefix, $from = '', $until = '', $set = '', $count = false, $deliveredRecords = 0, $maxItems = 0) { - global $DB; - - if ($metadataPrefix != 'oai_dc') { - throw new OAI2Exception('noRecordsMatch'); - } - - $files = array(); - $fs = get_file_storage(); - $hashes = $DB->get_records_sql("SELECT DISTINCT pathnamehash as hash FROM files"); - foreach ($hashes as $h) { - if ($file = $fs->get_file_by_hash($h->hash)) { - $files[] = $file; - } - } - if ($count) { - return sizeof($files); - } - if (empty($files)) { - throw new OAI2Exception('noRecordsMatch'); - } - $records = array(); - $now = date('Y-m-d-H:s'); - foreach ($files as $f) { - $filename = $f->get_filename(); - if (!empty($filename) && ($filename != ' ') && $filename != '.') { - $records[] = array('identifier' => $f->get_contenthash(), - 'datestamp' => $now, - 'set' => 'all', - 'metadata' => array( - 'container_name' => 'oai_dc:dc', - 'container_attributes' => array( - 'xmlns:oai_dc' => "http://www.openarchives.org/OAI/2.0/oai_dc/", - 'xmlns:dc' => "http://purl.org/dc/elements/1.1/", - 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", - 'xsi:schemaLocation' => - 'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd' - ), - 'fields' => array( - 'dc:title' => $f->get_filename(), - 'dc:author' => $f->get_author(), - ) - )); - } - } - return $records; - }, - - 'GetRecord' => - function($identifier, $metadataPrefix) { - global $DB; - - if ($metadataPrefix != 'oai_dc') { - throw new OAI2Exception('noRecordsMatch'); - } - - $fs = get_file_storage(); - $record = $DB->get_record_sql("SELECT id, pathnamehash FROM files WHERE contenthash = '{$identifier}' ORDER BY id LIMIT 1"); - if (!$file = $fs->get_file_by_hash($record->pathnamehash)) { - throw new OAI2Exception('idDoesNotExist'); - } - $now = date('Y-m-d-H:s'); - return array('identifier' => $file->get_contenthash(), - 'datestamp' => $now, - 'set' => 'all', - 'metadata' => array( - 'container_name' => 'oai_dc:dc', - 'container_attributes' => array( - 'xmlns:oai_dc' => "http://www.openarchives.org/OAI/2.0/oai_dc/", - 'xmlns:dc' => "http://purl.org/dc/elements/1.1/", - 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", - 'xsi:schemaLocation' => - 'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd' - ), - 'fields' => array( - 'dc:title' => $file->get_filename(), - 'dc:author' => $file->get_author(), - ) - )); - }, - ) -); - -$response = $oai2->response(); -$response->formatOutput = true; -$response->preserveWhiteSpace = false; -header('Content-Type: text/xml'); -echo $response->saveXML(); diff --git a/oai2client.php b/oai2client.php deleted file mode 100644 index 17cd461..0000000 --- a/oai2client.php +++ /dev/null @@ -1,85 +0,0 @@ - blocks may be re-assembled at the item level if it - * is the same for all metadata formats harvested. However, this information may be supplied - * differently for different metadata formats and may thus need to be store separately for each - * metadata format. - */ - -class OAI2Client { - - public function __construct($server_base_url) { - $this->server_base_url = $server_base_url; - require_once('./curl.php'); - $this->curl = new Curl(); - } - - public function Identify() { - return $this->curl->get($this->server_base_url.'?verb=Identify'); - } - - public function ListMetadataFormats($identifier = '') { - $url = $this->server_base_url.'?verb=ListMetadataFormats'; - if (!empty($identifier)) { - $url .= "&identifier={$identifier}"; - } - return $this->curl->get($url); - } - - public function ListSets($resumptionToken = '') { - $url = $this->server_base_url.'?verb=ListSets'; - return $this->curl->get($url); - } - - public function ListIdentifiers($options = array()) { - - $options_default = array('from' => null, - 'until' => null, - 'set' => null, - 'resumptionToken' => null, - 'metadataPrefix' => null); // required - - $url = $this->server_base_url.'?verb=ListIdentifiers'; - - if (!empty($options['metadataPrefix'])) { - $url .= "&metadataPrefix={$options['metadataPrefix']}"; - } - return $this->curl->get($url); - } - - public function ListRecords($options = array()) { - - $options_default = array('from' => null, - 'until' => null, - 'set' => null, - 'resumptionToken' => null, - 'metadataPrefix' => null); // required - - $url = $this->server_base_url.'?verb=ListRecords'; - - if (!empty($options['metadataPrefix'])) { - $url .= "&metadataPrefix={$options['metadataPrefix']}"; - } - return $this->curl->get($url); - } - - public function GetRecord($identifier, $metadataPrefix) { - $url = $this->server_base_url.'?verb=ListRecords'; - $url .= "&identifier={$identifier}&metadataPrefix={$metadataPrefix}"; - return $this->curl->get($url); - } -}