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 1a2cbcc commit 8237200
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
25 changes: 14 additions & 11 deletions papercite.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

class Papercite {

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

var $parse = false;

Expand Down Expand Up @@ -221,7 +221,7 @@ function process(&$matches) {
// (1) From the preferences
// (2) From the custom fields
// (3) From the general options
$options = array("format" => "IEEE", "group" => "none");
$options = array("format" => "ieee", "group" => "none", "bibtex_template" => "default", "bibshow_template" => "default");

// Get general preferences
if (!$this->pOptions)
Expand All @@ -246,7 +246,6 @@ function process(&$matches) {
$tplOptions = array("group" => $options["group"], "order" => $options["order"]);
$data = null;


// --- Process the commands ---
switch($command) {

Expand Down Expand Up @@ -295,7 +294,7 @@ function process(&$matches) {

foreach($entries as &$entry)
$entry["key"] = $entry["cite"];
return $this->showEntries($entries, $tplOptions, false);
return $this->showEntries($entries, $tplOptions, false, $this->getTemplate($options["bibtex_template"], $options["format"]));

/*
bibshow / bibcite commands
Expand Down Expand Up @@ -359,16 +358,20 @@ function process(&$matches) {
$refs[$num[0]]["pKey"] = $num[1];
}
}
// grouping of bibentries by year is switched of by default
// for this case, to allow the entries to show up in the
// order of usage
return $this->showEntries($refs, $tplOptions, true);

return $this->showEntries($refs, $tplOptions, true, $this->getTemplate($options["bibshow_template"], $options["format"]));

default:
return "[error in papercite: unhandled]";
}
}

function &getTemplate($mainTpl, $formatTpl) {
$main = file_get_contents(dirname(__FILE__) . "/tpl/" . $mainTpl . ".tpl");
$format = file_get_contents(dirname(__FILE__) . "/format/" . $formatTpl . ".tpl");
$template = str_replace("@#entry@", $format, $main);
return $template;
}

function toDownload($entry) {
if (array_key_exists('url',$entry)){
Expand All @@ -387,13 +390,13 @@ function toDownload($entry) {
* @param options The options to pass to bib2tpl
* @param getKeys Keep track of the keys for a final substitution
*/
function showEntries(&$refs, &$options, $getKeys) {
function showEntries(&$refs, &$options, $getKeys, &$template) {
$bib2tpl = new BibtexConverter($options);

foreach($refs as &$ref)
$ref["entryid"] = $this->counter++;

$r = $bib2tpl->display($refs, file_get_contents(dirname(__FILE__) . "/tpl/default.tpl"));
$r = $bib2tpl->display($refs, $template);
if ($getKeys) {
foreach($refs as &$group)
foreach($group as &$ref) {
Expand Down
15 changes: 4 additions & 11 deletions tpl/default.tpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
@{group@
<h3>@groupkey@ (@groupcount@)</h3>
@#entry@
<ul>
@{entry@
<div>
<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@
@{entry@ <li>
@#entry@
</li>
@}entry@
</ul>

@}group@
</body>

0 comments on commit 8237200

Please sign in to comment.