add support for overrding numeric index assignment
This commit is contained in:
+2
-3
@@ -4,11 +4,10 @@ php:
|
|||||||
- '5.4'
|
- '5.4'
|
||||||
- '5.5'
|
- '5.5'
|
||||||
- '5.6'
|
- '5.6'
|
||||||
- '7.0'
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- curl -o reflectivedoc.php http://www.monperrus.net/martin/reflectivedoc.php.txt
|
- curl -L -o reflectivedoc.php https://www.monperrus.net/martin/reflectivedoc.php.txt
|
||||||
- curl -o gakowiki-syntax.php http://www.monperrus.net/martin/gakowiki-syntax.php.txt
|
- curl -L -o gakowiki-syntax.php https://www.monperrus.net/martin/gakowiki-syntax.php.txt
|
||||||
- phpunit bibtexbrowser-test.php
|
- phpunit bibtexbrowser-test.php
|
||||||
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|||||||
@@ -241,14 +241,41 @@ add into ''bibtexbrowser.local.php'':
|
|||||||
''@define('BIBTEXBROWSER_BIBTEX_LINKS',false);''
|
''@define('BIBTEXBROWSER_BIBTEX_LINKS',false);''
|
||||||
|
|
||||||
====How to change the reference indices?====
|
====How to change the reference indices?====
|
||||||
|
The configuration of ABBRV_TYPE drives the indices
|
||||||
<pre>
|
<pre>
|
||||||
|
|
||||||
// index => [1] The essence of metamodeling
|
// index => [1] The essence of metamodeling
|
||||||
// year => [2005] 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
|
// 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
|
define('ABBRV_TYPE','year');// may be year/x-abbrv/key/none/index
|
||||||
</pre>
|
</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"?====
|
====How to use the "Academic style"?====
|
||||||
|
|
||||||
|
|||||||
+47
-1
@@ -44,6 +44,12 @@ if(is_file('reflectivedoc.php')) {
|
|||||||
require_once ('bibtexbrowser.php');
|
require_once ('bibtexbrowser.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SimpleDisplayExt extends SimpleDisplay {
|
||||||
|
function setIndices() {
|
||||||
|
$this->setIndicesInIncreasingOrderChangingEveryYear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class BTBTest extends PHPUnit_Framework_TestCase {
|
class BTBTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
@@ -55,7 +61,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
function createDB() {
|
function createDB() {
|
||||||
return $this->_createDB("@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n"
|
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");
|
."@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');
|
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&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.atitle=An+Article&rft.jtitle=New+Results&rft.volume=5&rft.issue=&rft.pub=&rfr_id=info%3Asid%2F%3A&rft.date=2009&rft.au=Foo+Bar&rft.au=Jane+Doe"></span></span> ',$first_entry->toHTML());
|
$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&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.atitle=An+Article&rft.jtitle=New+Results&rft.volume=5&rft.issue=&rft.pub=&rfr_id=info%3Asid%2F%3A&rft.date=2009&rft.au=Foo+Bar&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() {
|
function testMultiSearch() {
|
||||||
@@ -578,6 +599,31 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals("@string{foo={Foo}}",$btb->stringdb['foo']->toString());
|
$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() {
|
function test_identity() {
|
||||||
$btb = new BibDataBase();
|
$btb = new BibDataBase();
|
||||||
$btb->load('bibacid-utf8.bib');
|
$btb->load('bibacid-utf8.bib');
|
||||||
|
|||||||
+41
-15
@@ -1676,28 +1676,28 @@ class BibEntry {
|
|||||||
|
|
||||||
/** Returns the raw, undecorated abbreviation depending on ABBRV_TYPE. */
|
/** Returns the raw, undecorated abbreviation depending on ABBRV_TYPE. */
|
||||||
function getRawAbbrv() {
|
function getRawAbbrv() {
|
||||||
if (ABBRV_TYPE == 'index') return $this->index;
|
if (c('ABBRV_TYPE') == 'index') return $this->index;
|
||||||
if (ABBRV_TYPE == 'none') return '';
|
if (c('ABBRV_TYPE') == 'none') return '';
|
||||||
if (ABBRV_TYPE == 'key') return $this->getKey();
|
if (c('ABBRV_TYPE') == 'key') return $this->getKey();
|
||||||
if (ABBRV_TYPE == 'year') return $this->getYear();
|
if (c('ABBRV_TYPE') == 'year') return $this->getYear();
|
||||||
if (ABBRV_TYPE == 'x-abbrv') {
|
if (c('ABBRV_TYPE') == 'x-abbrv') {
|
||||||
if ($this->hasField('x-abbrv')) {return $this->getField('x-abbrv');}
|
if ($this->hasField('x-abbrv')) {return $this->getField('x-abbrv');}
|
||||||
return $this->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()]; }
|
if (isset($_GET[Q_INNER_KEYS_INDEX])) {return $_GET[Q_INNER_KEYS_INDEX][$this->getKey()]; }
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise it is a user-defined function in bibtexbrowser.local.php
|
// otherwise it is a user-defined function in bibtexbrowser.local.php
|
||||||
$f = ABBRV_TYPE;
|
$f = c('ABBRV_TYPE');
|
||||||
return $f($this);
|
return $f($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the abbreviation, etc [1] if ABBRV_TYPE='index'. */
|
/** Returns the abbreviation, etc [1] if ABBRV_TYPE='index'. */
|
||||||
function getAbbrv() {
|
function getAbbrv() {
|
||||||
$abbrv = $this->getRawAbbrv();
|
$abbrv = $this->getRawAbbrv();
|
||||||
if ( ABBRV_TYPE != 'none' ) {
|
if ( c('ABBRV_TYPE') != 'none' ) {
|
||||||
$abbrv = '['.$abbrv.']';
|
$abbrv = '['.$abbrv.']';
|
||||||
}
|
}
|
||||||
return $abbrv;
|
return $abbrv;
|
||||||
@@ -1768,7 +1768,7 @@ class BibEntry {
|
|||||||
break;
|
break;
|
||||||
case 'definition':
|
case 'definition':
|
||||||
$result .= '<dl class="bibline"><dt class="bibref">';
|
$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;
|
break;
|
||||||
case 'none':
|
case 'none':
|
||||||
break;
|
break;
|
||||||
@@ -3133,11 +3133,41 @@ class SimpleDisplay {
|
|||||||
return _DefaultBibliographyTitle($this->query);
|
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 */
|
/** Displays a set of bibtex entries in an HTML table */
|
||||||
function display() {
|
function display() {
|
||||||
|
|
||||||
uasort($this->entries, 'compare_bib_entries');
|
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) {
|
if ($this->options) {
|
||||||
foreach($this->options as $fname=>$opt) {
|
foreach($this->options as $fname=>$opt) {
|
||||||
$this->$fname($opt,$entries);
|
$this->$fname($opt,$entries);
|
||||||
@@ -3147,7 +3177,7 @@ class SimpleDisplay {
|
|||||||
if (BIBTEXBROWSER_DEBUG) {
|
if (BIBTEXBROWSER_DEBUG) {
|
||||||
echo 'Style: '.bibtexbrowser_configuration('BIBLIOGRAPHYSTYLE').'<br/>';
|
echo 'Style: '.bibtexbrowser_configuration('BIBLIOGRAPHYSTYLE').'<br/>';
|
||||||
echo 'Order: '.ORDER_FUNCTION.'<br/>';
|
echo 'Order: '.ORDER_FUNCTION.'<br/>';
|
||||||
echo 'Abbrv: '.ABBRV_TYPE.'<br/>';
|
echo 'Abbrv: '.c('ABBRV_TYPE').'<br/>';
|
||||||
echo 'Options: '.@implode(',',$this->options).'<br/>';
|
echo 'Options: '.@implode(',',$this->options).'<br/>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3162,16 +3192,12 @@ class SimpleDisplay {
|
|||||||
}
|
}
|
||||||
print_header_layout();
|
print_header_layout();
|
||||||
|
|
||||||
$count = count($this->entries);
|
|
||||||
$i=0;
|
|
||||||
$pred = NULL;
|
$pred = NULL;
|
||||||
foreach ($this->entries as $bib) {
|
foreach ($this->entries as $bib) {
|
||||||
if ($this->changeSection($pred, $bib)) {
|
if ($this->changeSection($pred, $bib)) {
|
||||||
echo $this->sectionHeader($bib, $pred);
|
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);
|
echo $bib->toHTML(true);
|
||||||
|
|
||||||
$pred = $bib;
|
$pred = $bib;
|
||||||
|
|||||||
Reference in New Issue
Block a user