fixes bug in generated hyperlinks. Closes #40.
This commit is contained in:
@@ -193,6 +193,21 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<a href="myarticle.pdf">[pdf]</a>',$first_entry->getUrlLink());
|
$this->assertEquals('<a href="myarticle.pdf">[pdf]</a>',$first_entry->getUrlLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/monperrus/bibtexbrowser/issues/40
|
||||||
|
function test_doi_url() {
|
||||||
|
$test_data = fopen('php://memory','x+');
|
||||||
|
fwrite($test_data, "@Article{Baldwin2014Quantum,Doi={10.1103/PhysRevA.90.012110},Url={http://link.aps.org/doi/10.1103/PhysRevA.90.012110}}"
|
||||||
|
);
|
||||||
|
fseek($test_data,0);
|
||||||
|
$btb = new BibDataBase();
|
||||||
|
$btb->update_internal("inline", $test_data);
|
||||||
|
$first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]];
|
||||||
|
$this->assertEquals('<pre class="purebibtex">@Article{Baldwin2014Quantum,Doi={<a href="http://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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // end class
|
} // end class
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
+10
-1
@@ -1662,13 +1662,22 @@ class BibEntry {
|
|||||||
$entry = htmlspecialchars($this->getFullText());
|
$entry = htmlspecialchars($this->getFullText());
|
||||||
|
|
||||||
// Fields that should be hyperlinks
|
// Fields that should be hyperlinks
|
||||||
|
// the order matters
|
||||||
$hyperlinks = array('url' => '%O', 'file' => '%O', 'pdf' => '%O', 'doi' => 'http://dx.doi.org/%O', 'gsid' => 'http://scholar.google.com/scholar?cites=%O');
|
$hyperlinks = array('url' => '%O', 'file' => '%O', 'pdf' => '%O', 'doi' => 'http://dx.doi.org/%O', 'gsid' => 'http://scholar.google.com/scholar?cites=%O');
|
||||||
|
|
||||||
|
$vals = array();
|
||||||
foreach ($hyperlinks as $field => $url) {
|
foreach ($hyperlinks as $field => $url) {
|
||||||
if ($this->hasField($field)) {
|
if ($this->hasField($field)) {
|
||||||
$href = str_replace('%O', $this->getField($field), $url);
|
$href = str_replace('%O', $this->getField($field), $url);
|
||||||
// this is not a parsing but a simple replacement
|
// this is not a parsing but a simple replacement
|
||||||
$entry = str_replace($this->getField($field), '<a'.(BIBTEXBROWSER_LINKS_IN_NEW_WINDOW?' target="_blank" ':'').' href="'.$href.'">'.$this->getField($field).'</a>', $entry);
|
$entry = str_replace($this->getField($field), '___'.$field.'___', $entry);
|
||||||
|
$vals[$field] = $href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($vals as $field => $href) {
|
||||||
|
if ($this->hasField($field)) {
|
||||||
|
// this is not a parsing but a simple replacement
|
||||||
|
$entry = str_replace('___'.$field.'___', '<a'.(BIBTEXBROWSER_LINKS_IN_NEW_WINDOW?' target="_blank" ':'').' href="'.$href.'">'.$this->getField($field).'</a>', $entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user