Browse Source

*** empty log message ***

replace/c24a8d1de403113542ba0936e844151de2785013
Martin Monperrus 17 years ago
parent
commit
ec1685f7ff
  1. 184
      bibtexbrowser.php

184
bibtexbrowser.php

@ -1,23 +1,32 @@
<?php /* bibtexbrowser: a PHP script to browse and search bib entries from BibTex files
[[#Features]]
===== Features =====
[[#Download]] | [[#Screenshot]] | [[#Features]] | [[#Related_tools]] | [[#Users]] | [[#Copyright]]
bibtexbrowser is a PHP script to browse and search bib entries from BibTex files. For instance, on the [[http://www.monperrus.net/martin/bibtexbrowser.php|bibtexbrowser demonstration site]], you can browse my main bibtex file.
For feature requests or bug reports, [[http://www.monperrus.net/martin/|please drop me an email ]].
Thanks to all [[#Users]] of bibtexbrowser :-)
=====Download=====
**[[http://www.monperrus.net/martin/bibtexbrowser.php.txt|Download bibtexbrowser]]**
=====Screenshot=====
<a href="bibtexbrowser-screenshot.png"><img height="500" src="bibtexbrowser-screenshot.png" alt="bibtexbrowser screenshot"/><br/></a>
=====Features=====
* [[http://www.monperrus.net/martin/bibtexbrowser.php|bibtexbrowser can display the menu and all entries without filtering from the $filename hardcoded in the script ]]
* [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib|bibtexbrowser can display the menu and all entries without filtering from the file name passed as parameter]]
* [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&amp;all|bibtexbrowser can display all entries out of a bibtex file]]
* [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&amp;year=2004|bibtexbrowser can display all entries for a given year]]
* [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&author=Barbara+A.+Kitchenham|bibtexbrowser can display all entries for an author]]
* [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&amp;author=Barbara+A.+Kitchenham|bibtexbrowser can display all entries for an author]]
* [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&amp;key=monperrus08phd|bibtexbrowser can display a single entry]]
* [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&amp;tag=mda|bibtexbrowser can display all entries with a bib keyword]]
* [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&amp;keywords=mda|bibtexbrowser can display all entries with a bib keyword]]
* [[http://www.monperrus.net/martin/bibtexbrowser.php?bib=biblio_monperrus.bib&amp;search=ocl|bibtexbrowser can display found entries with a search word (it can be in any bib field)]]
* bibtexbrowser allows multi criteria search, e.g. ?type=inproceedings&amp;year=2004
* bibtexbrowser outputs valid XHTML 1.0 Transitional
* bibtexbrowser in designed to be search engine friendly.
* You can include your publications list into your home page:
@ -26,7 +35,7 @@ session_start(); //to avoid reparsing the bib file; should be at the very top of
// the bib file
$_GET&#91;'bib'&#93;='mybib.bib';
// the request
$_GET&#91;'author'&#93;='Martin+Monperrus';
$_GET&#91;'author'&#93;='Martin Monperrus';
include('bibtexbrowser.php');
?>
And tailor it with a CSS style!
@ -47,10 +56,21 @@ And tailor it with a CSS style!
}
&#60;/style>
Warning: you may change the default iso-8859-1 encoding if your bib file is in utf-8
Warning: you may change the default iso-8859-1 encoding if your bib file is in utf-8 (define('ENCODING','iso-8859-1') below);
=====Users=====
Don't hesitate to [[http://www.monperrus.net/martin/|contact me]] to be added in the list!
* [[http://telecom.inescporto.pt/~jsc/bibtexbrowser.php|Jaime dos Santos Cardoso, INESC, Portugal]]
* [[http://ccm.uma.pt/bibtexbrowser.php|Centro de Ciências Matemáticas, Portugal]]
* [[http://bioinfo.lri.fr/publi/bibtexbrowser.php|Bioinformatics Group of LRI, Paris, France]]
* [[http://grapple.dcs.warwick.ac.uk/bibtexbrowser/bibtexbrowser.php|M. Hendrix, University of Warwick, UK]]
* [[http://www.cs.usask.ca/home/eramian/bib/Refereed_Journal_Articles.php|Mark Eramian, University of Saskatchewan, Canada]]
* [[https://www.cs.tcd.ie/~marined/publications.php|Dan Marinescu, Trinity College Dublin, Ireland]]
* [[http://kom.aau.dk/~gpp/publications.php?l=EN|Gian Paolo Perrucci, University of Aalborg, Denmark]]
* [[http://dme.uma.pt/luis/page5/bibtexbrowser.php?bib=jluisbib.bib|José Luís da Silva, Universidade da madeira, Portugal]]
===== Related tools =====
=====Related_tools=====
Old-fashioned:
[[http://nxg.me.uk/dist/bibhtml/|bibhtml]], [[http://www.litech.org/~wkiri/bib2html/|bib2html]], [[http://ilab.usc.edu/bibTOhtml/|bibtohtml]], [[http://people.csail.mit.edu/rahimi/bibtex/|bibtextohtml]], [[http://www.lri.fr/~filliatr/bibtex2html/|bibtex2html]], [[http://people.csail.mit.edu/mernst/software/bibtex2web.html |bibtex2web]], [[http://strategoxt.org/Stratego/BibtexTools|stratego bibtex module]]
@ -75,14 +95,13 @@ Misc:
This script is a fork from an excellent script of the University of Texas at El Paso.
(C) 2006-2007-2008 [[http://www.monperrus.net/martin/|Martin Monperrus]] - Don't hesitate to contact me :-)
(C) 2006-2007-2008-2009 Martin Monperrus
(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
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
Current version: v20081111
Past deprecated versions: v20080111, v20080229, v20080303, v20080515, v20080709, v20081027
Current version: v__DATE__
*/
@ -103,8 +122,8 @@ define('Q_AUTHOR', 'author');
define('Q_AUTHOR_PAGE', 'author_page');
define('TAGS_SIZE',20);
define('Q_TAG', 'tag');
define('Q_TAG_PAGE', 'tag_page');
define('Q_TAG', 'keywords');
define('Q_TAG_PAGE', 'keywords_page');
define('Q_TYPE', 'type');
define('Q_TYPE_PAGE', 'type_page');
@ -164,7 +183,7 @@ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && (strtotime($_SERVER['HTTP_IF_MO
exit;
}
// parse a new bib file, if this this file has not been already parsed
// parse a new bib file, if this file has not been already parsed
if (!isset($_SESSION[$filename]) ) {
echo '<!-- parsing '.$filename.'-->';
// we use serialize in order to be able to get a session correctly set up
@ -200,6 +219,7 @@ class BibParser {
//print_r($this->bibdb);
}
/** Returns the array of parsed bib entires. */
function getEntries() {
return $this->bibdb;
@ -302,7 +322,8 @@ class BibParser {
// clean out tex stuff
$result = str_replace('}','', $result);
$result = str_replace('{','', $result);
$result = str_replace(',','', $result);
// comas are important to recognize the author name format
//$result = str_replace(',','', $result);
$result = str_replace("\'", '', $result); // e.g., \'{e}
$result = str_replace('\`', '', $result);
$result = str_replace('\^', '', $result);
@ -553,15 +574,30 @@ function makeHref($query = NULL) {
}
/**
* Returns the formated author name. The argument is assumed to be
* <FirstName LastName>, and the return value is <LastName, FirstName>.
* Returns the last name of an author name. The argument is assumed to be
* <FirstName LastName> or <LastName, FirstName>.
*/
function getLastName($author){
$author = trim($author);
// the author format is "Joe Dupont"
if (strpos($author,',')===false) {
$parts=explode(' ', $author);
// get the last name
return array_pop($parts);
}
// the author format is "Dupont, J."
else {
$parts=explode(',', $author);
// get the last name
return array_shift($parts);
}
}
/**
* Returns the formated author name.
*/
function formatAuthor($author){
return trim($author);
/*return trim(!strrchr($author, ' ') ?
$author :
strrchr($author, ' ') . ', '
.substr($author, 0, strrpos($author, " ")));*/
}
/**
@ -709,7 +745,7 @@ else $page = 1;
global $filename;
$this->result = null;
if (isset($_GET[Q_KEY])){
if ($_GET[Q_KEY]!=''){
if (isset($this->db->bibdb[$_GET[Q_KEY]])) {
$this->result = new SingleResultDisplay(
@ -717,7 +753,7 @@ else $page = 1;
urldecode($_GET[Q_KEY])));
}
else { header('HTTP/1.1 404 Not found'); $this->result = new ErrorDisplay(); }
} else if (isset($_GET[Q_SEARCH])){ // search?
} else if ($_GET[Q_SEARCH]!=''){ // search?
$to_find = $_GET[Q_SEARCH];
$searched = $this->db->search($to_find);
if (count($searched)==1)
@ -727,45 +763,38 @@ else $page = 1;
$this->result = new ResultDisplay($searched, $header,array(Q_SEARCH => $to_find));
}
// clicking an author, a menu item from the authors menu?
} else if (isset($_GET[Q_AUTHOR])) {
$to_find = urldecode($_GET[Q_AUTHOR]);
$searched = $this->db->search($to_find, array('author'));
$header = 'Publications of ' . ucwords($to_find).' in '.$filename ;
$this->result = new ResultDisplay($searched, $header,array(Q_AUTHOR => $to_find));
// clicking a type, a menu item from the types menu?
} else if(isset($_GET[Q_TAG])) {
$to_find = $_GET[Q_TAG];
$searched = $this->db->search($to_find, array('keywords'));
$header = 'Keyword: ' . ucwords($to_find);
$this->result = new ResultDisplay($searched, $header,array(Q_TAG => $to_find));
}
else if(isset($_GET[Q_YEAR])) {
$to_find = $_GET[Q_YEAR];
$searched = $this->db->search($to_find, array('year'));
$header = 'Year: ' . ucwords($to_find);
$this->result = new ResultDisplay($searched, $header,array(Q_YEAR => $to_find));
}
else if(isset($_GET[Q_TYPE])) {
$to_find = $_GET[Q_TYPE];
$searched = $this->db->searchType($to_find);
$header = 'Type: ' . ucwords($to_find);
$this->result = new ResultDisplay($searched, $header,array(Q_TYPE => $to_find));
}
else if(isset($_GET[Q_ALL])) {
} else if(isset($_GET[Q_ALL])) {
$to_find = $_GET[Q_ALL];
$searched = array_values($this->db->bibdb);
$header = 'Bibtex entries in '.$filename ;
$header = 'Bibtex entries';
$this->result = new ResultDisplay($searched, $header,array(Q_ALL =>''));
}
else {
$query = array();
if ($_GET[Q_AUTHOR]!='') { $query[Q_AUTHOR]=$_GET[Q_AUTHOR]; }
if ($_GET[Q_TAG]!='') { $query[Q_TAG]=$_GET[Q_TAG]; }
if ($_GET[Q_YEAR]!='') { $query[Q_YEAR]=$_GET[Q_YEAR]; }
if ($_GET[Q_TYPE]!='') { $query[Q_TYPE]=$_GET[Q_TYPE]; }
//print_r($query);
if (count($query)<1) return false;
$searched = $this->db->multisearch($query);
$headers = array();
foreach($query as $k=>$v) $headers[] = ucwords($k).': '.ucwords($v);
$header = join(' &amp; ',$headers);
$this->result = new ResultDisplay($searched, $header, $query);
}
// adding the bibtex filename
if (isset($this->result)) $this->result->header.=' in '.$filename;
// requesting a different page of the result view?
if (isset($this->result) && isset($_GET[Q_RESULT])) {
$this->result->setPage($_GET[Q_RESULT]);
// we had the page number to the title
// we add the page number to the title
// in order to have unique titles
// google prefers that
$this->result->header.=' - page '.$_GET[Q_RESULT];
// requesting a differen page of type or author menus?
}
@ -1112,7 +1141,7 @@ class SingleResultDisplay extends ResultDisplay {
* bibliographic entries and maintain them.
*/
class BibDataBase {
/** A hash table from IDs (number) to bib entries (BibEntry). */
/** A hash table from keys (e.g. Goody1994) to bib entries (BibEntry instances). */
var $bibdb;
/** Creates a new database by parsing bib entries from the given
@ -1159,18 +1188,19 @@ class BibDataBase {
foreach ($this->bibdb as $bib) {
$authors =explode(' and ', $bib->getAuthor());
foreach($authors as $a){
$ta = trim($a);
$parts=explode(' ', $ta);
// get the last name
$key = array_pop($parts);
$result[$key] = $ta;
//we use an array because several authors can have the same lastname
@$result[getLastName($a)][$a]++;
}
}
ksort($result);
// now authors are sorted by last name
// we rebuild a new array for having good keys in author page
$realresult = array();
foreach($result as $v) $realresult[$v] = formatAuthor($v);
foreach($result as $x) {
ksort($x);
foreach($x as $v => $tmp) $realresult[$v] = formatAuthor($v);
}
return $realresult;
}
@ -1232,10 +1262,31 @@ class BibDataBase {
return $result;
}
/** Returns an array of bib entries (BibEntry) that
* satisfy the query
* $query is an hash with entry type as key and searched fragment as value
*/
function multisearch($query) {
if (count($query)<1) {return array();}
$result = array();
foreach ($this->bibdb as $bib) {
$entryisselected = true;
foreach ($query as $field => $fragment) {
if (($field!='type' && !$bib->hasPhrase(strtolower($fragment), array($field))) || ($field=='type' && $bib->getType()!=$fragment)) {
$entryisselected = false;
}
}
if ($entryisselected) $result[] = $bib;
}
return $result;
}
/** Returns an array of bib entries (BibEntry) that contains the
* given phrase in the given fields. If the fields are empty, all
* fields are searched. */
function search($phrase, $fields = NULL) {
* given phrase.
*/
function search($phrase) {
$phrase = strtolower(trim($phrase));
if (empty($phrase)) {
return array();
@ -1243,14 +1294,14 @@ class BibDataBase {
$result = array();
foreach ($this->bibdb as $bib) {
if ($bib->hasPhrase($phrase, $fields)) {
if ($bib->hasPhrase(strtolower($phrase))) {
$result[] = $bib;
}
}
//print_r($result);
return $result;
}
}
} // end class
function printHTMLHeaders($title,$noindex_metatag=false) {
@ -1260,7 +1311,7 @@ function printHTMLHeaders($title,$noindex_metatag=false) {
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo ENCODING ?>"/>
<meta name="generator" content="bibtexbrowser v20081111" />
<meta name="generator" content="bibtexbrowser v__DATE__" />
<?php if ($noindex_metatag) echo '<meta name="robots" content="noindex"/>' ?>
<title><?php echo $title; ?></title>
<style type="text/css">
@ -1356,6 +1407,7 @@ pre {
.a_name a {
color:#469AF8;
width:130px;
}
.bit_big{
font-size: small;
@ -1376,7 +1428,7 @@ $included=(__FILE__!=$_SERVER['SCRIPT_FILENAME']);
if (isset($_GET['menu']))
{
// menu pages don't need to be indexed by search engines
// we don't set the title and set noindex_metatag to true
// we don't set the title and set noindex metatag to true
printHTMLHeaders("",true);
echo $displaymanager->searchView();
echo $displaymanager->typeVC().'<br/>';
@ -1401,7 +1453,7 @@ else if (!$included) {
<!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">
<head>
<meta name="generator" content="bibtexbrowser v20081111" />
<meta name="generator" content="bibtexbrowser v__DATE__" />
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo ENCODING ?>"/>
<title>You are browsing <?php echo $filename; ?> with bibtexbrowser</title>
</head>

Loading…
Cancel
Save