diff options
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | bibtex.php | 64 | ||||
-rw-r--r-- | syntax.php | 56 |
3 files changed, 98 insertions, 23 deletions
@@ -24,5 +24,6 @@ no empty line are allowed before </bibtex> <papers> author = pashev year = 2005 +source = Публикации </papers> @@ -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 al.' => array('russian' => 'и др.'), 'Ed. by' => array('russian' => 'Под ред.'), + '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] .= ' (' . $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('. — ', $parts); } + protected function format_grant() + { + $parts = array(); // All parts are connected with '. — ' + + + 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('. — ', $parts); + } + protected function format_inproceedings() { @@ -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; |