Browse Source

improves the link target configuration

pull/63/merge
Martin Monperrus 9 years ago
parent
commit
e3e916444d
  1. 6
      bibtexbrowser-test.php
  2. 30
      bibtexbrowser.php

6
bibtexbrowser-test.php

@ -81,6 +81,12 @@ class BTBTest extends PHPUnit_Framework_TestCase {
// 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
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','DefaultBibliographyStyle');
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&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() {

30
bibtexbrowser.php

@ -68,10 +68,6 @@ if (defined('ENCODING')) {
// if you don't like it, you can be disable it by adding in bibtexbrowser.local.php // if you don't like it, you can be disable it by adding in bibtexbrowser.local.php
// @define('BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT',false); // @define('BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT',false);
@define('BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT',true); @define('BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT',true);
// if you disable the Javascript progressive enhancement,
// you may want the links to be open in a new window/tab
// if yes, add in bibtexbrowser.local.php define('BIBTEXBROWSER_BIB_IN_NEW_WINDOW',true);
@define('BIBTEXBROWSER_BIB_IN_NEW_WINDOW',false);
@define('BIBLIOGRAPHYSTYLE','DefaultBibliographyStyle');// this is the name of a function @define('BIBLIOGRAPHYSTYLE','DefaultBibliographyStyle');// this is the name of a function
@define('BIBLIOGRAPHYSECTIONS','DefaultBibliographySections');// this is the name of a function @define('BIBLIOGRAPHYSECTIONS','DefaultBibliographySections');// this is the name of a function
@define('BIBLIOGRAPHYTITLE','DefaultBibliographyTitle');// this is the name of a function @define('BIBLIOGRAPHYTITLE','DefaultBibliographyTitle');// this is the name of a function
@ -134,7 +130,7 @@ if (defined('ENCODING')) {
@define('BIBTEXBROWSER_GSID_LINKS',true); @define('BIBTEXBROWSER_GSID_LINKS',true);
// should pdf, doi, url, gsid links be opened in a new window? // should pdf, doi, url, gsid links be opened in a new window?
@define('BIBTEXBROWSER_LINKS_IN_NEW_WINDOW',false);
@define('BIBTEXBROWSER_LINKS_TARGET','_self');// can be _blank (new window), _top (with frames)
// should authors be linked to [none/homepage/resultpage] // should authors be linked to [none/homepage/resultpage]
// none: nothing // none: nothing
@ -291,6 +287,14 @@ function default_message() {
echo "</div>"; echo "</div>";
} }
/** returns the target of links */
function get_target() {
if (c('BIBTEXBROWSER_LINKS_TARGET')!='_self') {
return " target=\"".c('BIBTEXBROWSER_LINKS_TARGET')."\"";
}
else return "";
}
/** @nodoc */ /** @nodoc */
function _zetDB($bibtex_filenames) { function _zetDB($bibtex_filenames) {
@ -1285,7 +1289,7 @@ class BibEntry {
if ($altlabel==NULL) { $altlabel=$bibfield; } if ($altlabel==NULL) { $altlabel=$bibfield; }
$str = $this->getIconOrTxt($altlabel,$iconurl); $str = $this->getIconOrTxt($altlabel,$iconurl);
if ($this->hasField($bibfield)) { if ($this->hasField($bibfield)) {
return '<a'.(BIBTEXBROWSER_LINKS_IN_NEW_WINDOW?' target="_blank" ':'').' href="'.$this->getField($bibfield).'">'.$str.'</a>';
return '<a'.get_target().' href="'.$this->getField($bibfield).'">'.$str.'</a>';
} }
return ''; return '';
} }
@ -1296,7 +1300,7 @@ class BibEntry {
$href = 'href="'.$this->getURL().'"'; $href = 'href="'.$this->getURL().'"';
// we add biburl and title to be able to retrieve this important information // we add biburl and title to be able to retrieve this important information
// using Xpath expressions on the XHTML source // using Xpath expressions on the XHTML source
$link = "<a".(BIBTEXBROWSER_BIB_IN_NEW_WINDOW?' target="_blank" ':'')." class=\"biburl\" title=\"".$this->getKey()."\" {$href}>$bibstr</a>";
$link = '<a'.get_target()." class=\"biburl\" title=\"".$this->getKey()."\" {$href}>$bibstr</a>";
return $link; return $link;
} }
@ -1329,7 +1333,7 @@ class BibEntry {
function getDoiLink($iconurl=NULL) { function getDoiLink($iconurl=NULL) {
$str = $this->getIconOrTxt('doi',$iconurl); $str = $this->getIconOrTxt('doi',$iconurl);
if ($this->hasField('doi')) { if ($this->hasField('doi')) {
return '<a'.(BIBTEXBROWSER_LINKS_IN_NEW_WINDOW?' target="_blank" ':'').' href="http://dx.doi.org/'.$this->getField('doi').'">'.$str.'</a>';
return '<a'.get_target().' href="http://dx.doi.org/'.$this->getField('doi').'">'.$str.'</a>';
} }
return ''; return '';
} }
@ -1338,7 +1342,7 @@ class BibEntry {
function getGSLink($iconurl=NULL) { function getGSLink($iconurl=NULL) {
$str = $this->getIconOrTxt('cites',$iconurl); $str = $this->getIconOrTxt('cites',$iconurl);
if ($this->hasField('gsid')) { if ($this->hasField('gsid')) {
return ' <a'.(BIBTEXBROWSER_LINKS_IN_NEW_WINDOW?' target="_blank" ':'').' href="http://scholar.google.com/scholar?cites='.$this->getField("gsid").'">'.$str.'</a>';
return ' <a'.get_target().' href="http://scholar.google.com/scholar?cites='.$this->getField("gsid").'">'.$str.'</a>';
} }
return ''; return '';
} }
@ -1908,7 +1912,7 @@ class BibEntry {
foreach ($vals as $field => $href) { foreach ($vals as $field => $href) {
if ($this->hasField($field)) { if ($this->hasField($field)) {
// this is not a parsing but a simple replacement // 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);
$entry = str_replace('___'.$field.'___', '<a'.get_target().' href="'.$href.'">'.$this->getField($field).'</a>', $entry);
} }
} }
@ -2248,7 +2252,7 @@ function DefaultBibliographyStyle(&$bibentry) {
// title // title
// usually in bold: .bibtitle { font-weight:bold; } // usually in bold: .bibtitle { font-weight:bold; }
$title = '<span class="bibtitle" itemprop="name">'.$title.'</span>'; $title = '<span class="bibtitle" itemprop="name">'.$title.'</span>';
if ($bibentry->hasField('url')) $title = ' <a'.(BIBTEXBROWSER_BIB_IN_NEW_WINDOW?' target="_blank" ':'').' href="'.$bibentry->getField('url').'">'.$title.'</a>';
if ($bibentry->hasField('url')) $title = ' <a'.get_target().' href="'.$bibentry->getField('url').'">'.$title.'</a>';
$coreInfo = $title; $coreInfo = $title;
@ -2366,7 +2370,7 @@ function JanosBibliographyStyle(&$bibentry) {
// title // title
$title = '"'.$title.'"'; $title = '"'.$title.'"';
if ($bibentry->hasField('url')) $title = ' <a'.(BIBTEXBROWSER_BIB_IN_NEW_WINDOW?' target="_blank" ':'').' href="'.$bibentry->getField('url').'">'.$title.'</a>';
if ($bibentry->hasField('url')) $title = ' <a'.get_target().' href="'.$bibentry->getField('url').'">'.$title.'</a>';
$entry[] = $title; $entry[] = $title;
@ -2481,7 +2485,7 @@ function VancouverBibliographyStyle(&$bibentry) {
$title = $title . '. '; $title = $title . '. ';
} }
if ($bibentry->hasField('url')) { if ($bibentry->hasField('url')) {
$title = ' <a'.(BIBTEXBROWSER_BIB_IN_NEW_WINDOW?' target="_blank" ':'').' href="'.$bibentry->getField('url').'">'.$title.'</a>';
$title = ' <a'.get_target().' href="'.$bibentry->getField('url').'">'.$title.'</a>';
} }
$entry[] = $title; $entry[] = $title;

Loading…
Cancel
Save