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 7, 2011
1 parent 8e952a7 commit 3fa437f
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 52 deletions.
56 changes: 41 additions & 15 deletions bib2tpl/bibtex_converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* http://lmazy.verrech.net
*
* Modified by B. Piwowarski for inclusion in the papercite
* WordPress plug-in
*
* WordPress plug-in:
* - New template engine based on progressive parsing
* - Two templates mode (one for the entries, one for the list)
* - New macros
*
* This work is subject to Creative Commons
* Attribution-NonCommercial-ShareAlike 3.0 Unported.
Expand Down Expand Up @@ -475,8 +477,9 @@ function _callback($match) {
}

$matches = array();
preg_match("/^\?(\w+)(?:([~=><])([^@]+))?$/", $match[1], $matches);
preg_match("/^\?(#?[\w]+)(?:([~=><])([^@]+))?$/", $match[1], $matches);
$value = $this->_get_value($matches[1]);
//print "<div>Compares $value ($matches[1]) [$matches[2]] $matches[3]</div>";
switch($matches[2])
{
case "":
Expand All @@ -488,6 +491,12 @@ function _callback($match) {
case "~":
$condition = preg_match("/$matches[3]/",$value);
break;
case ">":
$condition = (float)$value > (float)$match[3];
break;
case "<":
$condition = (float)$value < (float)$match[3];
break;
default:
$condition = false;
}
Expand Down Expand Up @@ -562,27 +571,44 @@ function _callback($match) {
}

function _get_value($name) {
// --- Get the options
$v = null;
$count = false;

if ($name[0] == "#") {
$name = substr($name,1);
$count = true;
}

$pos = strpos($name, ":");
if ($pos > 0) {
$modifier = substr($name, $pos+1);
$name = substr($name, 0, $pos);
}

if ($this->_entry) {
// Special case: author
if ($name == "author") {
return $this->_helper->niceAuthors($this->_entry["author"], $modifier);
}

// Entry variable
if (array_key_exists($name, $this->_entry))
return $this->_entry[$name];
}
// --- If we have an entry
if ($this->_entry && array_key_exists($name, $this->_entry))
$v = $this->_entry[$name];


// Global variable
if (array_key_exists($name, $this->_globals)) {
return $this->_globals[$name];
else if (array_key_exists($name, $this->_globals)) {
$v = $this->_globals[$name];
}

// --- post processing

if ($count)
if (is_array($v))
return sizeof($v);
else
return $v ? 0 : 1;

if (is_array($v)) {
return $this->_helper->niceAuthors($v, $modifier);
}

return "$v";
}


Expand Down
20 changes: 15 additions & 5 deletions bib2tpl/lib/BibTex.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function parse()
foreach($this->data as &$entry)
foreach($entry as $fieldname => &$field)
if ($fieldname != "bibtex")
if ($fieldname == "author") {
if ($fieldname == "author" || $fieldname == "editor") {
foreach($field as &$text)
Structures_BibTex::process_accents($text);
} else {
Expand All @@ -368,12 +368,13 @@ function parse()
}

static function process_accents(&$text) {
$text = preg_replace_callback("#\\\\(?:['\"^`H~]|¨)\w|\\\\[LlcC]#", "Structures_BibTex::_accents_cb", $text);
$text = preg_replace_callback("#\\\\(?:['\"^`H~\.]|¨)\w|\\\\([LlcCoO]|ss|aa|AA|[ao]e|[OA]E)#", "Structures_BibTex::_accents_cb", $text);
}

static $accents = array(
"\'a" => "á", "\`a" => "à", "\^a" => "â", "\¨a" => "ä", '\"a' => "ä",
"\'A" => "Á", "\`A" => "À", "\^A" => "Â", "\¨A" => "Ä", '\"A' => "Ä",
"\aa" => "å", "\AA" => "Å", "\ae" => "æ", "\AE" => "Æ",
"\cc" => "ç",
"\cC" => "Ç",
"\'e" => "é", "\`e" => "è", "\^e" => "ê", "\¨e" => "ë", '\"e' => "ë",
Expand All @@ -384,11 +385,15 @@ static function process_accents(&$text) {
"\L" => "Ł",
"\~n" => "ñ",
"\~N" => "Ñ",
"\'o" => "ó", "\`o" => "ò", "\^o" => "ô", "\¨o" => "ö", '\"o' => "ö","\Ho" => "ő",
"\'O" => "Ó", "\`o" => "Ò", "\^O" => "Ô", "\¨O" => "Ö", '\"O' => "Ö", "\HO" => "Ő",
"\o" => "ø", "\oe" => "œ",
"\O" => "Ø", "\OE" => "Œ",
"\'o" => "ó", "\`o" => "ò", "\^o" => "ô", "\¨o" => "ö", '\"o' => "ö", "\~o" => "õ", "\Ho" => "ő",
"\'O" => "Ó", "\`o" => "Ò", "\^O" => "Ô", "\¨O" => "Ö", '\"O' => "Ö", "\~O" => "Õ", "\HO" => "Ő",
'\ss' => "ß",
"\'u" => "ú", "\`u" => "ù", "\^u" => "û", "\¨u" => "ü", '\"u' => "ü",
"\'U" => "Ú", "\`U" => "Ù", "\^U" => "Û", "\¨U" => "Ü", '\"U' => "Ü",
"\'z" => "ź",
"\'z" => "ź", "\.z" => "ż",
"\'Z" => "Ź", "\.Z" => "Ż",
);

static function _accents_cb($input) {
Expand Down Expand Up @@ -504,6 +509,11 @@ function _parseEntry($entry)
//Handling the authors
if (in_array('author', array_keys($ret)) && $this->_options['extractAuthors']) {
$ret['author'] = $this->_extractAuthors($ret['author']);

}
//Handling the editors
if (in_array('editor', array_keys($ret)) && $this->_options['extractAuthors']) {
$ret['editor'] = $this->_extractAuthors($ret['editor']);
}
}
return $ret;
Expand Down
34 changes: 34 additions & 0 deletions format/apa.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<formats>
<format types="proceedings unpublished">
@?author@@author@. @;author@@?year@(@year@). @;year@@?title@<span style="font-style: italic">@title@</span>. @;title@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@.
</format>

<format types="misc">
@?author@@author@. @;author@@?year@@year@@;year@@?date@, @date@@;date@@?title@<span style="font-style: italic">@title@</span>. @;title@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?type@ [@type@]@;type@.
</format>

<format types="book">
@?author@@author@. @;author@@?year@(@year@). @;year@@?title@<span style="font-style: italic">@title@</span>@;title@@?edition@@edition@ ed.@?volume@ @:@@;volume@@;edition@@?volume@Vol. @volume@@;volume@@?address@. @address@: @;address@@?publisher@@?@@:@ @;@@publisher@@;publisher@.
</format>

<format types="inbook">
@?author@@author@. @;author@@?year@(@year@). @;year@@?title@@title@. @;title@@?editor@In @editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?bookitle@@?edition@@:@In @;edition@<span style="font-style: italic">@bookitle@</span> @;bookitle@@?edition@@edition@ ed.@;edition@@?volume@@?pages@, @:@@;pages@Vol. @volume@@;volume@@?pages@@?address@, @:@@;address@pp. @pages@@;pages@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@.
</format>

<format types="article #">
@?author@@author@. @;author@@?year@(@year@). @;year@@?title@@title@. @;title@@?journal@<span style="font-style: italic">@journal@</span>@;journal@@?volume@, @volume@@;volume@@?number@(@number@)@;number@@?pages@, @pages@@;pages@.
</format>

<format types="inproceedings">
@?author@@author@. @;author@@?year@@year@@;year@@?date@, @date@@;date@@?title@<span style="font-style: italic">@title@</span>. @;title@@?booktitle@Paper presented at the @booktitle@@;booktitle@@?address@, @address@@;address@.
</format>

<format types="phdthesis">
@?author@@author@. @;author@@?year@(@year@)@?title@. @:@.@;title@@;year@@?title@<span style="font-style: italic">@title@</span>.@;title@@?type@Unpublished @type@ @;type@@?institution@, @institution@@;institution@@?address@, @address@@;address@.
</format>

<format types="techreport">
@?author@@author@. @;author@@?year@(@year@). @;year@@?title@<span style="font-style: italic">@title@</span> @;title@@?type@@type@@;type@@?number@@?address@ @:@@;address@No. @number@@;number@@?address@@address@: @;address@@?institution@@institution@@;institution@.
</format>

</formats>
30 changes: 30 additions & 0 deletions format/britishmedicaljournal.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<formats>
<format types="proceedings unpublished misc">
@?author@@author@. @;author@@?title@<span style="font-style: italic">@title@</span>. @;title@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@, @year@@;year@.
</format>

<format types="techreport">
@?author@@author@. @;author@@?title@<span style="font-style: italic">@title@</span>. @;title@@?type@[@type@] @;type@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@@?date@, @:@@;date@@year@@;year@@?date@ @date@@;date@.
</format>

<format types="book">
@?author@@author@. @;author@@?title@<span style="font-style: italic">@title@</span>. @;title@@?edition@@edition@ ed. @;edition@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@@?@, @:@@;@@year@@;year@.
</format>

<format types="inbook">
@?author@@author@. @;author@@?title@@title@. @;title@@?editor@In: @editor@, @?#editor>1@`editors`@:editor@`editor`@;editor@. @;editor@@?bookitle@@?edition@@:@In: @;edition@<span style="font-style: italic">@bookitle@</span>. @;bookitle@@?edition@@edition@ ed. @;edition@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@@?pages@, @:@@;pages@@year@@;year@@?pages@@?@:@:@, @;@@pages@@;pages@.
</format>

<format types="article #">
@?author@@author@. @;author@@?title@@title@. @;title@@?journal@<span style="font-style: italic">@journal@</span> @;journal@@?year@@year@@;year@@?volume@;@volume@@;volume@@?number@(@number@)@;number@@?pages@:@pages@@;pages@.
</format>

<format types="inproceedings">
@?author@@author@. @;author@@?title@@title@. @;title@@?booktitle@@booktitle@: @;booktitle@@?year@@year@ @;year@@?date@@date@; @;date@@?address@@address@. @;address@@?organization@@organization@@;organization@.
</format>

<format types="phdthesis">
@?author@@author@. @;author@@?title@@title@ @;title@@?type@@type@@;type@@?institution@. @institution@@;institution@@?year@, @year@@;year@.
</format>

</formats>
34 changes: 34 additions & 0 deletions format/chicago.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<formats>
<format types="unpublished misc">
@?author@@author@. @;author@@?year@@year@. @;year@@?title@<span style="font-style: italic">@title@</span>. @;title@@?editor@Edited by @editor@. @;editor@@?address@@address@@?publisher@:@:@.@;publisher@ @;address@@?publisher@@publisher@@;publisher@.
</format>

<format types="techreport">
@?author@@author@. @;author@@?year@@year@. @;year@@?title@<span style="font-style: italic">@title@</span>. @;title@@?address@@address@@?publisher@:@:@.@;publisher@ @;address@@?publisher@@publisher@@;publisher@@?date@, @date@@;date@.
</format>

<format types="book">
@?author@@author@. @;author@@?year@@year@. @;year@@?title@<span style="font-style: italic">@title@</span>. @;title@@?editor@Edited by @editor@. @;editor@@?edition@@edition@ ed. @;edition@@?volume@Vol. @volume@, @;volume@@?series@<span style="font-style: italic">@series@</span>. @;series@@?address@@address@@?publisher@:@:@.@;publisher@ @;address@@?publisher@@publisher@. @;publisher@.
</format>

<format types="inbook">
@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?editor@Edited by @editor@. @;editor@@?bookitle@In <span style="font-style: italic">@bookitle@</span>, @;bookitle@@?address@ @address@@?publisher@:@:@.@;publisher@ @;address@@?publisher@@publisher@. @;publisher@.
</format>

<format types="article #">
@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?journal@<span style="font-style: italic">@journal@</span> @;journal@@?volume@@volume@ @;volume@@?number@(@number@):@;number@@?pages@@pages@@;pages@.
</format>

<format types="proceedings">
@?title@@title@. @;title@@?organization@@organization@@;organization@@?address@@?date@, @:@@;date@@address@@;address@@?date@@date@@;date@@?year@ @year@@;year@.
</format>

<format types="inproceedings">
@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?booktitle@Paper read at @booktitle@@;booktitle@@?date@@?address@, @:@@;address@@date@@;date@@?address@@?@, @:@@;@at @address@@;address@.
</format>

<format types="phdthesis">
@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?type@@type@@;type@@?institution@, @institution@@;institution@@?address@, @address@@;address@.
</format>

</formats>
30 changes: 30 additions & 0 deletions format/harvard.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<formats>
<format types="proceedings unpublished misc">
@?author@@author@ @;author@@?year@(@year@) @;year@@?title@<span style="font-style: italic">@title@</span> @;title@@?editor@@editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?address@@address@, @;address@@?publisher@@publisher@@;publisher@.
</format>

<format types="inproceedings">
@?author@@author@ @;author@@?year@(@year@) @;year@@?title@<span style="font-style: italic">@title@</span> @;title@@?editor@@editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?journal@<span style="font-style: italic">@journal@</span>@;journal@@?address@ @address@, @;address@@?publisher@@publisher@@;publisher@@?pages@, @pages@@;pages@.
</format>

<format types="techreport">
@?author@@author@ @;author@@?year@(@year@) @;year@@?title@<span style="font-style: italic">@title@</span> @;title@@?address@@address@, @;address@@?publisher@@publisher@@;publisher@.
</format>

<format types="book">
@?author@@author@ @;author@@?year@(@year@) @;year@@?title@<span style="font-style: italic">@title@</span> @;title@@?editor@@editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?address@@address@, @;address@@?publisher@@publisher@@;publisher@.
</format>

<format types="inbook">
@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@. @;title@@?editor@@editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?bookitle@<span style="font-style: italic">@bookitle@</span>@;bookitle@@?edition@ @edition@ ed.@;edition@@?address@ @address@@;address@.
</format>

<format types="article #">
@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@. @;title@@?journal@<span style="font-style: italic">@journal@</span>, @;journal@@?volume@@volume@@;volume@@?pages@@pages@@;pages@.
</format>

<format types="phdthesis">
@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@. @;title@@?type@@type@@;type@@?address@@address@, @;address@@?institution@@institution@@;institution@.
</format>

</formats>
37 changes: 29 additions & 8 deletions format/ieee.tpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
<formats>
<format types="# article">
@author:initials@. <span style="font-style: italic;">@title@</span>.
@?journal@@journal@@?volume@ @volume@@?number@ (@number@)@;number@@;volume@, @;journal@
@?publisher@<span class="publist_rest">@publisher@</span>, @;publisher@
@?address@@address@,@;address@
@?year@@?month@@month@ @;month@@year@@;year@
</format>
</formats>
<format types="proceedings unpublished misc">
@?author@@author@, @;author@@?title@<span style="font-style: italic">@title@</span>@;title@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@, @year@@;year@.
</format>

<format types="book">
@?author@@author@, @;author@@?title@<span style="font-style: italic">@title@</span>@;title@@?edition@, @edition@ ed.@;edition@@?editor@, @editor@, @?#editor>1@Eds@:editor@Ed@;editor@.@;editor@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@, @year@@;year@@?volume@, vol. @volume@@;volume@
</format>

<format types="inbook">
@?author@@author@, @;author@@?title@"@title@@;title@@?bookitle@in <span style="font-style: italic">@bookitle@</span>@;bookitle@@?edition@, @edition@ ed.@;edition@@?editor@, @editor@, @?#editor>1@Eds@:editor@Ed@;editor@.@;editor@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@, @year@@;year@@?volume@, vol. @volume@@;volume@@?pages@, @?#pages>1@pp. @:pages@p. @;pages@@pages@@;pages@.
</format>

<format types="article #">
@?author@@author@, @;author@@?title@"@title@@;title@@?journal@<span style="font-style: italic">@journal@</span>@;journal@@?volume@, vol. @volume@@;volume@@?number@, iss. @number@@;number@@?pages@, @?#pages>1@pp. @:pages@p. @;pages@@pages@@;pages@@?year@, @year@@;year@
</format>

<format types="inproceedings">
@?author@@author@, @;author@@?title@"@title@@;title@@?booktitle@in <span style="font-style: italic">@booktitle@</span>@;booktitle@@?address@, @address@@;address@@?date@@date@@;date@@?year@ @year@@;year@@?pages@, @?#pages>1@pp. @:pages@p. @;pages@@pages@@;pages@.
</format>

<format types="phdthesis">
@?author@@author@, @;author@@?title@"@title@," @;title@@?type@@type@ @;type@@?institution@, @institution@@;institution@@?address@, @address@@;address@@?year@, @year@@;year@.
</format>

<format types="techreport">
@?author@@author@, @;author@@?title@"@title@," @;title@@?institution@@institution@@;institution@@?address@, @address@@;address@@?type@@type@ @;type@@?number@@number@@;number@@?date@@date@ @;date@@?year@@year@@;year@.
</format>

</formats>
30 changes: 30 additions & 0 deletions format/mla.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<formats>
<format types="proceedings unpublished misc">
@?author@@author@. @;author@@?title@@title@. @;title@@?editor@@?#editor>1@Eds.@:editor@Ed.@;editor@ @editor@. @;editor@@?address@@address@@?publisher@: @:@@;publisher@@;address@@?publisher@@publisher@, @;publisher@@?year@@year@@;year@.
</format>

<format types="inproceedings">
@?author@@author@. @;author@@?title@"@title@." @;title@@?journal@@journal@. @;journal@@?editor@@?#editor>1@Eds.@:editor@Ed.@;editor@ @editor@. @;editor@@?address@@address@: @;address@@?publisher@@publisher@, @;publisher@@?date@@date@ @;date@@?year@@year@. @;year@@?pages@@pages@@;pages@.
</format>

<format types="book">
@?author@@author@. @;author@@?title@@title@. @;title@@?series@@series@. @;series@@?editor@@?#editor>1@Eds.@:editor@Ed.@;editor@ @editor@. @;editor@@?edition@@edition@ ed. @;edition@@?volume@Vol. @volume@. @;volume@@?address@@address@@?publisher@: @:@@;publisher@@;address@@?publisher@@publisher@, @;publisher@@?year@@year@@;year@.
</format>

<format types="inbook">
@?author@@author@. @;author@@?title@"@title@." @;title@@?bookitle@@bookitle@. @;bookitle@@?editor@@?#editor>1@Eds.@:editor@Ed.@;editor@ @editor@. @;editor@@?edition@@edition@ ed. @;edition@@?volume@Vol. @volume@. @;volume@@?series@@series@. @;series@@?address@@address@: @;address@@?publisher@@publisher@, @;publisher@@?year@@year@. @;year@@?pages@@pages@@;pages@.
</format>

<format types="article #">
@?author@@author@. @;author@@?title@"@title@." @;title@@?journal@[u]@journal@[/u] @;journal@@?volume@@volume@@?number@.@:@ @;number@@;volume@@?number@@number@ @;number@@?year@(@year@)@?pages@: @:@@;pages@@;year@@?pages@@pages@@;pages@.
</format>

<format types="phdthesis">
@?author@@author@. @;author@@?title@"@title@." @;title@@?type@@type@ @;type@@?institution@@institution@, @;institution@@?year@@year@@;year@.
</format>

<format types="techreport">
@?author@@author@. @;author@@?institution@@institution@, @;institution@@?title@[u]@title@[/u]. @;title@@?year@@year@@;year@@?address@ @address@@;address@.
</format>

</formats>
Loading

0 comments on commit 3fa437f

Please sign in to comment.