aboutsummaryrefslogtreecommitdiffstats
path: root/lib/HTTP/CalDAV/Tools/ICalendarParser.php
diff options
context:
space:
mode:
authorJack Bates <jablko@users.sourceforge.net>2006-04-18 03:22:12 +0000
committerJack Bates <jablko@users.sourceforge.net>2006-04-18 03:22:12 +0000
commit5b0f19af8158984619f20aeffb5b8a0231cfecc2 (patch)
tree337becbf23cd5734e2acb72e2d24c88f8a5a6bf2 /lib/HTTP/CalDAV/Tools/ICalendarParser.php
parent40e077eb346693da15662632a90e5df0ff305046 (diff)
downloadphpicalendar-5b0f19af8158984619f20aeffb5b8a0231cfecc2.tar.gz
phpicalendar-5b0f19af8158984619f20aeffb5b8a0231cfecc2.tar.bz2
phpicalendar-5b0f19af8158984619f20aeffb5b8a0231cfecc2.zip
* Moved iCalendar parsing function into it's own class, complete with offsets support
* Fixed bug with $depth < 'infinity' * TODO If this parser works & has all necessary features, add documentation
Diffstat (limited to 'lib/HTTP/CalDAV/Tools/ICalendarParser.php')
-rw-r--r--lib/HTTP/CalDAV/Tools/ICalendarParser.php193
1 files changed, 193 insertions, 0 deletions
diff --git a/lib/HTTP/CalDAV/Tools/ICalendarParser.php b/lib/HTTP/CalDAV/Tools/ICalendarParser.php
new file mode 100644
index 0000000..0e3ffe3
--- /dev/null
+++ b/lib/HTTP/CalDAV/Tools/ICalendarParser.php
@@ -0,0 +1,193 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Helper for parsing iCalendar format
+ *
+ * Long description for file (if any)...
+ *
+ * PHP versions 4 & 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License & are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately
+ *
+ * @category HTTP
+ * @package HTTP_CalDAV_Server
+ * @author Jack Bates <ms419@freezone.co.uk>
+ * @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.1 2006/04/18 03:22:12 jablko Exp $
+ * @link http://pear.php.net/package/HTTP_CalDAV_Server
+ * @see HTTP_WebDAV_Server
+ */
+
+/**
+ * Helper for parsing iCalendar format
+ *
+ * Long description
+ *
+ * @category HTTP
+ * @package HTTP_CalDAV_Server
+ * @author Jack Bates <ms419@freezone.co.uk>
+ * @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.1 2006/04/18 03:22:12 jablko Exp $
+ * @link http://pear.php.net/package/HTTP_CalDAV_Server
+ * @see HTTP_WebDAV_Server
+ */
+class ICalendarParser
+{
+ /**
+ * Success state flag
+ *
+ * @var bool
+ * @access public
+ */
+ var $success = false;
+
+ /**
+ * Parsed components are collected here in post-order
+ *
+ * @var array
+ * @access public
+ */
+ var $comps = array();
+
+ /**
+ * Parsed components' offsets are collected here in post-order
+ *
+ * @var array
+ * @access public
+ */
+ var $offsets = array();
+
+ /**
+ * Constructor
+ *
+ * @param resource input stream handle
+ * @access public
+ */
+ function ICalendarParser($handle, $beginOffset=null, $endOffset=null,
+ $value=null, $filters=null)
+ {
+ $comps = array();
+ $beginOffsets = array();
+ $compValues = array($value);
+ $compFilters = array($filters);
+ $this->success = true;
+ while (($offset = ftell($handle)) !== false &&
+ ($line = fgets($handle, 4096)) !== false) {
+ if (isset($endOffset) && $offset > $endOffset) {
+ return;
+ }
+
+ $line = explode(':', trim($line));
+
+ if ($line[0] == 'END') {
+ if ($line[1] != $comps[count($comps) - 1]->name) {
+ $this->success = false;
+ return;
+ }
+
+ if (is_array($compFilters[count($compFilters) - 1]['filters'])) {
+ foreach ($compFilters[count($compFilters) - 1]['filters'] as $filter) {
+ if ($filter['name'] == 'time-range') {
+ if ($filter['value']['start'] > $comps[count($comps) - 1]->properties['DTEND'][0]->value || $filter['value']['end'] < $comps[count($comps) - 1]->properties['DTSTART'][0]->value) {
+ array_pop($compValues);
+ array_pop($compFilters);
+ continue;
+ }
+ }
+ }
+ }
+
+ if (count($comps) > 1 &&
+ !$comps[count($comps) - 2]->add_component($comps[count(
+ $comps) - 1])) {
+ $this->success = false;
+ return;
+ }
+
+ if (($offset = ftell($handle)) === false) {
+ $this->success = false;
+ return;
+ }
+
+ $this->comps[] = array_pop($comps);
+ $this->offsets[] = array(array_pop($beginOffsets), $offset);
+ array_pop($compValues);
+ array_pop($compFilters);
+ continue;
+ }
+
+ if ($line[0] == 'BEGIN') {
+ $compName = $line[1];
+ if (is_array($compValues[count($compValues) - 1]['comps']) &&
+ !isset($compValues[count($compValues) - 1]['comps'][$compName])) {
+ while (($line = fgets($handle, 4096)) !== false) {
+ if (trim($line) == "END:$compName") {
+ continue (2);
+ }
+ }
+
+ $this->success = false;
+ return;
+ }
+
+ $className = 'iCalendar_' . ltrim(strtolower($compName), 'v');
+ if ($line[1] == 'VCALENDAR') {
+ $className = 'iCalendar';
+ }
+
+ if (!class_exists($className)) {
+ while (($line = fgets($handle, 4096)) !== false) {
+ if (trim($line) == "END:$compName") {
+ continue (2);
+ }
+ }
+
+ $this->success = false;
+ return;
+ }
+
+ $comps[] = new $className;
+ $beginOffsets[] = $offset;
+ $compValues[] = $compValues[count($compValues) - 1]['comps'][$compName];
+ $compFilters[] = $compFilters[count($compFilters) - 1]['comps'][$compName];
+ continue;
+ }
+
+ $line[0] = explode(';=', $line[0]);
+ $propName = array_shift($line[0]);
+ if (is_array($compValues[count($compValues) - 1]['props']) &&
+ !in_array($propName,
+ $compValues[count($compValues) - 1]['props'])) {
+ continue;
+ }
+
+ $params = array();
+ while (!empty($line[0])) {
+ $params[array_shift($line[0])] = array_shift($line[0]);
+ }
+ $comps[count($comps) - 1]->add_property($propName, $line[1], $params);
+ }
+
+ if (!feof($handle)) {
+ $this->success = false;
+ }
+ }
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-handling-comment-ender-p: nil
+ * End:
+ */
+
+?>

© 2014-2024 Faster IT GmbH | imprint | privacy policy