Beispiel #1
0
function unapiExplainResponse($unapiID)
{
    global $contentTypeCharset;
    // these variables are specified in 'ini.inc.php'
    $unapiCollectionDoc = new XMLDocument();
    $unapiCollectionDoc->setEncoding($contentTypeCharset);
    $unapiCollection = new XML("formats");
    if (!empty($unapiID)) {
        $unapiCollection->setTagAttribute("id", $unapiID);
    }
    // Recommended format names are given at <http://unapi.stikipad.com/unapi/show/existing+formats>
    // TODO: add 'ISI', 'ODF XML' and 'Word XML'
    addNewBranch($unapiCollection, "format", array("name" => "bibtex", "type" => "text/plain", "docs" => "http://en.wikipedia.org/wiki/BibTeX"), "");
    // function 'addNewBranch()' is defined in 'webservice.inc.php'
    addNewBranch($unapiCollection, "format", array("name" => "endnote", "type" => "text/plain", "docs" => "http://www.ecst.csuchico.edu/~jacobsd/bib/formats/endnote.html"), "");
    addNewBranch($unapiCollection, "format", array("name" => "ris", "type" => "text/plain", "docs" => "http://www.adeptscience.co.uk/kb/article/A626"), "");
    addNewBranch($unapiCollection, "format", array("name" => "atom", "type" => "application/atom+xml", "docs" => "http://www.atomenabled.org/developers/syndication/"), "");
    addNewBranch($unapiCollection, "format", array("name" => "mods", "type" => "application/xml", "docs" => "http://www.loc.gov/standards/mods/"), "");
    addNewBranch($unapiCollection, "format", array("name" => "oai_dc", "type" => "application/xml", "docs" => "http://www.openarchives.org/OAI/openarchivesprotocol.html#dublincore"), "");
    addNewBranch($unapiCollection, "format", array("name" => "srw_dc", "type" => "application/xml", "docs" => "http://www.loc.gov/standards/sru/"), "");
    addNewBranch($unapiCollection, "format", array("name" => "srw_mods", "type" => "application/xml", "docs" => "http://www.loc.gov/standards/sru/"), "");
    addNewBranch($unapiCollection, "format", array("name" => "html", "type" => "text/html", "docs" => "http://www.w3.org/MarkUp/"), "");
    addNewBranch($unapiCollection, "format", array("name" => "rtf", "type" => "application/rtf", "docs" => "http://en.wikipedia.org/wiki/Rich_Text_Format"), "");
    addNewBranch($unapiCollection, "format", array("name" => "pdf", "type" => "application/pdf", "docs" => "http://partners.adobe.com/public/developer/pdf/index_reference.html"), "");
    addNewBranch($unapiCollection, "format", array("name" => "latex", "type" => "application/x-latex", "docs" => "http://en.wikipedia.org/wiki/LaTeX"), "");
    addNewBranch($unapiCollection, "format", array("name" => "markdown", "type" => "text/plain", "docs" => "http://daringfireball.net/projects/markdown/"), "");
    addNewBranch($unapiCollection, "format", array("name" => "text", "type" => "text/plain"), "");
    $unapiCollectionDoc->setXML($unapiCollection);
    $unapiCollectionString = $unapiCollectionDoc->getXMLString();
    return $unapiCollectionString;
}
Beispiel #2
0
function srwGeneratePackingSchema(&$thisObject, $srwPacking, $srwSchema)
{
    // available schemas taken from <http://www.loc.gov/z3950/agency/zing/srw/record-schemas.html>
    $srwSchemas = array("dc" => "info:srw/schema/1/dc-v1.1", "diag" => "info:srw/schema/1/diagnostic-v1.1", "zeerex" => "http://explain.z3950.org/dtd/2.0/", "mods" => "info:srw/schema/1/mods-v3.2", "onix" => "info:srw/schema/1/onix-v2.0", "marcxml" => "info:srw/schema/1/marcxml-v1.1", "ead" => "info:srw/schema/1/ead-2002", "zthes" => "http://zthes.z3950.org/xml/0.5/", "ccg" => "http://srw.cheshire3.org/schemas/ccg/1.0/", "rec" => "info:srw/schema/2/rec-1.0", "server-choice" => "info:srw/schema/1/server-choice", "xpath" => "info:srw/schema/1/xpath-1.0");
    addNewBranch($thisObject, "srw:recordPacking", array(), $srwPacking);
    // function 'addNewBranch()' is defined in 'webservice.inc.php'
    addNewBranch($thisObject, "srw:recordSchema", array(), $srwSchemas[$srwSchema]);
}
Beispiel #3
0
function openSearchDiagnostics($diagCode, $diagDetails, $exportStylesheet)
{
    global $contentTypeCharset;
    // defined in 'ini.inc.php'
    // Map SRU/W diagnostic numbers to their corresponding messages:
    // (i.e., for OpenSearch diagnostics, we simply re-use the SRU/W diagnostics)
    $diagMessages = mapSRWDiagnostics();
    // function 'mapSRWDiagnostics()' is defined in 'webservice.inc.php'
    if (isset($diagMessages[$diagCode])) {
        $diagMessage = $diagMessages[$diagCode];
    } else {
        $diagMessage = "Unknown error";
    }
    $atomCollectionDoc = new XMLDocument();
    $atomCollectionDoc->setEncoding($contentTypeCharset);
    $atomCollection = openSearchGenerateBaseTags("Error");
    // add feed-level tags:
    // - 'id':
    addNewBranch($atomCollection, "id", array(), "info:srw/diagnostic/1/");
    // could something else be used as diagnostics feed ID instead?
    // - OpenSearch elements:
    addNewBranch($atomCollection, "opensearch:totalResults", array(), "1");
    addNewBranch($atomCollection, "openSearch:startIndex", array(), "1");
    addNewBranch($atomCollection, "openSearch:itemsPerPage", array(), "1");
    $diagnosticsBranch = new XMLBranch("entry");
    // add entry-level tags:
    addNewBranch($diagnosticsBranch, "title", array(), $diagMessage);
    //		addNewBranch($atomCollection, "link", array("href" => ""), ""); // TODO (what could be used as link for a diagnostics entry?)
    addNewBranch($diagnosticsBranch, "updated", array(), generateISO8601TimeStamp());
    // function 'generateISO8601TimeStamp()' is defined in 'include.inc.php'
    addNewBranch($diagnosticsBranch, "id", array(), "info:srw/diagnostic/1/" . $diagCode);
    $diagContent = $diagMessage;
    if (!empty($diagDetails)) {
        $diagContent .= ": " . $diagDetails;
    }
    addNewBranch($diagnosticsBranch, "content", array("type" => "text"), "Error " . $diagCode . ": " . $diagContent);
    // TODO: I18n
    $atomCollection->addXMLBranch($diagnosticsBranch);
    $atomCollectionDoc->setXML($atomCollection);
    $atomCollectionString = $atomCollectionDoc->getXMLString();
    return $atomCollectionString;
}
Beispiel #4
0
function odfDocument($result, $odfBodyContentType)
{
    global $contentTypeCharset;
    // these variables are defined in 'ini.inc.php'
    global $convertExportDataToUTF8;
    $odfDocumentDoc = new XMLDocument();
    if ($convertExportDataToUTF8 == "yes" and $contentTypeCharset != "UTF-8") {
        $odfDocumentDoc->setEncoding("UTF-8");
    } else {
        $odfDocumentDoc->setEncoding($contentTypeCharset);
    }
    // Setup root element:
    $odfDocument = new XML("office:document-content");
    $rootAttributesArray = array("xmlns:office" => "urn:oasis:names:tc:opendocument:xmlns:office:1.0", "xmlns:style" => "urn:oasis:names:tc:opendocument:xmlns:style:1.0", "xmlns:text" => "urn:oasis:names:tc:opendocument:xmlns:text:1.0", "xmlns:table" => "urn:oasis:names:tc:opendocument:xmlns:table:1.0", "xmlns:draw" => "urn:urn:oasis:names:tc:opendocument:xmlns:drawing:1.0", "xmlns:fo" => "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", "xmlns:xlink" => "http://www.w3.org/1999/xlink", "xmlns:dc" => "http://purl.org/dc/elements/1.1/", "xmlns:meta" => "urn:oasis:names:tc:opendocument:xmlns:meta:1.0", "xmlns:number" => "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0", "xmlns:svg" => "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0", "xmlns:chart" => "urn:oasis:names:tc:opendocument:xmlns:chart:1.0", "xmlns:dr3d" => "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0", "xmlns:math" => "http://www.w3.org/1998/Math/MathML", "xmlns:form" => "urn:oasis:names:tc:opendocument:xmlns:form:1.0", "xmlns:script" => "urn:oasis:names:tc:opendocument:xmlns:script:1.0", "xmlns:ooo" => "http://openoffice.org/2004/office", "xmlns:ooow" => "http://openoffice.org/2004/writer", "xmlns:oooc" => "http://openoffice.org/2004/calc", "xmlns:dom" => "http://www.w3.org/2001/xml-events", "xmlns:xforms" => "http://www.w3.org/2002/xforms", "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "office:version" => "1.0");
    foreach ($rootAttributesArray as $attributeKey => $attributeValue) {
        $odfDocument->setTagAttribute($attributeKey, $attributeValue);
    }
    // Add common attributes:
    addNewBranch($odfDocument, "office-document-common-attrs", array(), "");
    // function 'addNewBranch()' is defined in 'webservice.inc.php'
    // Add scripts:
    addNewBranch($odfDocument, "office:scripts", array(), "");
    // Add font face declarations:
    $odfDocumentFontFaceDcls = new XMLBranch("office:font-face-decls");
    addNewBranch($odfDocumentFontFaceDcls, "style:font-face", array("style:name" => "Arial1", "svg:font-family" => "Arial", "style:font-pitch" => "variable"), "");
    addNewBranch($odfDocumentFontFaceDcls, "style:font-face", array("style:name" => "Lucidasans", "svg:font-family" => "Lucidasans", "style:font-pitch" => "variable"), "");
    addNewBranch($odfDocumentFontFaceDcls, "style:font-face", array("style:name" => "Arial", "svg:font-family" => "Arial", "style:font-family-generic" => "swiss", "style:font-pitch" => "variable"), "");
    $odfDocument->addXMLBranch($odfDocumentFontFaceDcls);
    // Add automatic styles:
    if ($odfBodyContentType == "spreadsheet") {
        $odfDocumentAutoStyles = new XMLBranch("office:automatic-styles");
        // Define table style:
        $odfDocumentStyle = new XMLBranch("style:style");
        $odfDocumentStyle->setTagAttribute("style:name", "ta1");
        $odfDocumentStyle->setTagAttribute("style:family", "table");
        $odfDocumentStyle->setTagAttribute("style:master-page-name", "Default");
        addNewBranch($odfDocumentStyle, "style:table-properties", array("table:display" => "true", "style:writing-mode" => "lr-tb"), "");
        $odfDocumentAutoStyles->addXMLBranch($odfDocumentStyle);
        // Define style for first table row:
        $odfDocumentStyle = new XMLBranch("style:style");
        $odfDocumentStyle->setTagAttribute("style:name", "ro1");
        $odfDocumentStyle->setTagAttribute("style:family", "table-row");
        addNewBranch($odfDocumentStyle, "style:table-row-properties", array("style:row-height" => "0.1681in", "fo:break-before" => "auto", "style:use-optimal-row-height" => "true"), "");
        $odfDocumentAutoStyles->addXMLBranch($odfDocumentStyle);
        // Define style for all other table rows:
        $odfDocumentStyle = new XMLBranch("style:style");
        $odfDocumentStyle->setTagAttribute("style:name", "ro2");
        $odfDocumentStyle->setTagAttribute("style:family", "table-row");
        addNewBranch($odfDocumentStyle, "style:table-row-properties", array("style:row-height" => "0.6425in", "fo:break-before" => "auto", "style:use-optimal-row-height" => "true"), "");
        $odfDocumentAutoStyles->addXMLBranch($odfDocumentStyle);
        $odfDocument->addXMLBranch($odfDocumentAutoStyles);
    }
    // Add body:
    $odfDocumentBody = new XMLBranch("office:body");
    if ($odfBodyContentType == "spreadsheet") {
        $odfSpreadsheet = odfSpreadsheet($result);
        $odfDocumentBody->addXMLasBranch($odfSpreadsheet);
    }
    $odfDocument->addXMLBranch($odfDocumentBody);
    $odfDocumentDoc->setXML($odfDocument);
    $odfDocumentString = $odfDocumentDoc->getXMLString();
    return $odfDocumentString;
}
Beispiel #5
0
function atomGenerateBaseTags($atomOperation)
{
    global $officialDatabaseName;
    // these variables are specified in 'ini.inc.php'
    global $databaseBaseURL;
    global $feedbackEmail;
    global $contentTypeCharset;
    global $convertExportDataToUTF8;
    global $logoImageURL;
    global $faviconImageURL;
    global $query;
    $atomCollection = new XML("feed");
    $atomCollection->setTagAttribute("xmlns", "http://www.w3.org/2005/Atom");
    $atomCollection->setTagAttribute("xmlns:opensearch", "http://a9.com/-/spec/opensearch/1.1/");
    $atomCollection->setTagAttribute("xmlns:unapi", "http://unapi.info/");
    // NOTE: is the unAPI namespace ok? Or should we use "http://unapi.info/specs/", or maybe something like "http://purl.org/unapi/ns/" ?
    $atomCollection->setTagAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
    $atomCollection->setTagAttribute("xmlns:dcterms", "http://purl.org/dc/terms/");
    $atomCollection->setTagAttribute("xmlns:prism", "http://prismstandard.org/namespaces/1.2/basic/");
    $officialDatabaseNameConv = encodeHTMLspecialchars($officialDatabaseName);
    // function 'encodeHTMLspecialchars()' is defined in 'include.inc.php'
    if ($atomOperation != "Error") {
        // convert database name to UTF-8:
        // (if '$convertExportDataToUTF8' is set to "yes" in 'ini.inc.php' and character encoding is not UTF-8 already)
        if ($convertExportDataToUTF8 == "yes" and $contentTypeCharset != "UTF-8") {
            $officialDatabaseNameConv = convertToCharacterEncoding("UTF-8", "IGNORE", $officialDatabaseNameConv);
        }
        // function 'convertToCharacterEncoding()' is defined in 'include.inc.php'
    }
    // ----------------------------------------------------------
    // Add feed-level tags:
    // (not yet used: category, contributor, rights)
    // - 'title':
    addNewBranch($atomCollection, "title", array("type" => "text"), $officialDatabaseNameConv);
    // - 'subtitle':
    if ($atomOperation == "Error") {
        addNewBranch($atomCollection, "subtitle", array(), "Search error!");
    } else {
        // ...extract the 'WHERE' clause from the SQL query to include a natural-language version (well, sort of) within the 'subtitle' element:
        $queryWhereClause = extractWHEREclause($query);
        // function 'extractWHEREclause()' is defined in 'include.inc.php'
        // construct a meaningful feed description based on the actual 'WHERE' clause:
        // TODO: For Atom XML, the query string should not get HTML encoded!
        $subTitle = "Displays records where " . encodeHTML(explainSQLQuery($queryWhereClause));
        // functions 'encodeHTML()' and 'explainSQLQuery()' are defined in 'include.inc.php'
        addNewBranch($atomCollection, "subtitle", array(), $subTitle);
    }
    // - 'updated':
    //    (TODO: the timestamp in the 'updated' element should really only get updated if any of the matching records was updated, right?)
    addNewBranch($atomCollection, "updated", array(), generateISO8601TimeStamp());
    // function 'generateISO8601TimeStamp()' is defined in 'include.inc.php'
    // - 'author':
    $authorBranch = new XMLBranch("author");
    $authorBranch->setTagContent($officialDatabaseNameConv, "author/name");
    $authorBranch->setTagContent($feedbackEmail, "author/email");
    $authorBranch->setTagContent($databaseBaseURL, "author/uri");
    $atomCollection->addXMLBranch($authorBranch);
    // - 'generator', 'icon', 'logo':
    addNewBranch($atomCollection, "generator", array("uri" => "http://www.refbase.net/", "version" => "0.9.5"), "Web Reference Database (http://refbase.sourceforge.net)");
    addNewBranch($atomCollection, "icon", array(), $databaseBaseURL . $faviconImageURL);
    addNewBranch($atomCollection, "logo", array(), $databaseBaseURL . $logoImageURL);
    // - 'link' (more links will be added in function 'atomCollection()'):
    //   - link to OpenSearch Description file:
    atomLink($atomCollection, $databaseBaseURL . "opensearch.php?operation=explain", "search", "OpenSearch", $officialDatabaseNameConv);
    //   - link to unAPI server:
    atomLink($atomCollection, $databaseBaseURL . "unapi.php", "unapi:unapi-server", "unAPI", "unAPI");
    return $atomCollection;
}
Beispiel #6
0
function addMetaElement(&$object, $namespace, $elementName, $elementAttributeArray, $elementContent, $elementType = "", $format = "xml")
{
    $addStatus = false;
    if (!empty($elementName) and !empty($elementContent)) {
        // Preprocess element contents (if necessary):
        // - 'creator', 'contributor':
        if (preg_match("/^(creator|contributor)\$/", $elementName)) {
            $elementContent = getPersons($elementContent);
        } elseif ($elementName == "identifier" and $elementType == "doi") {
            $elementContent = "info:doi/" . $elementContent;
        } elseif ($elementName == "identifier" and $elementType == "pmid") {
            // extract any PubMed ID from the given '$elementContent':
            // NOTE: should this better be done in the calling function?
            $pubmedID = preg_replace("/.*?PMID *: *(\\d+).*/i", "\\1", $elementContent);
            $elementContent = "info:pmid/" . $pubmedID;
        } elseif ($elementName == "identifier" and $elementType == "arxiv") {
            // extract any arXiv ID from the given '$elementContent':
            // NOTE: see note for PMID
            $arxivID = preg_replace("/.*?arXiv *: *([^ ;]+).*/i", "\\1", $elementContent);
            $elementContent = "info:arxiv/" . $arxivID;
        } elseif ($elementName == "identifier" and $elementType == "isbn") {
            $elementContent = "urn:ISBN:" . $elementContent;
        } elseif ($elementName == "identifier" and $elementType == "issn") {
            $elementContent = "urn:ISSN:" . $elementContent;
        } elseif ($elementName == "identifier" and $elementType == "openurl") {
            if (!preg_match("/^openurl:/", $elementContent)) {
                $elementContent = "openurl:" . $elementContent;
            }
            // use "openurl:" prefix if doesn't already exist in the given OpenURL
        } elseif ($elementName == "identifier" and $elementType == "url") {
            $elementContent = "url:" . $elementContent;
        } elseif ($elementName == "identifier" and $elementType == "citekey") {
            $elementContent = "citekey:" . $elementContent;
        } elseif ($elementName == "identifier" and $elementType == "citation") {
            $elementContent = "citation:" . $elementContent;
        } elseif ($elementName == "source" and $elementType == "series") {
            $elementContent = "series:" . $elementContent;
        } elseif ($elementName == "source" and $elementType == "issn") {
            $elementContent = "urn:ISSN:" . $elementContent;
        } elseif ($elementName == "relation" and $elementType == "url") {
            $elementContent = "url:" . $elementContent;
        } elseif ($elementName == "relation" and $elementType == "file") {
            $elementContent = "file:" . $elementContent;
        } elseif ($elementName == "type") {
            if (preg_match("/^((Simple|oai)?[- _]?(dc|Dublin[- _]?Core)[- _]?(terms)?)\$/i", $namespace)) {
                // Map refbase types to the corresponding eprint/resource types suggested for Simple
                // Dublin Core (<http://eprints-uk.rdn.ac.uk/project/docs/simpledc-guidelines/#type>):
                $dcTypesArray = mapDCTypes();
                // NOTE: for '$elementName="type"', variable '$elementType' is supposed to contain the
                //       thesis type from the refbase 'thesis' field (e.g. "Ph.D. thesis")
                if (isset($dcTypesArray[$elementContent]) and empty($elementType)) {
                    $elementContent = $dcTypesArray[$elementContent];
                } elseif (!empty($elementType)) {
                    $elementContent = $dcTypesArray["Thesis"];
                }
            }
        }
        // - 'subject':
        if ($elementName == "subject") {
            $elementContent = preg_split("/\\s*;\\s*/", $elementContent, -1, PREG_SPLIT_NO_EMPTY);
        }
        // get an array of all keywords
        // - 'language':
        //   TODO: convert to ISO notation (i.e. "en" instead of "English", etc)
        //         see <http://www.loc.gov/standards/iso639-2/php/code_list.php>
        if ($elementName == "language") {
            $elementContent = preg_split("/\\s*[;,]\\s*/", $elementContent, -1, PREG_SPLIT_NO_EMPTY);
        }
        // get an array of all languages
        // Prefix element name with given namespace:
        if (!empty($namespace)) {
            $elementName = $namespace . ":" . $elementName;
        }
        // Add metadata element(s) to the given object:
        if (is_array($elementContent)) {
            foreach ($elementContent as $singleElement) {
                addNewBranch($object, $elementName, $elementAttributeArray, $singleElement);
            }
        } else {
            // add string in '$elementContent' as a new element:
            addNewBranch($object, $elementName, $elementAttributeArray, $elementContent);
        }
        $addStatus = true;
    }
    return $addStatus;
}