From 531ebd0756df968bca3efc10c0b5eb6c2706e69d Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Wed, 5 Dec 2012 22:16:58 +0100 Subject: [PATCH] see http://www.monperrus.net/martin/bibtexbrowser-changelog --- bibtexbrowser.php | 114 +++++++++++++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 37 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index ae6a88e..45f7513 100644 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -1,5 +1,5 @@ + URL: http://www.monperrus.net/martin/bibtexbrowser/ Feedback & Bug Reports: martin.monperrus@gmail.com @@ -16,7 +16,7 @@ License, or (at your option) any later version. // added on Wednesday, June 01 2011, bug found by Carlos Bras if (!defined('BIBTEXBROWSER')) { // this if block ends at the very end of this file, after all class and function declarations. -define('BIBTEXBROWSER','v20121027'); +define('BIBTEXBROWSER','v20121205'); // *************** CONFIGURATION @@ -73,6 +73,12 @@ define('BIBTEXBROWSER','v20121027'); // suggested by Sascha Schnepp @define('BIBTEXBROWSER_BIBTEX_LINKS',true); +// should authors be linked to [none/homepage/resultpage] +// none: nothing +// their homepage if defined as @strings +// their publication lists according to this bibtex +@define('BIBTEXBROWSER_AUTHOR_LINKS','homepage'); + @define('BIBTEXBROWSER_DEBUG',false); @define('COMMA_NAMES',false);// do have authors in a comma separated form? @@ -227,15 +233,13 @@ function _zetDB($bibtex_filenames) { // we try to save a "compiled" in a txt file $compiledbib = 'bibtexbrowser_'.md5($bibtex_filenames).'.dat'; - $parse=filemtime(__FILE__)>filemtime($compiledbib); + $parse=filemtime(__FILE__)>@filemtime($compiledbib); - foreach(explode(MULTIPLE_BIB_SEPARATOR, $bibtex_filenames) as $bib) { // do we have a compiled version ? if (is_file($compiledbib) && is_readable($compiledbib) && filesize($compiledbib)>0 ) { - $f = fopen($compiledbib,'r'); //we use a lock to avoid that a call to bibbtexbrowser made while we write the object loads an incorrect object if (flock($f,LOCK_EX)) { @@ -253,7 +257,6 @@ function _zetDB($bibtex_filenames) { $parse=true; } } else {$parse=true;} - } // end for each // we don't have a compiled version if ($parse) { @@ -274,14 +277,14 @@ function _zetDB($bibtex_filenames) { // is it up to date ? wrt to the bib file and the script // then upgrading with a new version of bibtexbrowser triggers a new compilation of the bib file if (filemtime($bib)>filemtime($compiledbib) || filemtime(__FILE__)>filemtime($compiledbib)) { - //echo "updating..."; +// echo "updating ".$bib; $db->update($bib); $updated = true; } } - //echo var_export($parse); - //echo var_export($updated); +// echo var_export($parse); +// echo var_export($updated); $saved = false; // are we able to save the compiled version ? @@ -767,10 +770,16 @@ function xtrim($line) { It expects a **lower-case** char. */ function char2html($line,$latexmodifier,$char,$entitiyfragment) { - $line = str_replace('\\'.$latexmodifier.$char,'&'.$char.''.$entitiyfragment.';', $line); - $line = str_replace('\\'.$latexmodifier.'{'.$char.'}','&'.$char.''.$entitiyfragment.';', $line); - $line = str_replace('\\'.$latexmodifier.strtoupper($char),'&'.strtoupper($char).''.$entitiyfragment.';', $line); - $line = str_replace('\\'.$latexmodifier.'{'.strtoupper($char).'}','&'.strtoupper($char).''.$entitiyfragment.';', $line); + $line = char2html_case_sensitive($line,$latexmodifier,strtoupper($char),$entitiyfragment); + return char2html_case_sensitive($line,$latexmodifier,strtolower($char),$entitiyfragment); +} + +function char2html_case_sensitive($line,$latexmodifier,$char,$entitiyfragment) { +// old version +// $line = str_replace('\\'.$latexmodifier.$char,'&'.$char.''.$entitiyfragment.';', $line); +// $line = str_replace('\\'.$latexmodifier.' '.$char,'&'.$char.''.$entitiyfragment.';', $line); +// $line = str_replace('\\'.$latexmodifier.'{'.$char.'}','&'.$char.''.$entitiyfragment.';', $line); + $line = preg_replace('/\\\\'.preg_quote($latexmodifier,'/').' ?\\{?'.$char.'\\}?/','&'.$char.''.$entitiyfragment.';', $line); return $line; } @@ -834,6 +843,7 @@ function latex2html($line) { $line = char2html($line,'.','a',"ring"); $line = char2html($line,'c','c',"cedil"); + $line = char2html($line,'v','s',"caron"); $line = str_replace('\\ae','æ', $line); $line = str_replace('\\ss','ß', $line); @@ -902,6 +912,11 @@ class BibEntry { /** The index in a list of publications (e.g. [1] Foo */ var $index = ''; + /** returns a debug string representation */ + function __toString() { + return $this->getType()." ".$this->getKey(); + } + /** Creates an empty new bib entry. Each bib entry is assigned a unique * identification number. */ function BibEntry() { @@ -1110,18 +1125,35 @@ class BibEntry { */ function formattedAuthors() { return $this->getFormattedAuthorsImproved(); } - /** Adds to getFormattedAuthors() the home page links and returns a string (not an array) + /** Adds to getFormattedAuthors() the home page links and returns a string (not an array). Is configured with BIBTEXBROWSER_AUTHOR_LINKS and COMMA_NAMES. */ function getFormattedAuthorsImproved() { $array_authors = $this->getFormattedAuthors(); - foreach ($array_authors as $k => $author) { - $array_authors[$k]=$this->addHomepageLink($author); + + if (BIBTEXBROWSER_AUTHOR_LINKS=='homepage') { + foreach ($array_authors as $k => $author) { + $array_authors[$k]=$this->addHomepageLink($author); + } + } + + if (BIBTEXBROWSER_AUTHOR_LINKS=='resultpage') { + foreach ($array_authors as $k => $author) { + $array_authors[$k]=$this->addAuthorPageLink($author); + } } if (COMMA_NAMES) {$sep = '; ';} else {$sep = ', ';} + return implode($sep ,$array_authors); } + /** adds a link to the author page */ + function addAuthorPageLink($author) { + $link = makeHref(array(Q_AUTHOR => $author)); + return "$author"; + } + + /** Returns the authors of this entry as an array in a canonical form */ function getCanonicalAuthors() { $authors = array(); @@ -1186,8 +1218,7 @@ class BibEntry { if (COMMA_NAMES) {$sep = '; ';} else {$sep = ', ';} return implode($sep, $editors).', '.(count($editors)>1?'eds.':'ed.'); } - - + /** Returns the year of this entry? */ function getYear() { return $this->getField('year'); @@ -1637,7 +1668,6 @@ function DefaultBibliographyStyle(&$bibentry) { usage: Add the following line in "bibtexbrowser.local.php"
-include( 'bibtexbrowser-style-janos.php' );
 define('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle');
 
*/ @@ -1822,7 +1852,7 @@ class IndependentYearMenu { function poweredby() { $poweredby = "\n".'
'; $poweredby .= ''; - $poweredby .= 'Powered by bibtexbrowser'; + $poweredby .= 'Powered by bibtexbrowser'; $poweredby .= '
'."\n"; return $poweredby; } @@ -2106,11 +2136,11 @@ function query2title(&$query) { // and we remove the regexp modifiers ^ $ $v = preg_replace('/[$^]/','',$v); } - $headers[$k] = ucwords($k).': '.ucwords($v); + $headers[$k] = ucwords($k).': '.ucwords(htmlspecialchars($v)); } // special cases - if (isset($headers[Q_ALL])) $headers[Q_ALL] = 'Publications in '.$_GET[Q_FILE]; - if (isset($headers[Q_AUTHOR])) $headers[Q_AUTHOR] = 'Publications of '.$_GET[Q_AUTHOR]; + if (isset($headers[Q_ALL])) $headers[Q_ALL] = 'Publications in '.htmlspecialchars($_GET[Q_FILE]); + if (isset($headers[Q_AUTHOR])) $headers[Q_AUTHOR] = 'Publications of '.htmlspecialchars($_GET[Q_AUTHOR]); return join(' & ',$headers); } } @@ -2300,7 +2330,14 @@ function nonExistentBibEntryError() { exit; } - +/** handles queries with no result */ +class NotFoundDisplay { + function setTitle($title) { $this->title = $title; return $this; } + function getTitle() { return @$this->title ; } + function display() { + echo 'no result found, sorry.'; + } +} /** displays the publication records sorted by publication types (as configured by constant BIBLIOGRAPHYSECTIONS). usage:
@@ -2360,10 +2397,7 @@ class AcademicDisplay  {
 
     foreach (_DefaultBibliographySections() as $section) {
       $this->search2html($section['query'],$section['title']);
-    }
-
-    echo poweredby();
-    
+    }    
   }
 
 }
@@ -2425,7 +2459,6 @@ class BibEntryDisplay {
     echo '
'; //echo $this->display_old(); echo $this->displayOnSteroids(); - echo poweredby(); echo '
'; } @@ -2640,12 +2673,12 @@ class BibDataBase { $db->setData($empty_array, $this->stringdb); $db->build($filename); - $this->stringdb = $db->stringdb; + $this->stringdb = array_merge($this->stringdb, $db->stringdb); + $result = $db->builtdb; foreach ($result as $b) { - // new entries: if (!isset($this->bibdb[$b->getKey()])) { //echo 'adding...
'; @@ -2660,7 +2693,9 @@ class BibDataBase { // some entries have been removed foreach ($this->bibdb as $e) { - if (!isset($result[$e->getKey()])) { + if (!isset($result[$e->getKey()]) + && $e->filename==$filename // bug reported by Thomas on Dec 4 2012 + ) { //echo 'deleting...
'; unset($this->bibdb[$e->getKey()]); } @@ -2744,7 +2779,7 @@ class BibDataBase { $result = array(); foreach ($this->bibdb as $bib) { if (!$bib->hasField("keywords")) continue; - $tags =preg_split('/[,;]/', $bib->getField("keywords")); + $tags =preg_split('/[,;\\/]/', $bib->getField("keywords")); foreach($tags as $a){ $ta = trim($a); $result[$ta] = $ta; @@ -2983,7 +3018,7 @@ echo ' - + getRSS()!='') echo ''; ?> @@ -3023,6 +3058,7 @@ if (method_exists($content, 'getTitle')) { ?> display(); + echo poweredby(); if (BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT) { javascript(); @@ -3245,7 +3281,7 @@ class RSSDisplay { http:// - bibtexbrowser v20121027 + bibtexbrowser v20121205 entries as $bibentry) { @@ -3341,6 +3377,10 @@ class Dispatcher { $selectedEntries = $_GET[Q_DB]->multisearch($this->query); + if (count($selectedEntries)==0) { + $this->displayer = 'NotFoundDisplay'; + } + // default order uasort($selectedEntries, ORDER_FUNCTION); $selectedEntries = array_values($selectedEntries); @@ -3499,7 +3539,7 @@ class Dispatcher { function diagnosis() { header('Content-type: text/plain'); echo "php version: ".phpversion()."\n"; - echo "bibtexbrowser version: 20121027\n"; + echo "bibtexbrowser version: 20121205\n"; echo "dir: ".decoct(fileperms(dirname(__FILE__)))."\n"; echo "bibtex file: ".decoct(fileperms($_GET[Q_FILE]))."\n"; exit; @@ -3511,7 +3551,7 @@ class Dispatcher { - + You are browsing <?php echo $_GET[Q_FILE]; ?> with bibtexbrowser