diff options
author | Wesley Miaw <josuah@users.sourceforge.net> | 2005-10-30 01:32:44 +0000 |
---|---|---|
committer | Wesley Miaw <josuah@users.sourceforge.net> | 2005-10-30 01:32:44 +0000 |
commit | fc81f9ebde033c58f729f392dba7914112d40720 (patch) | |
tree | 949f1a56d5a6de5695d93eb6c01adc3f24907c4f /functions/ical_parser.php | |
parent | 966c67f92d14beaf7f6a2ba3386a8e6953cf9eb3 (diff) | |
download | phpicalendar-fc81f9ebde033c58f729f392dba7914112d40720.tar.gz phpicalendar-fc81f9ebde033c58f729f392dba7914112d40720.tar.bz2 phpicalendar-fc81f9ebde033c58f729f392dba7914112d40720.zip |
Added support for recursively searching for calendars in your
$calendar_path and the new iCal calendar repository structure. The
calendars are still referenced by calendar name, so all URLs are unchanged.
Refactored the date parsing code out of ical_parser.php and into
date_functions.php. Minor logic changes to the parser to correctly
populate the TODO date and time values.
Refactored the calendar name code into a new getCalendarName() function,
since calendar names may no longer be determined solely by filename if
using an iCal repository. Template code updated to match.
Added calls to stripslashes() for calendar text data, such as the summaries
and descriptions. Also put stripslashes() into people data, since people's
names may contain escaped characters.
Diffstat (limited to 'functions/ical_parser.php')
-rw-r--r-- | functions/ical_parser.php | 219 |
1 files changed, 25 insertions, 194 deletions
diff --git a/functions/ical_parser.php b/functions/ical_parser.php index 5086e07..60ca5c9 100644 --- a/functions/ical_parser.php +++ b/functions/ical_parser.php @@ -99,8 +99,7 @@ $calnumber = 1; foreach ($cal_filelist as $filename) { // Find the real name of the calendar. - $actual_calname = str_replace($calendar_path, '', $filename); - $actual_calname = str_replace('/', '', str_replace('.ics', '', $actual_calname)); + $actual_calname = getCalendarName($filename); if ($parse_file) { @@ -805,101 +804,17 @@ foreach ($cal_filelist as $filename) { // Start VTODO Parsing // case 'DUE': - $data = str_replace ('/softwarestudio.org/Olson_20011030_5/', '', $data); - $zulu_time = false; - if (substr($data,-1) == 'Z') $zulu_time = true; - $data = str_replace('T', '', $data); - $data = str_replace('Z', '', $data); - if (preg_match("/^DUE;VALUE=DATE/i", $field)) { - $allday_start = $data; - $start_date = $allday_start; - $start_unixtime = strtotime($data); - $due_date = date('Ymd', $start_unixtime); - } else { - if (preg_match("/^DUE;TZID=/i", $field)) { - $tz_tmp = explode('=', $field); - $tz_due = $tz_tmp[1]; - unset($tz_tmp); - } elseif ($zulu_time) { - $tz_due = 'GMT'; - } - - ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $data, $regs); - $due_date = $regs[1] . $regs[2] . $regs[3]; - $due_time = $regs[4] . $regs[5]; - $start_unixtime = mktime($regs[4], $regs[5], 0, $regs[2], $regs[3], $regs[1]); - - $dlst = date('I', $start_unixtime); - $server_offset_tmp = chooseOffset($start_unixtime); - if (isset($tz_due)) { - if (array_key_exists($tz_due, $tz_array)) { - $offset_tmp = $tz_array[$tz_due][$dlst]; - } else { - $offset_tmp = '+0000'; - } - } elseif (isset($calendar_tz)) { - if (array_key_exists($calendar_tz, $tz_array)) { - $offset_tmp = $tz_array[$calendar_tz][$dlst]; - } else { - $offset_tmp = '+0000'; - } - } else { - $offset_tmp = $server_offset_tmp; - } - $start_unixtime = calcTime($offset_tmp, $server_offset_tmp, $start_unixtime); - $due_date = date('Ymd', $start_unixtime); - $due_time = date('Hi', $start_unixtime); - unset($server_offset_tmp); - } + $datetime = extractDateTime($data, $property, $field); + $due_date = $datetime[1]; + $due_time = $datetime[2]; break; case 'COMPLETED': - $data = str_replace ('/softwarestudio.org/Olson_20011030_5/', '', $data); - $zulu_time = false; - if (substr($data,-1) == 'Z') $zulu_time = true; - $data = str_replace('T', '', $data); - $data = str_replace('Z', '', $data); - if (preg_match("/^COMPLETED;VALUE=DATE/i", $field)) { - $allday_start = $data; - $start_date = $allday_start; - } else { - if (preg_match("/^COMPLETED;TZID=/i", $field)) { - $tz_tmp = explode('=', $field); - $tz_completed = $tz_tmp[1]; - unset($tz_tmp); - } elseif ($zulu_time) { - $tz_completed = 'GMT'; - } - - ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $data, $regs); - $completed_date = $regs[1] . $regs[2] . $regs[3]; - $completed_time = $regs[4] . $regs[5]; - $start_unixtime = mktime($regs[4], $regs[5], 0, $regs[2], $regs[3], $regs[1]); - - $dlst = date('I', $start_unixtime); - $server_offset_tmp = chooseOffset($start_unixtime); - if (isset($tz_completed)) { - if (array_key_exists($tz_completed, $tz_array)) { - $offset_tmp = $tz_array[$tz_completed][$dlst]; - } else { - $offset_tmp = '+0000'; - } - } elseif (isset($calendar_tz)) { - if (array_key_exists($calendar_tz, $tz_array)) { - $offset_tmp = $tz_array[$calendar_tz][$dlst]; - } else { - $offset_tmp = '+0000'; - } - } else { - $offset_tmp = $server_offset_tmp; - } - $start_unixtime = calcTime($offset_tmp, $server_offset_tmp, $start_unixtime); - $completed_date = date('Ymd', $start_unixtime); - $completed_time = date('Hi', $start_unixtime); - unset($server_offset_tmp); - } - break; - + $datetime = extractDateTime($data, $property, $field); + $completed_date = $datetime[1]; + $completed_time = $datetime[2]; + break; + case 'PRIORITY': $vtodo_priority = "$data"; break; @@ -914,111 +829,24 @@ foreach ($cal_filelist as $filename) { case 'CATEGORIES': $vtodo_categories = "$data"; - break; + break; // // End VTODO Parsing case 'DTSTART': - $data = str_replace ('/softwarestudio.org/Olson_20011030_5/', '', $data); - $zulu_time = false; - if (substr($data,-1) == 'Z') $zulu_time = true; - $data = str_replace('T', '', $data); - $data = str_replace('Z', '', $data); - $field = str_replace(';VALUE=DATE-TIME', '', $field); - if ((preg_match("/^DTSTART;VALUE=DATE/i", $field)) || (ereg ('^([0-9]{4})([0-9]{2})([0-9]{2})$', $data))) { - ereg ('([0-9]{4})([0-9]{2})([0-9]{2})', $data, $dtstart_check); - if ($dtstart_check[1] < 1970) { - $data = '1971'.$dtstart_check[2].$dtstart_check[3]; - } - $allday_start = $data; - $start_date = $allday_start; - $start_unixtime = strtotime($data); - } else { - if (preg_match("/^DTSTART;TZID=/i", $field)) { - $tz_tmp = explode('=', $field); - $tz_dtstart = $tz_tmp[1]; - unset($tz_tmp); - } elseif ($zulu_time) { - $tz_dtstart = 'GMT'; - } - - preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})/', $data, $regs); - if ($regs[1] < 1970) { - $regs[1] = '1971'; - } - $start_date = $regs[1] . $regs[2] . $regs[3]; - $start_time = $regs[4] . $regs[5]; - $start_unixtime = mktime($regs[4], $regs[5], 0, $regs[2], $regs[3], $regs[1]); - - $dlst = date('I', $start_unixtime); - $server_offset_tmp = chooseOffset($start_unixtime); - if (isset($tz_dtstart)) { - if (array_key_exists($tz_dtstart, $tz_array)) { - $offset_tmp = $tz_array[$tz_dtstart][$dlst]; - } else { - $offset_tmp = '+0000'; - } - } elseif (isset($calendar_tz)) { - if (array_key_exists($calendar_tz, $tz_array)) { - $offset_tmp = $tz_array[$calendar_tz][$dlst]; - } else { - $offset_tmp = '+0000'; - } - } else { - $offset_tmp = $server_offset_tmp; - } - $start_unixtime = calcTime($offset_tmp, $server_offset_tmp, $start_unixtime); - $start_date = date('Ymd', $start_unixtime); - $start_time = date('Hi', $start_unixtime); - unset($server_offset_tmp, $offset_tmp, $tz_dtstart); - } + $datetime = extractDateTime($data, $property, $field); + $start_unixtime = $datetime[0]; + $start_date = $datetime[1]; + $start_time = $datetime[2]; + $allday_start = $datetime[3]; break; case 'DTEND': - $data = str_replace ('/softwarestudio.org/Olson_20011030_5/', '', $data); - $zulu_time = false; - if (substr($data,-1) == 'Z') $zulu_time = true; - $data = str_replace('T', '', $data); - $data = str_replace('Z', '', $data); - $field = str_replace(';VALUE=DATE-TIME', '', $field); - if (preg_match("/^DTEND;VALUE=DATE/i", $field)) { - preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})/', $data, $dtend_check); - if ($dtend_check[1] < 1970) { - $data = '1971'.$dtend_check[2].$dtend_check[3]; - } - $allday_end = $data; - } else { - if (preg_match("/^DTEND;TZID=/i", $field)) { - $tz_tmp = explode('=', $field); - $tz_dtend = $tz_tmp[1]; - unset($tz_tmp); - } elseif ($zulu_time) { - $tz_dtend = 'GMT'; - } - - preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})/', $data, $regs); - if ($regs[1] < 1970) { - $regs[1] = '1971'; - } - $end_date = $regs[1] . $regs[2] . $regs[3]; - $end_time = $regs[4] . $regs[5]; - $end_unixtime = mktime($regs[4], $regs[5], 0, $regs[2], $regs[3], $regs[1]); - - $dlst = date('I', $end_unixtime); - $server_offset_tmp = chooseOffset($end_unixtime); - if (isset($tz_dtend)) { - $offset_tmp = $tz_array[$tz_dtend][$dlst]; - } elseif (isset($calendar_tz)) { - $offset_tmp = $tz_array[$calendar_tz][$dlst]; - } else { - $offset_tmp = $server_offset_tmp; - } - $end_unixtime = calcTime($offset_tmp, $server_offset_tmp, $end_unixtime); - $end_date = date('Ymd', $end_unixtime); - $end_time = date('Hi', $end_unixtime); - unset($server_offset_tmp, $offset_tmp, $tz_dtend); - - } + $datetime = extractDateTime($data, $property, $field); + $end_unixtime = $datetime[0]; + $end_date = $datetime[1]; + $end_time = $datetime[2]; + $allday_end = $datetime[3]; break; case 'EXDATE': @@ -1042,6 +870,7 @@ foreach ($cal_filelist as $filename) { $data = str_replace("\\t", " ", $data); $data = str_replace("\\r", "<br />", $data); $data = str_replace('$', '$', $data); + $data = stripslashes($data); $data = htmlentities(urlencode($data)); if ($valarm_set == FALSE) { $summary = $data; @@ -1055,6 +884,7 @@ foreach ($cal_filelist as $filename) { $data = str_replace("\\t", " ", $data); $data = str_replace("\\r", "<br />", $data); $data = str_replace('$', '$', $data); + $data = stripslashes($data); $data = htmlentities(urlencode($data)); if ($valarm_set == FALSE) { $description = $data; @@ -1141,17 +971,18 @@ foreach ($cal_filelist as $filename) { case 'ATTENDEE': $field = str_replace("ATTENDEE;CN=", "", $field); $data = str_replace ("mailto:", "", $data); - $attendee[] = array ('name' => $field, 'email' => $data); + $attendee[] = array ('name' => stripslashes($field), 'email' => stripslashes($data)); break; case 'ORGANIZER': $field = str_replace("ORGANIZER;CN=", "", $field); $data = str_replace ("mailto:", "", $data); - $organizer[] = array ('name' => $field, 'email' => $data); + $organizer[] = array ('name' => stripslashes($field), 'email' => stripslashes($data)); break; case 'LOCATION': $data = str_replace("\\n", "<br />", $data); $data = str_replace("\\t", " ", $data); $data = str_replace("\\r", "<br />", $data); + $data = stripslashes($data); $location = $data; break; case 'URL': |