'.xmlstr($text, 'iso8859-1', false)."\n"; return $error; } function xmlstr($string, $charset="iso8859-1", $xmlescaped="false") { // just remove invalid characters $pattern ="/[\x-\x8\xb-\xc\xe-\x1f]/"; $string = preg_replace($pattern,'',$string); //$string = htmlspecialchars($string); // escape only if string is not escaped if (!$xmlescaped) { $xmlstr = utf8_encode($string); } if ($charset != "utf-8") { $xmlstr = utf8_encode($xmlstr); } return $xmlstr; } // will split a string into elements and return XML // supposed to print values from database function xmlrecord($sqlrecord, $element, $attr = '', $indent = 0) { global $SQL; global $xmlescaped; global $charset; $str = ''; if ($attr != '') { $attr = ' '.$attr; } if ($sqlrecord != '') { if (isset($SQL['split'])) { $temparr = explode($SQL['split'], $sqlrecord); foreach ($temparr as $val) { $str .= str_pad('', $indent).'<'.$element.$attr.'>'.xmlstr($val, $charset, $xmlescaped).'\n"; } return $str; } else { return str_pad('', $indent).'<'.$element.$attr.'>'.utf8_encode(xmlstr($sqlrecord, $charset, $xmlescaped)).'\n"; } } else { return ''; } } function xmlelement($element, $attr = '', &$indent, $open=true) { global $SQL; if ($attr != '') { $attr = ' '.$attr; } if ($open) { return str_pad('', $indent).'<'.$element.$attr.'>'."\n"; $indent += 2; } else { return str_pad('', $indent).''."\n"; $indent -= 2; } } // takes either an array or a string and outputs them as XML entities // this function assumes that the strings are written in iso8859-1 and have // not been escaped yet. function xmlformat($record, $element, $indent = 0) { $str = ''; if (is_array($record)) { foreach ($record as $val) { $str .= str_pad('', $indent).'<'.$element.'>'.xmlstr($val, 'iso8859-1', false).'\n"; } return $str; } elseif ($record != '') { return str_pad('', $indent).'<'.$element.'>'.xmlstr($record, 'iso8859-1', false).'\n"; } else { return ''; } } function date2UTCdatestamp($date) { global $granularity; switch ($granularity) { case 'YYYY-MM-DDThh:mm:ssZ': // we assume common date ("YYYY-MM-DD") or // datetime format ("YYYY-MM-DD hh:mm:ss") // in the database if (strstr($date, ' ')) { // date is datetime format if (strstr($date, '+')) { // format ("YYYY-MM-DD hh:mm:ss+01") list($ld, $lt) = explode(" ", $date); list($y, $m, $d) = explode("-", $ld); list($time, $tz) = explode("+", $lt); list($h, $min, $s) = explode(":", $time); if ($tz > 0) { $timestamp = mktime($h, $min, $s, $m, $d, $y); $timestamp -= (int) $tz * 86400; return strftime("%Y-%m-%dT%H:%M:%SZ", $timestamp); } } return str_replace(' ', 'T', $date).'Z'; } else { // date is date format // granularity 'YYYY-MM-DD' should be used... return $date.'T00:00:00Z'; } break; case 'YYYY-MM-DD': if (strstr($date, ' ')) { // date is datetime format list($date, $time) = explode(" ", $date); return $date; } else { return $date; } break; default: die("Unknown granularity!"); } } function checkDateFormat($date) { global $granularity; global $message; if ($granularity == 'YYYY-MM-DDThh:mm:ssZ') { $checkstr = '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$'; } else { $checkstr = '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}$)'; } if (ereg($checkstr, $date, $regs)) { if (checkdate($regs[2], $regs[3], $regs[1])) { return 1; } else { $message = "Invalid Date: $date is not a valid date."; return 0; } } else { $message = "Invalid Date Format: $date does not comply to the date format $granularity."; return 0; } } function formatDatestamp($datestamp) { global $granularity; //$datestamp = date2UTCdatestamp($datestamp); $datestamp = format_date($datestamp); if (!checkDateFormat($datestamp)) { if ($granularity == 'YYYY-MM-DD') { return '2002-01-01'; } else { return '2002-01-01T00:00:00Z'; } } else { return $datestamp; } } function oai_close() { global $compress; echo "\n"; //echo ""; if ($compress) { ob_end_flush(); } } function oai_exit() { global $CONTENT_TYPE; global $xmlheader; global $request; global $errors; header($CONTENT_TYPE); echo $xmlheader; echo $request; echo $errors; oai_close(); exit(); } function php_is_at_least($version) { list($c_r, $c_mj, $c_mn) = explode('.', phpversion()); list($v_r, $v_mj, $v_mn) = explode('.', $version); if ($c_r >= $v_r && $c_mj >= $v_mj && $c_mn >= $v_mn) return TRUE; else return FALSE; } function metadataHeader($prefix) { global $METADATAFORMATS; global $XMLSCHEMA; if ($prefix == "kmoddl_dc") { // return " "; return " "; } else if ($prefix == "nsdl_dc") { return ' '; } $myformat = $METADATAFORMATS[$prefix]; $str = ' <'.$prefix; if ($myformat['record_prefix']) { $str .= ':'.$myformat['record_prefix']; } $str .= "\n". ' xmlns:'.$prefix.'="'.$myformat['metadataNamespace'].'"'."\n"; if ($myformat['record_prefix'] && $myformat['record_namespace']) { $str .= ' xmlns:'.$myformat['record_prefix'].'="'.$myformat['record_namespace'].'"'."\n"; } $str .= ' xmlns:xsi="'.$XMLSCHEMA.'"'."\n". ' xsi:schemaLocation="'.$myformat['metadataNamespace']."\n". ' '.$myformat['schema'].'">'."\n"; return $str; } function changeFields($source, &$target) { $target = $source; } function format_date($mydate) { if (strlen($mydate) != 14) { return substr($mydate, 0, 4); } else { $formatdate = substr($mydate, 0, 4) . "-" . substr($mydate, 4, 2) . "-" . substr($mydate, 6, 2) . "T"; $formatdate .= substr($mydate, 8, 2) . ":" . substr($mydate, 10, 2) . ":" . substr($mydate, 12, 2) . "Z"; return $formatdate; } } ?> 'phdthesis', 'setName'=>'PHD Thesis', 'setDescription'=>'') //, // array('setSpec'=>'math', 'setName'=>'Mathematics') , // array('setSpec'=>'phys', 'setName'=>'Physics') ); // define all supported metadata formats // // myhandler is the name of the file that handles the request for the // specific metadata format. // [record_prefix] describes an optional prefix for the metadata // [record_namespace] describe the namespace for this prefix $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'=>'oai_dc.php', 'record_prefix'=>'dc', 'record_namespace' => 'http://purl.org/dc/elements/1.1/' ), 'nsdl_dc' => array('metadataPrefix'=>'nsdl_dc', 'schema'=>'http://ns.nsdl.org/schemas/nsdl_dc/nsdl_dc_v1.02.xsd', 'metadataNamespace'=>'http://ns.nsdl.org/nsdl_dc_v1.02/', 'myhandler'=>'nsdl_dc.php', 'record_prefix'=>'nsdl_dc', 'record_namespace' => 'http://purl.org/dc/elements/1.1/' ), 'kmoddl_dc' => array('metadataPrefix'=>'kmoddl_dc', 'schema'=>'http://purl.org/kmoddl/kmoddl_v1.00/kmoddl_v1.00.xsd', 'metadataNamespace'=>'http://purl.org/kmoddl/kmoddl_v1.00/', 'myhandler'=>'kmoddl_dc.php', 'record_prefix'=>'kmoddl', 'record_namespace' => 'http://purl.org/dc/elements/1.1/' ) //array('metadataPrefix'=>'olac', // 'schema'=>'http://www.language-archives.org/OLAC/olac-2.0.xsd', // 'metadataNamespace'=>'http://www.openarchives.org/OLAC/0.2/', // 'handler'=>'record_olac.php' //) ); // // DATABASE SETUP // // change according to your local DB setup. $DB_HOST = 'localhost'; $DB_USER = 'kmoddl_p'; $DB_PASSWD = 'F6Chassis#place'; $DB_NAME = 'kmoddl_production'; // Data Source Name: This is the universal connection string // if you use something other than mysql edit accordingly. // Example for MySQL $DSN = "mysql://$DB_USER:$DB_PASSWD@$DB_HOST/$DB_NAME"; // Example for Oracle // $DSN = "oci8://$DB_USER:$DB_PASSWD@$DB_NAME"; // the charset you store your metadata in your database // currently only utf-8 and iso8859-1 are supported $charset = "utf-8"; // if entities such as < > ' " in your metadata has already been escaped // then set this to true (e.g. you store < as < in your DB) $xmlescaped = false; // We store multiple entries for one element in a single row // in the database. SQL['split'] ist the delimiter for these entries. // If you do not do this, do not define $SQL['split'] // $SQL['split'] = ';'; // the name of the table where your store your metadata // $SQL['table'] = 'oai_records'; $SQL['table'] = 'oai_records'; // the name of the column where you store your sequence // (or autoincrement values). $SQL['id_column'] = 'serial'; // the name of the column where you store the unique identifiers // pointing to your item. // this is your internal identifier for the item // $SQL['identifier'] = 'url'; $SQL['identifier'] = 'serial'; // If you want to expand the internal identifier in some way // use this (but not for OAI stuff, see next line) $idPrefix = ''; // this is your external (OAI) identifier for the item // this will be expanded to // oai:$repositoryIdentifier:$idPrefix$SQL['identifier'] // should not be changed //$oaiprefix = "oai".$delimiter.$repositoryIdentifier.$delimiter.$idPrefix.$delimiter; $oaiprefix = "oai".$delimiter.$repositoryIdentifier.$delimiter; // adjust anIdentifier with sample contents an identifier $sampleIdentifier = $oaiprefix.'1'; // the name of the column where you store your datestamps // $SQL['datestamp'] = 'datestamp'; $SQL['datestamp'] = 'last_update'; // the name of the column where you store information whether // a record has been deleted. Leave it as it is if you do not use // this feature. $SQL['deleted'] = 'deleted'; // to be able to quickly retrieve the sets to which one item belongs, // the setnames are stored for each item // the name of the column where you store sets // $SQL['set'] = 'oai_set'; $SQL['set'] = 'oai_set'; // for checking with date stamps $SQL['earliest'] = date($earliestDatestamp); /* custom dublin core terms */ $SQL["dc_terms"] = array( "id" => "myid", "title"=>"title", "alternative"=>"alternative", "subject"=>"subject", "category_title"=>"category_title", "creator_family"=>"name_family", "creator_middle"=>"name_middle", "creator_given"=>"name_given", "description"=>"description", "publisher"=>"publisher", "contributor"=>"contributor", "date"=>"desc_date", "created"=>"date_created", "dcmi_type"=>"dcmi_type", "medium"=>"medium", "format"=>"format", "identifier"=>"identifier", "language"=>"english", "audience"=>"audience", "relation"=>"relation", "rights"=>"rights", "kmoddl_type"=>"KMODDLType", "voigtid" => "voigtid", "size" => "size", "identifier" => "identifier", "manufacturer" => "manufacturer" ); /* End of custom variables 2004.06.22 by Shin-Woo Kim */ // Here are a couple of queries which might need to be adjusted to // your needs. Normally, if you have correctly named the columns above, // this does not need to be done. // this function should generate a query which will return // all records // the useless condition id_column = id_column is just there to ease // further extensions to the query, please leave it as it is. function selectallQuery ($id = '') { global $SQL; if ($id != '' ) { if ( is_numeric($id) ) { $sql = "SELECT oai_records.*, oai_types.title FROM oai_records INNER JOIN oai_types ON oai_records.type = oai_types.id WHERE oai_records.serial = $id"; $result = @mysql_query( $sql ); if ( $row = mysql_fetch_array($result) ) { if ( $row["title"] == "model" ) { $sql = "SELECT oai_records.serial, oai_records.last_update, oai_types.title AS oai_type, v2_models.*, v2_models.title_english AS " . $SQL["dc_terms"]["title"] . ", v2_models.title_german AS " . $SQL["dc_terms"]["alternative"] . ", v2_models.title_prefix AS " . $SQL["dc_terms"]["identifier"] . ", v2_models.keywords AS " . $SQL["dc_terms"]["subject"] . ", v2_model_categories.title_english AS " . $SQL["dc_terms"]["category_title"] . ", v2_people.name_family AS " . $SQL["dc_terms"]["creator_family"] . ", v2_people.name_given AS " . $SQL["dc_terms"]["creator_given"] . ", v2_people.name_middle AS " . $SQL["dc_terms"]["creator_middle"] . ", v2_resource_types.oai_title AS " . $SQL["dc_terms"]["kmoddl_type"] . ", v2_dcmi_types.title AS " . $SQL["dc_terms"]["dcmi_type"] . ", v2_publishers.title AS " . $SQL["dc_terms"]["publisher"] . ", v2_manufacturers.name AS " . $SQL["dc_terms"]["manufacturer"] . " FROM oai_records INNER JOIN oai_types ON oai_records.type = oai_types.id INNER JOIN v2_models ON oai_records.id = v2_models.id INNER JOIN v2_people ON v2_models.fk_creator = v2_people.id INNER JOIN v2_model_categories ON v2_models.fk_category = v2_model_categories.id INNER JOIN v2_resource_types ON v2_models.fk_resource_type = v2_resource_types.id INNER JOIN v2_dcmi_types ON v2_resource_types.fk_DCMI_type = v2_dcmi_types.id INNER JOIN v2_publishers ON v2_models.fk_publisher = v2_publishers.id INNER JOIN v2_manufacturers ON v2_models.fk_manufacturer = v2_manufacturers.id WHERE oai_types.title = 'model' AND oai_records.serial = $id AND oai_records.status = 1 "; } else if ( $row["title"] == "resource" ) { $sql = "SELECT oai_records.serial, oai_records.last_update, oai_types.title AS oai_type, v2_resources.*, v2_resources.keywords AS " . $SQL["dc_terms"]["subject"] . ", v2_resource_types.oai_title AS " . $SQL["dc_terms"]["kmoddl_type"] . ", v2_dcmi_types.title AS " . $SQL["dc_terms"]["dcmi_type"] . ", v2_publishers.title AS " . $SQL["dc_terms"]["publisher"] . ", v2_mimetypes.formal AS " . $SQL["dc_terms"]["format"] . " FROM oai_records INNER JOIN oai_types ON oai_records.type = oai_types.id INNER JOIN v2_resources ON oai_records.id = v2_resources.id INNER JOIN v2_resource_types ON v2_resources.fk_resource_type = v2_resource_types.id INNER JOIN v2_dcmi_types ON v2_resource_types.fk_DCMI_type = v2_dcmi_types.id INNER JOIN v2_publishers ON v2_resources.fk_publisher = v2_publishers.id INNER JOIN v2_mimetypes ON v2_resources.fk_mimetype = v2_mimetypes.id WHERE oai_types.title = 'resource' AND oai_records.serial = $id AND v2_resources.status = 1 AND oai_records.status = 1 "; } else if ( $row["title"] == "reference" ) { $sql = "SELECT oai_records.serial, oai_records.last_update, oai_types.title AS oai_type, v2_bibrecords.*, v2_bibrecords.abstract AS " . $SQL["dc_terms"]["description"] . ", v2_bibrecord_publishers.title AS " . $SQL["dc_terms"]["publisher"] . ", v2_bibrecord_types.oai_title FROM oai_records INNER JOIN oai_types ON oai_records.type = oai_types.id INNER JOIN v2_bibrecords ON oai_records.id = v2_bibrecords.id INNER JOIN v2_bibrecord_types ON v2_bibrecords.fk_type = v2_bibrecord_types.id INNER JOIN v2_bibrecord_publishers ON v2_bibrecords.fk_publisher = v2_bibrecord_publishers.id WHERE oai_types.title = 'reference' AND oai_records.serial = $id AND oai_records.status = 1 "; } else { $sql = "SELECT * FROM oai_records WHERE serial = -1"; } } } else { return "SELECT * FROM oai_records WHERE serial = -1"; } } else { $sql["oai"] = "SELECT oai_records.*, oai_types.title FROM oai_records INNER JOIN oai_types ON oai_records.type = oai_types.id ORDER BY oai_records.serial"; $sql["models"] = "SELECT oai_records.serial, oai_records.last_update, oai_types.title AS oai_type, v2_models.*, v2_models.title_english AS " . $SQL["dc_terms"]["title"] . ", v2_models.title_german AS " . $SQL["dc_terms"]["alternative"] . ", v2_models.title_prefix AS " . $SQL["dc_terms"]["identifier"] . ", v2_models.keywords AS " . $SQL["dc_terms"]["subject"] . ", v2_model_categories.title_english AS " . $SQL["dc_terms"]["category_title"] . ", v2_people.name_family AS " . $SQL["dc_terms"]["creator_family"] . ", v2_people.name_given AS " . $SQL["dc_terms"]["creator_given"] . ", v2_people.name_middle AS " . $SQL["dc_terms"]["creator_middle"] . ", v2_resource_types.oai_title AS " . $SQL["dc_terms"]["kmoddl_type"] . ", v2_dcmi_types.title AS " . $SQL["dc_terms"]["dcmi_type"] . ", v2_publishers.title AS " . $SQL["dc_terms"]["publisher"] . ", v2_manufacturers.name AS " . $SQL["dc_terms"]["manufacturer"] . " FROM oai_records INNER JOIN oai_types ON oai_records.type = oai_types.id INNER JOIN v2_models ON oai_records.id = v2_models.id INNER JOIN v2_people ON v2_models.fk_creator = v2_people.id INNER JOIN v2_model_categories ON v2_models.fk_category = v2_model_categories.id INNER JOIN v2_resource_types ON v2_models.fk_resource_type = v2_resource_types.id INNER JOIN v2_dcmi_types ON v2_resource_types.fk_DCMI_type = v2_dcmi_types.id INNER JOIN v2_publishers ON v2_models.fk_publisher = v2_publishers.id INNER JOIN v2_manufacturers ON v2_models.fk_manufacturer = v2_manufacturers.id WHERE oai_types.title = 'model' AND oai_records.status = 1 "; $sql["resources"] = "SELECT oai_records.serial, oai_records.last_update, oai_types.title AS oai_type, v2_resources.*, v2_resources.keywords AS " . $SQL["dc_terms"]["subject"] . ", v2_resource_types.oai_title AS " . $SQL["dc_terms"]["kmoddl_type"] . ", v2_dcmi_types.title AS " . $SQL["dc_terms"]["dcmi_type"] . ", v2_publishers.title AS " . $SQL["dc_terms"]["publisher"] . ", v2_mimetypes.formal AS " . $SQL["dc_terms"]["format"] . " FROM oai_records INNER JOIN oai_types ON oai_records.type = oai_types.id INNER JOIN v2_resources ON oai_records.id = v2_resources.id INNER JOIN v2_resource_types ON v2_resources.fk_resource_type = v2_resource_types.id INNER JOIN v2_dcmi_types ON v2_resource_types.fk_DCMI_type = v2_dcmi_types.id INNER JOIN v2_publishers ON v2_resources.fk_publisher = v2_publishers.id INNER JOIN v2_mimetypes ON v2_resources.fk_mimetype = v2_mimetypes.id WHERE oai_types.title = 'resource' AND oai_records.status = 1 "; /* v2_people.name_family AS " . $SQL["dc_terms"]["creator_family"] . ", v2_people.name_given AS " . $SQL["dc_terms"]["creator_given"] . ", v2_people.name_middle AS " . $SQL["dc_terms"]["creator_middle"] . ", LEFT JOIN v2_people ON v2_resources.fk_desc_author = v2_people.id */ $sql["references"] = "SELECT oai_records.serial, oai_records.last_update, oai_types.title AS oai_type, v2_bibrecords.*, v2_bibrecord_publishers.title AS " . $SQL["dc_terms"]["publisher"] . ", v2_bibrecord_types.oai_title FROM oai_records INNER JOIN oai_types ON oai_records.type = oai_types.id INNER JOIN v2_bibrecords ON oai_records.id = v2_bibrecords.id INNER JOIN v2_bibrecord_types ON v2_bibrecords.fk_type = v2_bibrecord_types.id INNER JOIN v2_bibrecord_publishers ON v2_bibrecords.fk_publisher = v2_bibrecord_publishers.id WHERE oai_types.title = 'reference' AND oai_records.status = 1 "; $sql["orderby"] = "ORDER BY oai_records.serial"; } return $sql; } // this function will return identifier and datestamp for all records function idQuery ($id = '') { global $SQL; $sql = "SELECT * FROM " . $SQL["table"] . " WHERE oai_records.status = 1"; if ($id != '') { //$query .= $SQL['identifier']." ='$id'"; $sql .= " AND " . $SQL['identifier'] . " = '$id'"; } return $sql; } // filter for until function untilQuery($until) { global $SQL; $myDate = date($until); if ( $SQL['earliest'] > $myDate ) { return " AND " . $SQL['id_column'] . " = -1 "; } else { return ' and ' . $SQL['datestamp'] . " <= '$until'"; } } function untilBib($until) { global $SQL; $myDate = date($until); if ( $SQL['earliest'] > $myDate ) { return " AND " . $SQL['id_column'] . " = -1 "; } else { return " and date <= '$until'"; } } // filter for from function fromQuery($from) { global $SQL; return ' and ' . $SQL['datestamp'] . " >= '$from'"; } function fromBib($from) { global $SQL; return " and date >= '$from'"; } // filter for sets function setQuery($set) { global $SQL; return ''; //$SQL; //' and '.$SQL['set']." LIKE '%$set%'"; } // There is no need to change anything below. // Current Date $datetime = gmstrftime('%Y-%m-%dT%T'); $responseDate = $datetime.'Z'; // do not change // encoding="iso-8859-1" $XMLHEADER = ' '."\n"; $xmlheader = $XMLHEADER . ' '.$responseDate."\n"; // the xml schema namespace, do not change this $XMLSCHEMA = 'http://www.w3.org/2001/XMLSchema-instance'; /* // do not change $XMLHEADER = ' '."\n"; $OAIHEADER = ' '."\n"; $xmlheader = $OAIHEADER . ' '.$responseDate."\n"; // the xml schema namespace, do not change this $XMLSCHEMA = 'http://ns.nsdl.org/nsdl_dc_v1.02/'; //'http://www.w3.org/2001/XMLSchema-instance'; $NSDLALL = ' '; $NSDLALL_DATESTAMP = ' '; $NSDLLINKS = ' '; */ ?>