From 12f6cbd2b3bde924e770e7bbe6575a25f4b1114b Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Fri, 22 May 2015 23:05:00 +0200 Subject: [PATCH] explains how to use other bibliographic formats --- bibtexbrowser-documentation.wiki | 36 ++++++++++++++++++++++++++++++++ bibtexbrowser.php | 10 ++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/bibtexbrowser-documentation.wiki b/bibtexbrowser-documentation.wiki index aa8f0f3..d6335cb 100644 --- a/bibtexbrowser-documentation.wiki +++ b/bibtexbrowser-documentation.wiki @@ -363,6 +363,42 @@ class DynamicDispatcher extends Dispatcher { ?> +====How to load bibliographic data in other formats?==== + +If your bibliographic data comes from XML or a database, you can still browse it with bibtexbrowser as follows: +Add in ''bibtexbrowser.local.php'': +
+define("BIBTEXBROWSER_MAIN", 'PgmDispatcher');
+
+ +and then in ''bibtexbrowser.after.php'': +
+<?php
+class PgmDispatcher extends Dispatcher {
+  function getDB() {
+    $db = new BibDataBase();
+    
+    // builds the first entry
+    $entry = new BibEntry();
+    $entry->setType("article");
+    $entry->setField("title", "foo");
+    $entry->setField("year", "2014");
+    $entry->setKey("kolp");
+    $db->addEntry($entry);
+    
+    // builds the second entry
+    $entry2 = new BibEntry();
+    $entry2->setType("article");
+    $entry2->setField("title", "bar");
+    $entry2->setField("year", "2013");
+    $entry2->setKey("tili");
+    $db->addEntry($entry2);
+    
+    return $db;
+  }
+}
+?>
+
=====Related tools===== diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 1df6804..3562d75 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -1080,7 +1080,6 @@ class BibEntry { } else { //echo "xx".$value."xx\n"; } - $this->fields[$name] = $value; } @@ -3379,6 +3378,15 @@ class BibDataBase { return $this->bibdb[$key]; } + /** Adds a new bib entry to the database. */ + function addEntry($entry) { + if (!$entry->hasField('key')) { + die('error: a bibliographic entry must have a key'); + } + $this->bibdb[$entry->getKey()] = $entry; + } + + /** * Returns an array containing all bib entries matching the given * type.