From af1a7d974b0f8616faca9073a734de51fbd5ea04 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Sun, 23 Apr 2006 20:09:50 +0000 Subject: * Fixed "value" syntax problem * Fixed start offset problem * Some code tidying --- lib/HTTP/CalDAV/Tools/ICalendarParser.php | 64 +++++++++++++++++++++++-------- lib/bennu/iCalendar_components.php | 8 +--- lib/bennu/iCalendar_parameters.php | 5 +-- lib/bennu/iCalendar_properties.php | 13 +------ 4 files changed, 54 insertions(+), 36 deletions(-) (limited to 'lib') diff --git a/lib/HTTP/CalDAV/Tools/ICalendarParser.php b/lib/HTTP/CalDAV/Tools/ICalendarParser.php index 803b5de..1d80d8d 100644 --- a/lib/HTTP/CalDAV/Tools/ICalendarParser.php +++ b/lib/HTTP/CalDAV/Tools/ICalendarParser.php @@ -20,7 +20,7 @@ * @author Jack Bates * @copyright 2006 The PHP Group * @license PHP License 3.0 http://www.php.net/license/3_0.txt - * @version CVS: $Id: ICalendarParser.php,v 1.2 2006/04/22 22:50:24 jablko Exp $ + * @version CVS: $Id: ICalendarParser.php,v 1.3 2006/04/23 20:09:50 jablko Exp $ * @link http://pear.php.net/package/HTTP_CalDAV_Server * @see HTTP_WebDAV_Server */ @@ -35,7 +35,7 @@ * @author Jack Bates * @copyright 2006 The PHP Group * @license PHP License 3.0 http://www.php.net/license/3_0.txt - * @version CVS: $Id: ICalendarParser.php,v 1.2 2006/04/22 22:50:24 jablko Exp $ + * @version CVS: $Id: ICalendarParser.php,v 1.3 2006/04/23 20:09:50 jablko Exp $ * @link http://pear.php.net/package/HTTP_CalDAV_Server * @see HTTP_WebDAV_Server */ @@ -49,13 +49,29 @@ class ICalendarParser */ var $_handle; + /** + * Line of input + * + * @var string + * @access private + */ + var $_line; + + /** + * Offset of line + * + * @var int + * @access private + */ + var $_offset; + /** * Success state flag * * @var bool * @access public */ - var $success = false; + var $success = true; /** * Parsed components are collected here in post-order @@ -82,12 +98,12 @@ class ICalendarParser var $_compStack = array(); /** - * Begin offset stack for tracking begin offsets of nested components + * Begin offset stack for tracking start offsets of nested components * * @var array * @access private */ - var $_beginOffsetStack = array(); + var $_startOffsetStack = array(); /** * Offsets stack for parsing within specific ranges @@ -114,6 +130,21 @@ class ICalendarParser */ var $_filterStack = array(); + /** + * Parse RFC2445 date-time + * + * May eventually get moved someplace more appropriate + * TODO Timezone support + * + * @param string RFC2445 date-time + * @return int timestamp + * @access public + */ + function datetime_to_timestamp($datetime) + { + return gmmktime(substr($datetime, 9, 2), substr($datetime, 11, 2), substr($datetime, 13, 2), substr($datetime, 4, 2), substr($datetime, 6, 2), substr($datetime, 0, 4)); + } + /** * Constructor * @@ -123,15 +154,16 @@ class ICalendarParser function ICalendarParser($handle, $offsets=null, $value=null, $filters=null) { $this->_handle = $handle; - $this->success = true; $this->_offsetStack[] = $offsets; - $this->_valueStack[] = $value; + + // FIXME Separate comps & props stacks? + $this->_valueStack[] = array('comps' => $value); $this->_filterStack[] = $filters; while ($this->success && - ($offset = ftell($this->_handle)) !== false && - ($line = fgets($this->_handle, 4096)) !== false) { + ($this->_offset = ftell($this->_handle)) !== false && + ($this->_line = fgets($this->_handle, 4096)) !== false) { if (is_array($this->_offsetStack[count($this->_offsetStack) - 1]['offsets'])) { - if ($offset > $this->_offsetStack[count($this->_offsetStack) - 1]['offsets'][0][1]) { + if ($this->_offset > $this->_offsetStack[count($this->_offsetStack) - 1]['offsets'][0][1]) { if (array_shift($this->_offsetStack[count($this->_offsetStack) - 1]['offsets']) !== null) { if (fseek($this->_offsetStack[count($this->_offsetStack) - 1]['offsets'][0][0])) { $this->success = false; @@ -157,10 +189,10 @@ class ICalendarParser } } - $line = explode(':', trim($line)); + $line = explode(':', trim($this->_line)); if ($line[0] == 'BEGIN') { - $this->_beginComp($line[1]); + $this->_startComp($line[1]); continue; } @@ -187,7 +219,7 @@ class ICalendarParser } } - function _beginComp($name) + function _startComp($name) { if (is_array($this->_valueStack[count($this->_valueStack) - 1]['comps']) && !isset($this->_valueStack[count($this->_valueStack) - 1]['comps'][$name])) { @@ -218,7 +250,7 @@ class ICalendarParser } $this->_compStack[] = new $class; - $this->_beginOffsetStack[] = $offset; + $this->_startOffsetStack[] = $this->_offset; $this->_offsetStack[] = $this->_offsetStack[count($this->_offsetStack) - 1]['comps'][$name]; $this->_valueStack[] = $this->_valueStack[count($this->_valueStack) - 1]['comps'][$name]; $this->_filterStack[] = $this->_filterStack[count($this->_filterStack) - 1]['comps'][$name]; @@ -236,7 +268,7 @@ class ICalendarParser if ($filter['name'] == 'time-range') { if ($filter['value']['start'] > $this->_compStack[count($this->_compStack) - 1]->properties['DTEND'][0]->value || $filter['value']['end'] < $this->_compStack[count($this->_compStack) - 1]->properties['DTSTART'][0]->value) { array_pop($this->_compStack); - array_pop($this->_beginOffsetStack); + array_pop($this->_startOffsetStack); array_pop($this->_offsetStack); array_pop($this->_valueStack); array_pop($this->_filterStack); @@ -257,7 +289,7 @@ class ICalendarParser } $this->comps[] = array_pop($this->_compStack); - $this->offsets[] = array(array_pop($this->_beginOffsetStack), $offset); + $this->offsets[] = array(array_pop($this->_startOffsetStack), $offset); array_pop($this->_offsetStack); array_pop($this->_valueStack); array_pop($this->_filterStack); diff --git a/lib/bennu/iCalendar_components.php b/lib/bennu/iCalendar_components.php index 13abac5..4b51f58 100644 --- a/lib/bennu/iCalendar_components.php +++ b/lib/bennu/iCalendar_components.php @@ -1,4 +1,4 @@ - diff --git a/lib/bennu/iCalendar_properties.php b/lib/bennu/iCalendar_properties.php index bec729e..d19cbf7 100644 --- a/lib/bennu/iCalendar_properties.php +++ b/lib/bennu/iCalendar_properties.php @@ -1,4 +1,4 @@ -= 0 && $value <= 100); } - } class iCalendar_property_priority extends iCalendar_property { @@ -533,7 +530,6 @@ class iCalendar_property_status extends iCalendar_property { return in_array($value, $allowed); } - } class iCalendar_property_summary extends iCalendar_property { @@ -818,7 +814,6 @@ class iCalendar_property_attendee extends iCalendar_property { return false; } - } class iCalendar_property_contact extends iCalendar_property { @@ -902,7 +897,6 @@ class iCalendar_property_recurrence_id extends iCalendar_property { return true; } - } class iCalendar_property_related_to extends iCalendar_property { @@ -979,7 +973,6 @@ class iCalendar_property_exdate extends iCalendar_property { return true; } - } class iCalendar_property_exrule extends iCalendar_property { @@ -1021,7 +1014,6 @@ class iCalendar_property_rdate extends iCalendar_property { return true; } - } class iCalendar_property_rrule extends iCalendar_property { @@ -1277,7 +1269,6 @@ class iCalendar_property_request_status extends iCalendar_property { return false; } - } -- cgit v1.2.3