Пример #1
0
function oaidcCollection($result)
{
    global $contentTypeCharset;
    // these variables are defined in 'ini.inc.php'
    global $convertExportDataToUTF8;
    global $citeKeysArray;
    // '$citeKeysArray' is made globally available from
    // within this function
    // Individual records are objects and collections of records are strings
    $oaidcCollectionDoc = new XMLDocument();
    if ($convertExportDataToUTF8 == "yes" and $contentTypeCharset != "UTF-8") {
        $oaidcCollectionDoc->setEncoding("UTF-8");
    } else {
        $oaidcCollectionDoc->setEncoding($contentTypeCharset);
    }
    $oaidcCollection = new XML("dcCollection");
    $oaidcCollection->setTagAttribute("xmlns:oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
    $oaidcCollection->setTagAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
    $oaidcCollection->setTagAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    $oaidcCollection->setTagAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
    // ----------------------------------------------------------
    // Add OAI_DC XML entries:
    $exportArray = array();
    // array for individually exported records
    $citeKeysArray = array();
    // array of cite keys (used to ensure uniqueness of cite keys among all exported records)
    // Generate the export for each record and push them onto an array:
    while ($row = @mysql_fetch_array($result)) {
        // Export the current record as OAI_DC XML:
        $record = oaidcRecord($row, "oai_dc");
        if (!empty($record)) {
            // unless the record buffer is empty...
            array_push($exportArray, $record);
        }
        // ...add it to an array of exports
    }
    // for each of the OAI_DC XML entries in the result set...
    foreach ($exportArray as $oaidc) {
        $oaidcCollection->addXMLasBranch($oaidc);
    }
    $oaidcCollectionDoc->setXML($oaidcCollection);
    $oaidcCollectionString = $oaidcCollectionDoc->getXMLString();
    return $oaidcCollectionString;
}
Пример #2
0
function srwCollection($result, $rowOffset, $showRows, $exportStylesheet, $displayType)
{
    global $contentTypeCharset;
    // these variables are defined in 'ini.inc.php'
    global $convertExportDataToUTF8;
    global $exportFormat;
    // this is needed so that we can distinguish between "SRW_DC XML" and "SRW_MODS XML" record formats
    // The array '$transtab_refbase_unicode' contains search & replace patterns
    // for conversion from refbase markup to Unicode entities.
    global $transtab_refbase_unicode;
    // defined in 'transtab_refbase_unicode.inc.php'
    global $fieldSpecificSearchReplaceActionsArray;
    // Individual records are objects and collections of records are strings
    // Defines field-specific search & replace 'actions' that will be applied to all those refbase fields that are listed in the corresponding 'fields' element:
    // (If you don't want to perform any search and replace actions, specify an empty array, like: '$fieldSpecificSearchReplaceActionsArray = array();'.
    //  Note that the search patterns MUST include the leading & trailing slashes -- which is done to allow for mode modifiers such as 'imsxU'.)
    //                                          "/Search Pattern/"  =>  "Replace Pattern"
    $fieldSpecificSearchReplaceActionsArray = array();
    if ($convertExportDataToUTF8 == "yes") {
        $fieldSpecificSearchReplaceActionsArray[] = array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_unicode);
    }
    $srwCollectionDoc = new XMLDocument();
    if ($convertExportDataToUTF8 == "yes" and $contentTypeCharset != "UTF-8") {
        $srwCollectionDoc->setEncoding("UTF-8");
    } else {
        $srwCollectionDoc->setEncoding($contentTypeCharset);
    }
    $srwCollection = srwGenerateBaseTags("searchRetrieveResponse");
    $showRowsOriginal = $showRows;
    // save original value of '$showRows' (which may get modified by the 'seekInMySQLResultsToOffset()' function below)
    // Find out how many rows are available and (if there were rows found) seek to the current offset:
    // function 'seekInMySQLResultsToOffset()' is defined in 'include.inc.php'
    list($result, $rowOffset, $showRows, $rowsFound, $previousOffset, $nextOffset, $showMaxRow) = seekInMySQLResultsToOffset($result, $rowOffset, $showRows, $displayType, "");
    addNewBranch($srwCollection, "srw:numberOfRecords", array(), $rowsFound);
    // function 'addNewBranch()' is defined in 'webservice.inc.php'
    // <srw:resultSetId> not supported
    // <srw:resultSetIdleTime> not supported
    $srwRecordsBranch = new XMLBranch("srw:records");
    if ($showRowsOriginal != 0) {
        $exportArray = array();
        // Array for individually exported records
        // Generate the export for each record and push them onto an array:
        for ($rowCounter = 0; $rowCounter < $showRows && ($row = @mysql_fetch_array($result)); $rowCounter++) {
            if (preg_match("/DC/i", $exportFormat)) {
                // export the current record as DC XML (i.e. simple Dublin Core):
                $record = oaidcRecord($row, "srw_dc");
            } else {
                // by default, we export the current record as MODS XML:
                $record = modsRecord($row);
            }
            // function 'modsRecord()' is defined in 'modsxml.inc.php'
            // TODO: build 'extraRecordData' for OAI-PMH (see below) using:
            //       $row['serial'], $row['modified_date'], $row['modified_time']
            if (!empty($record)) {
                // unless the record buffer is empty...
                array_push($exportArray, $record);
            }
            // ...add it to an array of exports
        }
        $i = $rowOffset;
        // initialize counter
        // for each of the DC/MODS records in the result set...
        foreach ($exportArray as $record) {
            ++$i;
            // increment $i by one, then return $i
            $srwRecordBranch = new XMLBranch("srw:record");
            if (preg_match("/DC/i", $exportFormat)) {
                srwGeneratePackingSchema($srwRecordBranch, "xml", "dc");
            } else {
                srwGeneratePackingSchema($srwRecordBranch, "xml", "mods");
            }
            $srwRecordDataBranch = new XMLBranch("srw:recordData");
            if (preg_match("/MODS/i", $exportFormat)) {
                // NOTE: converting the MODS object into a string to perform search & replace actions
                //       may be very clumsy but I don't know any better... ?:-/
                $recordString = $record->getXMLString();
                $recordString = preg_replace('/<mods/i', '<mods xmlns="http://www.loc.gov/mods/v3"', $recordString);
                // alternatively to the above line we could add a 'mods:' identifier to all MODS XML tags:
                //				$recordString = preg_replace("#<(/)?#","<\\1mods:",$recordString);
                $record->removeAllBranches();
                $record->parseFromString($recordString);
            }
            $srwRecordDataBranch->addXMLasBranch($record);
            $srwRecordBranch->addXMLBranch($srwRecordDataBranch);
            // TODO: add 'extraRecordData' for OAI-PMH as explained in <http://www.dlib.org/dlib/february05/sanderson/02sanderson.html>
            //       Example:
            //                <extraRecordData>
            //                    <oai:header xmlns:oai="http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
            //                        <oai:identifier>...</oai:identifier>
            //                        <oai:datestamp>...</oai:datestamp>
            //                        <oai:setSpec>...</oai:setSpec>
            //                    </oai:header>
            //                </extraRecordData>
            //
            //       Then add to the SRW 'Explain' response:
            //          1.  an oai.identifier index containing a unique identifier for each record in the database
            //          2.  an oai.datestamp index containing the date/time the record was added or changed in the database
            //          3.  an optional oai.set index, browsable via the scan operation, to support selective harvesting of records
            addNewBranch($srwRecordBranch, "srw:recordPosition", array(), $i);
            $srwRecordsBranch->addXMLBranch($srwRecordBranch);
        }
    }
    $srwCollection->addXMLBranch($srwRecordsBranch);
    if ($showRowsOriginal != 0 && $showMaxRow < $rowsFound) {
        // show 'nextRecordPosition' if the SRU query did not contain 'maximumRecords=0' and if there are any remaining records to be displayed
        addNewBranch($srwCollection, "srw:nextRecordPosition", array(), $showMaxRow + 1);
    }
    $srwCollectionDoc->setXML($srwCollection);
    $srwCollectionString = $srwCollectionDoc->getXMLString();
    // Add the XML Stylesheet definition:
    // Note that this is just a hack (that should get fixed) since I don't know how to do it properly using the ActiveLink PHP XML Package ?:-/
    if (!empty($exportStylesheet)) {
        $srwCollectionString = preg_replace("/(?=\\<srw:searchRetrieveResponse)/i", "<?xml-stylesheet type=\"text/xsl\" href=\"" . $exportStylesheet . "\"?>\n", $srwCollectionString);
    }
    return $srwCollectionString;
}