/** * Answer the current harvester config array * * @return string * @access public * @static * @since 3/9/07 */ static function getCurrentHarvesterConfig() { global $errors; $harmoni = Harmoni::instance(); $config = $harmoni->getAttachedData('OAI_CONFIG'); if ($config->getProperty('ENABLE_OAI')) { $harvesterConfig = $config->getProperty('OAI_HARVESTER_CONFIG'); foreach ($harvesterConfig as $configArray) { if (!count($configArray["ips_allowed"])) { return $configArray; } else { foreach ($configArray["ips_allowed"] as $ipRange) { $ipRange = str_replace(".", "\\.", $ipRange); if (preg_match('/^' . $ipRange . '/', $_SERVER['REMOTE_ADDR'])) { return $configArray; } } } } require_once dirname(__FILE__) . "/phpoai2/oai2/oaidp-util.php"; require_once dirname(__FILE__) . "/phpoai2/oai2/oaidp-config.php"; $errors .= oai_error('unauthorizedHarvesterIP', "\$_SERVER['REMOTE_ADDR']", $_SERVER['REMOTE_ADDR']); } else { require_once dirname(__FILE__) . "/phpoai2/oai2/oaidp-util.php"; require_once dirname(__FILE__) . "/phpoai2/oai2/oaidp-config.php"; // throwError(new Error('harvesting disabled')); $errors .= oai_error('harvestingDisabled'); } oai_exit(); }
$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) { echo "Cannot find records: {$query}\n"; $errors[] = oai_error('noRecordsMatch'); } } } if (!empty($errors)) { oai_exit(); } // Will we need a new ResumptionToken? if ($args['verb'] == 'ListRecords') { $maxItems = MAXRECORDS; } elseif ($args['verb'] == 'ListIdentifiers') { $maxItems = MAXIDS; } else { exit("Check " . __FILE__ . " " . __LINE__ . ", there is something wrong."); } $maxrec = min($num_rows - $deliveredrecords, $maxItems); if ($num_rows - $deliveredrecords > $maxItems) { $cursor = (int) $deliveredrecords + $maxItems; $restoken = createResumToken($cursor, $extquery, $metadataPrefix); $expirationdatetime = gmstrftime('%Y-%m-%dT%TZ', time() + TOKEN_VALID); } elseif (isset($args['resumptionToken'])) {
$checkList = array("required"=>array("metadataPrefix"),"ops"=>array("from","until","set")); } checkArgs($args, $checkList); if (empty($errors)) include 'listrecords.php'; 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();
/** * Index function. * * @noinspection PhpUnusedLocalVariableInspection */ public function indexAction() { // Need to define some variables global so they can // be accessed by the OAI classes global $output; global $xmlheader; global $errors; global $granularity; global $SQL; global $METADATAFORMATS; global $XMLSCHEMA; $output = ''; $errors = ''; if ($this->isTestingEnv()) { $_SERVER['SERVER_NAME'] = 'localhost'; $_SERVER['REQUEST_METHOD'] = 'GET'; unset($_GET['enabledModules']); } $MY_URI = 'http://' . $_SERVER['SERVER_NAME'] . $this->view->webroot . '/oai'; $compression = array('gzip', 'deflate'); $XMLHEADER = '<?xml version="1.0" encoding="UTF-8"?> <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">' . "\n"; $responseDate = gmstrftime('%Y-%m-%dT%H:%M:%S') . 'Z'; $xmlheader = $XMLHEADER . ' <responseDate>' . $responseDate . "</responseDate>\n"; $repositoryName = $this->Setting->getValueByName(OAI_REPOSITORY_NAME_KEY, $this->moduleName); $baseURL = $MY_URI; $protocolVersion = '2.0'; $adminEmail = $this->Setting->getValueByName(OAI_ADMIN_EMAIL_KEY, $this->moduleName); $earliestDatestamp = 'T00:00:00Z'; $deletedRecord = 'persistent'; $granularity = 'YYYY-MM-DDThh:mm:ssZ'; $show_identifier = false; $repositoryIdentifier = $this->Setting->getValueByName(OAI_REPOSITORY_IDENTIFIER_KEY, $this->moduleName); $delimiter = ':'; $idPrefix = ''; $oaiprefix = 'oai' . $delimiter . $repositoryIdentifier . $delimiter . $idPrefix; $setspecprefix = 'hdl_'; $METADATAFORMATS = 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/', 'myhandler' => 'record_dc.php', 'record_prefix' => 'dc', 'record_namespace' => 'http://purl.org/dc/elements/1.1/')); $MAXIDS = 5; $MAXRECORDS = 5; $tokenValid = 24 * 3600; $expirationdatetime = gmstrftime('%Y-%m-%dT%H:%M:%SZ', time() + $tokenValid); $SQL['split'] = ';'; $XMLSCHEMA = 'http://www.w3.org/2001/XMLSchema-instance'; $MidasTempDirectory = $this->getTempDirectory(); require_once BASE_PATH . '/modules/oai/library/oai/oaidp-util.php'; if ($_SERVER['REQUEST_METHOD'] == 'GET') { $args = $_GET; } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { $args = $_POST; } else { $errors .= oai_error('badRequestMethod', $_SERVER['REQUEST_METHOD']); } // Some fixes for CakePHP unset($args['url']); $reqattr = ''; if (is_array($args)) { foreach ($args as $key => $val) { $reqattr .= ' ' . $key . '="' . htmlspecialchars(stripslashes($val)) . '"'; } } // in case register_globals is on, clean up polluted global scope $verbs = array('from', 'identifier', 'metadataPrefix', 'set', 'resumptionToken', 'until'); foreach ($verbs as $val) { unset(${$val}); } $request = ' <request' . $reqattr . '>' . $MY_URI . "</request>\n"; $request_err = ' <request>' . $MY_URI . "</request>\n"; if (is_array($compression)) { $compress = false; } if (isset($args['verb'])) { switch ($args['verb']) { case 'GetRecord': unset($args['verb']); include BASE_PATH . '/modules/oai/library/oai/getrecord.php'; break; case 'Identify': unset($args['verb']); // we never use compression in Identify $compress = false; include BASE_PATH . '/modules/oai/library/oai/identify.php'; break; case 'ListIdentifiers': unset($args['verb']); include BASE_PATH . '/modules/oai/library/oai/listidentifiers.php'; break; case 'ListMetadataFormats': unset($args['verb']); include BASE_PATH . '/modules/oai/library/oai/listmetadataformats.php'; break; case 'ListRecords': unset($args['verb']); include BASE_PATH . '/modules/oai/library/oai/listrecords.php'; break; case 'ListSets': unset($args['verb']); include BASE_PATH . '/modules/oai/library/oai/listsets.php'; break; default: // we never use compression with errors $compress = false; $errors .= oai_error('badVerb', $args['verb']); } /* switch */ } else { $errors .= oai_error('noVerb'); } if ($errors != '' && $this->isTestingEnv()) { echo $errors; } elseif ($errors != '') { oai_exit(); } if ($compress) { ob_start('ob_gzhandler'); } $this->disableLayout(); $this->disableView(); if (!$this->isTestingEnv()) { header('Content-Type: text/plain'); } echo $xmlheader; echo $request; echo $output; if (!$this->isTestingEnv()) { oai_close(); exit; } }