From: <ja...@us...> - 2006-04-18 03:22:17
|
Update of /cvsroot/phpicalendar/phpicalendar/lib/HTTP/CalDAV In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12568/lib/HTTP/CalDAV Modified Files: Server.php Log Message: * 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 Index: Server.php =================================================================== RCS file: /cvsroot/phpicalendar/phpicalendar/lib/HTTP/CalDAV/Server.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Server.php 13 Apr 2006 22:33:13 -0000 1.4 --- Server.php 18 Apr 2006 03:22:12 -0000 1.5 *************** *** 27,30 **** --- 27,31 ---- require_once 'Tools/ReportParser.php'; + require_once 'Tools/ICalendarParser.php'; /** *************** *** 70,74 **** $options['path'] = $this->path; ! $options['depth'] = 'infinity'; if (isset($_SERVER['HTTP_DEPTH'])) { $options['depth'] = $_SERVER['HTTP_DEPTH']; --- 71,77 ---- $options['path'] = $this->path; ! /* The request MAY include a Depth header. If no Depth header is ! included, Depth:0 is assumed. */ ! $options['depth'] = 0; if (isset($_SERVER['HTTP_DEPTH'])) { $options['depth'] = $_SERVER['HTTP_DEPTH']; *************** *** 148,152 **** $status = $this->get($options); if (empty($status)) { ! $status = '403 Forbidden'; } --- 151,155 ---- $status = $this->get($options); if (empty($status)) { ! $status = '404 Not Found'; } *************** *** 156,160 **** if ($options['mimetype'] != 'text/calendar') { ! return $this->calDavProp('calendar-data', null, '404 Not Found'); } --- 159,164 ---- if ($options['mimetype'] != 'text/calendar') { ! return $this->calDavProp('calendar-data', null, ! '404 Not Found'); } *************** *** 164,175 **** // What about data? } else { ! return $this->calDavProp('calendar-data', null, '404 Not Found'); } ! if (!($value = $this->_parseComponent($handle, $reqprop['value'], $filters))) { ! return $this->calDavProp('calendar-data', null, '404 Not Found'); } ! return HTTP_CalDAV_Server::calDavProp('calendar-data', $value); } --- 168,184 ---- // What about data? } else { ! return $this->calDavProp('calendar-data', null, ! '404 Not Found'); } ! $parser = new ICalendarParser($handle, null, null, ! $reqprop['value'], $filters); ! if (!$parser->success) { ! return $this->calDavProp('calendar-data', null, ! '404 Not Found'); } ! return HTTP_CalDAV_Server::calDavProp('calendar-data', ! $parser->comps[count($parser->comps) - 1]); } *************** *** 180,273 **** } - function _parseComponent($handle, $value=null, $filters=null) - { - $comps = array(); - $compValues = array($value); - $compFilters = array($filters); - while (($line = fgets($handle, 4096)) !== false) { - $line = explode(':', trim($line)); - - if ($line[0] == 'END') { - if ($line[1] != $comps[count($comps) - 1]->name) { - 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 we're about to pop the root component, we ignore the rest - // of our input - if (count($comps) == 1) { - return array_pop($comps); - } - - if (!$comps[count($comps) - 2]->add_component(array_pop($comps))) { - return; - } - - 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); - } - } - - 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); - } - } - - return; - } - - $comps[] = new $className; - $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); - } - } - function _multistatus($responses) { --- 189,192 ---- |