예제 #1
0
function addNewBranch(&$thisBranch, $elementName, $elementAttributeArray, $elementContent)
{
    $newBranch = new XMLBranch($elementName);
    if (!empty($elementAttributeArray)) {
        foreach ($elementAttributeArray as $elementAttributeKey => $elementAttributeValue) {
            $newBranch->setTagAttribute($elementAttributeKey, $elementAttributeValue);
        }
    }
    if (!empty($elementContent)) {
        $newBranch->setTagContent($elementContent);
    }
    $thisBranch->addXMLBranch($newBranch);
}
예제 #2
0
 /**
  *	Returns HTML-formatted RSS items
  *	@method		getHTMLTitlesFormatted
  *	@returns	string HTML-formatted RSS items
  */
 function getHTMLTitlesFormatted()
 {
     $itemBranchesXML = new XML_("ul");
     reset($this->itemBranches);
     foreach ($this->itemBranches as $newsItem) {
         $itemXML = new XMLBranch("li");
         $itemLinkXML = new XMLBranch("a");
         $itemLinkXML->setTagContent($newsItem->getTagContent("item/title"));
         $itemLinkXML->setTagAttribute("href", $newsItem->getTagContent("item/link"));
         $itemXML->addXMLBranch($itemLinkXML);
         $itemBranchesXML->addXMLBranch($itemXML);
     }
     return $itemBranchesXML->getXMLString();
 }
예제 #3
0
 /**
  *	Returns class documentation as a string, formatted in HTML
  *	@method		getClassDocFromClass
  *	@param		object objClass
  *	@returns	string HTML-formatted documentation if successful, false otherwise
  */
 function getClassDocFromClass($objClass)
 {
     if (is_object($objClass) && get_class($objClass) == "phpclass") {
         $classDocXML = new XML("html");
         // ---------------------- HEAD ---------------------- //
         $headXML = new XMLBranch("head");
         $headXML->setTagContent($objClass->getInfo("name"), "head/title");
         $headXML->setTagContent("", "head/meta");
         $headXML->setTagAttribute("http-equiv", "content-type", "head/meta");
         $headXML->setTagAttribute("content", "text/html; charset=ISO-8859-1", "head/meta");
         $headXML->setTagContent($this->CSSStringDefault, "head/style");
         $headXML->setTagAttribute("type", "text/css", "head/style");
         // ---------------------- BODY ---------------------- //
         $bodyXML = new XMLBranch("body");
         $classTitleXML = new XMLBranch("h1");
         $classTitleXML->setTagAttribute("class", "classTitle");
         $classTitleXML->setTagContent($objClass->getInfo("name") . " Class");
         $bodyXML->addXMLBranch($classTitleXML);
         foreach ($objClass->info as $infoKey => $infoValue) {
             $brXML = new XMLBranch("br");
             $bodyXML->addXMLBranch($brXML);
             if (is_array($infoValue)) {
                 $spanXML = new XMLBranch("span");
                 $spanXML->setTagAttribute("class", $infoKey);
                 $spanXML->setTagContent(ucfirst($infoKey) . ":");
                 $ulXML = new XMLBranch("ul");
                 $ulXML->setTagAttribute("class", $infoKey);
                 foreach ($infoValue as $value) {
                     $liXML = new XMLBranch("li");
                     $liXML->setTagContent($value);
                     $ulXML->addXMLBranch($liXML);
                 }
                 $bodyXML->addXMLBranch($spanXML);
                 $bodyXML->addXMLBranch($ulXML);
             } else {
                 $spanXML = new XMLBranch("span");
                 $spanXML->setTagAttribute("class", $infoKey);
                 $spanXML->setTagContent(ucfirst($infoKey) . ": " . $infoValue);
                 $bodyXML->addXMLBranch($spanXML);
             }
         }
         $hrXML = new XMLBranch("hr");
         $bodyXML->addXMLBranch($hrXML);
         $h2XML = new XMLBranch("h2");
         $h2XML->setTagAttribute("class", "methodsTitle");
         $h2XML->setTagContent("All Methods");
         $bodyXML->addXMLBranch($h2XML);
         $spanXML = new XMLBranch("span");
         $spanXML->setTagAttribute("class", "methodList");
         foreach ($objClass->methods as $methodName => $method) {
             $aMethodXML = new XMLBranch("a");
             $aMethodXML->setTagAttribute("href", "#" . $methodName);
             $aMethodXML->setTagContent($methodName);
             $brXML = new XMLBranch("br");
             $spanXML->addXMLBranch($aMethodXML);
             $spanXML->addXMLBranch($brXML);
         }
         $bodyXML->addXMLBranch($spanXML);
         foreach ($objClass->methods as $methodName => $method) {
             $hrXML = new XMLBranch("hr");
             $bodyXML->addXMLBranch($hrXML);
             $pMethodXML = new XMLBranch("p");
             $aMethodXML = new XMLBranch("a");
             $aMethodXML->setTagAttribute("name", $methodName);
             $spanXMLName = new XMLBranch("span");
             $spanXMLName->setTagAttribute("class", "methodName");
             $spanXMLName->setTagContent($methodName);
             $spanXMLArgs = new XMLBranch("span");
             $tagContentArgs = " ( ";
             if (is_array($method->params) && count($method->params) > 0) {
                 $paramCount = 0;
                 foreach ($method->params as $key => $value) {
                     if ($paramCount > 0) {
                         $tagContentArgs .= ", ";
                     }
                     $tagContentArgs .= $key;
                     $paramCount++;
                 }
             }
             $tagContentArgs .= " )";
             $spanXMLArgs->setTagContent($tagContentArgs);
             $aMethodXML->addXMLBranch($spanXMLName);
             $aMethodXML->addXMLBranch($spanXMLArgs);
             $pMethodXML->addXMLBranch($aMethodXML);
             $bodyXML->addXMLBranch($pMethodXML);
             unset($method->info["name"]);
             foreach ($method->info as $infoKey => $infoValue) {
                 if (is_array($infoValue)) {
                     $pXML = new XMLBranch("p");
                     $pXML->setTagAttribute("class", $infoKey);
                     $pXML->setTagContent(ucfirst($infoKey) . ":");
                     $ulXML = new XMLBranch("ul");
                     $ulXML->setTagAttribute("class", $infoKey);
                     foreach ($infoValue as $value) {
                         $liXML = new XMLBranch("li");
                         $liXML->setTagContent($value);
                         $ulXML->addXMLBranch($liXML);
                     }
                     $bodyXML->addXMLBranch($pXML);
                     $bodyXML->addXMLBranch($ulXML);
                 } else {
                     $pXML = new XMLBranch("p");
                     $pXML->setTagAttribute("class", $infoKey);
                     $pXML->setTagContent(ucfirst($infoKey) . ": " . $infoValue);
                     $bodyXML->addXMLBranch($pXML);
                 }
             }
             if (is_array($method->params) && count($method->params) > 0) {
                 $pParamXML = new XMLBranch("p");
                 //$pParamXML->setTagAttribute("class", "param");
                 $paramTitleXML = new XMLBranch("span");
                 $paramTitleXML->setTagContent("Arguments:");
                 $pParamXML->addXMLBranch($paramTitleXML);
                 $paramListXML = new XMLBranch("ul");
                 foreach ($method->params as $key => $value) {
                     $paramItemXML = new XMLBranch("li");
                     $paramItemXML->setTagAttribute("class", "param");
                     $paramItemXML->setTagContent($key);
                     $paramListXML->addXMLBranch($paramItemXML);
                 }
                 $pParamXML->addXMLBranch($paramListXML);
                 $bodyXML->addXMLBranch($pParamXML);
             }
         }
         // ---------------------- END  ---------------------- //
         $classDocXML->addXMLBranch($headXML);
         $classDocXML->addXMLBranch($bodyXML);
         return $classDocXML->getXMLString(0);
     } else {
         return false;
     }
 }
예제 #4
0
function srwExplainResponse($exportStylesheet)
{
    global $contentTypeCharset;
    // these variables are specified in 'ini.inc.php'
    global $databaseBaseURL;
    global $officialDatabaseName;
    global $hostInstitutionName;
    global $feedbackEmail;
    global $logoImageURL;
    global $defaultLanguage;
    global $defaultFeedFormat;
    global $loc;
    // defined in 'locales/core.php'
    $srwCollectionDoc = new XMLDocument();
    $srwCollectionDoc->setEncoding($contentTypeCharset);
    $srwCollection = srwGenerateBaseTags("explainResponse");
    $srwRecordBranch = new XMLBranch("srw:record");
    srwGeneratePackingSchema($srwRecordBranch, "xml", "zeerex");
    $srwRecordDataBranch = new XMLBranch("srw:recordData");
    $srwExplainBranch = new XMLBranch("explain");
    $srwExplainBranch->setTagAttribute("xmlns", "http://explain.z3950.org/dtd/2.0/");
    $srwExplainBranch->setTagAttribute("xmlns:refb", "http://refbase.net/");
    // extract the protocol from the base URL:
    if (preg_match("#^([^:]+)://.*#", $databaseBaseURL)) {
        $databaseProtocol = preg_replace("#^([^:]+)://.*#", "\\1", $databaseBaseURL);
    } else {
        $databaseProtocol = "";
    }
    // extract the host from the base URL:
    if (preg_match("#^[^:]+://(?:www\\.)?[^/]+.*#", $databaseBaseURL)) {
        $databaseHost = preg_replace("#^[^:]+://(?:www\\.)?([^/]+).*#", "\\1", $databaseBaseURL);
    } else {
        $databaseHost = $databaseBaseURL;
    }
    // extract the path on server from the base URL:
    if (preg_match("#^[^:]+://(?:www\\.)?[^/]+/.+#", $databaseBaseURL)) {
        $databasePathOnServer = preg_replace("#^[^:]+://(?:www\\.)?[^/]+/(.+)#", "\\1", $databaseBaseURL);
    } else {
        $databasePathOnServer = "";
    }
    // get the total number of records in the database:
    $recordCount = getTotalNumberOfRecords();
    // function 'getTotalNumberOfRecords()' is defined in 'include.inc.php'
    // get the default number of records per page preferred by the current user:
    $showRows = $_SESSION['userRecordsPerPage'];
    // get date/time information when the database was last modified:
    $lastModified = getLastModifiedDateTime();
    // function 'getLastModifiedDateTime()' is defined in 'include.inc.php'
    // --- begin server info ------------------------------------
    $srwServerInfoBranch = new XMLBranch("serverInfo");
    $srwServerInfoBranch->setTagAttribute("protocol", "SRU");
    $srwServerInfoBranch->setTagAttribute("version", "1.1");
    if (!empty($databaseProtocol)) {
        $srwServerInfoBranch->setTagAttribute("transport", $databaseProtocol);
    }
    $srwServerInfoBranch->setTagContent($databaseHost, "serverInfo/host");
    $srwServerInfoBranch->setTagContent("80", "serverInfo/port");
    // NOTE: this should really be a variable in 'ini.inc.php' or such
    addNewBranch($srwServerInfoBranch, "database", array("numRecs" => $recordCount, "lastUpdate" => $lastModified), $databasePathOnServer . "sru.php");
    // function 'addNewBranch()' is defined in 'webservice.inc.php'
    // IMPORTANT: if you want to allow remote users who are NOT logged in (userID=0) to query the refbase database
    //            via 'sru.php' then either the 'Export' or the 'Batch export' user permission needs to be
    //            enabled at 'user_options.php?userID=0'. This will allow export of XML records via 'sru.php'
    //            but won't allow a user who isn't logged in to export records via the web interface. However, you
    //            should be aware that a direct GET query like 'show.php?author=miller&submit=Export&exportFormat=MODS%20XML'
    //            will be also allowed then!
    // As an alternative, you can provide explicit login information within the 'serverInfo/authentication' tag
    // below. But, obviously, the provided login information should be only given for an account that has the
    // 'Export' permission bit enabled but has otherwise limited access rights!
    // If the 'authentication' element is present, but empty, then it implies that authentication is required
    // to connect to the server, however there is no publically available login. If it contains a string, then
    // this is the token to give in order to authenticate. Otherwise it may contain three elements:
    // 1. user: The username to supply.
    // 2. group: The group to supply.
    // 3. password: The password to supply.
    //		$srwServerInfoAuthenticationBranch = new XMLBranch("authentication");
    //		$srwServerInfoAuthenticationBranch->setTagContent("LOGINEMAIL", "authentication/user");
    //		$srwServerInfoAuthenticationBranch->setTagContent("PASSWORD", "authentication/password");
    //		$srwServerInfoBranch->addXMLBranch($srwServerInfoAuthenticationBranch);
    $srwExplainBranch->addXMLBranch($srwServerInfoBranch);
    // --- end server info --------------------------------------
    // --- begin database info ----------------------------------
    $srwDatabaseInfoBranch = new XMLBranch("databaseInfo");
    addNewBranch($srwDatabaseInfoBranch, "title", array("lang" => $defaultLanguage, "primary" => "true"), $officialDatabaseName);
    addNewBranch($srwDatabaseInfoBranch, "description", array("lang" => $defaultLanguage, "primary" => "true"), encodeHTMLspecialchars($loc["ThisDatabaseAttempts"]));
    $srwDatabaseInfoBranch->setTagContent(encodeHTMLspecialchars($hostInstitutionName), "databaseInfo/author");
    $srwDatabaseInfoBranch->setTagContent(encodeHTMLspecialchars($hostInstitutionName) . " (" . $feedbackEmail . ")", "databaseInfo/contact");
    $srwDatabaseImplementationBranch = new XMLBranch("implementation");
    $srwDatabaseImplementationBranch->setTagAttribute("version", "0.9.6");
    $srwDatabaseImplementationBranch->setTagAttribute("identifier", "refbase");
    $srwDatabaseImplementationBranch->setTagContent("Web Reference Database (http://refbase.sourceforge.net)", "implementation/title");
    $srwDatabaseInfoBranch->addXMLBranch($srwDatabaseImplementationBranch);
    $srwDatabaseLinksBranch = new XMLBranch("links");
    addNewBranch($srwDatabaseLinksBranch, "link", array("type" => "www"), $databaseBaseURL);
    addNewBranch($srwDatabaseLinksBranch, "link", array("type" => "sru"), $databaseBaseURL . "sru.php");
    addNewBranch($srwDatabaseLinksBranch, "link", array("type" => "rss"), $databaseBaseURL . generateURL("show.php", $defaultFeedFormat, array("where" => 'serial RLIKE ".+"'), true, $showRows));
    // function 'generateURL()' is defined in 'include.inc.php'
    addNewBranch($srwDatabaseLinksBranch, "link", array("type" => "icon"), $databaseBaseURL . $logoImageURL);
    $srwDatabaseInfoBranch->addXMLBranch($srwDatabaseLinksBranch);
    $srwExplainBranch->addXMLBranch($srwDatabaseInfoBranch);
    // --- end database info ------------------------------------
    // --- begin index info -------------------------------------
    $srwIndexInfoBranch = new XMLBranch("indexInfo");
    addNewBranch($srwIndexInfoBranch, "set", array("identifier" => "info:srw/cql-context-set/1/cql-v1.1", "name" => "cql"), "");
    addNewBranch($srwIndexInfoBranch, "set", array("identifier" => "info:srw/cql-context-set/1/dc-v1.1", "name" => "dc"), "");
    addNewBranch($srwIndexInfoBranch, "set", array("identifier" => "http://zing.z3950.org/cql/bath/2.0/", "name" => "bath"), "");
    addNewBranch($srwIndexInfoBranch, "set", array("identifier" => "info:srw/cql-context-set/2/rec-1.1", "name" => "rec"), "");
    // TODO: The index info of the refbase explain response should also list the original refbase field names,
    //       similar to how the COPAC SRU gateway does it (<http://tweed.lib.ed.ac.uk:8080/elf/search/copac>).
    //       Example:
    //			<index search="true" scan="false" sort="false">
    //				<title>Author</title>
    //				<map>
    //					<name>
    //						author
    //					</name>
    //				</map>
    //				<map>
    //					<name set="dc">
    //						creator
    //					</name>
    //				</map>
    //			</index>
    $indexArray = array();
    // TODO: '$indexArray' should be an array of arrays so that it can hold multiple mappings
    $indexArray["dc.creator"] = array("_set" => "dc", "_index" => "creator", "_title" => "author(s) of the resource", "_refbaseIndex" => "refbase-author");
    $indexArray["dc.title"] = array("_set" => "dc", "_index" => "title", "_title" => "publication title of the resource", "_refbaseIndex" => "refbase-title");
    $indexArray["dc.date"] = array("_set" => "dc", "_index" => "date", "_title" => "year of publication of the resource", "_refbaseIndex" => "refbase-year");
    $indexArray["dc.language"] = array("_set" => "dc", "_index" => "language", "_title" => "language of the resource", "_refbaseIndex" => "refbase-language");
    $indexArray["dc.description"] = array("_set" => "dc", "_index" => "description", "_title" => "abstract or summary of the resource", "_refbaseIndex" => "refbase-abstract");
    $indexArray["dc.contributor"] = array("_set" => "dc", "_index" => "contributor", "_title" => "editor(s) of the resource", "_refbaseIndex" => "refbase-editor");
    // the mapping dc.contributor <-> refbase-editor might be suboptimal, but probably as best as we can do for now
    $indexArray["dc.subject"] = array("_set" => "dc", "_index" => "subject", "_title" => "topic of the resource", "_refbaseIndex" => "refbase-keywords");
    $indexArray["dc.format"] = array("_set" => "dc", "_index" => "format", "_title" => "physical or digital manifestation of the resource", "_refbaseIndex" => "refbase-medium");
    // Note: Currently, we simply expose the contents of the refbase 'type' field as 'dc.type'.
    //       This may not be ideal since it differs from the approved terms that should be used as values for the 'dc.type' element: <http://dublincore.org/documents/dcmi-type-vocabulary/>.
    //       However, the document "Using simple Dublin Core to describe eprints" (<http://eprints-uk.rdn.ac.uk/project/docs/simpledc-guidelines/#type>)
    //       recommends type values that are much closer (but still not identical) to our own type values.
    $indexArray["dc.type"] = array("_set" => "dc", "_index" => "type", "_title" => "nature or genre of the resource", "_refbaseIndex" => "refbase-type");
    $indexArray["dc.publisher"] = array("_set" => "dc", "_index" => "publisher", "_title" => "publisher", "_refbaseIndex" => "refbase-publisher");
    $indexArray["dc.coverage"] = array("_set" => "dc", "_index" => "coverage", "_title" => "geographic or topographic area of research", "_refbaseIndex" => "refbase-area");
    // Note: I'm note sure, if 'bath.name' (or maybe better: 'bath.personalName') can be also used to describe the author/creator ('dc.creator') of a publication
    //      "'Name Search -- Keyword' searches for complete word in headings (or references) for people, corporate bodies, conferences, and geographic names."
    //		$indexArray["bath.name"] = array("_set"          => "bath",
    //		                                 "_index"        => "name",
    //		                                 "_title"        => "author",
    //		                                 "_refbaseIndex" => "refbase-author");
    // Note: Not sure again whether 'bath.topicalSubject' can be offered as synonym for 'dc.subject'
    //       "'Topical Subject Search -- Keyword' searches for complete word in a topical subject heading or reference."
    //		$indexArray["bath.topicalSubject"] = array("_set"          => "bath",
    //		                                           "_index"        => "topicalSubject",
    //		                                           "_title"        => "keywords",
    //		                                           "_refbaseIndex" => "refbase-keywords");
    // NOTE: I'm not sure if 'isbn' is a valid name for the Bath Context Set? At least, it's not listed at <http://zing.z3950.org/srw/bath/2.0/#2>.
    //       However, 'bath.isbn' is used e.g. by <http://z3950.loc.gov:7090/voyager?operation=explain&version=1.1> and other SRU servers.
    $indexArray["bath.isbn"] = array("_set" => "bath", "_index" => "isbn", "_title" => "international standard book number", "_refbaseIndex" => "refbase-isbn");
    $indexArray["bath.issn"] = array("_set" => "bath", "_index" => "issn", "_title" => "international standard serial number", "_refbaseIndex" => "refbase-issn");
    $indexArray["bath.corporateName"] = array("_set" => "bath", "_index" => "corporateName", "_title" => "corporate author of this publication", "_refbaseIndex" => "refbase-corporate_author");
    $indexArray["bath.conferenceName"] = array("_set" => "bath", "_index" => "conferenceName", "_title" => "conference this publication was presented at", "_refbaseIndex" => "refbase-conference");
    // NOTE: I'm not sure if 'notes' is a valid name for the Bath Context Set?
    //       'bath.notes' is mentioned at <http://www.loc.gov/z3950/lcserver.html> and <http://zing.z3950.org/srw/bath/2.0/#3>.
    $indexArray["bath.notes"] = array("_set" => "bath", "_index" => "notes", "_title" => "notes about the resource", "_refbaseIndex" => "refbase-notes");
    $indexArray["rec.identifier"] = array("_set" => "rec", "_index" => "identifier", "_title" => "database record number", "_refbaseIndex" => "refbase-serial");
    $indexArray["rec.creationDate"] = array("_set" => "rec", "_index" => "creationDate", "_title" => "date/time at which the record was created", "_refbaseIndex" => "refbase-created_date-created_time");
    // 'sru.php': CQL search term should get splitted into date & time information!
    $indexArray["rec.creationAgentName"] = array("_set" => "rec", "_index" => "creationAgentName", "_title" => "name of the agent responsible for creation of the record", "_refbaseIndex" => "refbase-created_by");
    $indexArray["rec.lastModificationDate"] = array("_set" => "rec", "_index" => "lastModificationDate", "_title" => "date/time at which the record was last modified", "_refbaseIndex" => "refbase-modified_date-modified_time");
    // 'sru.php': CQL search term should get splitted into date & time information!
    $indexArray["rec.lastModificationAgentName"] = array("_set" => "rec", "_index" => "lastModificationAgentName", "_title" => "name of the agent responsible for last modifying the record", "_refbaseIndex" => "refbase-modified_by");
    $indexArray["bib.citekey"] = array("_set" => "bib", "_index" => "citekey", "_title" => "user-specific cite key for the record", "_refbaseIndex" => "refbase-cite_key");
    // Not sure how these fields can be mapped:
    // 		"publication" => "Book title or journal name",
    // 		"abbrev_journal" => "Abbreviated journal name",
    // 		"volume" => "Publication volume",
    // 		"issue" => "Publication issue",
    // 		"pages" => "Range or total number of pages",
    // 		"place" => "Place of publication",
    // 		"series_title" => "Series title",                     // -> could 'bath.seriesTitle' be used? compare with <http://www.loc.gov/z3950/lcserver.html> and <http://copac.ac.uk/interfaces/srw/>
    // 		"abbrev_series_title" => "Abbreviated series title",
    // 		"series_volume" => "Series volume",
    // 		"series_issue" => "Series issue",
    // 		"thesis" => "Thesis",
    // 		"doi" => "Digital object identifier",
    // 		"url" => "Uniform resource locator",
    foreach ($indexArray as $indexKey => $index) {
        $srwIndexBranch = new XMLBranch("index");
        $srwIndexBranch->setTagAttribute("search", "true");
        $srwIndexBranch->setTagAttribute("scan", "false");
        $srwIndexBranch->setTagAttribute("sort", "false");
        $srwIndexBranch->setTagAttribute("refb:index", $index["_refbaseIndex"]);
        addNewBranch($srwIndexBranch, "title", array("lang" => "en"), $index["_title"]);
        $srwIndexMapBranch = new XMLBranch("map");
        addNewBranch($srwIndexMapBranch, "name", array("set" => $index["_set"]), $index["_index"]);
        $srwIndexBranch->addXMLBranch($srwIndexMapBranch);
        $srwIndexInfoBranch->addXMLBranch($srwIndexBranch);
    }
    $srwExplainBranch->addXMLBranch($srwIndexInfoBranch);
    // --- end index info ---------------------------------------
    // --- begin schema info -------------------------------------
    $srwSchemaInfoBranch = new XMLBranch("schemaInfo");
    // MODS:
    $modsSchemaBranch = new XMLBranch("schema");
    $modsSchemaBranch->setTagAttribute("identifier", "http://www.loc.gov/mods/v3");
    // or should 'info:srw/schema/1/mods-v3.2' be used?
    $modsSchemaBranch->setTagAttribute("location", "http://www.loc.gov/standards/mods/v3/mods-3-0.xsd");
    $modsSchemaBranch->setTagAttribute("sort", "false");
    $modsSchemaBranch->setTagAttribute("retrieve", "true");
    $modsSchemaBranch->setTagAttribute("name", "mods");
    addNewBranch($modsSchemaBranch, "title", array("lang" => "en"), "Metadata Object Description Schema (MODS) v3");
    $srwSchemaInfoBranch->addXMLBranch($modsSchemaBranch);
    // Simple Dublin Core (DC):
    $dcSchemaBranch = new XMLBranch("schema");
    $dcSchemaBranch->setTagAttribute("identifier", "http://purl.org/dc/elements/1.1/");
    // or should 'info:srw/schema/1/dc-v1.1' be used?
    $dcSchemaBranch->setTagAttribute("location", "http://dublincore.org/schemas/xmls/simpledc20021212.xsd");
    $dcSchemaBranch->setTagAttribute("sort", "false");
    $dcSchemaBranch->setTagAttribute("retrieve", "true");
    $dcSchemaBranch->setTagAttribute("name", "dc");
    addNewBranch($dcSchemaBranch, "title", array("lang" => "en"), "Simple Dublin Core (DC) v1.1");
    $srwSchemaInfoBranch->addXMLBranch($dcSchemaBranch);
    // Simple Dublin Core (OAI_DC):
    // See recommendations for use of simple Dublin Core metadata to describe eprints in eprint archives: <http://eprints-uk.rdn.ac.uk/project/docs/simpledc-guidelines/>
    // Example SRW+DC output from LoC: <http://z3950.loc.gov:7090/voyager?query=dc.creator+%3D+%22miller%22&version=1.1&operation=searchRetrieve&recordSchema=dc&startRecord=1&maximumRecords=10>
    //		$oaidcSchemaBranch = new XMLBranch("schema");
    //		$oaidcSchemaBranch->setTagAttribute("identifier", "http://www.openarchives.org/OAI/2.0/oai_dc/");
    //		$oaidcSchemaBranch->setTagAttribute("location", "http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
    //		$oaidcSchemaBranch->setTagAttribute("sort", "false");
    //		$oaidcSchemaBranch->setTagAttribute("retrieve", "true");
    //		$oaidcSchemaBranch->setTagAttribute("name", "oai_dc");
    //
    //		addNewBranch($oaidcSchemaBranch, "title", array("lang" => "en"), "Simple Dublin Core for OAI-PMH (OAI_DC)");
    //
    //		$srwSchemaInfoBranch->addXMLBranch($oaidcSchemaBranch);
    $srwExplainBranch->addXMLBranch($srwSchemaInfoBranch);
    // --- end schema info ---------------------------------------
    // --- begin config info -------------------------------------
    $srwConfigInfoBranch = new XMLBranch("configInfo");
    // default:
    addNewBranch($srwConfigInfoBranch, "default", array("type" => "retrieveSchema"), "mods");
    addNewBranch($srwConfigInfoBranch, "default", array("type" => "numberOfRecords"), $showRows);
    addNewBranch($srwConfigInfoBranch, "default", array("type" => "stylesheet"), $databaseBaseURL . "srwmods2html.xsl");
    addNewBranch($srwConfigInfoBranch, "default", array("type" => "contextSet"), "cql");
    addNewBranch($srwConfigInfoBranch, "default", array("type" => "index"), "cql.serverChoice");
    addNewBranch($srwConfigInfoBranch, "default", array("type" => "relation"), "all");
    // setting:
    addNewBranch($srwConfigInfoBranch, "setting", array("type" => "sortSchema"), "identifier");
    addNewBranch($srwConfigInfoBranch, "setting", array("type" => "recordPacking"), "xml");
    // supports:
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "proximity"), "false");
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "resultSets"), "false");
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "relationModifier"), "false");
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "booleanModifier"), "false");
    // TODO: set to 'true' when Rob's CQL-PHP has been implemented successfully
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "sort"), "false");
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "maskingCharacter"), "true");
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "anchoring"), "true");
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "emptyTerm"), "false");
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "recordXPath"), "false");
    addNewBranch($srwConfigInfoBranch, "supports", array("type" => "scan"), "false");
    $srwExplainBranch->addXMLBranch($srwConfigInfoBranch);
    // --- end config info ---------------------------------------
    $srwRecordDataBranch->addXMLBranch($srwExplainBranch);
    $srwRecordBranch->addXMLBranch($srwRecordDataBranch);
    $srwCollection->addXMLBranch($srwRecordBranch);
    $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:explainResponse)/i", "<?xml-stylesheet type=\"text/xsl\" href=\"" . $exportStylesheet . "\"?>\n", $srwCollectionString);
    }
    return $srwCollectionString;
}
예제 #5
0
function modsRecord($row)
{
    global $databaseBaseURL;
    // these variables are defined in 'ini.inc.php'
    global $contentTypeCharset;
    global $fileVisibility;
    global $fileVisibilityException;
    global $filesBaseURL;
    global $convertExportDataToUTF8;
    // defined in 'transtab_unicode_charset.inc.php' and 'transtab_latin1_charset.inc.php'
    global $alnum, $alpha, $cntrl, $dash, $digit, $graph, $lower, $print, $punct, $space, $upper, $word, $patternModifiers;
    $exportPrivate = True;
    // This will be a global variable or will be used
    // when modsRow is called and will determine if we
    // export user-specific data
    $exportRecordURL = True;
    // Specifies whether an attribution string containing
    // the URL to the refbase database record (and the last
    // modification date) shall be written to the notes branch.
    // Note that this string is required by the "-A|--append"
    // feature of the 'refbase' command line client
    // convert this record's modified date/time info to UNIX time stamp format:
    // => "date('D, j M Y H:i:s O')", e.g. "Sat, 15 Jul 2006 22:24:16 +0200"
    // function 'generateRFC2822TimeStamp()' is defined in 'include.inc.php'
    $currentDateTimeStamp = generateRFC2822TimeStamp($row['modified_date'], $row['modified_time']);
    // --- BEGIN TYPE * ---
    //   |
    //   | These apply to everything
    // this is a stupid hack that maps the names of the '$row' array keys to those used
    // by the '$formVars' array (which is required by function 'generateCiteKey()')
    // (eventually, the '$formVars' array should use the MySQL field names as names for its array keys)
    $formVars = buildFormVarsArray($row);
    // function 'buildFormVarsArray()' is defined in 'include.inc.php'
    // generate or extract the cite key for this record
    // (note that charset conversion can only be done *after* the cite key has been generated,
    //  otherwise cite key generation will produce garbled text!)
    $citeKey = generateCiteKey($formVars);
    // function 'generateCiteKey()' is defined in 'include.inc.php'
    // Create an XML object for a single record.
    $record = new XML("mods");
    $record->setTagAttribute("version", "3.2");
    if (!empty($citeKey)) {
        $record->setTagAttribute("ID", $citeKey);
    }
    // titleInfo
    //   Regular Title
    if (!empty($row['title'])) {
        $record->setTagContent(encodeXMLField('title', $row['title']), "mods/titleInfo/title");
    }
    //   Translated Title
    //   NOTE: This field is excluded by the default cite SELECT method
    if (!empty($row['orig_title'])) {
        $orig_title = new XMLBranch("titleInfo");
        $orig_title->setTagAttribute("type", "translated");
        $orig_title->setTagContent(encodeXMLField('orig_title', $row['orig_title']), "titleInfo/title");
        $record->addXMLBranch($orig_title);
    }
    // name
    //   author
    if (!empty($row['author'])) {
        if (preg_match("/ *\\(eds?\\)\$/", $row['author'])) {
            $author = preg_replace("/[ \r\n]*\\(eds?\\)/i", "", $row['author']);
            $nameArray = separateNames("author", "/\\s*;\\s*/", "/\\s*,\\s*/", "/(?<=^|[{$word}])[^-{$word}]+|(?<=^|[{$upper}])(?=\$|[{$upper}])/{$patternModifiers}", $author, "personal", "editor");
        } else {
            if ($row['type'] == "Map") {
                $nameArray = separateNames("author", "/\\s*;\\s*/", "/\\s*,\\s*/", "/(?<=^|[{$word}])[^-{$word}]+|(?<=^|[{$upper}])(?=\$|[{$upper}])/{$patternModifiers}", $row['author'], "personal", "cartographer");
            } else {
                $nameArray = separateNames("author", "/\\s*;\\s*/", "/\\s*,\\s*/", "/(?<=^|[{$word}])[^-{$word}]+|(?<=^|[{$upper}])(?=\$|[{$upper}])/{$patternModifiers}", $row['author'], "personal", "author");
            }
        }
        foreach ($nameArray as $singleName) {
            $record->addXMLBranch($singleName);
        }
    }
    // originInfo
    if (!empty($row['year']) || !empty($row['publisher']) || !empty($row['place'])) {
        $origin = new XMLBranch("originInfo");
        // dateIssued
        if (!empty($row['year'])) {
            $origin->setTagContent(encodeXMLField('year', $row['year']), "originInfo/dateIssued");
        }
        // Book Chapters and Journal Articles only have a dateIssued
        // (editions, places, and publishers are associated with the host)
        if (!preg_match("/^(Book Chapter|Journal Article)\$/", $row['type'])) {
            // publisher
            if (!empty($row['publisher'])) {
                $origin->setTagContent(encodeXMLField('publisher', $row['publisher']), "originInfo/publisher");
            }
            // place
            if (!empty($row['place'])) {
                $origin->setTagContent(encodeXMLField('place', $row['place']), "originInfo/place/placeTerm");
                $origin->setTagAttribute("type", "text", "originInfo/place/placeTerm");
            }
            // edition
            if (!empty($row['edition'])) {
                $origin->setTagContent(encodeXMLField('edition', $row['edition']), "originInfo/edition");
            }
        }
        if ($origin->hasBranch()) {
            $record->addXMLBranch($origin);
        }
    }
    // language
    if (!empty($row['language'])) {
        $record->setTagContent(encodeXMLField('language', $row['language']), "mods/language");
    }
    // abstract
    // NOTE: This field is excluded by the default cite SELECT method
    if (!empty($row['abstract'])) {
        $abstract = new XMLBranch("abstract");
        $abstract->setTagContent(encodeXMLField('abstract', $row['abstract']));
        if (!empty($row['summary_language'])) {
            $abstract->setTagAttribute("lang", encodeXMLField('summary_language', $row['summary_language']));
        }
        $record->addXMLBranch($abstract);
    }
    // subject
    //   keywords
    if (!empty($row['keywords'])) {
        $subjectArray = array();
        $subjectArray = preg_split("/\\s*;\\s*/", $row['keywords']);
        // "unrelated" keywords
        foreach ($subjectArray as $singleSubject) {
            $subjectBranch = new XMLBranch("subject");
            $topicArray = array();
            $topicArray = preg_split("/\\s*,\\s*/", $singleSubject);
            // "related" keywords
            foreach ($topicArray as $singleTopic) {
                $topicBranch = new XMLBranch("topic");
                $topicBranch->setTagContent(encodeXMLField('keywords', $singleTopic));
                $subjectBranch->addXMLBranch($topicBranch);
            }
            $record->addXMLBranch($subjectBranch);
        }
    }
    //   user_keys
    //   NOTE: a copy of the above.  Needs to be a separate function later.
    if (!empty($row['user_keys']) && $exportPrivate) {
        $subjectArray = array();
        $subjectArray = preg_split("/\\s*;\\s*/", $row['user_keys']);
        // "unrelated" user_keys
        foreach ($subjectArray as $singleSubject) {
            $subjectBranch = new XMLBranch("subject");
            $topicArray = array();
            $topicArray = preg_split("/\\s*,\\s*/", $singleSubject);
            // "related" user_keys
            foreach ($topicArray as $singleTopic) {
                $topicBranch = new XMLBranch("topic");
                $topicBranch->setTagContent(encodeXMLField('user_keys', $singleTopic));
                $subjectBranch->addXMLBranch($topicBranch);
            }
            $record->addXMLBranch($subjectBranch);
        }
    }
    //   user_groups
    //   NOTE: a copy of the above.  Needs to be a separate function later.
    if (!empty($row['user_groups']) && $exportPrivate) {
        $subjectArray = array();
        $subjectArray = preg_split("/\\s*;\\s*/", $row['user_groups']);
        // "unrelated" user_groups
        foreach ($subjectArray as $singleSubject) {
            $subjectBranch = new XMLBranch("subject");
            $topicArray = array();
            $topicArray = preg_split("/\\s*,\\s*/", $singleSubject);
            // "related" user_groups
            foreach ($topicArray as $singleTopic) {
                $topicBranch = new XMLBranch("topic");
                $topicBranch->setTagContent(encodeXMLField('user_groups', $singleTopic));
                $subjectBranch->addXMLBranch($topicBranch);
            }
            $record->addXMLBranch($subjectBranch);
        }
    }
    // notes
    if (!empty($row['notes'])) {
        $record->setTagContent(encodeXMLField('notes', $row['notes']), "mods/note");
    }
    // user_notes
    if (!empty($row['user_notes']) && $exportPrivate) {
        // replaces any generic notes
        $record->setTagContent(encodeXMLField('user_notes', $row['user_notes']), "mods/note");
    }
    // refbase attribution string
    if ($exportRecordURL) {
        $attributionBranch = new XMLBranch("note");
        $attributionBranch->setTagContent("exported from refbase (" . $databaseBaseURL . "show.php?record=" . $row['serial'] . "), last updated on " . $currentDateTimeStamp);
        $record->addXMLBranch($attributionBranch);
    }
    // typeOfResource
    // maps are 'cartographic', software is 'software, multimedia',
    // and everything else is 'text'
    $type = new XMLBranch("typeOfResource");
    if ($row['type'] == "Map") {
        $type->setTagContent("cartographic");
    } else {
        if ($row['type'] == "Software") {
            $type->setTagContent("software, multimedia");
        } else {
            $type->setTagContent("text");
        }
    }
    if ($row['type'] == "Manuscript") {
        $type->setTagAttribute("manuscript", "yes");
    }
    $record->addXMLBranch($type);
    // location
    //   Physical Location
    //   NOTE: This field is excluded by the default cite SELECT method
    //         This should also be parsed later
    if (!empty($row['location'])) {
        $location = new XMLBranch("location");
        $locationArray = array();
        $locationArray = preg_split("/\\s*;\\s*/", $row['location']);
        foreach ($locationArray as $singleLocation) {
            $locationBranch = new XMLBranch("physicalLocation");
            $locationBranch->setTagContent(encodeXMLField('location', $singleLocation));
            $location->addXMLBranch($locationBranch);
        }
        $record->addXMLBranch($location);
    }
    //   URL (also an identifier, see below)
    //   NOTE: This field is excluded by the default cite SELECT method
    if (!empty($row['url'])) {
        $location = new XMLBranch("location");
        $location->setTagContent(encodeXMLField('url', $row['url']), "location/url");
        $record->addXMLBranch($location);
    }
    // Include a link to any corresponding FILE if one of the following conditions is met:
    // - the variable '$fileVisibility' (defined in 'ini.inc.php') is set to 'everyone'
    // - the variable '$fileVisibility' is set to 'login' AND the user is logged in
    // - the variable '$fileVisibility' is set to 'user-specific' AND the 'user_permissions' session variable contains 'allow_download'
    // - the array variable '$fileVisibilityException' (defined in 'ini.inc.php') contains a pattern (in array element 1) that matches the contents of the field given (in array element 0)
    if ($fileVisibility == "everyone" or $fileVisibility == "login" and isset($_SESSION['loginEmail']) or $fileVisibility == "user-specific" and (isset($_SESSION['user_permissions']) and preg_match("/allow_download/", $_SESSION['user_permissions'])) or !empty($fileVisibilityException) and preg_match($fileVisibilityException[1], $row[$fileVisibilityException[0]])) {
        //   file
        //   Note that when converting MODS to Endnote or RIS, Bibutils will include the above
        //   URL (if given), otherwise it'll take the URL from the 'file' field. I.e. for
        //   Endnote or RIS, the URL to the PDF is only included if no regular URL is available.
        if (!empty($row['file'])) {
            $location = new XMLBranch("location");
            if (preg_match('#^(https?|ftp|file)://#i', $row['file'])) {
                // if the 'file' field contains a full URL (starting with "http://", "https://",  "ftp://", or "file://")
                $URLprefix = "";
                // we don't alter the URL given in the 'file' field
            } else {
                // if the 'file' field contains only a partial path (like 'polarbiol/10240001.pdf') or just a file name (like '10240001.pdf')
                // use the base URL of the standard files directory as prefix:
                if (preg_match('#^/#', $filesBaseURL)) {
                    // absolute path -> file dir is located outside of refbase root dir
                    $URLprefix = 'http://' . $_SERVER['HTTP_HOST'] . $filesBaseURL;
                } else {
                    // relative path -> file dir is located within refbase root dir
                    $URLprefix = $databaseBaseURL . $filesBaseURL;
                }
            }
            $location->setTagContent(encodeXMLField('file', $URLprefix . $row['file']), "location/url");
            $location->setTagAttribute("displayLabel", "Electronic full text", "location/url");
            // the 'access' attribute requires MODS v3.2 or greater:
            $location->setTagAttribute("access", "raw object", "location/url");
            $record->addXMLBranch($location);
        }
    }
    // identifier
    //   url
    if (!empty($row['url'])) {
        $identifier = new XMLBranch("identifier");
        $identifier->setTagContent(encodeXMLField('url', $row['url']));
        $identifier->setTagAttribute("type", "uri");
        $record->addXMLBranch($identifier);
    }
    //   doi
    if (!empty($row['doi'])) {
        $identifier = new XMLBranch("identifier");
        $identifier->setTagContent(encodeXMLField('doi', $row['doi']));
        $identifier->setTagAttribute("type", "doi");
        $record->addXMLBranch($identifier);
    }
    //   pubmed
    //   NOTE: Until refbase stores PubMed & arXiv IDs in a better way,
    //         we extract them from the 'notes' field
    if (preg_match("/PMID *: *\\d+/i", $row['notes'])) {
        $identifier = new XMLBranch("identifier");
        $identifier->setTagContent(preg_replace("/.*?PMID *: *(\\d+).*/i", "\\1", $row['notes']));
        $identifier->setTagAttribute("type", "pubmed");
        $record->addXMLBranch($identifier);
    }
    //   arxiv
    //   NOTE: see note for pubmed
    if (preg_match("/arXiv *: *[^ ;]+/i", $row['notes'])) {
        $identifier = new XMLBranch("identifier");
        $identifier->setTagContent(preg_replace("/.*?arXiv *: *([^ ;]+).*/i", "\\1", $row['notes']));
        $identifier->setTagAttribute("type", "arxiv");
        $record->addXMLBranch($identifier);
    }
    //   cite_key
    if (!empty($citeKey)) {
        $identifier = new XMLBranch("identifier");
        $identifier->setTagContent(encodeXMLField('cite_key', $citeKey));
        $identifier->setTagAttribute("type", "citekey");
        $record->addXMLBranch($identifier);
    }
    //   local--CALL NUMBER
    //   NOTE: This should really be parsed!
    if (!empty($row['call_number'])) {
        $identifierArray = array();
        $identifierArray = preg_split("/\\s*;\\s*/", $row['call_number']);
        foreach ($identifierArray as $singleIdentifier) {
            if (!preg_match("/@\\s*\$/", $singleIdentifier)) {
                $identifierBranch = new XMLBranch("identifier");
                $identifierBranch->setTagContent(encodeXMLField('call_number', $singleIdentifier));
                $identifierBranch->setTagAttribute("type", "local");
                $record->addXMLBranch($identifierBranch);
            }
        }
    }
    // --- END TYPE * ---
    // -----------------------------------------
    // --- BEGIN TYPE != ABSTRACT || BOOK CHAPTER || CONFERENCE ARTICLE || JOURNAL ARTICLE || MAGAZINE ARTICLE || NEWSPAPER ARTICLE ---
    //   |
    //   | BOOK WHOLE, CONFERENCE VOLUME, JOURNAL, MANUAL, MANUSCRIPT, MAP, MISCELLANEOUS, PATENT,
    //   | REPORT, and SOFTWARE have some info as a branch off the root, whereas ABSTRACT, BOOK CHAPTER,
    //   | CONFERENCE ARTICLE, JOURNAL ARTICLE, MAGAZINE ARTICLE and NEWSPAPER ARTICLE place it in the relatedItem branch.
    if (!preg_match("/^(Abstract|Book Chapter|Conference Article|Journal Article|Magazine Article|Newspaper Article)\$/", $row['type'])) {
        // name
        //   editor
        if (!empty($row['editor'])) {
            $editor = $row['editor'];
            $author = $row['author'];
            if (preg_match("/ *\\(eds?\\)\$/", $editor)) {
                $editor = preg_replace("/[ \r\n]*\\(eds?\\)/i", "", $editor);
            }
            if (preg_match("/ *\\(eds?\\)\$/", $author)) {
                $author = preg_replace("/[ \r\n]*\\(eds?\\)/i", "", $author);
            }
            if ($editor != $author) {
                $nameArray = separateNames("editor", "/\\s*;\\s*/", "/\\s*,\\s*/", "/(?<=^|[{$word}])[^-{$word}]+|(?<=^|[{$upper}])(?=\$|[{$upper}])/{$patternModifiers}", $editor, "personal", "editor");
                foreach ($nameArray as $singleName) {
                    $record->addXMLBranch($singleName);
                }
            }
        }
        //   corporate
        //   (we treat a 'corporate_author' similar to how Bibutils converts the BibTeX
        //   'organization' field to MODS XML, i.e., we add a separate name element with
        //    a 'type="corporate"' attribute and an 'author' role (or a 'degree grantor'
        //    role in case of theses))
        if (!empty($row['corporate_author'])) {
            $nameBranch = new XMLBranch("name");
            $nameBranch->setTagAttribute("type", "corporate");
            $nameBranch->setTagContent(encodeXMLField('corporate_author', $row['corporate_author']), "name/namePart");
            if (empty($row['thesis'])) {
                $nameBranch->setTagContent("author", "name/role/roleTerm");
            } else {
                // thesis
                $nameBranch->setTagContent("degree grantor", "name/role/roleTerm");
            }
            $nameBranch->setTagAttribute("authority", "marcrelator", "name/role/roleTerm");
            $nameBranch->setTagAttribute("type", "text", "name/role/roleTerm");
            $record->addXMLBranch($nameBranch);
        }
        //   conference
        if (!empty($row['conference'])) {
            $nameBranch = new XMLBranch("name");
            $nameBranch->setTagAttribute("type", "conference");
            $nameBranch->setTagContent(encodeXMLField('conference', $row['conference']), "name/namePart");
            $record->addXMLBranch($nameBranch);
        }
        // genre
        //   type
        //      NOTE: Is there a better MARC genre[1] for 'manuscript?'
        //            [1]<http://www.loc.gov/marc/sourcecode/genre/genrelist.html>
        $genremarc = new XMLBranch("genre");
        $genre = new XMLBranch("genre");
        //      NOTE: According to the MARC "Source Codes for Genre"[1]
        //            the MARC authority should be 'marcgt', not 'marc'.
        //            [1]<http://www.loc.gov/marc/sourcecode/genre/genresource.html>
        $genremarc->setTagAttribute("authority", "marcgt");
        if (empty($row['thesis'])) {
            // theses will get their own genre (see below)
            if ($row['type'] == "Book Whole") {
                $record->setTagContent("monographic", "mods/originInfo/issuance");
                $genremarc->setTagContent("book");
            } else {
                if ($row['type'] == "Conference Volume") {
                    $genremarc->setTagContent("conference publication");
                } else {
                    if ($row['type'] == "Journal") {
                        $genremarc->setTagContent("periodical");
                        $genre->setTagContent("academic journal");
                    } else {
                        if ($row['type'] == "Manual") {
                            // should we set '<issuance>monographic' here (and for the ones below)?
                            $genremarc->setTagContent("instruction");
                            $genre->setTagContent("manual");
                        } else {
                            if ($row['type'] == "Manuscript") {
                                $genremarc->setTagContent("loose-leaf");
                                $genre->setTagContent("manuscript");
                            } else {
                                if ($row['type'] == "Map") {
                                    $genremarc->setTagContent("map");
                                } else {
                                    if ($row['type'] == "Miscellaneous") {
                                        $genre->setTagContent("miscellaneous");
                                    } else {
                                        if ($row['type'] == "Patent") {
                                            $genremarc->setTagContent("patent");
                                        } else {
                                            if ($row['type'] == "Report") {
                                                $genremarc->setTagContent("technical report");
                                                $genre->setTagContent("report");
                                            } else {
                                                if ($row['type'] == "Software") {
                                                    //        $genremarc->setTagContent("programmed text"); // would this be correct?
                                                    $genre->setTagContent("software");
                                                } else {
                                                    if (!empty($row['type'])) {
                                                        // catch-all: don't use a MARC genre
                                                        $genre->setTagContent(encodeXMLField('type', $row['type']));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($genremarc->hasLeaf()) {
                $record->addXMLBranch($genremarc);
            }
            if ($genre->hasLeaf()) {
                $record->addXMLBranch($genre);
            }
        } else {
            // if (!empty($row['thesis']))
            $record->setTagContent("monographic", "mods/originInfo/issuance");
            $thesismarc = new XMLBranch("genre");
            $thesis = new XMLBranch("genre");
            $thesismarc->setTagContent("thesis");
            $thesismarc->setTagAttribute("authority", "marcgt");
            // tweak thesis names so that Bibutils will recognize them:
            if ($row['thesis'] == "Master's thesis") {
                $row['thesis'] = "Masters thesis";
            }
            $thesis->setTagContent(encodeXMLField('thesis', $row['thesis']));
            $record->addXMLBranch($thesismarc);
            $record->addXMLBranch($thesis);
        }
        // physicalDescription
        //   pages
        if (!empty($row['pages'])) {
            $description = new XMLBranch("physicalDescription");
            $pages = new XMLBranch("extent");
            $pages->setTagAttribute("unit", "pages");
            if (preg_match("/[0-9] *- *[0-9]/", $row['pages'])) {
                // if a page range
                // split the page range into start and end pages
                list($pagestart, $pageend) = preg_split('/\\s*[-]\\s*/', $row['pages']);
                if ($pagestart < $pageend) {
                    // extents MUST span multiple pages
                    $pages->setTagContent(encodeXMLField('pages', $pagestart), "extent/start");
                    $pages->setTagContent(encodeXMLField('pages', $pageend), "extent/end");
                } else {
                    $pages->setTagContent(encodeXMLField('pages', $row['pages']));
                }
            } else {
                if (preg_match("/^\\d\\d*\\s*pp?.?\$/", $row['pages'])) {
                    list($pagetotal) = preg_split('/\\s*pp?/', $row['pages']);
                    $pages->setTagContent(encodeXMLField('pages', $pagetotal), "extent/total");
                } else {
                    $pages->setTagContent(encodeXMLField('pages', $row['pages']));
                }
            }
            $description->addXMLBranch($pages);
            $record->addXMLBranch($description);
        }
        // identifier
        //   isbn
        if (!empty($row['isbn'])) {
            $identifier = new XMLBranch("identifier");
            $identifier->setTagContent(encodeXMLField('isbn', $row['isbn']));
            $identifier->setTagAttribute("type", "isbn");
            $record->addXMLBranch($identifier);
        }
        //   issn
        if (!empty($row['issn'])) {
            $identifier = new XMLBranch("identifier");
            $identifier->setTagContent(encodeXMLField('issn', $row['issn']));
            $identifier->setTagAttribute("type", "issn");
            $record->addXMLBranch($identifier);
        }
        // series
        if (!empty($row['series_editor']) || !empty($row['series_title']) || !empty($row['abbrev_series_title']) || !empty($row['series_volume']) || !empty($row['series_issue'])) {
            $record->addXMLBranch(serialBranch($row['series_editor'], $row['series_title'], $row['abbrev_series_title'], $row['series_volume'], $row['series_issue']));
        }
    } else {
        // if (preg_match("/^(Abstract|Book Chapter|Conference Article|Journal Article|Magazine Article|Newspaper Article)$/", $row['type']))
        // relatedItem
        $related = new XMLBranch("relatedItem");
        $related->setTagAttribute("type", "host");
        // title (Publication)
        if (!empty($row['publication'])) {
            $related->setTagContent(encodeXMLField('publication', $row['publication']), "relatedItem/titleInfo/title");
        }
        // title (Abbreviated Journal)
        if (!empty($row['abbrev_journal'])) {
            $titleabbrev = new XMLBranch("titleInfo");
            $titleabbrev->setTagAttribute("type", "abbreviated");
            $titleabbrev->setTagContent(encodeXMLField('abbrev_journal', $row['abbrev_journal']), "titleInfo/title");
            $related->addXMLBranch($titleabbrev);
        }
        // name
        //   editor
        if (!empty($row['editor'])) {
            $editor = $row['editor'];
            if (preg_match("/ *\\(eds?\\)\$/", $editor)) {
                $editor = preg_replace("/[ \r\n]*\\(eds?\\)/i", "", $editor);
            }
            $nameArray = separateNames("editor", "/\\s*;\\s*/", "/\\s*,\\s*/", "/(?<=^|[{$word}])[^-{$word}]+|(?<=^|[{$upper}])(?=\$|[{$upper}])/{$patternModifiers}", $editor, "personal", "editor");
            foreach ($nameArray as $singleName) {
                $related->addXMLBranch($singleName);
            }
        }
        //   corporate
        //   NOTE: a copy of the code for 'corporate_author' above.
        //         Needs to be a separate function later.
        if (!empty($row['corporate_author'])) {
            $nameBranch = new XMLBranch("name");
            $nameBranch->setTagAttribute("type", "corporate");
            $nameBranch->setTagContent(encodeXMLField('corporate_author', $row['corporate_author']), "name/namePart");
            if (empty($row['thesis'])) {
                $nameBranch->setTagContent("author", "name/role/roleTerm");
            } else {
                // thesis
                $nameBranch->setTagContent("degree grantor", "name/role/roleTerm");
            }
            $nameBranch->setTagAttribute("authority", "marcrelator", "name/role/roleTerm");
            $nameBranch->setTagAttribute("type", "text", "name/role/roleTerm");
            $related->addXMLBranch($nameBranch);
        }
        //   conference
        //   NOTE: a copy of the code for 'conference' above.
        //         Needs to be a separate function later.
        if (!empty($row['conference'])) {
            $nameBranch = new XMLBranch("name");
            $nameBranch->setTagAttribute("type", "conference");
            $nameBranch->setTagContent(encodeXMLField('conference', $row['conference']), "name/namePart");
            $related->addXMLBranch($nameBranch);
        }
        // originInfo
        $relorigin = new XMLBranch("originInfo");
        // dateIssued
        if (!empty($row['year'])) {
            $relorigin->setTagContent(encodeXMLField('year', $row['year']), "originInfo/dateIssued");
        }
        // publisher
        if (!empty($row['publisher'])) {
            $relorigin->setTagContent(encodeXMLField('publisher', $row['publisher']), "originInfo/publisher");
        }
        // place
        if (!empty($row['place'])) {
            $relorigin->setTagContent(encodeXMLField('place', $row['place']), "originInfo/place/placeTerm");
            $relorigin->setTagAttribute("type", "text", "originInfo/place/placeTerm");
        }
        // edition
        if (!empty($row['edition'])) {
            $relorigin->setTagContent(encodeXMLField('edition', $row['edition']), "originInfo/edition");
        }
        if ($relorigin->hasBranch()) {
            $related->addXMLBranch($relorigin);
        }
        // genre (and originInfo/issuance)
        if (empty($row['thesis'])) {
            // theses will get their own genre (see below)
            if (preg_match("/^(Journal Article|Magazine Article)\$/", $row['type'])) {
                $related->setTagContent("continuing", "relatedItem/originInfo/issuance");
                $genremarc = new XMLBranch("genre");
                $genre = new XMLBranch("genre");
                $genremarc->setTagContent("periodical");
                $genremarc->setTagAttribute("authority", "marcgt");
                if ($row['type'] == "Magazine Article") {
                    $genre->setTagContent("magazine");
                } else {
                    $genre->setTagContent("academic journal");
                }
                $related->addXMLBranch($genremarc);
                $related->addXMLBranch($genre);
            } else {
                if ($row['type'] == "Abstract") {
                    $record->setTagContent("abstract or summary", "mods/genre");
                    $record->setTagAttribute("authority", "marcgt", "mods/genre");
                } else {
                    if ($row['type'] == "Conference Article") {
                        $related->setTagContent("conference publication", "relatedItem/genre");
                        $related->setTagAttribute("authority", "marcgt", "relatedItem/genre");
                    } else {
                        if ($row['type'] == "Newspaper Article") {
                            $related->setTagContent("continuing", "relatedItem/originInfo/issuance");
                            $related->setTagContent("newspaper", "relatedItem/genre");
                            $related->setTagAttribute("authority", "marcgt", "relatedItem/genre");
                        } else {
                            // if ($row['type'] == "Book Chapter")
                            $related->setTagContent("monographic", "relatedItem/originInfo/issuance");
                            $related->setTagContent("book", "relatedItem/genre");
                            $related->setTagAttribute("authority", "marcgt", "relatedItem/genre");
                        }
                    }
                }
            }
        } else {
            // if (!empty($row['thesis']))
            $thesismarc = new XMLBranch("genre");
            $thesis = new XMLBranch("genre");
            $thesismarc->setTagContent("thesis");
            $thesismarc->setTagAttribute("authority", "marcgt");
            // tweak thesis names so that Bibutils will recognize them:
            if ($row['thesis'] == "Master's thesis") {
                $row['thesis'] = "Masters thesis";
            }
            $thesis->setTagContent(encodeXMLField('thesis', $row['thesis']));
            $related->addXMLBranch($thesismarc);
            $related->addXMLBranch($thesis);
        }
        if (!empty($row['year']) || !empty($row['volume']) || !empty($row['issue']) || !empty($row['pages'])) {
            $part = new XMLBranch("part");
            if (!empty($row['year'])) {
                $part->setTagContent(encodeXMLField('year', $row['year']), "date");
            }
            if (!empty($row['volume'])) {
                $detailvolume = new XMLBranch("detail");
                $detailvolume->setTagContent(encodeXMLField('volume', $row['volume']), "detail/number");
                $detailvolume->setTagAttribute("type", "volume");
                $part->addXMLBranch($detailvolume);
            }
            if (!empty($row['issue'])) {
                $detailnumber = new XMLBranch("detail");
                $detailnumber->setTagContent(encodeXMLField('issue', $row['issue']), "detail/number");
                $detailnumber->setTagAttribute("type", "issue");
                $part->addXMLBranch($detailnumber);
            }
            if (!empty($row['pages'])) {
                if (preg_match("/[0-9] *- *[0-9]/", $row['pages'])) {
                    // if a page range
                    // split the page range into start and end pages
                    list($pagestart, $pageend) = preg_split('/\\s*[-]\\s*/', $row['pages']);
                    if ($pagestart < $pageend) {
                        // extents MUST span multiple pages
                        $pages = new XMLBranch("extent");
                        $pages->setTagContent(encodeXMLField('pages', $pagestart), "extent/start");
                        $pages->setTagContent(encodeXMLField('pages', $pageend), "extent/end");
                        $pages->setTagAttribute("unit", "page");
                    } else {
                        $pages = new XMLBranch("detail");
                        if ($pagestart == $pageend) {
                            // single-page item
                            $pages->setTagContent(encodeXMLField('pages', $pagestart), "detail/number");
                        } else {
                            $pages->setTagContent(encodeXMLField('pages', $row['pages']), "detail/number");
                        }
                        $pages->setTagAttribute("type", "page");
                    }
                } else {
                    $pages = new XMLBranch("detail");
                    $pages->setTagContent(encodeXMLField('pages', $row['pages']), "detail/number");
                    $pages->setTagAttribute("type", "page");
                }
                $part->addXMLBranch($pages);
            }
            $related->addXMLBranch($part);
        }
        // identifier
        //   isbn
        if (!empty($row['isbn'])) {
            $identifier = new XMLBranch("identifier");
            $identifier->setTagContent(encodeXMLField('isbn', $row['isbn']));
            $identifier->setTagAttribute("type", "isbn");
            $related->addXMLBranch($identifier);
        }
        //   issn
        if (!empty($row['issn'])) {
            $identifier = new XMLBranch("identifier");
            $identifier->setTagContent(encodeXMLField('issn', $row['issn']));
            $identifier->setTagAttribute("type", "issn");
            $related->addXMLBranch($identifier);
        }
        // series
        if (!empty($row['series_editor']) || !empty($row['series_title']) || !empty($row['abbrev_series_title']) || !empty($row['series_volume']) || !empty($row['series_issue'])) {
            $related->addXMLBranch(serialBranch($row['series_editor'], $row['series_title'], $row['abbrev_series_title'], $row['series_volume'], $row['series_issue']));
        }
        $record->addXMLBranch($related);
    }
    // --- END TYPE == ABSTRACT || BOOK CHAPTER || CONFERENCE ARTICLE || JOURNAL ARTICLE || MAGAZINE ARTICLE || NEWSPAPER ARTICLE ---
    return $record;
}
예제 #6
0
 function pdw_textbox(&$obj, $params)
 {
     // 	if (is_object($obj) && (get_class($obj)=="document" || get_class($obj)=="image" || get_class($obj)=="textbox"))
     // 	{
     // 		parent::pdw_document;
     $this->parent =& $obj;
     $this->paragstyle = "Frame Contents";
     $this->spanstyle = "";
     $this->frameno =& $obj->frameno;
     $frameno = $this->frameno++;
     $this->name = 'Frame' . $this->frameno;
     $this->imglist =& $this->parent->imglist;
     $this->zip =& $this->parent->zip;
     $this->autostyle =& $this->parent->autostyle;
     $this->lang =& $this->parent->lang;
     $this->country =& $this->parent->country;
     $this->fontdef =& $this->parent->fontdef;
     $this->fontlist =& $this->parent->fontlist;
     $this->fontdecls =& $this->parent->fontdecls;
     /////<style:style>
     $this->style = new XMLBranch("style:style");
     $this->style->setTagAttribute("style:name", 'fr' . $frameno);
     $this->style->setTagAttribute("style:family", "graphics");
     $this->style->setTagAttribute("style:parent-style-name", "Frame");
     /////<style:propieties>
     $this->styleprop = new XMLBranch("style:properties");
     /////<draw:text-box>
     $this->office = new XMLBranch("draw:text-box");
     $this->office->setTagAttribute("draw:style-name", 'fr' . $frameno);
     $this->office->setTagAttribute("draw:name", "Frame" . $frameno);
     $this->frameprop =& $this->office;
     if (!array_key_exists('anchor', $params)) {
         $params['anchor'] = 'paragraph';
     }
     if (!array_key_exists('h-pos', $params)) {
         $params['h-pos'] = 'from-left';
     }
     if (!array_key_exists('h-rel', $params)) {
         $params['h-rel'] = 'paragraph';
     }
     if (!array_key_exists('v-pos', $params)) {
         $params['v-pos'] = 'from-top';
     }
     if (!array_key_exists('v-rel', $params)) {
         $params['v-rel'] = 'paragraph';
     }
     foreach ($params as $key => $value) {
         switch ($key) {
             case 'columns':
                 $col = new XMLBranch('style:columns');
                 $col->setTagAttribute('fo:column-count', $value);
                 $col->setTagAttribute('fo:column-gap', '0cm');
                 $this->styleprop->addXMLBranch($col);
                 break;
             case 'chain':
                 $this->styleprop->setTagAttribute('style:chain-next-name', $value);
                 break;
         }
     }
     $this->_style($params, $this->styleprop);
     $this->_frame($params, $this->office);
     // 	$this->frameno++;
     // 	}
     // 	else $this->_error('Not an document object');
 }
예제 #7
0
 function SetFootnoteStyle($mleft = 0.499, $mright = 0, $fontsize = 10, $numformat = 1)
 {
     if (!($headlines = $this->styles->getBranches('office:document-styles/office:styles', 'style:style', 'style:name', 'Footnote'))) {
     }
     $headline1 = new XMLBranch('style:style');
     $headline1->setTagAttribute('style:name', $this->paragstyle);
     $headline1->setTagAttribute('style:family', 'paragraph');
     $headline1->setTagAttribute('style:parent-style-name', 'Standard');
     $headline1->setTagAttribute('style:class', 'extra');
     $headline11 = new XMLBranch('style:properties');
     $headline11->setTagAttribute('fo:margin-left', $mleft . 'cm');
     $headline11->setTagAttribute('fo:margin-right', $mright . 'cm');
     $headline11->setTagAttribute('fo:font-size', $fontsize . 'pt');
     $headline11->setTagAttribute('style:font-size-asian', $fontsize . 'pt');
     $headline11->setTagAttribute('style:font-size-complex', $fontsize . 'pt');
     $headline11->setTagAttribute('fo:text-indent', '-0.499cm');
     $headline11->setTagAttribute('style:auto-text-indent', 'false');
     $headline11->setTagAttribute('text:number-lines', 'false');
     $headline11->setTagAttribute('text:line-number', '0');
     $headline1->addXMLBranch($headline11);
     $headline2 = new XMLBranch('style:style');
     $headline2->setTagAttribute('style:name', 'Footnote Symbol');
     $headline2->setTagAttribute('style:family', 'text');
     $headline3 = new XMLBranch('style:style');
     $headline3->setTagAttribute('style:name', 'Footnote anchor');
     $headline3->setTagAttribute('style:family', 'text');
     $headline31 = new XMLBranch('style:properties');
     $headline31->setTagAttribute('style:text-position', 'super 58%');
     $headline3->addXMLBranch($headline31);
     $headline4 = new XMLBranch('text:footnotes-configuration');
     $headline4->setTagAttribute('text:citation-style-name', 'Footnote Symbol');
     $headline4->setTagAttribute('text:citation-body-style-name', 'Footnote anchor');
     $headline4->setTagAttribute('style:num-format', $numformat);
     $headline4->setTagAttribute('text:start-value', '0');
     $headline4->setTagAttribute('text:footnotes-position', 'page');
     $headline4->setTagAttribute('text:start-numbering-at', 'document');
     $headlines = $this->styles->getBranches('office:document-styles', 'office:styles');
     $end = count($headlines) - 1;
     $headlines[0]->addXMLBranch($headline1);
     $headlines[0]->addXMLBranch($headline2);
     $headlines[0]->addXMLBranch($headline3);
     $headlines[0]->addXMLBranch($headline4);
 }
예제 #8
0
파일: pdw_style.php 프로젝트: rrsc/freemed
 function _style(&$params, &$styleprop)
 {
     foreach ($params as $key => $value) {
         switch ($key) {
             case 'borders':
                 $border = explode(',', $value);
                 $styleprop->setTagAttribute("fo:border-left", $border[0]);
                 $styleprop->setTagAttribute("fo:border-right", $border[1]);
                 $styleprop->setTagAttribute("fo:border-top", $border[2]);
                 $styleprop->setTagAttribute("fo:border-bottom", $border[3]);
                 break;
             case 'padding':
                 $pad = explode(',', $value);
                 $styleprop->setTagAttribute('fo:padding-left', $pad[0] . 'cm');
                 $styleprop->setTagAttribute('fo:padding-right', $pad[1] . 'cm');
                 $styleprop->setTagAttribute('fo:padding-top', $pad[2] . 'cm');
                 $styleprop->setTagAttribute('fo:padding-bottom', $pad[3] . 'cm');
                 break;
             case 'margins':
                 $margin = explode(',', $value);
                 $styleprop->setTagAttribute('fo:margin-left', $margin[0] . 'cm');
                 $styleprop->setTagAttribute('fo:margin-right', $margin[1] . 'cm');
                 $styleprop->setTagAttribute('fo:margin-top', $margin[2] . 'cm');
                 $styleprop->setTagAttribute('fo:margin-bottom', $margin[3] . 'cm');
                 break;
             case 'bgimg':
                 $bgimage = new XMLBranch('style:background-image');
                 $bgimage->setTagAttribute('xlink:href', '');
                 $bgimage->setTagAttribute('xlink:type', '');
                 $bgimage->setTagAttribute('xlink:actuate', 'onLoad');
                 $styleprop->addXMLBranch($bgimage);
                 break;
             case 'bgcolor':
                 $styleprop->setTagAttribute('fo:background-color', $value);
                 break;
             case 'shadow':
                 $styleprop->setTagAttribute('style:shadow', $value);
                 break;
             case 'wrap':
                 $styleprop->setTagAttribute('style:wrap', $value);
                 break;
             case 'h-pos':
                 $styleprop->setTagAttribute('style:horizontal-pos', $value);
                 break;
             case 'h-rel':
                 $styleprop->setTagAttribute('style:horizontal-rel', $value);
                 break;
             case 'v-pos':
                 $styleprop->setTagAttribute('style:vertical-pos', $value);
                 break;
             case 'v-rel':
                 $styleprop->setTagAttribute('style:vertical-rel', $value);
                 break;
             case "stroke":
                 $styleprop->setTagAttribute('draw:stroke', $value);
                 break;
             case "strokewidth":
                 $styleprop->setTagAttribute('svg:stroke-width', $value . 'cm');
                 break;
             case "fillgradient":
                 $styleprop->setTagAttribute('draw:fill', 'gradient');
                 $styleprop->setTagAttribute('draw:fill-gradient-name', $value);
                 break;
             case "fillcolor":
                 $styleprop->setTagAttribute('draw:fill', 'solid');
                 $styleprop->setTagAttribute('draw:fill-color', $value);
                 break;
         }
     }
 }
예제 #9
0
function odfSpreadsheetTableRow($recordExportArray, $rowType)
{
    // create an XML object for a single record
    $record = new XML("table:table-row");
    if ($rowType == "heading") {
        $record->setTagAttribute("table:style-name", "ro1");
        foreach ($recordExportArray as $odfIndex => $indexValue) {
            $tableCell = new XMLBranch("table:table-cell");
            $tableCell->setTagAttribute("office:value-type", "string");
            $tableCell->setTagContent($odfIndex, "table:table-cell/text:p");
            $record->addXMLBranch($tableCell);
        }
    } else {
        $record->setTagAttribute("table:style-name", "ro2");
        foreach ($recordExportArray as $odfIndex => $indexValue) {
            $tableCell = new XMLBranch("table:table-cell");
            if (!empty($indexValue)) {
                $tableCell->setTagAttribute("office:value-type", "string");
                $tableCell->setTagContent($indexValue, "table:table-cell/text:p");
            }
            $record->addXMLBranch($tableCell);
        }
    }
    return $record;
}