Browse Source

merged with Martin's changes

pull/5/head
Matthieu Guillaumin 13 years ago
parent
commit
154f7410ea
  1. 223
      bibtexbrowser.php

223
bibtexbrowser.php

@ -1,10 +1,10 @@
<?php /* bibtexbrowser: publication lists with bibtex and PHP <?php /* bibtexbrowser: publication lists with bibtex and PHP
<!--this is version v20121205 -->
<!--this is version v__GITHUB__ -->
URL: http://www.monperrus.net/martin/bibtexbrowser/ URL: http://www.monperrus.net/martin/bibtexbrowser/
Feedback & Bug Reports: martin.monperrus@gmail.com Feedback & Bug Reports: martin.monperrus@gmail.com
(C) 2013 Matthieu Guillaumin (C) 2013 Matthieu Guillaumin
(C) 2006-2012 Martin Monperrus
(C) 2006-2013 Martin Monperrus
(C) 2005-2006 The University of Texas at El Paso / Joel Garcia, Leonardo Ruiz, and Yoonsik Cheon (C) 2005-2006 The University of Texas at El Paso / Joel Garcia, Leonardo Ruiz, and Yoonsik Cheon
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as modify it under the terms of the GNU General Public License as
@ -17,7 +17,7 @@ License, or (at your option) any later version.
// added on Wednesday, June 01 2011, bug found by Carlos Bras // added on Wednesday, June 01 2011, bug found by Carlos Bras
if (!defined('BIBTEXBROWSER')) { if (!defined('BIBTEXBROWSER')) {
// this if block ends at the very end of this file, after all class and function declarations. // this if block ends at the very end of this file, after all class and function declarations.
define('BIBTEXBROWSER','v20121205');
define('BIBTEXBROWSER','v__GITHUB__');
// *************** CONFIGURATION // *************** CONFIGURATION
@ -80,6 +80,12 @@ define('BIBTEXBROWSER','v20121205');
// their publication lists according to this bibtex // their publication lists according to this bibtex
@define('BIBTEXBROWSER_AUTHOR_LINKS','homepage'); @define('BIBTEXBROWSER_AUTHOR_LINKS','homepage');
// BIBTEXBROWSER_LAYOUT defines the HTML rendering layout of the produced HTML
// may be table/list/ordered_list/definition (for <table>, <ol>, <dl> resp.).
// for list/ordered_list, the abbrevations are not taken into account (see ABBRV_TYPE)
// for ordered_list, the index is given by HTML directly (in increasing order)
@define('BIBTEXBROWSER_LAYOUT','table');
@define('BIBTEXBROWSER_DEBUG',false); @define('BIBTEXBROWSER_DEBUG',false);
@define('COMMA_NAMES',false);// do have authors in a comma separated form? @define('COMMA_NAMES',false);// do have authors in a comma separated form?
@ -118,8 +124,6 @@ define('BIBTEXBROWSER','v20121205');
@define('METADATA_DC',true); @define('METADATA_DC',true);
@define('METADATA_EPRINTS',false); @define('METADATA_EPRINTS',false);
@define('LAYOUT','table'); // may be table/list/deflist. defines the HTML rendering options (<table>, <ol>/<ul>, <dl>, resp.). 'list' only works with 'ABBRV_TYPE'='index' (ordered list) and 'none' (unordered list, the default if another choice than 'list' is made).
// in embedded mode, we still need a URL for displaying bibtex entries alone // in embedded mode, we still need a URL for displaying bibtex entries alone
// this is usually resolved to bibtexbrowser.php // this is usually resolved to bibtexbrowser.php
// but can be overridden in bibtexbrowser.local.php // but can be overridden in bibtexbrowser.local.php
@ -141,7 +145,7 @@ define('Q_INNER_TYPE', 'x-bibtex-type');// used for representing the type of the
// we ensure that the pages won't get polluted // we ensure that the pages won't get polluted
// if future versions of PHP change warning mechanisms... // if future versions of PHP change warning mechanisms...
@error_reporting(E_ERROR);
@error_reporting(/*pp4php:serl*/E_ALL/*lres*/);
/** parses $_GET[Q_FILE] and puts the result (an object of type BibDataBase) in $_GET[Q_DB]. /** parses $_GET[Q_FILE] and puts the result (an object of type BibDataBase) in $_GET[Q_DB].
@ -243,7 +247,7 @@ function _zetDB($bibtex_filenames) {
&& is_readable($compiledbib) && is_readable($compiledbib)
&& filesize($compiledbib)>0 && filesize($compiledbib)>0
) { ) {
$f = fopen($compiledbib,'r+'); // my Unix seems to consider flock as a writing operation
$f = fopen($compiledbib,'r+'); // some Unix seem to consider flock as a writing operation
//we use a lock to avoid that a call to bibbtexbrowser made while we write the object loads an incorrect object //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)) { if (flock($f,LOCK_EX)) {
$s = filesize($compiledbib); $s = filesize($compiledbib);
@ -1245,7 +1249,7 @@ class BibEntry {
return $this->fields; return $this->fields;
} }
/** Returns the abbreviation. */
/** Returns the raw, undecorated abbreviation depending on ABBRV_TYPE. */
function getRawAbbrv() { function getRawAbbrv() {
if (ABBRV_TYPE == 'index') return $this->index; if (ABBRV_TYPE == 'index') return $this->index;
if (ABBRV_TYPE == 'none') return ''; if (ABBRV_TYPE == 'none') return '';
@ -1260,10 +1264,10 @@ class BibEntry {
return $f($this); return $f($this);
} }
/** Returns the abbreviation. */
/** Returns the abbreviation, etc [1] if ABBRV_TYPE='index'. */
function getAbbrv() { function getAbbrv() {
$abbrv = $this->getRawAbbrv(); $abbrv = $this->getRawAbbrv();
if ( ABBRV_TYPE == 'key' || ABBRV_TYPE == 'year' || ( ABBRV_TYPE == 'index' && LAYOUT != 'list' ) ) {
if ( ABBRV_TYPE != 'none' ) {
$abbrv = '['.$abbrv.']'; $abbrv = '['.$abbrv.']';
} }
return $abbrv; return $abbrv;
@ -1309,44 +1313,48 @@ class BibEntry {
/** Outputs HTML line according to layout */ /** Outputs HTML line according to layout */
function toHTML() { function toHTML() {
switch(LAYOUT) { // open row
switch(BIBTEXBROWSER_LAYOUT) { // open row
case 'list': case 'list':
echo '<li class="bibline" value="'.$this->getAbbrv().'">';
echo '<li class="bibline">';
break;
case 'ordered_list':
echo '<li class="bibline">';
break; break;
case 'table': case 'table':
echo '<tr class="bibline"><td class="bibref">'; echo '<tr class="bibline"><td class="bibref">';
break; break;
case 'deflist':
echo '<dl class="bibline"><dt class="bibref">'; break;
case 'definition':
echo '<dl class="bibline"><dt class="bibref">';
if (ABBRV_TYPE=='none') { die ('Cannot define an empty term!'); }
break;
} }
$this->anchor();
switch(LAYOUT) { // close bibref and open bibitem
echo $this->anchor();
switch(BIBTEXBROWSER_LAYOUT) { // close bibref and open bibitem
case 'table': case 'table':
echo $this->getAbbrv().'</td><td class="bibitem">'; echo $this->getAbbrv().'</td><td class="bibitem">';
break; break;
case 'deflist':
case 'definition':
echo $this->getAbbrv().'</dt><dd class="bibitem">'; echo $this->getAbbrv().'</dt><dd class="bibitem">';
break; break;
} }
echo bib2html($this); echo bib2html($this);
echo bib2links($this);
switch(LAYOUT) { // close row
echo $this->bib2links();
switch(BIBTEXBROWSER_LAYOUT) { // close row
case 'list': case 'list':
echo '</li>';
echo '</li>'."\n";
break;
case 'ordered_list':
echo '</li>'."\n";
break; break;
case 'table': case 'table':
echo '</td></tr>';
echo '</td></tr>'."\n";
break; break;
case 'deflist':
echo '</dd></dl>';
case 'definition':
echo '</dd></dl>'."\n";
break; break;
} }
} }
/** Create the entry anchor */
function anchor() {
echo '<a name="'.$this->getAbbrv().'"></a>';
}
/** Outputs an coins URL: see http://ocoins.info/cobg.html /** Outputs an coins URL: see http://ocoins.info/cobg.html
* Used by Zotero, mendeley, etc. * Used by Zotero, mendeley, etc.
@ -1398,7 +1406,7 @@ class BibEntry {
// referrer, the id pf a collection of objects // referrer, the id pf a collection of objects
// see also http://www.openurl.info/registry/docs/pdf/info-sid.pdf // 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[]='rfr_id='.s3988('info:sid/'.@$_SERVER['HTTP_HOST'].':'.@$_GET[Q_FILE]);
$url_parts[]='rft.date='.s3988($this->getYear()); $url_parts[]='rft.date='.s3988($this->getYear());
@ -1409,6 +1417,40 @@ class BibEntry {
} }
/** Returns an anchor for this entry. */
function anchor() {
return '<a name="'.$this->getRawAbbrv().'"></a>';
}
/** returns a collection of links for the given bibtex entry
* e.g. [bibtex] [doi][pdf]
*/
function bib2links() {
$href = 'href="'.$this->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 .= " <a".(BIBTEXBROWSER_BIB_IN_NEW_WINDOW?' target="_blank" ':'')." class=\"biburl\" title=\"".$this->getKey()."\" {$href}>[bibtex]</a>";
}
// returns an empty string if no url present
$str .= $this->getUrlLink();
if ($this->hasField('doi')) {
$str .= ' <a href="http://dx.doi.org/'.$this->getField("doi").'">[doi]</a>';
}
// Google Scholar ID
if ($this->hasField('gsid')) {
$str .= ' <a href="http://scholar.google.com/scholar?cites='.$this->getField("gsid").'">[cites]</a>';
}
return $str;
}
/** /**
@ -1454,32 +1496,36 @@ class BibEntry {
} }
} }
/** returns an HTML tag depending on BIBTEXBROWSER_LAYOUT e.g. <TABLE> */
function get_HTML_tag_for_layout() {
switch(BIBTEXBROWSER_LAYOUT) { /* switch for different layouts */
case 'list':
$tag='ul';
break;
case 'ordered_list':
$tag='ol';
break;
case 'table':
$tag = 'table';
break;
case 'definition':
$tag = 'div';
break;
default:
die('Unknown BIBTEXBROWSER_LAYOUT');
}
return $tag;
}
function layoutHeaderHTML() {
$tag = '';
switch(LAYOUT) { /* switch for different layouts */
case 'list':
if (ABBRV_TYPE=='index') {
$tag='ol';
} else { // assume none
$tag='ul';
}
break;
case 'table':
$tag = 'table';
break;
case 'deflist':
$tag = 'div';
break;
default:
die('Unknown LAYOUT');
}
echo '<' . $tag . ' class="result">';
return $tag;
/** prints the header of a layouted HTML, depending on BIBTEXBROWSER_LAYOUT e.g. <TABLE> */
function print_header_layout() {
echo '<' . get_HTML_tag_for_layout() . ' class="result">'."\n";
} }
function layoutFooterHTML($tag) {
echo '</' . $tag . '>';
/** prints the footer of a layouted HTML, depending on BIBTEXBROWSER_LAYOUT e.g. </TABLE> */
function print_footer_layout() {
echo '</' . get_HTML_tag_for_layout() . '>';
} }
/** this function encapsulates the user-defined name for bib to HTML*/ /** this function encapsulates the user-defined name for bib to HTML*/
@ -1488,30 +1534,6 @@ function bib2html(&$bibentry) {
return $function($bibentry); return $function($bibentry);
} }
function bib2links(&$bibentry) {
$href = 'href="'.$bibentry->getURL().'"';
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 .= " <a".(BIBTEXBROWSER_BIB_IN_NEW_WINDOW?' target="_blank" ':'')." class=\"biburl\" title=\"".$bibentry->getKey()."\" {$href}>[bibtex]</a>";
}
// returns an empty string if no url present
$str .= $bibentry->getUrlLink();
if ($bibentry->hasField('doi')) {
$str .= ' <a href="http://dx.doi.org/'.$bibentry->getField("doi").'">[doi]</a>';
}
// Google Scholar ID
if ($bibentry->hasField('gsid')) {
$str .= ' <a href="http://scholar.google.com/scholar?cites='.$bibentry->getField("gsid").'">[cites]</a>';
}
return $str;
}
/** encapsulates the user-defined sections. @nodoc */ /** encapsulates the user-defined sections. @nodoc */
function _DefaultBibliographySections() { function _DefaultBibliographySections() {
$function = BIBLIOGRAPHYSECTIONS; $function = BIBLIOGRAPHYSECTIONS;
@ -1727,7 +1749,7 @@ function DefaultBibliographyStyle(&$bibentry) {
} }
// add the Coin URL // add the Coin URL
$result .= "\n".$bibentry->toCoins();
$result .= $bibentry->toCoins();
return $result; return $result;
} }
@ -1922,7 +1944,7 @@ class IndependentYearMenu {
function poweredby() { function poweredby() {
$poweredby = "\n".'<div style="text-align:right;font-size: xx-small;opacity: 0.6;" class="poweredby">'; $poweredby = "\n".'<div style="text-align:right;font-size: xx-small;opacity: 0.6;" class="poweredby">';
$poweredby .= '<!-- If you like bibtexbrowser, thanks to keep the link :-) -->'; $poweredby .= '<!-- If you like bibtexbrowser, thanks to keep the link :-) -->';
$poweredby .= 'Powered by <a href="http://www.monperrus.net/martin/bibtexbrowser/">bibtexbrowser</a><!--v20121205-->';
$poweredby .= 'Powered by <a href="http://www.monperrus.net/martin/bibtexbrowser/">bibtexbrowser</a><!--v__GITHUB__-->';
$poweredby .= '</div>'."\n"; $poweredby .= '</div>'."\n";
return $poweredby; return $poweredby;
} }
@ -2371,7 +2393,7 @@ class SimpleDisplay {
echo 'Options: '.@implode(',',$this->options).'<br/>'; echo 'Options: '.@implode(',',$this->options).'<br/>';
} }
$tag = layoutHeaderHTML();
print_header_layout();
$count = count($this->entries); $count = count($this->entries);
$i=0; $i=0;
@ -2382,7 +2404,7 @@ class SimpleDisplay {
$bib->toHTML(); $bib->toHTML();
} // end foreach } // end foreach
layoutFooterHTML($tag);
print_footer_layout();
} // end function } // end function
} // end class } // end class
@ -2438,21 +2460,21 @@ class AcademicDisplay {
uasort($entries, ORDER_FUNCTION); uasort($entries, ORDER_FUNCTION);
if (count($entries)>0) { if (count($entries)>0) {
echo "\n".'<div class="btb-header">'.$title.'</div>'."\n";
$tag = layoutHeaderHTML();
echo "\n".'<div class="btb-header">'.$title.'</div>'."\n";
print_header_layout();
// by default the abbreviation is incremented over all searches
// since we don't know before hand all section, we can not index in decreasing order
static $count;
if ($count == NULL) { $count = 1; } // init
$id = $count;
foreach ($entries as $bib) {
$bib->setIndex($id++);
$bib->toHTML();
} // end foreach
$count = @$count + count($entries);
layoutFooterHTML($tag);
// by default the abbreviation is incremented over all searches
// since we don't know before hand all section, we can not index in decreasing order
static $count;
if ($count == NULL) { $count = 1; } // init
$id = $count;
foreach ($entries as $bib) {
$bib->setIndex($id++);
$bib->toHTML();
} // end foreach
$count = @$count + count($entries);
print_footer_layout();
} }
} }
@ -3085,7 +3107,7 @@ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo ENCODING ?>"/> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo ENCODING ?>"/>
<meta name="generator" content="bibtexbrowser v20121205" />
<meta name="generator" content="bibtexbrowser v__GITHUB__" />
<?php <?php
// if ($content->getRSS()!='') echo '<link rel="alternate" type="application/rss+xml" title="RSS" href="'.$content->getRSS().'&amp;rss" />'; // if ($content->getRSS()!='') echo '<link rel="alternate" type="application/rss+xml" title="RSS" href="'.$content->getRSS().'&amp;rss" />';
?> ?>
@ -3243,7 +3265,7 @@ class PagedDisplay {
} }
$this->menu($less, $more); $this->menu($less, $more);
$tag = layoutHeaderHTML();
print_header_layout();
for ($i = 0; $i < PAGE_SIZE; $i++) { for ($i = 0; $i < PAGE_SIZE; $i++) {
$index = ($this->page-1)*PAGE_SIZE + $i; $index = ($this->page-1)*PAGE_SIZE + $i;
if (isset($this->entries[$index])) { if (isset($this->entries[$index])) {
@ -3254,7 +3276,8 @@ class PagedDisplay {
//break; //break;
} }
} // end foreach } // end foreach
layoutFooterHTML($tag);
print_footer_layout();
$this->menu($less, $more); $this->menu($less, $more);
} }
@ -3348,7 +3371,7 @@ class RSSDisplay {
<link>http://<?php echo $_SERVER['HTTP_HOST'].htmlentities($_SERVER['REQUEST_URI']);?></link> <link>http://<?php echo $_SERVER['HTTP_HOST'].htmlentities($_SERVER['REQUEST_URI']);?></link>
<atom:link href="http://<?php echo $_SERVER['HTTP_HOST'].htmlentities($_SERVER['REQUEST_URI']);?>" rel="self" type="application/rss+xml" /> <atom:link href="http://<?php echo $_SERVER['HTTP_HOST'].htmlentities($_SERVER['REQUEST_URI']);?>" rel="self" type="application/rss+xml" />
<description></description> <description></description>
<generator>bibtexbrowser v20121205</generator>
<generator>bibtexbrowser v__GITHUB__</generator>
<?php <?php
foreach($this->entries as $bibentry) { foreach($this->entries as $bibentry) {
@ -3606,7 +3629,7 @@ class Dispatcher {
function diagnosis() { function diagnosis() {
header('Content-type: text/plain'); header('Content-type: text/plain');
echo "php version: ".phpversion()."\n"; echo "php version: ".phpversion()."\n";
echo "bibtexbrowser version: 20121205\n";
echo "bibtexbrowser version: __GITHUB__\n";
echo "dir: ".decoct(fileperms(dirname(__FILE__)))."\n"; echo "dir: ".decoct(fileperms(dirname(__FILE__)))."\n";
echo "bibtex file: ".decoct(fileperms($_GET[Q_FILE]))."\n"; echo "bibtex file: ".decoct(fileperms($_GET[Q_FILE]))."\n";
exit; exit;
@ -3618,7 +3641,7 @@ class Dispatcher {
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta name="generator" content="bibtexbrowser v20121205" />
<meta name="generator" content="bibtexbrowser v__GITHUB__" />
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo ENCODING ?>"/> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo ENCODING ?>"/>
<title>You are browsing <?php echo $_GET[Q_FILE]; ?> with bibtexbrowser</title> <title>You are browsing <?php echo $_GET[Q_FILE]; ?> with bibtexbrowser</title>
</head> </head>
@ -3640,4 +3663,4 @@ class Dispatcher {
$class = BIBTEXBROWSER_MAIN;// extension point $class = BIBTEXBROWSER_MAIN;// extension point
$main = new $class(); $main = new $class();
$main->main(); $main->main();
?>
?>
Loading…
Cancel
Save