示例#1
0
function citeRecords($result, $rowsFound, $query, $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $previousOffset, $nextOffset, $wrapResults, $citeStyle, $citeOrder, $citeType, $orderBy, $headerMsg, $userID, $viewType)
{
    global $officialDatabaseName;
    // these variables are defined in 'ini.inc.php'
    global $databaseBaseURL;
    global $contentTypeCharset;
    global $client;
    // The array '$transtab_refbase_ascii' contains search & replace patterns for conversion from refbase markup to plain text
    global $transtab_refbase_ascii;
    // defined in 'transtab_refbase_ascii.inc.php'
    $plainTextData = "";
    // make sure that our buffer variable is empty
    // Header:
    if (!empty($headerMsg)) {
        // Decode any HTML entities:
        // (these may occur in the header message e.g. if the user's preferred display language is not English but German or French, etc)
        $headerMsg = decodeHTML($contentTypeCharset, $headerMsg);
        // function 'decodeHTML()' is defined in 'include.inc.php', and '$contentTypeCharset' is defined in 'ini.inc.php'
        // Convert refbase markup in the header message into plain text:
        $headerMsg = searchReplaceText($transtab_refbase_ascii, $headerMsg, true);
        // function 'searchReplaceText()' is defined in 'include.inc.php'
        $plainTextData .= "{$headerMsg}\n\n";
        // prefix any passed header message
    }
    // Initialize array variables:
    $yearsArray = array();
    $typeTitlesArray = array();
    // Define inline text markup to be used by the 'citeRecord()' function:
    $markupPatternsArray = array("bold-prefix" => "", "bold-suffix" => "", "italic-prefix" => "", "italic-suffix" => "", "underline-prefix" => "", "underline-suffix" => "", "endash" => "-", "emdash" => "-", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => '"', "double-quote-right" => '"', "single-quote" => "'", "single-quote-left" => "'", "single-quote-right" => "'", "less-than" => "<", "greater-than" => ">", "newline" => "\n");
    // Defines search & replace 'actions' that will be applied upon TEXT output to all those refbase fields that are listed
    // in the corresponding 'fields' element:
    $plainTextSearchReplaceActionsArray = array(array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_ascii));
    // For CLI queries, we'll allow paging thru the result set, i.e. we honour the values of the CLI options '-S|--start' ('$rowOffset')
    // and '-R|--rows' ('$showRows') ('$rowOffset' and '$showRows' are re-assigned in function 'seekInMySQLResultsToOffset()' in 'include.inc.php')
    if (preg_match("/^cli/i", $client)) {
        // if the query originated from a command line client such as the "refbase" CLI client ("cli-refbase-1.0")
        $showMaxRows = $showRows;
    } else {
        $showMaxRows = $rowsFound;
    }
    // otherwise show all rows
    // LOOP OVER EACH RECORD:
    // Fetch one page of results (or less if on the last page)
    // (i.e., upto the limit specified in $showMaxRows) fetch a row into the $row array and ...
    for ($rowCounter = 0; $rowCounter < $showMaxRows && ($row = @mysql_fetch_array($result)); $rowCounter++) {
        foreach ($row as $rowFieldName => $rowFieldValue) {
            // Apply search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$plainTextSearchReplaceActionsArray':
            foreach ($plainTextSearchReplaceActionsArray as $fieldActionsArray) {
                if (in_array($rowFieldName, $fieldActionsArray['fields'])) {
                    $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $row[$rowFieldName], true);
                }
            }
        }
        // function 'searchReplaceText()' is defined in 'include.inc.php'
        // Order attributes according to the chosen output style & record type:
        $record = citeRecord($row, $citeStyle, $citeType, $markupPatternsArray, false);
        // function 'citeRecord()' is defined in the citation style file given in '$citeStyleFile' (which, in turn, must reside in the 'cite' directory of the refbase root directory), see function 'generateCitations()'
        // Print out the current record:
        if (!empty($record)) {
            // Print any section heading(s):
            if (preg_match("/year|type/i", $citeOrder)) {
                list($yearsArray, $typeTitlesArray, $sectionHeading) = generateSectionHeading($yearsArray, $typeTitlesArray, $row, $citeOrder, "", "", "", "\n\n", "", "\n\n");
                // function 'generateSectionHeading()' is defined in 'cite.inc.php'
                $plainTextData .= $sectionHeading;
            }
            // Write plain TEXT paragraph:
            if (preg_match("/^cli/i", $client)) {
                // 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: currently, the following placeholders are not available for citation output:
                //       <:keywords:>, <:issn:>, <:area:>, <:notes:>, <:userKeys:>
                //       if the cite key specification uses one of these placeholders, it will get ignored
                $citeKey = generateCiteKey($formVars);
                // function 'generateCiteKey()' is defined in 'include.inc.php'
                $plainTextData .= "[" . $row['serial'] . "] ";
                if (!empty($citeKey)) {
                    // Use the custom cite key that's been build according to the user's individual export options:
                    $plainTextData .= "{" . $citeKey . "} ";
                }
            }
            $plainTextData .= $record . "\n\n";
            // create paragraph with encoded record text
        }
    }
    if (preg_match("/^cli/i", $client)) {
        // Calculate the maximum result number on each page:
        if ($rowOffset + $showRows < $rowsFound) {
            $showMaxRow = $rowOffset + $showRows;
        } else {
            $showMaxRow = $rowsFound;
        }
        // for the last results page, correct the maximum result number if necessary
        if ($rowsFound == 1) {
            $footerInfoPart = " record found";
        } else {
            $footerInfoPart = " records found";
        }
        $rowsFoundInfo = $rowOffset + 1 . "-" . $showMaxRow . " of " . $rowsFound . $footerInfoPart;
        // prints e.g. "1-5 of 23 records found"
        $rowsFoundDelimiter = preg_replace("/./i", "-", $rowsFoundInfo);
        // generate a line of hyphens which has the same length as the string in '$rowsFoundInfo' (e.g. "-----------------------")
        $plainTextData .= $rowsFoundDelimiter . "\n" . $rowsFoundInfo . "\n\n";
        // append info about rows displayed/found
        $plainTextData .= $officialDatabaseName . "\n" . $databaseBaseURL . "\n\n";
        // append database name and URL (comment this line if you don't like that)
        if ($showQuery == "1") {
            // display SQL query:
            $plainTextData .= "Query: " . $query . "\n\n";
        }
    }
    return $plainTextData;
}
示例#2
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;
}
示例#3
0
function citeRecords($result, $rowsFound, $query, $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $previousOffset, $nextOffset, $wrapResults, $citeStyle, $citeOrder, $citeType, $orderBy, $headerMsg, $userID, $viewType)
{
    global $contentTypeCharset;
    // defined in 'ini.inc.php'
    global $client;
    // The array '$transtab_refbase_latex' contains search & replace patterns for conversion from refbase markup to LaTeX markup & entities.
    // Converts refbase fontshape markup (italic, bold) into LaTeX commands of the 'textcomp' package, super- and subscript as well as greek
    // symbols get converted into the respective commands in math mode. You may need to adopt the LaTeX markup to suit your individual needs.
    global $transtab_refbase_latex;
    // defined in 'transtab_refbase_latex.inc.php'
    // The arrays '$transtab_latin1_latex' and '$transtab_unicode_latex' provide translation tables for best-effort conversion of higher ASCII
    // characters from ISO-8859-1 (or Unicode, respectively) to LaTeX entities.
    global $transtab_latin1_latex;
    // defined in 'transtab_latin1_latex.inc.php'
    global $transtab_unicode_latex;
    // defined in 'transtab_unicode_latex.inc.php'
    // --- Begin style-specific settings ----------------------------------
    // NOTE: the given settings are meant to be used with the natbib package;
    //       you'll have to adopt these settings if you'd like to generate a
    //       .bbl file for another style/package
    // 1) Define header with .bst style-specific declarations:
    // NOTE: since this header is normally inserted by BibTeX from the used .bst style, I'm not sure if there's a variant of this header that's
    //       universally accepted by natbib. So, if necessary adopt it to your needs.
    // -- by default, we use this header (as inserted by a .bst style that was generated from 'merlin.mbs' via the docstrip utility):
    $bblHeader = "\\providecommand{\\natexlab}[1]{#1}" . "\n" . "\\providecommand{\\url}[1]{\\texttt{#1}}" . "\n" . "\\providecommand{\\urlprefix}{URL }" . "\n" . "\\providecommand{\\eprint}[2][]{\\url{#2}}" . "\n\n";
    // -- here's another header example (as inserted by 'elsart-harv.bst'):
    //		$bblHeader = "\\expandafter\\ifx\\csname natexlab\\endcsname\\relax\\def\\natexlab#1{#1}\\fi" . "\n"
    //		           . "\\expandafter\\ifx\\csname url\\endcsname\\relax" . "\n"
    //		           . "  \\def\\url#1{\\texttt{#1}}\\fi" . "\n"
    //		           . "\\expandafter\\ifx\\csname urlprefix\\endcsname\\relax\\def\\urlprefix{URL }\\fi" . "\n\n";
    // 2) Define name of \bibitem command:
    $bibItemCommand = "\\bibitem";
    // use "\\harvarditem" for the Harvard family of styles
    // 3) Define variables and placeholder strings which together will form the \bibitem option string:
    // -- variables:
    $betweenShortAuthorsDelim = " & ";
    // used to connect individual author names in the short author list
    $betweenFullAuthorsDelim = ", ";
    // used to connect multiple authors in the full author list
    $betweenLastAuthorsDelim = " & ";
    // used to connect the second-to-last author with the last author in the full author list
    $etalIdentifierString = " et~al.";
    // appended to the first author's last name if the record's number of authors exceeds the number given in '$maxAuthorCountInShortAuthorList'
    $maxAuthorCountInShortAuthorList = 2;
    // maximum number of authors to be used in the short author list
    // -- placeholder strings:
    // (please see the refbase online documentation for more info about placeholders and their syntax: <http://placeholders.refbase.net/>)
    $year = "<:year[4]:>";
    // year format, e.g. "1990"
    $shortAuthorList = "<:authors[" . $maxAuthorCountInShortAuthorList . "|" . $betweenShortAuthorsDelim . "|" . $etalIdentifierString . "]:>";
    // format of the short author list which is used as text citation, e.g. "Jones", "Jones and Baker" or "Jones et al."
    $fullAuthorList = "<:authors[0|_#_§_~_|]:>";
    // format of the full author list, e.g. "Jones, Baker, and Williams"
    // NOTE: in the above placeholder string, we use the string "_#_§_~_" as author delimiter which allows us to uniquely identify that delimiter again below, and replace it with the contents of either '$betweenFullAuthorsDelim' or '$betweenLastAuthorsDelim' (depending on its position)
    // 4) Define \bibitem option format:
    // -- extended natbib 5.3 style:
    $bibItemOptionShort = "[{" . $shortAuthorList . "}(" . $year . ")" . "]";
    // e.g.: \bibitem[{Jones et al.}(1990)]{key}...
    $bibItemOptionFull = "[{" . $shortAuthorList . "}(" . $year . "){" . $fullAuthorList . "}]";
    // e.g.: \bibitem[{Jones et al.}(1990){Jones, Baker, and Williams}]{key}...
    // NOTE: since the author lists may contain parentheses, we need to enclose them in curly brackets to work around a natbib limitation
    // -- native natbib style:
    //		$bibItemOptionShort = "[" . $shortAuthorList . "(" . $year . ")" . "]"; // e.g.: \bibitem[Jones et al.(1990)]{key}...
    //		$bibItemOptionFull = "";
    // -- apalike style:
    //		$bibItemOptionShort = "[" . $shortAuthorList . ", " . $year . "]"; // e.g.: \bibitem[Jones et al., 1990]{key}...
    //		$bibItemOptionFull = "";
    // -- newapa or chicago styles:
    //		$bibItemOptionShort = "[\\protect\\citeauthoryear{" . $fullAuthorList . "}{" . $shortAuthorList . "}{" . $year . "}" . "]"; // this assumes that it's not allowed to omit the full author list, though I dunno)
    //		$bibItemOptionFull = "[\\protect\\citeauthoryear{" . $fullAuthorList . "}{" . $shortAuthorList . "}{" . $year . "}" . "]"; // e.g.: \bibitem[\protect\citeauthoryear{Jones, Baker, and Williams}{Jones et al.}{1990}]{key}...
    // -- named style:
    //		$bibItemOptionShort = "[\\protect\\citeauthoryear{" . $shortAuthorList . "}{" . $year . "}" . "]"; // e.g.: \bibitem[\protect\citeauthoryear{Jones et al.}{1990}]{key}...
    //		$bibItemOptionFull = "";
    // -- astron style:
    //		$bibItemOptionShort = "[\\protect\\astroncite{" . $shortAuthorList . "}{" . $year . "}" . "]"; // e.g.: \bibitem[\protect\astroncite{Jones et al.}{1990}]{key}...
    //		$bibItemOptionFull = "";
    // -- authordate style:
    //		$bibItemOptionShort = "[\\protect\\citename{" . $shortAuthorList . ", }" . $year . "]"; // e.g.: \bibitem[\protect\citename{Jones et al., }1990]{key}...
    //		$bibItemOptionFull = "";
    // -- harvard style:
    //		$bibItemOptionShort = "[" . $shortAuthorList . "]{" . $fullAuthorList . "}{" . $year . "}"; // this assumes that it's not allowed to omit the full author list, though I dunno)
    //		$bibItemOptionFull = "[" . $shortAuthorList . "]{" . $fullAuthorList . "}{" . $year . "}"; // e.g.: \harvarditem[Jones et al.]{Jones, Baker, and Williams}{1990}{key}...
    // 5) Define deduplication prefix and suffix strings:
    //    Identical text citation strings get uniquified by appending letters to the year, e.g. duplicate occurrences
    //    of "Jones et al. 1990" should become "Jones et al. 1990a" and "Jones et al. 1990b" in the final output.
    //    These prefix/suffix strings will be inserted before/after the deduplication letter:
    $dedupPrefix = "{\\natexlab{";
    // these prefix/suffix strings are required by natbib; if any custom command (such as '\natexlab') is used, make sure that the command is also defined above in variable '$bblHeader'
    $dedupSuffix = "}}";
    // --- End style-specific settings ------------------------------------
    // Initialize array variables:
    $yearsArray = array();
    $typeTitlesArray = array();
    $bibItemsArray = array();
    // Define inline text markup to be used by the 'citeRecord()' function:
    $markupPatternsArray = array("bold-prefix" => "\\textbf{", "bold-suffix" => "}", "italic-prefix" => "\\textit{", "italic-suffix" => "}", "underline-prefix" => "\\ul{", "underline-suffix" => "}", "endash" => "--", "emdash" => "---", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => "{\\textquotedblleft}", "double-quote-right" => "{\\textquotedblright}", "single-quote" => "'", "single-quote-left" => "{\\textquoteleft}", "single-quote-right" => "{\\textquoteright}", "less-than" => "<", "greater-than" => ">", "newline" => "\n\n");
    // Defines search & replace 'actions' that will be applied upon LaTeX output to all those refbase fields that are listed
    // in the corresponding 'fields' element:
    $latexSearchReplaceActionsArray = array(array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_latex));
    // For CLI queries, we'll allow paging thru the result set, i.e. we honour the values of the CLI options '-S|--start' ('$rowOffset')
    // and '-R|--rows' ('$showRows') ('$rowOffset' and '$showRows' are re-assigned in function 'seekInMySQLResultsToOffset()' in 'include.inc.php')
    if (preg_match("/^cli/i", $client)) {
        // if the query originated from a command line client such as the "refbase" CLI client ("cli-refbase-1.0")
        $showMaxRows = $showRows;
    } else {
        $showMaxRows = $rowsFound;
    }
    // otherwise show all rows
    // Setup the basic .bbl document structure:
    $latexData = "\\begin{thebibliography}{" . $showMaxRows . "}\n\n";
    // Add header with .bst style-specific declarations:
    $latexData .= $bblHeader;
    // LOOP OVER EACH RECORD:
    // Fetch one page of results (or less if on the last page)
    // (i.e., upto the limit specified in $showMaxRows) fetch a row into the $row array and ...
    for ($rowCounter = 0; $rowCounter < $showMaxRows && ($row = @mysql_fetch_array($result)); $rowCounter++) {
        foreach ($row as $rowFieldName => $rowFieldValue) {
            // Apply search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$latexSearchReplaceActionsArray':
            foreach ($latexSearchReplaceActionsArray as $fieldActionsArray) {
                if (in_array($rowFieldName, $fieldActionsArray['fields'])) {
                    $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $row[$rowFieldName], true);
                }
            }
        }
        // function 'searchReplaceText()' is defined in 'include.inc.php'
        // Order attributes according to the chosen output style & record type:
        $record = citeRecord($row, $citeStyle, $citeType, $markupPatternsArray, false);
        // function 'citeRecord()' is defined in the citation style file given in '$citeStyleFile' (which, in turn, must reside in the 'cite' directory of the refbase root directory), see function 'generateCitations()'
        // Print out the current record:
        if (!empty($record)) {
            // 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: currently, the following placeholders are not available for citation output:
            //       <:keywords:>, <:issn:>, <:area:>, <:notes:>, <:userKeys:>
            //       if the cite key specification uses one of these placeholders, it will get ignored
            $citeKey = generateCiteKey($formVars);
            // function 'generateCiteKey()' is defined in 'include.inc.php'
            // The '\bibitem' command requires a cite key, which is why we'll include the record's serial number
            // even when the user's export options specify 'export_cite_keys=no' or 'autogenerate_cite_keys=no':
            // NOTE: maybe we should always generate a cite key here, even if 'export_cite_keys=no' or 'autogenerate_cite_keys=no'??
            if (empty($citeKey)) {
                $citeKey = $row['serial'];
            }
            // Generate the \bibitem option string that's used to build the proper text citation:
            $bibItemOptionShortString = parsePlaceholderString($formVars, $bibItemOptionShort, "<:authors[2| and | et~al.]:><(:year:)>");
            // function 'parsePlaceholderString()' is defined in 'include.inc.php'
            if (!empty($bibItemOptionFull) and preg_match("/^[^;]+(;[^;]+){" . $maxAuthorCountInShortAuthorList . "}/", $row['author'])) {
                // include full author list:
                $bibItemOptionString = parsePlaceholderString($formVars, $bibItemOptionFull, "<:authors[2| and | et~al.]:><(:year:)><:authors[0|, |]:>");
                $bibItemOptionString = preg_replace("/_#_§_~_(?!.*?_#_§_~_)/", $betweenLastAuthorsDelim, $bibItemOptionString);
                // replace last occurrence of "_#_§_~_"
                $bibItemOptionString = preg_replace("/_#_§_~_/", $betweenFullAuthorsDelim, $bibItemOptionString);
                // replace all other occurrences of "_#_§_~_"
            } else {
                // only include short author list:
                $bibItemOptionString = $bibItemOptionShortString;
            }
            // In case of duplicate text citation strings, append a letter to the year in the \bibitem option string as well as in the formatted reference:
            // NOTE: - this is not fool proof and currently only works if there are no more than 26 duplicate text citations (letters a-z)
            //       - the below replace actions get triggered on the first four-digit number that happens to be identical to the record's year, but depending on the reference format, this may not be the actual year of the reference but some other number!
            for ($i = 0; isset($bibItemsArray[$bibItemOptionShortString]); $i++) {
                // Update the existing \bibitem entry (that has an identical text citation string) and append an "a" to it's year items:
                if ($i == 0) {
                    $dedupPrefixQuoted = preg_quote($dedupPrefix, "/");
                    // escape meta characters (including '/' that is used as delimiter for the PCRE replace functions below and which gets passed as second argument)
                    $dedupSuffixQuoted = preg_quote($dedupSuffix, "/");
                    $oldBibItemOptionShortString = preg_replace("/^\\[(.+)\\]\$/", "\\1", $bibItemOptionShortString);
                    // remove square brackets from short \bibitem option string (which is required for the subsequent 'str_replace()' action to work with short and full option strings)
                    $newBibItemOptionShortString = preg_replace("/(" . $row['year'] . ")(" . $dedupPrefixQuoted . "[a-z]*" . $dedupSuffixQuoted . ")*/", "\\1" . $dedupPrefix . "a" . $dedupSuffix, $oldBibItemOptionShortString, 1);
                    $bibItemsArray[$bibItemOptionShortString] = str_replace($oldBibItemOptionShortString, $newBibItemOptionShortString, $bibItemsArray[$bibItemOptionShortString]);
                    $bibItemsArray[$bibItemOptionShortString] = preg_replace("/(" . $row['year'] . ")(" . $dedupPrefixQuoted . "[a-z]*" . $dedupSuffixQuoted . ")*(?!.*?" . $row['year'] . ")/", "\\1" . $dedupPrefix . "a" . $dedupSuffix, $bibItemsArray[$bibItemOptionShortString], 1);
                    // note that this will fail if the formatted reference contains a number after the year that is identical to the year!
                }
                // Append a letter to the year items of the current \bibitem entry:
                $bibItemOptionShortString = preg_replace("/(" . $row['year'] . ")(" . $dedupPrefixQuoted . "[a-z]*" . $dedupSuffixQuoted . ")*/e", "'\\1{$dedupPrefix}'.chr(98 + {$i}).'{$dedupSuffix}'", $bibItemOptionShortString, 1);
                // the 'e' modifier allows to execute PHP code within the replacement pattern
                $bibItemOptionString = preg_replace("/(" . $row['year'] . ")(" . $dedupPrefixQuoted . "[a-z]*" . $dedupSuffixQuoted . ")*/e", "'\\1{$dedupPrefix}'.chr(98 + {$i}).'{$dedupSuffix}'", $bibItemOptionString, 1);
                $record = preg_replace("/(" . $row['year'] . ")(" . $dedupPrefixQuoted . "[a-z]*" . $dedupSuffixQuoted . ")*/e", "'\\1{$dedupPrefix}'.chr(98 + {$i}).'{$dedupSuffix}'", $record, 1);
            }
            // Attempt to convert higher ASCII chars (i.e., characters with an ASCII value of >= 128) to their corresponding LaTeX entities:
            if ($contentTypeCharset == "UTF-8") {
                $recordEncoded = searchReplaceText($transtab_unicode_latex, $record, false);
            } else {
                $recordEncoded = searchReplaceText($transtab_latin1_latex, $record, false);
            }
            // We have to make sure that the \bibitem option string also contains proper LaTeX entities:
            if ($contentTypeCharset == "UTF-8") {
                $bibItemOptionStringEncoded = searchReplaceText($transtab_unicode_latex, $bibItemOptionString, false);
            } else {
                $bibItemOptionStringEncoded = searchReplaceText($transtab_latin1_latex, $bibItemOptionString, false);
            }
            // Copy the current \bibitem entry to the array of generated \bibitem entries:
            $bibItemsArray[$bibItemOptionShortString] = $bibItemCommand . $bibItemOptionStringEncoded . "{" . $citeKey . "} " . $recordEncoded;
        }
    }
    $latexData .= implode("\n\n", $bibItemsArray) . "\n\n";
    $latexData .= "\\end{thebibliography}\n\n";
    return $latexData;
}
示例#4
0
$importedRecordsArray = array();
if (count($importRecordNumbersRecognizedFormatArray) == 1 and !preg_match("/^(cli|be)/i", $client)) {
    // If no specific cite key exists in the record data, any existing 'call_number' string gets also copied to the
    // user-specific 'cite_key' field (which will ensure that this original call number/cite key is retained as
    // cite key upon export); however, note that (depending on the user's settings) the cite key may get modified
    // or regenerated by function 'generateCiteKey()' below
    if (!empty($importDataArray['records'][0]['call_number']) and empty($importDataArray['records'][0]['cite_key'])) {
        $importDataArray['records'][0]['cite_key'] = $importDataArray['records'][0]['call_number'];
    }
    // This is a stupid hack that maps the names of the '$importDataArray['records'][0]' array keys to those
    // used by the '$parsedRecordFormVars' (='$formVars') array (which is required by function 'generateCiteKey()')
    // (eventually, the '$formVars' array should use the MySQL field names as names for its array keys)
    $parsedRecordFormVars = buildFormVarsArray($importDataArray['records'][0]);
    // function 'buildFormVarsArray()' is defined in 'include.inc.php'
    // Generate or modify (e.g. uniquify) the cite key for this record:
    $importDataArray['records'][0]['cite_key'] = generateCiteKey($parsedRecordFormVars);
    // function 'generateCiteKey()' is defined in 'include.inc.php'
    // save import data to session variable:
    // NOTE: Saving import data to a session variable allows to retain large param/value strings (that would exceed
    //       the maximum string limit for GET requests). This works around a limitation in Internet Explorer which
    //       has a maximum URL length of 2,083 characters & a maximum path length of 2,048 characters.
    //       More info: <http://support.microsoft.com/kb/208427/EN-US/>
    saveSessionVariable("importData", $importDataArray['records'][0]);
    // RELOCATE TO IMPORT PAGE:
    // call 'record.php' and load the form fields with the data of the current record
    header("Location: record.php?recordAction=add&mode=import&importSource=generic");
    exit;
    // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
} else {
    // Add all records to the database (i.e., for each record, add a row entry to MySQL table 'refs'):
    // ('$importedRecordsArray' will hold the serial numbers of all newly imported records)
示例#5
0
function citeRecords($result, $rowsFound, $query, $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $previousOffset, $nextOffset, $wrapResults, $citeStyle, $citeOrder, $citeType, $orderBy, $headerMsg, $userID, $viewType)
{
    global $contentTypeCharset;
    // defined in 'ini.inc.php'
    global $client;
    // The array '$transtab_refbase_latex' contains search & replace patterns for conversion from refbase markup to LaTeX markup & entities.
    // Converts refbase fontshape markup (italic, bold) into LaTeX commands of the 'textcomp' package, super- and subscript as well as greek
    // symbols get converted into the respective commands in math mode. You may need to adopt the LaTeX markup to suit your individual needs.
    global $transtab_refbase_latex;
    // defined in 'transtab_refbase_latex.inc.php'
    // The arrays '$transtab_latin1_latex' and '$transtab_unicode_latex' provide translation tables for best-effort conversion of higher ASCII
    // characters from ISO-8859-1 (or Unicode, respectively) to LaTeX entities.
    global $transtab_latin1_latex;
    // defined in 'transtab_latin1_latex.inc.php'
    global $transtab_unicode_latex;
    // defined in 'transtab_unicode_latex.inc.php'
    // Initialize array variables:
    $yearsArray = array();
    $typeTitlesArray = array();
    // Define inline text markup to be used by the 'citeRecord()' function:
    $markupPatternsArray = array("bold-prefix" => "\\textbf{", "bold-suffix" => "}", "italic-prefix" => "\\textit{", "italic-suffix" => "}", "underline-prefix" => "\\ul{", "underline-suffix" => "}", "endash" => "--", "emdash" => "---", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => "{\\textquotedblleft}", "double-quote-right" => "{\\textquotedblright}", "single-quote" => "'", "single-quote-left" => "{\\textquoteleft}", "single-quote-right" => "{\\textquoteright}", "less-than" => "<", "greater-than" => ">", "newline" => "\n\n");
    // Defines search & replace 'actions' that will be applied upon LaTeX output to all those refbase fields that are listed
    // in the corresponding 'fields' element:
    $latexSearchReplaceActionsArray = array(array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_latex));
    // For CLI queries, we'll allow paging thru the result set, i.e. we honour the values of the CLI options '-S|--start' ('$rowOffset')
    // and '-R|--rows' ('$showRows') ('$rowOffset' and '$showRows' are re-assigned in function 'seekInMySQLResultsToOffset()' in 'include.inc.php')
    if (preg_match("/^cli/i", $client)) {
        // if the query originated from a command line client such as the "refbase" CLI client ("cli-refbase-1.0")
        $showMaxRows = $showRows;
    } else {
        $showMaxRows = $rowsFound;
    }
    // otherwise show all rows
    // Setup the basic LaTeX document structure:
    $latexData = "%&LaTeX\n" . "\\documentclass{article}\n\n";
    // NOTE: the "Vancouver" & "Harvard 1" citation styles make use of the '\ul' command which requires '\usepackage{soul}'
    // TODO: figure out a better logic when to include the '\usepackage{soul}' statement (or should we simply always include it?)
    if (preg_match("/^(Vancouver|Harvard 1)\$/i", $citeStyle)) {
        $latexData .= "\\usepackage{soul}\n";
    }
    if ($contentTypeCharset == "UTF-8") {
        $latexData .= "\\usepackage[utf8]{inputenc}\n";
    } else {
        $latexData .= "\\usepackage[latin1]{inputenc}\n";
    }
    $latexData .= "\\usepackage[T1]{fontenc}\n" . "\\usepackage{textcomp}\n\n";
    $latexData .= "\\begin{document}\n\n";
    // Header:
    if (!empty($headerMsg)) {
        // Remove any colon (":") from end of header message:
        $headerMsg = trimTextPattern($headerMsg, ":", false, true);
        // function 'trimTextPattern()' is defined in 'include.inc.php'
        // Decode any HTML entities:
        // (these may occur in the header message e.g. if the user's preferred display language is not English but German or French, etc)
        $headerMsg = decodeHTML($contentTypeCharset, $headerMsg);
        // function 'decodeHTML()' is defined in 'include.inc.php', and '$contentTypeCharset' is defined in 'ini.inc.php'
        // Convert refbase markup in the header message into appropriate LaTeX markup & entities:
        $headerMsg = searchReplaceText($transtab_refbase_latex, $headerMsg, true);
        // function 'searchReplaceText()' is defined in 'include.inc.php'
        // Attempt to convert higher ASCII chars (i.e., characters with an ASCII value of >= 128) in the header message to their corresponding LaTeX entities:
        if ($contentTypeCharset == "UTF-8") {
            $headerMsg = searchReplaceText($transtab_unicode_latex, $headerMsg, false);
        } else {
            $headerMsg = searchReplaceText($transtab_latin1_latex, $headerMsg, false);
        }
        $latexData .= "\\title{" . $headerMsg . "}\n\n" . "\\maketitle\n\n";
    }
    if (!preg_match("/type|year/i", $citeOrder)) {
        $latexData .= "\\begin{thebibliography}{" . $showMaxRows . "}\n\n";
    }
    // LOOP OVER EACH RECORD:
    // Fetch one page of results (or less if on the last page)
    // (i.e., upto the limit specified in $showMaxRows) fetch a row into the $row array and ...
    for ($rowCounter = 0; $rowCounter < $showMaxRows && ($row = @mysql_fetch_array($result)); $rowCounter++) {
        foreach ($row as $rowFieldName => $rowFieldValue) {
            // Apply search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$latexSearchReplaceActionsArray':
            foreach ($latexSearchReplaceActionsArray as $fieldActionsArray) {
                if (in_array($rowFieldName, $fieldActionsArray['fields'])) {
                    $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $row[$rowFieldName], true);
                }
            }
        }
        // function 'searchReplaceText()' is defined in 'include.inc.php'
        // Order attributes according to the chosen output style & record type:
        $record = citeRecord($row, $citeStyle, $citeType, $markupPatternsArray, false);
        // function 'citeRecord()' is defined in the citation style file given in '$citeStyleFile' (which, in turn, must reside in the 'cite' directory of the refbase root directory), see function 'generateCitations()'
        // Print out the current record:
        if (!empty($record)) {
            // Print any section heading(s):
            if (preg_match("/year|type/i", $citeOrder)) {
                list($yearsArray, $typeTitlesArray, $sectionHeading) = generateSectionHeading($yearsArray, $typeTitlesArray, $row, $citeOrder, "", "", "\\section*{", "}\n\n", "\\subsection*{", "}\n\n");
                // function 'generateSectionHeading()' is defined in 'cite.inc.php'
                $latexData .= $sectionHeading;
            }
            // Attempt to convert higher ASCII chars (i.e., characters with an ASCII value of >= 128) to their corresponding LaTeX entities:
            if ($contentTypeCharset == "UTF-8") {
                $recordEncoded = searchReplaceText($transtab_unicode_latex, $record, false);
            } else {
                $recordEncoded = searchReplaceText($transtab_latin1_latex, $record, false);
            }
            // Write LaTeX paragraph:
            if (!preg_match("/type|year/i", $citeOrder)) {
                // 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: currently, the following placeholders are not available for citation output:
                //       <:keywords:>, <:issn:>, <:area:>, <:notes:>, <:userKeys:>
                //       if the cite key specification uses one of these placeholders, it will get ignored
                $citeKey = generateCiteKey($formVars);
                // function 'generateCiteKey()' is defined in 'include.inc.php'
                if (!empty($citeKey)) {
                    // Use the custom cite key that's been build according to the user's individual export options:
                    $latexData .= "\\bibitem{" . $citeKey . "} ";
                } else {
                    // The '\bibitem' command requires a cite key, which is why we'll include the record's serial number
                    // even when the user's export options specify 'export_cite_keys=no' or 'autogenerate_cite_keys=no':
                    $latexData .= "\\bibitem{" . $row['serial'] . "} ";
                }
            }
            $latexData .= $recordEncoded . "\n\n";
            // create paragraph with encoded record text
        }
    }
    if (!preg_match("/type|year/i", $citeOrder)) {
        $latexData .= "\\end{thebibliography}\n\n";
    }
    $latexData .= "\\end{document}\n\n";
    return $latexData;
}
示例#6
0
function addRecords($importDataArray)
{
    global $loginUserID;
    global $tableRefs, $tableUserData;
    // defined in 'db.inc.php'
    global $connection;
    connectToMySQLDatabase();
    $recognizedArrayFormatsAndVersions = array('refbase' => array("1.0"));
    // for each recognized format, this array lists its format identifier as element key and an array of known versions as element value
    $serialNumbersArray = array();
    // initialize array variable which will hold the serial numbers of all imported records
    // Verify the structure of the '$importDataArray':
    if (!empty($importDataArray['type']) and !empty($importDataArray['version']) and !empty($importDataArray['records'])) {
        // Currently, we only support the default "refbase" array structure in its initial version ("1.0") (support for other more generalized array formats may come later)
        if ($importDataArray['type'] == "refbase" and in_array($importDataArray['version'], $recognizedArrayFormatsAndVersions['refbase'])) {
            $recordsArray = $importDataArray['records'];
            // get the array of records that shall be imported
            // First, setup some required variables:
            // Get the current date (e.g. '2003-12-31'), time (e.g. '23:59:49') and user name & email address (e.g. 'Matthias Steffens (refbase@extracts.de)'):
            // note that we use the same time stamp for ALL imported records (so that users can easily identify all records belonging to one import action)
            list($currentDate, $currentTime, $currentUser) = getCurrentDateTimeUser();
            // LOOP OVER EACH RECORD:
            foreach ($recordsArray as $recordData) {
                // Initialize some variables (in order to avoid "undefined index" messages when the particular array elements are not available):
                if (isset($recordData['author'])) {
                    $author = $recordData['author'];
                } else {
                    $author = "";
                }
                if (isset($recordData['pages'])) {
                    $pages = $recordData['pages'];
                } else {
                    $pages = "";
                }
                if (isset($recordData['volume'])) {
                    $volume = $recordData['volume'];
                } else {
                    $volume = "";
                }
                if (isset($recordData['series_volume'])) {
                    $seriesVolume = $recordData['series_volume'];
                } else {
                    $seriesVolume = "";
                }
                // Assign correct values to the calculation fields 'first_author', 'author_count', 'first_page', 'volume_numeric' and 'series_volume_numeric':
                list($firstAuthor, $authorCount, $firstPage, $volumeNumeric, $seriesVolumeNumeric) = generateCalculationFieldContent($author, $pages, $volume, $seriesVolume);
                // CONSTRUCT SQL QUERY:
                // INSERT - construct a query to add data as new record
                $queryRefs = "";
                // note: we'll prefix "INSERT INTO $tableRefs SET " *after* we've parsed all array elements to trap the case that none of the array elements did contain any data
                if (!empty($recordData['author'])) {
                    $queryRefs .= "author = " . quote_smart($recordData['author']) . ", ";
                }
                if (!empty($firstAuthor)) {
                    $queryRefs .= "first_author = " . quote_smart($firstAuthor) . ", ";
                }
                if (!empty($authorCount)) {
                    $queryRefs .= "author_count = " . quote_smart($authorCount) . ", ";
                }
                if (!empty($recordData['title'])) {
                    $queryRefs .= "title = " . quote_smart($recordData['title']) . ", ";
                }
                if (!empty($recordData['year'])) {
                    $queryRefs .= "year = " . quote_smart($recordData['year']) . ", ";
                }
                if (!empty($recordData['publication'])) {
                    $queryRefs .= "publication = " . quote_smart($recordData['publication']) . ", ";
                }
                if (!empty($recordData['abbrev_journal'])) {
                    $queryRefs .= "abbrev_journal = " . quote_smart($recordData['abbrev_journal']) . ", ";
                }
                if (!empty($recordData['volume'])) {
                    $queryRefs .= "volume = " . quote_smart($recordData['volume']) . ", ";
                }
                if (!empty($volumeNumeric)) {
                    $queryRefs .= "volume_numeric = " . quote_smart($volumeNumeric) . ", ";
                }
                if (!empty($recordData['issue'])) {
                    $queryRefs .= "issue = " . quote_smart($recordData['issue']) . ", ";
                }
                if (!empty($recordData['pages'])) {
                    $queryRefs .= "pages = " . quote_smart($recordData['pages']) . ", ";
                }
                if (!empty($firstPage)) {
                    $queryRefs .= "first_page = " . quote_smart($firstPage) . ", ";
                }
                if (!empty($recordData['address'])) {
                    $queryRefs .= "address = " . quote_smart($recordData['address']) . ", ";
                }
                if (!empty($recordData['corporate_author'])) {
                    $queryRefs .= "corporate_author = " . quote_smart($recordData['corporate_author']) . ", ";
                }
                if (!empty($recordData['keywords'])) {
                    $queryRefs .= "keywords = " . quote_smart($recordData['keywords']) . ", ";
                }
                if (!empty($recordData['abstract'])) {
                    $queryRefs .= "abstract = " . quote_smart($recordData['abstract']) . ", ";
                }
                if (!empty($recordData['publisher'])) {
                    $queryRefs .= "publisher = " . quote_smart($recordData['publisher']) . ", ";
                }
                if (!empty($recordData['place'])) {
                    $queryRefs .= "place = " . quote_smart($recordData['place']) . ", ";
                }
                if (!empty($recordData['editor'])) {
                    $queryRefs .= "editor = " . quote_smart($recordData['editor']) . ", ";
                }
                if (!empty($recordData['language'])) {
                    $queryRefs .= "language = " . quote_smart($recordData['language']) . ", ";
                }
                if (!empty($recordData['summary_language'])) {
                    $queryRefs .= "summary_language = " . quote_smart($recordData['summary_language']) . ", ";
                }
                if (!empty($recordData['orig_title'])) {
                    $queryRefs .= "orig_title = " . quote_smart($recordData['orig_title']) . ", ";
                }
                if (!empty($recordData['series_editor'])) {
                    $queryRefs .= "series_editor = " . quote_smart($recordData['series_editor']) . ", ";
                }
                if (!empty($recordData['series_title'])) {
                    $queryRefs .= "series_title = " . quote_smart($recordData['series_title']) . ", ";
                }
                if (!empty($recordData['abbrev_series_title'])) {
                    $queryRefs .= "abbrev_series_title = " . quote_smart($recordData['abbrev_series_title']) . ", ";
                }
                if (!empty($recordData['series_volume'])) {
                    $queryRefs .= "series_volume = " . quote_smart($recordData['series_volume']) . ", ";
                }
                if (!empty($seriesVolumeNumeric)) {
                    $queryRefs .= "series_volume_numeric = " . quote_smart($seriesVolumeNumeric) . ", ";
                }
                if (!empty($recordData['series_issue'])) {
                    $queryRefs .= "series_issue = " . quote_smart($recordData['series_issue']) . ", ";
                }
                if (!empty($recordData['edition'])) {
                    $queryRefs .= "edition = " . quote_smart($recordData['edition']) . ", ";
                }
                if (!empty($recordData['issn'])) {
                    $queryRefs .= "issn = " . quote_smart($recordData['issn']) . ", ";
                }
                if (!empty($recordData['isbn'])) {
                    $queryRefs .= "isbn = " . quote_smart($recordData['isbn']) . ", ";
                }
                if (!empty($recordData['medium'])) {
                    $queryRefs .= "medium = " . quote_smart($recordData['medium']) . ", ";
                }
                if (!empty($recordData['area'])) {
                    $queryRefs .= "area = " . quote_smart($recordData['area']) . ", ";
                }
                if (!empty($recordData['expedition'])) {
                    $queryRefs .= "expedition = " . quote_smart($recordData['expedition']) . ", ";
                }
                if (!empty($recordData['conference'])) {
                    $queryRefs .= "conference = " . quote_smart($recordData['conference']) . ", ";
                }
                // the 'location' and 'call_number' fields are handled below
                if (!empty($recordData['approved'])) {
                    $queryRefs .= "approved = " . quote_smart($recordData['approved']) . ", ";
                }
                if (!empty($recordData['file'])) {
                    $queryRefs .= "file = " . quote_smart($recordData['file']) . ", ";
                }
                // the 'serial' field is handled below
                if (!empty($recordData['orig_record'])) {
                    $queryRefs .= "orig_record = " . quote_smart($recordData['orig_record']) . ", ";
                }
                if (!empty($recordData['type'])) {
                    $queryRefs .= "type = " . quote_smart($recordData['type']) . ", ";
                }
                if (!empty($recordData['thesis'])) {
                    $queryRefs .= "thesis = " . quote_smart(strlen($recordData['thesis']) > 0 ? 'yes' : 'no') . ", ";
                }
                if (!empty($recordData['notes'])) {
                    $queryRefs .= "notes = " . quote_smart($recordData['notes']) . ", ";
                }
                if (!empty($recordData['url'])) {
                    $queryRefs .= "url = " . quote_smart($recordData['url']) . ", ";
                }
                if (!empty($recordData['doi'])) {
                    $queryRefs .= "doi = " . quote_smart($recordData['doi']) . ", ";
                }
                if (!empty($recordData['contribution_id'])) {
                    $queryRefs .= "contribution_id = " . quote_smart($recordData['contribution_id']) . ", ";
                }
                if (!empty($recordData['online_publication'])) {
                    $queryRefs .= "online_publication = " . quote_smart($recordData['online_publication']) . ", ";
                }
                if (!empty($recordData['online_citation'])) {
                    $queryRefs .= "online_citation = " . quote_smart($recordData['online_citation']) . ", ";
                }
                if (!empty($queryRefs)) {
                    // we only honour the 'call_number' string if some other record data were passed as well:
                    //
                    // if the 'prefix_call_number' option is set to "true", any 'call_number' string will be prefixed with
                    // the correct call number prefix of the currently logged-in user (e.g. 'IP� @ msteffens @ '):
                    if (isset($_SESSION['loginEmail']) and isset($importDataArray['options']['prefix_call_number']) and $importDataArray['options']['prefix_call_number'] == "true") {
                        $callNumberPrefix = getCallNumberPrefix();
                        // build a correct call number prefix for the currently logged-in user (e.g. 'IP� @ msteffens')
                        if (!empty($recordData['call_number'])) {
                            $queryRefs .= "call_number = " . quote_smart($callNumberPrefix . " @ " . $recordData['call_number']) . ", ";
                        } else {
                            $queryRefs .= "call_number = " . quote_smart($callNumberPrefix . " @ ") . ", ";
                        }
                        // similar to the GUI behaviour, we'll also add a call number prefix if the 'call_number' string is empty
                    } else {
                        if (!empty($recordData['call_number'])) {
                            $queryRefs .= "call_number = " . quote_smart($recordData['call_number']) . ", ";
                        }
                    }
                    // if no specific cite key exists in '$recordData', any existing 'call_number' string gets also copied to the
                    // user-specific 'cite_key' field (which will ensure that this original call number/cite key is retained as
                    // cite key upon export); however, note that (depending on the user's settings) the cite key may get modified
                    // or regenerated by function 'generateCiteKey()' below
                    if (isset($_SESSION['loginEmail']) and !empty($recordData['call_number']) and empty($recordData['cite_key'])) {
                        $recordData['cite_key'] = $recordData['call_number'];
                    }
                    // for the 'location' field, we accept input from the '$recordData',
                    // but if no data were given, we'll add the currently logged-in user to the 'location' field:
                    if (!empty($recordData['location'])) {
                        $queryRefs .= "location = " . quote_smart($recordData['location']) . ", ";
                    } elseif (isset($_SESSION['loginEmail'])) {
                        $queryRefs .= "location = " . quote_smart($currentUser) . ", ";
                    }
                    $queryRefs .= "serial = NULL, ";
                    // inserting 'NULL' into an auto_increment PRIMARY KEY attribute allocates the next available key value
                    // we accept custom values for the *date/*time/*by fields if they are in correct format (*date: 'YYYY-MM-DD'; *time: 'HH:MM:SS'; *by: 'string'),
                    // otherwise we'll use the current date & time as well as the currently logged-in user name & email address:
                    if (!empty($recordData['created_by'])) {
                        $queryRefs .= "created_by = " . quote_smart($recordData['created_by']) . ", ";
                    } elseif (isset($_SESSION['loginEmail'])) {
                        $queryRefs .= "created_by = " . quote_smart($currentUser) . ", ";
                    }
                    if (!empty($recordData['created_date']) and preg_match("/^\\d{4}-\\d{2}-\\d{2}\$/", $recordData['created_date'])) {
                        $queryRefs .= "created_date = " . quote_smart($recordData['created_date']) . ", ";
                    } else {
                        $queryRefs .= "created_date = " . quote_smart($currentDate) . ", ";
                    }
                    if (!empty($recordData['created_time']) and preg_match("/^\\d{2}:\\d{2}:\\d{2}\$/", $recordData['created_time'])) {
                        $queryRefs .= "created_time = " . quote_smart($recordData['created_time']) . ", ";
                    } else {
                        $queryRefs .= "created_time = " . quote_smart($currentTime) . ", ";
                    }
                    if (!empty($recordData['modified_by'])) {
                        $queryRefs .= "modified_by = " . quote_smart($recordData['modified_by']) . ", ";
                    } elseif (isset($_SESSION['loginEmail'])) {
                        $queryRefs .= "modified_by = " . quote_smart($currentUser) . ", ";
                    }
                    if (!empty($recordData['modified_date']) and preg_match("/^\\d{4}-\\d{2}-\\d{2}\$/", $recordData['modified_date'])) {
                        $queryRefs .= "modified_date = " . quote_smart($recordData['modified_date']) . ", ";
                    } else {
                        $queryRefs .= "modified_date = " . quote_smart($currentDate) . ", ";
                    }
                    if (!empty($recordData['modified_time']) and preg_match("/^\\d{2}:\\d{2}:\\d{2}\$/", $recordData['modified_time'])) {
                        $queryRefs .= "modified_time = " . quote_smart($recordData['modified_time']) . "";
                    } else {
                        $queryRefs .= "modified_time = " . quote_smart($currentTime);
                    }
                    $queryRefs = "INSERT INTO {$tableRefs} SET " . $queryRefs;
                    // finalize the query by prefixing it with the actual MySQL command
                    // ADD RECORD:
                    // RUN the query on the database through the connection:
                    $result = queryMySQLDatabase($queryRefs);
                    // Get the record id that was created:
                    $serialNo = @mysql_insert_id($connection);
                    // find out the unique ID number of the newly created record (Note: this function should be called immediately after the
                    // SQL INSERT statement! After any subsequent query it won't be possible to retrieve the auto_increment identifier value for THIS record!)
                    // ADD USER DATA:
                    if (isset($_SESSION['loginEmail'])) {
                        // Note: At the moment, the record in table 'user_data' will be always created for the currently logged-in user,
                        //       i.e. we don't try to match any custom data given in the 'location' field with users from table 'users'
                        //       in order to set the 'user_id' in table 'user_data' accordingly
                        // This is a stupid hack that maps the names of the '$recordData' 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($recordData);
                        // Generate or extract the cite key for this record:
                        $citeKey = generateCiteKey($formVars);
                        // Construct SQL query:
                        $queryUserData = "INSERT INTO {$tableUserData} SET ";
                        if (!empty($recordData['marked']) and preg_match("/^(no|yes)\$/", $recordData['marked'])) {
                            $queryUserData .= "marked = " . quote_smart($recordData['marked']) . ", ";
                        }
                        if (!empty($recordData['copy']) and preg_match("/^(false|true|ordered|fetch)\$/", $recordData['copy'])) {
                            $queryUserData .= "copy = " . quote_smart($recordData['copy']) . ", ";
                        } else {
                            $queryUserData .= "copy = 'true', ";
                        }
                        // by default, 'false' would get inserted if omitted; we insert 'true' here in order to be consistent with manual record additions
                        if (!empty($recordData['selected']) and preg_match("/^(no|yes)\$/", $recordData['selected'])) {
                            $queryUserData .= "selected = " . quote_smart($recordData['selected']) . ", ";
                        }
                        if (!empty($recordData['user_keys'])) {
                            $queryUserData .= "user_keys = " . quote_smart($recordData['user_keys']) . ", ";
                        }
                        if (!empty($recordData['user_notes'])) {
                            $queryUserData .= "user_notes = " . quote_smart($recordData['user_notes']) . ", ";
                        }
                        if (!empty($recordData['user_file'])) {
                            $queryUserData .= "user_file = " . quote_smart($recordData['user_file']) . ", ";
                        }
                        if (!empty($recordData['user_groups'])) {
                            $queryUserData .= "user_groups = " . quote_smart($recordData['user_groups']) . ", ";
                        }
                        $queryUserData .= "cite_key = " . quote_smart($citeKey) . ", ";
                        if (!empty($recordData['related'])) {
                            $queryUserData .= "related = " . quote_smart($recordData['related']) . ", ";
                        }
                        $queryUserData .= "record_id = " . quote_smart($serialNo) . ", " . "user_id = " . quote_smart($loginUserID) . ", " . "data_id = NULL";
                        // inserting 'NULL' into an auto_increment PRIMARY KEY attribute allocates the next available key value
                        // RUN the query on the database through the connection:
                        $result = queryMySQLDatabase($queryUserData);
                    }
                    // Append this record's serial number to the array of imported record serials:
                    $serialNumbersArray[] = $serialNo;
                }
                // else: '$recordData' did not contain any data, so we skip this record
            }
            // (END LOOP OVER EACH RECORD)
        }
        // else: unknown array structure, return an empty '$serialNumbersArray'
    }
    // else: couldn't verify structure of '$importDataArray', return an empty '$serialNumbersArray'
    return $serialNumbersArray;
    // return list of serial numbers of all imported records
}
示例#7
0
function parseRecord($row, $odfIndexesToRefbaseFieldsArray, $referenceTypesToRefbaseTypesArray, $universalSearchReplaceActionsArray, $fieldSpecificSearchReplaceActionsArray)
{
    global $officialDatabaseName;
    // these variables are defined in 'ini.inc.php'
    global $databaseBaseURL;
    global $contentTypeCharset;
    global $convertExportDataToUTF8;
    $fieldParametersArray = array();
    // 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
    $citeKey = generateCiteKey($formVars);
    // function 'generateCiteKey()' is defined in 'include.inc.php'
    // PARSE RECORD:
    // parse the '$odfIndexesToRefbaseFieldsArray' which maps ODF indexes to refbase field names and assign fields accordingly:
    foreach ($odfIndexesToRefbaseFieldsArray as $odfIndex => $refbaseField) {
        if (empty($odfIndexesToRefbaseFieldsArray[$odfIndex])) {
            $fieldParametersArray[$odfIndex] = "";
            // for any unsupported ODF index we'll insert an empty string
        } else {
            // copy row field data to array of field parameters (using the corresponding ODF index name as element key):
            if (!is_array($odfIndexesToRefbaseFieldsArray[$odfIndex])) {
                if (!empty($refbaseField) and !empty($row[$refbaseField])) {
                    $fieldParametersArray[$odfIndex] = $row[$refbaseField];
                }
            } else {
                $useDefault = true;
                // ...we'll extract field data from different refbase fields depending on the current record's reference type:
                foreach ($odfIndexesToRefbaseFieldsArray[$odfIndex] as $referenceType => $refbaseField) {
                    if ($row['type'] == $referenceType) {
                        $useDefault = false;
                        if (is_array($odfIndexesToRefbaseFieldsArray[$odfIndex][$referenceType])) {
                            foreach ($odfIndexesToRefbaseFieldsArray[$odfIndex][$referenceType] as $refbaseField) {
                                if (!empty($refbaseField) and !empty($row[$refbaseField])) {
                                    $fieldParametersArray[$odfIndex] = $row[$refbaseField];
                                    break;
                                }
                            }
                        } elseif (!empty($refbaseField) and !empty($row[$refbaseField])) {
                            $fieldParametersArray[$odfIndex] = $row[$refbaseField];
                        }
                        break;
                    }
                }
                // 'Other' is used as default for all refbase types that were NOT explicitly specified:
                if ($useDefault and !isset($fieldParametersArray[$odfIndex]) and isset($odfIndexesToRefbaseFieldsArray[$odfIndex]['Other'])) {
                    if (is_array($odfIndexesToRefbaseFieldsArray[$odfIndex]['Other'])) {
                        foreach ($odfIndexesToRefbaseFieldsArray[$odfIndex]['Other'] as $refbaseField) {
                            if (!empty($refbaseField) and !empty($row[$refbaseField])) {
                                $fieldParametersArray[$odfIndex] = $row[$refbaseField];
                                break;
                            }
                        }
                    } elseif (!empty($odfIndexesToRefbaseFieldsArray[$odfIndex]['Other']) and !empty($row[$odfIndexesToRefbaseFieldsArray[$odfIndex]['Other']])) {
                        $fieldParametersArray[$odfIndex] = $row[$odfIndexesToRefbaseFieldsArray[$odfIndex]['Other']];
                    }
                }
                // if this ODF field is still not set, 'Any' is used as default, no matter whether any refbase types were specified explicitly or not:
                if (!isset($fieldParametersArray[$odfIndex]) and isset($odfIndexesToRefbaseFieldsArray[$odfIndex]['Any'])) {
                    if (is_array($odfIndexesToRefbaseFieldsArray[$odfIndex]['Any'])) {
                        foreach ($odfIndexesToRefbaseFieldsArray[$odfIndex]['Any'] as $refbaseField) {
                            if (!empty($refbaseField) and !empty($row[$refbaseField])) {
                                $fieldParametersArray[$odfIndex] = $row[$refbaseField];
                                break;
                            }
                        }
                    } elseif (!empty($odfIndexesToRefbaseFieldsArray[$odfIndex]['Any']) and !empty($row[$odfIndexesToRefbaseFieldsArray[$odfIndex]['Any']])) {
                        $fieldParametersArray[$odfIndex] = $row[$odfIndexesToRefbaseFieldsArray[$odfIndex]['Any']];
                    }
                }
            }
            // if this ODF field isn't set yet, provide an empty string:
            if (!isset($fieldParametersArray[$odfIndex])) {
                $fieldParametersArray[$odfIndex] = "";
            }
        }
    }
    // POST-PROCESS FIELD DATA:
    // currently, we'll always overwrite the record serial in the 'Identifier' field with the generated cite key:
    // (this means that NO identifier will be exported if you've unchecked the export option "Include cite keys on export")
    $fieldParametersArray['Identifier'] = $citeKey;
    // convert refbase type names into ODF type numbers:
    $fieldParametersArray['BibliographyType'] = $referenceTypesToRefbaseTypesArray[$fieldParametersArray['BibliographyType']];
    // for theses, set the correct ODF type:
    if (!empty($row['thesis'])) {
        if ($row['thesis'] == "Ph.D. thesis" or $row['thesis'] == "Doctoral thesis") {
            $fieldParametersArray['BibliographyType'] = "11";
        } else {
            $fieldParametersArray['BibliographyType'] = "9";
        }
        // Thesis
        if (isset($fieldParametersArray['Annote'])) {
            $fieldParametersArray['Annote'] .= "; " . $row['thesis'];
        } else {
            $fieldParametersArray['Annote'] = $row['thesis'];
        }
    }
    // if a DOI was copied to the URL field, we'll need to add the DOI resolver:
    if (!empty($row['doi']) and preg_match("/^\\d{2}\\.\\d{4}\\//", $fieldParametersArray['URL'])) {
        $fieldParametersArray['URL'] = "http://dx.doi.org/" . $fieldParametersArray['URL'];
    }
    // use the series volume as volume if 'series_volume' contains some info, but 'volume' doesn't:
    if (empty($row['volume']) and !empty($row['series_volume'])) {
        $fieldParametersArray['Volume'] = $row['series_volume'];
    }
    // set the fourth ODF custom field to a refbase database attribution string and the database URL:
    $fieldParametersArray['Custom4'] = "exported from " . $officialDatabaseName . " (" . $databaseBaseURL . ")";
    // set the fifth ODF custom field to the record's permanent database URL:
    $fieldParametersArray['Custom5'] = $databaseBaseURL . "show.php?record=" . $row['serial'];
    // apply universal search & replace actions, encode special chars and charset conversions to every field that shall be exported:
    foreach ($fieldParametersArray as $fieldName => $fieldValue) {
        if (!empty($fieldValue)) {
            // perform universal search & replace actions:
            if (!empty($universalSearchReplaceActionsArray)) {
                $fieldParametersArray[$fieldName] = searchReplaceText($universalSearchReplaceActionsArray, $fieldParametersArray[$fieldName], true);
            }
            // function 'searchReplaceText()' is defined in 'include.inc.php'
            // we only convert those special chars to entities which are supported by XML:
            $fieldParametersArray[$fieldName] = encodeHTMLspecialchars($fieldParametersArray[$fieldName]);
            // function 'encodeHTMLspecialchars()' is defined in 'include.inc.php'
            // convert field data to UTF-8 (if '$convertExportDataToUTF8' is set to "yes" in 'ini.inc.php' and character encoding is not UTF-8 already):
            // (note that charset conversion can only be done *after* the cite key has been generated, otherwise cite key generation will produce garbled text!)
            if ($convertExportDataToUTF8 == "yes" and $contentTypeCharset != "UTF-8") {
                $fieldParametersArray[$fieldName] = convertToCharacterEncoding("UTF-8", "IGNORE", $fieldParametersArray[$fieldName]);
            }
            // function 'convertToCharacterEncoding()' is defined in 'include.inc.php'
        }
    }
    // apply field-specific search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$fieldSpecificSearchReplaceActionsArray':
    foreach ($fieldSpecificSearchReplaceActionsArray as $fieldActionsArray) {
        foreach ($fieldParametersArray as $fieldName => $fieldValue) {
            if (in_array($fieldName, $fieldActionsArray['fields'])) {
                $fieldParametersArray[$fieldName] = searchReplaceText($fieldActionsArray['actions'], $fieldValue, true);
            }
        }
    }
    // function 'searchReplaceText()' is defined in 'include.inc.php'
    return $fieldParametersArray;
}
示例#8
0
function atomEntry($row, $markupPatternsArray)
{
    global $databaseBaseURL;
    // these variables are defined in 'ini.inc.php'
    global $contentTypeCharset;
    global $fileVisibility;
    global $fileVisibilityException;
    global $filesBaseURL;
    global $convertExportDataToUTF8;
    global $defaultCiteStyle;
    global $citeStyle;
    global $citeOrder;
    global $alnum, $alpha, $cntrl, $dash, $digit, $graph, $lower, $print, $punct, $space, $upper, $word, $patternModifiers;
    // defined in 'transtab_unicode_charset.inc.php' and 'transtab_latin1_charset.inc.php'
    // The array '$transtab_refbase_unicode' contains search & replace patterns for conversion from refbase markup to Unicode entities.
    global $transtab_refbase_unicode;
    // defined in 'transtab_refbase_unicode.inc.php'
    // The array '$transtab_refbase_ascii' contains search & replace patterns for conversion from refbase markup to plain text.
    global $transtab_refbase_ascii;
    // defined in 'transtab_refbase_ascii.inc.php'
    // The array '$transtab_refbase_html' contains search & replace patterns for conversion from refbase markup to HTML markup & entities.
    // Note that this will only convert markup which wasn't converted to Unicode entities by '$transtab_refbase_unicode'; this will provide
    // for correct rendering of italic and bold letters in 'content' elements (which is of 'type="xhtml"').
    global $transtab_refbase_html;
    // defined in 'transtab_refbase_html.inc.php'
    // NOTE: We remove again some search & replace patterns that are present by default in '$transtab_refbase_html' since they cause
    //       problems here; this is surely hacky but I don't know any better. :-/
    unset($transtab_refbase_html['/ +- +/']);
    // this would incorrectly convert author initials such as "J. - L." to "J. &#8211; L."
    // Define inline text markup to generate a plain text citation string:
    // (to be included within a 'dcterms:bibliographicCitation' element)
    $markupPatternsArrayPlain = array("bold-prefix" => "", "bold-suffix" => "", "italic-prefix" => "", "italic-suffix" => "", "underline-prefix" => "", "underline-suffix" => "", "endash" => "-", "emdash" => "-", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => '"', "double-quote-right" => '"', "single-quote" => "'", "single-quote-left" => "'", "single-quote-right" => "'", "less-than" => "<", "greater-than" => ">", "newline" => "\n");
    // 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:
    // (to be included within a 'dc:identifier' element)
    $citeKey = generateCiteKey($formVars);
    // function 'generateCiteKey()' is defined in 'include.inc.php'
    // Generate OpenURL data:
    // (to be included within a 'dc:identifier' element)
    $openURL = openURL($row, "openurl:");
    // function 'openURL()' is defined in 'openurl.inc.php'
    // Encode special chars and perform charset conversions:
    foreach ($row as $rowFieldName => $rowFieldValue) {
        // We only convert those special chars to entities which are supported by XML:
        // function 'encodeHTMLspecialchars()' is defined in 'include.inc.php'
        $row[$rowFieldName] = encodeHTMLspecialchars($row[$rowFieldName]);
        // Convert field data to UTF-8:
        // (if '$convertExportDataToUTF8' is set to "yes" in 'ini.inc.php' and character encoding is not UTF-8 already)
        // (Note that charset conversion can only be done *after* the cite key has been generated, otherwise cite key
        //  generation will produce garbled text!)
        // function 'convertToCharacterEncoding()' is defined in 'include.inc.php'
        if ($convertExportDataToUTF8 == "yes" and $contentTypeCharset != "UTF-8") {
            $row[$rowFieldName] = convertToCharacterEncoding("UTF-8", "IGNORE", $row[$rowFieldName]);
        }
    }
    // Defines field-specific search & replace 'actions' that will be applied to all those refbase fields that are listed in the corresponding 'fields' element:
    // (If you don't want to perform any search and replace actions, specify an empty array, like: '$fieldSpecificSearchReplaceActionsArray = array();'.
    //  Note that the search patterns MUST include the leading & trailing slashes -- which is done to allow for mode modifiers such as 'imsxU'.)
    //                                          "/Search Pattern/"  =>  "Replace Pattern"
    $fieldSpecificSearchReplaceActionsArray = array();
    if ($convertExportDataToUTF8 == "yes") {
        $fieldSpecificSearchReplaceActionsArray[] = array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_unicode);
    }
    // Apply field-specific search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$fieldSpecificSearchReplaceActionsArray':
    foreach ($fieldSpecificSearchReplaceActionsArray as $fieldActionsArray) {
        foreach ($row as $rowFieldName => $rowFieldValue) {
            if (in_array($rowFieldName, $fieldActionsArray['fields'])) {
                $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $rowFieldValue, true);
            }
        }
    }
    // function 'searchReplaceText()' is defined in 'include.inc.php'
    // Fetch the name of the citation style file that's associated with the style given in '$citeStyle':
    $citeStyleFile = getStyleFile($citeStyle);
    // function 'getStyleFile()' is defined in 'include.inc.php'
    if (empty($citeStyleFile)) {
        $citeStyle = $defaultCiteStyle;
        // if the given cite style could not be found, we'll use the default cite style which is defined by the '$defaultCiteStyle' variable in 'ini.inc.php'
        $citeStyleFile = getStyleFile($citeStyle);
    }
    // Include the found citation style file *once*:
    include_once "cite/" . $citeStyleFile;
    // Generate a proper citation for this record, ordering attributes according to the chosen output style & record type:
    // - Plain text version of citation string:
    //   (the plain text version of the citation string will be included in the 'dcterms:bibliographicCitation' element which should contain plain text only)
    $recordCitationPlain = citeRecord($row, $citeStyle, "", $markupPatternsArrayPlain, false);
    // function 'citeRecord()' is defined in the citation style file given in '$citeStyleFile' (which, in turn, must reside in the 'styles' directory of the refbase root directory)
    //   Convert any refbase markup that remains in the citation string (such as _italic_ or **bold**) to plain text:
    $recordCitationPlain = searchReplaceText($transtab_refbase_ascii, $recordCitationPlain, true);
    // - HTML version of citation string:
    //   (note that, for output of Atom XML, we do NOT HTML encode higher ASCII characters; thus, the last param in the below function call is 'false')
    $recordCitation = citeRecord($row, $citeStyle, "", $markupPatternsArray, false);
    //   Convert any refbase markup that remains in the citation string (such as _italic_ or **bold**) into HTML markup:
    //   (the HTML version of the citation string will be included in the Atom 'content' element which uses 'type="xhtml"')
    $recordCitation = searchReplaceText($transtab_refbase_html, $recordCitation, true);
    // Save a plain text version of the title to a new variable:
    // (this will be included in the 'dc:title' element which should contain plain text only)
    $titlePlain = searchReplaceText($transtab_refbase_ascii, $row['title'], true);
    // Convert any remaining refbase markup in the abstract & title to HTML markup:
    // (we use 'type="xhtml"' in the Atom 'title' and 'summary' elements)
    $row['title'] = searchReplaceText($transtab_refbase_html, $row['title'], true);
    $row['abstract'] = searchReplaceText($transtab_refbase_html, $row['abstract'], true);
    // Convert keywords to plain text:
    // (keywords will be written to 'dc:subject' elements which should contain plain text only)
    $row['keywords'] = searchReplaceText($transtab_refbase_ascii, $row['keywords'], true);
    // To avoid advertising email adresses in public Atom XML output, we remove the email address from contents of the
    // 'modified_by' and 'created_by' fields which get displayed in the 'author' and 'content' elements.
    // The following pattern does not attempt to do fancy parsing of email addresses but simply assumes the string format of the
    // 'modified_by' and 'created_by' fields (table 'refs'). If you change the string format, you must modify this pattern as well!
    $creatorName = preg_replace("/(.+?) \\([^)]+\\)/", "\\1", $row['created_by']);
    $editorName = preg_replace("/(.+?) \\([^)]+\\)/", "\\1", $row['modified_by']);
    // Strip any " (ed)" or " (eds)" suffix from author/editor string:
    if (preg_match("/ *\\(eds?\\)\$/", $row['author'])) {
        $row['author'] = preg_replace("/[ \r\n]*\\(eds?\\)/i", "", $row['author']);
    }
    if (preg_match("/ *\\(eds?\\)\$/", $row['editor'])) {
        $row['editor'] = preg_replace("/[ \r\n]*\\(eds?\\)/i", "", $row['editor']);
    }
    // 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)
    //
    // TODO: - the URL-generating code should be made into a dedicated function (since it's shared with 'modsxml.inc.php' and 'oaidcxml.inc.php')
    $printURL = false;
    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]])) {
        if (!empty($row['file'])) {
            if (preg_match('#^(https?|ftp|file)://#i', $row['file'])) {
                $URLprefix = "";
                // we don't alter the URL given in the 'file' field
            } else {
                // 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;
                }
            }
            $printURL = true;
        }
    }
    // ----------------------------------------------------------
    // Start Atom XML entry:
    $entry = new XML("entry");
    // create an XML object for a single record
    // Add entry-level tags:
    // (not yet used: category, contributor, source, rights)
    // - 'id':
    addNewBranch($entry, "id", array(), $databaseBaseURL . generateURL("show.php", "html", array("record" => $row['serial']), true));
    // - 'title':
    //   TODO: - the 'title' element is required for 'entry', so we may need to insert something else if the record's title is missing
    //		addNewBranch($entry, "title", array("type" => "text"), $titlePlain); // plain text version
    addNewBranch($entry, "title", array("type" => "xhtml"), '<div xmlns="http://www.w3.org/1999/xhtml">' . $row['title'] . '</div>');
    // - 'updated':
    addNewBranch($entry, "updated", array(), generateISO8601TimeStamp($row['modified_date'], $row['modified_time']));
    // function 'generateISO8601TimeStamp()' is defined in 'include.inc.php'
    // - 'published':
    //   NOTE: we use the 'published' element to indicate the date/time when the record was created in the refbase database,
    //         and not when the record's resource was originally published
    addNewBranch($entry, "published", array(), generateISO8601TimeStamp($row['created_date'], $row['created_time']));
    // - 'link':
    //   NOTE: According to the Atom spec, a feed is limited to ONE 'rel=alternate' link per type and hreflang!
    //   A) Main display formats:
    //   - HTML output for this record:
    //     NOTE: How can we output an 'alternate' link to the HTML citation with the same 'type'?
    //           But, maybe, this isn't necessary since a client GUI (layered over the Atom XML data) would expose
    //           the record citation (from the 'content' or 'bibliographicCitation' element) anyhow... ?
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "html", array("record" => $row['serial']), true, "", "", $citeStyle), "alternate", "html", "View record in HTML format");
    // function 'generateURL()' is defined in 'include.inc.php'
    //   B) Export formats
    //   NOTE: should we rather generate 'unapi.php' and 'opensearch.php' URLs where possible?
    //   TODO: add links for ADS, ISI, RSS XML and Word XML
    //   - BibTeX data for this record:
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "BibTeX", array("record" => $row['serial']), true), "alternate", "BibTeX", "Export record in BibTeX format");
    //   - Endnote data for this record:
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "Endnote", array("record" => $row['serial']), true), "alternate", "Endnote", "Export record in Endnote format");
    //   - RIS data for this record:
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "RIS", array("record" => $row['serial']), true), "alternate", "RIS", "Export record in RIS format");
    //   - Atom XML data for this record:
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "Atom XML", array("record" => $row['serial']), true, "", "", $citeStyle), "alternate", "Atom XML", "Export record as Atom XML");
    //   - MODS XML data for this record:
    //     NOTE: while we include a link to SRW_MODS XML on feed level, we instead include a link to MODS XML on entry level since the SRW overhead isn't really needed here
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "MODS XML", array("record" => $row['serial']), true), "alternate", "MODS XML", "Export record as MODS XML");
    //   - OAI_DC XML data for this record:
    //     NOTE: A link to MODS XML is already used with this type!
    //		atomLink($entry, $databaseBaseURL . generateURL("show.php", "OAI_DC XML", array("record" => $row['serial']), true, "", "", $citeStyle), "alternate", "OAI_DC XML", "Export record as OAI_DC XML");
    //   - ODF XML data for this record:
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "ODF XML", array("record" => $row['serial'], "exportType" => "file"), true), "alternate", "ODF XML", "Export record as ODF XML");
    //   - SRW_DC XML data for this record:
    //     NOTE: A link to MODS XML is already used with this type!
    //		atomLink($entry, $databaseBaseURL . generateURL("show.php", "SRW_DC XML", array("record" => $row['serial']), true, "", "", $citeStyle), "alternate", "SRW_DC XML", "Export record as SRW_DC XML");
    //   - SRW_MODS XML data for this record:
    //     NOTE: A link to MODS XML is already used with this type!
    //		atomLink($entry, $databaseBaseURL . generateURL("show.php", "SRW_MODS XML", array("record" => $row['serial']), true), "alternate", "SRW_MODS XML", "Export record as SRW_MODS XML");
    //   C) Citation formats:
    //   - RTF citations for this record:
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "RTF", array("record" => $row['serial']), true, "", "", $citeStyle, $citeOrder), "alternate", "RTF", "Output record as citation in RTF format");
    //   - PDF citations for this record:
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "PDF", array("record" => $row['serial']), true, "", "", $citeStyle, $citeOrder), "alternate", "PDF", "Output record as citation in PDF format");
    //   - LaTeX citations for this record:
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "LaTeX", array("record" => $row['serial']), true, "", "", $citeStyle, $citeOrder), "alternate", "LaTeX", "Output record as citation in LaTeX format");
    //   - LaTeX .bbl citations for this record:
    //     NOTE: A link to a LaTeX citation is already used with this type!
    //		atomLink($entry, $databaseBaseURL . generateURL("show.php", "LaTeX .bbl", array("record" => $row['serial']), true, "", "", $citeStyle, $citeOrder), "alternate", "LaTeX .bbl", "Output record as citation in LaTeX .bbl format");
    //   - Markdown citations for this record:
    atomLink($entry, $databaseBaseURL . generateURL("show.php", "Markdown", array("record" => $row['serial']), true, "", "", $citeStyle, $citeOrder), "alternate", "Markdown", "Output record as citation in Markdown format");
    //   - ASCII citations for this record:
    //     NOTE: A link to a Markdown citation is already used with this type!
    //		atomLink($entry, $databaseBaseURL . generateURL("show.php", "ASCII", array("record" => $row['serial']), true, "", "", $citeStyle, $citeOrder), "alternate", "ASCII", "Output record as citation in ASCII format");
    //   D) Related links:
    //   - Related URL:
    //     TODO: - the 'type' (and 'title'?) attributes should get adopted if something other than an URL pointing to a HTML page is given
    if (!empty($row['url'])) {
        atomLink($entry, $row['url'], "related", "html", "Web page");
    }
    //   - Related FILE:
    //     NOTE: - should we better use the 'enclosure' element instead?
    //     TODO: - the 'type' attribute should get adopted if something other than PDF is given
    if ($printURL) {
        atomLink($entry, $URLprefix . $row['file'], "related", "PDF", "Electronic full text");
    }
    // - 'author':
    //   NOTE: The Atom 'author' element contains the database user who created this record,
    //         while the publication authors are contained within 'dc:creator' elements
    $recAuthorBranch = new XMLBranch("author");
    $recAuthorBranch->setTagContent($creatorName, "author/name");
    $entry->addXMLBranch($recAuthorBranch);
    // - 'contributor':
    //   NOTE: The Atom 'contributor' element contains the database user who edited this record last,
    //         while the publication editors are contained within 'dc:contributor' elements
    if ($creatorName != $editorName) {
        $recEditorBranch = new XMLBranch("contributor");
        $recEditorBranch->setTagContent($editorName, "contributor/name");
        $entry->addXMLBranch($recEditorBranch);
    }
    // - 'content':
    //   NOTE: According to the Atom spec, all HTML markup must be escaped if 'type="html"' is used. In case of
    //         'type="xhtml"', HTML markup is not entity escaped but must be wrapped in a single XHTML 'div' element.
    //         See: <http://atompub.org/rfc4287.html#element.content>
    //              <http://www.atomenabled.org/developers/syndication/#text>
    //		addNewBranch($entry, "content", array("type" => "html"), encodeHTMLspecialchars($recordCitation));
    addNewBranch($entry, "content", array("type" => "xhtml"), '<div xmlns="http://www.w3.org/1999/xhtml">' . '<div class="unapi"><abbr class="unapi-id" title="' . $databaseBaseURL . generateURL("show.php", "html", array("record" => $row['serial']), true) . '"></abbr></div>' . $recordCitation . '</div>');
    // - 'summary':
    if (!empty($row['abstract'])) {
        addNewBranch($entry, "summary", array("type" => "xhtml"), '<div xmlns="http://www.w3.org/1999/xhtml">' . $row['abstract'] . '</div>');
    }
    // ----------------------------------------------------------
    // Add Dublin Core elements:
    // NOTE: With a few exceptions, we try to adhere to the guidelines given at
    //       "Using simple Dublin Core to describe eprints" by Andy Powell et al.
    //       See: <http://eprints-uk.rdn.ac.uk/project/docs/simpledc-guidelines/>
    // - 'dc:title':
    if (!empty($row['title'])) {
        addMetaElement($entry, "dc", "title", array(), $titlePlain);
    }
    // function 'addMetaElement()' is defined in 'webservice.inc.php'
    // - 'dc:creator':
    //   NOTE: should we use 'foaf:maker' instead of (or in addition to) 'dc:creator'?
    //   ( xmlns:foaf="http://xmlns.com/foaf/0.1/" )
    //
    //   <foaf:maker>
    //     <foaf:Person>
    //       <foaf:name> [ Name of author 1 ] </foaf:name>
    //     </foaf:Person>
    //   </foaf:maker>
    if (!empty($row['author']) and $row['author'] != $row['editor']) {
        addMetaElement($entry, "dc", "creator", array(), $row['author']);
    }
    // - 'dc:creator':
    //   TODO: add refbase corporate author(s) as 'dc:creator'
    // - 'dc:contributor':
    if (!empty($row['editor'])) {
        addMetaElement($entry, "dc", "contributor", array(), $row['editor']);
    }
    // - 'dc:description':
    //   NOTE: since we already use the Atom-native 'summary' element for the record
    //         abstract/summary, we don't add the abstract again as 'dc:description'
    // - 'dc:identifier':
    //   - DOI:
    if (!empty($row['doi'])) {
        addMetaElement($entry, "dc", "identifier", array(), $row['doi'], "doi");
    }
    //   - PMID:
    if (!empty($row['notes']) and preg_match("/PMID *: *\\d+/i", $row['notes'])) {
        addMetaElement($entry, "dc", "identifier", array(), $row['notes'], "pmid");
    }
    //   - arXiv:
    if (!empty($row['notes']) and preg_match("/arXiv *: *[^ ;]+/i", $row['notes'])) {
        addMetaElement($entry, "dc", "identifier", array(), $row['notes'], "arxiv");
    }
    //   - ISBN:
    if (!empty($row['isbn'])) {
        addMetaElement($entry, "dc", "identifier", array(), $row['isbn'], "isbn");
    }
    //   - OpenURL:
    addMetaElement($entry, "dc", "identifier", array(), $openURL, "openurl");
    //   - Cite key:
    addMetaElement($entry, "dc", "identifier", array(), $citeKey, "citekey");
    // - 'dcterms:bibliographicCitation':
    //   NOTE: While Andy Powell (see link above) recommends to put this into a
    //         'dc:identifier' element, we'll put it into a 'dcterms:bibliographicCitation'
    //         element instead, since the citation couldn't be uniquely identified within a
    //         'dc:identifier' element without a 'citation:' prefix (or the like) but that
    //         would be non-standard. Within 'dcterms:bibliographicCitation', the citation
    //         can be uniquely identified and extracted easily.
    //         Compare with 'oaidcxml.inc.php' where, for 'oai_dc:dc' output, we put the
    //         bibliographic citation into a 'dc:identifier' element and use a "citation:"
    //         prefix:
    //		addMetaElement($entry, "dc", "identifier", array(), encodeHTMLspecialchars($recordCitationPlain), "citation");
    addMetaElement($entry, "dcterms", "bibliographicCitation", array(), encodeHTMLspecialchars($recordCitationPlain));
    // - 'dc:source':
    //   NOTE: - In <http://eprints-uk.rdn.ac.uk/project/docs/simpledc-guidelines/>,
    //           Andy Powell et al. recommend that this element should NOT be used!
    //           However, for Atom XML output, we do use the 'dc:source' element for series
    //           info (series title plus volume & issue).
    //           Compare with 'oaidcxml.inc.php' where, for 'oai_dc:dc' output, we also
    //           include publication info in a 'dc:source' element.
    //           Example: <dc:source>Polar Biology, Vol. 25, No. 10</dc:source>
    //   - Series info:
    if (!empty($row['series_title']) or !empty($row['abbrev_series_title'])) {
        if (!empty($row['series_title'])) {
            $series = $row['series_title'];
        } elseif (!empty($row['abbrev_series_title'])) {
            $series = $row['abbrev_series_title'];
        }
        if (!empty($row['series_volume'])) {
            $series .= ", Vol. " . $row['series_volume'];
        }
        if (!empty($row['series_issue'])) {
            $series .= ", No. " . $row['series_issue'];
        }
        if (!empty($series)) {
            addMetaElement($entry, "dc", "source", array(), $series);
        }
        // NOTE: To distinguish between regular publication & series info,
        //       should we better use a "series:" prefix here? If so, use:
        //				addMetaElement($entry, "dc", "source", array(), $series, "series");
    }
    // - 'dc:date':
    if (!empty($row['year'])) {
        addMetaElement($entry, "dc", "date", array(), $row['year']);
    }
    // - 'dc:type':
    if (!empty($row['type'])) {
        addMetaElement($entry, "dc", "type", array(), $row['type'], $row['thesis']);
    }
    //   In case of a thesis, we add another 'dc:type' element with the actual thesis type:
    if (!empty($row['thesis'])) {
        addMetaElement($entry, "dc", "type", array(), $row['thesis']);
    }
    // - 'dc:format':
    //   TODO: ideally, we should parse the content of the refbase 'medium' field and map it
    //         to a media-type term from <http://www.iana.org/assignments/media-types/>
    if (!empty($row['medium'])) {
        $mediaType = $row['medium'];
    } else {
        $mediaType = "text";
    }
    addMetaElement($entry, "dc", "format", array(), $mediaType);
    // - 'dc:subject':
    if (!empty($row['keywords'])) {
        addMetaElement($entry, "dc", "subject", array(), $row['keywords']);
    }
    // - 'dc:coverage':
    //   TODO: should we add contents from the refbase 'area' field as 'dc:coverage' element(s)?
    // - 'dc:relation':
    //   NOTE: currently, we only add 'related' links (and not 'alternate' links) as 'dc:relation'
    //   - Related URL:
    if (!empty($row['url'])) {
        addMetaElement($entry, "dc", "relation", array(), $row['url'], "url");
    }
    //   - Related FILE:
    if ($printURL) {
        addMetaElement($entry, "dc", "relation", array(), $URLprefix . $row['file'], "file");
    }
    // - 'dc:publisher':
    if (!empty($row['publisher'])) {
        addMetaElement($entry, "dc", "publisher", array(), $row['publisher']);
    }
    // - 'dc:language':
    //   TODO: convert to ISO notation (i.e. "en" instead of "English", etc)
    if (!empty($row['language'])) {
        addMetaElement($entry, "dc", "language", array(), $row['language']);
    }
    // ----------------------------------------------------------
    // Add PRISM elements:
    // (not yet used: section)
    // - 'prism:issn':
    //   NOTE: see note for ISBN above
    if (!empty($row['issn'])) {
        addMetaElement($entry, "prism", "issn", array(), $row['issn']);
    }
    // - 'prism:publicationName':
    if (!empty($row['publication'])) {
        addMetaElement($entry, "prism", "publicationName", array(), $row['publication']);
    } elseif (!empty($row['abbrev_journal'])) {
        addMetaElement($entry, "prism", "publicationName", array(), $row['abbrev_journal']);
    }
    // - 'prism:publicationDate':
    if (!empty($row['year'])) {
        addMetaElement($entry, "prism", "publicationDate", array(), $row['year']);
    }
    // - 'prism:volume':
    if (!empty($row['volume'])) {
        addMetaElement($entry, "prism", "volume", array(), $row['volume']);
    }
    // - 'prism:number':
    if (!empty($row['issue'])) {
        addMetaElement($entry, "prism", "number", array(), $row['issue']);
    }
    // - 'prism:startingPage', 'prism:endingPage':
    //   TODO: Similar code is used in 'include.in.php', 'modsxml.inc.php' and 'openurl.inc.php',
    //         so this should be made into a dedicated function!
    if (!empty($row['pages']) and preg_match("/\\d+/i", $row['pages'])) {
        $pages = preg_replace("/^\\D*(\\d+)( *[{$dash}]+ *\\d+)?.*/i{$patternModifiers}", "\\1\\2", $row['pages']);
        // extract page range (if there's any), otherwise just the first number
        $startPage = preg_replace("/^\\D*(\\d+).*/i", "\\1", $row['pages']);
        // extract starting page
        $endPage = extractDetailsFromField("pages", $pages, "/\\D+/", "[-1]");
        // extract ending page (function 'extractDetailsFromField()' is defined in 'include.inc.php')
        // NOTE: To extract the ending page, we'll use function 'extractDetailsFromField()'
        //       instead of just grabbing a matched regex pattern since it'll also work
        //       when just a number but no range is given (e.g. when startPage = endPage)
        // - 'prism:startingPage':
        if (preg_match("/\\d+ *[{$dash}]+ *\\d+/i{$patternModifiers}", $row['pages'])) {
            // if there's a page range
            addMetaElement($entry, "prism", "startingPage", array(), $startPage);
        }
        // - 'prism:endingPage':
        addMetaElement($entry, "prism", "endingPage", array(), $endPage);
    }
    // See also other potentially useful elements from arXiv Atom feeds:
    // (arXiv example: <http://export.arxiv.org/api/query?search_query=all:immunology&id_list=&start=0&max_results=30>)
    //
    // <author>
    //   <name>
    //     Margarita Voitikova
    //   </name>
    //   <arxiv:affiliation xmlns:arxiv="http://arxiv.org/schemas/atom">
    //     Institute of Molecular and Atomic Physics, National Academy of Sciences of Belarus
    //   </arxiv:affiliation>
    // </author>
    //
    // <arxiv:comment xmlns:arxiv="http://arxiv.org/schemas/atom">
    //   6 pages, 3 figures, submitted for publication
    // </arxiv:comment>
    //
    // <arxiv:journal_ref xmlns:arxiv="http://arxiv.org/schemas/atom">
    //   Theory in Biosciences, 123, 431 (2005)
    // </arxiv:journal_ref>
    //
    // <link title="doi" href="http://dx.doi.org/10.1016/j.physd.2005.03.004" rel="related" />
    return $entry;
}
示例#9
0
function oaidcRecord($row, $metadataPrefix = "oai_dc", $addNameSpaceInfo = true)
{
    global $databaseBaseURL;
    // these variables are defined in 'ini.inc.php'
    global $contentTypeCharset;
    global $fileVisibility;
    global $fileVisibilityException;
    global $filesBaseURL;
    global $convertExportDataToUTF8;
    global $defaultCiteStyle;
    global $citeStyle;
    global $alnum, $alpha, $cntrl, $dash, $digit, $graph, $lower, $print, $punct, $space, $upper, $word, $patternModifiers;
    // defined in 'transtab_unicode_charset.inc.php' and 'transtab_latin1_charset.inc.php'
    // The array '$transtab_refbase_unicode' contains search & replace patterns for conversion from refbase markup to Unicode entities.
    global $transtab_refbase_unicode;
    // defined in 'transtab_refbase_unicode.inc.php'
    // The array '$transtab_refbase_ascii' contains search & replace patterns for conversion from refbase markup to plain text.
    global $transtab_refbase_ascii;
    // defined in 'transtab_refbase_ascii.inc.php'
    // Define inline text markup to generate a plain text citation string:
    // (to be included within a 'dcterms:bibliographicCitation' element)
    $markupPatternsArrayPlain = array("bold-prefix" => "", "bold-suffix" => "", "italic-prefix" => "", "italic-suffix" => "", "underline-prefix" => "", "underline-suffix" => "", "endash" => "-", "emdash" => "-", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => '"', "double-quote-right" => '"', "single-quote" => "'", "single-quote-left" => "'", "single-quote-right" => "'", "less-than" => "<", "greater-than" => ">", "newline" => "\n");
    // 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:
    // (to be included within a 'dc:identifier' element)
    $citeKey = generateCiteKey($formVars);
    // function 'generateCiteKey()' is defined in 'include.inc.php'
    // Generate OpenURL data:
    // (to be included within a 'dc:identifier' element)
    $openURL = openURL($row, "openurl:");
    // function 'openURL()' is defined in 'openurl.inc.php'
    // Encode special chars and perform charset conversions:
    foreach ($row as $rowFieldName => $rowFieldValue) {
        // We only convert those special chars to entities which are supported by XML:
        // function 'encodeHTMLspecialchars()' is defined in 'include.inc.php'
        $row[$rowFieldName] = encodeHTMLspecialchars($row[$rowFieldName]);
        // Convert field data to UTF-8:
        // (if '$convertExportDataToUTF8' is set to "yes" in 'ini.inc.php' and character encoding is not UTF-8 already)
        // (Note that charset conversion can only be done *after* the cite key has been generated, otherwise cite key
        //  generation will produce garbled text!)
        // function 'convertToCharacterEncoding()' is defined in 'include.inc.php'
        if ($convertExportDataToUTF8 == "yes" and $contentTypeCharset != "UTF-8") {
            $row[$rowFieldName] = convertToCharacterEncoding("UTF-8", "IGNORE", $row[$rowFieldName]);
        }
    }
    // Defines field-specific search & replace 'actions' that will be applied to all those refbase fields that are listed in the corresponding 'fields' element:
    // (If you don't want to perform any search and replace actions, specify an empty array, like: '$fieldSpecificSearchReplaceActionsArray = array();'.
    //  Note that the search patterns MUST include the leading & trailing slashes -- which is done to allow for mode modifiers such as 'imsxU'.)
    //                                          "/Search Pattern/"  =>  "Replace Pattern"
    $fieldSpecificSearchReplaceActionsArray = array();
    if ($convertExportDataToUTF8 == "yes") {
        $fieldSpecificSearchReplaceActionsArray[] = array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_unicode);
    }
    // Apply field-specific search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$fieldSpecificSearchReplaceActionsArray':
    foreach ($fieldSpecificSearchReplaceActionsArray as $fieldActionsArray) {
        foreach ($row as $rowFieldName => $rowFieldValue) {
            if (in_array($rowFieldName, $fieldActionsArray['fields'])) {
                $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $rowFieldValue, true);
            }
        }
    }
    // function 'searchReplaceText()' is defined in 'include.inc.php'
    // Fetch the name of the citation style file that's associated with the style given in '$citeStyle':
    $citeStyleFile = getStyleFile($citeStyle);
    // function 'getStyleFile()' is defined in 'include.inc.php'
    if (empty($citeStyleFile)) {
        $citeStyle = $defaultCiteStyle;
        // if the given cite style could not be found, we'll use the default cite style which is defined by the '$defaultCiteStyle' variable in 'ini.inc.php'
        $citeStyleFile = getStyleFile($citeStyle);
    }
    // Include the found citation style file *once*:
    include_once "cite/" . $citeStyleFile;
    // Generate a proper citation for this record, ordering attributes according to the chosen output style & record type:
    // - Plain text version of citation string:
    $recordCitationPlain = citeRecord($row, $citeStyle, "", $markupPatternsArrayPlain, false);
    // function 'citeRecord()' is defined in the citation style file given in '$citeStyleFile' (which, in turn, must reside in the 'styles' directory of the refbase root directory)
    //   Convert any refbase markup that remains in the citation string (such as _italic_ or **bold**) to plain text:
    $recordCitationPlain = searchReplaceText($transtab_refbase_ascii, $recordCitationPlain, true);
    // Convert any remaining refbase markup in the 'title', 'keywords' & 'abstract' fields to plain text:
    $row['title'] = searchReplaceText($transtab_refbase_ascii, $row['title'], true);
    $row['keywords'] = searchReplaceText($transtab_refbase_ascii, $row['keywords'], true);
    $row['abstract'] = searchReplaceText($transtab_refbase_ascii, $row['abstract'], true);
    // Strip any " (ed)" or " (eds)" suffix from author/editor string:
    if (preg_match("/ *\\(eds?\\)\$/", $row['author'])) {
        $row['author'] = preg_replace("/[ \r\n]*\\(eds?\\)/i", "", $row['author']);
    }
    if (preg_match("/ *\\(eds?\\)\$/", $row['editor'])) {
        $row['editor'] = preg_replace("/[ \r\n]*\\(eds?\\)/i", "", $row['editor']);
    }
    // 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)
    //
    // TODO: - the URL-generating code should be made into a dedicated function (since it's shared with 'modsxml.inc.php' and 'atomxml.inc.php')
    $printURL = false;
    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]])) {
        if (!empty($row['file'])) {
            if (preg_match('#^(https?|ftp|file)://#i', $row['file'])) {
                $URLprefix = "";
                // we don't alter the URL given in the 'file' field
            } else {
                // 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;
                }
            }
            $printURL = true;
        }
    }
    // ----------------------------------------------------------
    // Start OAI_DC XML record:
    if (!empty($metadataPrefix)) {
        $recordPrefix = $metadataPrefix . ":";
    }
    $record = new XML($recordPrefix . "dc");
    // create an XML object for a single record
    if ($addNameSpaceInfo) {
        if ($metadataPrefix == "oai_dc") {
            $record->setTagAttribute("xmlns:oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
        } elseif ($metadataPrefix == "srw_dc") {
            $record->setTagAttribute("xmlns:srw_dc", "info:srw/schema/1/dc-v1.1");
        }
        $record->setTagAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
        if ($metadataPrefix == "oai_dc") {
            $record->setTagAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            $record->setTagAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
        } elseif ($metadataPrefix == "srw_dc") {
            $record->setTagAttribute("xmlns:prism", "http://prismstandard.org/namespaces/1.2/basic/");
        }
    }
    // Add Dublin Core elements:
    // NOTE: With a few exceptions, we try to adhere to the guidelines given at
    //       "Using simple Dublin Core to describe eprints" by Andy Powell et al.
    //       See: <http://eprints-uk.rdn.ac.uk/project/docs/simpledc-guidelines/>
    // - 'dc:title':
    if (!empty($row['title'])) {
        addMetaElement($record, "dc", "title", array(), $row['title']);
    }
    // function 'addMetaElement()' is defined in 'webservice.inc.php'
    // - 'dc:creator':
    if (!empty($row['author']) and $row['author'] != $row['editor']) {
        addMetaElement($record, "dc", "creator", array(), $row['author']);
    }
    // - 'dc:creator':
    //   TODO: add refbase corporate author(s) as 'dc:creator'
    // - 'dc:contributor':
    if (!empty($row['editor'])) {
        addMetaElement($record, "dc", "contributor", array(), $row['editor']);
    }
    // - 'dc:description':
    if (!empty($row['abstract'])) {
        addMetaElement($record, "dc", "description", array(), $row['abstract']);
    }
    // - 'dc:identifier':
    //   - DOI:
    if (!empty($row['doi'])) {
        addMetaElement($record, "dc", "identifier", array(), $row['doi'], "doi");
    }
    //   - PMID:
    if (!empty($row['notes']) and preg_match("/PMID *: *\\d+/i", $row['notes'])) {
        addMetaElement($record, "dc", "identifier", array(), $row['notes'], "pmid");
    }
    //   - arXiv:
    if (!empty($row['notes']) and preg_match("/arXiv *: *[^ ;]+/i", $row['notes'])) {
        addMetaElement($record, "dc", "identifier", array(), $row['notes'], "arxiv");
    }
    //   - ISBN:
    if (!empty($row['isbn'])) {
        addMetaElement($record, "dc", "identifier", array(), $row['isbn'], "isbn");
    }
    //   - OpenURL:
    addMetaElement($record, "dc", "identifier", array(), $openURL, "openurl");
    //   - refbase ID:
    addMetaElement($record, "dc", "identifier", array(), $databaseBaseURL . generateURL("show.php", "html", array("record" => $row['serial']), true), "url");
    //   - Cite key:
    addMetaElement($record, "dc", "identifier", array(), $citeKey, "citekey");
    //   - Bibliographic citation:
    //     NOTE: In 'atomxml.inc.php', the bibliographic citation is put into a
    //           'dcterms:bibliographicCitation' element so that it can be uniquely
    //           identified and extracted easily. However, in case of simple Dublin
    //           Core output, we just put it into a 'dc:identifier' element and
    //           use a "citation:" prefix.
    addMetaElement($record, "dc", "identifier", array(), encodeHTMLspecialchars($recordCitationPlain), "citation");
    // - 'dc:source':
    //   NOTE: - In <http://eprints-uk.rdn.ac.uk/project/docs/simpledc-guidelines/>,
    //           Andy Powell et al. recommend that this element should NOT be used!
    //           However, we use 'dc:source' elements for publication & series info
    //           (publication/series title plus volume & issue) to provide a dedicated
    //           source string that's easily readable and parsable.
    //           Example: <dc:source>Polar Biology, Vol. 25, No. 10</dc:source>
    //         - While we could also append the page info to the publication
    //           'dc:source' element, this info is more pertinent to the article
    //           itself and is thus not included. For 'srw_dc:dc' output, page info is
    //           included in PRISM elements (see below).
    //         - All metadata (including the page info) are also provided as a machine
    //           parsable citation in form of an OpenURL ContextObject (see above).
    //   - Publication info:
    //     NOTE: We only include the 'dc:source' element for 'oai_dc:dc' output. In case of 'srw_dc:dc'
    //           output, we use the more fine-grained PRISM elements instead (see below)
    if ($metadataPrefix == "oai_dc" and (!empty($row['publication']) or !empty($row['abbrev_journal']))) {
        if (!empty($row['publication'])) {
            $source = $row['publication'];
        } elseif (!empty($row['abbrev_journal'])) {
            $source = $row['abbrev_journal'];
        }
        if (!empty($row['volume'])) {
            $source .= ", Vol. " . $row['volume'];
        }
        if (!empty($row['issue'])) {
            $source .= ", No. " . $row['issue'];
        }
        if (!empty($source)) {
            addMetaElement($record, "dc", "source", array(), $source);
        }
    }
    //   - Series info:
    if (!empty($row['series_title']) or !empty($row['abbrev_series_title'])) {
        if (!empty($row['series_title'])) {
            $series = $row['series_title'];
        } elseif (!empty($row['abbrev_series_title'])) {
            $series = $row['abbrev_series_title'];
        }
        if (!empty($row['series_volume'])) {
            $series .= ", Vol. " . $row['series_volume'];
        }
        if (!empty($row['series_issue'])) {
            $series .= ", No. " . $row['series_issue'];
        }
        if (!empty($series)) {
            addMetaElement($record, "dc", "source", array(), $series);
        }
        // NOTE: To distinguish between regular publication & series info,
        //       should we better use a "series:" prefix here? If so, use:
        //				addMetaElement($record, "dc", "source", array(), $series, "series");
    }
    //   - ISSN:
    //     NOTE: for 'srw_dc:dc' output, we put the ISSN into the 'prism:issn' element
    if ($metadataPrefix == "oai_dc" and !empty($row['issn'])) {
        addMetaElement($record, "dc", "source", array(), $row['issn'], "issn");
    }
    // - 'dc:date':
    if (!empty($row['year'])) {
        addMetaElement($record, "dc", "date", array(), $row['year']);
    }
    // - 'dc:type':
    if (!empty($row['type'])) {
        addMetaElement($record, "dc", "type", array(), $row['type'], $row['thesis']);
    }
    //   In case of a thesis, we add another 'dc:type' element with the actual thesis type:
    if (!empty($row['thesis'])) {
        addMetaElement($record, "dc", "type", array(), $row['thesis']);
    }
    // - 'dc:format':
    //   TODO: ideally, we should parse the content of the refbase 'medium' field and map it
    //         to a media-type term from <http://www.iana.org/assignments/media-types/>
    if (!empty($row['medium'])) {
        $mediaType = $row['medium'];
    } else {
        $mediaType = "text";
    }
    addMetaElement($record, "dc", "format", array(), $mediaType);
    // - 'dc:subject':
    //   TODO: add user-specific keywords (from field 'user_keys') if the user is logged in
    if (!empty($row['keywords'])) {
        addMetaElement($record, "dc", "subject", array(), $row['keywords']);
    }
    // - 'dc:coverage':
    //   TODO: should we add contents from the refbase 'area' field as 'dc:coverage' element(s)?
    // - 'dc:relation':
    //   - Related URL:
    if (!empty($row['url'])) {
        addMetaElement($record, "dc", "relation", array(), $row['url'], "url");
    }
    //   - Related FILE:
    if ($printURL) {
        addMetaElement($record, "dc", "relation", array(), $URLprefix . $row['file'], "file");
    }
    // - 'dc:publisher':
    if (!empty($row['publisher'])) {
        addMetaElement($record, "dc", "publisher", array(), $row['publisher']);
    }
    // - 'dc:language':
    //   TODO: convert to ISO notation (i.e. "en" instead of "English", etc)
    if (!empty($row['language'])) {
        addMetaElement($record, "dc", "language", array(), $row['language']);
    }
    // ----------------------------------------------------------
    // Add PRISM elements:
    // NOTE: When using the 'srw_dc' namespace (i.e. 'info:srw/schema/1/dc-v1.1' as detailed at
    //       <http://www.loc.gov/standards/sru/resources/dc-schema.html>), I don't think it's allowed
    //       to include anything but the fifteen elements from simple Dublin Core. Is this correct?
    //       If so, then:
    //
    // TODO: Do we need to put the PRISM elements in <extraRecordData> instead? Or can we put them within
    //       a separate branch outside of (and next to) the '<srw_dc:dc>' element? Or shall we better omit
    //       them entirely?
    //       More info on SRU Extra Data>: <http://www.loc.gov/standards/sru/specs/extra-data.html>
    //
    //       See also "Mixing DC metadata with other metadata schemas" in "Guidelines for implementing
    //       Dublin Core in XML" <http://dublincore.org/documents/dc-xml-guidelines/>
    if ($metadataPrefix == "srw_dc") {
        // - 'prism:issn':
        if (!empty($row['issn'])) {
            addMetaElement($record, "prism", "issn", array(), $row['issn']);
        }
        // - 'prism:publicationName':
        if (!empty($row['publication'])) {
            addMetaElement($record, "prism", "publicationName", array(), $row['publication']);
        } elseif (!empty($row['abbrev_journal'])) {
            addMetaElement($record, "prism", "publicationName", array(), $row['abbrev_journal']);
        }
        // - 'prism:publicationDate':
        if (!empty($row['year'])) {
            addMetaElement($record, "prism", "publicationDate", array(), $row['year']);
        }
        // - 'prism:volume':
        if (!empty($row['volume'])) {
            addMetaElement($record, "prism", "volume", array(), $row['volume']);
        }
        // - 'prism:number':
        if (!empty($row['issue'])) {
            addMetaElement($record, "prism", "number", array(), $row['issue']);
        }
        // - 'prism:startingPage', 'prism:endingPage':
        //   TODO: Similar code is used in 'include.in.php', 'modsxml.inc.php' and 'openurl.inc.php',
        //         so this should be made into a dedicated function!
        if (!empty($row['pages']) and preg_match("/\\d+/i", $row['pages'])) {
            $pages = preg_replace("/^\\D*(\\d+)( *[{$dash}]+ *\\d+)?.*/i{$patternModifiers}", "\\1\\2", $row['pages']);
            // extract page range (if there's any), otherwise just the first number
            $startPage = preg_replace("/^\\D*(\\d+).*/i", "\\1", $row['pages']);
            // extract starting page
            $endPage = extractDetailsFromField("pages", $pages, "/\\D+/", "[-1]");
            // extract ending page (function 'extractDetailsFromField()' is defined in 'include.inc.php')
            // NOTE: To extract the ending page, we'll use function 'extractDetailsFromField()'
            //       instead of just grabbing a matched regex pattern since it'll also work
            //       when just a number but no range is given (e.g. when startPage = endPage)
            // - 'prism:startingPage':
            if (preg_match("/\\d+ *[{$dash}]+ *\\d+/i{$patternModifiers}", $row['pages'])) {
                // if there's a page range
                addMetaElement($record, "prism", "startingPage", array(), $startPage);
            }
            // - 'prism:endingPage':
            addMetaElement($record, "prism", "endingPage", array(), $endPage);
        }
    }
    return $record;
}