From 94aeb68a882d76f0f140fbcfdf860929a4ed8045 Mon Sep 17 00:00:00 2001 From: Markus Jochim Date: Fri, 19 Sep 2014 17:47:11 +0200 Subject: [PATCH] Tidied up generation mechanism for [pdf], [doi] links etc. Removed duplicate code that existed inside and outside of get*Link() functions. Added option BIBTEXBROWSER_LINKS_IN_NEW_WINDOW. It is used instead of BIBTEXBROWSER_BIB_IN_NEW_WINDOW for external links (everything but [bibtex]). --- bibtexbrowser.php | 53 +++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 1bcba45..4ff34d8 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -100,6 +100,9 @@ function bibtexbrowser_configure($key, $value) { // do we add [gsid] links (Google Scholar)? @define('BIBTEXBROWSER_GSID_LINKS',true); +// should pdf, doi, url, gsid links be opened in a new window? +@define('BIBTEXBROWSER_LINKS_IN_NEW_WINDOW',true); + // should authors be linked to [none/homepage/resultpage] // none: nothing // their homepage if defined as @strings @@ -1109,11 +1112,21 @@ class BibEntry { if ($altlabel==NULL) { $altlabel=$bibfield; } $str = $this->getIconOrTxt($altlabel,$iconurl); if ($this->hasField($bibfield)) { - return ''.$str.''; + return ''.$str.''; } return ''; } + /** returns a "[bib]" link */ + function getBibLink($iconurl=NULL) { + $bibstr = $this->getIconOrTxt('bibtex',$iconurl); + $href = 'href="'.$this->getURL().'"'; + // we add biburl and title to be able to retrieve this important information + // using Xpath expressions on the XHTML source + $link = "getKey()."\" {$href}>$bibstr"; + return $link; + } + /** 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')) { @@ -1129,34 +1142,22 @@ class BibEntry { } } - /** returns a "[bib]" link if relevant */ - function getBibLink($iconurl=NULL) { - if (BIBTEXBROWSER_BIBTEX_LINKS) { - $bibstr = $this->getIconOrTxt('bibtex',$iconurl); - $href = 'href="'.$this->getURL().'"'; - $link = "getKey()."\" {$href}>$bibstr"; - return $link; - } else { - return ''; - } - } /** DOI are a special kind of links, where the url depends on the doi */ function getDoiLink($iconurl=NULL) { $str = $this->getIconOrTxt('doi',$iconurl); - if (BIBTEXBROWSER_DOI_LINKS && $this->hasField('doi')) { - return ''.$str.''; + if ($this->hasField('doi')) { + return ''.$str.''; } return ''; } - /** GS are a special kind of links, where the url depends on the google scholar id */ + /** GS (Google Scholar) are a special kind of links, where the url depends on the google scholar id */ function getGSLink($iconurl=NULL) { $str = $this->getIconOrTxt('cites',$iconurl); - // Google Scholar ID - if (BIBTEXBROWSER_GSID_LINKS && $this->hasField('gsid')) { - return ' '.$str.''; + if ($this->hasField('gsid')) { + return ' '.$str.''; } return ''; } @@ -1678,28 +1679,22 @@ function get_HTML_tag_for_layout() { * e.g. [bibtex] [doi][pdf] */ function bib2links_default(&$bibentry) { - $href = 'href="'.$bibentry->getURL().'"'; - $str = ''; if (BIBTEXBROWSER_BIBTEX_LINKS) { - // we add biburl and title to be able to retrieve this important information - // using Xpath expressions on the XHTML source - $str .= "getKey()."\" {$href}>[bibtex]"; + $str .= ' '.$bibentry->getBibLink(); } if (BIBTEXBROWSER_PDF_LINKS) { - // returns an empty string if no url present $str .= ' '.$bibentry->getUrlLink(); } - if (BIBTEXBROWSER_DOI_LINKS && $bibentry->hasField('doi')) { - $str .= ' [doi]'; + if (BIBTEXBROWSER_DOI_LINKS) { + $str .= ' '.$bibentry->getDoiLink(); } - // Google Scholar ID - if (BIBTEXBROWSER_GSID_LINKS && $bibentry->hasField('gsid')) { - $str .= ' [cites]'; + if (BIBTEXBROWSER_GSID_LINKS) { + $str .= ' '.$bibentry->getGSLink(); } $str .= '';