From 57440dd5c9ee1719c51639c2f744e287444b93b7 Mon Sep 17 00:00:00 2001 From: Amaury Balmer Date: Fri, 17 Feb 2023 16:28:24 +0100 Subject: [PATCH] add description on identify route --- Classes/Server.php | 30 +++++++++++++++++++++++++++++- Configuration/Main.php | 6 ++++++ index.php | 3 ++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Classes/Server.php b/Classes/Server.php index 79ba8ff..3c32bfe 100644 --- a/Classes/Server.php +++ b/Classes/Server.php @@ -39,6 +39,9 @@ class Server private $token_prefix = ''; private $token_valid = 86400; + const NS_URI_OAI_DC = 'http://www.openarchives.org/OAI/2.0/oai_dc/'; + const NS_URI_DC = 'http://purl.org/dc/elements/1.1/'; + public function __construct($uri, $args, $identifyResponse, $callbacks, $config) { $this->uri = $uri; @@ -92,7 +95,32 @@ public function Identify() $cmf = $this->response->addToVerbNode('Identify', null, true); foreach ($this->identifyResponse as $key => $val) { - $this->response->addChild($cmf, $key, $val); + if ( $key === 'description' ) { + $element = $this->response->doc->createElement( 'description' ); + $metadata_node = $cmf->appendChild( $element ); + + $element = $this->response->doc->createElement( 'oai_dc:dc' ); + $element->setAttribute( 'xmlns:oai_dc', self::NS_URI_OAI_DC ); + $element->setAttribute( 'xmlns', 'http://www.openarchives.org/OAI/2.0/' ); + $element->setAttribute( 'xmlns:dc', 'http://purl.org/dc/elements/1.1/' ); + $element->setAttribute( 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance' ); + $element->setAttribute( 'xsi:schemaLocation', + 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd' ); + $sub_description_node = $metadata_node->appendChild( $element ); + + foreach ( $val as $_key => $content ) { + if ( 'identifier' == $_key ) { + $element = $this->response->doc->createElement( 'dc:identifier', htmlspecialchars( html_entity_decode( $content, ENT_QUOTES, 'UTF-8' ), ENT_XML1, 'UTF-8' ) ); + } else { + $element = $this->response->doc->createElement( 'dc:description', htmlspecialchars( html_entity_decode( $content, ENT_QUOTES, 'UTF-8' ), ENT_XML1, 'UTF-8' ) ); + $element->setAttribute( 'xml:lang', str_replace('lang:', '', $_key) ); + } + + $sub_description_node->appendChild( $element ); + } + } else { + $this->response->addChild($cmf, $key, $val); + } } } } diff --git a/Configuration/Main.php b/Configuration/Main.php index 8c447d1..c4afb05 100644 --- a/Configuration/Main.php +++ b/Configuration/Main.php @@ -56,6 +56,12 @@ 'oai_dc' => [ 'schema' => 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd', 'namespace' => 'http://www.openarchives.org/OAI/2.0/oai_dc/', + 'description' => array( + 'identifier' => 'https://urloftheoairepo/', + 'lang:fre' => 'French language description of the OAI warehouse.', + 'lang:eng' => 'English language description of the OAI warehouse.' + // You can add any additional languages + ) ], ], diff --git a/index.php b/index.php index 9be7def..f21de39 100644 --- a/index.php +++ b/index.php @@ -50,7 +50,8 @@ 'adminEmail' => $config->getConfigValue('adminEmail'), 'earliestDatestamp' => gmdate('Y-m-d\TH:i:s\Z', $data->getEarliest()), 'deletedRecord' => $config->getConfigValue('deletedRecord'), - 'granularity' => 'YYYY-MM-DDThh:mm:ssZ' + 'granularity' => 'YYYY-MM-DDThh:mm:ssZ', + 'description' => $config->getConfigValue('metadataPrefix')['oai_dc']['description'] ]; $oai2 = new Server(