diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 333160b..ae6a88e 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,13 +16,15 @@ 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','v20120703'); +define('BIBTEXBROWSER','v20121027'); // *************** CONFIGURATION // I recommend to put your changes in bibtexbrowser.local.php // it will help you to upgrade the script with a new version -@include(dirname(__FILE__).'/bibtexbrowser.local.php'); +// the changes that require existing bibtexbrowser symbols should be in bibtexbrowser.after.php (included at the end of this file) +@include(preg_replace('/\.php$/','.local.php',__FILE__)); + // there is no encoding transformation from the bibtex file to the html file // if your bibtex file contains 8 bits characters in utf-8 // change the following parameter @@ -54,6 +56,10 @@ define('BIBTEXBROWSER','v20120703'); // Wrapper to use when we are included by another script @define('BIBTEXBROWSER_EMBEDDED_WRAPPER', 'NoWrapper'); + +// Wrapper to use when we are included by another script +@define('BIBTEXBROWSER_MAIN', 'Dispatcher'); + // default order functions @define('ORDER_FUNCTION','compare_bib_entry_by_year_and_month'); // can be @define('ORDER_FUNCTION','compare_bib_entry_by_title'); @@ -82,7 +88,7 @@ define('BIBTEXBROWSER','v20120703'); @define('Q_AUTHOR_PAGE', 'author_page'); @define('Q_TAG', 'keywords'); @define('Q_TAG_PAGE', 'keywords_page'); -@define('Q_TYPE', 'type'); +@define('Q_TYPE', 'type');// used for queries @define('Q_TYPE_PAGE', 'type_page'); @define('Q_ALL', 'all'); @define('Q_ENTRY', 'entry'); @@ -113,6 +119,9 @@ define('BIBTEXBROWSER','v20120703'); // *************** END CONFIGURATION +define('Q_INNER_AUTHOR', '_author');// internally used for representing the author +define('Q_INNER_TYPE', 'x-bibtex-type');// used for representing the type of the bibtex entry internally + // for clean search engine links // we disable url rewriting // ... and hope that your php configuration will accept one of these @@ -218,7 +227,8 @@ function _zetDB($bibtex_filenames) { // we try to save a "compiled" in a txt file $compiledbib = 'bibtexbrowser_'.md5($bibtex_filenames).'.dat'; - $parse=false; + $parse=filemtime(__FILE__)>filemtime($compiledbib); + foreach(explode(MULTIPLE_BIB_SEPARATOR, $bibtex_filenames) as $bib) { // do we have a compiled version ? if (is_file($compiledbib) @@ -699,13 +709,18 @@ class BibDBBuilder { // we add a timestamp $this->currentEntry->setTimestamp(); + // we add a key if there is no key + if (!$this->currentEntry->hasField(Q_KEY)) { + $this->currentEntry->setField(Q_KEY,md5($this->currentEntry->getTitle().implode('',$this->currentEntry->getRawAuthors()))); + } + // we set the fulltext $this->currentEntry->text = $entrysource; // we format the author names in a special field // to enable search if ($this->currentEntry->hasField('author')) { - $this->currentEntry->setField('_author',$this->currentEntry->getFormattedAuthorsImproved()); + $this->currentEntry->setField(Q_INNER_AUTHOR,$this->currentEntry->getFormattedAuthorsImproved()); } // ignoring jabref comments @@ -716,7 +731,7 @@ class BibDBBuilder { // we add it to the string database else if ($this->currentEntry->getType()=='string') { foreach($this->currentEntry->fields as $k => $v) { - $k!='type' and $this->stringdb[$k]=$v; + $k!=Q_INNER_TYPE and $this->stringdb[$k]=$v; } } @@ -913,12 +928,12 @@ class BibEntry { /** Returns the type of this bib entry. */ function getType() { // strtolower is important to be case-insensitive - return strtolower($this->getField(Q_TYPE)); + return strtolower($this->getField(Q_INNER_TYPE)); } /** Sets the key of this bib entry. */ function setKey($value) { - $this->setField('key',$value); + $this->setField(Q_KEY,$value); } /** Sets a field of this bib entry. */ @@ -944,7 +959,7 @@ class BibEntry { // to support space e.g. "@article {" // as generated by ams.org // thanks to Jacob Kellner - $this->fields[Q_TYPE] =trim($value); + $this->fields[Q_INNER_TYPE] =trim($value); } function setIndex($index) { $this->index = $index; } @@ -957,7 +972,7 @@ class BibEntry { } // echo $this->filename; // echo $this->getKey(); - return BIBTEXBROWSER_URL.'?'.createQueryString(array('key'=>$this->getKey(), Q_FILE=>$this->filename)); + return BIBTEXBROWSER_URL.'?'.createQueryString(array(Q_KEY=>$this->getKey(), Q_FILE=>$this->filename)); } /** Tries to build a good absolute URL for this entry */ @@ -1011,7 +1026,7 @@ class BibEntry { /** Returns the key of this entry */ function getKey() { - return $this->getField('key'); + return $this->getField(Q_KEY); } /** Returns the title of this entry? */ @@ -1081,7 +1096,7 @@ class BibEntry { } - /** Returns the authors as a string depending on the configuration parameter COMMA_NAMES */ + /** Returns the authors as an array of strings (one string per author) */ function getFormattedAuthors() { $authors = array(); foreach ($this->getRawAuthors() as $author) { @@ -1130,7 +1145,7 @@ class BibEntry { * all author names except for the first one and appending ", et al." */ function getCompactedAuthors($author){ - $authors = $this->getAuthors(); + $authors = $this->getRawAuthors(); $etal = count($authors) > 1 ? ', et al.' : ''; return $this->formatAuthor($authors[0]) . $etal; } @@ -1225,7 +1240,7 @@ class BibEntry { return $this->text; } - /** Returns true if this bib entry contains the given phrase + /** Returns true if this bib entry contains the given phrase (PREG regexp) * in the given field. if $field is null, all fields are considered. * Note that this method is NOT case sensitive */ function hasPhrase($phrase, $field = null) { @@ -1484,13 +1499,18 @@ return array( // Books array( - 'query' => array(Q_TYPE=>'book'), + 'query' => array(Q_TYPE=>'book|proceedings'), 'title' => 'Books' ), + // Book chapters + array( + 'query' => array(Q_TYPE=>'incollection|inbook'), + 'title' => 'Book Chapters' + ), // Journal / Bookchapters array( - 'query' => array(Q_TYPE=>'article|incollection'), - 'title' => 'Refereed Articles and Book Chapters' + 'query' => array(Q_TYPE=>'article'), + 'title' => 'Refereed Articles' ), // conference papers array( @@ -1730,7 +1750,9 @@ function createQueryString($array_param) { } // then a simple transformation and implode foreach ($array_param as $key => $val) { - if($key == '_author') { $key = 'author'; } + // the inverse transformation should also be implemented into query2title + if($key == Q_INNER_AUTHOR) { $key = Q_AUTHOR; } + if($key == Q_INNER_TYPE) { $key = Q_TYPE; } $array_param[$key]=$key .'='. urlencode($val); } return implode("&",$array_param); @@ -1800,7 +1822,7 @@ class IndependentYearMenu { function poweredby() { $poweredby = "\n".'
';print_r($selectedEntries);echo ''; + if ($this->displayer=='') { $this->displayer = BIBTEXBROWSER_DEFAULT_DISPLAY; } @@ -3309,13 +3355,14 @@ class Dispatcher { // do we have a displayer? if ($this->displayer!='') { - + $options = array(); if (isset($_GET['dopt'])) { $options = json_decode($_GET['dopt'],true); } // required for PHP4 to have this intermediate variable + $x = new $this->displayer(); if (method_exists($x,'setEntries')) { @@ -3330,10 +3377,6 @@ class Dispatcher { $x->setQuery($this->query); } - if (method_exists($x,'setWrapper')) { - $x->setWrapper($this); - } - // should call method display() on $x new $this->wrapper($x); @@ -3397,17 +3440,12 @@ class Dispatcher { function author() { // Friday, October 29 2010 - // changed fomr 'author' to '_author' - // because '_author' is already formatted - // doing so we can search at the same time "Joe Dupont" an "Dupont, Joe" - $this->query['_author']=$_GET[Q_AUTHOR]; + // changed from 'author' to '_author' + // in order to search at the same time "Joe Dupont" an "Dupont, Joe" + $this->query[Q_INNER_AUTHOR]=$_GET[Q_AUTHOR]; } function type() { - // remarks KEN - // "book" selects inbook, book, bookchapter - // so we add the regexp modifiers - if (strlen($_GET[Q_TYPE])>0 && !preg_match('/^\^.*\$$/',$_GET[Q_TYPE])) { $_GET[Q_TYPE] = '^'.$_GET[Q_TYPE].'$'; } $this->query[Q_TYPE]= $_GET[Q_TYPE]; } @@ -3461,7 +3499,7 @@ class Dispatcher { function diagnosis() { header('Content-type: text/plain'); echo "php version: ".phpversion()."\n"; - echo "bibtexbrowser version: 20120703\n"; + echo "bibtexbrowser version: 20121027\n"; echo "dir: ".decoct(fileperms(dirname(__FILE__)))."\n"; echo "bibtex file: ".decoct(fileperms($_GET[Q_FILE]))."\n"; exit; @@ -3473,7 +3511,7 @@ class Dispatcher { - +