diff --git a/bibtexbrowser-test.php b/bibtexbrowser-test.php index 5fdb759..6f3cdd7 100755 --- a/bibtexbrowser-test.php +++ b/bibtexbrowser-test.php @@ -209,6 +209,20 @@ class BTBTest extends PHPUnit_Framework_TestCase { } + function test_filter_view() { + $test_data = fopen('php://memory','x+'); + fwrite($test_data, "@article{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009,pages={42--4242},number=1}\n"); + fseek($test_data,0); + $db = new BibDataBase(); + $db->update_internal("inline", $test_data); + $dis = $db->getEntryByKey('aKey'); + $this->assertEquals("@article{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009,pages={42--4242},number=1}",$dis->getText()); + + // now ith option + bibtexbrowser_configure('BIBTEXBROWSER_BIBTEX_VIEW', 'reconstructed'); + bibtexbrowser_configure('BIBTEXBROWSER_BIBTEX_VIEW_FILTEREDOUT', 'pages|number'); + $this->assertEquals("@article{aKey,\n title = {A Book},\n author = {Martin Monperrus},\n publisher = {Springer},\n year = {2009},\n}\n", $dis->getText()); + } } // end class diff --git a/bibtexbrowser.php b/bibtexbrowser.php index c134df1..f5c32dc 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -29,6 +29,16 @@ $CONFIGURATION = array(); function bibtexbrowser_configure($key, $value) { global $CONFIGURATION; $CONFIGURATION[$key]=$value; + if (!defined($key)) { define($key, $value); } // for backward compatibility +} +function bibtexbrowser_configuration($key) { + global $CONFIGURATION; + if (isset($CONFIGURATION[$key])) {return $CONFIGURATION[$key];} + if (defined($key)) {return constant($key);} + throw new Exception('no such configuration parameter: '.$key); +} +function c($key) { // shortcut + return bibtexbrowser_configuration($key); } // *************** CONFIGURATION @@ -1521,13 +1531,13 @@ class BibEntry { /** Returns the verbatim text of this bib entry. */ function getText() { - if (BIBTEXBROWSER_BIBTEX_VIEW == 'original') { + if (c('BIBTEXBROWSER_BIBTEX_VIEW') == 'original') { return $this->text; } - if (BIBTEXBROWSER_BIBTEX_VIEW == 'reconstructed') { + if (c('BIBTEXBROWSER_BIBTEX_VIEW') == 'reconstructed') { $result = '@'.$this->getType().'{'.$this->getKey().",\n"; foreach ($this->fields as $k=>$v) { - if ( !preg_match('/^('.BIBTEXBROWSER_BIBTEX_VIEW_FILTEREDOUT.')$/i', $k) + if ( !preg_match('/^('.c('BIBTEXBROWSER_BIBTEX_VIEW_FILTEREDOUT').')$/i', $k) && !preg_match('/^(key|'.Q_INNER_AUTHOR.'|'.Q_INNER_TYPE.')$/i', $k) ) { $result .= ' '.$k.' = {'.$v.'},'."\n";