The library can be used directly on .bib files, or cached using a (SQLite) database. This file is an example of the cached version. Go here to see the demonstration of the static, non DB cached, version.
The basic outline is the same for both scenarios. First, one instantiates a Bibtex object and tells it where to obtain the references from, in this case the 'refs.bib' and 'references.bib' files.
Note that currently the `cite` and `citet` functions can both access a Bibtex object either as their first argument, or as default case, through the global $Site variable.
$Path['lib'] = './lib/';
require_once $Path['lib'] . 'lib_bibtex.inc.php';
$bib = new Bibtex('refs', 'references.bib');
$Site['bibtex'] = $bib; // if we want to use cite([Bibtex $bib], ,
// , ..), without specifying what bib-object
// to cite from as it's first argument, store the
// object in $Site['bibtex'].
The above Bibtex object parses the provided bibtex files on every run;
fine for a small site using small bibtex files, like a personal list of
your publications, but inefficient nevertheless.
Alternatively, one can use a database cached version of the library,
which only re-parses the provided bibtex files if their date of modification
do not match with data in the database. Although the code uses fairly
standard SQL and the PDO interface, it has only been tested using SQLite.
Analogously to above, one can create a Database Cached version of a Bibtex object as follows:
$bdb = new PDO('sqlite:./dbib.sqlite'); // get a PDO for a sqlite database,
// see below for the schema
$bib = new DBibtex($bdb, 'refs', 'references.bib'); // create the actual object.
// if no .bib's are given, only
// data in database is used, no
// attempts to reparse are made
Where the scheme for the database is:
CREATE TABLE bibmeta (fname TEXT, fdate TEXT); CREATE TABLE bibdata (type TEXT, key TEXT, author TEXT, title TEXT, publisher TEXT, year TEXT, booktitle TEXT, editor TEXT, journal TEXT, volume TEXT, number TEXT, note TEXT, implementationurl TEXT, paperurl TEXT, tags TEXT);
Once we have the Bibtex object, we can use it in two ways, i.e.,
- by the standard LaTeX way of sprinkling some text with cite- and citet-functions, or,
- by querying it directly, setting conditions on bibtex fields,
We support all sorts of ordering of the bibliography; not however that if one uses in-text cites, and one requires something else than usage-based order, a pre-scan of the content containing the cites is necessary.
As possible use cases we see
- easily maintainable, dynamic, bibtex file driven, personal (e.g. here) or research group publication listing websites.
- neat scientifically cited overviews, such as for tutorials, e.g. on Mining Sets of Patterns
- all the other, endless, possible uses one can have of having the data in some bibtex files readily available in php.
As I'm particularly bad at writing help-files, I'll just give a live demonstration of the cached, DB version of the library below. You can find the live demonstration of the static, non-DB cached version here. (Note that in the download package you'll find this demo included separately for the two variants.) The library has a (growing) number of undocumented features, so don't be surprised if it can already do what you want, although it is not specified here.
Usage Examples - Cached
First, one instantiates a Bibtex object and tells it where to obtain the references from, in this case the 'refs.bib' and 'references.bib' files. Note that currently the `cite` and `citet` functions can both access a Bibtex object either as their first argument, or as default case, through the global $Site variable.
$bdb = new PDO('sqlite:./dbib.sqlite'); // get a PDO for a sqlite database,
// see below for the schema
$bib = new DBibtex($bdb, 'refs', 'references.bib'); // create the actual object.
// if no .bib's are given, only
// data in database is used, no
// attempts to reparse are made
$Site['bibtex'] = $bib;
We can use the library in two ways, i.e., 1) by querying it directly, and printing the resulting list of publications, or, 2) by the standard LaTeX way of sprinkling some text with cite- and citet-functions, and (optionally) printing the list of referenced publications. For printing the list, these two can be combined. That is, under the hood, both methods simply 'activate' the selected/cited references, and upon printing the list, all 'activated' publications are printed.
Let us start by considering some examples of the 2nd method. For these examples, we consider the following text which we will store in a file called example-content.inc.php.
This and that has long been known to be such and so <?=cite('vreeken2079', 'siebes06',
'DBLP:journals/tkde/MiettinenMGDM08');?>. Furthermore, <?=citet('agrawal93')?>
clearly did not <?=cite($bib, 'agrawal93')?>.
This example includes two calls to the basic cite function, requesting two references present in the provided database, and one missing; and one call to the citet function. The former function displays a (list of) citations in the currently selected style, whereas the latter automatically prints the names of the authors of the reference and then adds its citation. Both functions use, if it is an object the first argument as the Bibtex library, otherwise they fall back to the '$Site['bibtex']' object.
Basic citing, without prescanning. Numeric references, usage-ordered.
In its most basic set-up, we can use the below code
$Site['bibtex']->SetBibliographyStyle('numeric'); // not necessary here, is the default
$Site['bibtex']->SetBibliographyOrder('usage'); // not necessary here, is the default
include 'example-content.inc.php';
$Site['bibtex']->PrintBibliography();
to obtain a numbered bibliography, and to sort the bibliography (and hence, deal the numbers in the order of) based on the order in which they are used in the content, resulting in