diff --git a/bibtexbrowser.bibliography.php b/bibtexbrowser.bibliography.php index 97902e2..61040e6 100644 --- a/bibtexbrowser.bibliography.php +++ b/bibtexbrowser.bibliography.php @@ -1,6 +1,7 @@ , one can cite +/* Example: As shown in , one can use bibtex within HTML/PHP. */ function cite() { global $citations; @@ -38,19 +39,16 @@ function cite() { // prepare bibtexbrowser query function make_bibtexbrowser_bibliography_keys() { global $citations; - $keylist = array(); - foreach ( $citation as $entry => $ref ) { - $keylist["$ref"] = $entry; // make sure keys are strings - } - return json_encode($keylist) ; + return json_encode(array_flip($citations)) ; } function make_bibliography() { global $_GET; $_GET = array(); $_GET['bib']='mg.bib'; - $_GET['bibliography']=1; + $_GET['bibliography']=1; // sets assoc_keys $_GET['keys']=make_bibtexbrowser_bibliography_keys(); + //print_r($_GET); include( 'bibtexbrowser.php' ); } diff --git a/bibtexbrowser.local.php b/bibtexbrowser.local.php index 5e017a7..1f68dbf 100644 --- a/bibtexbrowser.local.php +++ b/bibtexbrowser.local.php @@ -119,38 +119,30 @@ function MGBibliographyStyle(&$bibentry) { $result .= '
'; return $result; -} +} // end style function /** Class to display a bibliography of a page. */ class BibliographyDisplay { - function setDB(&$bibdatabase) { - $this->setEntries($bibdatabase->bibdb); - } + function setDB(&$bibdatabase) { $this->setEntries($bibdatabase->bibdb); } /** sets the entries to be shown */ - function setEntries(&$entries) { - $this->entries = $entries; - } + 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 - ?> diff --git a/bibtexbrowser.php b/bibtexbrowser.php index e5d8c14..2521ed5 100644 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -100,7 +100,8 @@ define('BIBTEXBROWSER','v20130206'); @define('Q_ALL', 'all'); @define('Q_ENTRY', 'entry'); @define('Q_KEY', 'key'); -@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_KEYS', 'keys'); // select entries using a JSON array of bibtex keys +@define('Q_ASSOCKEYS', 'assoc_keys'); // consider Q_KEYS as an associative array, and use the keys of Q_KEYS as item abbrv @define('Q_SEARCH', 'search'); @define('Q_EXCLUDE', 'exclude'); @define('Q_RESULT', 'result'); @@ -3000,24 +3001,21 @@ class BibDataBase { if (isset($query[Q_ALL])) return array_values($this->bibdb); if (array_key_exists( Q_KEYS, $query )) { - $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; - } - } + $keylist = (array) $query[Q_KEYS]; + $reflist = array_flip($keylist); + $is_assoc = array_key_exists( Q_ASSOCKEYS, $query ); //array_values($query[Q_KEYS]) !== $query[Q_KEYS]; + //if ($is_assoc) echo "Assoc"; + //print_r($keylist); } else { $is_assoc = false; } + unset($query[Q_ASSOCKEYS]); // not used for filtering the bibtex entries $result = array(); foreach ($this->bibdb as $bib) { $entryisselected = true; - $akey = -1; + $akey = ''; foreach ($query as $field => $fragment) { $field = strtolower($field); if ($field==Q_SEARCH) { @@ -3046,12 +3044,11 @@ class BibDataBase { } else if ($field==Q_KEYS) { if ( ! in_array( $bib->getKey(), $keylist ) ) { - if ($is_assoc) { - $akey = array_search( $bib->getKey(), $keylist ); - } + //echo $bib->getKey() . " not in list