diff --git a/bibtexbrowser-documentation.wiki b/bibtexbrowser-documentation.wiki index aec2970..ae16009 100644 --- a/bibtexbrowser-documentation.wiki +++ b/bibtexbrowser-documentation.wiki @@ -168,6 +168,42 @@ 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 reference style for links?==== + +'''Setting your own style function''' +Beyond modifying the CSS of links (''.bibline a {}''), the style for links is also encapsulated in a function. If you want to modify the style for links, you can copy the default style in a new file, say ''bibtexbrowser-yourstyle.php'', and rename the function ''bib2links_default'' in say ''MyFancyBib2links''. +Then, add in the file ''bibtexbrowser.local.php'': +
+getBibLink(); + // returns an empty string if no url field present + $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; +} +define('BIBTEXBROWSER_LINK_STYLE','MyFancyBib2links'); +?> ++ + +You can use your personalized function to add support for new fields in bibtex (''pdf'', ''file'', etc.). Check-out the 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 file field present + $result .= $bibentry->getLink('file'); + // 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 e4a1e95..04b56dd 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -87,6 +87,8 @@ 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); @@ -1053,12 +1055,75 @@ class BibEntry { return BIBTEXBROWSER_URL.'?'.createQueryString(array(Q_KEY=>$this->getKey(), Q_FILE=>$this->filename)); } - /** returns a "[pdf]" link if relevant */ + /** Read the bibtex field $bibfield and return a link with icon 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($bibfield,$icon,$def) specifies the icon url $icon and default text $def. + */ + function getLink($bibfield,$iconurl=NULL,$def=NULL) { + $show = true; + if ( $bibfield === 'pdf' || $bibfield === 'url' ) { $show = BIBTEXBROWSER_PDF_LINKS; }; + if ($def==NULL) { $def=$bibfield; } + $str = $this->getIconOrTxt($def,$iconurl); + if ( $show && $this->hasField($bibfield)) { + return ' '.$str.''; + } + return ''; + } + + /* a few specializations of getLink */ + + /** returns a "[url]" link if relevant. modified to exploit the new method, while keeping backward compatibility */ function getUrlLink() { - if ($this->hasField('url')) return ' [pdf]'; + return $this->getLink('url'); + } + + /** 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='