function contextObject($row) { global $databaseBaseURL; // defined in 'ini.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' // Defines search & replace 'actions' that will be applied 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)); 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'])) { // function 'searchReplaceText()' is defined in 'include.inc.php' $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $row[$rowFieldName], true); } } } $co = array(); // rfr_id $co["rfr_id"] = "info:sid/" . preg_replace("#http://#", "", $databaseBaseURL); // genre (type) if (isset($row['type'])) { if ($row['type'] == "Journal Article") { $co["rft.genre"] = "article"; } elseif ($row['type'] == "Book Chapter") { $co["rft.genre"] = "bookitem"; } elseif ($row['type'] == "Book Whole") { $co["rft.genre"] = "book"; } elseif ($row['type'] == "Conference Article") { $co["rft.genre"] = "proceeding"; } elseif ($row['type'] == "Conference Volume") { $co["rft.genre"] = "conference"; } elseif ($row['type'] == "Journal") { $co["rft.genre"] = "journal"; } elseif ($row['type'] == "Manuscript") { $co["rft.genre"] = "preprint"; } elseif ($row['type'] == "Report") { $co["rft.genre"] = "report"; } // "report" is only supported by OpenURL v1.0 (but not v0.1) } // atitle, btitle, title (title, publication) if ($row['type'] == "Journal Article" || $row['type'] == "Book Chapter") { if (!empty($row['title'])) { $co["rft.atitle"] = $row['title']; } if (!empty($row['publication'])) { $co["rft.title"] = $row['publication']; if ($row['type'] == "Book Chapter") { $co["rft.btitle"] = $row['publication']; } } } elseif (!empty($row['title'])) { $co["rft.title"] = $row['title']; } if ($row['type'] == "Book Whole" && !empty($row['title'])) { $co["rft.btitle"] = $row['title']; } // stitle (abbrev_journal) if (!empty($row['abbrev_journal'])) { $co["rft.stitle"] = $row['abbrev_journal']; if (empty($row['publication']) && !isset($co["rft.title"])) { // we duplicate the abbreviated journal name to 'rft.title' since the // CrossRef resolver seems to require 'rft.title' (otherwise it aborts // with an error: "No journal identifier supplied") $co["rft.title"] = $row['abbrev_journal']; } } // series (series_title) if (!empty($row['series_title'])) { $co["rft.series"] = $row['series_title']; } // issn if (!empty($row['issn'])) { $co["rft.issn"] = $row['issn']; } // isbn if (!empty($row['isbn'])) { $co["rft.isbn"] = $row['isbn']; } // date (year) if (!empty($row['year'])) { $co["rft.date"] = $row['year']; } // volume if (!empty($row['volume'])) { $co["rft.volume"] = $row['volume']; } // issue if (!empty($row['issue'])) { $co["rft.issue"] = $row['issue']; } // spage, epage, tpages (pages) // NOTE: lifted from modsxml.inc.php--should throw some into a new include file if (!empty($row['pages'])) { if (preg_match("/[0-9] *- *[0-9]/", $row['pages'])) { list($pagestart, $pageend) = preg_split('/\\s*[-]\\s*/', $row['pages']); if ($pagestart < $pageend) { $co["rft.spage"] = $pagestart; $co["rft.epage"] = $pageend; } } elseif ($row['type'] == "Book Whole") { $pagetotal = preg_replace('/^(\\d+)\\s*pp?\\.?$/', "\\1", $row['pages']); $co["rft.tpages"] = $pagetotal; } else { $co["rft.spage"] = $row['pages']; } } // aulast, aufirst, author (author) if (!empty($row['author'])) { $author = $row['author']; $aulast = extractAuthorsLastName("/ *; */", "/ *, */", 1, $author); $aufirst = extractAuthorsGivenName("/ *; */", "/ *, */", 1, $author); if (!empty($aulast)) { $co["rft.aulast"] = $aulast; } if (!empty($aufirst)) { $co["rft.aufirst"] = $aufirst; } // TODO: cleanup and put this function in include.inc.php? $authorcount = count(preg_split("/ *; */", $author)); for ($i = 0; $i < $authorcount - 1; $i++) { $aul = extractAuthorsLastName("/ *; */", "/ *, */", $i + 2, $author); $auf = extractAuthorsGivenName("/ *; */", "/ *, */", $i + 2, $author); if (!empty($aul)) { $au = $aul; if (!empty($auf)) { $au .= ", "; } } if (!empty($auf)) { $au .= $auf; } if (!empty($au)) { $co["rft.au" . $i] = $au; } } } // pub (publisher) if (!empty($row['publisher'])) { $co["rft.pub"] = $row['publisher']; } // place if (!empty($row['place'])) { $co["rft.place"] = $row['place']; } // id (doi, url) if (!empty($row['doi'])) { $co["rft_id"] = "info:doi/" . $row['doi']; } elseif (!empty($row['url'])) { $co["rft_id"] = $row['url']; } return $co; }
function renderRefbase($input, &$parser) { $hostName = "localhost"; $databaseName = "literature"; $username = "******"; $password = "******"; $tableRefs = "refs"; $databaseBaseURL = "http://" . $_SERVER['HTTP_HOST'] . "/refbase/"; $transtab_refbase_html = array("/__(?!_)(.+?)__/" => "<u>\\1</u>", "/_(.+?)_/" => "<i>\\1</i>", "/\\*\\*(.+?)\\*\\*/" => "<b>\\1</b>", "/\\[super:(.+?)\\]/i" => "<sup>\\1</sup>", "/\\[sub:(.+?)\\]/i" => "<sub>\\1</sub>", "/\\[permil\\]/" => "‰", "/\\[infinity\\]/" => "∞", "/\\[alpha\\]/" => "α", "/\\[beta\\]/" => "β", "/\\[gamma\\]/" => "γ", "/\\[delta\\]/" => "δ", "/\\[epsilon\\]/" => "ε", "/\\[zeta\\]/" => "ζ", "/\\[eta\\]/" => "η", "/\\[theta\\]/" => "θ", "/\\[iota\\]/" => "ι", "/\\[kappa\\]/" => "κ", "/\\[lambda\\]/" => "λ", "/\\[mu\\]/" => "μ", "/\\[nu\\]/" => "ν", "/\\[xi\\]/" => "ξ", "/\\[omicron\\]/" => "ο", "/\\[pi\\]/" => "π", "/\\[rho\\]/" => "ρ", "/\\[sigmaf\\]/" => "ς", "/\\[sigma\\]/" => "σ", "/\\[tau\\]/" => "τ", "/\\[upsilon\\]/" => "υ", "/\\[phi\\]/" => "φ", "/\\[chi\\]/" => "χ", "/\\[psi\\]/" => "ψ", "/\\[omega\\]/" => "ω", "/\\[Alpha\\]/" => "Α", "/\\[Beta\\]/" => "Β", "/\\[Gamma\\]/" => "Γ", "/\\[Delta\\]/" => "Δ", "/\\[Epsilon\\]/" => "Ε", "/\\[Zeta\\]/" => "Ζ", "/\\[Eta\\]/" => "Η", "/\\[Theta\\]/" => "Θ", "/\\[Iota\\]/" => "Ι", "/\\[Kappa\\]/" => "Κ", "/\\[Lambda\\]/" => "Λ", "/\\[Mu\\]/" => "Μ", "/\\[Nu\\]/" => "Ν", "/\\[Xi\\]/" => "Ξ", "/\\[Omicron\\]/" => "Ο", "/\\[Pi\\]/" => "Π", "/\\[Rho\\]/" => "Ρ", "/\\[Sigma\\]/" => "Σ", "/\\[Tau\\]/" => "Τ", "/\\[Upsilon\\]/" => "Υ", "/\\[Phi\\]/" => "Φ", "/\\[Chi\\]/" => "Χ", "/\\[Psi\\]/" => "Ψ", "/\\[Omega\\]/" => "Ω", "/(?:\"|")(.+?)(?:\"|")/" => "“\\1”", "/ +- +/" => " – "); $link = mysql_connect($hostName, $username, $password); if (!$link) { die("Couldn't connect to MySQL"); } mysql_select_db($databaseName, $link) or die("Couldn't open {$db}: " . mysql_error()); //select the new updated values $result = mysql_query("SELECT type, author, title, year, publication, volume, issue, pages, publisher, place, language, issn, doi FROM {$tableRefs} where serial={$input}") or die("SELECT Error: " . mysql_error()); $cite = ""; while ($row = mysql_fetch_array($result)) { if ($row["type"] == "Journal Article") { $cite .= "{{cite_journal|url={$databaseBaseURL}" . "show.php?record={$input}|"; if (!empty($row["author"])) { $author = $row["author"]; $aulast = extractAuthorsLastName(" *; *", " *, *", 1, $author); $aufirst = extractAuthorsGivenName(" *; *", " *, *", 1, $author); if (!empty($aulast)) { $cite .= "last=" . $aulast . "|"; } if (!empty($aufirst)) { $cite .= "first=" . $aufirst . "|"; if (!empty($aulast)) { $cite .= "authorlink={$aufirst} {$aulast}" . "|"; } } $authorcount = count(preg_split("/ *; */", $author)); $au = ""; for ($i = 0; $i < $authorcount - 1; $i++) { $aul = extractAuthorsLastName(" *; *", " *, *", $i + 2, $author); $auf = extractAuthorsGivenName(" *; *", " *, *", $i + 2, $author); if (!empty($aul)) { if (!empty($auf)) { $au .= "[[{$auf} {$aul}|{$aul}, {$auf}]]; "; } } } if (!empty($au)) { $cite .= "coauthors=" . trim($au, '; ') . "|"; } } if (!empty($row["year"])) { $cite .= "year=" . $row['year'] . "|"; } if (!empty($row["title"])) { $title = searchReplaceText($transtab_refbase_html, $row['title'], true); $cite .= "title=" . $title . "|"; } if (!empty($row["language"])) { $cite .= "language=" . $row['language'] . "|"; } if (!empty($row["publication"])) { $cite .= "journal=" . $row['publication'] . "|"; } if (!empty($row["volume"])) { $cite .= "volume=" . $row['volume'] . "|"; } if (!empty($row["issue"])) { $cite .= "issue=" . $row['issue'] . "|"; } if (!empty($row["pages"])) { $cite .= "pages=" . $row['pages'] . "|"; } if (!empty($row["place"])) { $cite .= "location=" . $row['place'] . "|"; } if (!empty($row["publiser"])) { $cite .= "publisher=" . $row['publisher'] . "|"; } if (!empty($row["issn"])) { $cite .= "issn=" . $row['issn'] . "|"; } if (!empty($row["doi"])) { $cite .= "doi=" . $row['doi'] . "|"; } $cite .= "}}"; } } global $wgParser; $output = $wgParser->recursiveTagParse($cite); return $output; }