/** * Extract the BibTeX data. * * @param string $data * @return array */ private function extract($data) { $data = trim($data) . "\n"; $parser = new \PARSEENTRIES(); $parser->expandMacro = true; $parser->removeDelimit = true; $parser->loadBibtexString($data); $parser->extractEntries(); $bibTeX = $parser->returnArrays(); $bibTeX = $bibTeX[2]; $length = count($bibTeX); $author = new \PARSECREATORS(); $date = new \PARSEMONTH(); $page = new \PARSEPAGE(); for ($i = 0; $i < $length; $i++) { if (isset($bibTeX[$i]['author']) == true) { $bibTeX[$i]['author'] = $author->parse($bibTeX[$i]['author']); } if (isset($bibTeX[$i]['editor']) == true) { $bibTeX[$i]['editor'] = $author->parse($bibTeX[$i]['editor']); } if (isset($bibTeX[$i]['month']) == true) { $bibTeX[$i]['month'] = $date->init($bibTeX[$i]['month']); } if (isset($bibTeX[$i]['pages']) == true && $bibTeX[$i]['pages'] != '' && preg_match('/^[0-9]+$/', $bibTeX[$i]['pages']) == 0) { $bibTeX[$i]['pages'] = $page->init($bibTeX[$i]['pages']); } } return $bibTeX; }
function bib_content() { $pathToOsbib = DOKU_PLUGIN . 'bibtex/OSBib/'; include_once $pathToOsbib . 'format/bibtexParse/PARSEENTRIES.php'; include_once $pathToOsbib . 'format/BIBFORMAT.php'; $data = parseBibFile($_REQUEST['file']); /* Get the bibtex entries into an associative array */ $parse = new PARSEENTRIES(); $parse->expandMacro = TRUE; $parse->fieldExtract = TRUE; $parse->removeDelimit = TRUE; $parse->loadBibtexString($data); $parse->extractEntries(); list($preamble, $strings, $entries) = $parse->returnArrays(); $ref = $_REQUEST['ref']; foreach ($entries as $entry) { if (trim($entry['bibtexCitation']) == $ref) { return rawOutput($entry); } } }
/** * Callback function that converts BibTeX text pasted into wiki into * an HTML table, which can then be imported by Exhibit using the * Exhibit Extension for Mediawiki. See Parse_Entries.php for proper credit to author. * @param {String} $input This is the text the user enters ino the wikitext input box. */ function bibtexToHTMLTable($input, $argv) { include "Parse_Entries.php"; try { if ($argv["file"]) { $file = $argv["file"]; if (preg_match("@^http://@", $file)) { // get a remote url via fopen $fp = @fopen($file, "r"); if ($fp) { $input .= stream_get_contents($fp); fclose($fp); } } else { // treat as an uploaded file on the wiki $image = new Image(Title::makeTitle(NS_IMAGE, $file)); if ($image->exists()) { $input .= file_get_contents($image->getImagePath()); } } } //Use the bibtex parser to get arrays from the bibtex in the <bibtex> tags. $parse = new PARSEENTRIES(); $parse->loadBibtexString($input); $parse->extractEntries(); list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays(); //Find all the fields in these bibtex entries: $fields = array(); foreach ($entries as $entry) { $thekeys = array_keys($entry); foreach ($thekeys as $key) { array_push($fields, $key); } } $fields = array_unique($fields); //Make sure bibtexCitation is first field, since it must be unique, makes //table look better. Find where it is now, and switch with what's there. reset($fields); $count = 0; while ($thekey = current($fields)) { if ($thekey == "bibtexCitation") { break; } else { $count++; next($fields); } } $tempval = $fields[0]; $fields[0] = "bibtexCitation"; $fields[$count] = $tempval; //Construct table header with these fields. $output = '<table id="bibtextable"><tr>'; foreach ($fields as $field) { if ($field == "bibtexCitation") { $output .= "\n<th ex:name=\"label\">{$field}</th>"; } else { $output .= "\n<th ex:name=\"{$field}\">{$field}</th>"; } } $output .= "</tr>\n"; //Fill in rest of table, with fields in right column. foreach ($entries as $entry) { $output .= "<tr>"; foreach ($fields as $field) { if (array_key_exists($field, $entry)) { if ($field == "author") { $entry[$field] = str_replace(" and ", " ; ", $entry[$field]); } $output .= "<td>{$entry[$field]}</td>"; } else { $output .= "<td></td>"; } } $output .= "</tr>\n"; } $output .= "</table>"; //Give a reasonable default lens. //$output .= '<div ex:role="exhibit-lens" ex:itemTypes="Publication" class="publication-lens" style="display: none"> <span ex:control="copy-button" class="copy-button"></span> <div><span class="publication-title" ex:content=".label"></span><i ex:if-exists=".venue"><span ex:content=".venue"></span>, </i> <i ex:if-exists=".event"><span ex:content=".event"></span>, </i> <span ex:content=".year"></span>. <span ex:if-exists=".status">(<span ex:content=".status"></span>)</span> </div> <div class="authors" ex:content=".author"></div> <div ex:if-exists=".abstract" class="abstract" ex:content=".abstract"></div> <div ex:if-exists=".excerpt" class="excerpt" ex:content=".excerpt"></div> <div class="downloads"> <a ex:if-exists=".url" ex:href-content=".url">[Source]</a> <a ex:if-exists=".talkURL" ex:href-content=".talkURL">[Talk Video]</a> <a ex:if-exists=".screencastURL" ex:href-content=".screencastURL">[Screencast <span ex:content=".screencastKB"></span> KB]</a> <a ex:if-exists=".pdfURL" ex:href-content=".pdfURL">[PDF <span ex:content=".pdfKB"></span> KB]</a> <a ex:if-exists=".pptURL" ex:href-content=".pptURL">[PowerPoint <span ex:content=".pptKB"></span> KB]</a> <a ex:if-exists=".psURL" ex:href-content=".psURL">[PS <span ex:content=".psKB"></span> KB]</a> </div> </div>'; $output .= '<div ex:role="exhibit-lens" style="display:none"> <div> <div style="font-size:120%; font-style:italic"> <span ex:content=".title"></span> </div> <div> Authors: <span ex:content=".author"></span>, <span ex:content=".year" style="font-size: 80%; font-weight:bold"></span>. </div> </div> <div><a ex:if-exists=".pdfurl" ex:href-content=".pdfurl">[PDF <span ex:content=".pdfkb"></span> KB]</a> </div>'; } catch (Exception $e) { $output = "Error in Bibtex"; } return $output; }
function execute($par) { global $wgOut; include "Parse_Entries.php"; #Don't want to output standard Wiki stuff, just want blank page. $wgOut->disable(); # If just Special:BibtexExport , explain what it is and die. if ($par == "") { echo "<h3>You haven't specified which wiki page you would like the BibTeX from.</h3>"; echo "<div style=\"width:33em\">"; echo "To grab the BibTeX between the <bibtex> and </bibtex> tags "; echo "in an article, simply visit Special:BibtexExport/Article_Name."; echo "<p>"; echo "To narrow it down you can append a query to the URL. For example, if you "; echo "wanted to get the bibtex for all the Haystack publications by David Huynh "; echo "in the year 2005, simply visit: <p>"; echo "<a href=\"http://simile.mit.edu/exhibited-wiki/Special:BibtexExport/Haystack?field:author=David%20Huynh&field:year=2005\">"; echo "http://simile.mit.edu/exhibited-wiki/Special:BibtexExport/Haystack?field:author=David%20Huynh&field:year=2005</a>"; echo "</div>"; die; } # Grab the article associated with the text past Special:BibtexExport. # e.g. Special:BibtexExport/Some_Article will grab all the data in the # Some_Article page. $title = Title::newFromURL($par); $article = new Article($title); $article->loadContent(); $text = $article->getContent(); # Try to get just the stuff in <bibtex> </bibtex> tags. $bibtexmatches = array(); $anything = Parser::extractTagsAndParams(array('bibtex'), $text, $bibtexmatches); # info stored in $bibtexmatches array, but key is randomly generated, so must # iterate through the *one* element in the array. # that in turn is an array, with the second key being the content foreach ($bibtexmatches as $match) { $bibtex = $match[1]; } # If there's a query string (e.g. Special:BibtexExport/Article?author=name) # we have more work to do. Otherwise, we're done. if (!$_SERVER['QUERY_STRING']) { echo "{$bibtex}"; } else { #Parse Bibtex $parse = new PARSEENTRIES(); $parse->loadBibtexString($bibtex); $parse->extractEntries(); list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays(); #filter by queries of form, e.g., ?field:author=Charles%20Darwin $queries = explode("&", $_SERVER['QUERY_STRING']); foreach ($queries as $query) { $survivingentries = array(); list($attr, $val) = explode("=", $query); $val = rawurldecode($val); $explodedattr = explode(":", $attr); if ($explodedattr[0] == "field") { # filter by some field $filterby = $explodedattr[1]; #Now we know what to filter by, let's go through the bibtex. foreach ($entries as $entry) { if ($filterby == "author") { $authorarray = explode(" and ", $entry['author']); if (in_array($val, $authorarray)) { $survivingentries[] = $entry; } } elseif ($entry[$filterby] == $val) { $survivingentries[] = $entry; } } } unset($entries); $entries = $survivingentries; unset($survivingentries); } #Surviving entries should now be in $entries. echo self::parsedEntriesToBibtex($entries); } exit; }