1<?php 2/* 3Released through http://bibliophile.sourceforge.net under the GPL licence. 4Do whatever you like with this -- some credit to the author(s) would be appreciated. 5 6A collection of PHP classes to manipulate bibtex files. 7 8If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net so 9that your improvements can be added to the release package. 10 11Mark Grimshaw 2005 12http://bibliophile.sourceforge.net 13*/ 14/***** 15* PARSEMONTH: BibTeX MONTH import class 16* 17* BibTeX month field can come in as: 18* jan 19* "8~" # jan 20* jan#"~8" 21* etc. 22* where # is concatenation and '~' can be any non-numeric character. 23*****/ 24 25// 17/June/2005 - Mark Grimshaw: month fields that have multiple dates (e.g. dec # " 5--9," or nov # " 29" # "--" # dec # " 2") are correctly parsed. 26class PARSEMONTH 27{ 28// Constructor 29 function PARSEMONTH() 30 { 31 } 32 function init($monthField) 33 { 34 $startMonth = $this->startDay = $endMonth = $this->endDay = FALSE; 35 $date = split("#", $monthField); 36 foreach($date as $field) 37 { 38 $field = ucfirst(strtolower(trim($field))); 39 if($month = array_search($field, $this->monthToLongName())) 40 { 41 if(!$startMonth) 42 $startMonth = $month; 43 else 44 $endMonth = $month; 45 continue; 46 } 47 else if($month = array_search($field, $this->monthToShortName())) 48 { 49 if(!$startMonth) 50 $startMonth = $month; 51 else 52 $endMonth = $month; 53 continue; 54 } 55 $this->parseDay($field); 56 } 57 if($this->endDay && !$endMonth) 58 $endMonth = $startMonth; 59 return array($startMonth, $this->startDay, $endMonth, $this->endDay); 60 } 61// extract day of month from field 62 function parseDay($dayField) 63 { 64 preg_match("/([0-9]+).*([0-9]+)|([0-9]+)/", $dayField, $array); 65 if(array_key_exists(3, $array)) 66 { 67 if(!$this->startDay) 68 $this->startDay = $array[3]; 69 else if(!$this->endDay) 70 $this->endDay = $array[3]; 71 } 72 else 73 { 74 if(array_key_exists(1, $array)) 75 $this->startDay = $array[1]; 76 if(array_key_exists(2, $array)) 77 $this->endDay = $array[2]; 78 } 79 } 80// Convert month to long name 81 function monthToLongName() 82 { 83 return array( 84 1 => 'January', 85 2 => 'February', 86 3 => 'March', 87 4 => 'April', 88 5 => 'May', 89 6 => 'June', 90 7 => 'July', 91 8 => 'August', 92 9 => 'September', 93 10 => 'October', 94 11 => 'November', 95 12 => 'December', 96 ); 97 } 98// Convert month to short name 99 function monthToShortName() 100 { 101 return array( 102 1 => 'Jan', 103 2 => 'Feb', 104 3 => 'Mar', 105 4 => 'Apr', 106 5 => 'May', 107 6 => 'Jun', 108 7 => 'Jul', 109 8 => 'Aug', 110 9 => 'Sep', 111 10 => 'Oct', 112 11 => 'Nov', 113 12 => 'Dec', 114 ); 115 } 116} 117?> 118