Browse Source

*** empty log message ***

replace/c24a8d1de403113542ba0936e844151de2785013
Martin Monperrus 18 years ago
parent
commit
8a425c3864
  1. 93
      bibtexbrowser.php

93
bibtexbrowser.php

@ -108,25 +108,25 @@ if (isset($_GET[Q_FILE])) {
// parse a new bib file, if requested // parse a new bib file, if requested
if (isset($_SESSION[Q_FILE]) && isset($_SESSION['main']) && ($filename == $_SESSION[Q_FILE])) { if (isset($_SESSION[Q_FILE]) && isset($_SESSION['main']) && ($filename == $_SESSION[Q_FILE])) {
$dispmgr = $_SESSION['main'];
$_SESSION['main'] = $_SESSION['main'];
} else { } else {
$dispmgr = new DisplayManager(new BibDataBase($filename));
$_SESSION['main'] = new DisplayManager(new BibDataBase($filename));
} }
$_SESSION[Q_FILE] = $filename; $_SESSION[Q_FILE] = $filename;
// stores the information in the session for performance
$_SESSION['main'] = & $dispmgr;
if (isset($_GET[Q_ENTRY])) {
$headers=getallheaders();
$headers['date'] = time(); // ajout de la date
$headers['file'] = $_GET[Q_FILE].'#'.$_GET[Q_ENTRY];//$dispmgr->db->getEntry($_GET[Q_ENTRY])->getTitle();
$headers['ip'] = $_SERVER["REMOTE_ADDR"];
$file = fopen ("log-bibtexbrowser.txt", "a");
fputs($file,serialize($headers)."\n");
fclose($file);
}
if (isset($_GET[Q_ENTRY])) {//__removeme__
$headers=getallheaders();//__removeme__
if (!eregi("googlebot|slurp|msnbot|fast",$headers['User-Agent'])) {
$headers['date'] = time();//__removeme__
$entry = $_SESSION['main']->db->getEntry($_GET[Q_ENTRY]);//__removeme__
$headers['file'] = $_GET[Q_FILE].'#'.$entry->getTitle();//__removeme__
$headers['ip'] = $_SERVER["REMOTE_ADDR"];//__removeme__
$file = fopen ("log-bibtexbrowser.txt", "a");//__removeme__
fputs($file,serialize($headers)."\n");//__removeme__
fclose($file);//__removeme__
}
}//__removeme__
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
@ -228,7 +228,7 @@ class BibParser {
/** Creates and return a bib entry by doing any postprogessing to /** Creates and return a bib entry by doing any postprogessing to
* the arguments. E.g., canonical rep. of type names. */ * the arguments. E.g., canonical rep. of type names. */
function makeBibEntry($type, $fields, $raw_bib) {
function makeBibEntry($type, &$fields, $raw_bib) {
// remove a trailing comma, if exists. // remove a trailing comma, if exists.
foreach ($fields as $name => $value) { foreach ($fields as $name => $value) {
$fields[$name] = rtrim($value, ','); $fields[$name] = rtrim($value, ',');
@ -295,25 +295,6 @@ class BibParser {
} }
/** A class to parse a single bib entry starting from the given
* source code line. */
class SingleEntryParser extends BibParser {
function SingleEntryParser() {
}
/** Parses and returns an entry. */
function parse($filename, $startIndex) {
$file = fopen($filename, 'r');
while ($startIndex > 0) {
fgets($file, READLINE_LIMIT);
$startIndex--;
}
$e =& $this->parseEntry($file);
fclose($file);
return $e;
}
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// BIB ENTRIES // BIB ENTRIES
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -334,12 +315,12 @@ class BibEntry {
/** Creates a new bib entry. Each bib entry is assigned a unique /** Creates a new bib entry. Each bib entry is assigned a unique
* identification number. */ * identification number. */
function BibEntry($type, $fields = array(), $text = '') {
function BibEntry($type, &$fields, &$text) {
static $id = 0; static $id = 0;
$this->id = $id++; $this->id = $id++;
$this->type = $type; $this->type = $type;
$this->fields =& $fields;
$this->text =& $text;
$this->fields =$fields;
$this->text =$text;
} }
/** Returns the type of this bib entry. */ /** Returns the type of this bib entry. */
@ -464,7 +445,7 @@ class DisplayManager {
/** Creates a new display manager that uses the given bib database. */ /** Creates a new display manager that uses the given bib database. */
function DisplayManager(&$db) { function DisplayManager(&$db) {
$this->db =& $db;
$this->db =$db;
} }
/** Displays the title in a table. */ /** Displays the title in a table. */
@ -746,7 +727,7 @@ class ResultDisplay {
/** Creates an instance with the given entries and header. */ /** Creates an instance with the given entries and header. */
function ResultDisplay(&$result, $header,$filter) { function ResultDisplay(&$result, $header,$filter) {
$this->result =& $result;
$this->result = $result;
$this->header = $header; $this->header = $header;
$this->page = 1; $this->page = 1;
$this->filter = $filter; $this->filter = $filter;
@ -777,24 +758,23 @@ class ResultDisplay {
* displayed. * displayed.
*/ */
function displayContents() { function displayContents() {
$biblist =& $this->result;
$page = $this->page; $page = $this->page;
// print error message if no entry. // print error message if no entry.
if (empty($biblist)) {
if (empty($this->result)) {
echo "<b>No match found!</b>\n"; echo "<b>No match found!</b>\n";
return; return;
} }
// print a page bar, a list of clickable page numbers // print a page bar, a list of clickable page numbers
$pageSize = PAGE_SIZE; // no. of entries per page $pageSize = PAGE_SIZE; // no. of entries per page
$noPages = ceil(count($biblist) / $pageSize);
$noPages = ceil(count($this->result) / $pageSize);
if ($noPages>1) $this->displayPageBar($noPages, $page); if ($noPages>1) $this->displayPageBar($noPages, $page);
// create a year -> entries map to display by years // create a year -> entries map to display by years
$years = array(); $years = array();
foreach ($biblist as $e) {
foreach ($this->result as $e) {
$y = trim($e->getField(YEAR)); $y = trim($e->getField(YEAR));
$years[$y][] = $e; $years[$y][] = $e;
} }
@ -904,18 +884,17 @@ class SingleResultDisplay extends ResultDisplay {
* mutated to read the rest of the fields. * mutated to read the rest of the fields.
*/ */
function SingleResultDisplay(&$bibentry) { function SingleResultDisplay(&$bibentry) {
$this->result =& $bibentry;
$this->result = $bibentry;
$this->header = $this->result->getTitle(); $this->header = $this->result->getTitle();
} }
/** Displays the bib entry, both in the formatted and raw text. /** Displays the bib entry, both in the formatted and raw text.
* The object may be mutated. */ * The object may be mutated. */
function displayContents() { function displayContents() {
$entry =& $this->result;
if ($entry) {
$this->displayEntryFormatted($entry);
if ($this->result) {
$this->displayEntryFormatted($this->result);
echo '<br/><div class="header">BibTeX entry:</div>'; echo '<br/><div class="header">BibTeX entry:</div>';
$this->displayEntryUnformatted($entry);
$this->displayEntryUnformatted($this->result);
} }
} }
@ -1208,13 +1187,13 @@ pre {
</style> </style>
<? <?
$result = $dispmgr->mainVC();
$result = $_SESSION['main']->mainVC();
?> ?>
<title> <title>
<? <?
if ($result != null) echo $result->header.' in '.$filename; if ($result != null) echo $result->header.' in '.$filename;
else echo 'bibtexbrowser: dynamic bibtex to HTML';
else echo 'You are browsing '.$filename;
?> ?>
</title> </title>
@ -1224,16 +1203,14 @@ else echo 'bibtexbrowser: dynamic bibtex to HTML';
if (isset($_GET['menu'])) if (isset($_GET['menu']))
{ {
echo '<body>'; echo '<body>';
echo $dispmgr->searchView();
echo $dispmgr->typeVC().'<br/>';
echo $dispmgr->yearVC().'<br/>';
echo $dispmgr->authorVC().'<br/>';
echo $dispmgr->tagVC().'<br/>';
echo $_SESSION['main']->searchView();
echo $_SESSION['main']->typeVC().'<br/>';
echo $_SESSION['main']->yearVC().'<br/>';
echo $_SESSION['main']->authorVC().'<br/>';
echo $_SESSION['main']->tagVC().'<br/>';
echo '</body>'; echo '</body>';
} // end isset($_GET['menu'] } // end isset($_GET['menu']
else { else {
?>
<?
if ($result != null) { if ($result != null) {
echo '<body>'; echo '<body>';
$result->display(); $result->display();

Loading…
Cancel
Save