Browse Source

Roll back for xmlns to have standard http links.

pull/66/head
Xiaodong Qi 9 years ago
parent
commit
abc6dc1fed
  1. 140
      bibtexbrowser-test.php
  2. 134
      bibtexbrowser.php

140
bibtexbrowser-test.php

@ -2,10 +2,10 @@
/** PhPUnit tests for bibtexbrowser /** PhPUnit tests for bibtexbrowser
To run them: To run them:
$ phpunit bibtexbrowser-test.php
$ phpunit bibtexbrowser-test.php
With coverage: With coverage:
$ phpunit --coverage-html ./coverage btb-test.php
$ phpunit --coverage-html ./coverage btb-test.php
(be sure that xdebug is enabled: /etc/php5/cli/conf.d# ln -s ../../mods-available/xdebug.ini) (be sure that xdebug is enabled: /etc/php5/cli/conf.d# ln -s ../../mods-available/xdebug.ini)
*/ */
@ -22,7 +22,7 @@ error_reporting(E_ALL);
@copy('bibtexbrowser.local.php','bibtexbrowser.local.php.bak'); @copy('bibtexbrowser.local.php','bibtexbrowser.local.php.bak');
@unlink('bibtexbrowser.local.php'); @unlink('bibtexbrowser.local.php');
if(is_file('reflectivedoc.php')) {
if(is_file('reflectivedoc.php')) {
set_error_handler("exception_error_handler"); set_error_handler("exception_error_handler");
require('reflectivedoc.php'); require('reflectivedoc.php');
$_GET['library'] = 1; $_GET['library'] = 1;
@ -47,13 +47,13 @@ class BTBTest extends PHPUnit_Framework_TestCase {
if (!function_exists('gk_wiki2html')) { include('gakowiki-syntax.php'); } if (!function_exists('gk_wiki2html')) { include('gakowiki-syntax.php'); }
create_wiki_parser()->parse(file_get_contents('bibtexbrowser-documentation.wiki')); create_wiki_parser()->parse(file_get_contents('bibtexbrowser-documentation.wiki'));
} }
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=2009}\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");
} }
function _createDB($content, $fakefilename="inline") { function _createDB($content, $fakefilename="inline") {
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
fwrite($test_data, $content); fwrite($test_data, $content);
@ -67,15 +67,15 @@ class BTBTest extends PHPUnit_Framework_TestCase {
function test_bibentry_to_html_book() { function test_bibentry_to_html_book() {
$btb = $this->createDB(); $btb = $this->createDB();
$first_entry=$btb->getEntryByKey('aKey'); $first_entry=$btb->getEntryByKey('aKey');
// default style // default style
$this->assertEquals("A Book (Martin Monperrus), Springer, 2009. [bibtex]",strip_tags($first_entry->toHTML())); $this->assertEquals("A Book (Martin Monperrus), Springer, 2009. [bibtex]",strip_tags($first_entry->toHTML()));
$this->assertEquals('<span itemscope="" itemtype="https://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">A Book</span> (<span class="bibauthor"><span itemprop="author" itemtype="https://schema.org/Person">Martin Monperrus</span></span>), <span class="bibpublisher">Springer</span>, <span itemprop="datePublished">2009</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.btitle=A+Book&amp;rft.genre=book&amp;rft.pub=Springer&amp;rfr_id=info%3Asid%2F%3A&amp;rft.date=2009&amp;rft.au=Martin+Monperrus"></span></span> <span class="bibmenu"><a class="biburl" title="aKey" href="bibtexbrowser.php?key=aKey&amp;bib=inline">[bibtex]</a></span>',$first_entry->toHTML());
$this->assertEquals('<span itemscope="" itemtype="http://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">A Book</span> (<span class="bibauthor"><span itemprop="author" itemtype="https://schema.org/Person">Martin Monperrus</span></span>), <span class="bibpublisher">Springer</span>, <span itemprop="datePublished">2009</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.btitle=A+Book&amp;rft.genre=book&amp;rft.pub=Springer&amp;rfr_id=info%3Asid%2F%3A&amp;rft.date=2009&amp;rft.au=Martin+Monperrus"></span></span> <span class="bibmenu"><a class="biburl" title="aKey" href="bibtexbrowser.php?key=aKey&amp;bib=inline">[bibtex]</a></span>',$first_entry->toHTML());
// IEEE style // IEEE style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle'); bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle');
$this->assertEquals("Martin Monperrus, \"A Book\", Springer, 2009.\n [bibtex]",strip_tags($first_entry->toHTML())); $this->assertEquals("Martin Monperrus, \"A Book\", Springer, 2009.\n [bibtex]",strip_tags($first_entry->toHTML()));
// Vancouver style // Vancouver style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','VancouverBibliographyStyle'); bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','VancouverBibliographyStyle');
$this->assertEquals("Martin Monperrus. A Book. Springer; 2009.\n [bibtex]",strip_tags($first_entry->toHTML())); $this->assertEquals("Martin Monperrus. A Book. Springer; 2009.\n [bibtex]",strip_tags($first_entry->toHTML()));
@ -91,24 +91,24 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals("1-2",$first_entry->getField("pages")); $this->assertEquals("1-2",$first_entry->getField("pages"));
$this->assertEquals("1",$first_entry->getPages()[0]); $this->assertEquals("1",$first_entry->getPages()[0]);
$this->assertEquals("2",$first_entry->getPages()[1]); $this->assertEquals("2",$first_entry->getPages()[1]);
// default style // default style
$this->assertEquals("An Article (Foo Bar and Jane Doe), In New Results, volume 5, 2009. [bibtex]",strip_tags($first_entry->toHTML())); $this->assertEquals("An Article (Foo Bar and Jane Doe), In New Results, volume 5, 2009. [bibtex]",strip_tags($first_entry->toHTML()));
$this->assertEquals('<span itemscope="" itemtype="https://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">An Article</span> (<span class="bibauthor"><span itemprop="author" itemtype="https://schema.org/Person">Foo Bar</span> and <span itemprop="author" itemtype="https://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> <span class="bibmenu"><a class="biburl" title="aKeyA" href="bibtexbrowser.php?key=aKeyA&amp;bib=inline">[bibtex]</a></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="https://schema.org/Person">Foo Bar</span> and <span itemprop="author" itemtype="https://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> <span class="bibmenu"><a class="biburl" title="aKeyA" href="bibtexbrowser.php?key=aKeyA&amp;bib=inline">[bibtex]</a></span>',$first_entry->toHTML());
// IEEE style // IEEE style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle'); bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle');
$this->assertEquals("Foo Bar and Jane Doe, \"An Article\", In New Results, vol. 5, pp. 1-2, 2009.\n [bibtex]",strip_tags($first_entry->toHTML())); $this->assertEquals("Foo Bar and Jane Doe, \"An Article\", In New Results, vol. 5, pp. 1-2, 2009.\n [bibtex]",strip_tags($first_entry->toHTML()));
// Vancouver style // Vancouver style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','VancouverBibliographyStyle'); bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','VancouverBibliographyStyle');
$this->assertEquals("Foo Bar and Jane Doe. An Article. New Results. 2009;5:1-2.\n [bibtex]",strip_tags($first_entry->toHTML())); $this->assertEquals("Foo Bar and Jane Doe. An Article. New Results. 2009;5:1-2.\n [bibtex]",strip_tags($first_entry->toHTML()));
// changing the target // changing the target
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','DefaultBibliographyStyle'); bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','DefaultBibliographyStyle');
bibtexbrowser_configure('BIBTEXBROWSER_LINKS_TARGET','_top'); bibtexbrowser_configure('BIBTEXBROWSER_LINKS_TARGET','_top');
$this->assertEquals('<span itemscope="" itemtype="https://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">An Article</span> (<span class="bibauthor"><span itemprop="author" itemtype="https://schema.org/Person">Foo Bar</span> and <span itemprop="author" itemtype="https://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> <span class="bibmenu"><a target="_top" class="biburl" title="aKeyA" href="bibtexbrowser.php?key=aKeyA&amp;bib=inline">[bibtex]</a></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="https://schema.org/Person">Foo Bar</span> and <span itemprop="author" itemtype="https://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> <span class="bibmenu"><a target="_top" class="biburl" title="aKeyA" href="bibtexbrowser.php?key=aKeyA&amp;bib=inline">[bibtex]</a></span>',$first_entry->toHTML());
} }
function testMultiSearch() { function testMultiSearch() {
@ -119,7 +119,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(count($results) == 1); $this->assertTrue(count($results) == 1);
$this->assertTrue($entry->getTitle() == 'A Book'); $this->assertTrue($entry->getTitle() == 'A Book');
} }
function testMultiSearch2() { function testMultiSearch2() {
$btb = $this->createDB(); $btb = $this->createDB();
$q=array(Q_AUTHOR=>'monperrus|ducasse'); $q=array(Q_AUTHOR=>'monperrus|ducasse');
@ -131,31 +131,31 @@ class BTBTest extends PHPUnit_Framework_TestCase {
function test_config_value() { function test_config_value() {
// default value // default value
$this->assertFalse(config_value('BIBTEXBROWSER_NO_DEFAULT'));
$this->assertFalse(config_value('BIBTEXBROWSER_NO_DEFAULT'));
// setting to true // setting to true
bibtexbrowser_configure('BIBTEXBROWSER_NO_DEFAULT', true); bibtexbrowser_configure('BIBTEXBROWSER_NO_DEFAULT', true);
$this->assertTrue(config_value('BIBTEXBROWSER_NO_DEFAULT'));
$this->assertTrue(config_value('BIBTEXBROWSER_NO_DEFAULT'));
ob_start(); ob_start();
default_message(); default_message();
$this->assertEquals('', ob_get_clean()); $this->assertEquals('', ob_get_clean());
// setting to false // setting to false
bibtexbrowser_configure('BIBTEXBROWSER_NO_DEFAULT', false); bibtexbrowser_configure('BIBTEXBROWSER_NO_DEFAULT', false);
$this->assertFalse(config_value('BIBTEXBROWSER_NO_DEFAULT'));
$this->assertFalse(config_value('BIBTEXBROWSER_NO_DEFAULT'));
ob_start(); ob_start();
default_message(); default_message();
$this->assertContains('Congratulations', ob_get_clean()); $this->assertContains('Congratulations', ob_get_clean());
} }
function testInternationalization() { function testInternationalization() {
$btb = $this->createDB(); $btb = $this->createDB();
global $BIBTEXBROWSER_LANG; global $BIBTEXBROWSER_LANG;
$BIBTEXBROWSER_LANG=array(); $BIBTEXBROWSER_LANG=array();
$BIBTEXBROWSER_LANG['Refereed Conference Papers']="foo"; $BIBTEXBROWSER_LANG['Refereed Conference Papers']="foo";
$this->assertEquals("foo",__("Refereed Conference Papers")); $this->assertEquals("foo",__("Refereed Conference Papers"));
$BIBTEXBROWSER_LANG['Books']="Livres"; $BIBTEXBROWSER_LANG['Books']="Livres";
$d = new AcademicDisplay(); $d = new AcademicDisplay();
$d->setDB($btb); $d->setDB($btb);
@ -165,7 +165,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertContains('Livres', $data); $this->assertContains('Livres', $data);
} }
function testNoSlashInKey() { function testNoSlashInKey() {
$btb = $this->createDB(); $btb = $this->createDB();
$q=array(Q_SEARCH=>'Slash'); $q=array(Q_SEARCH=>'Slash');
@ -179,7 +179,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$entry2 = $results[0]; $entry2 = $results[0];
$this->assertSame($entry2,$entry); $this->assertSame($entry2,$entry);
} }
function test_string_should_be_deleted_after_update() { function test_string_should_be_deleted_after_update() {
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n". fwrite($test_data, "@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n".
@ -190,7 +190,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$btb->update_internal("inline", $test_data); $btb->update_internal("inline", $test_data);
// print_r($btb->stringdb); // print_r($btb->stringdb);
$this->assertEquals(1,count($btb->stringdb)); $this->assertEquals(1,count($btb->stringdb));
// replacing the existing one // replacing the existing one
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey2,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n". fwrite($test_data, "@book{aKey2,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n".
@ -201,17 +201,17 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$btb->update_internal("inline2", $test_data); $btb->update_internal("inline2", $test_data);
// print_r($btb->stringdb); // print_r($btb->stringdb);
$this->assertEquals(1,count($btb->stringdb)); $this->assertEquals(1,count($btb->stringdb));
$this->assertEquals("2009",$btb->stringdb['x']->value);//
$this->assertEquals("2009",$btb->stringdb['x']->value);//
// now adding another one and removing the string // now adding another one and removing the string
$test_data2 = fopen('php://memory','x+'); $test_data2 = fopen('php://memory','x+');
fwrite($test_data2, "@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n". fwrite($test_data2, "@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n".
"@String{y=2010}\n" "@String{y=2010}\n"
); );
fseek($test_data2,0);
fseek($test_data2,0);
$btb->update_internal("inline2", $test_data2); $btb->update_internal("inline2", $test_data2);
$this->assertEquals(1,count($btb->stringdb));//
$this->assertEquals("2010",$btb->stringdb['y']->value);//
$this->assertEquals(1,count($btb->stringdb));//
$this->assertEquals("2010",$btb->stringdb['y']->value);//
} }
@ -232,9 +232,9 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals("42",$metadata['citation_firstpage']); $this->assertEquals("42",$metadata['citation_firstpage']);
$this->assertEquals("4242",$metadata['citation_lastpage']); $this->assertEquals("4242",$metadata['citation_lastpage']);
$this->assertEquals("1",$metadata['citation_issue']); $this->assertEquals("1",$metadata['citation_issue']);
} }
function test_metadata_opengraph() { function test_metadata_opengraph() {
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
fwrite($test_data, "@article{aKey,title={A Book},author={Martin Monperrus},url={http://foo.com/},publisher={Springer},year=2009,pages={42--4242},number=1}\n". fwrite($test_data, "@article{aKey,title={A Book},author={Martin Monperrus},url={http://foo.com/},publisher={Springer},year=2009,pages={42--4242},number=1}\n".
@ -245,15 +245,15 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$db->update_internal("inline", $test_data); $db->update_internal("inline", $test_data);
$dis = new BibEntryDisplay($db->getEntryByKey('aKey')); $dis = new BibEntryDisplay($db->getEntryByKey('aKey'));
$metadata = $dis->metadata_dict(); $metadata = $dis->metadata_dict();
//print_r($metadata); //print_r($metadata);
$this->assertEquals("A Book",$metadata['og:title']); $this->assertEquals("A Book",$metadata['og:title']);
$this->assertEquals("article",$metadata['og:type']); $this->assertEquals("article",$metadata['og:type']);
$this->assertTrue(1 == preg_match("/http:.*author=Martin\+Monperrus/",$metadata['og:author'])); $this->assertTrue(1 == preg_match("/http:.*author=Martin\+Monperrus/",$metadata['og:author']));
$this->assertEquals("2009",$metadata['og:published_time']);
$this->assertEquals("2009",$metadata['og:published_time']);
} }
function test_math_cal() { function test_math_cal() {
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey,title={{A {Book} $\mbox{foo}$ tt $\boo{t}$}} ,author={Martin Monperrus},publisher={Springer},year=2009}\n". fwrite($test_data, "@book{aKey,title={{A {Book} $\mbox{foo}$ tt $\boo{t}$}} ,author={Martin Monperrus},publisher={Springer},year=2009}\n".
@ -261,24 +261,24 @@ class BTBTest extends PHPUnit_Framework_TestCase {
); );
fseek($test_data,0); fseek($test_data,0);
$btb = new BibDataBase(); $btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
$btb->update_internal("inline", $test_data);
$first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]]; $first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]];
// $this->assertTrue(strpos('A Book{} $\mbox{foo}$',$first_entry->toHTML());
$this->assertEquals('A Book $\mbox{foo}$ tt $\boo{t}$',$first_entry->getTitle());
// $this->assertTrue(strpos('A Book{} $\mbox{foo}$',$first_entry->toHTML());
$this->assertEquals('A Book $\mbox{foo}$ tt $\boo{t}$',$first_entry->getTitle());
} }
function test_link_configuration() { function test_link_configuration() {
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey,pdf={myarticle.pdf}}\n" fwrite($test_data, "@book{aKey,pdf={myarticle.pdf}}\n"
); );
fseek($test_data,0); fseek($test_data,0);
$btb = new BibDataBase(); $btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
$btb->update_internal("inline", $test_data);
$first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]]; $first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]];
$this->assertEquals('<a href="myarticle.pdf">[pdf]</a>',$first_entry->getLink('pdf'));
$this->assertEquals('<a href="myarticle.pdf">[pdf]</a>',$first_entry->getPdfLink());
$this->assertEquals('<a href="myarticle.pdf">[pdf]</a>',$first_entry->getLink('pdf'));
$this->assertEquals('<a href="myarticle.pdf">[pdf]</a>',$first_entry->getPdfLink());
$this->assertEquals('<a href="myarticle.pdf"><img class="icon" src="pdficon.png" alt="[pdf]" title="pdf"/></a>',$first_entry->getLink('pdf','pdficon.png')); $this->assertEquals('<a href="myarticle.pdf"><img class="icon" src="pdficon.png" alt="[pdf]" title="pdf"/></a>',$first_entry->getLink('pdf','pdficon.png'));
$this->assertEquals('<a href="myarticle.pdf">[see]</a>',$first_entry->getLink('pdf',NULL,'see'));
$this->assertEquals('<a href="myarticle.pdf">[see]</a>',$first_entry->getLink('pdf',NULL,'see'));
} }
// see https://github.com/monperrus/bibtexbrowser/pull/14 // see https://github.com/monperrus/bibtexbrowser/pull/14
@ -288,9 +288,9 @@ class BTBTest extends PHPUnit_Framework_TestCase {
); );
fseek($test_data,0); fseek($test_data,0);
$btb = new BibDataBase(); $btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
$btb->update_internal("inline", $test_data);
$first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]]; $first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]];
$this->assertEquals('<a href="myarticle.pdf">[pdf]</a>',$first_entry->getPdfLink());
$this->assertEquals('<a href="myarticle.pdf">[pdf]</a>',$first_entry->getPdfLink());
} }
// https://github.com/monperrus/bibtexbrowser/issues/40 // https://github.com/monperrus/bibtexbrowser/issues/40
@ -300,9 +300,9 @@ class BTBTest extends PHPUnit_Framework_TestCase {
); );
fseek($test_data,0); fseek($test_data,0);
$btb = new BibDataBase(); $btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
$btb->update_internal("inline", $test_data);
$first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]]; $first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]];
$this->assertEquals('<pre class="purebibtex">@Article{Baldwin2014Quantum,Doi={<a href="https://dx.doi.org/10.1103/PhysRevA.90.012110">10.1103/PhysRevA.90.012110</a>},Url={<a href="http://link.aps.org/doi/10.1103/PhysRevA.90.012110">http://link.aps.org/doi/10.1103/PhysRevA.90.012110</a>}}</pre>',$first_entry->toEntryUnformatted());
$this->assertEquals('<pre class="purebibtex">@Article{Baldwin2014Quantum,Doi={<a href="https://dx.doi.org/10.1103/PhysRevA.90.012110">10.1103/PhysRevA.90.012110</a>},Url={<a href="http://link.aps.org/doi/10.1103/PhysRevA.90.012110">http://link.aps.org/doi/10.1103/PhysRevA.90.012110</a>}}</pre>',$first_entry->toEntryUnformatted());
} }
function test_filter_view() { function test_filter_view() {
@ -313,7 +313,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$db->update_internal("inline", $test_data); $db->update_internal("inline", $test_data);
$dis = $db->getEntryByKey('aKey'); $dis = $db->getEntryByKey('aKey');
$this->assertEquals("@article{aKey,title={A Book},author={Martin M\'e},publisher={Springer},year=2009,pages={42--4242},number=1}",$dis->getText()); $this->assertEquals("@article{aKey,title={A Book},author={Martin M\'e},publisher={Springer},year=2009,pages={42--4242},number=1}",$dis->getText());
// now ith option // now ith option
bibtexbrowser_configure('BIBTEXBROWSER_BIBTEX_VIEW', 'reconstructed'); bibtexbrowser_configure('BIBTEXBROWSER_BIBTEX_VIEW', 'reconstructed');
bibtexbrowser_configure('BIBTEXBROWSER_BIBTEX_VIEW_FILTEREDOUT', 'pages|number'); bibtexbrowser_configure('BIBTEXBROWSER_BIBTEX_VIEW_FILTEREDOUT', 'pages|number');
@ -322,7 +322,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
function test_BIBTEXBROWSER_USE_LATEX2HTML() { function test_BIBTEXBROWSER_USE_LATEX2HTML() {
$bibtex = "@article{aKey,title={\`a Book},author={J\'e Lo},publisher={Springer},year=2009,pages={42--4242},number=1}\n"; $bibtex = "@article{aKey,title={\`a Book},author={J\'e Lo},publisher={Springer},year=2009,pages={42--4242},number=1}\n";
bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', true); bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', true);
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
fwrite($test_data, $bibtex); fwrite($test_data, $bibtex);
@ -332,7 +332,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$dis = $db->getEntryByKey('aKey'); $dis = $db->getEntryByKey('aKey');
$this->assertEquals("à Book",$dis->getTitle()); $this->assertEquals("à Book",$dis->getTitle());
$this->assertEquals("Jé Lo",$dis->getFormattedAuthorsString()); $this->assertEquals("Jé Lo",$dis->getFormattedAuthorsString());
bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', false); bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', false);
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
fwrite($test_data, $bibtex); fwrite($test_data, $bibtex);
@ -344,7 +344,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals("J\'e Lo",$dis->getFormattedAuthorsString()); $this->assertEquals("J\'e Lo",$dis->getFormattedAuthorsString());
} }
function test_PagedDisplay() { function test_PagedDisplay() {
$PAGE_SIZE = 3; $PAGE_SIZE = 3;
bibtexbrowser_configure('BIBTEXBROWSER_DEFAULT_DISPLAY', 'PagedDisplay'); bibtexbrowser_configure('BIBTEXBROWSER_DEFAULT_DISPLAY', 'PagedDisplay');
@ -357,7 +357,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$content = "<div>".ob_get_clean()."</div>"; $content = "<div>".ob_get_clean()."</div>";
$xml = new SimpleXMLElement($content); $xml = new SimpleXMLElement($content);
$result = $xml->xpath('//td[@class=\'bibref\']'); $result = $xml->xpath('//td[@class=\'bibref\']');
$this->assertEquals($PAGE_SIZE,count($result));
$this->assertEquals($PAGE_SIZE,count($result));
} }
function test_getKeywords() { function test_getKeywords() {
@ -396,13 +396,13 @@ class BTBTest extends PHPUnit_Framework_TestCase {
fseek($test_data,0); fseek($test_data,0);
$db = new BibDataBase(); $db = new BibDataBase();
$db->update_internal("inline", $test_data); $db->update_internal("inline", $test_data);
$dis = $db->getEntryByKey('aKey'); $dis = $db->getEntryByKey('aKey');
$this->assertEquals("",$dis->getPdfLink()); $this->assertEquals("",$dis->getPdfLink());
$dis = $db->getEntryByKey('bKey'); $dis = $db->getEntryByKey('bKey');
$this->assertEquals('<a href="magic.pdf">[pdf]</a>',$dis->getPdfLink()); $this->assertEquals('<a href="magic.pdf">[pdf]</a>',$dis->getPdfLink());
$dis = $db->getEntryByKey('cKey'); $dis = $db->getEntryByKey('cKey');
$this->assertEquals('<a href="magic2.pdf">[pdf]</a>',$dis->getPdfLink()); $this->assertEquals('<a href="magic2.pdf">[pdf]</a>',$dis->getPdfLink());
} }
@ -416,7 +416,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$db = new BibDataBase(); $db = new BibDataBase();
$db->update_internal("inline", $test_data); $db->update_internal("inline", $test_data);
$entry = $db->getEntryByKey('aKey61'); $entry = $db->getEntryByKey('aKey61');
// test with formatting with default options same as getRawAuthors() // test with formatting with default options same as getRawAuthors()
$authors = $entry->getFormattedAuthorsArray(); $authors = $entry->getFormattedAuthorsArray();
$this->assertEquals(3, count($authors)); $this->assertEquals(3, count($authors));
@ -447,7 +447,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
// test with first_name last_name formatAuthorCanonical // test with first_name last_name formatAuthorCanonical
bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', false); bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', false);
bibtexbrowser_configure('USE_INITIALS_FOR_NAMES', false); bibtexbrowser_configure('USE_INITIALS_FOR_NAMES', false);
bibtexbrowser_configure('USE_FIRST_THEN_LAST', true);
bibtexbrowser_configure('USE_FIRST_THEN_LAST', true);
$authors = $entry->getFormattedAuthorsArray(); $authors = $entry->getFormattedAuthorsArray();
$this->assertEquals(3, count($authors)); $this->assertEquals(3, count($authors));
$this->assertEquals("Heribert Meyer", $authors[0]); $this->assertEquals("Heribert Meyer", $authors[0]);
@ -484,7 +484,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(2,count($authors)); $this->assertEquals(2,count($authors));
$this->assertEquals("Meyer, Heribert", $authors[0]); $this->assertEquals("Meyer, Heribert", $authors[0]);
$this->assertEquals("Meyer, Heribert and Foo Bar", $entry->getFormattedAuthorsString()); $this->assertEquals("Meyer, Heribert and Foo Bar", $entry->getFormattedAuthorsString());
// Github issue 61 // Github issue 61
$bibtex = "@article{aKey61,title={An article Book},author = {Meyer, Heribert and {Advanced Air and Ground Research Team} and Foo Bar and J{\'e} Ko and J{\'e} Le and Fd L{\'e}}}\n"; $bibtex = "@article{aKey61,title={An article Book},author = {Meyer, Heribert and {Advanced Air and Ground Research Team} and Foo Bar and J{\'e} Ko and J{\'e} Le and Fd L{\'e}}}\n";
// wrong parsing of author names // wrong parsing of author names
@ -503,12 +503,12 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals("J{\'e} Le", $authors[4]); $this->assertEquals("J{\'e} Le", $authors[4]);
$this->assertEquals("Fd L{\'e}", $authors[5]); $this->assertEquals("Fd L{\'e}", $authors[5]);
} }
function test_latex2html() { function test_latex2html() {
$this->assertEquals('"', latex2html("``"));
$this->assertEquals('"', latex2html("''"));
$this->assertEquals('&eacute;', latex2html("\'e"));
$this->assertEquals('&eacute;', latex2html("{\'e}"));
$this->assertEquals('"', latex2html("``"));
$this->assertEquals('"', latex2html("''"));
$this->assertEquals('&eacute;', latex2html("\'e"));
$this->assertEquals('&eacute;', latex2html("{\'e}"));
} }
function test_homepage_link() { function test_homepage_link() {
@ -524,9 +524,9 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('<a href="http://example.net/">Foo Acé</a>', $authors[1]); $this->assertEquals('<a href="http://example.net/">Foo Acé</a>', $authors[1]);
$this->assertEquals('<a href="http://www.monperrus.net/martin">Monperrus, Martin</a>', $authors[2]); $this->assertEquals('<a href="http://www.monperrus.net/martin">Monperrus, Martin</a>', $authors[2]);
} }
function test_author_index() { function test_author_index() {
bibtexbrowser_configure('USE_FIRST_THEN_LAST', true);
bibtexbrowser_configure('USE_FIRST_THEN_LAST', true);
$bibtex = "@string{hp_MartinMonperrus={http://www.monperrus.net/martin},hp_FooAcé={http://example.net/}},@article{aKey61,title={An article Book},author = {Martin Monperrus and Foo Ac\'e and Monperrus, Martin}}\n"; $bibtex = "@string{hp_MartinMonperrus={http://www.monperrus.net/martin},hp_FooAcé={http://example.net/}},@article{aKey61,title={An article Book},author = {Martin Monperrus and Foo Ac\'e and Monperrus, Martin}}\n";
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
@ -545,18 +545,18 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(5, count($btb->stringdb)); $this->assertEquals(5, count($btb->stringdb));
$this->assertEquals("@string{foo={Foo}}",$btb->stringdb['foo']->toString()); $this->assertEquals("@string{foo={Foo}}",$btb->stringdb['foo']->toString());
} }
function test_identity() { function test_identity() {
$btb = new BibDataBase(); $btb = new BibDataBase();
$btb->load('bibacid-utf8.bib'); $btb->load('bibacid-utf8.bib');
// computing the representation // computing the representation
$d = new SimpleDisplay(); $d = new SimpleDisplay();
$d->setDB($btb); $d->setDB($btb);
ob_start(); ob_start();
$d->display(); $d->display();
$rep = ob_get_clean(); $rep = ob_get_clean();
$nref = count($btb->bibdb); $nref = count($btb->bibdb);
$bibtex = $btb->toBibtex(); $bibtex = $btb->toBibtex();
// reparsing the new content // reparsing the new content
@ -571,14 +571,14 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($rep, $rep2); $this->assertEquals($rep, $rep2);
} }
function test_cli() {
function test_cli() {
$test_file="test_cli.bib"; $test_file="test_cli.bib";
copy('bibacid-utf8.bib', $test_file); copy('bibacid-utf8.bib', $test_file);
system('php bibtexbrowser-cli.php '.$test_file." --id classical --set-title \"a new title\""); system('php bibtexbrowser-cli.php '.$test_file." --id classical --set-title \"a new title\"");
$db = new BibDataBase(); $db = new BibDataBase();
$db->load($test_file); $db->load($test_file);
$this->assertEquals("a new title", $db->getEntryByKey('classical')->getField('title')); $this->assertEquals("a new title", $db->getEntryByKey('classical')->getField('title'));
// multiple changes // multiple changes
system('php bibtexbrowser-cli.php '.$test_file." --id classical --set-title \"a new title\" --id with_abstract --set-title \"a new title\" --set-year 1990"); system('php bibtexbrowser-cli.php '.$test_file." --id classical --set-title \"a new title\" --id with_abstract --set-title \"a new title\" --set-year 1990");
$db = new BibDataBase(); $db = new BibDataBase();
@ -594,7 +594,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$btb = $this->createDB(); $btb = $this->createDB();
$first_entry=$btb->getEntryByKey('aKey'); $first_entry=$btb->getEntryByKey('aKey');
$this->assertTrue($first_entry->hasField('author')); $this->assertTrue($first_entry->hasField('author'));
$first_entry->removeField('author');
$first_entry->removeField('author');
$this->assertFalse($first_entry->hasField('author')); $this->assertFalse($first_entry->hasField('author'));
} }
@ -622,7 +622,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$entry=$db->getEntryByKey("key"); $entry=$db->getEntryByKey("key");
$this->assertContains('<a href="https://scholar.google.com/scholar?cites=1234">[citations]</a>', $entry->toHTML()); $this->assertContains('<a href="https://scholar.google.com/scholar?cites=1234">[citations]</a>', $entry->toHTML());
} }
} // end class } // end class
@copy('bibtexbrowser.local.php.bak','bibtexbrowser.local.php'); @copy('bibtexbrowser.local.php.bak','bibtexbrowser.local.php');

134
bibtexbrowser.php

@ -603,7 +603,7 @@ class StateBasedBibtexParser {
else if ($s==' ' || $s=="\t" || $s=="\n" || $s=="\r" ) { else if ($s==' ' || $s=="\t" || $s=="\n" || $s=="\r" ) {
// blank characters are not taken into account when values are not in quotes or curly brackets // blank characters are not taken into account when values are not in quotes or curly brackets
} }
else {
else {
$entryvalue=$entryvalue.$s; $entryvalue=$entryvalue.$s;
} }
} }
@ -619,13 +619,13 @@ class StateBasedBibtexParser {
$state = GETVALUEDELIMITEDBYCURLYBRACKETS_1NESTEDLEVEL; $state = GETVALUEDELIMITEDBYCURLYBRACKETS_1NESTEDLEVEL;
$entryvalue=$entryvalue.$s; $entryvalue=$entryvalue.$s;
$delegate->entryValuePart($finalkey,$fieldvaluepart,'CURLYTOP'); $delegate->entryValuePart($finalkey,$fieldvaluepart,'CURLYTOP');
$fieldvaluepart='';
$fieldvaluepart='';
} }
else if ($s=='}') { // end entry else if ($s=='}') { // end entry
$state = GETVALUE; $state = GETVALUE;
$delegate->entryValuePart($finalkey,$fieldvaluepart,'CURLYTOP'); $delegate->entryValuePart($finalkey,$fieldvaluepart,'CURLYTOP');
} }
else {
else {
$entryvalue=$entryvalue.$s; $entryvalue=$entryvalue.$s;
$fieldvaluepart=$fieldvaluepart.$s; $fieldvaluepart=$fieldvaluepart.$s;
} }
@ -648,7 +648,7 @@ class StateBasedBibtexParser {
$fieldvaluepart=''; $fieldvaluepart='';
$entryvalue=$entryvalue.$s; $entryvalue=$entryvalue.$s;
} }
else {
else {
$entryvalue=$entryvalue.$s; $entryvalue=$entryvalue.$s;
$fieldvaluepart=$fieldvaluepart.$s; $fieldvaluepart=$fieldvaluepart.$s;
} }
@ -731,12 +731,12 @@ class ParserDelegate {
function beginEntry() {} function beginEntry() {}
function endEntry($entrysource) {} function endEntry($entrysource) {}
/** called for each sub parts of type {part} of a field value
/** called for each sub parts of type {part} of a field value
* for now, only CURLYTOP and CURLYONE events * for now, only CURLYTOP and CURLYONE events
*/ */
function entryValuePart($key, $value, $type) {} function entryValuePart($key, $value, $type) {}
} // end class ParserDelegate } // end class ParserDelegate
@ -783,7 +783,7 @@ class StringEntry {
$this->value=$v; $this->value=$v;
$this->filename=$filename; $this->filename=$filename;
} }
function toString() { function toString() {
return '@string{'.$this->name.'={'.$this->value.'}}'; return '@string{'.$this->name.'={'.$this->value.'}}';
} }
@ -921,7 +921,7 @@ class BibDBBuilder extends ParserDelegate {
// to enable search // to enable search
if ($this->currentEntry->hasField('author')) { if ($this->currentEntry->hasField('author')) {
$this->currentEntry->setField(Q_INNER_AUTHOR,$this->currentEntry->getFormattedAuthorsString()); $this->currentEntry->setField(Q_INNER_AUTHOR,$this->currentEntry->getFormattedAuthorsString());
foreach($this->currentEntry->getCanonicalAuthors() as $author) { foreach($this->currentEntry->getCanonicalAuthors() as $author) {
$homepage_key = $this->currentEntry->getHomePageKey($author); $homepage_key = $this->currentEntry->getHomePageKey($author);
if (isset($this->stringdb[$homepage_key])) { if (isset($this->stringdb[$homepage_key])) {
@ -945,9 +945,9 @@ class BibDBBuilder extends ParserDelegate {
// we add it to the database // we add it to the database
else { else {
$this->builtdb[$this->currentEntry->getKey()] = $this->currentEntry; $this->builtdb[$this->currentEntry->getKey()] = $this->currentEntry;
}
}
} }
} // end class BibDBBuilder } // end class BibDBBuilder
@ -1087,7 +1087,7 @@ function latex2html($line, $do_clean_extra_bracket=true) {
$line = str_replace('}','',$line); $line = str_replace('}','',$line);
$line = str_replace('{','',$line); $line = str_replace('{','',$line);
} }
// we restore the math env // we restore the math env
for($i = 0; $i < count($maths); $i++) { for($i = 0; $i < count($maths); $i++) {
$line = str_replace('__MATH'.$i.'__', $maths[$i], $line); $line = str_replace('__MATH'.$i.'__', $maths[$i], $line);
@ -1200,7 +1200,7 @@ class BibEntry {
} }
function transformValue($value) { function transformValue($value) {
if (c('BIBTEXBROWSER_USE_LATEX2HTML'))
if (c('BIBTEXBROWSER_USE_LATEX2HTML'))
{ {
// trim space // trim space
$value = xtrim($value); $value = xtrim($value);
@ -1208,7 +1208,7 @@ class BibEntry {
// transform Latex markup to HTML entities (easier than a one to one mapping to each character) // transform Latex markup to HTML entities (easier than a one to one mapping to each character)
// HTML entity is an intermediate format // HTML entity is an intermediate format
$value = latex2html($value); $value = latex2html($value);
// transform to the target output encoding // transform to the target output encoding
$value = html_entity_decode($value, ENT_QUOTES|ENT_XHTML, OUTPUT_ENCODING); $value = html_entity_decode($value, ENT_QUOTES|ENT_XHTML, OUTPUT_ENCODING);
} }
@ -1219,21 +1219,21 @@ class BibEntry {
function removeField($name) { function removeField($name) {
$name = strtolower($name); $name = strtolower($name);
unset($this->raw_fields[$name]); unset($this->raw_fields[$name]);
unset($this->fields[$name]);
unset($this->fields[$name]);
} }
/** Sets a field of this bib entry. */ /** Sets a field of this bib entry. */
function setField($name, $value) { function setField($name, $value) {
$name = strtolower($name); $name = strtolower($name);
$this->raw_fields[$name] = $value; $this->raw_fields[$name] = $value;
// fields that should not be transformed // fields that should not be transformed
// we assume that "comment" is never latex code // we assume that "comment" is never latex code
// but instead could contain HTML code (with links using the character "~" for example) // but instead could contain HTML code (with links using the character "~" for example)
// so "comment" is not transformed too // so "comment" is not transformed too
if ($name!='url' && $name!='comment') {
$value = $this->transformValue($value);
if ($name!='url' && $name!='comment') {
$value = $this->transformValue($value);
// 4. transform existing encoded character in the new format // 4. transform existing encoded character in the new format
if (function_exists('mb_convert_encoding') && OUTPUT_ENCODING != BIBTEX_INPUT_ENCODING) { if (function_exists('mb_convert_encoding') && OUTPUT_ENCODING != BIBTEX_INPUT_ENCODING) {
$value = mb_convert_encoding($value, OUTPUT_ENCODING, BIBTEX_INPUT_ENCODING); $value = mb_convert_encoding($value, OUTPUT_ENCODING, BIBTEX_INPUT_ENCODING);
@ -1242,12 +1242,12 @@ class BibEntry {
} else { } else {
//echo "xx".$value."xx\n"; //echo "xx".$value."xx\n";
} }
$this->fields[$name] = $value; $this->fields[$name] = $value;
} }
function clean_top_curly($value) { function clean_top_curly($value) {
$value = preg_replace('/^\{/','', $value); $value = preg_replace('/^\{/','', $value);
$value = preg_replace('/\}$/','', $value); $value = preg_replace('/\}$/','', $value);
@ -1311,7 +1311,7 @@ class BibEntry {
function getUrlLink($iconurl, $label) { function getUrlLink($iconurl, $label) {
return $this->getPdfLink($iconurl, $label); return $this->getPdfLink($iconurl, $label);
} }
/** returns a "[pdf]" link for the entry, if possible. /** returns a "[pdf]" link for the entry, if possible.
Tries to get the target URL from the 'pdf' field first, then from 'url' or 'file'. Tries to get the target URL from the 'pdf' field first, then from 'url' or 'file'.
*/ */
@ -1443,7 +1443,7 @@ class BibEntry {
function getRawAuthors() { function getRawAuthors() {
return $this->split_authors(); return $this->split_authors();
} }
function split_authors() { function split_authors() {
$array = preg_split('/ and /i', @$this->raw_fields[Q_AUTHOR]); $array = preg_split('/ and /i', @$this->raw_fields[Q_AUTHOR]);
$res = array(); $res = array();
@ -1457,29 +1457,29 @@ class BibEntry {
} }
} }
if (!preg_match('/\}/',latex2html($array[count($array)-1],false))) { if (!preg_match('/\}/',latex2html($array[count($array)-1],false))) {
$res[] = trim($array[count($array)-1]);
$res[] = trim($array[count($array)-1]);
} }
return $res; return $res;
} }
/** /**
* Returns the formated author name w.r.t to the user preference
* Returns the formated author name w.r.t to the user preference
* encoded in USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT and USE_INITIALS_FOR_NAMES * encoded in USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT and USE_INITIALS_FOR_NAMES
*/ */
function formatAuthor($author){ function formatAuthor($author){
$author = $this->transformValue($author); $author = $this->transformValue($author);
if (bibtexbrowser_configuration('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT')) { if (bibtexbrowser_configuration('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT')) {
return $this->formatAuthorCommaSeparated($author); return $this->formatAuthorCommaSeparated($author);
}
}
if (bibtexbrowser_configuration('USE_INITIALS_FOR_NAMES')) { if (bibtexbrowser_configuration('USE_INITIALS_FOR_NAMES')) {
return $this->formatAuthorInitials($author); return $this->formatAuthorInitials($author);
}
}
if (bibtexbrowser_configuration('USE_FIRST_THEN_LAST')) { if (bibtexbrowser_configuration('USE_FIRST_THEN_LAST')) {
return $this->formatAuthorCanonical($author); return $this->formatAuthorCanonical($author);
} }
return $author; return $author;
} }
@ -1524,8 +1524,8 @@ class BibEntry {
*/ */
function getFormattedAuthorsArray() { function getFormattedAuthorsArray() {
$array_authors = array(); $array_authors = array();
// first we use formatAuthor // first we use formatAuthor
foreach ($this->getRawAuthors() as $author) { foreach ($this->getRawAuthors() as $author) {
$array_authors[]=$this->formatAuthor($author); $array_authors[]=$this->formatAuthor($author);
@ -1551,11 +1551,11 @@ class BibEntry {
function getFormattedAuthorsString() { function getFormattedAuthorsString() {
return $this->implodeAuthors($this->getFormattedAuthorsArray()); return $this->implodeAuthors($this->getFormattedAuthorsArray());
} }
function implodeAuthors($authors) {
function implodeAuthors($authors) {
if (count($authors)==0) return ''; if (count($authors)==0) return '';
if (count($authors)==1) return $authors[0]; if (count($authors)==1) return $authors[0];
$result = ''; $result = '';
if (bibtexbrowser_configuration('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT')) {$sep = '; ';} else {$sep = ', ';} if (bibtexbrowser_configuration('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT')) {$sep = '; ';} else {$sep = ', ';}
@ -1566,7 +1566,7 @@ class BibEntry {
$result .= $authors[count($authors)-2].bibtexbrowser_configuration('LAST_AUTHOR_SEPARATOR'). $authors[count($authors)-1]; $result .= $authors[count($authors)-2].bibtexbrowser_configuration('LAST_AUTHOR_SEPARATOR'). $authors[count($authors)-1];
return $result; return $result;
} }
/** adds a link to the author page */ /** adds a link to the author page */
function addAuthorPageLink($author) { function addAuthorPageLink($author) {
$link = makeHref(array(Q_AUTHOR => $author)); $link = makeHref(array(Q_AUTHOR => $author));
@ -1603,10 +1603,10 @@ class BibEntry {
} }
function getHomePageKey($author) { function getHomePageKey($author) {
return strtolower('hp_'.preg_replace('/ /', '', $this->formatAuthorCanonical(latex2html($author)))); return strtolower('hp_'.preg_replace('/ /', '', $this->formatAuthorCanonical(latex2html($author))));
} }
/** add the link to the homepage if it is defined in a string /** add the link to the homepage if it is defined in a string
* e.g. @string{hp_MartinMonperrus="http://www.monperrus.net/martin"} * e.g. @string{hp_MartinMonperrus="http://www.monperrus.net/martin"}
* The string is a concatenation of firstname, lastname, prefixed by hp_ * The string is a concatenation of firstname, lastname, prefixed by hp_
@ -1615,7 +1615,7 @@ class BibEntry {
*/ */
function addHomepageLink($author) { function addHomepageLink($author) {
// hp as home page // hp as home page
// accents are normally handled
// accents are normally handled
// e.g. @STRING{hp_Jean-MarcJézéquel="http://www.irisa.fr/prive/jezequel/"} // e.g. @STRING{hp_Jean-MarcJézéquel="http://www.irisa.fr/prive/jezequel/"}
$homepage = $this->getHomePageKey($author); $homepage = $this->getHomePageKey($author);
if (isset($this->homepages[$homepage])) if (isset($this->homepages[$homepage]))
@ -1656,7 +1656,7 @@ class BibEntry {
function getKeywords() { function getKeywords() {
return preg_split('/[,;\\/]/', $this->getField("keywords")); return preg_split('/[,;\\/]/', $this->getField("keywords"));
} }
/** Returns the value of the given field? */ /** Returns the value of the given field? */
function getField($name) { function getField($name) {
// 2010-06-07: profiling showed that this is very costly // 2010-06-07: profiling showed that this is very costly
@ -1722,7 +1722,7 @@ class BibEntry {
$result = '@'.$this->getType().'{'.$this->getKey().",\n"; $result = '@'.$this->getType().'{'.$this->getKey().",\n";
foreach ($this->raw_fields as $k=>$v) { foreach ($this->raw_fields as $k=>$v) {
if ( !preg_match('/^('.c('BIBTEXBROWSER_BIBTEX_VIEW_FILTEREDOUT').')$/i', $k) if ( !preg_match('/^('.c('BIBTEXBROWSER_BIBTEX_VIEW_FILTEREDOUT').')$/i', $k)
&& !preg_match('/^(key|'.Q_INNER_AUTHOR.'|'.Q_INNER_TYPE.')$/i', $k) )
&& !preg_match('/^(key|'.Q_INNER_AUTHOR.'|'.Q_INNER_TYPE.')$/i', $k) )
{ {
$result .= ' '.$k.' = {'.$v.'},'."\n"; $result .= ' '.$k.' = {'.$v.'},'."\n";
} }
@ -1730,7 +1730,7 @@ class BibEntry {
$result .= "}\n"; $result .= "}\n";
return $result; return $result;
} }
throw new Exception('incorrect value of BIBTEXBROWSER_BIBTEX_VIEW: '+BIBTEXBROWSER_BIBTEX_VIEW);
throw new Exception('incorrect value of BIBTEXBROWSER_BIBTEX_VIEW: '+BIBTEXBROWSER_BIBTEX_VIEW);
} }
/** Returns true if this bib entry contains the given phrase (PREG regexp) /** Returns true if this bib entry contains the given phrase (PREG regexp)
@ -2259,17 +2259,17 @@ function DefaultBibliographyStyle(&$bibentry) {
$coreInfo = $title; $coreInfo = $title;
// adding author info // adding author info
if ($bibentry->hasField('author')) { if ($bibentry->hasField('author')) {
$coreInfo .= ' (<span class="bibauthor">'; $coreInfo .= ' (<span class="bibauthor">';
$authors = array(); $authors = array();
foreach ($bibentry->getFormattedAuthorsArray() as $a) { foreach ($bibentry->getFormattedAuthorsArray() as $a) {
$authors[]='<span itemprop="author" itemtype="https://schema.org/Person">'.$a.'</span>';
$authors[]='<span itemprop="author" itemtype="http://schema.org/Person">'.$a.'</span>';
} }
$coreInfo .= $bibentry->implodeAuthors($authors); $coreInfo .= $bibentry->implodeAuthors($authors);
$coreInfo .= '</span>)'; $coreInfo .= '</span>)';
} }
@ -2340,7 +2340,7 @@ function DefaultBibliographyStyle(&$bibentry) {
// add the Coin URL // add the Coin URL
$result .= $bibentry->toCoins(); $result .= $bibentry->toCoins();
return '<span itemscope="" itemtype="https://schema.org/ScholarlyArticle">'.$result.'</span>';
return '<span itemscope="" itemtype="http://schema.org/ScholarlyArticle">'.$result.'</span>';
} }
@ -2512,7 +2512,7 @@ function VancouverBibliographyStyle(&$bibentry) {
$publisher = 'Master\'s thesis, '.$bibentry->getField(SCHOOL); $publisher = 'Master\'s thesis, '.$bibentry->getField(SCHOOL);
} else if ($type=="techreport") { } else if ($type=="techreport") {
$publisher = 'Technical report, '.$bibentry->getField("institution"); $publisher = 'Technical report, '.$bibentry->getField("institution");
}
}
if ($bibentry->hasField("publisher")) { if ($bibentry->hasField("publisher")) {
$publisher = $bibentry->getField("publisher"); $publisher = $bibentry->getField("publisher");
} }
@ -3407,23 +3407,23 @@ class BibEntryDisplay {
if (METADATA_DC) { if (METADATA_DC) {
$result = $this->metadata_dublin_core($result); $result = $this->metadata_dublin_core($result);
} }
if (METADATA_OPENGRAPH) { if (METADATA_OPENGRAPH) {
$result = $this->metadata_opengraph($result); $result = $this->metadata_opengraph($result);
} }
if (METADATA_EPRINTS) { if (METADATA_EPRINTS) {
$result = $this->metadata_eprints($result); $result = $this->metadata_eprints($result);
} }
return $result;
return $result;
} // end function metadata } // end function metadata
function metadata_opengraph($result) { function metadata_opengraph($result) {
// Facebook metadata // Facebook metadata
// see http://ogp.me // see http://ogp.me
// https://developers.facebook.com/tools/debug/og/object/ // https://developers.facebook.com/tools/debug/og/object/
$result[] = array('og:type','article');
$result[] = array('og:type','article');
$result[] = array('og:title',$this->bib->getTitle()); $result[] = array('og:title',$this->bib->getTitle());
foreach($this->bib->getRawAuthors() as $author) { foreach($this->bib->getRawAuthors() as $author) {
// opengraph requires a URL as author value // opengraph requires a URL as author value
@ -3432,7 +3432,7 @@ class BibEntryDisplay {
$result[] = array('og:published_time',$this->bib->getYear()); $result[] = array('og:published_time',$this->bib->getYear());
return $result; return $result;
} // end function metadata_opengraph } // end function metadata_opengraph
function metadata_dublin_core($result) { function metadata_dublin_core($result) {
// Dublin Core should not be used for bibliographic metadata // Dublin Core should not be used for bibliographic metadata
// according to several sources // according to several sources
@ -3447,7 +3447,7 @@ class BibEntryDisplay {
$result[] = array('DC.Issued',$this->bib->getYear()); $result[] = array('DC.Issued',$this->bib->getYear());
return $result; return $result;
} }
function metadata_google_scholar($result) { function metadata_google_scholar($result) {
// the description may mix with the Google Scholar tags // the description may mix with the Google Scholar tags
// we remove it // we remove it
@ -3527,10 +3527,10 @@ class BibEntryDisplay {
$result[] = array('citation_lastpage',$pages[1]); $result[] = array('citation_lastpage',$pages[1]);
} }
} }
return $result; return $result;
} }
function metadata_eprints($result) { function metadata_eprints($result) {
// --------------------------------- BEGIN METADATA EPRINTS // --------------------------------- BEGIN METADATA EPRINTS
// and now adding eprints metadata // and now adding eprints metadata
@ -3906,7 +3906,7 @@ class BibDataBase {
} }
return $result; return $result;
} }
/** returns the text of all @String entries of this dabatase */ /** returns the text of all @String entries of this dabatase */
function stringEntriesText() { function stringEntriesText() {
$s = ""; $s = "";
@ -3921,7 +3921,7 @@ class BibDataBase {
foreach($this->bibdb as $bibentry) { $s.=$bibentry->getText()."\n"; } foreach($this->bibdb as $bibentry) { $s.=$bibentry->getText()."\n"; }
return $s; return $s;
} }
} // end class } // end class
/** returns the default CSS of bibtexbrowser */ /** returns the default CSS of bibtexbrowser */
@ -4062,7 +4062,7 @@ usage:
<pre> <pre>
$db = zetDB('bibacid-utf8.bib'); $db = zetDB('bibacid-utf8.bib');
$dis = new BibEntryDisplay($db->getEntryByKey('classical')); $dis = new BibEntryDisplay($db->getEntryByKey('classical'));
HTMLTemplate($dis);
HTMLTemplate($dis);
</pre> </pre>
* $content: an object with methods * $content: an object with methods
display() display()
@ -4075,10 +4075,10 @@ function HTMLTemplate(&$content) {
// when we load a page with AJAX // when we load a page with AJAX
// the HTTP header is taken into account, not the <meta http-equiv> // the HTTP header is taken into account, not the <meta http-equiv>
header('Content-type: text/html; charset='.OUTPUT_ENCODING); header('Content-type: text/html; charset='.OUTPUT_ENCODING);
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
?> ?>
<html xmlns="https://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo OUTPUT_ENCODING ?>"/> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo OUTPUT_ENCODING ?>"/>
<meta name="generator" content="bibtexbrowser v__GITHUB__" /> <meta name="generator" content="bibtexbrowser v__GITHUB__" />
@ -4317,7 +4317,7 @@ class RSSDisplay {
// be careful of < // be careful of <
$desc = str_replace('<','&#60;',$desc); $desc = str_replace('<','&#60;',$desc);
// final test with encoding:
// final test with encoding:
if (function_exists('mb_check_encoding')) { // (PHP 4 >= 4.4.3, PHP 5 >= 5.1.3) if (function_exists('mb_check_encoding')) { // (PHP 4 >= 4.4.3, PHP 5 >= 5.1.3)
if (!mb_check_encoding($desc,OUTPUT_ENCODING)) { if (!mb_check_encoding($desc,OUTPUT_ENCODING)) {
return 'encoding error: please check the content of OUTPUT_ENCODING'; return 'encoding error: please check the content of OUTPUT_ENCODING';
@ -4340,7 +4340,7 @@ class RSSDisplay {
// //
?> ?>
<rss version="2.0" xmlns:atom="https://www.w3.org/2005/Atom">
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<title><?php echo $this->title;?></title> <title><?php echo $this->title;?></title>
<link>http://<?php echo $_SERVER['HTTP_HOST'].htmlentities($_SERVER['REQUEST_URI']);?></link> <link>http://<?php echo $_SERVER['HTTP_HOST'].htmlentities($_SERVER['REQUEST_URI']);?></link>
@ -4706,8 +4706,8 @@ class Dispatcher {
function frameset() { ?> function frameset() { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta name="generator" content="bibtexbrowser v__GITHUB__" /> <meta name="generator" content="bibtexbrowser v__GITHUB__" />
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo OUTPUT_ENCODING ?>"/> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo OUTPUT_ENCODING ?>"/>

Loading…
Cancel
Save