diff --git a/bibtexbrowser_bibliography.php b/bibtexbrowser.bibliography.php similarity index 55% rename from bibtexbrowser_bibliography.php rename to bibtexbrowser.bibliography.php index 8cdbc30..97902e2 100644 --- a/bibtexbrowser_bibliography.php +++ b/bibtexbrowser.bibliography.php @@ -1,5 +1,11 @@ $ref ) { + $keylist["$ref"] = $entry; // make sure keys are strings + } + return json_encode($keylist) ; +} + +function make_bibliography() { + global $_GET; + $_GET = array(); + $_GET['bib']='mg.bib'; + $_GET['bibliography']=1; + $_GET['keys']=make_bibtexbrowser_bibliography_keys(); + include( 'bibtexbrowser.php' ); } ?> diff --git a/bibtexbrowser.local.php b/bibtexbrowser.local.php index 3b45ff3..5e017a7 100644 --- a/bibtexbrowser.local.php +++ b/bibtexbrowser.local.php @@ -138,17 +138,13 @@ class BibliographyDisplay { /** Displays a set of bibtex entries in an HTML table */ function display() { - ksort($this->entries); //, ORDER_FUNCTION); + ksort($this->entries); // sort the keys, not the values layoutHeaderHTML(); - - $count = count($this->entries); - $i=0; foreach ($this->entries as $ref => $bib) { $bib->setIndex($ref); $bib->toHTML(); } // end foreach - layoutFooterHTML(); } // end function diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 8b549cd..e5d8c14 100644 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -100,12 +100,12 @@ define('BIBTEXBROWSER','v20130206'); @define('Q_ALL', 'all'); @define('Q_ENTRY', 'entry'); @define('Q_KEY', 'key'); -@define('Q_KEYS', 'keys'); // select entries using a list of bibtex entries +@define('Q_KEYS', 'keys'); // select entries using a JSON array of bibtex keys (if an associative array is used, the keys of this array are used as item abbrv) @define('Q_SEARCH', 'search'); -@define('Q_BIBLIOGRAPHY', 'bibliography'); // select entries and their index using a JSON associative array @define('Q_EXCLUDE', 'exclude'); @define('Q_RESULT', 'result'); @define('Q_ACADEMIC', 'academic'); +@define('Q_BIBLIOGRAPHY', 'bibliography'); @define('Q_DB', 'bibdb'); @define('Q_LATEST', 'latest'); @define('AUTHOR', 'author'); @@ -2999,23 +2999,25 @@ class BibDataBase { if (count($query)<1) {return array();} if (isset($query[Q_ALL])) return array_values($this->bibdb); - if (array_key_exists( Q_BIBLIOGRAPHY, $query )) { - $citations = array(); - foreach ($query[Q_BIBLIOGRAPHY] as $key => $value) { - $citations[$key] = $value; - } - } if (array_key_exists( Q_KEYS, $query )) { - $citations = array(); - foreach ($query[Q_KEYS] as $id => $key) { - $citations[] = $key; + $keylist = array(); + $is_assoc = (bool)count(array_filter(array_keys($query[Q_KEYS]), 'is_string')); + foreach ($query[Q_KEYS] as $ref => $key) { + if ($is_assoc) { + $keylist[$ref] = $key; + } else { + $keylist[] = $key; + } } + } else { + $is_assoc = false; } $result = array(); foreach ($this->bibdb as $bib) { $entryisselected = true; + $akey = -1; foreach ($query as $field => $fragment) { $field = strtolower($field); if ($field==Q_SEARCH) { @@ -3042,14 +3044,11 @@ class BibDataBase { break; } } - else if ($field==Q_BIBLIOGRAPHY) { - if ( !array_key_exists( $bib->getKey(), $citations ) ) { - $entryisselected = false; - break; - } - } else if ($field==Q_KEYS) { - if ( ! in_array( $bib->getKey(), $citations ) ) { + if ( ! in_array( $bib->getKey(), $keylist ) ) { + if ($is_assoc) { + $akey = array_search( $bib->getKey(), $keylist ); + } $entryisselected = false; break; } @@ -3063,9 +3062,7 @@ class BibDataBase { } if ($entryisselected) { - if ($field==Q_BIBLIOGRAPHY) { - $akey = $citations[$bib->getKey()]; - } else { + if ($akey<0) { $akey = count($result)+1; } $result[$akey] = $bib; @@ -3743,10 +3740,6 @@ class Dispatcher { function bibliography() { $this->displayer='BibliographyDisplay'; - if (preg_match('/utf-?8/i',ENCODING)) { - $_GET[Q_BIBLIOGRAPHY] = json_decode($_GET[Q_BIBLIOGRAPHY]); - } - $this->query[Q_BIBLIOGRAPHY]=$_GET[Q_BIBLIOGRAPHY]; } function layout() { $this->query[LAYOUT]=$_GET[LAYOUT]; } @@ -3754,7 +3747,7 @@ class Dispatcher { function keys() { if (preg_match('/utf-?8/i',ENCODING)) { // Create array from list of bibtex entries - $_GET[Q_KEYS] = array_filter(explode(',',strtr($_GET[Q_KEYS]," ",",")),'strlen'); + $_GET[Q_KEYS] = json_decode($_GET[Q_KEYS]); } $this->query[Q_KEYS]=$_GET[Q_KEYS]; }