Browse Source

introduced Q_ASSOCKEYS and improves Q_KEYS and Q_BIBLIOGRAPHY

pull/2/head
Matthieu Guillaumin 13 years ago
parent
commit
3abf3f0b9b
  1. 14
      bibtexbrowser.bibliography.php
  2. 14
      bibtexbrowser.local.php
  3. 41
      bibtexbrowser.php

14
bibtexbrowser.bibliography.php

@ -1,6 +1,7 @@
<?php
// TODO: improve by loading bibtexbrowser DB first, then cite() checks whether the entry is in the DB (prints "?" if not found). this also allows for non-numeric refs.
/* TODO: improve by loading bibtexbrowser DB first, then cite() checks whether the entry is in the DB (prints "?" if not found). this also allows for using other ABBRV than indices.
*/
@define('LAYOUT','list');
@define('USEBIBTHUMBNAIL',0);
@ -15,7 +16,7 @@ function linkify($a) {
}
// Create citations from bibtex entries. One argument per bibtex entry.
/* Example: As shown in <?php cite("MyBibtexEntry2013");?> , one can cite
/* Example: As shown in <?php cite("MyBibtexEntry2013","MyOtherRef2013");?> , 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' );
}

14
bibtexbrowser.local.php

@ -119,38 +119,30 @@ function MGBibliographyStyle(&$bibentry) {
$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);
}
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
?>

41
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<br/>\n";
$entryisselected = false;
break;
}
//echo $bib->getKey() . " in list<br/>\n";
}
else {
if (!$bib->hasPhrase($fragment, $field)) {
@ -3062,13 +3059,16 @@ class BibDataBase {
}
if ($entryisselected) {
if ($akey<0) {
$akey = count($result)+1;
if ( $is_assoc ) {
$result[$reflist[$bib->getKey()]] = $bib;
} else {
$result[] = $bib;
}
$result[$akey] = $bib;
} else {
//echo "entry ".$bib->getKey()." not selected\n";
}
}
//foreach ($result as $ref=>$bib) {echo $ref." => ".$bib->getKey()." ";}
return $result;
}
} // end class
@ -3740,6 +3740,7 @@ class Dispatcher {
function bibliography() {
$this->displayer='BibliographyDisplay';
$this->query[Q_ASSOCKEYS]=1;
}
function layout() { $this->query[LAYOUT]=$_GET[LAYOUT]; }
@ -3752,6 +3753,10 @@ class Dispatcher {
$this->query[Q_KEYS]=$_GET[Q_KEYS];
}
function assoc_keys() {
$this->query[Q_ASSOCKEYS]=$_GET[Q_ASSOCKEYS];
}
/** is used to remotely analyzed a situation */
function diagnosis() {
header('Content-type: text/plain');

Loading…
Cancel
Save