diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 3c21b52..7598efe 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -89,8 +89,6 @@ And tailor it with a CSS style, for example: .date { background-color: blue; } .rheader { font-size: large } .bibline { padding:3px; padding-left:15px; vertical-align:top;} -.bibtitle { font-weight:bold; } -.bibbooktitle { font-style:italic; } </style> =====Adding links to the slides ===== @@ -212,6 +210,7 @@ define('YEAR', 'year'); // default bib file, if no file is specified in the query string. if (!isset($_GET[Q_FILE])) { header('HTTP/1.1 404 Not found'); + header('Content-type: text/plain');// to be validated by W3 die('No bibtex file passed as parameter (e.g. bibtexbrowser.php?bib=mybib.php)'); } @@ -643,6 +642,8 @@ function latex2html($line) { return trim($line); } +/** Note that & are encoded as %26 and not as & so it does not break the Z3988 URL */ +function s3988($s) {return urlencode(utf8_encode($s));} // ---------------------------------------------------------------------- // BIB ENTRIES @@ -883,46 +884,104 @@ class BibEntry { } + /** Outputs an coins URL: see http://ocoins.info/cobg.html + * Used by Zotero, mendeley, etc. + */ + function toCoins() { + $url_parts=array(); + $url_parts[]='ctx_ver=Z39.88-2004'; + + $type = $this->getType(); + if ($type=="book") { + $url_parts[]='rft_val_fmt='.s3988('info:ofi/fmt:kev:mtx:book'); + $url_parts[]='rft.btitle='.s3988($this->getTitle()); + $url_parts[]='rft.genre=book'; + } else if ($type=="inproceedings") { + $url_parts[]='rft_val_fmt='.s3988('info:ofi/fmt:kev:mtx:book'); + $url_parts[]='rft.atitle='.s3988($this->getTitle()); + $url_parts[]='rft.btitle='.s3988($this->getField(BOOKTITLE)); + + // zotero does not support with this proceeding and conference + // they give the wrong title + //$url_parts[]='rft.genre=proceeding'; + //$url_parts[]='rft.genre=conference'; + $url_parts[]='rft.genre=bookitem'; + } else if ($type=="incollection" ) { + $url_parts[]='rft_val_fmt='.s3988('info:ofi/fmt:kev:mtx:book'); + $url_parts[]='rft.btitle='.s3988($this->getField(BOOKTITLE)); + $url_parts[]='rft.atitle='.s3988($this->getTitle()); + $url_parts[]='rft.genre=bookitem'; + } else if ($type=="article") { + $url_parts[]='rft_val_fmt='.s3988('info:ofi/fmt:kev:mtx:journal'); + $url_parts[]='rft.atitle='.s3988($this->getTitle()); + $url_parts[]='rft.jtitle='.s3988($this->getField("journal")); + $url_parts[]='rft.volume='.s3988($this->getField("volume")); + $url_parts[]='rft.issue='.s3988($this->getField("issue")); + } else { // techreport, phdthesis + $url_parts[]='rft_val_fmt='.s3988('info:ofi/fmt:kev:mtx:book'); + $url_parts[]='rft.btitle='.s3988($this->getTitle()); + $url_parts[]='rft.genre=report'; + } + + $url_parts[]='rft.pub='.s3988($this->getPublisher()); + + // referent + if ($this->hasField('url')) { + $url_parts[]='rft_id='.s3988($this->getField("url")); + } else if ($this->hasField('doi')) { + $url_parts[]='rft_id='.s3988('info:doi/'.$this->getField("doi")); + } + + // referrer, the id pf a collection of objects + // see also http://www.openurl.info/registry/docs/pdf/info-sid.pdf + $url_parts[]='rfr_id='.s3988('info:sid/'.$_SERVER['HTTP_HOST'].':'.$_GET[Q_FILE]); + $url_parts[]='rft.date='.s3988($this->getYear()); + foreach ($this->getFormattedAuthors() as $au) $url_parts[]='rft.au='.s3988($au); + + + return implode('&',$url_parts); + + } /** Outputs an HTML string */ function toString() { - $title = $this->getField(TITLE); + $title = $this->getTitle(); $type = $this->getType(); $entry=array(); // title - $title = ''.$title.''; + $title = ''.$title.''; if ($this->hasField('url')) $title = ' '.$title.''; $entry[] = $title; // author if ($this->hasField('author')) { - $entry[0] .= ' ('.$this->formattedAuthors().')'; + $entry[0] .= ' ('.$this->formattedAuthors().')'; } // now the origin of the publication is in italic $booktitle = ''; if (($type=="misc") && $this->hasField("note")) { - $booktitle = ''.$this->getField("note").''; + $booktitle = $this->getField("note"); } if ($type=="inproceedings") { - $booktitle = 'In '.$this->getField(BOOKTITLE).''; + $booktitle = 'In '.$this->getField(BOOKTITLE); } if ($type=="incollection") { - $booktitle = 'Chapter in '.$this->getField(BOOKTITLE).''; + $booktitle = 'Chapter in '.$this->getField(BOOKTITLE); } if ($type=="article") { - $booktitle = 'In '.$this->getField("journal").''; + $booktitle = 'In '.$this->getField("journal"); } @@ -934,37 +993,37 @@ class BibEntry { foreach ($this->getEditors() as $ed) { $editors[]=formatAuthor($ed); } - $editor = ''.implode(', ',$editors).', '.(count($editors)>1?'eds.':'ed.'); + $editor = implode(', ',$editors).', '.(count($editors)>1?'eds.':'ed.'); } if ($booktitle!='') { - if ($editor!='') $entry[] = $booktitle.' ('.$editor.')'; - else $entry[] = $booktitle; + if ($editor!='') $booktitle .=' ('.$editor.')'; + $entry[] = ''.$booktitle.''; } $publisher=''; if ($type=="phdthesis") { - $publisher = 'PhD thesis, '.$this->getField(SCHOOL).''; + $publisher = 'PhD thesis, '.$this->getField(SCHOOL); } if ($type=="mastersthesis") { - $publisher = 'Master\'s thesis, '.$this->getField(SCHOOL).''; + $publisher = 'Master\'s thesis, '.$this->getField(SCHOOL); } if ($type=="techreport") { - $publisher = 'Technical report, '.$this->getField("institution").''; + $publisher = 'Technical report, '.$this->getField("institution"); } if ($this->hasField("publisher")) { - $publisher = ''.$this->getField("publisher").''; + $publisher = $this->getField("publisher"); } if ($publisher!='') $entry[] = $publisher; - if ($this->hasField('volume')) $entry[] = "volume ".''.$this->getField("volume").''; + if ($this->hasField('volume')) $entry[] = "volume ".$this->getField("volume"); - if ($this->hasField(YEAR)) $entry[] = ''.$this->getYear().''; + if ($this->hasField(YEAR)) $entry[] = $this->getYear(); $result = implode(", ",$entry).'.'; @@ -973,7 +1032,10 @@ class BibEntry { $result .= " (".$this->getField("comment").")"; } - return ''.$result.''; + // add the Coin URL + $result .= "\n".''; + + return $result; } /** @@ -983,8 +1045,8 @@ class BibEntry { */ function toEntryUnformatted() { $text =$this->getText(); + // Note this is exactly the initial formatting thanks to the PRE tag ?> -
bib = $bibentry; - $this->title = $this->bib->getTitle().' (bibliographic bibtex entry)'; + $this->title = $this->bib->getTitle().' (bibtex bibliographic entry)'; } function display() { echo $this->formatedHeader(); + echo ''; echo $this->bib->toEntryUnformatted(); //echo $this->bib->toString(); echo $this->poweredby(); @@ -1943,8 +2006,6 @@ body { padding-left:15px; font-size: small; } -.bibtitle { font-weight:bold; } -.bibbooktitle { font-style:italic; } TD { vertical-align:text-top; } @@ -2028,7 +2089,7 @@ class BibtexDisplay { } function display() { - header('Content-type: text/plain'); + header('Content-type: text/plain; charset='.ENCODING); echo '% '.query2title($this->query)."\n"; echo '% Encoding: '.ENCODING."\n"; foreach($this->results as $bibentry) { echo $bibentry->getText()."\n"; }