Browse Source

add support for overrding numeric index assignment

pull/81/merge
Martin Monperrus 8 years ago
parent
commit
dc4419678a
  1. 5
      .travis.yml
  2. 29
      bibtexbrowser-documentation.wiki
  3. 48
      bibtexbrowser-test.php
  4. 56
      bibtexbrowser.php

5
.travis.yml

@ -4,11 +4,10 @@ php:
- '5.4'
- '5.5'
- '5.6'
- '7.0'
script:
- curl -o reflectivedoc.php http://www.monperrus.net/martin/reflectivedoc.php.txt
- curl -o gakowiki-syntax.php http://www.monperrus.net/martin/gakowiki-syntax.php.txt
- curl -L -o reflectivedoc.php https://www.monperrus.net/martin/reflectivedoc.php.txt
- curl -L -o gakowiki-syntax.php https://www.monperrus.net/martin/gakowiki-syntax.php.txt
- phpunit bibtexbrowser-test.php
sudo: false

29
bibtexbrowser-documentation.wiki

@ -241,14 +241,41 @@ add into ''bibtexbrowser.local.php'':
''@define('BIBTEXBROWSER_BIBTEX_LINKS',false);''
====How to change the reference indices?====
The configuration of ABBRV_TYPE drives the indices
<pre>
// index => [1] The essence of metamodeling
// year => [2005] The essence of metamodeling
// x-abbrv => [SoSyM] The essence of metamodeling if the bibtex entry contains a field x-abbrv
define('ABBRV_TYPE','year');// may be year/x-abbrv/key/none/index
</pre>
One can also extend class SimpleDisplay to tweak the indices.
For instance, this configuration ...
<pre>
// bibtexbrowser.local.php
class SimpleDisplayExt extends SimpleDisplay {
// overriding the default
function setIndices() {
$this->setIndicesInIncreasingOrderChangingEveryYear();
}
}
bibtexbrowser_configure('BIBTEXBROWSER_DEFAULT_DISPLAY','SimpleDisplayExt');
</pre>
results in resetting the numeric indices every year as follows
<pre>
2017
[1] article1... (2017) [pdf] [doi]
[2] article2... (2017) [pdf] [doi]
[3] article3... (2017) [pdf] [doi]
etc..
2016
[1] article1... (2017) [pdf] [doi]
[2] article2... (2017) [pdf] [doi]
[3] article3... (2017) [pdf] [doi]
</pre>
====How to use the "Academic style"?====

48
bibtexbrowser-test.php

@ -44,6 +44,12 @@ if(is_file('reflectivedoc.php')) {
require_once ('bibtexbrowser.php');
}
class SimpleDisplayExt extends SimpleDisplay {
function setIndices() {
$this->setIndicesInIncreasingOrderChangingEveryYear();
}
}
class BTBTest extends PHPUnit_Framework_TestCase {
@ -55,7 +61,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
function createDB() {
return $this->_createDB("@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n"
."@book{aKey/withSlash,title={Slash Dangerous for web servers},author={Ap Ache},publisher={Springer},year=2009}\n"
."@book{aKey/withSlash,title={Slash Dangerous for web servers},author={Ap Ache},publisher={Springer},year=2010}\n"
."@article{aKeyA,title={An Article},author={Foo Bar and Jane Doe},volume=5,journal=\"New Results\",year=2009,pages={1-2}}\n");
}
@ -132,6 +138,21 @@ class BTBTest extends PHPUnit_Framework_TestCase {
bibtexbrowser_configure('BIBTEXBROWSER_LINKS_TARGET','_top');
$this->assertEquals('<span itemscope="" itemtype="http://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">An Article</span> (<span class="bibauthor"><span itemprop="author" itemtype="http://schema.org/Person">Foo Bar</span> and <span itemprop="author" itemtype="http://schema.org/Person">Jane Doe</span></span>), <span class="bibbooktitle">In <span itemprop="isPartOf">New Results</span></span>, volume 5, <span itemprop="datePublished">2009</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.atitle=An+Article&amp;rft.jtitle=New+Results&amp;rft.volume=5&amp;rft.issue=&amp;rft.pub=&amp;rfr_id=info%3Asid%2F%3A&amp;rft.date=2009&amp;rft.au=Foo+Bar&amp;rft.au=Jane+Doe"></span></span> ',$first_entry->toHTML());
// testing ABBRV_TYPE
bibtexbrowser_configure('ABBRV_TYPE','year');
$this->assertEquals("[2009]",$first_entry->getAbbrv());
bibtexbrowser_configure('ABBRV_TYPE','key');
$this->assertEquals("[aKeyA]",$first_entry->getAbbrv());
bibtexbrowser_configure('ABBRV_TYPE','index');
$this->assertEquals("[]",$first_entry->getAbbrv());
$first_entry->setIndex('foo');
$this->assertEquals("[foo]",$first_entry->getAbbrv());
bibtexbrowser_configure('ABBRV_TYPE','none');
$this->assertEquals("",$first_entry->getAbbrv());
// resetting the default link style
bibtexbrowser_configure('BIBTEXBROWSER_LINK_STYLE','bib2links_default');
}
function testMultiSearch() {
@ -578,6 +599,31 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals("@string{foo={Foo}}",$btb->stringdb['foo']->toString());
}
function test_indices() {
$btb = $this->createDB();
$this->assertEquals("[]", $btb->getEntryByKey('aKey')->getAbbrv());
$d = new SimpleDisplay();
$d->setDB($btb);
ob_start();
$d->display();
ob_get_clean();
// the indices have been set by SimpleDisplay
$this->assertEquals("[1]", $btb->getEntryByKey('aKey')->getAbbrv());
$this->assertEquals("[3]", $btb->getEntryByKey('aKey-withSlash')->getAbbrv());
// SimpleDisplayExt sets the indices differently, using setIndicesInIncreasingOrderChangingEveryYear
$d = new SimpleDisplayExt();
$d->setDB($btb);
ob_start();
$d->display();
ob_get_clean();
$this->assertEquals("[2]", $btb->getEntryByKey('aKey')->getAbbrv());
$this->assertEquals("[1]", $btb->getEntryByKey('aKey-withSlash')->getAbbrv());
}
function test_identity() {
$btb = new BibDataBase();
$btb->load('bibacid-utf8.bib');

56
bibtexbrowser.php

@ -1676,28 +1676,28 @@ class BibEntry {
/** Returns the raw, undecorated abbreviation depending on ABBRV_TYPE. */
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 == 'x-abbrv') {
if (c('ABBRV_TYPE') == 'index') return $this->index;
if (c('ABBRV_TYPE') == 'none') return '';
if (c('ABBRV_TYPE') == 'key') return $this->getKey();
if (c('ABBRV_TYPE') == 'year') return $this->getYear();
if (c('ABBRV_TYPE') == 'x-abbrv') {
if ($this->hasField('x-abbrv')) {return $this->getField('x-abbrv');}
return $this->abbrv;
}
if (ABBRV_TYPE == 'keys-index') {
if (c('ABBRV_TYPE') == 'keys-index') {
if (isset($_GET[Q_INNER_KEYS_INDEX])) {return $_GET[Q_INNER_KEYS_INDEX][$this->getKey()]; }
return '';
}
// otherwise it is a user-defined function in bibtexbrowser.local.php
$f = ABBRV_TYPE;
$f = c('ABBRV_TYPE');
return $f($this);
}
/** Returns the abbreviation, etc [1] if ABBRV_TYPE='index'. */
function getAbbrv() {
$abbrv = $this->getRawAbbrv();
if ( ABBRV_TYPE != 'none' ) {
if ( c('ABBRV_TYPE') != 'none' ) {
$abbrv = '['.$abbrv.']';
}
return $abbrv;
@ -1768,7 +1768,7 @@ class BibEntry {
break;
case 'definition':
$result .= '<dl class="bibline"><dt class="bibref">';
if (ABBRV_TYPE=='none') { die ('Cannot define an empty term!'); }
if (c('ABBRV_TYPE')=='none') { die ('Cannot define an empty term!'); }
break;
case 'none':
break;
@ -3133,11 +3133,41 @@ class SimpleDisplay {
return _DefaultBibliographyTitle($this->query);
}
function setIndices() {
$this->setIndicesInDecreasingOrder();
}
function setIndicesInIncreasingOrderChangingEveryYear() {
$i=1;
$pred = NULL;
foreach ($this->entries as $bib) {
if ($this->changeSection($pred, $bib)) {
$i=1;
}
$bib->setIndex($i++);
$pred = $bib;
} // end foreach
}
function setIndicesInDecreasingOrder() {
$count = count($this->entries);
$i=0;
foreach ($this->entries as $bib) {
// 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++));
} // end foreach
}
/** Displays a set of bibtex entries in an HTML table */
function display() {
uasort($this->entries, 'compare_bib_entries');
// now that the entries are sorted, setting the index of entries
// this function can be overloaded
$this->setIndices();
if ($this->options) {
foreach($this->options as $fname=>$opt) {
$this->$fname($opt,$entries);
@ -3147,7 +3177,7 @@ class SimpleDisplay {
if (BIBTEXBROWSER_DEBUG) {
echo 'Style: '.bibtexbrowser_configuration('BIBLIOGRAPHYSTYLE').'<br/>';
echo 'Order: '.ORDER_FUNCTION.'<br/>';
echo 'Abbrv: '.ABBRV_TYPE.'<br/>';
echo 'Abbrv: '.c('ABBRV_TYPE').'<br/>';
echo 'Options: '.@implode(',',$this->options).'<br/>';
}
@ -3162,16 +3192,12 @@ class SimpleDisplay {
}
print_header_layout();
$count = count($this->entries);
$i=0;
$pred = NULL;
foreach ($this->entries as $bib) {
if ($this->changeSection($pred, $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
$bib->setIndex($count-($i++));
echo $bib->toHTML(true);
$pred = $bib;

Loading…
Cancel
Save