From fa569937068a53ffb1c3a55d991ac0294835eb50 Mon Sep 17 00:00:00 2001 From: Matthieu Guillaumin Date: Wed, 27 Feb 2013 19:53:42 +0100 Subject: [PATCH] the LAYOUT option and minor modifications --- bibtexbrowser.php | 154 +++++++++++++++++++++++++++++++++------------- 1 file changed, 110 insertions(+), 44 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 45f7513..f49baa4 100644 --- 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','v20121205'); @define('METADATA_DC',true); @define('METADATA_EPRINTS',false); +@define('LAYOUT','table'); // may be table/list/deflist. defines the HTML rendering options (,
    /
)with two TDS inside + /** Outputs HTML line according to layout */ + function toHTML() { + switch(LAYOUT) { + case 'list': $this->toLI(); break; + case 'table': $this->toTR(); break; + case 'deflist': $this->toDD(); break; + } + } + + /** Create the entry anchor */ + function anchor() { + echo ''; + } + + /** Outputs an TR line with two TDS inside */ function toTR() { echo ''; echo ' '; echo '\n"; // toTR() must be self-contained + } - $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 an LI line with SPANs for each element, setting the item value according to getAbbrv(). */ + function toLI() { + echo '
  • '; + $this->anchor(); + echo bib2html($this); + echo "
  • \n"; + } - if ($this->hasField('doi')) { - echo ' [doi]'; - } - - // Google Scholar ID - if ($this->hasField('gsid')) { - echo ' [cites]'; - } - echo "\n"; + /** Outputs an DL line (
    +
    ) */ + function toDD() { + echo '
    '; + $this->anchor(); + echo $this->getAbbrv().'
    '; + echo bib2html($this); + echo "
    \n"; } /** Outputs an coins URL: see http://ocoins.info/cobg.html @@ -1436,10 +1456,58 @@ 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); + $str = $function($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 */ @@ -2301,21 +2369,19 @@ class SimpleDisplay { echo 'Options: '.@implode(',',$this->options).'
    '; } - ?> + $tag = layoutHeaderHTML(); -
    '; - //echo ''; - + $this->anchor(); echo $this->getAbbrv().''; echo bib2html($this); + 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 + // 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 @@ -2381,11 +2447,11 @@ class AcademicDisplay { 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 +2463,7 @@ class AcademicDisplay { foreach (_DefaultBibliographySections() as $section) { $this->search2html($section['query'],$section['title']); - } + } } } @@ -3176,18 +3242,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 +3544,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 +3639,4 @@ class Dispatcher { $class = BIBTEXBROWSER_MAIN;// extension point $main = new $class(); $main->main(); -?> \ No newline at end of file +?>