diff --git a/src/oaipmh-expose/class-tainacan-oaipmh-expose.php b/src/oaipmh-expose/class-tainacan-oaipmh-expose.php index 79ae52fa3..00890446c 100644 --- a/src/oaipmh-expose/class-tainacan-oaipmh-expose.php +++ b/src/oaipmh-expose/class-tainacan-oaipmh-expose.php @@ -26,6 +26,8 @@ class OAIPMH_Expose { var $xmlescaped; var $text; var $code; + var $token_valid; + var $token_prefix; /** * @@ -68,25 +70,21 @@ class OAIPMH_Expose { * If there are more records to deliver * a ResumptionToken will be generated. */ - $this->MAXRECORDS = 100; - - /** Maximum mumber of identifiers to deliver - * (verb is ListIdentifiers) - * If there are more identifiers to deliver - * a ResumptionToken will be generated. - */ - define('MAXIDS', 100); + $this->MAXRECORDS = has_filter( 'tainacan-oai-maxrecords' ) ? apply_filters('tainacan-oai-maxrecords', 100) : 100; /** After 24 hours resumptionTokens become invalid. Unit is second. */ - define('TOKEN_VALID', 24 * 3600); - define('MY_URI', get_bloginfo( 'url' )); + $this->token_valid = has_filter( 'tainacan-oai-token-valid' ) ? apply_filters('tainacan-oai-token-valid', 24 * 3600) : 24 * 3600; - $this->expirationdatetime = gmstrftime('%Y-%m-%dT%TZ', time() + TOKEN_VALID); + if ( !defined('TAINACAN_OAI_REPOSITORY_URL') ) { + define('TAINACAN_OAI_REPOSITORY_URL', get_bloginfo( 'url' )); + } + + $this->expirationdatetime = gmstrftime('%Y-%m-%dT%TZ', time() + $this->token_valid); /** Where token is saved and path is included */ $token_path = $this->create_token_dir(); if($token_path){ - define('TOKEN_PREFIX', $token_path); + $this->token_prefix = $token_path; } $this->METADATAFORMATS = array( @@ -98,13 +96,11 @@ class OAIPMH_Expose { 'record_namespace' => 'http://purl.org/dc/elements/1.1/' ) ); - $this->supported_formats = array('oai_dc'); if (!is_array($this->METADATAFORMATS)) { exit("Configuration of METADATAFORMAT has been wrongly set. Correct your " . __FILE__); } - define('XMLSCHEMA', 'http://www.w3.org/2001/XMLSchema-instance'); $this->charset = "iso8859-1"; $this->xmlescaped = false; } @@ -211,7 +207,7 @@ class OAIPMH_Expose { */ function createResumToken($cursor, $from,$until,$sets, $metadataPrefix) { $token = $this->get_token(); - $fp = fopen(TOKEN_PREFIX . $token, 'w'); + $fp = fopen($this->token_prefix . $token, 'w'); if ($fp == false) { exit("Cannot write. Writer permission needs to be changed."); } diff --git a/src/oaipmh-expose/class-tainacan-oaipmh-get-record.php b/src/oaipmh-expose/class-tainacan-oaipmh-get-record.php index 1f3328fd5..a68ef4217 100644 --- a/src/oaipmh-expose/class-tainacan-oaipmh-get-record.php +++ b/src/oaipmh-expose/class-tainacan-oaipmh-get-record.php @@ -182,10 +182,10 @@ class OAIPMH_Get_Record extends OAIPMH_Expose { if ( isset($data['resumptionToken']) ) { - if ( !file_exists(TOKEN_PREFIX . $data['resumptionToken']) ) { + if ( !file_exists($this->token_prefix . $data['resumptionToken']) ) { $this->errors[] = $this->oai_error('badResumptionToken', '', $data['resumptionToken']); } else { - $readings = $this->readResumToken(TOKEN_PREFIX . $data['resumptionToken']); + $readings = $this->readResumToken($this->token_prefix . $data['resumptionToken']); if ($readings == false) { $this->errors[] = $this->oai_error('badResumptionToken', '', $data['resumptionToken']); } else { diff --git a/src/oaipmh-expose/class-tainacan-oaipmh-list-identifiers.php b/src/oaipmh-expose/class-tainacan-oaipmh-list-identifiers.php index 586d7943f..280a3bc15 100644 --- a/src/oaipmh-expose/class-tainacan-oaipmh-list-identifiers.php +++ b/src/oaipmh-expose/class-tainacan-oaipmh-list-identifiers.php @@ -153,10 +153,10 @@ class OAIPMH_List_Identifiers extends OAIPMH_Expose { if ( isset($data['resumptionToken']) ) { - if ( !file_exists(TOKEN_PREFIX . $data['resumptionToken']) ) { + if ( !file_exists($this->token_prefix . $data['resumptionToken']) ) { $this->errors[] = $this->oai_error('badResumptionToken', '', $data['resumptionToken']); } else { - $readings = $this->readResumToken(TOKEN_PREFIX . $data['resumptionToken']); + $readings = $this->readResumToken($this->token_prefix . $data['resumptionToken']); if ($readings == false) { $this->errors[] = $this->oai_error('badResumptionToken', '', $data['resumptionToken']); } else { @@ -212,7 +212,7 @@ class OAIPMH_List_Identifiers extends OAIPMH_Expose { } $this->cursor = (int) $this->deliveredrecords + $this->MAXRECORDS; $this->restoken = $this->createResumToken($this->cursor, $this->from,$this->until,$this->sets, $this->metadataPrefix); - $this->expirationdatetime = date("Y-m-d\TH:i:s\Z", time() * TOKEN_VALID); + $this->expirationdatetime = date("Y-m-d\TH:i:s\Z", time() * $this->token_valid); } } diff --git a/src/oaipmh-expose/class-tainacan-oaipmh-list-records.php b/src/oaipmh-expose/class-tainacan-oaipmh-list-records.php index a6b046590..c7a03c734 100644 --- a/src/oaipmh-expose/class-tainacan-oaipmh-list-records.php +++ b/src/oaipmh-expose/class-tainacan-oaipmh-list-records.php @@ -231,10 +231,10 @@ class OAIPMH_List_Records extends OAIPMH_Expose { if ( isset($data['resumptionToken']) ) { - if ( !file_exists(TOKEN_PREFIX . $data['resumptionToken']) ) { + if ( !file_exists($this->token_prefix . $data['resumptionToken']) ) { $this->errors[] = $this->oai_error('badResumptionToken', '', $data['resumptionToken']); } else { - $readings = $this->readResumToken(TOKEN_PREFIX . $data['resumptionToken']); + $readings = $this->readResumToken($this->token_prefix . $data['resumptionToken']); if ($readings == false) { $this->errors[] = $this->oai_error('badResumptionToken', '', $data['resumptionToken']); } else { @@ -290,7 +290,7 @@ class OAIPMH_List_Records extends OAIPMH_Expose { } $this->cursor = (int) $this->deliveredrecords + $this->MAXRECORDS; $this->restoken = $this->createResumToken($this->cursor, $this->from,$this->until,$this->sets, $this->metadataPrefix); - $this->expirationdatetime = date("Y-m-d\TH:i:s\Z", time() * TOKEN_VALID); + $this->expirationdatetime = date("Y-m-d\TH:i:s\Z", time() * $this->token_valid); } } diff --git a/src/oaipmh-expose/class-tainacan-oaipmh-list-sets.php b/src/oaipmh-expose/class-tainacan-oaipmh-list-sets.php index 32fbe9077..894529942 100644 --- a/src/oaipmh-expose/class-tainacan-oaipmh-list-sets.php +++ b/src/oaipmh-expose/class-tainacan-oaipmh-list-sets.php @@ -122,10 +122,10 @@ class OAIPMH_List_Sets extends OAIPMH_Expose { if (isset($data['resumptionToken'])) { - if (!file_exists(TOKEN_PREFIX . $data['resumptionToken'])) { + if (!file_exists($this->token_prefix . $data['resumptionToken'])) { $this->errors[] = $this->oai_error('badResumptionToken', '', $data['resumptionToken']); } else { - $readings = $this->readResumToken(TOKEN_PREFIX . $data['resumptionToken']); + $readings = $this->readResumToken($this->token_prefix . $data['resumptionToken']); if ($readings == false) { $this->errors[] = $this->oai_error('badResumptionToken', '', $data['resumptionToken']); } else { @@ -158,9 +158,7 @@ class OAIPMH_List_Sets extends OAIPMH_Expose { } $this->cursor = (int) $this->deliveredrecords + $this->MAXRECORDS; $this->restoken = $this->createResumToken($this->cursor, $this->from,$this->until,$this->sets, $this->metadataPrefix); - // var_dump(time() + TOKEN_VALID,date("Y-m-d\TH:i:s\Z", time() + TOKEN_VALID)); - $this->expirationdatetime = date("Y-m-d\TH:i:s\Z", time() + TOKEN_VALID); - //$this->expirationdatetime = gmstrftime('%Y-%m-%d\T%T\Z', time() + TOKEN_VALID); + $this->expirationdatetime = date("Y-m-d\TH:i:s\Z", time() + $this->token_valid); } } diff --git a/src/oaipmh-expose/class-tainacan-xml-create.php b/src/oaipmh-expose/class-tainacan-xml-create.php index ad9520aeb..47692d56b 100644 --- a/src/oaipmh-expose/class-tainacan-xml-create.php +++ b/src/oaipmh-expose/class-tainacan-xml-create.php @@ -94,7 +94,7 @@ class Xml_Create { * Keys of the array define attributes, and values are their content. */ function create_request($par_array) { - $request = $this->addChild($this->doc->documentElement, "request", MY_URI); + $request = $this->addChild($this->doc->documentElement, "request", TAINACAN_OAI_REPOSITORY_URL); foreach ($par_array as $key => $value) { $request->setAttribute($key, $value); }