function test_config_value()
 {
     // default value
     $this->assertFalse(config_value('BIBTEXBROWSER_NO_DEFAULT'));
     // setting to true
     bibtexbrowser_configure('BIBTEXBROWSER_NO_DEFAULT', true);
     $this->assertTrue(config_value('BIBTEXBROWSER_NO_DEFAULT'));
     ob_start();
     default_message();
     $this->assertEquals('', ob_get_flush());
     // setting to false
     bibtexbrowser_configure('BIBTEXBROWSER_NO_DEFAULT', false);
     $this->assertFalse(config_value('BIBTEXBROWSER_NO_DEFAULT'));
     ob_start();
     default_message();
     $this->assertContains('Congratulations', ob_get_flush());
 }
 /** @nodoc */
 function _zetDB($bibtex_filenames)
 {
     $db = null;
     // Check if magic_quotes_runtime is active
     if (get_magic_quotes_runtime()) {
         // Deactivate
         // otherwise it does not work
         set_magic_quotes_runtime(false);
     }
     // default bib file, if no file is specified in the query string.
     if (!isset($bibtex_filenames) || $bibtex_filenames == "") {
         default_message();
         exit;
     }
     // first does the bibfiles exist:
     // $bibtex_filenames can be urlencoded for instance if they contain slashes
     // so we decode it
     $bibtex_filenames = urldecode($bibtex_filenames);
     // ---------------------------- HANDLING unexistent files
     foreach (explode(MULTIPLE_BIB_SEPARATOR, $bibtex_filenames) as $bib) {
         // get file extension to only allow .bib files
         $ext = pathinfo($bib, PATHINFO_EXTENSION);
         // this is a security protection
         if (BIBTEXBROWSER_LOCAL_BIB_ONLY && (!file_exists($bib) || strcasecmp($ext, 'bib') != 0)) {
             // to automate dectection of faulty links with tools such as webcheck
             header('HTTP/1.1 404 Not found');
             // escape $bib to prevent XSS
             $escapedBib = htmlEntities($bib, ENT_QUOTES);
             die('<b>the bib file ' . $escapedBib . ' does not exist !</b>');
         }
     }
     // end for each
     // ---------------------------- HANDLING HTTP If-modified-since
     // testing with $ curl -v --header "If-Modified-Since: Fri, 23 Oct 2010 19:22:47 GMT" "... bibtexbrowser.php?key=wasylkowski07&bib=..%252Fstrings.bib%253B..%252Fentries.bib"
     // and $ curl -v --header "If-Modified-Since: Fri, 23 Oct 2000 19:22:47 GMT" "... bibtexbrowser.php?key=wasylkowski07&bib=..%252Fstrings.bib%253B..%252Fentries.bib"
     // save bandwidth and server cpu
     // (imagine the number of requests from search engine bots...)
     $bib_is_unmodified = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
     foreach (explode(MULTIPLE_BIB_SEPARATOR, $bibtex_filenames) as $bib) {
         $bib_is_unmodified = $bib_is_unmodified && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) > filemtime($bib);
     }
     // end for each
     if ($bib_is_unmodified && !headers_sent()) {
         header("HTTP/1.1 304 Not Modified");
         exit;
     }
     // ---------------------------- HANDLING caching of compiled bibtex files
     // for sake of performance, once the bibtex file is parsed
     // we try to save a "compiled" in a txt file
     $compiledbib = 'bibtexbrowser_' . md5($bibtex_filenames) . '.dat';
     $parse = filemtime(__FILE__) > @filemtime($compiledbib);
     // do we have a compiled version ?
     if (is_file($compiledbib) && is_readable($compiledbib) && filesize($compiledbib) > 0) {
         $f = fopen($compiledbib, 'r+');
         // some Unix seem to consider flock as a writing operation
         //we use a lock to avoid that a call to bibbtexbrowser made while we write the object loads an incorrect object
         if (flock($f, LOCK_EX)) {
             $s = filesize($compiledbib);
             $ser = fread($f, $s);
             $db = @unserialize($ser);
             flock($f, LOCK_UN);
         } else {
             die('could not get the lock');
         }
         fclose($f);
         // basic test
         // do we have an correct version of the file
         if (!is_a($db, 'BibDataBase')) {
             unlink($compiledbib);
             if (BIBTEXBROWSER_DEBUG) {
                 die('$db not a BibDataBase. please reload.');
             }
             $parse = true;
         }
     } else {
         $parse = true;
     }
     // we don't have a compiled version
     if ($parse) {
         //echo '<!-- parsing -->';
         // then parsing the file
         $db = createBibDataBase();
         foreach (explode(MULTIPLE_BIB_SEPARATOR, $bibtex_filenames) as $bib) {
             $db->load($bib);
         }
     }
     $updated = false;
     // now we may update the database
     if (!file_exists($compiledbib)) {
         @touch($compiledbib);
         $updated = true;
         // limit case
     } else {
         foreach (explode(MULTIPLE_BIB_SEPARATOR, $bibtex_filenames) as $bib) {
             // is it up to date ? wrt to the bib file and the script
             // then upgrading with a new version of bibtexbrowser triggers a new compilation of the bib file
             if (filemtime($bib) > filemtime($compiledbib) || filemtime(__FILE__) > filemtime($compiledbib)) {
                 //       echo "updating  ".$bib;
                 $db->update($bib);
                 $updated = true;
             }
         }
     }
     //   echo var_export($parse);
     //   echo var_export($updated);
     $saved = false;
     // are we able to save the compiled version ?
     // note that the compiled version is saved in the current working directory
     if (($parse || $updated) && is_writable($compiledbib)) {
         // we use 'a' because the file is not locked between fopen and flock
         $f = fopen($compiledbib, 'a');
         //we use a lock to avoid that a call to bibbtexbrowser made while we write the object loads an incorrect object
         if (flock($f, LOCK_EX)) {
             //       echo '<!-- saving -->';
             ftruncate($f, 0);
             fwrite($f, serialize($db));
             flock($f, LOCK_UN);
             $saved = true;
         } else {
             die('could not get the lock');
         }
         fclose($f);
     }
     // end saving the cached verions
     //else echo '<!-- please chmod the directory containing the bibtex file to be able to keep a compiled version (much faster requests for large bibtex files) -->';
     return array(&$db, $parse, $updated, $saved);
 }