/** * 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(); }
echo __FILE__ . ',' . __LINE__ . "<br />"; echo "Query: {$query}<br />\n"; print_r($db->errorInfo()); exit; } else { $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);
$countrec = 0; while ($countrec++ < $maxrec) { $element = $items[$countrec - 1]; if (!$element instanceof ItemDao || !$itemModel->policyCheck($element, null, MIDAS_POLICY_READ)) { continue; } $identifier = $oaiprefix . $element->getUuid(); $datestamp = formatDatestamp($element->getDateUpdate()); $output .= ' <record>' . "\n"; $output .= ' <header>' . "\n"; $output .= xmlformat($identifier, 'identifier', '', 4); $output .= xmlformat($datestamp, 'datestamp', '', 4); // return the metadata record itself $folders = $element->getFolders(); if (empty($folders)) { $errors .= oai_error('resourceIdDoesNotExist', '', $record[1]); } foreach ($folders as $folder) { $setspec = $setspecprefix . str_replace('/', '_', $folder->getUuid()); $output .= xmlrecord($setspec, 'setSpec', '', 3); } $output .= ' </header>' . "\n"; $revision = $itemModel->getLastRevision($element); if ($revision === false) { throw new Zend_Exception('The item must have at least one revision to have metadata', MIDAS_INVALID_POLICY); } $metadata = $itemRevisionModel->getMetadata($revision); include BASE_PATH . '/modules/oai/library/oai/' . $inc_record; $output .= ' </record>' . "\n"; } // ResumptionToken
} else { $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();
/** Check if provided correct arguments for a request. * * Only number of parameters is checked. * metadataPrefix has to be checked before it is used. * set has to be checked before it is used. * resumptionToken has to be checked before it is used. * from and until can easily checked here because no extra information * is needed. */ function checkArgs($args, $checkList) { // global $errors, $TOKEN_VALID, $METADATAFORMATS; global $errors, $METADATAFORMATS; // $verb = $args['verb']; unset($args["verb"]); debug_print_r('checkList', $checkList); debug_print_r('args', $args); // "verb" has been checked before, no further check is needed if (isset($checkList['required'])) { for ($i = 0; $i < count($checkList["required"]); $i++) { debug_message("Checking: par{$i}: " . $checkList['required'][$i] . " in "); debug_var_dump("isset(\$args[\$checkList['required'][\$i]])", isset($args[$checkList['required'][$i]])); // echo "key exists". array_key_exists($checkList["required"][$i],$args)."\n"; if (isset($args[$checkList['required'][$i]]) == false) { // echo "caught\n"; $errors[] = oai_error('missingArgument', $checkList["required"][$i]); } else { // if metadataPrefix is set, it is in required section if (isset($args['metadataPrefix'])) { $metadataPrefix = $args['metadataPrefix']; // Check if the format is supported, it has enough infor (an array), last if a handle has been defined. if (!array_key_exists($metadataPrefix, $METADATAFORMATS) || !(is_array($METADATAFORMATS[$metadataPrefix]) || !isset($METADATAFORMATS[$metadataPrefix]['myhandler']))) { $errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix); } } unset($args[$checkList["required"][$i]]); } } } debug_message('Before return'); debug_print_r('errors', $errors); if (!empty($errors)) { return; } // check to see if there is unwanted foreach ($args as $key => $val) { debug_message("checkArgs: {$key}"); if (!in_array($key, $checkList["ops"])) { debug_message("Wrong\n" . print_r($checkList['ops'], true)); $errors[] = oai_error('badArgument', $key, $val); } switch ($key) { case 'from': case 'until': if (!checkDateFormat($val)) { $errors[] = oai_error('badGranularity', $key, $val); } break; case 'resumptionToken': // only check for expairation if ((int) $val + TOKEN_VALID < time()) { $errors[] = oai_error('badResumptionToken'); } break; } } }
unset($args['verb']); include dirname(__FILE__) . '/oai2/listmetadataformats.php'; break; case 'ListRecords': unset($args['verb']); include dirname(__FILE__) . '/oai2/listrecords.php'; break; case 'ListSets': unset($args['verb']); include dirname(__FILE__) . '/oai2/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 != '') { oai_exit(); } if ($compress) { ob_start('ob_gzhandler'); } header($CONTENT_TYPE); echo $xmlheader; echo $request; echo $output; oai_close();
<?php /** * \file * \brief Response to Verb ListSets * * Lists what sets are available to records in the system. */ // Here the size of sets is small, no resumptionToken is taken care. if (is_array($SETS)) { $outputObj = new ANDS_Response_XML($args); foreach ($SETS as $set) { $setNode = $outputObj->add2_verbNode("set"); foreach ($set as $key => $val) { if ($key == 'setDescription') { $desNode = $outputObj->addChild($setNode, $key); $des = $outputObj->doc->createDocumentFragment(); $des->appendXML($val); $desNode->appendChild($des); } else { $outputObj->addChild($setNode, $key, $val); } } } } else { $errors[] = oai_error('noSetHierarchy'); oai_exit(); }
require_once BASE_PATH . '/core/controllers/components/UuidComponent.php'; $uuiComponent = new UuidComponent(); // remove the OAI part to get the identifier $uuid = str_replace($oaiprefix, '', $identifier); $element = $uuiComponent->getByUid($uuid); if ($element == false || !$element instanceof ItemDao) { $errors .= oai_error('idDoesNotExist', 'identifier', $identifier); } elseif (!$itemModel->policyCheck($element, null, MIDAS_POLICY_READ)) { $errors .= oai_error('idDoesNotExist', 'identifier', $identifier); } } //break and clean up on error if ($errors != '') { oai_exit(); } // currently it is assumed that an existing identifier // can be served in all available metadataformats... if (is_array($METADATAFORMATS)) { $output .= " <ListMetadataFormats>\n"; foreach ($METADATAFORMATS as $key => $val) { $output .= " <metadataFormat>\n"; $output .= xmlformat($key, 'metadataPrefix', '', 3); $output .= xmlformat($val['schema'], 'schema', '', 3); $output .= xmlformat($val['metadataNamespace'], 'metadataNamespace', '', 3); $output .= " </metadataFormat>\n"; } $output .= " </ListMetadataFormats>\n"; } else { $errors .= oai_error('noMetadataFormats'); oai_exit(); }
/** * Answer an array of set information * * @return array * @access public * @since 3/28/07 */ function getOaiSetArray($db) { global $SQL; $query = "SELECT DISTINCT oai_set FROM " . $SQL['table']; $res = $db->query($query); if (DB::isError($res)) { if ($SHOW_QUERY_ERROR) { echo __FILE__ . "," . __LINE__ . "<br />"; echo "Query: {$query}<br />\n"; die($db->errorNative()); } else { $errors .= oai_error('noSetHierarchy'); } } else { $num_rows = $res->numRows(); if (DB::isError($num_rows)) { if ($SHOW_QUERY_ERROR) { echo __FILE__ . "," . __LINE__ . "<br />"; die($db->errorNative()); } } if (!$num_rows) { $errors .= oai_error('noSetHierarchy'); } } $repositoryManager = Services::getService('Repository'); $idManager = Services::getService('Id'); $sets = array(); while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { $set = array(); $set['setSpec'] = $row['oai_set']; $id = $idManager->getId($row['oai_set']); $repository = $repositoryManager->getRepository($id); $set['setName'] = $repository->getDisplayName(); $set['setDescription'] = $repository->getDescription(); $sets[] = $set; } return $sets; }
/** * 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; } }
* | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | * | | * +----------------------------------------------------------------------+ * | Derived from work by U. Müller, HUB Berlin, 2002 | * | | * | Written by Heinrich Stamerjohanns, May 2002 | * | stamer@uni-oldenburg.de | * +----------------------------------------------------------------------+ */ // // $Id$ // // parse and check args if (empty($errors) && count($args) > 0) { foreach ($args as $key => $val) { $errors .= oai_error('badArgument', $key, $val); } } // break and clean up on error if ($errors != '') { oai_exit(); } // see http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm // for details $indent = 2; $output .= " <Identify>\n"; $output .= xmlformat($repositoryName, 'repositoryName', '', $indent); $output .= xmlformat($baseURL, 'baseURL', '', $indent); $output .= xmlformat($protocolVersion, 'protocolVersion', '', $indent); $output .= xmlformat($adminEmail, 'adminEmail', '', $indent); $output .= xmlformat($earliestDatestamp, 'earliestDatestamp', '', $indent);
$datestamp = formatDatestamp($record[$SQL['datestamp']]); if (isset($record[$SQL['deleted']]) && $record[$SQL['deleted']] == 'true' && ($deletedRecord == 'transient' || $deletedRecord == 'persistent')) { $status_deleted = TRUE; } else { $status_deleted = FALSE; } // print Header $output .= ' <record>' . "\n"; $output .= ' <header'; if ($status_deleted) { $output .= ' status="deleted"'; } $output .= '>' . "\n"; // use xmlrecord since we include stuff from database; $output .= xmlrecord($identifier, 'identifier', '', 3); $output .= xmlformat($datestamp, 'datestamp', '', 3); if (!$status_deleted) { $output .= xmlrecord($record[$SQL['set']], 'setSpec', '', 3); } $output .= ' </header>' . "\n"; // return the metadata record itself if (!$status_deleted) { include dirname(__FILE__) . '/' . $inc_record; } $output .= ' </record>' . "\n"; } else { // we should never get here oai_error('idDoesNotExist'); } // End GetRecord $output .= ' </GetRecord>' . "\n";
$errors[] = oai_error('idDoesNotExist', '', $identifier); } } elseif (!$res->rowCount()) { // based on PHP manual, it might only work for some DBs $errors[] = oai_error('idDoesNotExist', '', $identifier); } if (!empty($errors)) { oai_exit(); } $record = $res->fetch(PDO::FETCH_ASSOC); if ($record === false) { if (SHOW_QUERY_ERROR) { echo __FILE__ . ',' . __LINE__ . "<br />"; echo "Query: {$query}<br />\n"; } $errors[] = oai_error('idDoesNotExist', '', $identifier); } $identifier = $record[$SQL['identifier']]; $datestamp = formatDatestamp($record[$SQL['datestamp']]); if (isset($record[$SQL['deleted']]) && $record[$SQL['deleted']] == 'true' && ($deletedRecord == 'transient' || $deletedRecord == 'persistent')) { $status_deleted = TRUE; } else { $status_deleted = FALSE; } $outputObj = new ANDS_Response_XML($args); $cur_record = $outputObj->create_record(); $cur_header = $outputObj->create_header($identifier, $datestamp, $record[$SQL['set']], $cur_record); // return the metadata record itself if (!$status_deleted) { include $inc_record; // where the metadata node is generated.