diff --git a/.travis.yml b/.travis.yml index 2531277..e802053 100644 --- a/.travis.yml +++ b/.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 diff --git a/bibtexbrowser-documentation.wiki b/bibtexbrowser-documentation.wiki index 2bd45a0..cffce94 100755 --- a/bibtexbrowser-documentation.wiki +++ b/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
- // 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+One can also extend class SimpleDisplay to tweak the indices. + +For instance, this configuration ... +
+// bibtexbrowser.local.php +class SimpleDisplayExt extends SimpleDisplay { + // overriding the default + function setIndices() { + $this->setIndicesInIncreasingOrderChangingEveryYear(); + } +} +bibtexbrowser_configure('BIBTEXBROWSER_DEFAULT_DISPLAY','SimpleDisplayExt'); ++results in resetting the numeric indices every year as follows +
+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] ++ ====How to use the "Academic style"?==== diff --git a/bibtexbrowser-test.php b/bibtexbrowser-test.php index 7a5351f..6c2f558 100755 --- a/bibtexbrowser-test.php +++ b/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('An Article ( ), In New Results, volume 5, 2009. ',$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'); diff --git a/bibtexbrowser.php b/bibtexbrowser.php index e4ef317..fc1dd03 100755 --- a/bibtexbrowser.php +++ b/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 .= '