Browse Source

Inverted order of conditionals in GetUrlLink, and renamed function.

Fixes #50.

Fixed test case as well.
pull/51/head
Federico Poloni 10 years ago
parent
commit
c6f82792bd
  1. 4
      bibtexbrowser-test.php
  2. 10
      bibtexbrowser.php

4
bibtexbrowser-test.php

@ -204,7 +204,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'));
} }
@ -218,7 +218,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

10
bibtexbrowser.php

@ -1199,13 +1199,13 @@ class BibEntry {
} }
/** returns a "[pdf]" link if relevant. modified to exploit the new method, while keeping backward compatibility */ /** returns a "[pdf]" link if relevant. modified to exploit the new method, while keeping backward compatibility */
function getUrlLink($iconurl = NULL, $label = 'pdf') {
if ($this->hasField('url')) {
return $this->getLink('url', $iconurl, $label);
}
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')) {
@ -1816,7 +1816,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; };
} }

Loading…
Cancel
Save