1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Horde_Icalendar_Vtimezone extends Horde_Icalendar
16: {
17: 18: 19: 20: 21:
22: public $type = 'vTimeZone';
23:
24: 25: 26: 27: 28:
29: public function exportvCalendar()
30: {
31: return $this->_exportvData('VTIMEZONE');
32: }
33:
34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
45: public function parseChild(&$child, $year)
46: {
47:
48: $result['time'] = 0;
49:
50: try {
51: $t = $child->getAttribute('TZOFFSETFROM');
52: } catch (Horde_Icalendar_Exception $e) {
53: return false;
54: }
55: $result['from'] = ($t['hour'] * 60 * 60 + $t['minute'] * 60) * ($t['ahead'] ? 1 : -1);
56:
57: try {
58: $t = $child->getAttribute('TZOFFSETTO');
59: } catch (Horde_Icalendar_Exception $e) {
60: return false;
61: }
62: $result['to'] = ($t['hour'] * 60 * 60 + $t['minute'] * 60) * ($t['ahead'] ? 1 : -1);
63:
64: try {
65: $switch_time = $child->getAttribute('DTSTART');
66: } catch (Horde_Icalendar_Exception $e) {
67: return false;
68: }
69:
70: try {
71: $rrules = $child->getAttribute('RRULE');
72: } catch (Horde_Icalendar_Exception $e) {
73: if (!is_int($switch_time)) {
74: return false;
75: }
76:
77:
78: $t = getdate($switch_time);
79: $result['time'] = @gmmktime($t['hours'], $t['minutes'], $t['seconds'],
80: $t['mon'], $t['mday'], $t['year']);
81: return $result;
82: }
83:
84: $rrules = explode(';', $rrules);
85: foreach ($rrules as $rrule) {
86: $t = explode('=', $rrule);
87: switch ($t[0]) {
88: case 'FREQ':
89: if ($t[1] != 'YEARLY') {
90: return false;
91: }
92: break;
93:
94: case 'INTERVAL':
95: if ($t[1] != '1') {
96: return false;
97: }
98: break;
99:
100: case 'BYMONTH':
101: $month = intval($t[1]);
102: break;
103:
104: case 'BYDAY':
105: $len = strspn($t[1], '1234567890-+');
106: if ($len == 0) {
107: return false;
108: }
109: $weekday = substr($t[1], $len);
110: $weekdays = array(
111: 'SU' => 0,
112: 'MO' => 1,
113: 'TU' => 2,
114: 'WE' => 3,
115: 'TH' => 4,
116: 'FR' => 5,
117: 'SA' => 6
118: );
119: $weekday = $weekdays[$weekday];
120: $which = intval(substr($t[1], 0, $len));
121: break;
122:
123: case 'UNTIL':
124: if (intval($year) > intval(substr($t[1], 0, 4))) {
125: return false;
126: }
127: break;
128: }
129: }
130:
131: if (empty($month) || !isset($weekday)) {
132: return false;
133: }
134:
135: if (is_int($switch_time)) {
136:
137: $switch_time = strftime('%H:%M:%S', $switch_time);
138: $switch_time = explode(':', $switch_time);
139: } else {
140: $switch_time = explode('T', $switch_time);
141: if (count($switch_time) != 2) {
142: return false;
143: }
144: $switch_time[0] = substr($switch_time[1], 0, 2);
145: $switch_time[2] = substr($switch_time[1], 4, 2);
146: $switch_time[1] = substr($switch_time[1], 2, 2);
147: }
148:
149:
150: $when = gmmktime($switch_time[0], $switch_time[1], $switch_time[2],
151: $month, 1, $year);
152:
153: $first_of_month_weekday = intval(gmstrftime('%w', $when));
154:
155:
156: if ($weekday >= $first_of_month_weekday) {
157: $weekday -= 7;
158: }
159: $when -= ($first_of_month_weekday - $weekday) * 60 * 60 * 24;
160:
161:
162:
163: if ($which < 0) {
164: do {
165: $when += 60*60*24*7;
166: } while (intval(gmstrftime('%m', $when)) == $month);
167: }
168:
169:
170: $when += $which * 60 * 60 * 24 * 7;
171:
172: $result['time'] = $when;
173:
174: return $result;
175: }
176:
177: }
178: