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. --- bibtex.php | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'bibtex.php') diff --git a/bibtex.php b/bibtex.php index 1d72b29..a6aa8ac 100644 --- a/bibtex.php +++ b/bibtex.php @@ -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[] = '' . $this->entry['doer'] . ''; @@ -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;}; -- cgit v1.2.3