From 8d28126de4a323145172ef5399404ceb2445fb0b Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Sat, 9 Mar 2013 23:42:06 +0100 Subject: [PATCH 1/4] changed the version number to __GITHUB__ (the github version is not a release) --- bibtexbrowser.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 45f7513..991e590 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','v20121205'); +define('BIBTEXBROWSER','v__GITHUB__'); // *************** CONFIGURATION @@ -138,7 +138,7 @@ define('Q_INNER_TYPE', 'x-bibtex-type');// used for representing the type of the // we ensure that the pages won't get polluted // if future versions of PHP change warning mechanisms... -@error_reporting(E_ERROR); +@error_reporting(/*pp4php:serl*/E_ALL/*lres*/); /** parses $_GET[Q_FILE] and puts the result (an object of type BibDataBase) in $_GET[Q_DB]. @@ -1852,7 +1852,7 @@ class IndependentYearMenu { function poweredby() { $poweredby = "\n".'
'; $poweredby .= ''; - $poweredby .= 'Powered by bibtexbrowser'; + $poweredby .= 'Powered by bibtexbrowser'; $poweredby .= '
'."\n"; return $poweredby; } @@ -3018,7 +3018,7 @@ echo ' - + getRSS()!='') echo ''; ?> @@ -3281,7 +3281,7 @@ class RSSDisplay { http:// - bibtexbrowser v20121205 + bibtexbrowser v__GITHUB__ entries as $bibentry) { @@ -3539,7 +3539,7 @@ class Dispatcher { function diagnosis() { header('Content-type: text/plain'); echo "php version: ".phpversion()."\n"; - echo "bibtexbrowser version: 20121205\n"; + echo "bibtexbrowser version: __GITHUB__\n"; echo "dir: ".decoct(fileperms(dirname(__FILE__)))."\n"; echo "bibtex file: ".decoct(fileperms($_GET[Q_FILE]))."\n"; exit; @@ -3551,7 +3551,7 @@ class Dispatcher { - + You are browsing <?php echo $_GET[Q_FILE]; ?> with bibtexbrowser From bf49236033d20ceb0ea258a62ccc6e8026cd32a8 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Sat, 9 Mar 2013 23:45:11 +0100 Subject: [PATCH 2/4] fixed a spurious 'notice' when used as library --- bibtexbrowser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 bibtexbrowser.php diff --git a/bibtexbrowser.php b/bibtexbrowser.php old mode 100644 new mode 100755 index 991e590..e043ccb --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -1379,7 +1379,7 @@ class BibEntry { // referrer, the id pf a collection of objects // see also http://www.openurl.info/registry/docs/pdf/info-sid.pdf - $url_parts[]='rfr_id='.s3988('info:sid/'.$_SERVER['HTTP_HOST'].':'.@$_GET[Q_FILE]); + $url_parts[]='rfr_id='.s3988('info:sid/'.@$_SERVER['HTTP_HOST'].':'.@$_GET[Q_FILE]); $url_parts[]='rft.date='.s3988($this->getYear()); From f9b2f7a62a715bd28c40ce636ee6fe8f1cf5141b Mon Sep 17 00:00:00 2001 From: Matthieu Guillaumin Date: Sun, 10 Mar 2013 09:44:10 +0100 Subject: [PATCH 3/4] added a LAYOUT option use @define(LAYOUT,{'table','list','deflist'}) to choose between table, ul, ol ('list' and ABBRV_TYPE='index') and definition lists for displaying bibtex entries. $bib->index is now displayed as a number, not a number in brackets, for compatibility with list values. however this is invisible to the user because the brackets are added in getAbbrv(). bib2html now includes the echoing of links. --- bibtexbrowser.php | 179 +++++++++++++++++++++++++++++++--------------- 1 file changed, 123 insertions(+), 56 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index e043ccb..c8922b6 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -3,6 +3,7 @@ URL: http://www.monperrus.net/martin/bibtexbrowser/ Feedback & Bug Reports: martin.monperrus@gmail.com +(C) 2013 Matthieu Guillaumin (C) 2006-2012 Martin Monperrus (C) 2005-2006 The University of Texas at El Paso / Joel Garcia, Leonardo Ruiz, and Yoonsik Cheon This program is free software; you can redistribute it and/or @@ -117,6 +118,8 @@ define('BIBTEXBROWSER','v__GITHUB__'); @define('METADATA_DC',true); @define('METADATA_EPRINTS',false); +@define('LAYOUT','table'); // may be table/list/deflist. defines the HTML rendering options (,
    /
      ,
      , resp.). 'list' only works with 'ABBRV_TYPE'='index' (ordered list) and 'none' (unordered list, the default if another choice than 'list' is made). + // in embedded mode, we still need a URL for displaying bibtex entries alone // this is usually resolved to bibtexbrowser.php // but can be overridden in bibtexbrowser.local.php @@ -240,7 +243,7 @@ function _zetDB($bibtex_filenames) { && is_readable($compiledbib) && filesize($compiledbib)>0 ) { - $f = fopen($compiledbib,'r'); + $f = fopen($compiledbib,'r+'); // my Unix seems to consider flock as a writing operation //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)) { $s = filesize($compiledbib); @@ -1243,21 +1246,29 @@ class BibEntry { } /** Returns the abbreviation. */ - function getAbbrv() { + function getRawAbbrv() { if (ABBRV_TYPE == 'index') return $this->index; if (ABBRV_TYPE == 'none') return ''; - if (ABBRV_TYPE == 'key') return '['.$this->getKey().']'; - if (ABBRV_TYPE == 'year') return '['.$this->getYear().']'; + if (ABBRV_TYPE == 'key') return $this->getKey(); + if (ABBRV_TYPE == 'year') return $this->getYear(); if (ABBRV_TYPE == 'x-abbrv') { if ($this->hasField('x-abbrv')) {return $this->getField('x-abbrv');} return $this->abbrv; } - // otherwise it is a user-defined function in bibtexbrowser.local.php $f = ABBRV_TYPE; return $f($this); } + /** Returns the abbreviation. */ + function getAbbrv() { + $abbrv = $this->getRawAbbrv(); + if ( ABBRV_TYPE == 'key' || ABBRV_TYPE == 'year' || ( ABBRV_TYPE == 'index' && LAYOUT != 'list' ) ) { + $abbrv = '['.$abbrv.']'; + } + return $abbrv; + } + /** Sets the abbreviation (e.g. [OOPSLA] or [1]) */ function setAbbrv($abbrv) { @@ -1296,37 +1307,45 @@ class BibEntry { } - /** Outputs an HTML line (
)with two TDS inside - */ - function toTR() { - echo ''; - echo ' '; - echo ''; + break; + case 'deflist': + echo ''; + break; + } + } - if ($this->hasField('doi')) { - echo ' [doi]'; - } - - // Google Scholar ID - if ($this->hasField('gsid')) { - echo ' [cites]'; - } - echo "\n"; + /** Create the entry anchor */ + function anchor() { + echo ''; } /** Outputs an coins URL: see http://ocoins.info/cobg.html @@ -1436,12 +1455,63 @@ class BibEntry { } +function layoutHeaderHTML() { + $tag = ''; + switch(LAYOUT) { /* switch for different layouts */ + case 'list': + if (ABBRV_TYPE=='index') { + $tag='ol'; + } else { // assume none + $tag='ul'; + } + break; + case 'table': + $tag = 'table'; + break; + case 'deflist': + $tag = 'div'; + break; + default: + die('Unknown LAYOUT'); + } + echo '<' . $tag . ' class="result">'; + return $tag; +} + +function layoutFooterHTML($tag) { + echo ''; +} + /** this function encapsulates the user-defined name for bib to HTML*/ function bib2html(&$bibentry) { $function = BIBLIOGRAPHYSTYLE; return $function($bibentry); } +function bib2links(&$bibentry) { + $href = 'href="'.$bibentry->getURL().'"'; + + if (BIBTEXBROWSER_BIBTEX_LINKS) { + // we add biburl and title to be able to retrieve this important information + // using Xpath expressions on the XHTML source + $str .= " getKey()."\" {$href}>[bibtex]"; + } + + // returns an empty string if no url present + $str .= $bibentry->getUrlLink(); + + if ($bibentry->hasField('doi')) { + $str .= ' [doi]'; + } + + // Google Scholar ID + if ($bibentry->hasField('gsid')) { + $str .= ' [cites]'; + } + + return $str; +} + /** encapsulates the user-defined sections. @nodoc */ function _DefaultBibliographySections() { $function = BIBLIOGRAPHYSECTIONS; @@ -2301,21 +2371,19 @@ class SimpleDisplay { echo 'Options: '.@implode(',',$this->options).'
'; } - ?> + $tag = layoutHeaderHTML(); -
'; - //echo ''; - - echo $this->getAbbrv().''; - echo bib2html($this); - - $href = 'href="'.$this->getURL().'"'; - - if (BIBTEXBROWSER_BIBTEX_LINKS) { - // we add biburl and title to be able to retrieve this important information - // using Xpath expressions on the XHTML source - echo " getKey()."\" {$href}>[bibtex]"; - } - - // returns an empty string if no url present - echo $this->getUrlLink(); + /** Outputs HTML line according to layout */ + function toHTML() { + switch(LAYOUT) { // open row + case 'list': + echo '
  • '; + break; + case 'table': + echo '
  • '; + break; + case 'deflist': + echo '
    '; break; + } + $this->anchor(); + switch(LAYOUT) { // close bibref and open bibitem + case 'table': + echo $this->getAbbrv().'
    '; + break; + case 'deflist': + echo $this->getAbbrv().'
    '; + break; + } + echo bib2html($this); + echo bib2links($this); + switch(LAYOUT) { // close row + case 'list': + echo ''; + break; + case 'table': + echo '
    - entries); $i=0; foreach ($this->entries as $bib) { - // by default, index are in decrasing order + // by default, index are in decreasing order // so that when you add a publicaton recent , the indices of preceding publications don't change - $bib->setIndex('['.($count-($i++)).']'); - $bib->toTR(); + $bib->setIndex($count-($i++)); + $bib->toHTML(); } // end foreach - ?> -
    - 0) { echo "\n".'
    '.$title.'
    '."\n"; - echo ''."\n"; + $tag = layoutHeaderHTML(); - // by default the abbreviation is incermented over all - // searches + // by default the abbreviation is incremented over all searches // since we don't know before hand all section, we can not index in decreasing order static $count; if ($count == NULL) { $count = 1; } // init $id = $count; foreach ($entries as $bib) { - $bib->setIndex('['.($id++).']'); - $bib->toTR(); + $bib->setIndex($id++); + $bib->toHTML(); } // end foreach $count = @$count + count($entries); - echo '
    '; + layoutFooterHTML($tag); } } @@ -2397,7 +2464,7 @@ class AcademicDisplay { foreach (_DefaultBibliographySections() as $section) { $this->search2html($section['query'],$section['title']); - } + } } } @@ -3176,18 +3243,18 @@ class PagedDisplay { } $this->menu($less, $more); - echo ''; + $tag = layoutHeaderHTML(); for ($i = 0; $i < PAGE_SIZE; $i++) { $index = ($this->page-1)*PAGE_SIZE + $i; if (isset($this->entries[$index])) { $bib = $this->entries[$index]; - $bib->toTR(); + $bib->toHTML(); } else { //break; } } // end foreach - echo '
    '; + layoutFooterHTML($tag); $this->menu($less, $more); } @@ -3478,7 +3545,7 @@ class Dispatcher { function keywords() { $this->query[Q_TAG]=$_GET[Q_TAG]; } - function author() { + function author() { // Friday, October 29 2010 // changed from 'author' to '_author' // in order to search at the same time "Joe Dupont" an "Dupont, Joe" @@ -3573,4 +3640,4 @@ class Dispatcher { $class = BIBTEXBROWSER_MAIN;// extension point $main = new $class(); $main->main(); -?> \ No newline at end of file +?> From 2d3f27015dbe2cb002a5cfc33dba73850909960d Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Sun, 10 Mar 2013 09:48:36 +0100 Subject: [PATCH 4/4] refactored the excellent commit of M. Guillaumin - LAYOUT -> BIBTEXBROWSER_LAYOUT by convention - BIBTEXBROWSER_LAYOUT has non-abbreviated values (for sake of intuitiveness) - BIBTEXBROWSER_LAYOUT has no complex interplay with ABBRV_TYPE (for sake of intuitiveness) - ordered lists are responsible for the indices - no new line at the end of the file - renamed or moved some functions --- bibtexbrowser.php | 205 ++++++++++++++++++++++++++-------------------- 1 file changed, 114 insertions(+), 91 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index c8922b6..1fa4e5b 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -4,7 +4,7 @@ URL: http://www.monperrus.net/martin/bibtexbrowser/ Feedback & Bug Reports: martin.monperrus@gmail.com (C) 2013 Matthieu Guillaumin -(C) 2006-2012 Martin Monperrus +(C) 2006-2013 Martin Monperrus (C) 2005-2006 The University of Texas at El Paso / Joel Garcia, Leonardo Ruiz, and Yoonsik Cheon This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -80,6 +80,12 @@ define('BIBTEXBROWSER','v__GITHUB__'); // their publication lists according to this bibtex @define('BIBTEXBROWSER_AUTHOR_LINKS','homepage'); +// BIBTEXBROWSER_LAYOUT defines the HTML rendering layout of the produced HTML +// may be table/list/ordered_list/definition (for ,
      ,
      resp.). +// for list/ordered_list, the abbrevations are not taken into account (see ABBRV_TYPE) +// for ordered_list, the index is given by HTML directly (in increasing order) +@define('BIBTEXBROWSER_LAYOUT','table'); + @define('BIBTEXBROWSER_DEBUG',false); @define('COMMA_NAMES',false);// do have authors in a comma separated form? @@ -118,8 +124,6 @@ define('BIBTEXBROWSER','v__GITHUB__'); @define('METADATA_DC',true); @define('METADATA_EPRINTS',false); -@define('LAYOUT','table'); // may be table/list/deflist. defines the HTML rendering options (
    ,
      /
        ,
        , resp.). 'list' only works with 'ABBRV_TYPE'='index' (ordered list) and 'none' (unordered list, the default if another choice than 'list' is made). - // in embedded mode, we still need a URL for displaying bibtex entries alone // this is usually resolved to bibtexbrowser.php // but can be overridden in bibtexbrowser.local.php @@ -243,7 +247,7 @@ function _zetDB($bibtex_filenames) { && is_readable($compiledbib) && filesize($compiledbib)>0 ) { - $f = fopen($compiledbib,'r+'); // my Unix seems to consider flock as a writing operation + $f = fopen($compiledbib,'r+'); // some Unix seem to consider flock as a writing operation //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)) { $s = filesize($compiledbib); @@ -1245,7 +1249,7 @@ class BibEntry { return $this->fields; } - /** Returns the abbreviation. */ + /** Returns the raw, undecorated abbreviation depending on ABBRV_TYPE. */ function getRawAbbrv() { if (ABBRV_TYPE == 'index') return $this->index; if (ABBRV_TYPE == 'none') return ''; @@ -1260,10 +1264,10 @@ class BibEntry { return $f($this); } - /** Returns the abbreviation. */ + /** Returns the abbreviation, etc [1] if ABBRV_TYPE='index'. */ function getAbbrv() { $abbrv = $this->getRawAbbrv(); - if ( ABBRV_TYPE == 'key' || ABBRV_TYPE == 'year' || ( ABBRV_TYPE == 'index' && LAYOUT != 'list' ) ) { + if ( ABBRV_TYPE != 'none' ) { $abbrv = '['.$abbrv.']'; } return $abbrv; @@ -1309,44 +1313,48 @@ class BibEntry { /** Outputs HTML line according to layout */ function toHTML() { - switch(LAYOUT) { // open row + switch(BIBTEXBROWSER_LAYOUT) { // open row case 'list': - echo '
      • '; + echo '
      • '; + break; + case 'ordered_list': + echo '
      • '; break; case 'table': echo '
    '; + echo ''."\n"; break; - case 'deflist': - echo ''; + case 'definition': + echo ''."\n"; break; } } - /** Create the entry anchor */ - function anchor() { - echo ''; - } /** Outputs an coins URL: see http://ocoins.info/cobg.html * Used by Zotero, mendeley, etc. @@ -1409,6 +1417,40 @@ class BibEntry { } + /** Returns an anchor for this entry. */ + function anchor() { + return ''; + } + + /** returns a collection of links for the given bibtex entry + * e.g. [bibtex] [doi][pdf] + */ + function bib2links() { + $href = 'href="'.$this->getURL().'"'; + + $str = ''; + + if (BIBTEXBROWSER_BIBTEX_LINKS) { + // we add biburl and title to be able to retrieve this important information + // using Xpath expressions on the XHTML source + $str .= " getKey()."\" {$href}>[bibtex]"; + } + + // returns an empty string if no url present + $str .= $this->getUrlLink(); + + if ($this->hasField('doi')) { + $str .= ' [doi]'; + } + + // Google Scholar ID + if ($this->hasField('gsid')) { + $str .= ' [cites]'; + } + + return $str; + } + /** @@ -1454,32 +1496,36 @@ class BibEntry { } } +/** returns an HTML tag depending on BIBTEXBROWSER_LAYOUT e.g.
    '; break; - case 'deflist': - echo '
    '; break; + case 'definition': + echo '
    '; + if (ABBRV_TYPE=='none') { die ('Cannot define an empty term!'); } + break; } - $this->anchor(); - switch(LAYOUT) { // close bibref and open bibitem + echo $this->anchor(); + switch(BIBTEXBROWSER_LAYOUT) { // close bibref and open bibitem case 'table': echo $this->getAbbrv().'
    '; break; - case 'deflist': + case 'definition': echo $this->getAbbrv().'
    '; break; } echo bib2html($this); - echo bib2links($this); - switch(LAYOUT) { // close row + echo $this->bib2links(); + switch(BIBTEXBROWSER_LAYOUT) { // close row case 'list': - echo ''; + echo ''."\n"; + break; + case 'ordered_list': + echo ''."\n"; break; case 'table': - echo '
    */ +function get_HTML_tag_for_layout() { + switch(BIBTEXBROWSER_LAYOUT) { /* switch for different layouts */ + case 'list': + $tag='ul'; + break; + case 'ordered_list': + $tag='ol'; + break; + case 'table': + $tag = 'table'; + break; + case 'definition': + $tag = 'div'; + break; + default: + die('Unknown BIBTEXBROWSER_LAYOUT'); + } + return $tag; +} -function layoutHeaderHTML() { - $tag = ''; - switch(LAYOUT) { /* switch for different layouts */ - case 'list': - if (ABBRV_TYPE=='index') { - $tag='ol'; - } else { // assume none - $tag='ul'; - } - break; - case 'table': - $tag = 'table'; - break; - case 'deflist': - $tag = 'div'; - break; - default: - die('Unknown LAYOUT'); - } - echo '<' . $tag . ' class="result">'; - return $tag; + +/** prints the header of a layouted HTML, depending on BIBTEXBROWSER_LAYOUT e.g.
    */ +function print_header_layout() { + echo '<' . get_HTML_tag_for_layout() . ' class="result">'."\n"; } -function layoutFooterHTML($tag) { - echo ''; +/** prints the footer of a layouted HTML, depending on BIBTEXBROWSER_LAYOUT e.g.
    */ +function print_footer_layout() { + echo ''; } /** this function encapsulates the user-defined name for bib to HTML*/ @@ -1488,30 +1534,6 @@ function bib2html(&$bibentry) { return $function($bibentry); } -function bib2links(&$bibentry) { - $href = 'href="'.$bibentry->getURL().'"'; - - if (BIBTEXBROWSER_BIBTEX_LINKS) { - // we add biburl and title to be able to retrieve this important information - // using Xpath expressions on the XHTML source - $str .= " getKey()."\" {$href}>[bibtex]"; - } - - // returns an empty string if no url present - $str .= $bibentry->getUrlLink(); - - if ($bibentry->hasField('doi')) { - $str .= ' [doi]'; - } - - // Google Scholar ID - if ($bibentry->hasField('gsid')) { - $str .= ' [cites]'; - } - - return $str; -} - /** encapsulates the user-defined sections. @nodoc */ function _DefaultBibliographySections() { $function = BIBLIOGRAPHYSECTIONS; @@ -1727,7 +1749,7 @@ function DefaultBibliographyStyle(&$bibentry) { } // add the Coin URL - $result .= "\n".$bibentry->toCoins(); + $result .= $bibentry->toCoins(); return $result; } @@ -2371,7 +2393,7 @@ class SimpleDisplay { echo 'Options: '.@implode(',',$this->options).'
    '; } - $tag = layoutHeaderHTML(); + print_header_layout(); $count = count($this->entries); $i=0; @@ -2382,7 +2404,7 @@ class SimpleDisplay { $bib->toHTML(); } // end foreach - layoutFooterHTML($tag); + print_footer_layout(); } // end function } // end class @@ -2438,21 +2460,21 @@ class AcademicDisplay { uasort($entries, ORDER_FUNCTION); if (count($entries)>0) { - echo "\n".'
    '.$title.'
    '."\n"; - $tag = layoutHeaderHTML(); + echo "\n".'
    '.$title.'
    '."\n"; + print_header_layout(); - // by default the abbreviation is incremented over all searches - - // since we don't know before hand all section, we can not index in decreasing order - static $count; - if ($count == NULL) { $count = 1; } // init - $id = $count; - foreach ($entries as $bib) { - $bib->setIndex($id++); - $bib->toHTML(); - } // end foreach - $count = @$count + count($entries); - layoutFooterHTML($tag); + // by default the abbreviation is incremented over all searches + + // since we don't know before hand all section, we can not index in decreasing order + static $count; + if ($count == NULL) { $count = 1; } // init + $id = $count; + foreach ($entries as $bib) { + $bib->setIndex($id++); + $bib->toHTML(); + } // end foreach + $count = @$count + count($entries); + print_footer_layout(); } } @@ -3243,7 +3265,7 @@ class PagedDisplay { } $this->menu($less, $more); - $tag = layoutHeaderHTML(); + print_header_layout(); for ($i = 0; $i < PAGE_SIZE; $i++) { $index = ($this->page-1)*PAGE_SIZE + $i; if (isset($this->entries[$index])) { @@ -3254,7 +3276,8 @@ class PagedDisplay { //break; } } // end foreach - layoutFooterHTML($tag); + + print_footer_layout(); $this->menu($less, $more); } @@ -3640,4 +3663,4 @@ class Dispatcher { $class = BIBTEXBROWSER_MAIN;// extension point $main = new $class(); $main->main(); -?> +?> \ No newline at end of file