diff --git a/bibtexbrowser-documentation.wiki b/bibtexbrowser-documentation.wiki index 3028e15..c61915e 100644 --- a/bibtexbrowser-documentation.wiki +++ b/bibtexbrowser-documentation.wiki @@ -172,6 +172,43 @@ See Janos Tapolcai's style, which looks like IEEE references (see function Janos For contributing with a new style, [[http://www.monperrus.net/martin/|please drop me an email ]] +====How to change the link style?==== + +By default each bibliographic entry is followed by +[bibtex] [pdf] [doi], etc. + +This can be tailored by configuring as follows (in the file ''bibtexbrowser.local.php'') +
getBibLink(); + + $result .= ' '.$bibentry->getLink('url'); + + // Google Scholar ID. empty string if no gsid field present + $result .= ' '.$bibentry->getGSLink(); + + // returns an empty string if no doi field present + $result .= ' '.$bibentry->getDoiLink(); + + return $result; +} +?> ++ + +You can use your personalized function to add support for new fields in bibtex (''pdf'', ''file'', etc.). Check-out the documentation of functions ''getLink()'', ''getBibLink()'', ''getGSLink()'' and ''getDoiLink()'': they accept an optional argument for providing an image/icon instead of printing text. + +
+ // returns an empty string if no pdf field present + $result .= $bibentry->getLink('pdf','http://url.to/icons/pdf.png'); + // returns an empty string if no slides field present + $result .= $bibentry->getLink('slides'); + // returns an empty string if no poster field present + $result .= $bibentry->getLink('poster'); ++ ====How to specify the encoding of bibtex files (UTF-8/ISO-8859-1/etc.)? ==== diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 4048956..ab2326d 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -87,8 +87,10 @@ function bibtexbrowser_configure($key, $value) { @define('BIBTEXBROWSER_NO_DEFAULT', false); +// BIBTEXBROWSER_LINK_STYLE defines which function to use to display the links of a bibtex entry +@define('BIBTEXBROWSER_LINK_STYLE','bib2links_default'); + // do we add [bibtex] links ? -// suggested by Sascha Schnepp @define('BIBTEXBROWSER_BIBTEX_LINKS',true); // do we add [pdf] links ? @define('BIBTEXBROWSER_PDF_LINKS',true); @@ -1070,12 +1072,83 @@ class BibEntry { return BIBTEXBROWSER_URL.'?'.createQueryString(array(Q_KEY=>$this->getKey(), Q_FILE=>$this->filename)); } - /** returns a "[pdf]" link if relevant */ - function getUrlLink() { - if ($this->hasField('url')) return ' [pdf]'; + /** @see bib2links(), kept for backward compatibility */ + function bib2links() { + return bib2links($this); + } + + /** Read the bibtex field $bibfield and return a link with icon (if $iconurl is given) or text + * e.g. given the bibtex entry: @article{myarticle, pdf={myarticle.pdf}}, + * $bibtexentry->getLink('pdf') creates a link to myarticle.pdf using the text '[pdf]'. + * $bibtexentry->getLink('pdf','pdficon.png') returns <a href="myarticle.pdf"><img src="pdficon.png"/></a> + * if you want a label that is different from the bibtex field, add a third parameter. + */ + function getLink($bibfield,$iconurl=NULL,$altlabel=NULL) { + $show = true; + if ($altlabel==NULL) { $altlabel=$bibfield; } + $str = $this->getIconOrTxt($altlabel,$iconurl); + if ($this->hasField($bibfield)) { + return ''.$str.''; + } + return ''; + } + + /** 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); + } + if ($this->hasField('pdf')) { + return $this->getLink('pdf', $iconurl, $label); + } + } + + /** 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.''; + } + return ''; + } + + /** GS 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.''; + } return ''; } + /** replace [$ext] with an icon whose url is defined in a string + * e.g. getIconOrTxt('pdf') will print '[pdf]' + * or getIconOrTxt('pdf','http://link/to/icon.png') will use the icon linked by the url, or print '[pdf'] + * if the url does not point to a valid file (using the "alt" property of the "img" html tag) + */ + function getIconOrTxt($txt,$iconurl=NULL) { + if ( $iconurl==NULL ) { + $str='['.$txt.']'; + } else { + $str='