diff --git a/bibtexbrowser.php b/bibtexbrowser.php
index 45f7513..0683604 100644
--- a/bibtexbrowser.php
+++ b/bibtexbrowser.php
@@ -117,6 +117,13 @@ define('BIBTEXBROWSER','v20121205');
@define('METADATA_DC',true);
@define('METADATA_EPRINTS',false);
+/* to use provided icons, uncomment the next three lines */
+function e2i($e) { return "icons/".$e.".png"; }
+$icons = json_encode(array("pdf" => e2i("pdf"), "bib" => e2i("bib"), "doi" => e2i("doi"), "url" => e2i("url"), "slides" => e2i("slides"), "poster" => e2i("slides"), "gsc" => e2i("google_scholar") ));
+@define('ICONS',$icons);
+@define('ICONS','[]');
+@define('Q_ICONS','icons');
+
// in embedded mode, we still need a URL for displaying bibtex entries alone
// this is usually resolved to bibtexbrowser.php
// but can be overridden in bibtexbrowser.local.php
@@ -147,6 +154,7 @@ See also zetDB().
function setDB() {
list($db, $parsed, $updated, $saved) = _zetDB(@$_GET[Q_FILE]);
$_GET[Q_DB] = $db;
+ $_GET[Q_ICONS] = (array) json_decode(ICONS); // not sure this is the best place for this action
return $updated;
}
@@ -240,7 +248,7 @@ function _zetDB($bibtex_filenames) {
&& is_readable($compiledbib)
&& filesize($compiledbib)>0
) {
- $f = fopen($compiledbib,'r');
+ $f = fopen($compiledbib,'r+');
//we use a lock to avoid that a call to bibbtexbrowser made while we write the object loads an incorrect object
if (flock($f,LOCK_EX)) {
$s = filesize($compiledbib);
@@ -999,12 +1007,71 @@ class BibEntry {
return "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'/'.$this->getURL();
}
- /** 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]' or the pdf icon specified in the bibtex file (cf. getIconOrTxt)
+ * getLink($bibfield,$icon,$def) specifies the icon key $icon and default text $def.
+ */
+ function getLink($bibfield,$icon=NULL,$def=NULL) {
+ if ($icon==NULL) { $icon=$bibfield; }
+ $str = $this->getIconOrTxt($icon,$def);
+ if ($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() {
+ $bibstr = $this->getIconOrTxt('bib');
+ $href = 'href="'.$this->getURL().'"';
+ $link = "getKey()."\" {$href}>$bibstr";
+ return $link;
+ }
+
+
+ /** DOI are a special kind of links, where the url depends on the doi */
+ function getDoiLink() {
+ $str = $this->getIconOrTxt('doi');
+ if ($this->hasField('doi')) {
+ return ' '.$str.'';
+ }
+ return '';
+ }
+
+ /** GS are a special kind of links, where the url depends on the google scholar id */
+ function getGSLink() {
+ $str = $this->getIconOrTxt('gsc','cites');
+ // Google Scholar ID
+ if ($this->hasField('gsid')) {
+ return ' '.$str.'';
+ }
return '';
}
+ /** replace [$ext] with an icon whose url is defined in a string
+ * e.g. getIconOrTxt('pdf') will show the icon defined in $_GET[Q_ICONS]['pdf'] or print '[pdf]'
+ * or getIconOrTxt('pdf','paper') will show the icon defined by $_GET[Q_ICONS]['pdf'] or print '[paper]'
+ * The replacement text is also used if the url does not point to a valid file (using the "alt" property of the "img" html tag)
+ */
+ function getIconOrTxt($ext,$def=NULL) {
+ if ($def==NULL) { $def=$ext; }
+ $icons = $_GET[Q_ICONS];
+ if ( array_key_exists($ext,$icons) ) {
+ $str='';
+ } else {
+ $str='['.$def.']';
+ }
+ return $str;
+ }
+
/** Reruns the abstract */
function getAbstract() {
if ($this->hasField('abstract')) return $this->getField('abstract');
@@ -1307,25 +1374,22 @@ class BibEntry {
echo '