From 58900ff73b43d3731b9b62ff24e77d7bc200cf1b Mon Sep 17 00:00:00 2001 From: Matthieu Guillaumin Date: Wed, 27 Feb 2013 15:21:44 +0100 Subject: [PATCH] fixes #2. the only limitation is LAYOUT=list works only with ABBRV_TYPE=index. --- bibtexbrowser.bibliography.php | 59 ++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/bibtexbrowser.bibliography.php b/bibtexbrowser.bibliography.php index 61040e6..bcd8a02 100644 --- a/bibtexbrowser.bibliography.php +++ b/bibtexbrowser.bibliography.php @@ -1,17 +1,20 @@ ?"; } return '' . $a . '' ; } @@ -20,34 +23,42 @@ function linkify($a) { */ function cite() { global $citations; + global $DB; $entries = func_get_args(); // list of bibtex entries $refs = array(); // corresponding references foreach ($entries as $entry) { - if ( array_key_exists ( $entry , $citations ) ) { - $ref = $citations[$entry] ; - } else { - $ref = count( $citations ) + 1 ; - $citations[$entry] = $ref ; - } - $refs[] = $ref; + $bib = $DB->getEntryByKey($entry); + if ( empty($bib) ) { + $ref = array(); // empty ref for detection by linkify, while getting last with sort() + $refs[] = $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 ; + } + } + $refs[] = $ref; } sort( $refs ); $links = array_map( 'linkify', $refs ); echo "[" . implode(",",$links) . "]" ; } -// prepare bibtexbrowser query -function make_bibtexbrowser_bibliography_keys() { - global $citations; - return json_encode(array_flip($citations)) ; -} - +// Function to print out the table/list of references function make_bibliography() { - global $_GET; + global $citations; + $bibfile = $_GET[Q_FILE]; // save bibfilename before resetting $_GET $_GET = array(); - $_GET['bib']='mg.bib'; - $_GET['bibliography']=1; // sets assoc_keys - $_GET['keys']=make_bibtexbrowser_bibliography_keys(); + $_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' ); }