diff --git a/bibtexbrowser.php b/bibtexbrowser.php
index 97d081f..413c995 100755
--- a/bibtexbrowser.php
+++ b/bibtexbrowser.php
@@ -18,6 +18,9 @@ Thanks to all [[#Users]] of bibtexbrowser :-)
=====Features=====
+* **New (02/2009)** bibtexbrowser can display all entries for an author with an academic style [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&academic=Martin+Monperrus|demo]]
+* **New (01/2009)** bibtexbrowser allows multi criteria search, e.g. ?type=inproceedings&year=2004
+* **HOT: bibtexbrowser can be used to include your publication list into your home page** [[http://www.monperrus.net/martin/|demo]]
* bibtexbrowser can display the menu and all entries without filtering from the $filename hardcoded in the script [[http://www.monperrus.net/martin/bibtexbrowser.php|demo]]
* bibtexbrowser can display the menu and all entries without filtering from the file name passed as parameter [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib|demo]]
* bibtexbrowser can display all entries out of a bibtex file [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&all|demo]]
@@ -25,19 +28,16 @@ Thanks to all [[#Users]] of bibtexbrowser :-)
* bibtexbrowser can display a single entry [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&key=monperrus08phd|demo]]
* bibtexbrowser can display all entries with a bib keyword [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&keywords=mda|demo]]
* bibtexbrowser can display found entries with a search word (it can be in any bib field) [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&search=ocl|demo]]
-* bibtexbrowser allows multi criteria search, e.g. ?type=inproceedings&year=2004
* bibtexbrowser outputs valid XHTML 1.0 Transitional
* bibtexbrowser in designed to be search engine friendly.
* bibtexbrowser can display all entries for an author [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&author=Barbara+A.+Kitchenham|demo]]
-* bibtexbrowser can display all entries for an author with an academic style [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&academic=Martin+Monperrus|demo]]
-* bibtexbrowser can be used to include your publication list into your home page [[http://www.monperrus.net/martin/|demo]]
* bibtexbrowser can be used with different encodings (change the default iso-8859-1 encoding if your bib file is in utf-8 ''define('ENCODING','utf-8')'' )
=====How to include your publication list in your home page=====
Use this PHP snippet:
<?php
-$_GET['bib']='mybib.bib';
+$_GET['bib']='mybib.bib';
$_GET['academic']='Martin Monperrus';
include('bibtexbrowser.php');
?>
@@ -152,11 +152,6 @@ define('YEAR', 'year');
// if future versions of PHP change warning mechanisms...
@error_reporting(E_ERROR);
-// we use sessions to avoid reparsing the bib file for each request
-// the session may be already started
-// by an external script that includes bibtexbrowser
-@session_start();
-
// default bib file, if no file is specified in the query string.
global $filename;
$filename = "biblio_monperrus.bib";
@@ -179,15 +174,41 @@ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && (strtotime($_SERVER['HTTP_IF_MO
}
-// parse a new bib file, if this file has not been already parsed
-if (!isset($_SESSION[$filename]) ) {
- // for sake of performance, once the bibtex file is parsed
- // the object that represents the database is stored in $_SESSION
- // we use serialize in order to be able to get a session correctly set up
- // without bibtexbrowser loaded in PHP
- $_SESSION[$filename] = serialize(new BibDataBase($filename));
+// for sake of performance, once the bibtex file is parsed
+// we try to save a "compiled" in a txt file
+$compiledbib = $filename.'.txt';
+// do we have a compiled version ?
+if (is_file($compiledbib) && is_readable($compiledbib)) {
+ // is it up to date ?
+ if (filemtime($filename)>filemtime($compiledbib)) {
+ // no, then reparse
+ $bibdb = new BibDataBase($filename);
+ }
+ else {
+ // yes then take it
+ $bibdb = unserialize(file_get_contents($compiledbib));
+ }
}
-$displaymanager=new DisplayManager(unserialize($_SESSION[$filename]));
+// we don't have a compiled version
+else {
+ // then parsing the file
+ $bibdb = new BibDataBase($filename);
+
+ // are we able to save the compiled version ?
+ if ((!is_file($compiledbib) && is_writable(dirname($compiledbib))) || (is_file($compiledbib) && is_writable($compiledbib)) ) {
+ // we can use file_put_contents
+ // but don't do it for compatibility with PHP 4.3
+ $f = fopen($compiledbib,'w');
+ fwrite($f,serialize(new BibDataBase($filename)));
+ fclose($f);
+ }
+}
+
+$displaymanager=new DisplayManager($bibdb);
+
+
+
+
////////////////////////////////////////////////////////
@@ -236,43 +257,43 @@ $isinentry = false;
$delegate->beginFile();
foreach($f as $s) {
-
+
if ($isinentry) $entrysource.=$s;
-
+
if ($state==NOTHING) {
// this is the beginning of an entry
- if ($s=='@') {
+ if ($s=='@') {
$delegate->beginEntry();
$state = GETTYPE;
$isinentry = true;
$entrysource='@';
}
}
-
+
else if ($state==GETTYPE) {
// this is the beginning of a key
- if ($s=='{') {
+ if ($s=='{') {
$state = GETKEY;
$delegate->setEntryType($entrytype);
$entrytype='';
}
else $entrytype=$entrytype.$s;
}
-
+
else if ($state==GETKEY) {
// now we get the value
- if ($s=='=') {
+ if ($s=='=') {
$state = GETVALUE;
$finalkey=$entrykey;
$entrykey='';}
// oups we only have the key :-) anyway
- else if ($s=='}') {
+ else if ($s=='}') {
$state = NOTHING;$isinentry = false;$delegate->endEntry($entrysource);
$delegate->setEntryKey($entrykey);
$entrykey='';
}
// OK now we look for values
- else if ($s==',') {
+ else if ($s==',') {
$state=GETKEY;
$delegate->setEntryKey($entrykey);
$entrykey='';}
@@ -281,13 +302,13 @@ foreach($f as $s) {
// we just got a =, we can now receive the value, but we don't now whether the value
// is delimited by curly brackets, double quotes or nothing
else if ($state==GETVALUE) {
-
+
// the value is delimited by double quotes
- if ($s=='"') {
+ if ($s=='"') {
$state = GETVALUEDELIMITEDBYQUOTES;
$entryvalue='';}
// the value is delimited by curly brackets
- else if ($s=='{') {
+ else if ($s=='{') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS;
$entryvalue='';}
// the end of the key and no value found: it is the bibtex key e.g. \cite{Descartes1637}
@@ -296,7 +317,7 @@ foreach($f as $s) {
$delegate->setEntryField(trim($finalkey),$entryvalue);
$entryvalue='';}
// this is the end of the value AND of the entry
- else if ($s=='}') {
+ else if ($s=='}') {
$state = NOTHING;$isinentry = false;
$delegate->setEntryField(trim($finalkey),$entryvalue);
$delegate->endEntry($entrysource);
@@ -307,13 +328,13 @@ foreach($f as $s) {
/* GETVALUEDELIMITEDBYCURLYBRACKETS* handle entries delimited by curly brackets and the possible nested curly brackets */
else if ($state==GETVALUEDELIMITEDBYCURLYBRACKETS) {
-
- if ($s=='\\') {
+
+ if ($s=='\\') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_ESCAPED;
$entryvalue=$entryvalue.$s;}
- else if ($s=='{') {
+ else if ($s=='{') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_1NESTEDLEVEL;}
- else if ($s=='}') {
+ else if ($s=='}') {
$state = GETVALUE;}
else { $entryvalue=$entryvalue.$s;}
}
@@ -324,12 +345,12 @@ foreach($f as $s) {
}
// in first level of curly bracket
else if ($state==GETVALUEDELIMITEDBYCURLYBRACKETS_1NESTEDLEVEL) {
- if ($s=='\\') {
+ if ($s=='\\') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_1NESTEDLEVEL_ESCAPED;
$entryvalue=$entryvalue.$s;}
- else if ($s=='{') {
+ else if ($s=='{') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_2NESTEDLEVEL;}
- else if ($s=='}') {
+ else if ($s=='}') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS;}
else { $entryvalue=$entryvalue.$s;}
}
@@ -338,15 +359,15 @@ foreach($f as $s) {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_1NESTEDLEVEL;
$entryvalue=$entryvalue.$s;
}
-
+
// in second level of curly bracket
else if ($state==GETVALUEDELIMITEDBYCURLYBRACKETS_2NESTEDLEVEL) {
- if ($s=='\\') {
+ if ($s=='\\') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_2NESTEDLEVEL_ESCAPED;
$entryvalue=$entryvalue.$s;}
- else if ($s=='{') {
+ else if ($s=='{') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_3NESTEDLEVEL;}
- else if ($s=='}') {
+ else if ($s=='}') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_1NESTEDLEVEL;}
else { $entryvalue=$entryvalue.$s;}
}
@@ -358,10 +379,10 @@ foreach($f as $s) {
// in third level of curly bracket
else if ($state==GETVALUEDELIMITEDBYCURLYBRACKETS_3NESTEDLEVEL) {
- if ($s=='\\') {
+ if ($s=='\\') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_3NESTEDLEVEL_ESCAPED;
$entryvalue=$entryvalue.$s;}
- else if ($s=='}') {
+ else if ($s=='}') {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_2NESTEDLEVEL;}
else { $entryvalue=$entryvalue.$s;}
}
@@ -373,10 +394,10 @@ foreach($f as $s) {
/* handles entries delimited by double quotes */
else if ($state==GETVALUEDELIMITEDBYQUOTES) {
- if ($s=='\\') {
+ if ($s=='\\') {
$state = GETVALUEDELIMITEDBYQUOTES_ESCAPED;
$inentryvaluedelimitedB=$inentryvaluedelimitedB.$s;}
- else if ($s=='"') {
+ else if ($s=='"') {
$state = GETVALUE;
$entryvalue=$entryvalue.$inentryvaluedelimitedB;
$inentryvaluedelimitedB='';}
@@ -396,30 +417,31 @@ $delegate->endFile();
/** This class can be used together with StateBasedBibParser */
class XMLPrettyPrinter {
function beginFile() {
- header('Content-type: text/xml;');
+ header('Content-type: text/xml;');
print '';
print '