From 3fa437fcedd1ff28140e2210788b1ef6b2be958e Mon Sep 17 00:00:00 2001 From: bpiwowar Date: Thu, 7 Apr 2011 09:53:46 +0000 Subject: [PATCH] git-svn-id: https://plugins.svn.wordpress.org/papercite/trunk@369988 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- bib2tpl/bibtex_converter.php | 56 +++++++++++++++++++++++--------- bib2tpl/lib/BibTex.php | 20 +++++++++--- format/apa.tpl | 34 +++++++++++++++++++ format/britishmedicaljournal.tpl | 30 +++++++++++++++++ format/chicago.tpl | 34 +++++++++++++++++++ format/harvard.tpl | 30 +++++++++++++++++ format/ieee.tpl | 37 ++++++++++++++++----- format/mla.tpl | 30 +++++++++++++++++ format/turabian.tpl | 30 +++++++++++++++++ papercite.php | 17 ++++------ readme.txt | 7 ++-- utils/osbib2tpl.php | 54 +++++++++++++++++++++++------- 12 files changed, 327 insertions(+), 52 deletions(-) create mode 100644 format/apa.tpl create mode 100644 format/britishmedicaljournal.tpl create mode 100644 format/chicago.tpl create mode 100644 format/harvard.tpl create mode 100644 format/mla.tpl create mode 100644 format/turabian.tpl diff --git a/bib2tpl/bibtex_converter.php b/bib2tpl/bibtex_converter.php index 0725c32..80461b2 100644 --- a/bib2tpl/bibtex_converter.php +++ b/bib2tpl/bibtex_converter.php @@ -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. @@ -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 "
Compares $value ($matches[1]) [$matches[2]] $matches[3]
"; switch($matches[2]) { case "": @@ -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; } @@ -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"; } diff --git a/bib2tpl/lib/BibTex.php b/bib2tpl/lib/BibTex.php index 4ea27e6..117d94d 100644 --- a/bib2tpl/lib/BibTex.php +++ b/bib2tpl/lib/BibTex.php @@ -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 { @@ -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' => "ë", @@ -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) { @@ -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; diff --git a/format/apa.tpl b/format/apa.tpl new file mode 100644 index 0000000..6018a50 --- /dev/null +++ b/format/apa.tpl @@ -0,0 +1,34 @@ + + +@?author@@author@. @;author@@?year@(@year@). @;year@@?title@@title@. @;title@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@. + + + +@?author@@author@. @;author@@?year@@year@@;year@@?date@, @date@@;date@@?title@@title@. @;title@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?type@ [@type@]@;type@. + + + +@?author@@author@. @;author@@?year@(@year@). @;year@@?title@@title@@;title@@?edition@@edition@ ed.@?volume@ @:@@;volume@@;edition@@?volume@Vol. @volume@@;volume@@?address@. @address@: @;address@@?publisher@@?@@:@ @;@@publisher@@;publisher@. + + + +@?author@@author@. @;author@@?year@(@year@). @;year@@?title@@title@. @;title@@?editor@In @editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?bookitle@@?edition@@:@In @;edition@@bookitle@ @;bookitle@@?edition@@edition@ ed.@;edition@@?volume@@?pages@, @:@@;pages@Vol. @volume@@;volume@@?pages@@?address@, @:@@;address@pp. @pages@@;pages@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@. + + + +@?author@@author@. @;author@@?year@(@year@). @;year@@?title@@title@. @;title@@?journal@@journal@@;journal@@?volume@, @volume@@;volume@@?number@(@number@)@;number@@?pages@, @pages@@;pages@. + + + +@?author@@author@. @;author@@?year@@year@@;year@@?date@, @date@@;date@@?title@@title@. @;title@@?booktitle@Paper presented at the @booktitle@@;booktitle@@?address@, @address@@;address@. + + + +@?author@@author@. @;author@@?year@(@year@)@?title@. @:@.@;title@@;year@@?title@@title@.@;title@@?type@Unpublished @type@ @;type@@?institution@, @institution@@;institution@@?address@, @address@@;address@. + + + +@?author@@author@. @;author@@?year@(@year@). @;year@@?title@@title@ @;title@@?type@@type@@;type@@?number@@?address@ @:@@;address@No. @number@@;number@@?address@@address@: @;address@@?institution@@institution@@;institution@. + + + diff --git a/format/britishmedicaljournal.tpl b/format/britishmedicaljournal.tpl new file mode 100644 index 0000000..6924629 --- /dev/null +++ b/format/britishmedicaljournal.tpl @@ -0,0 +1,30 @@ + + +@?author@@author@. @;author@@?title@@title@. @;title@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@, @year@@;year@. + + + +@?author@@author@. @;author@@?title@@title@. @;title@@?type@[@type@] @;type@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@@?date@, @:@@;date@@year@@;year@@?date@ @date@@;date@. + + + +@?author@@author@. @;author@@?title@@title@. @;title@@?edition@@edition@ ed. @;edition@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@@?@, @:@@;@@year@@;year@. + + + +@?author@@author@. @;author@@?title@@title@. @;title@@?editor@In: @editor@, @?#editor>1@`editors`@:editor@`editor`@;editor@. @;editor@@?bookitle@@?edition@@:@In: @;edition@@bookitle@. @;bookitle@@?edition@@edition@ ed. @;edition@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@@?pages@, @:@@;pages@@year@@;year@@?pages@@?@:@:@, @;@@pages@@;pages@. + + + +@?author@@author@. @;author@@?title@@title@. @;title@@?journal@@journal@ @;journal@@?year@@year@@;year@@?volume@;@volume@@;volume@@?number@(@number@)@;number@@?pages@:@pages@@;pages@. + + + +@?author@@author@. @;author@@?title@@title@. @;title@@?booktitle@@booktitle@: @;booktitle@@?year@@year@ @;year@@?date@@date@; @;date@@?address@@address@. @;address@@?organization@@organization@@;organization@. + + + +@?author@@author@. @;author@@?title@@title@ @;title@@?type@@type@@;type@@?institution@. @institution@@;institution@@?year@, @year@@;year@. + + + diff --git a/format/chicago.tpl b/format/chicago.tpl new file mode 100644 index 0000000..5c25f3e --- /dev/null +++ b/format/chicago.tpl @@ -0,0 +1,34 @@ + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?editor@Edited by @editor@. @;editor@@?address@@address@@?publisher@:@:@.@;publisher@ @;address@@?publisher@@publisher@@;publisher@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?address@@address@@?publisher@:@:@.@;publisher@ @;address@@?publisher@@publisher@@;publisher@@?date@, @date@@;date@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?editor@Edited by @editor@. @;editor@@?edition@@edition@ ed. @;edition@@?volume@Vol. @volume@, @;volume@@?series@@series@. @;series@@?address@@address@@?publisher@:@:@.@;publisher@ @;address@@?publisher@@publisher@. @;publisher@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?editor@Edited by @editor@. @;editor@@?bookitle@In @bookitle@, @;bookitle@@?address@ @address@@?publisher@:@:@.@;publisher@ @;address@@?publisher@@publisher@. @;publisher@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?journal@@journal@ @;journal@@?volume@@volume@ @;volume@@?number@(@number@):@;number@@?pages@@pages@@;pages@. + + + +@?title@@title@. @;title@@?organization@@organization@@;organization@@?address@@?date@, @:@@;date@@address@@;address@@?date@@date@@;date@@?year@ @year@@;year@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?booktitle@Paper read at @booktitle@@;booktitle@@?date@@?address@, @:@@;address@@date@@;date@@?address@@?@, @:@@;@at @address@@;address@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?type@@type@@;type@@?institution@, @institution@@;institution@@?address@, @address@@;address@. + + + diff --git a/format/harvard.tpl b/format/harvard.tpl new file mode 100644 index 0000000..b703287 --- /dev/null +++ b/format/harvard.tpl @@ -0,0 +1,30 @@ + + +@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@ @;title@@?editor@@editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?address@@address@, @;address@@?publisher@@publisher@@;publisher@. + + + +@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@ @;title@@?editor@@editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?journal@@journal@@;journal@@?address@ @address@, @;address@@?publisher@@publisher@@;publisher@@?pages@, @pages@@;pages@. + + + +@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@ @;title@@?address@@address@, @;address@@?publisher@@publisher@@;publisher@. + + + +@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@ @;title@@?editor@@editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?address@@address@, @;address@@?publisher@@publisher@@;publisher@. + + + +@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@. @;title@@?editor@@editor@ (@?#editor>1@Eds.@:editor@Ed.@;editor@), @;editor@@?bookitle@@bookitle@@;bookitle@@?edition@ @edition@ ed.@;edition@@?address@ @address@@;address@. + + + +@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@. @;title@@?journal@@journal@, @;journal@@?volume@@volume@@;volume@@?pages@@pages@@;pages@. + + + +@?author@@author@ @;author@@?year@(@year@) @;year@@?title@@title@. @;title@@?type@@type@@;type@@?address@@address@, @;address@@?institution@@institution@@;institution@. + + + diff --git a/format/ieee.tpl b/format/ieee.tpl index ae0f008..a2b6dfb 100644 --- a/format/ieee.tpl +++ b/format/ieee.tpl @@ -1,9 +1,30 @@ - - @author:initials@. @title@. - @?journal@@journal@@?volume@ @volume@@?number@ (@number@)@;number@@;volume@, @;journal@ - @?publisher@@publisher@, @;publisher@ - @?address@@address@,@;address@ - @?year@@?month@@month@ @;month@@year@@;year@ - - \ No newline at end of file + +@?author@@author@, @;author@@?title@@title@@;title@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@@?year@, @year@@;year@. + + + +@?author@@author@, @;author@@?title@@title@@;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@ + + + +@?author@@author@, @;author@@?title@"@title@@;title@@?bookitle@in @bookitle@@;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@. + + + +@?author@@author@, @;author@@?title@"@title@@;title@@?journal@@journal@@;journal@@?volume@, vol. @volume@@;volume@@?number@, iss. @number@@;number@@?pages@, @?#pages>1@pp. @:pages@p. @;pages@@pages@@;pages@@?year@, @year@@;year@ + + + +@?author@@author@, @;author@@?title@"@title@@;title@@?booktitle@in @booktitle@@;booktitle@@?address@, @address@@;address@@?date@@date@@;date@@?year@ @year@@;year@@?pages@, @?#pages>1@pp. @:pages@p. @;pages@@pages@@;pages@. + + + +@?author@@author@, @;author@@?title@"@title@," @;title@@?type@@type@ @;type@@?institution@, @institution@@;institution@@?address@, @address@@;address@@?year@, @year@@;year@. + + + +@?author@@author@, @;author@@?title@"@title@," @;title@@?institution@@institution@@;institution@@?address@, @address@@;address@@?type@@type@ @;type@@?number@@number@@;number@@?date@@date@ @;date@@?year@@year@@;year@. + + + diff --git a/format/mla.tpl b/format/mla.tpl new file mode 100644 index 0000000..68b18a3 --- /dev/null +++ b/format/mla.tpl @@ -0,0 +1,30 @@ + + +@?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@. + + + +@?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@. + + + +@?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@. + + + +@?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@. + + + +@?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@. + + + +@?author@@author@. @;author@@?title@"@title@." @;title@@?type@@type@ @;type@@?institution@@institution@, @;institution@@?year@@year@@;year@. + + + +@?author@@author@. @;author@@?institution@@institution@, @;institution@@?title@[u]@title@[/u]. @;title@@?year@@year@@;year@@?address@ @address@@;address@. + + + diff --git a/format/turabian.tpl b/format/turabian.tpl new file mode 100644 index 0000000..ae3b074 --- /dev/null +++ b/format/turabian.tpl @@ -0,0 +1,30 @@ + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?editor@Edited by @editor@. @;editor@@?address@@address@: @;address@@?publisher@@publisher@@;publisher@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?journal@@journal@ @;journal@@?address@@address@: @;address@@?publisher@@publisher@. @;publisher@@?date@@date@@;date@@?pages@, @pages@@;pages@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?editor@Edited by @editor@. @;editor@@?series@@series@. @;series@@?address@@address@: @;address@@?publisher@@publisher@. @;publisher@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?bookitle@In @bookitle@@;bookitle@@?editor@, ed. @editor@@;editor@@?volume@, @volume@:@;volume@@?pages@@?address@@:@ @;address@@pages@@;pages@@?address@. @address@: @;address@@?publisher@@publisher@. @;publisher@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?journal@@journal@ @;journal@@?volume@@volume@@;volume@@?number@, @number@@;number@@?pages@: @pages@@;pages@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?type@@type@, @;type@@?institution@@institution@@;institution@. + + + +@?author@@author@. @;author@@?year@@year@. @;year@@?title@@title@. @;title@@?address@@address@: @;address@@?institution@@institution@. @;institution@@?type@@type@@;type@@?number@, @number@@;number@. + + + diff --git a/papercite.php b/papercite.php index dfc9d6c..7076ccf 100755 --- a/papercite.php +++ b/papercite.php @@ -4,7 +4,7 @@ Plugin Name: papercite Plugin URI: http://www.bpiwowar.net/papercite Description: papercite enables to add BibTeX entries formatted as HTML in wordpress pages and posts. The input data is the bibtex text file and the output is HTML. - Version: 0.3.3 + Version: 0.3.4 Author: Benjamin Piwowarski Author URI: http://www.bpiwowar.net */ @@ -16,14 +16,8 @@ - Stefan Aiche: group by year option - Łukasz Radliński: bug fixes & handling polish characters - - Sergio Andreozzi has written bib2html on which papercite is based - Contributors (bib2html): - - Cristiana Bolchini: cleaner bibtex presentation - - Patrick Maué: remote bibliographies managed by citeulike.org or bibsonomy.org - - Nemo: more characters on key - - Marco Loregian: inverting bibtex and html - + Some parts of the code come from bib2html (version 0.9.3) written by + Sergio Andreozzi. 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 @@ -478,17 +472,18 @@ function papercite_cb($myContent) { return str_replace($papercite->keys, $papercite->keyValues, $text); } +// --- Add the documentation link in the plugin list function papercite_row_cb($data, $file) { if ($file == "papercite/papercite.php") { $data[] = "Documentation"; } return $data; } +add_filter('plugin_row_meta', 'papercite_row_cb',1,2); // --- Add the different handlers to WordPress --- add_action('init', 'papercite_init'); add_action('wp_head', 'papercite_head'); -add_filter('the_content', 'papercite_cb',1); -add_filter('plugin_row_meta', 'papercite_row_cb',1,2); +add_filter('the_content', 'papercite_cb'); ?> diff --git a/readme.txt b/readme.txt index faa2027..540ff6e 100755 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: bpiwowar Tags: formatting, bibtex Requires at least: 2.7 Tested up to: 3.1.1 -Stable tag: 0.3.3 +Stable tag: 0.3.4 papercite helps to format bibtex entries to display a bibliography or cite papers. @@ -81,7 +81,10 @@ subfolders tpl (citation list rendering) and format (entry rendering). == Changelog == - += 0.3.4 = + * Formats are back, translated from OSBib (not perfect, but close to + the output in version prior to 0.3.0 + * More latex accents handled = 0.3.3 = * Fixed bug 7: umlaut (still) not handled * Fixed bug 12: bug with remote URLs diff --git a/utils/osbib2tpl.php b/utils/osbib2tpl.php index 13f1b00..f6867c4 100644 --- a/utils/osbib2tpl.php +++ b/utils/osbib2tpl.php @@ -59,6 +59,7 @@ function readResource(&$formats, $xml, $bibtexMap) { $bibtexType = $bibtexMap->types[$type]; $depth = $xml->depth; + $data = array(); while ($xml->levelRead($depth)) { // Got an element @@ -73,35 +74,66 @@ function readResource(&$formats, $xml, $bibtexMap) { } if ($xml->name == "ultimate") { - $data .= $xml->readString(); - } - - if (!array_key_exists($xml->name, $bibtexMap->$type)) + $data[] = array("", $xml->readString()); + } + else if ($xml->name == "independent") { + $xml->skipToEnd(); + } else if (!array_key_exists($xml->name, $bibtexMap->$type)) { + msg("Cannot translate $xml->name in $type\n"); + $data[] = array("",""); $xml->skipToEnd(); - else { + } else { $types = &$bibtexMap->$type; $name = $types[$xml->name]; $fieldDepth = $xml->depth; $pre = ""; $post = ""; + $values = array(); while ($xml->levelRead($fieldDepth)) { if ($xml->nodeType == XMLReader::ELEMENT) { - switch($xml->name) { - case "pre": $pre = processShortcodes($xml->readString()); break; - case "post": $post = processShortcodes($xml->readString()); break; - } + $values[$xml->name] = processShortcodes($xml->readString()); $xml->skiptoEnd(); } } - $data .= "$pre@$name@$post"; + $data[] = array($name, $values); } } // end (element) } + // Deals with the special OSBib fields + // and concatenate the bib2tpl string + $text = ""; + for($i = 0; $i < sizeof($data); $i++) { + $row = &$data[$i]; + $name = $row[0]; + if ($name) { + $options = &$row[1]; + $field = "@?$name@$options[pre]@$name@$options[post]@;$name@"; + $field = preg_replace("/__SINGULAR_PLURAL__/", "@?#$name>1@$options[plural]@:$name@$options[singular]@;$name@", $field); + + $next = $i+1 < sizeof($data) ? $data[$i+1][0] : false; + if ($next) { + $field = preg_replace("/__DEPENDENT_ON_NEXT_FIELD__/", "@?$next@$options[dependentPost]@:@$options[dependentPostAlternative]@;$next@", $field); + } else + $field = preg_replace("/__DEPENDENT_ON_NEXT_FIELD__/", "$options[dependentPostAlternative]", $field); + + $previous = $i > 0 ? $data[$i-1][0] : false; + if ($previous) { + $field = preg_replace("/__DEPENDENT_ON_PREVIOUS_FIELD__/", "@?$next@$options[dependentPre]@:@$options[dependentPreAlternative]@;$next@", $field); + } else + $previous = preg_replace("/__DEPENDENT_ON_PREVIOUS_FIELD__/", "$options[dependentPreAlternative]", $field); + + + $text .= $field; + } else + $text .= $row[1]; + } + + // Finish by filling up the structure assert(!array_key_exists($type, $formats)); $types = array(); if ($bibtexType) $types[] = $bibtexType; - $formats[$type] = array($types, $data); + $formats[$type] = array($types, $text); if ($bibtexType == "article") $formats[$type][0][] = "#"; }