aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor <pashev.igor@gmail.com>2010-11-02 17:21:32 +0300
committerIgor <pashev.igor@gmail.com>2010-11-02 17:21:32 +0300
commit1bc232fa85fb52ee10eecb3f1afaeaca80f433d7 (patch)
tree7755d6ada4ce4816b5cbc82f66413c5d07079ec7
parent008c5a8a7df36d8c96853ed9754e7065dfa4b99d (diff)
downloaddokuwiki-plugin-papers-1bc232fa85fb52ee10eecb3f1afaeaca80f433d7.tar.gz
Added support for @GRANT; for specifying source page ; for passing options to renderer
-rw-r--r--README1
-rw-r--r--bibtex.php64
-rw-r--r--syntax.php56
3 files changed, 98 insertions, 23 deletions
diff --git a/README b/README
index e71a2e5..8e92f90 100644
--- a/README
+++ b/README
@@ -24,5 +24,6 @@ no empty line are allowed before </bibtex>
<papers>
author = pashev
year = 2005
+source = Публикации
</papers>
diff --git a/bibtex.php b/bibtex.php
index 9fd391f..0484915 100644
--- a/bibtex.php
+++ b/bibtex.php
@@ -124,7 +124,7 @@ class BibtexParser
foreach ($search as $key => $value)
{
$key = strtolower($key);
- if (!empty($entry[$key]) && !preg_match($value, $entry[$key]))
+ if (!empty($entry[$key]) && !preg_match('/' . $value . '/u', $entry[$key]))
{
$select = false;
break;
@@ -189,6 +189,7 @@ class BibtexParserTeam extends BibtexParser
'no.' => array('russian' => '№'),
'et&nbsp;al.' => array('russian' => 'и&nbsp;др.'),
'Ed.&nbsp;by' => array('russian' => 'Под&nbsp;ред.'),
+ 'leader' => array('russian' => 'рук.'),
);
protected function _($str)
@@ -261,6 +262,30 @@ class BibtexParserTeam extends BibtexParser
);
}
+ protected function format_organization() // for @GRANT
+ {
+ $this->format_field_default('organization');
+ $this->entry['organization'] = '<strong>' . $this->entry['organization'] . '</strong>';
+ }
+
+ protected function format_doer() // for @GRANT
+ {
+ $res = '';
+ $authors_array = preg_split('/\s+and\s+/',
+ $this->expand_string($this->entry['doer']));
+
+ foreach ($authors_array as &$a)
+ {
+ $a = $this->format_author1($a);
+ }
+
+ if(isset($authors_array[1]))
+ $authors_array[0] .= '&nbsp;(' . $this->_('leader') . ')';
+ $res = implode(', ', $authors_array);
+
+ $this->entry['doer'] = $res;
+ }
+
protected function format_pages()
{
$this->format_field_default('pages');
@@ -364,7 +389,7 @@ class BibtexParserTeam extends BibtexParser
}
else
{
- $res = 'Not implemented for ' . $this->entry['entry'];
+ $res = 'Not implemented for "' . $this->entry['entry'] . '"';
}
$res .= '.';
@@ -460,7 +485,7 @@ class BibtexParserTeam extends BibtexParser
$parts[] = $this->entry['year'];
}
- if (!empty($this->entry['manth']))
+ if (!empty($this->entry['month']))
{
$parts[] = $this->entry['month'];
}
@@ -484,6 +509,39 @@ class BibtexParserTeam extends BibtexParser
return implode('.&nbsp;&mdash; ', $parts);
}
+ protected function format_grant()
+ {
+ $parts = array(); // All parts are connected with '.&nbsp;&mdash; '
+
+
+ if (!empty($this->entry['organization']))
+ {
+ $parts[] = $this->entry['organization'];
+ }
+
+ if (!empty($this->entry['number']))
+ {
+ $parts[] = $this->entry['number'];
+ }
+
+ if (!empty($this->entry['title']))
+ {
+ $parts[] = $this->entry['title'];
+ }
+
+ if (!empty($this->entry['year']))
+ {
+ $parts[] = $this->entry['year'];
+ }
+
+ if (!empty($this->entry['doer']))
+ {
+ $parts[] = '<em>' . $this->entry['doer'] . '</em>';
+ }
+
+ return implode('.&nbsp;&mdash; ', $parts);
+ }
+
protected function format_inproceedings()
{
diff --git a/syntax.php b/syntax.php
index 9bbd0ea..4f2b2ad 100644
--- a/syntax.php
+++ b/syntax.php
@@ -52,26 +52,49 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin
preg_match('/<(\w+)>/', $match, $tmp);
$tag = $tmp[1];
unset($tmp);
- return array($state, $tag, array());
+ return array($state, $tag, '', array());
case DOKU_LEXER_UNMATCHED :
if ($tag === 'papers') // Parse <papers>...</papers>
{
- $bibtex = new BibtexParserWorker();
- $bibtex->read_file(wikiFN($this->getConf('bibtex')));
$spec = array();
$fields = preg_split('/\s*\n\s*/u', $match);
foreach ($fields as &$f)
{
if (preg_match('/\s*(\w+?)\s*=\s*(.*)/u', $f, $m))
{
- $spec[$m[1]] = '/' . $m[2] . '/u';
+ $spec[$m[1]] = $m[2];
}
}
+ $source = '';
+ if (isset($spec['source']))
+ {
+ $source = wikiFN($spec['source']);
+ unset($spec['source']);
+ }
+ else
+ {
+ $source = wikiFN($this->getConf('bibtex'));
+ }
+
+ $options = array();
+ foreach(array('raw', 'byyear') as $o)
+ {
+ if (isset($spec[$o]))
+ {
+ $options[$o] = $spec[$o];
+ unset($spec[$o]);
+ }
+ }
+
+ $bibtex = (!isset($options['byyear']) || $options['byyear']) ?
+ new BibtexParserTeam() : new BibtexParserWorker();
+ $bibtex->read_file($source);
+ unset($source);
$bibtex->select($spec);
unset($spec);
$bibtex->sort();
- return array($state, $tag, $bibtex);
+ return array($state, $tag, $bibtex, $options);
}
elseif ($tag === 'bibtex') // Parse <bibtex>...</bibtex>
{
@@ -79,11 +102,11 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin
$bibtex->read_text($match);
$bibtex->select();
$bibtex->sort();
- return array($state, $tag, $bibtex);
+ return array($state, $tag, $bibtex, array());
}
case DOKU_LEXER_EXIT :
- return array($state, $tag, '');
+ return array($state, $tag, '', array());
}
return array();
}
@@ -91,22 +114,14 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin
function render($mode, &$renderer, $data)
{
if ($mode != 'xhtml') return false;
- list($state, $tag, $bibtex) = $data;
+ list($state, $tag, $bibtex, $options) = $data;
switch ($state)
{
case DOKU_LEXER_ENTER:
break;
case DOKU_LEXER_UNMATCHED:
- if ($tag === 'bibtex')
- {
- $renderer->doc .= $this->format_bibtex($bibtex);
- }
- elseif ($tag === 'papers')
- {
- $renderer->doc .= $this->format_bibtex($bibtex, array('raw'=>true));
- }
-
+ $renderer->doc .= $this->format_bibtex($bibtex, $options);
break;
case DOKU_LEXER_EXIT:
@@ -130,12 +145,13 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin
foreach ($bibtex->SELECTION as &$entry)
{
// <papers> tag results in just a list of papers
- if (!isset($options['raw']) || $options['raw'])
+ if (!isset($options['raw']) || !$options['raw'])
{
// No 'Year' title for papers of a worker (team member)
- if (!isset($options['year']) || $options['year'])
+ if (!isset($options['byyear']) || ($options['byyear']))
{
- preg_match('/(\d{4})/u', $entry['year'], $matches);
+ // Remember about ranges: 2009-2010 - take the last year
+ preg_match('/.*(\d{4})/u', $entry['year'], $matches);
$year = $matches[1];
if ($year < $this->getConf('year_min'))
break;