Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…b8457f37-d9ea-0310-8a92-e5e31aec5664
  • Loading branch information
bpiwowar committed Apr 1, 2011
1 parent 8ade3c3 commit 1a2cbcc
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 34 deletions.
51 changes: 33 additions & 18 deletions papercite.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

// Uncomment when options are debugged
// include("papercite_options.php");

// Options

include("papercite_options.php");

class Papercite {

static $option_names = array("format", "timeout", "file");

var $parse = false;


Expand All @@ -56,9 +57,10 @@ class Papercite {
// Our caches (bibtex files and formats)
var $cache = array();

// List of current citations
// Array of arrays of current citations
var $cites = array();

// Global replacements for cited keys
var $keys = array();
var $keyValues = array();

Expand Down Expand Up @@ -205,6 +207,7 @@ function process(&$matches) {
// Includes once
include_once("bib2tpl/bibtex_converter.php");


// Get the options
$command = $matches[1];

Expand All @@ -213,25 +216,36 @@ function process(&$matches) {
$options_pairs = array();
preg_match_all("/\s*(?:(\w+)=(\S+))(\s+|$)/", $matches[2], $options_pairs, PREG_SET_ORDER);

$options = array();
foreach($options_pairs as $x) {
$options[$x[1]] = $x[2];
// Set preferences, by order of increasing priority
// (0) Set in
// (1) From the preferences
// (2) From the custom fields
// (3) From the general options
$options = array("format" => "IEEE", "group" => "none");

// Get general preferences
if (!$this->pOptions)
$this->pOptions = &get_option('papercite_options');

foreach(self::$option_names as &$name) {
if (array_key_exists($name, $this->pOptions))
$options[$name] = $this->pOptions[$name];
$custom_field = get_post_custom_values("papercite_$name");
if (sizeof($custom_field) > 0)
$options[$name] = $custom_field[0];
}

// Set values if not given
$format = array_key_exists("format", $options) ? $options["format"] : "IEEE";

// Handle grouping
foreach($options_pairs as $x) {
$options[$x[1]] = $x[2];
}

$group = "none";
// For compatibility
// --- Compatibility issues
if (array_key_exists("groupByYear", $options) && (strtoupper($options["groupByYear"]) == "TRUE"))
$group = "year";
else if (array_key_exists("group", $options))
$group = $options["group"];
$options["group"] = "year";

$tplOptions = array("group" => $group, "order" => "desc");
$tplOptions = array("group" => $options["group"], "order" => $options["order"]);
$data = null;


// --- Process the commands ---
switch($command) {
Expand Down Expand Up @@ -413,7 +427,8 @@ function papercite_init() {
wp_enqueue_script('papercite');
}

wp_register_style( 'papercite_css', WP_PLUGIN_URL . '/papercite/papercite.css' );
// Register and enqueue the stylesheet
wp_register_style('papercite_css', WP_PLUGIN_URL . '/papercite/papercite.css' );
wp_enqueue_style('papercite_css');

$papercite = new Papercite();
Expand Down
57 changes: 43 additions & 14 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
=== Plugin Name ===
Contributors: bpiwowar
Tags: formatting, bibtex
Requires at least: 2.0
Tested up to: 3.0.1
Requires at least: 2.7
Tested up to: 3.1
Stable tag: 0.2.14

papercite helps to format bibtex entries to display a bibliography or
Expand Down Expand Up @@ -75,7 +75,9 @@ Just change it.
== Changelog ==

= 0.3.0 =
* Complete code overhaul - switched to a new bibtex / template system
* Complete code overhaul - switched to a new bibtex / template
system
* Preference system to set defaults
= 0.2.14 =
* Grouped by year option (patch due to S. Aiche)
* Now generates an id which does not depend on the key (fix javascript related bugs)
Expand Down Expand Up @@ -151,6 +153,16 @@ PDF file should have be named **KEY**`.pdf` where **KEY** is the
bibtex key in lowercase, where `:` and `/` have been replaced by `-`.


= Options =

You can set default parameters through the options or using
page/post custom fields (use the prefix `papercite_` for
custom fields):
1. `file`: The default bibtex file (can be a URL)
2. `timeout`: The default time-out before reloading an
external resource
2. `format`: The default format

= Bibliography mode =

This is my whole list of publications:
Expand Down Expand Up @@ -192,26 +204,43 @@ You end with the following to print the list of references:

You can modify how publications are displayed using several options:

* format
* groupByYear
* `key-format` How to format the citing key of the publication
* `format` How to format the publication
* `group` How to group publications
* `order` How to order publications

Each of these options are described next. Finally, the template
language used to format entries is described at the following URL:
http://lmazy.verrech.net/bib2tpl/templates/

= Format =

You can modify the style of the citations by using the `format`
parameter with the `bibshow` and `bibtex` commands.
For example,

`[bibtex file=mypub.bib format=britishmedicaljournal]`
`[bibtex file=mypub.bib format=ieee]`

The following format are currently available:

* ieee (default)
* apa
* britishmedicaljournal
* chicago
* harvard
* mla
* turabian

You can group the citations by year using the groupByYear
= Group =

You can group the citations using the `group` option with values
`none` (by default), `year`, `firstauthor`, or `entrytype`.
You can order the groups using the `group-order` option which can take
values among `asc`, `desc` or `none` (none by default).

Example:
`[bibtex file=mypub.bib group=year group-order=desc]`

= Sort =

You can sort the citations using the `sort` option together
by a description of the sorting key. Note that the sort

`[bibtex file=mypub.bib sort=year:desc]`


`[bibtex file=mypub.bib groupByYear=TRUE]`

7 changes: 5 additions & 2 deletions tpl/default.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
@{group@
<h3>@groupkey@ (@groupcount@)</h3>
@#entry@
<ul>
@{entry@
<div>
[@key@] @author@, <strong>@title@</strong>, @year@
<a href="javascript:void(0)" ref="papercite_@entryid@" class="papercite_toggle">show bibtex</a> <div class="papercite_bibtex" id="papercite_@entryid@">
<span class="papercite_author">@author@</span>. <span class="publist_title">@title@</span>. @?journal@<span class="publist_rest">@journal@@?volume@ @volume@@?number@ (@number@)@;number@@;volume@</span>, @;journal@ @?publisher@<span class="publist_rest">@publisher@</span>, @;publisher@ @?address@<span class="publist_rest">@address@</span>, @;address@ <span class="publist_date">@?year@@?month@@month@ @;month@@year@@;year@</span>
<a href="javascript:void(0)" ref="papercite_@entryid@" class="papercite_toggle">show bibtex</a> <div class="papercite_bibtex" id="papercite_@entryid@">
@bibtex@
</div>
</div>
@}entry@
</ul>

@}group@
</body>

0 comments on commit 1a2cbcc

Please sign in to comment.