From fee4593473d62ca11b0a41104219351369bd3189 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Thu, 3 Oct 2013 22:57:32 +0200 Subject: [PATCH] refactoring --- bibtexbrowser.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 093dd46..bb18ab1 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -656,17 +656,15 @@ class BibDBBuilder { return $this; } - function build($bibfilename) { + function build($bibfilename, $handle = NULL) { - if (gettype($bibfilename)=='string') { - $this->filename = $bibfilename; + $this->filename = $bibfilename; + if ($handle == NULL) { $handle = fopen($bibfilename, "r"); - } else { - $this->filename = uniqid(); - $handle = $bibfilename; } if (!$handle) die ('cannot open '.$bibfilename); + $parser = new StateBasedBibtexParser($this); $parser->parse($handle); fclose($handle); @@ -751,7 +749,7 @@ class BibDBBuilder { $this->currentEntry->setTimestamp(); // we add a key if there is no key - if (!$this->currentEntry->hasField(Q_KEY)) { + if (!$this->currentEntry->hasField(Q_KEY) && $this->currentEntry->getType()!='string') { $this->currentEntry->setField(Q_KEY,md5($this->currentEntry->getTitle().implode('',$this->currentEntry->getRawAuthors()))); } @@ -2818,12 +2816,16 @@ class BibDataBase { } /** Updates a database (replaces the new bibtex entries by the most recent ones) */ - function update($filename) { + function update($filename) { + $this->update_internal($filename, NULL); + } + /** See update */ + function update_internal($resource_name, $resource) { $empty_array = array(); $db = createBibDBBuilder(); $db->setData($empty_array, $this->stringdb); - $db->build($filename); + $db->build($resource_name, $resource); $this->stringdb = array_merge($this->stringdb, $db->stringdb); @@ -2846,7 +2848,7 @@ class BibDataBase { // some entries have been removed foreach ($this->bibdb as $e) { if (!isset($result[$e->getKey()]) - && $e->filename==$filename // bug reported by Thomas on Dec 4 2012 + && $e->filename==$resource_name // bug reported by Thomas on Dec 4 2012 ) { //echo 'deleting...
'; unset($this->bibdb[$e->getKey()]);