diff options
-rw-r--r-- | bibtex.php | 35 | ||||
-rw-r--r-- | syntax.php | 58 |
2 files changed, 63 insertions, 30 deletions
@@ -2,7 +2,6 @@ class BibtexParser { - public $STRINGS = array(); // @STRING(matveev="В. И. Матвеев") -> 'matveev' => "В. И. Матвеев" protected $STRINGS_o = array(); // 'jetp' => 1 - to sort by journal importance public $ENTRIES = array(); @@ -107,6 +106,23 @@ class BibtexParser } } + public function expand_years() + { + $entries = array(); // \/ - no ref! + foreach ($this->ENTRIES as $e) + { + if (!empty($e['years']) && preg_match('/(\d{4})\D+?(\d{4})/', $e['years'], $m)) + { + for ($y = $m[1]; $y <= $m[2]; $y++) + { + $e['year'] = $y; + $entries[] = $e; + } + } + } + $this->ENTRIES = array_merge($this->ENTRIES, $entries); + } + /* * $SELECTION keeps only references * to BiBTeX entries stored in $ENTRIES @@ -208,10 +224,8 @@ class BibtexParserTeam extends BibtexParser */ protected function cmp_entries(&$a, &$b) { - // by year (if range - by last year) - $x = preg_match('/.*([0-9]{4})/ui', $a['year'], $matches) ? $matches[1] : 0; - $y = preg_match('/.*([0-9]{4})/ui', $b['year'], $matches) ? $matches[1] : 0; - // die ("$x < $y"); + $x = preg_match('/.*([0-9]{4})/u', $a['year'], $matches) ? $matches[1] : 0; + $y = preg_match('/.*([0-9]{4})/u', $b['year'], $matches) ? $matches[1] : 0; if ($x > $y) {return -1;}; if ($x < $y) {return 1;}; @@ -529,11 +543,16 @@ class BibtexParserTeam extends BibtexParser $parts[] = $this->entry['title']; } - if (!empty($this->entry['year'])) + if (!empty($this->entry['years'])) + { + $parts[] = $this->entry['years']; + } + elseif (!empty($this->entry['year'])) { $parts[] = $this->entry['year']; } + if (!empty($this->entry['doer'])) { $parts[] = '<em>' . $this->entry['doer'] . '</em>'; @@ -620,8 +639,8 @@ class BibtexParserWorker extends BibtexParserTeam if ($x > $y) {return 1;}; // by year (if range - by last year) - $x = preg_match('/.*([0-9]{4})/ui', $a['year'], $matches) ? $matches[1] : 0; - $y = preg_match('/.*([0-9]{4})/ui', $b['year'], $matches) ? $matches[1] : 0; + $x = preg_match('/.*(\d{4})/u', $a['year'], $matches) ? $matches[1] : 0; + $y = preg_match('/.*(\d{4})/u', $b['year'], $matches) ? $matches[1] : 0; // die ("$x < $y"); if ($x > $y) {return -1;}; if ($x < $y) {return 1;}; @@ -96,6 +96,7 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin new BibtexParserTeam() : new BibtexParserWorker(); $bibtex->read_file($source); unset($source); + $bibtex->expand_years(); $bibtex->select($spec); unset($spec); $bibtex->sort(); @@ -105,6 +106,7 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin { $bibtex = new BibtexParserTeam(); $bibtex->read_text($match); + $bibtex->expand_years(); $bibtex->select(); $bibtex->sort(); return array($state, $tag, $bibtex, array()); @@ -147,15 +149,16 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin $year = ''; $year_prev = ''; $type = ''; $type_prev = ''; $in_list = false; + $dub = array(); + $byyear = !isset($options['byyear']) || $options['byyear']; + $raw = !isset($options['raw']) || !$options['raw']; + foreach ($bibtex->SELECTION as &$entry) { - // <papers> tag results in just a list of papers - if (!isset($options['raw']) || !$options['raw']) + if ($raw) { - // No 'Year' title for papers of a worker (team member) - if (!isset($options['byyear']) || ($options['byyear'])) + if ($byyear) { - // 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')) @@ -189,32 +192,43 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin $res .= '<h3 class="sectionedit3">' . $this->getLang($type) . "</h3>\n"; } } - if (!$in_list) { $res .= "<ol>\n"; $in_list = true; } - $res .= '<li class="level1"><div class="li" style="padding:0.3em;">' . $entry['html']; - - $links = array(); - foreach ($this->getConf('filetypes') as $type) + + /* + * Grants may last for several years. + * We dublicate each grant for every year it lasts. + * If we sort grants by years first, we display grant in + * each year. Otherwise we ignore dublicates. + */ + + if (empty($dub[$entry['id']]) || $byyear) { - $file = $this->getConf('papers_ns') . '/' . $entry['id'] . '.' . mb_strtolower($type); - if (file_exists(PAPERS_DATADIR . $file)) + $dub[$entry['id']] = true; + $res .= '<li class="level1"><div class="li" style="padding:0.3em;">' . $entry['html']; + + $links = array(); + foreach ($this->getConf('filetypes') as $type) { - $size = round(filesize(PAPERS_DATADIR . $file) / 1024) . ' ' . $this->getLang('KiB'); - $links[] = '{{:' . preg_replace('/\//u', ':', $file) . "|$type $size}}"; + $file = $this->getConf('papers_ns') . '/' . $entry['id'] . '.' . mb_strtolower($type); + if (file_exists(PAPERS_DATADIR . $file)) + { + $size = round(filesize(PAPERS_DATADIR . $file) / 1024) . ' ' . $this->getLang('KiB'); + $links[] = '{{:' . preg_replace('/\//u', ':', $file) . "|$type $size}}"; + } } + if (!empty($links)) + { + $link_text = $this->wikirender('(' . implode(' | ', $links) . ')'); + $link_text = preg_replace('/<\/?p>/u', '', $link_text); + $link_text = preg_replace('/\s+(\d+)\s+/u', ' \1 ', $link_text); + $res .= '<span class="noprint">' . $link_text . '</span>'; + } + $res .= "</div></li>\n"; } - if (!empty($links)) - { - $link_text = $this->wikirender('(' . implode(' | ', $links) . ')'); - $link_text = preg_replace('/<\/?p>/u', '', $link_text); - $link_text = preg_replace('/\s+(\d+)\s+/u', ' \1 ', $link_text); - $res .= '<span class="noprint">' . $link_text . '</span>'; - } - $res .= "</div></li>\n"; } |