
3 changed files with 529 additions and 52 deletions
@ -0,0 +1,84 @@ |
|||
<?php |
|||
|
|||
// Load the database without doing anything else
|
|||
function load_DB() { |
|||
$_GET['library']=1; |
|||
include( 'bibtexbrowser.php' ); |
|||
setDB(); |
|||
return $_GET[Q_DB]; |
|||
} |
|||
$DB = load_DB(); |
|||
|
|||
// Keep track of all citations and their reference numbers (order of appearance)
|
|||
$citations = array(); |
|||
|
|||
// Function to create a link for a bibtex entry
|
|||
function linkify($txt,$a) { |
|||
if ( empty($a) ) { return '<b><abbr title="'.$txt.'">?</abbr></b>'; } |
|||
return '<a href="#' . $a . '" class="bibreflink"><abbr title="'.$txt.'">' . $a . '</abbr></a>' ; |
|||
} |
|||
|
|||
// Create citations from bibtex entries. One argument per bibtex entry.
|
|||
/* Example: As shown in <?php cite("MyBibtexEntry2013","MyOtherRef2013");?> , one can use bibtex within HTML/PHP.
|
|||
*/ |
|||
function cite() { |
|||
global $citations; |
|||
global $DB; |
|||
$entries = func_get_args(); // list of bibtex entries
|
|||
$refs = array(); // corresponding references
|
|||
foreach ($entries as $entry) { |
|||
$bib = $DB->getEntryByKey($entry); |
|||
if ( empty($bib) ) { |
|||
$ref = array(); // empty ref for detection by linkify, while getting last with sort()
|
|||
$txt = "Unknown key «$entry»"; |
|||
$refs[$txt] = $ref; |
|||
continue; |
|||
} |
|||
if (ABBRV_TYPE != 'index') { |
|||
$ref = $bib->getAbbrv(); |
|||
$citations[$entry] = $ref; |
|||
} else { |
|||
if ( array_key_exists ( $entry , $citations ) ) { |
|||
$ref = $citations[$entry] ; |
|||
} else { |
|||
$ref = count( $citations ) + 1 ; |
|||
$citations[$entry] = $ref ; |
|||
} |
|||
} |
|||
$txt = $bib->getVeryCompactedAuthors() . ", «" . $bib->getTitle() . "», " . $bib->getYear() ; |
|||
$refs[$txt] = $ref; |
|||
} |
|||
asort( $refs ); |
|||
$links = array(); |
|||
foreach ( $refs as $txt => $ref ) { |
|||
$links[] = linkify($txt,$ref); |
|||
} |
|||
echo "[" . implode(",",$links) . "]" ; |
|||
} |
|||
|
|||
// Function to print out the table/list of references
|
|||
function make_bibliography() { |
|||
global $citations; |
|||
$bibfile = $_GET[Q_FILE]; // save bibfilename before resetting $_GET
|
|||
$_GET = array(); |
|||
$_GET['bib'] = $bibfile; |
|||
$_GET['bibliography'] = 1; // also sets $_GET['assoc_keys']=1
|
|||
$_GET['keys'] = json_encode(array_flip($citations)); |
|||
//print_r($_GET);
|
|||
include( 'bibtexbrowser.php' ); |
|||
?>
|
|||
<script type="text/javascript" ><!-- |
|||
updateCitation = function () { //detect hash change
|
|||
var hash = window.location.hash.slice(1); //hash to string
|
|||
$('.bibline').each(function() {$(this).removeClass("bibline-active");}); |
|||
if (hash) { |
|||
$('[name='+hash+']').parents('.bibline').each(function() {$(this).addClass("bibline-active");}); |
|||
} |
|||
}; |
|||
$(window).bind('hashchange',updateCitation); |
|||
updateCitation(); |
|||
--></script> |
|||
<?php |
|||
} |
|||
|
|||
?>
|
@ -0,0 +1,161 @@ |
|||
<?php |
|||
|
|||
// Add the 'thumbnail' option for rendering
|
|||
@define('USEBIBTHUMBNAIL',0); |
|||
@define('BIBTHUMBNAIL','thumbnail'); |
|||
|
|||
/** does nothing but calls method display() on the content and use javascript if needed. |
|||
*/ |
|||
class JsWrapper { |
|||
function JsWrapper(&$content) { |
|||
echo $content->display(); |
|||
if (BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT) { |
|||
javascript(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
function MGBibliographyStyle(&$bibentry) { |
|||
$title = $bibentry->getTitle(); |
|||
$type = $bibentry->getType(); |
|||
|
|||
// later on, all values of $entry will be joined by a comma
|
|||
$entry=array(); |
|||
|
|||
|
|||
// thumbnail
|
|||
if (USEBIBTHUMBNAIL && $bibentry->hasField(BIBTHUMBNAIL)) { |
|||
$thumb = '<img class="thumbnail" src="'.$bibentry->getField(BIBTHUMBNAIL).'" alt=""/>';} |
|||
else $thumb = ''; |
|||
|
|||
// title
|
|||
// usually in bold: .bibtitle { font-weight:bold; }
|
|||
$title = '<span class="bibtitle">'.$title.'</span><br/>'."\n"; |
|||
if ($bibentry->hasField('url')) $title = '<a'.(BIBTEXBROWSER_BIB_IN_NEW_WINDOW?' target="_blank" ':'').' href="'.$bibentry->getField("url").'">'.$title.'</a>'; |
|||
|
|||
|
|||
// author
|
|||
if ($bibentry->hasField('author')) { |
|||
$coreInfo = $title . '<span class="bibauthor">'.$bibentry->getFormattedAuthorsImproved().'</span>';} |
|||
else $coreInfo = $title; |
|||
|
|||
// core info usually contains title + author
|
|||
$entry[] = $thumb.$coreInfo; |
|||
|
|||
// now the book title
|
|||
$booktitle = ''; |
|||
if ($type=="inproceedings") { |
|||
$booktitle = 'In '.$bibentry->getField(BOOKTITLE); } |
|||
if ($type=="incollection") { |
|||
$booktitle = 'Chapter in '.$bibentry->getField(BOOKTITLE);} |
|||
if ($type=="inbook") { |
|||
$booktitle = 'Chapter in '.$bibentry->getField('chapter');} |
|||
if ($type=="article") { |
|||
$booktitle = 'In '.$bibentry->getField("journal");} |
|||
|
|||
//// we may add the editor names to the booktitle
|
|||
$editor=''; |
|||
if ($bibentry->hasField(EDITOR)) { |
|||
$editor = $bibentry->getFormattedEditors(); |
|||
} |
|||
if ($editor!='') $booktitle .=' ('.$editor.')'; |
|||
// end editor section
|
|||
|
|||
// is the booktitle available
|
|||
if ($booktitle!='') { |
|||
$entry[] = '<br/><span class="bibbooktitle">'.$booktitle.'</span>'; |
|||
} |
|||
|
|||
|
|||
$publisher=''; |
|||
if ($type=="phdthesis") { |
|||
$publisher = 'PhD thesis, '.$bibentry->getField(SCHOOL); |
|||
} |
|||
if ($type=="mastersthesis") { |
|||
$publisher = 'Master\'s thesis, '.$bibentry->getField(SCHOOL); |
|||
} |
|||
if ($type=="bachelorsthesis") { |
|||
$publisher = 'Bachelor\'s thesis, '.$bibentry->getField(SCHOOL); |
|||
} |
|||
if ($type=="techreport") { |
|||
$publisher = 'Technical report, '.$bibentry->getField("institution"); |
|||
} |
|||
|
|||
if ($type=="misc") { |
|||
$publisher = $bibentry->getField('howpublished'); |
|||
} |
|||
|
|||
if ($bibentry->hasField("publisher")) { |
|||
$publisher = $bibentry->getField("publisher"); |
|||
} |
|||
|
|||
if ($publisher!='') $entry[] = '<span class="bibpublisher">'.$publisher.'</span>'; |
|||
|
|||
|
|||
if ($bibentry->hasField('volume')) $entry[] = "volume ".$bibentry->getField("volume"); |
|||
|
|||
|
|||
if ($bibentry->hasField(YEAR)) $entry[] = $bibentry->getYear(); |
|||
|
|||
$result = implode(", ",$entry).'.'; |
|||
|
|||
// some comments (e.g. acceptance rate)?
|
|||
if ($bibentry->hasField('comment')) { |
|||
$result .= " (".$bibentry->getField("comment").")"; |
|||
} |
|||
if ($bibentry->hasField('note')) { |
|||
$result .= " (".$bibentry->getField("note").")"; |
|||
} |
|||
|
|||
// add the Coin URL
|
|||
//$result .= "\n".$bibentry->toCoins();
|
|||
$result .= "<br/>\n"; |
|||
|
|||
// we add biburl and title to be able to retrieve this important information
|
|||
// using Xpath expressions on the XHTML source
|
|||
$result .= $bibentry->getBibLink(); |
|||
// returns an empty string if no pdf present
|
|||
$result .= $bibentry->getLink('pdf'); |
|||
// returns an empty string if no url present
|
|||
$result .= $bibentry->getLink('url'); |
|||
// returns an empty string if no slides present
|
|||
$result .= $bibentry->getLink('slides'); |
|||
// returns an empty string if no poster present
|
|||
$result .= $bibentry->getLink('poster'); |
|||
// Google Scholar ID. empty string if no gsid present
|
|||
$result .= $bibentry->getGSLink(); |
|||
// returns an empty string if no doi present
|
|||
$result .= $bibentry->getDoiLink(); |
|||
|
|||
$result .= '<hr style="visibility: hidden; height:0; clear:both;"/>'; |
|||
|
|||
return $result; |
|||
} // end style function
|
|||
|
|||
/** Class to display a bibliography of a page. */ |
|||
class BibliographyDisplay { |
|||
function setDB(&$bibdatabase) { $this->setEntries($bibdatabase->bibdb); } |
|||
|
|||
/** sets the entries to be shown */ |
|||
function setEntries(&$entries) { $this->entries = $entries; } |
|||
|
|||
function setTitle($title) { $this->title = $title; return $this; } |
|||
function getTitle() { return @$this->title ; } |
|||
|
|||
/** Displays a set of bibtex entries in an HTML table */ |
|||
function display() { |
|||
ksort($this->entries); // sort the keys, not the values
|
|||
layoutHeaderHTML(); |
|||
foreach ($this->entries as $ref => $bib) { |
|||
$bib->setIndex($ref); |
|||
$bib->toHTML(); |
|||
} // end foreach
|
|||
layoutFooterHTML(); |
|||
} // end function
|
|||
} // end class
|
|||
|
|||
|
|||
|
|||
?>
|
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue