merges PR #51
This commit is contained in:
+36
-3
@@ -237,7 +237,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
|||||||
$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->getLink('pdf'));
|
||||||
$this->assertEquals('<a href="myarticle.pdf">[pdf]</a>',$first_entry->getUrlLink());
|
$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'));
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
|||||||
$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->getUrlLink());
|
$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
|
||||||
@@ -332,6 +332,40 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals(2,count($dis->getKeywords()));
|
$this->assertEquals(2,count($dis->getKeywords()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# https://github.com/monperrus/bibtexbrowser/pull/51
|
||||||
|
function test_emptyGetPdfLink() {
|
||||||
|
$bibtex = "
|
||||||
|
@article{aKey,
|
||||||
|
title={\`a Book},
|
||||||
|
author={Martin Monperrus},
|
||||||
|
publisher={Springer},
|
||||||
|
year=2009,
|
||||||
|
pages={42--4242},
|
||||||
|
number=1
|
||||||
|
}
|
||||||
|
@article{bKey,
|
||||||
|
url={magic.pdf},
|
||||||
|
}
|
||||||
|
@article{cKey,
|
||||||
|
pdf={magic2.pdf},
|
||||||
|
url={magic3}
|
||||||
|
}";
|
||||||
|
$test_data = fopen('php://memory','x+');
|
||||||
|
fwrite($test_data, $bibtex);
|
||||||
|
fseek($test_data,0);
|
||||||
|
$db = new BibDataBase();
|
||||||
|
$db->update_internal("inline", $test_data);
|
||||||
|
|
||||||
|
$dis = $db->getEntryByKey('aKey');
|
||||||
|
$this->assertEquals("",$dis->getPdfLink());
|
||||||
|
|
||||||
|
$dis = $db->getEntryByKey('bKey');
|
||||||
|
$this->assertEquals('<a href="magic.pdf">[pdf]</a>',$dis->getPdfLink());
|
||||||
|
|
||||||
|
$dis = $db->getEntryByKey('cKey');
|
||||||
|
$this->assertEquals('<a href="magic2.pdf">[pdf]</a>',$dis->getPdfLink());
|
||||||
|
}
|
||||||
|
|
||||||
function test_formatting() {
|
function test_formatting() {
|
||||||
|
|
||||||
$bibtex = "@article{aKey61,title={An article Book},author = {Meyer, Heribert and {Advanced Air and Ground Research Team} and Foo Bar}}\n";
|
$bibtex = "@article{aKey61,title={An article Book},author = {Meyer, Heribert and {Advanced Air and Ground Research Team} and Foo Bar}}\n";
|
||||||
@@ -426,7 +460,6 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals("Foo Bar", $authors[2]);
|
$this->assertEquals("Foo Bar", $authors[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // end class
|
} // end class
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
+14
-6
@@ -1273,19 +1273,27 @@ class BibEntry {
|
|||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns a "[pdf]" link if relevant. modified to exploit the new method, while keeping backward compatibility */
|
/** same as `getPdfLink`, kept for backward compatibility */
|
||||||
function getUrlLink($iconurl = NULL, $label = 'pdf') {
|
function getUrlLink($iconurl, $label) {
|
||||||
if ($this->hasField('url')) {
|
return $this->getPdfLink($iconurl, $label);
|
||||||
return $this->getLink('url', $iconurl, $label);
|
}
|
||||||
}
|
|
||||||
|
/** 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'.
|
||||||
|
*/
|
||||||
|
function getPdfLink($iconurl = NULL, $label = 'pdf') {
|
||||||
if ($this->hasField('pdf')) {
|
if ($this->hasField('pdf')) {
|
||||||
return $this->getLink('pdf', $iconurl, $label);
|
return $this->getLink('pdf', $iconurl, $label);
|
||||||
}
|
}
|
||||||
|
if ($this->hasField('url')) {
|
||||||
|
return $this->getLink('url', $iconurl, $label);
|
||||||
|
}
|
||||||
// Adding link to PDF file exported by Zotero
|
// Adding link to PDF file exported by Zotero
|
||||||
// ref: https://github.com/monperrus/bibtexbrowser/pull/14
|
// ref: https://github.com/monperrus/bibtexbrowser/pull/14
|
||||||
if ($this->hasField('file')) {
|
if ($this->hasField('file')) {
|
||||||
return $this->getLink('file', $iconurl, $label);
|
return $this->getLink('file', $iconurl, $label);
|
||||||
}
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1913,7 +1921,7 @@ function bib2links_default(&$bibentry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (BIBTEXBROWSER_PDF_LINKS) {
|
if (BIBTEXBROWSER_PDF_LINKS) {
|
||||||
$link = $bibentry->getUrlLink();
|
$link = $bibentry->getPdfLink();
|
||||||
if ($link != '') { $links[] = $link; };
|
if ($link != '') { $links[] = $link; };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user