From 33b066a6e67b223ed4138e7d779d445f8078193b Mon Sep 17 00:00:00 2001 From: Igor Date: Sat, 6 Nov 2010 00:12:23 +0300 Subject: Support for @GRANT. Each grant may lasts for several years, so we introduce new field ("years=2006--2009") and dublicate grants entry for each year, appending "year=2006", "year=2007" and so on. --- syntax.php | 58 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'syntax.php') diff --git a/syntax.php b/syntax.php index 622887b..8f37108 100644 --- a/syntax.php +++ b/syntax.php @@ -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) { - // 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 .= '

' . $this->getLang($type) . "

\n"; } } - if (!$in_list) { $res .= "
    \n"; $in_list = true; } - $res .= '
  1. ' . $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 .= '
  2. ' . $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 .= '' . $link_text . ''; + } + $res .= "
  3. \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 .= '' . $link_text . ''; - } - $res .= "\n"; } -- cgit v1.2.3