$skip_duplicates = true; switch ($import_behaviour) { case 'update': // always update $skip_duplicates = false; break; case 'user_skip': case 'user_update': // user can shoose to update/skip $user_update_setting = get_input('user_update_setting'); $skip_duplicates = $user_update_setting !== 'update'; break; } // load lib publications_load_bibtex_browser(); $parser = new BibDataBase(); $parser->load($_FILES['bibtex_import']['tmp_name']); $entries = $parser->getEntries(); if (empty($entries)) { register_error(elgg_echo('publication:bibtex:blank')); forward(REFERER); } $dbprefix = elgg_get_config('dbprefix'); $exists_options = ['type' => 'object', 'subtype' => Publication::SUBTYPE, 'count' => true, 'joins' => ["JOIN {$dbprefix}objects_entity oe ON e.guid = oe.guid"]]; /* handle owned publications only */ if (elgg_get_plugin_setting('bibtex_import_duplicates', 'publications') === 'yes') { $exists_options['owner_guid'] = elgg_get_logged_in_user_guid(); } $entity_attributes = ['guid', 'type', 'subtype', 'owner_guid', 'site_guid', 'container_guid', 'access_id', 'time_created', 'time_updated', 'last_action', 'enabled', 'title', 'description']; $processed_entry_fields = ['x-bibtex-type', 'key', 'title', 'timestamp', 'lines', 'pages', 'author', '_author', 'editor', 'journal', 'abstract']; // a bibtex file can have multiple entries
<!--this is version 1 --> URL: http://www.umweltinformatik-marburg.de/mitarbeiterinnen-und-mitarbeiter/forteva-spaska/ Feedback & Bug Reports: spaska.forteva@uni-marburg.de The programm use (C) 2015 The University Marburg / Spaska Forteva This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ $_GET['library'] = 1; define('BIBTEXBROWSER_BIBTEX_LINKS',false); // no [bibtex] link by default require_once('lib/bibtexbrowser.php'); global $db; $db = new BibDataBase(); $db->load('ei/ei_publications.bib'); $author = $_GET['author']; # Publications-titles mapping depends from the language $mainTitles = array(); if(isset($_GET['l'])) { if ( $_GET['l'] == 1) { $mainTitles = array('article'=>'Articles', 'techreport'=>'Software/technical reports', 'inbook'=>'Book chapters', 'book'=>'Book chapters', 'conference'=>'Conference papers/contributions', 'unpublished'=>'Submitted articles' );
function test_zotero() { $test_data = fopen('php://memory', 'x+'); fwrite($test_data, "@book{aKey,file={myarticle.pdf}}\n"); fseek($test_data, 0); $btb = new BibDataBase(); $btb->update_internal("inline", $test_data); $first_entry = $btb->bibdb[array_keys($btb->bibdb)[0]]; $this->assertEquals('<a href="myarticle.pdf">[pdf]</a>', $first_entry->getUrlLink()); }
function test_BIBTEXBROWSER_USE_LATEX2HTML() { $bibtex = "@article{aKey,title={\\`a Book},author={Martin Monperrus},publisher={Springer},year=2009,pages={42--4242},number=1}\n"; bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', true); $test_data = fopen('php://memory', 'x+'); fwrite($test_data, $bibtex); fseek($test_data, 0); $db = new BibDataBase(); $db->update_internal("inline", $test_data); $dis = $db->getEntryByKey('aKey'); $this->assertEquals("à Book", $dis->getTitle()); bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', false); $test_data = fopen('php://memory', 'x+'); fwrite($test_data, $bibtex); fseek($test_data, 0); $db = new BibDataBase(); $db->update_internal("inline", $test_data); $dis = $db->getEntryByKey('aKey'); $this->assertEquals("\\`a Book", $dis->getTitle()); }
/** sets the database of bibtex entries (object of type BibDataBase) * in $_GET[Q_DB] * Uses a caching mechanism on disk for sake of performance */ function setDB() { // default bib file, if no file is specified in the query string. if (!isset($_GET[Q_FILE]) || $_GET[Q_FILE] == "") { ?> <div id="bibtexbrowser_message"> Congratulations! bibtexbrowser is correctly installed!<br/> Now you have to pass the name of the bibtex file as parameter (e.g. bibtexbrowser.php?bib=mybib.php)<br/> You may browse:<br/> <?php foreach (glob("*.bib") as $bibfile) { $url = "?bib=" . $bibfile; echo '<a href="' . $url . '">' . $bibfile . '</a><br/>'; } echo "</div>"; return; // we cannot set the db wtihout a bibfile } // first does the bibfiles exist: // $_GET[Q_FILE] can be urlencoded for instance if they contain slashes // so we decode it $_GET[Q_FILE] = urldecode($_GET[Q_FILE]); // ---------------------------- HANDLING unexistent files foreach (explode(MULTIPLE_BIB_SEPARATOR, $_GET[Q_FILE]) as $bib) { if (!file_exists($bib)) { // to automate dectection of faulty links with tools such as webcheck header('HTTP/1.1 404 Not found'); die('<b>the bib file ' . $bib . ' 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, $_GET[Q_FILE]) 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($_GET[Q_FILE]) . '.dat'; $parse = true; foreach (explode(MULTIPLE_BIB_SEPARATOR, $_GET[Q_FILE]) as $bib) { // do we have a compiled version ? if (is_file($compiledbib) && is_readable($compiledbib)) { // 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)) { $_GET[Q_DB] = unserialize(file_get_contents($compiledbib)); // basic test // do we have an correct version of the file if (is_a($_GET[Q_DB], 'BibDataBase')) { // at least we can switch off the parsing $parse = false; } } } } // end for each // we don't have a compiled version if ($parse) { //echo '<!-- parsing -->'; // then parsing the file $db = new BibDataBase(); foreach (explode(MULTIPLE_BIB_SEPARATOR, $_GET[Q_FILE]) as $bib) { $db->load($bib); } $_GET[Q_DB] = $db; // are we able to save the compiled version ? // note that the compiled version is saved in the current working directory if (!is_file($compiledbib) && is_writable(getcwd()) || is_file($compiledbib) && is_writable($compiledbib)) { // we can use file_put_contents // but don't do it for compatibility with PHP 4.3 $f = fopen($compiledbib, 'w'); //we use a lock to avoid that a call to bbtexbrowser made while we write the object loads an incorrect object if (flock($f, LOCK_EX)) { fwrite($f, serialize($_GET[Q_DB])); } fclose($f); } //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) -->'; } // end parsing and saving }
URL: http://www.umweltinformatik-marburg.de/mitarbeiterinnen-und-mitarbeiter/forteva-spaska/ Feedback & Bug Reports: spaska.forteva@uni-marburg.de The programm use (C) 2015 The University Marburg / Spaska Forteva This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ $_GET['library'] = 1; define('BIBTEXBROWSER_BIBTEX_LINKS',false); // no [bibtex] link by default require_once('lib/bibtexbrowser.php'); global $db; $db = new BibDataBase(); $db->load('ei/ei_projects.bib'); # Publications-titles mapping depends from the language $mainTitles = array(); if(isset($_GET['l'])) { if ( $_GET['l'] == 1) { $mainTitles = array('app' => array('Applicants', 'Applicant'), 'pp' => 'Participating partner', 'fn' => 'Funding', 'ps' => array('Project staffs', 'Project staff'), 'web'=> 'Web', 'year'=>'Funding' ); } else { $mainTitles = array('app' => array('Applicants', 'Applicant'),