From cad00235d3056bf8af322266ffea98bd955279f8 Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 12:37:04 +0200 Subject: [PATCH 01/16] Allow the user to search for a range of years --- bibtexbrowser.php | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index f7441a7..e1d3bb1 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -139,6 +139,7 @@ function bibtexbrowser_configure($key, $value) { @define('Q_ACADEMIC', 'academic'); @define('Q_DB', 'bibdb'); @define('Q_LATEST', 'latest'); +@define('Q_RANGE', 'range'); @define('AUTHOR', 'author'); @define('EDITOR', 'editor'); @define('SCHOOL', 'school'); @@ -3213,6 +3214,25 @@ class BibDataBase { break; } } + else if ($field==Q_RANGE) { + $year = $bib->getYear(); + $withinRange = false; + + foreach ($query[Q_RANGE] as $elements) { + if ($elements[0] === "" && $elements[1] === "") + $withinRange = true; + else if ($elements[0] === "" && $year <= $elements[1]) + $withinRange = true; + else if ($elements[1] === "" && $year >= $elements[0]) + $withinRange = true; + else if ($year <= $elements[1] && $year >= $elements[0]) { + $withinRange = true; + } + } + + if (!$withinRange) + $entryisselected = false; + } else { if (!$bib->hasPhrase($fragment, $field)) { $entryisselected = false; @@ -3852,6 +3872,68 @@ class Dispatcher { function type() { $this->query[Q_TYPE]= $_GET[Q_TYPE]; } + /** + * Allow the user to search for a range of dates + * + * The query string can comprise several elements separated by commas and + * optionally white-space. + * Each element can either be one number (a year) or two numbers + * (a range of years) separated by anything non-numerical. + * + */ + function range() { + $ranges = explode(',', $_GET[Q_RANGE]); + $result = array(); + + $nextYear = 1 + (int) date('Y'); + $nextYear2D = $nextYear % 100; + $thisCentury = $nextYear - $nextYear2D; + + foreach ($ranges as $range) { + $range = trim($range); + preg_match('/([0-9]*)([^0-9]*)([0-9]*)/', $range, $matches); + array_shift($matches); + + // If the number is empty, leave it empty - dont put it to 0 + // If the number is two-digit, assume it to be within the last century or next year + if ($matches[0] === "") { + $lower = ""; + } else if ($matches[0] < 100) { + if ($matches[0] > $nextYear2D) { + $lower = $thisCentury + $matches[0] - 100; + } else { + $lower = $thisCentury + $matches[0]; + } + } else { + $lower = $matches[0]; + } + + // If no separator to indicate a range of years was supplied, + // the upper and lower boundaries are the same. + // + // Otherwise, again: + // If the number is empty, leave it empty - dont put it to 0 + // If the number is two-digit, assume it to be within the last century or next year + if ($matches[1] === "") + $upper = $lower; + else { + if ($matches[2] === "") { + $upper = ""; + } else if ($matches[2] < 100) { + if ($matches[2] > $nextYear2D) { + $upper = $thisCentury + $matches[2] - 100; + } else { + $upper = $thisCentury + $matches[2]; + } + } else { + $upper = $matches[2]; + } + } + + $result[] = array($lower, $upper); + } + $this->query[Q_RANGE] = $result; + } function menu() { $menu = createMenuManager(); From 91070361ab74aee8e33ec88fc61e646fa2786a7a Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 12:57:31 +0200 Subject: [PATCH 02/16] i18n and graceful sorting for year values 'in press', 'submitted' and 'accepted' The sorting mechanism relied solely on strcmp before, which yielded a more or less random result. It is now possible to define an order as long as the strings in the bibtex file are given in their standard English form. In output though, the strings are internationalised. --- bibtexbrowser.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index e1d3bb1..20f54b8 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -122,6 +122,9 @@ function bibtexbrowser_configure($key, $value) { @define('READLINE_LIMIT',1024); @define('Q_YEAR', 'year'); @define('Q_YEAR_PAGE', 'year_page'); +@define('Q_YEAR_INPRESS', 'in press'); +@define('Q_YEAR_ACCEPTED', 'accepted'); +@define('Q_YEAR_SUBMITTED', 'submitted'); @define('Q_FILE', 'bib'); @define('Q_AUTHOR', 'author'); @define('Q_AUTHOR_PAGE', 'author_page'); @@ -1376,6 +1379,9 @@ class BibEntry { /** Returns the year of this entry? */ function getYear() { + return __(strtolower($this->getField('year'))); + } + function getYearRaw() { return $this->getField('year'); } @@ -1728,7 +1734,47 @@ function compare_bib_entry_by_mtime($a, $b) */ function compare_bib_entry_by_year($a, $b) { - return -strcmp($a->getYear(),$b->getYear()); + $yearA = (int) $a->getYear(); + $yearB = (int) $b->getYear(); + + if ($yearA === 0) { + switch (strtolower($a->getYearRaw())) { + case Q_YEAR_INPRESS: + $yearA = PHP_INT_MAX; + break; + case Q_YEAR_ACCEPTED: + $yearA = PHP_INT_MAX - 1; + break; + case Q_YEAR_SUBMITTED: + $yearA = PHP_INT_MAX - 2; + break; + default: + $yearA = PHP_INT_MAX - 3; + } + } + + if ($yearB === 0) { + switch (strtolower($b->getYearRaw())) { + case 'in press': + $yearB = PHP_INT_MAX; + break; + case 'accepted': + $yearB = PHP_INT_MAX - 1; + break; + case 'submitted': + $yearB = PHP_INT_MAX - 2; + break; + default: + $yearB = PHP_INT_MAX - 3; + } + } + + if ($yearA === $yearB) + return 0; + else if ($yearA > $yearB) + return -1; + else + return 1; } /** compares two instances of BibEntry by title From ed9084e4e38f1799e3fb0f59238591251fed9cdf Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 13:25:57 +0200 Subject: [PATCH 03/16] Made sorting of non-int year values easily configurable --- bibtexbrowser.php | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 20f54b8..b84828b 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -155,6 +155,15 @@ function bibtexbrowser_configure($key, $value) { @define('METADATA_DC',true); @define('METADATA_EPRINTS',false); +// define sort order for special values in 'year' field +// highest number is sorted first +// don't exceed 0 though, since the values are added to PHP_INT_MAX +@define('ORDER_YEAR_INPRESS', -0); +@define('ORDER_YEAR_ACCEPTED', -1); +@define('ORDER_YEAR_SUBMITTED', -2); +@define('ORDER_YEAR_OTHERNONINT', -3); + + // 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 @@ -1740,32 +1749,32 @@ function compare_bib_entry_by_year($a, $b) if ($yearA === 0) { switch (strtolower($a->getYearRaw())) { case Q_YEAR_INPRESS: - $yearA = PHP_INT_MAX; + $yearA = PHP_INT_MAX + ORDER_YEAR_INPRESS; break; case Q_YEAR_ACCEPTED: - $yearA = PHP_INT_MAX - 1; + $yearA = PHP_INT_MAX + ORDER_YEAR_ACCEPTED; break; case Q_YEAR_SUBMITTED: - $yearA = PHP_INT_MAX - 2; + $yearA = PHP_INT_MAX + ORDER_YEAR_SUBMITTED; break; default: - $yearA = PHP_INT_MAX - 3; + $yearA = PHP_INT_MAX + ORDER_YEAR_OTHERNONINT; } } if ($yearB === 0) { switch (strtolower($b->getYearRaw())) { - case 'in press': - $yearB = PHP_INT_MAX; + case Q_YEAR_INPRESS: + $yearB = PHP_INT_MAX + ORDER_YEAR_INPRESS; break; - case 'accepted': - $yearB = PHP_INT_MAX - 1; + case Q_YEAR_ACCEPTED: + $yearB = PHP_INT_MAX + ORDER_YEAR_ACCEPTED; break; - case 'submitted': - $yearB = PHP_INT_MAX - 2; + case Q_YEAR_SUBMITTED: + $yearB = PHP_INT_MAX + ORDER_YEAR_SUBMITTED; break; default: - $yearB = PHP_INT_MAX - 3; + $yearB = PHP_INT_MAX + ORDER_YEAR_OTHERNONINT; } } From 5a159bcfd5c53771b445f40f88a5185f3bc8db69 Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 14:09:45 +0200 Subject: [PATCH 04/16] Now also applies graceful ordering and i18n of non-string year-values to yearIndex() --- bibtexbrowser.php | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index b84828b..caf2ccc 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -2457,9 +2457,13 @@ else $page = 1; $index = 0; foreach ($items as $key => $item) { if ($index >= $startIndex && $index < $endIndex) { - $href = makeHref(array($queryKey => $key)); - echo ''. $item ."\n"; - echo "
\n"; + if ($queryKey === 'year') { + $href = makeHref(array($queryKey => __($item))); + } else { + $href = makeHref(array($queryKey => $key)); + } + echo ''. $item ."\n"; + echo "
\n"; } $index++; } @@ -3201,10 +3205,31 @@ class BibDataBase { $result = array(); foreach ($this->bibdb as $bib) { if (!$bib->hasField("year")) continue; - $year = $bib->getField("year"); - $result[$year] = $year; + $year = strtolower($bib->getYearRaw()); + $yearInt = (int) $year; + + // Allow for ordering of non-string values ('in press' etc.) + switch ($year) { + case (string) $yearInt: // Sorry for this hacky type-casting + $key = $year; + break; + case Q_YEAR_INPRESS: + $key = PHP_INT_MAX + ORDER_YEAR_INPRESS; + break; + case Q_YEAR_ACCEPTED: + $key = PHP_INT_MAX + ORDER_YEAR_ACCEPTED; + break; + case Q_YEAR_SUBMITTED: + $key = PHP_INT_MAX + ORDER_YEAR_SUBMITTED; + break; + default: + $key = PHP_INT_MAX + ORDER_YEAR_OTHERNONINT; } - arsort($result); + + $result[$key] = $year; + } + + krsort($result); return $result; } From 242eed4eca1455c7504ca1719b724311a7c977ea Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 14:28:54 +0200 Subject: [PATCH 05/16] Now displaying something sensible in result heading for Q_RANGE searches --- bibtexbrowser.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index caf2ccc..d862e72 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -2483,6 +2483,12 @@ function query2title(&$query) { $v = preg_replace('/[$^]/','',$v); } if($k == Q_KEYS) { $v=json_encode(array_values($v)); } + if($k == Q_RANGE) { + foreach ($v as &$range) { + $range = $range[0].'-'.$range[1]; + } + $v = join($v, ','); + } $headers[$k] = __(ucwords($k)).': '.ucwords(htmlspecialchars($v)); } // special cases From e800ac4fd82494a55e1a006eb9539f8807dff73f Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 15:13:05 +0200 Subject: [PATCH 06/16] =?UTF-8?q?Added=20css=20class=20and=20i18n=20to=20n?= =?UTF-8?q?o=20=E2=80=9Cresult=E2=80=9D=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bibtexbrowser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index d862e72..53ed7e1 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -2718,7 +2718,7 @@ class NotFoundDisplay { function setTitle($title) { $this->title = $title; return $this; } function getTitle() { return @$this->title ; } function display() { - echo 'no result found, sorry.'; + echo ''.__('No results').''; } } /** displays the publication records sorted by publication types (as configured by constant BIBLIOGRAPHYSECTIONS). From 09e4bf98bbb3fc6e949d976779e0d400c8a93eaf Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 15:24:18 +0200 Subject: [PATCH 07/16] =?UTF-8?q?Escape=20German=20=C3=9F=20in=20addition?= =?UTF-8?q?=20to=20umlauts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bibtexbrowser.php | 1 + 1 file changed, 1 insertion(+) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 53ed7e1..ce50510 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -920,6 +920,7 @@ function latex2html($line) { $line = char2html($line,'"','o',"uml"); $line = char2html($line,'"','u',"uml"); $line = char2html($line,'"','y',"uml"); + $line = char2html($line,'"','s',"zlig"); $line = char2html($line,'^','a',"circ"); $line = char2html($line,'^','e',"circ"); From f7daaefeecd6f18f904f85f9707a68c913133c0d Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 15:53:28 +0200 Subject: [PATCH 08/16] Option FORCE_NAMELIST_SEPARATOR allows for commas between authors as well as between last and first name --- bibtexbrowser.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index ce50510..1bcba45 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -115,6 +115,7 @@ function bibtexbrowser_configure($key, $value) { @define('BIBTEXBROWSER_DEBUG',false); @define('COMMA_NAMES',false);// do have authors in a comma separated form? +@define('FORCE_NAMELIST_SEPARATOR', ''); // if non-empty, use this to separate multiple names regardless of COMMA_NAMES @define('TYPES_SIZE',10); // number of entry types per table @define('YEAR_SIZE',20); // number of years per table @define('AUTHORS_SIZE',30); // number of authors per table @@ -1312,6 +1313,7 @@ class BibEntry { } if (COMMA_NAMES) {$sep = '; ';} else {$sep = ', ';} + if (FORCE_NAMELIST_SEPARATOR !== '') {$sep = FORCE_NAMELIST_SEPARATOR;} return implode($sep ,$array_authors); } @@ -1384,6 +1386,7 @@ class BibEntry { $editors[]=$this->addHomepageLink($this->formatAuthor($editor)); } if (COMMA_NAMES) {$sep = '; ';} else {$sep = ', ';} + if (FORCE_NAMELIST_SEPARATOR !== '') {$sep = FORCE_NAMELIST_SEPARATOR;} return implode($sep, $editors).', '.(count($editors)>1?'eds.':'ed.'); } From 94aeb68a882d76f0f140fbcfdf860929a4ed8045 Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 17:47:11 +0200 Subject: [PATCH 09/16] Tidied up generation mechanism for [pdf], [doi] links etc. Removed duplicate code that existed inside and outside of get*Link() functions. Added option BIBTEXBROWSER_LINKS_IN_NEW_WINDOW. It is used instead of BIBTEXBROWSER_BIB_IN_NEW_WINDOW for external links (everything but [bibtex]). --- bibtexbrowser.php | 53 +++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 1bcba45..4ff34d8 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -100,6 +100,9 @@ function bibtexbrowser_configure($key, $value) { // do we add [gsid] links (Google Scholar)? @define('BIBTEXBROWSER_GSID_LINKS',true); +// should pdf, doi, url, gsid links be opened in a new window? +@define('BIBTEXBROWSER_LINKS_IN_NEW_WINDOW',true); + // should authors be linked to [none/homepage/resultpage] // none: nothing // their homepage if defined as @strings @@ -1109,11 +1112,21 @@ class BibEntry { if ($altlabel==NULL) { $altlabel=$bibfield; } $str = $this->getIconOrTxt($altlabel,$iconurl); if ($this->hasField($bibfield)) { - return ''.$str.''; + return ''.$str.''; } return ''; } + /** returns a "[bib]" link */ + function getBibLink($iconurl=NULL) { + $bibstr = $this->getIconOrTxt('bibtex',$iconurl); + $href = 'href="'.$this->getURL().'"'; + // we add biburl and title to be able to retrieve this important information + // using Xpath expressions on the XHTML source + $link = "getKey()."\" {$href}>$bibstr"; + return $link; + } + /** returns a "[pdf]" link if relevant. modified to exploit the new method, while keeping backward compatibility */ function getUrlLink($iconurl = NULL, $label = 'pdf') { if ($this->hasField('url')) { @@ -1129,34 +1142,22 @@ class BibEntry { } } - /** returns a "[bib]" link if relevant */ - function getBibLink($iconurl=NULL) { - if (BIBTEXBROWSER_BIBTEX_LINKS) { - $bibstr = $this->getIconOrTxt('bibtex',$iconurl); - $href = 'href="'.$this->getURL().'"'; - $link = "getKey()."\" {$href}>$bibstr"; - return $link; - } else { - return ''; - } - } /** DOI are a special kind of links, where the url depends on the doi */ function getDoiLink($iconurl=NULL) { $str = $this->getIconOrTxt('doi',$iconurl); - if (BIBTEXBROWSER_DOI_LINKS && $this->hasField('doi')) { - return ''.$str.''; + if ($this->hasField('doi')) { + return ''.$str.''; } return ''; } - /** GS are a special kind of links, where the url depends on the google scholar id */ + /** GS (Google Scholar) are a special kind of links, where the url depends on the google scholar id */ function getGSLink($iconurl=NULL) { $str = $this->getIconOrTxt('cites',$iconurl); - // Google Scholar ID - if (BIBTEXBROWSER_GSID_LINKS && $this->hasField('gsid')) { - return ' '.$str.''; + if ($this->hasField('gsid')) { + return ' '.$str.''; } return ''; } @@ -1678,28 +1679,22 @@ function get_HTML_tag_for_layout() { * e.g. [bibtex] [doi][pdf] */ function bib2links_default(&$bibentry) { - $href = 'href="'.$bibentry->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]"; + $str .= ' '.$bibentry->getBibLink(); } if (BIBTEXBROWSER_PDF_LINKS) { - // returns an empty string if no url present $str .= ' '.$bibentry->getUrlLink(); } - if (BIBTEXBROWSER_DOI_LINKS && $bibentry->hasField('doi')) { - $str .= ' [doi]'; + if (BIBTEXBROWSER_DOI_LINKS) { + $str .= ' '.$bibentry->getDoiLink(); } - // Google Scholar ID - if (BIBTEXBROWSER_GSID_LINKS && $bibentry->hasField('gsid')) { - $str .= ' [cites]'; + if (BIBTEXBROWSER_GSID_LINKS) { + $str .= ' '.$bibentry->getGSLink(); } $str .= ''; From 26d3553564ff6b552833d830128fe144dba21505 Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 18:09:17 +0200 Subject: [PATCH 10/16] Turns doi, url, gsid etc. into hyperlinks in bibtex entry display Does not yet work in js progressive enhancement mode --- bibtexbrowser.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 4ff34d8..1697dd9 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -1622,10 +1622,16 @@ class BibEntry { $result = ""; $result .= '
'; // pre is nice when it is embedded with no CSS available
     $entry = htmlspecialchars($this->getFullText());
-    if ($this->hasField('url')) {
-      $url = $this->getField('url');
-      // this is not a parsing but a simple replacement
-      $entry = str_replace($url,''.$url.'', $entry);
+
+    // Fields that should be hyperlinks
+    $hyperlinks = array('url' => '%O', 'file' => '%O', 'pdf' => '%O', 'doi' => 'http://dx.doi.org/%O', 'gsid' => 'http://scholar.google.com/scholar?cites=%O');
+
+    foreach ($hyperlinks as $field => $url) {
+      if ($this->hasField($field)) {
+        $href = str_replace('%O', $this->getField($field), $url);
+        // this is not a parsing but a simple replacement
+        $entry = str_replace($this->getField($field), ''.$this->getField($field).'', $entry);
+      }
     }
 
     $result .=  $entry;

From b0dabd167ac0501ca524abe24e5ea6251d20181d Mon Sep 17 00:00:00 2001
From: Markus Jochim 
Date: Fri, 19 Sep 2014 18:14:33 +0200
Subject: [PATCH 11/16] added compare_bib_entry_by_name()

---
 bibtexbrowser.php | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/bibtexbrowser.php b/bibtexbrowser.php
index 1697dd9..ea0125c 100755
--- a/bibtexbrowser.php
+++ b/bibtexbrowser.php
@@ -1805,6 +1805,26 @@ function compare_bib_entry_by_raw_abbrv($a, $b)
   return strcmp($a->getRawAbbrv(),$b->getRawAbbrv());
 }
 
+/** compares two instances of BibEntry by author or editor
+ */
+function compare_bib_entry_by_name($a, $b)
+{
+  if ($a->hasField(AUTHOR))
+    $namesA = $a->getAuthor();
+  else if ($a->hasField(EDITOR))
+    $namesA = $a->getField(EDITOR);
+  else
+    $namesA = __('No author');
+
+  if ($b->hasField(AUTHOR))
+    $namesB = $b->getAuthor();
+  else if ($b->hasField(EDITOR))
+    $namesB = $b->getField(EDITOR);
+  else
+    $namesB = __('No author');
+
+  return strcmp($namesA, $namesB);
+}
 
 /** compares two instances of BibEntry by month
  * @author Jan Geldmacher

From 13e922ac005f0bb47c4579de8490f8385b065e85 Mon Sep 17 00:00:00 2001
From: Markus Jochim 
Date: Fri, 19 Sep 2014 18:39:31 +0200
Subject: [PATCH 12/16] Splitted list layout by year; added
 BIBTEXBROWSER_HTMLHEADINGLEVEL

---
 bibtexbrowser.php | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/bibtexbrowser.php b/bibtexbrowser.php
index ea0125c..c5a5420 100755
--- a/bibtexbrowser.php
+++ b/bibtexbrowser.php
@@ -115,6 +115,9 @@ function bibtexbrowser_configure($key, $value) {
 // for ordered_list, the index is given by HTML directly (in increasing order)
 @define('BIBTEXBROWSER_LAYOUT','table');
 
+// Which is the first html  level that should be used in embedded mode?
+@define('BIBTEXBROWSER_HTMLHEADINGLEVEL', 2);
+
 @define('BIBTEXBROWSER_DEBUG',false);
 
 @define('COMMA_NAMES',false);// do have authors in a comma separated form?
@@ -1711,6 +1714,7 @@ function bib2links_default(&$bibentry) {
 
 /** prints the header of a layouted HTML, depending on BIBTEXBROWSER_LAYOUT e.g.  */
 function print_header_layout() {
+  if (BIBTEXBROWSER_LAYOUT == 'list') return;
   echo '<' . get_HTML_tag_for_layout() . ' class="result">'."\n";
 }
 
@@ -2632,6 +2636,14 @@ class SimpleDisplay  {
 
   var $options = array();
 
+  var $headingLevel = BIBTEXBROWSER_HTMLHEADINGLEVEL;
+  function incHeadingLevel ($by=1) {
+  	$this->headingLevel += $by;
+  }
+  function decHeadingLevel ($by=1) {
+  	$this->headingLevel -= $by;
+  }
+
   function setDB(&$bibdatabase) {
     $this->setEntries($bibdatabase->bibdb);
   }
@@ -2689,7 +2701,7 @@ class SimpleDisplay  {
     $pred = NULL;
     foreach ($this->entries as $bib) {
       if ($this->changeSection($pred, $bib)) {
-        echo $this->sectionHeader($bib);
+        echo $this->sectionHeader($bib, $pred);
       }
       // by default, index are in decreasing order
       // so that when you add a publicaton recent , the indices of preceding publications don't change
@@ -2712,7 +2724,7 @@ class SimpleDisplay  {
     return $f($pred, $bib) != 0;
   }
 
-  function sectionHeader($bib) {
+  function sectionHeader($bib, $pred) {
     switch(BIBTEXBROWSER_LAYOUT) {
       case 'table':
         return ''."\n";
@@ -2720,6 +2732,15 @@ class SimpleDisplay  {
       case 'definition':
         return '
'.$bib->getYear().'
'."\n"; break; + case 'list': + $string = ''; + if ($pred) $string .= "\n"; + if ($bib->hasField(YEAR)) + $year = $bib->getYear(); + else + $year = __('No date'); + return $string.'headingLevel.'>'.$year."headingLevel.">\n
    \n"; + break; default: return ''; } From 3c27800e16e2174b168b1edaff79f1b60ffb2c50 Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 18:52:18 +0200 Subject: [PATCH 13/16] Added result count to every bibliography section in academic display, total count in normal display --- bibtexbrowser.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index c5a5420..32360a2 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -2694,6 +2694,12 @@ class SimpleDisplay { echo 'Options: '.@implode(',',$this->options).'
    '; } + if ($this->headingLevel == BIBTEXBROWSER_HTMLHEADINGLEVEL) { + echo "\n".count($this->entries)." "; + if (count($this->entries) == 1) echo __('result'); + else echo __('results'); + echo "\n"; + } print_header_layout(); $count = count($this->entries); From 78c3487aeaabae138dba6bb8d8dba6587af3095d Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 19:26:09 +0200 Subject: [PATCH 14/16] Added a table of contents to search results in academic display --- bibtexbrowser.php | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 32360a2..8e9f7cd 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -118,6 +118,8 @@ function bibtexbrowser_configure($key, $value) { // Which is the first html level that should be used in embedded mode? @define('BIBTEXBROWSER_HTMLHEADINGLEVEL', 2); +@define('BIBTEXBROWSER_ACADEMIC_TOC', true); + @define('BIBTEXBROWSER_DEBUG',false); @define('COMMA_NAMES',false);// do have authors in a comma separated form? @@ -2816,11 +2818,45 @@ class AcademicDisplay { $this->db = createBibDataBase(); $this->db->bibdb = $this->entries; - foreach (_DefaultBibliographySections() as $section) { - $this->search2html($section['query'],$section['title']); + if (BIBTEXBROWSER_ACADEMIC_TOC != true) { + foreach (_DefaultBibliographySections() as $section) { + $this->search2html($section['query'],$section['title']); + } + } else { + $sections = array(); + echo "
      "; + + foreach (_DefaultBibliographySections() as $section) { + $entries = $this->db->multisearch($section['query']); + + if (count($entries)>0) { + $anchor = preg_replace("/[^a-zA-Z]/", "", $section['title']); + echo "
    • ".$section['title']." (".count($entries).")
    • "; + + $display = createBasicDisplay(); + $display->incHeadingLevel(); + $display->setEntries($entries); + $display->headerCSS = 'theader'; + + $sections[] = array ( + 'display' => $display, + 'anchor' => $anchor, + 'title' => $section['title'], + 'count' => count($entries) + ); + } + } + echo "
    "; + + foreach ($sections as $section) { + echo "\n"; + echo ""; + echo $section['title']." (".$section['count'].")"; + echo "\n", + $section['display']->display(); + } } } - } From b7ca107d6b91ed3803588fa7e6ecd4617377991b Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 19:53:46 +0200 Subject: [PATCH 15/16] added copyright notice --- bibtexbrowser.php | 1 + 1 file changed, 1 insertion(+) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 8e9f7cd..0892732 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -4,6 +4,7 @@ URL: http://www.monperrus.net/martin/bibtexbrowser/ Feedback & Bug Reports: martin.monperrus@gnieh.org (C) 2012-2014 Github contributors +(C) 2014 Markus Jochim (C) 2006-2014 Martin Monperrus (C) 2013 Matthieu Guillaumin (C) 2005-2006 The University of Texas at El Paso / Joel Garcia, Leonardo Ruiz, and Yoonsik Cheon From 89361841bb7d7686130ddd79742d4d700d58d200 Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 21:32:25 +0200 Subject: [PATCH 16/16] Fixed a bug where '0 results' would be shown with the corresponding heading being invisible --- bibtexbrowser.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 0892732..b36ce43 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -2698,9 +2698,12 @@ class SimpleDisplay { } if ($this->headingLevel == BIBTEXBROWSER_HTMLHEADINGLEVEL) { - echo "\n".count($this->entries)." "; - if (count($this->entries) == 1) echo __('result'); - else echo __('results'); + echo "\n".''; + if (count($this->entries) == 1) { + echo count ($this->entries).' '.__('result'); + } else if (count($this->entries) != 0) { + echo count ($this->entries).' '.__('results'); + } echo "\n"; } print_header_layout();
'.$bib->getYear().'