aboutsummaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorChad Little <clittle@users.sourceforge.net>2003-06-30 22:48:25 +0000
committerChad Little <clittle@users.sourceforge.net>2003-06-30 22:48:25 +0000
commitbf8d96066ff80a8717420ac80e16b96d337e33c3 (patch)
treed1550a1aebe7ee7113e98162a2b8204662d08fa4 /functions
parent743cae611eeb4436d3d8dc865c010b2b3fd0102a (diff)
downloadphpicalendar-bf8d96066ff80a8717420ac80e16b96d337e33c3.tar.gz
phpicalendar-bf8d96066ff80a8717420ac80e16b96d337e33c3.tar.bz2
phpicalendar-bf8d96066ff80a8717420ac80e16b96d337e33c3.zip
Multiple Calendar support.
Diffstat (limited to 'functions')
-rw-r--r--functions/ical_parser.php1700
-rw-r--r--functions/init.inc.php47
-rw-r--r--functions/list_icals.php13
-rw-r--r--functions/overlapping_events.php12
4 files changed, 914 insertions, 858 deletions
diff --git a/functions/ical_parser.php b/functions/ical_parser.php
index 34dbebc..98a1305 100644
--- a/functions/ical_parser.php
+++ b/functions/ical_parser.php
@@ -51,946 +51,968 @@ if ($is_webcal == false && $save_parsed_cals == 'yes') {
}
if ($parse_file) {
- // patch to speed up parser
-
- $ifile = fopen($filename, "r");
- if ($ifile == FALSE) exit(error($error_invalidcal_lang, $filename));
- $nextline = fgets($ifile, 1024);
- if (trim($nextline) != 'BEGIN:VCALENDAR') exit(error($error_invalidcal_lang, $filename));
-
- // Set a value so we can check to make sure $master_array contains valid data
- $master_array['-1'] = 'valid cal file';
-
- // Set default calendar name - can be overridden by X-WR-CALNAME
- $calendar_name = $cal_filename;
- $master_array['calendar_name'] = $calendar_name;
-
+// some initializations, that have to be outside the calnumber loop
// auxiliary array for determining overlaps of events
$overlap_array = array ();
-
+
// using $uid to set specific points in array, if $uid is not in the
// .ics file, we need to have some unique place in the array
$uid_counter = 0;
+}
+
+$calnumber = 1;
+foreach ($cal_filelist as $filename) {
+
+ if ($parse_file) {
+ // patch to speed up parser
-// read file in line by line
-// XXX end line is skipped because of the 1-line readahead
- while (!feof($ifile)) {
- $line = $nextline;
+ $ifile = fopen($filename, "r");
+ if ($ifile == FALSE) exit(error($error_invalidcal_lang, $filename));
$nextline = fgets($ifile, 1024);
- $nextline = ereg_replace("[\r\n]", "", $nextline);
- while (substr($nextline, 0, 1) == " ") {
- $line = $line . substr($nextline, 1);
+ if (trim($nextline) != 'BEGIN:VCALENDAR') exit(error($error_invalidcal_lang, $filename));
+
+ // Set a value so we can check to make sure $master_array contains valid data
+ $master_array['-1'] = 'valid cal file';
+
+ // Set default calendar name - can be overridden by X-WR-CALNAME
+ $calendar_name = $cal_filename;
+ $master_array['calendar_name'] = $calendar_name;
+
+ // read file in line by line
+ // XXX end line is skipped because of the 1-line readahead
+ while (!feof($ifile)) {
+ $line = $nextline;
$nextline = fgets($ifile, 1024);
$nextline = ereg_replace("[\r\n]", "", $nextline);
- }
- $line = trim($line);
- if ($line == 'BEGIN:VEVENT') {
- // each of these vars were being set to an empty string
- unset (
- $start_time, $end_time, $start_date, $end_date, $summary,
- $allday_start, $allday_end, $start, $end, $the_duration,
- $beginning, $rrule_array, $start_of_vevent, $description,
- $valarm_description, $start_unixtime, $end_unixtime,
- $recurrence_id, $uid, $class, $location
- );
-
- $except_dates = array();
- $except_times = array();
- $first_duration = TRUE;
- $count = 1000000;
- $valarm_set = FALSE;
- $attendee = array();
- $organizer = array();
-
- unset(
- $until, $bymonth, $byday, $bymonthday, $byweek, $byweekno,
- $byminute, $byhour, $bysecond, $byyearday, $bysetpos, $wkst,
- $interval, $number
- );
-
- } elseif ($line == 'END:VEVENT') {
-
- // CLASS support
- if (isset($class)) {
- if ($class == 'PRIVATE') {
- $summary ='**PRIVATE**';
- $description ='**PRIVATE**';
- } elseif ($class == 'CONFIDENTIAL') {
- $summary ='**CONFIDENTIAL**';
- $description ='**CONFIDENTIAL**';
- }
- }
-
- // make sure we have some value for $uid
- if (!isset($uid)) {
- $uid = $uid_counter;
- $uid_counter++;
- $uid_valid = false;
- } else {
- $uid_valid = true;
- }
-
- if ($uid_valid && isset($processed[$uid]) && isset($recurrence_id['date'])) {
- $old_start_date = $processed[$uid][0];
- $old_start_time = $processed[$uid][1];
- $start_date_tmp = $recurrence_id['date'];
- if (!isset($start_date)) $start_date = $old_start_date;
- if (!isset($start_time)) $start_time = $master_array[$old_start_date][$old_start_time][$uid]['event_start'];
- if (!isset($start_unixtime)) $start_unixtime = $master_array[$old_start_date][$old_start_time][$uid]['start_unixtime'];
- if (!isset($end_unixtime)) $end_unixtime = $master_array[$old_start_date][$old_start_time][$uid]['end_unixtime'];
- if (!isset($end_time)) $end_time = $master_array[$old_start_date][$old_start_time][$uid]['event_end'];
- if (!isset($summary)) $summary = $master_array[$old_start_date][$old_start_time][$uid]['event_text'];
- if (!isset($length)) $length = $master_array[$old_start_date][$old_start_time][$uid]['event_length'];
- if (!isset($description)) $description = $master_array[$old_start_date][$old_start_time][$uid]['description'];
- removeOverlap($start_date_tmp, $old_start_time, $uid);
- if (isset($master_array[$start_date_tmp][$old_start_time])) unset($master_array[$start_date_tmp][$old_start_time]);
- $write_processed = false;
- } else {
- $write_processed = true;
+ while (substr($nextline, 0, 1) == " ") {
+ $line = $line . substr($nextline, 1);
+ $nextline = fgets($ifile, 1024);
+ $nextline = ereg_replace("[\r\n]", "", $nextline);
}
-
- if (!isset($summary)) $summary = '';
- if (!isset($description)) $description = '';
- if (!isset($status)) $status = '';
- if (!isset($class)) $class = '';
- if (!isset($location)) $location = '';
-
- $mArray_begin = mktime (0,0,0,12,21,($this_year - 1));
- $mArray_end = mktime (0,0,0,1,12,($this_year + 1));
-
- if (isset($start_time) && isset($end_time)) {
- // Mozilla style all-day events or just really long events
- if (($end_time - $start_time) > 2345) {
- $allday_start = $start_date;
- $allday_end = ($start_date + 1);
+ $line = trim($line);
+ if ($line == 'BEGIN:VEVENT') {
+ // each of these vars were being set to an empty string
+ unset (
+ $start_time, $end_time, $start_date, $end_date, $summary,
+ $allday_start, $allday_end, $start, $end, $the_duration,
+ $beginning, $rrule_array, $start_of_vevent, $description,
+ $valarm_description, $start_unixtime, $end_unixtime,
+ $recurrence_id, $uid, $class, $location
+ );
+
+ $except_dates = array();
+ $except_times = array();
+ $first_duration = TRUE;
+ $count = 1000000;
+ $valarm_set = FALSE;
+ $attendee = array();
+ $organizer = array();
+
+ unset(
+ $until, $bymonth, $byday, $bymonthday, $byweek, $byweekno,
+ $byminute, $byhour, $bysecond, $byyearday, $bysetpos, $wkst,
+ $interval, $number
+ );
+
+ } elseif ($line == 'END:VEVENT') {
+
+ // CLASS support
+ if (isset($class)) {
+ if ($class == 'PRIVATE') {
+ $summary ='**PRIVATE**';
+ $description ='**PRIVATE**';
+ } elseif ($class == 'CONFIDENTIAL') {
+ $summary ='**CONFIDENTIAL**';
+ $description ='**CONFIDENTIAL**';
+ }
+ }
+
+ // make sure we have some value for $uid
+ if (!isset($uid)) {
+ $uid = $uid_counter;
+ $uid_counter++;
+ $uid_valid = false;
+ } else {
+ $uid_valid = true;
}
- }
- if (isset($start_unixtime,$end_unixtime) && date('d',$start_unixtime) != date('d',$end_unixtime)) {
- $spans_day = true;
- } else {
- $spans_day = false;
- }
- if (isset($start_time) && $start_time != '') {
- ereg ('([0-9]{2})([0-9]{2})', $start_time, $time);
- ereg ('([0-9]{2})([0-9]{2})', $end_time, $time2);
- if (isset($start_unixtime) && isset($end_unixtime)) {
- $length = $end_unixtime - $start_unixtime;
+
+ if ($uid_valid && isset($processed[$uid]) && isset($recurrence_id['date'])) {
+ $old_start_date = $processed[$uid][0];
+ $old_start_time = $processed[$uid][1];
+ $start_date_tmp = $recurrence_id['date'];
+ if (!isset($start_date)) $start_date = $old_start_date;
+ if (!isset($start_time)) $start_time = $master_array[$old_start_date][$old_start_time][$uid]['event_start'];
+ if (!isset($start_unixtime)) $start_unixtime = $master_array[$old_start_date][$old_start_time][$uid]['start_unixtime'];
+ if (!isset($end_unixtime)) $end_unixtime = $master_array[$old_start_date][$old_start_time][$uid]['end_unixtime'];
+ if (!isset($end_time)) $end_time = $master_array[$old_start_date][$old_start_time][$uid]['event_end'];
+ if (!isset($summary)) $summary = $master_array[$old_start_date][$old_start_time][$uid]['event_text'];
+ if (!isset($length)) $length = $master_array[$old_start_date][$old_start_time][$uid]['event_length'];
+ if (!isset($description)) $description = $master_array[$old_start_date][$old_start_time][$uid]['description'];
+ removeOverlap($start_date_tmp, $old_start_time, $uid);
+ if (isset($master_array[$start_date_tmp][$old_start_time][$uid])) {
+ unset($master_array[$start_date_tmp][$old_start_time][$uid]); // SJBO added $uid twice here
+ }
+ $write_processed = false;
} else {
- $length = ($time2[1]*60+$time2[2]) - ($time[1]*60+$time[2]);
+ $write_processed = true;
}
- $drawKey = drawEventTimes($start_time, $end_time);
- ereg ('([0-9]{2})([0-9]{2})', $drawKey['draw_start'], $time3);
- $hour = $time3[1];
- $minute = $time3[2];
- }
-
- // RECURRENCE-ID Support
- if (isset($recurrence_d)) {
+ if (!isset($summary)) $summary = '';
+ if (!isset($description)) $description = '';
+ if (!isset($status)) $status = '';
+ if (!isset($class)) $class = '';
+ if (!isset($location)) $location = '';
- $recurrence_delete["$recurrence_d"]["$recurrence_t"] = $uid;
- }
+ $mArray_begin = mktime (0,0,0,12,21,($this_year - 1));
+ $mArray_end = mktime (0,0,0,1,12,($this_year + 1));
- // handle single changes in recurring events
- // Maybe this is no longer need since done at bottom of parser? - CL 11/20/02
- if ($uid_valid && $write_processed) {
- if (!isset($hour)) $hour = 00;
- if (!isset($minute)) $minute = 00;
- $processed[$uid] = array($start_date,($hour.$minute));
- }
-
- // Handling of the all day events
- if ((isset($allday_start) && $allday_start != '')) {
- $start = strtotime($allday_start);
- if (isset($allday_end)) {
- $end = strtotime($allday_end);
+ if (isset($start_time) && isset($end_time)) {
+ // Mozilla style all-day events or just really long events
+ if (($end_time - $start_time) > 2345) {
+ $allday_start = $start_date;
+ $allday_end = ($start_date + 1);
+ }
+ }
+ if (isset($start_unixtime,$end_unixtime) && date('d',$start_unixtime) != date('d',$end_unixtime)) {
+ $spans_day = true;
} else {
- $end = strtotime('+1 day', $start);
+ $spans_day = false;
}
- if (($end > $mArray_begin) && ($end < $mArray_end)) {
- while ($start != $end) {
- $start_date2 = date('Ymd', $start);
- $master_array[($start_date2)][('-1')][$uid]= array ('event_text' => $summary, 'description' => $description);
- $start = strtotime('+1 day', $start);
+ if (isset($start_time) && $start_time != '') {
+ ereg ('([0-9]{2})([0-9]{2})', $start_time, $time);
+ ereg ('([0-9]{2})([0-9]{2})', $end_time, $time2);
+ if (isset($start_unixtime) && isset($end_unixtime)) {
+ $length = $end_unixtime - $start_unixtime;
+ } else {
+ $length = ($time2[1]*60+$time2[2]) - ($time[1]*60+$time[2]);
}
- if (!$write_processed) $master_array[($start_date)]['-1'][$uid]['exception'] = true;
+
+ $drawKey = drawEventTimes($start_time, $end_time);
+ ereg ('([0-9]{2})([0-9]{2})', $drawKey['draw_start'], $time3);
+ $hour = $time3[1];
+ $minute = $time3[2];
}
- }
-
- // Handling regular events
- if ((isset($start_time) && $start_time != '') && (!isset($allday_start) || $allday_start == '')) {
- if ($spans_day) {
- $start_tmp = strtotime(date('Ymd',$start_unixtime));
- $end_date_tmp = date('Ymd',$end_unixtime);
- while ($start_tmp < $end_unixtime) {
- $start_date_tmp = date('Ymd',$start_tmp);
- if ($start_date_tmp == $start_date) {
- $time_tmp = $hour.$minute;
- $start_time_tmp = $start_time;
- } else {
- $time_tmp = '0000';
- $start_time_tmp = '0000';
- }
- if ($start_date_tmp == $end_date_tmp) {
- $end_time_tmp = $end_time;
- } else {
- $end_time_tmp = '2400';
- }
- $nbrOfOverlaps = checkOverlap($start_date_tmp, $start_time_tmp, $end_time_tmp, $uid);
- $master_array[$start_date_tmp][$time_tmp][$uid] = array ('event_start' => $start_time_tmp, 'event_end' => $end_time_tmp, 'start_unixtime' => $start_unixtime, 'end_unixtime' => $end_unixtime, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => true, 'location' => $location, 'organizer' => serialize($organizer), 'attendee' => serialize($attendee) );
- $start_tmp = strtotime('+1 day',$start_tmp);
- }
- if (!$write_processed) $master_array[$start_date][($hour.$minute)][$uid]['exception'] = true;
- } else {
- $nbrOfOverlaps = checkOverlap($start_date, $start_time, $end_time, $uid);
- $master_array[($start_date)][($hour.$minute)][$uid] = array ('event_start' => $start_time, 'event_end' => $end_time, 'start_unixtime' => $start_unixtime, 'end_unixtime' => $end_unixtime, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => false, 'location' => $location, 'organizer' => serialize($organizer), 'attendee' => serialize($attendee) );
- if (!$write_processed) $master_array[($start_date)][($hour.$minute)][$uid]['exception'] = true;
+
+ // RECURRENCE-ID Support
+ if (isset($recurrence_d)) {
+
+ $recurrence_delete["$recurrence_d"]["$recurrence_t"] = $uid;
}
- }
-
- // Handling of the recurring events, RRULE
- if (isset($rrule_array) && is_array($rrule_array)) {
- if (isset($allday_start) && $allday_start != '') {
- $hour = '-';
- $minute = '1';
- $rrule_array['START_DAY'] = $allday_start;
- $rrule_array['END_DAY'] = $allday_end;
- $rrule_array['END'] = 'end';
- $recur_start = $allday_start;
- $start_date = $allday_start;
+
+ // handle single changes in recurring events
+ // Maybe this is no longer need since done at bottom of parser? - CL 11/20/02
+ if ($uid_valid && $write_processed) {
+ if (!isset($hour)) $hour = 00;
+ if (!isset($minute)) $minute = 00;
+ $processed[$uid] = array($start_date,($hour.$minute));
+ }
+
+ // Handling of the all day events
+ if ((isset($allday_start) && $allday_start != '')) {
+ $start = strtotime($allday_start);
if (isset($allday_end)) {
- $diff_allday_days = dayCompare($allday_end, $allday_start);
- } else {
- $diff_allday_days = 1;
+ $end = strtotime($allday_end);
+ } else {
+ $end = strtotime('+1 day', $start);
+ }
+ if (($end > $mArray_begin) && ($end < $mArray_end)) {
+ while ($start != $end) {
+ $start_date2 = date('Ymd', $start);
+ $master_array[($start_date2)][('-1')][$uid]= array ('event_text' => $summary, 'description' => $description, 'calnumber' => $calnumber);
+ $start = strtotime('+1 day', $start);
+ }
+ if (!$write_processed) $master_array[($start_date)]['-1'][$uid]['exception'] = true;
}
- } else {
- $rrule_array['START_DATE'] = $start_date;
- $rrule_array['START_TIME'] = $start_time;
- $rrule_array['END_TIME'] = $end_time;
- $rrule_array['END'] = 'end';
- }
-
- $start_date_time = strtotime($start_date);
- $this_month_start_time = strtotime($this_year.$this_month.'01');
- if ($save_parsed_cals == 'yes' && !$is_webcal) {
- $start_range_time = strtotime($this_year.'-01-01 -1 month -2 days');
- $end_range_time = strtotime($this_year.'-12-31 +1 month +2 days');
- } else {
- $start_range_time = strtotime('-1 month -2 day', $this_month_start_time);
- $end_range_time = strtotime('+2 month +2 day', $this_month_start_time);
}
- foreach ($rrule_array as $key => $val) {
- switch($key) {
- case 'FREQ':
- switch ($val) {
- case 'YEARLY': $freq_type = 'year'; break;
- case 'MONTHLY': $freq_type = 'month'; break;
- case 'WEEKLY': $freq_type = 'week'; break;
- case 'DAILY': $freq_type = 'day'; break;
- case 'HOURLY': $freq_type = 'hour'; break;
- case 'MINUTELY': $freq_type = 'minute'; break;
- case 'SECONDLY': $freq_type = 'second'; break;
+ // Handling regular events
+ if ((isset($start_time) && $start_time != '') && (!isset($allday_start) || $allday_start == '')) {
+ if ($spans_day) {
+ $start_tmp = strtotime(date('Ymd',$start_unixtime));
+ $end_date_tmp = date('Ymd',$end_unixtime);
+ while ($start_tmp < $end_unixtime) {
+ $start_date_tmp = date('Ymd',$start_tmp);
+ if ($start_date_tmp == $start_date) {
+ $time_tmp = $hour.$minute;
+ $start_time_tmp = $start_time;
+ } else {
+ $time_tmp = '0000';
+ $start_time_tmp = '0000';
}
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = strtolower($val);
- break;
- case 'COUNT':
- $count = $val;
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $count;
- break;
- case 'UNTIL':
- $until = ereg_replace('T', '', $val);
- $until = ereg_replace('Z', '', $until);
- ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $until, $regs);
- $year = $regs[1];
- $month = $regs[2];
- $day = $regs[3];
- $until = mktime(0,0,0,$month,$day,$year);
- if (ereg('^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$', $val)) {
- // RFC 2445 says that if an UNTIL has a date-time value,
- // it MUST be in UTC (i.e. trailing Z). iCal tends to
- // put an end date on the next day early in the morning,
- // not in UTC time, so we try to correct for it.
- //
- // Bill's guess: iCal stores the UNTIL internally as
- // 23:59:59 UTC, then accidentally converts that to local
- // time when exporting the event. Thus, if the UNTIL time
- // is before noon, it is a day ahead; if it's after noon
- // it's the right day.
- if ($regs[4] < 12)
- $until = strtotime('-1 day', $until);
+ if ($start_date_tmp == $end_date_tmp) {
+ $end_time_tmp = $end_time;
+ } else {
+ $end_time_tmp = '2400';
}
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = localizeDate($dateFormat_week,$until);
- break;
- case 'INTERVAL':
- $number = $val;
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $number;
- break;
- case 'BYSECOND':
- $bysecond = $val;
- $bysecond = split (',', $bysecond);
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bysecond;
- break;
- case 'BYMINUTE':
- $byminute = $val;
- $byminute = split (',', $byminute);
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byminute;
- break;
- case 'BYHOUR':
- $byhour = $val;
- $byhour = split (',', $byhour);
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byhour;
- break;
- case 'BYDAY':
- $byday = $val;
- $byday = split (',', $byday);
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byday;
- break;
- case 'BYMONTHDAY':
- $bymonthday = $val;
- $bymonthday = split (',', $bymonthday);
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bymonthday;
- break;
- case 'BYYEARDAY':
- $byyearday = $val;
- $byyearday = split (',', $byyearday);
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byyearday;
- break;
- case 'BYWEEKNO':
- $byweekno = $val;
- $byweekno = split (',', $byweekno);
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byweekno;
- break;
- case 'BYMONTH':
- $bymonth = $val;
- $bymonth = split (',', $bymonth);
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bymonth;
- break;
- case 'BYSETPOS':
- $bysetpos = $val;
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bysetpos;
- break;
- case 'WKST':
- $wkst = $val;
- $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $wkst;
- break;
- case 'END':
+ $nbrOfOverlaps = checkOverlap($start_date_tmp, $start_time_tmp, $end_time_tmp, $uid);
+ $master_array[$start_date_tmp][$time_tmp][$uid] = array ('event_start' => $start_time_tmp, 'event_end' => $end_time_tmp, 'start_unixtime' => $start_unixtime, 'end_unixtime' => $end_unixtime, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => true, 'location' => $location, 'organizer' => serialize($organizer), 'attendee' => serialize($attendee) );
+ $start_tmp = strtotime('+1 day',$start_tmp);
+ }
+ if (!$write_processed) $master_array[$start_date][($hour.$minute)][$uid]['exception'] = true;
+ } else {
+ $nbrOfOverlaps = checkOverlap($start_date, $start_time, $end_time, $uid);
+ $master_array[($start_date)][($hour.$minute)][$uid] = array ('event_start' => $start_time, 'event_end' => $end_time, 'start_unixtime' => $start_unixtime, 'end_unixtime' => $end_unixtime, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => false, 'location' => $location, 'organizer' => serialize($organizer), 'attendee' => serialize($attendee), 'calnumber' => $calnumber );
+ if (!$write_processed) $master_array[($start_date)][($hour.$minute)][$uid]['exception'] = true;
+ }
+ }
+
+ // Handling of the recurring events, RRULE
+ if (isset($rrule_array) && is_array($rrule_array)) {
+ if (isset($allday_start) && $allday_start != '') {
+ $hour = '-';
+ $minute = '1';
+ $rrule_array['START_DAY'] = $allday_start;
+ $rrule_array['END_DAY'] = $allday_end;
+ $rrule_array['END'] = 'end';
+ $recur_start = $allday_start;
+ $start_date = $allday_start;
+ if (isset($allday_end)) {
+ $diff_allday_days = dayCompare($allday_end, $allday_start);
+ } else {
+ $diff_allday_days = 1;
+ }
+ } else {
+ $rrule_array['START_DATE'] = $start_date;
+ $rrule_array['START_TIME'] = $start_time;
+ $rrule_array['END_TIME'] = $end_time;
+ $rrule_array['END'] = 'end';
+ }
- // if $until isn't set yet, we set it to the end of our range we're looking at
- if (!isset($until)) $until = $end_range_time;
- $end_date_time = $until;
- $start_range_time_tmp = $start_range_time;
- $end_range_time_tmp = $end_range_time;
-
- // If the $end_range_time is less than the $start_date_time, or $start_range_time is greater
- // than $end_date_time, we may as well forget the whole thing
- // It doesn't do us any good to spend time adding data we aren't even looking at
- // this will prevent the year view from taking way longer than it needs to
- if ($end_range_time_tmp >= $start_date_time && $start_range_time_tmp <= $end_date_time) {
+ $start_date_time = strtotime($start_date);
+ $this_month_start_time = strtotime($this_year.$this_month.'01');
+ if ($save_parsed_cals == 'yes' && !$is_webcal) {
+ $start_range_time = strtotime($this_year.'-01-01 -1 month -2 days');
+ $end_range_time = strtotime($this_year.'-12-31 +1 month +2 days');
+ } else {
+ $start_range_time = strtotime('-1 month -2 day', $this_month_start_time);
+ $end_range_time = strtotime('+2 month +2 day', $this_month_start_time);
+ }
+
+ foreach ($rrule_array as $key => $val) {
+ switch($key) {
+ case 'FREQ':
+ switch ($val) {
+ case 'YEARLY': $freq_type = 'year'; break;
+ case 'MONTHLY': $freq_type = 'month'; break;
+ case 'WEEKLY': $freq_type = 'week'; break;
+ case 'DAILY': $freq_type = 'day'; break;
+ case 'HOURLY': $freq_type = 'hour'; break;
+ case 'MINUTELY': $freq_type = 'minute'; break;
+ case 'SECONDLY': $freq_type = 'second'; break;
+ }
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = strtolower($val);
+ break;
+ case 'COUNT':
+ $count = $val;
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $count;
+ break;
+ case 'UNTIL':
+ $until = ereg_replace('T', '', $val);
+ $until = ereg_replace('Z', '', $until);
+ ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $until, $regs);
+ $year = $regs[1];
+ $month = $regs[2];
+ $day = $regs[3];
+ $until = mktime(0,0,0,$month,$day,$year);
+ if (ereg('^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$', $val)) {
+ // RFC 2445 says that if an UNTIL has a date-time value,
+ // it MUST be in UTC (i.e. trailing Z). iCal tends to
+ // put an end date on the next day early in the morning,
+ // not in UTC time, so we try to correct for it.
+ //
+ // Bill's guess: iCal stores the UNTIL internally as
+ // 23:59:59 UTC, then accidentally converts that to local
+ // time when exporting the event. Thus, if the UNTIL time
+ // is before noon, it is a day ahead; if it's after noon
+ // it's the right day.
+ if ($regs[4] < 12)
+ $until = strtotime('-1 day', $until);
+ }
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = localizeDate($dateFormat_week,$until);
+ break;
+ case 'INTERVAL':
+ $number = $val;
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $number;
+ break;
+ case 'BYSECOND':
+ $bysecond = $val;
+ $bysecond = split (',', $bysecond);
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bysecond;
+ break;
+ case 'BYMINUTE':
+ $byminute = $val;
+ $byminute = split (',', $byminute);
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byminute;
+ break;
+ case 'BYHOUR':
+ $byhour = $val;
+ $byhour = split (',', $byhour);
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byhour;
+ break;
+ case 'BYDAY':
+ $byday = $val;
+ $byday = split (',', $byday);
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byday;
+ break;
+ case 'BYMONTHDAY':
+ $bymonthday = $val;
+ $bymonthday = split (',', $bymonthday);
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bymonthday;
+ break;
+ case 'BYYEARDAY':
+ $byyearday = $val;
+ $byyearday = split (',', $byyearday);
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byyearday;
+ break;
+ case 'BYWEEKNO':
+ $byweekno = $val;
+ $byweekno = split (',', $byweekno);
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byweekno;
+ break;
+ case 'BYMONTH':
+ $bymonth = $val;
+ $bymonth = split (',', $bymonth);
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bymonth;
+ break;
+ case 'BYSETPOS':
+ $bysetpos = $val;
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bysetpos;
+ break;
+ case 'WKST':
+ $wkst = $val;
+ $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $wkst;
+ break;
+ case 'END':
- // if the beginning of our range is less than the start of the item, we may as well set it equal to it
- if ($start_range_time_tmp < $start_date_time) $start_range_time_tmp = $start_date_time;
- if ($end_range_time_tmp > $end_date_time) $end_range_time_tmp = $end_date_time;
-
- // initialze the time we will increment
- $next_range_time = $start_range_time_tmp;
+ // if $until isn't set yet, we set it to the end of our range we're looking at
+ if (!isset($until)) $until = $end_range_time;
+ $end_date_time = $until;
+ $start_range_time_tmp = $start_range_time;
+ $end_range_time_tmp = $end_range_time;
- $count_to = 0;
- // start at the $start_range and go until we hit the end of our range.
- while (($next_range_time >= $start_range_time_tmp) && ($next_range_time <= $end_range_time_tmp) && ($count_to != $count)) {
- $func = $freq_type.'Compare';
- $diff = $func(date('Ymd',$next_range_time), $start_date);
- if ($diff < $count) {
- if ($diff % $number == 0) {
- $interval = $number;
- switch ($rrule_array['FREQ']) {
- case 'DAILY':
- $next_date_time = $next_range_time;
- $recur_data[] = $next_date_time;
- break;
- case 'WEEKLY':
- if (is_array($byday)) {
- // loop through the days on which this event happens
- foreach($byday as $day) {
- // use my fancy little function to get the date of each day
- $day = two2threeCharDays($day);
- $next_date = dateOfWeek(date('Ymd', $next_range_time),$day);
- $next_date_time = strtotime($next_date);
- $recur_data[] = $next_date_time;
- }
- }
- break;
- case 'MONTHLY':
- $next_range_time = strtotime(date('Y-m-01', $next_range_time));
- // month has two cases, either $bymonthday or $byday
- if (is_array($bymonthday)) {
- // loop through the days on which this event happens
- foreach($bymonthday as $day) {
- $year = date('Y', $next_range_time);
- $month = date('m', $next_range_time);
- if (checkdate($month,$day,$year)) {
- $next_date_time = mktime(0,0,0,$month,$day,$year);
+ // If the $end_range_time is less than the $start_date_time, or $start_range_time is greater
+ // than $end_date_time, we may as well forget the whole thing
+ // It doesn't do us any good to spend time adding data we aren't even looking at
+ // this will prevent the year view from taking way longer than it needs to
+ if ($end_range_time_tmp >= $start_date_time && $start_range_time_tmp <= $end_date_time) {
+
+ // if the beginning of our range is less than the start of the item, we may as well set it equal to it
+ if ($start_range_time_tmp < $start_date_time) $start_range_time_tmp = $start_date_time;
+ if ($end_range_time_tmp > $end_date_time) $end_range_time_tmp = $end_date_time;
+
+ // initialze the time we will increment
+ $next_range_time = $start_range_time_tmp;
+
+ $count_to = 0;
+ // start at the $start_range and go until we hit the end of our range.
+ while (($next_range_time >= $start_range_time_tmp) && ($next_range_time <= $end_range_time_tmp) && ($count_to != $count)) {
+ $func = $freq_type.'Compare';
+ $diff = $func(date('Ymd',$next_range_time), $start_date);
+ if ($diff < $count) {
+ if ($diff % $number == 0) {
+ $interval = $number;
+ switch ($rrule_array['FREQ']) {
+ case 'DAILY':
+ $next_date_time = $next_range_time;
+ $recur_data[] = $next_date_time;
+ break;
+ case 'WEEKLY':
+ if (is_array($byday)) {
+ // loop through the days on which this event happens
+ foreach($byday as $day) {
+ // use my fancy little function to get the date of each day
+ $day = two2threeCharDays($day);
+ $next_date = dateOfWeek(date('Ymd', $next_range_time),$day);
+ $next_date_time = strtotime($next_date);
$recur_data[] = $next_date_time;
}
}
- // our other case
- } else {
- // loop through the days on which this event happens
- foreach($byday as $day) {
- ereg ('([-\+]{0,1})([0-9]{1})([A-Z]{2})', $day, $byday_arr);
- $nth = $byday_arr[2]-1;
- $on_day = two2threeCharDays($byday_arr[3]);
- $on_day_num = two2threeCharDays($byday_arr[3],false);
- if ($byday_arr[1] == '-') {
- $last_day_tmp = date('t',$next_range_time);
- $next_range_time = strtotime(date('Y-m-'.$last_day_tmp, $next_range_time));
- $last_tmp = (date('w',$next_range_time) == $on_day_num) ? '' : 'last ';
- $next_date_time = strtotime($last_tmp.$on_day.' -'.$nth.' week', $next_range_time);
- } else {
- $next_date_time = strtotime($on_day.' +'.$nth.' week', $next_range_time);
+ break;
+ case 'MONTHLY':
+ $next_range_time = strtotime(date('Y-m-01', $next_range_time));
+ // month has two cases, either $bymonthday or $byday
+ if (is_array($bymonthday)) {
+ // loop through the days on which this event happens
+ foreach($bymonthday as $day) {
+ $year = date('Y', $next_range_time);
+ $month = date('m', $next_range_time);
+ if (checkdate($month,$day,$year)) {
+ $next_date_time = mktime(0,0,0,$month,$day,$year);
+ $recur_data[] = $next_date_time;
+ }
}
- $next_date = date('Ymd', $next_date_time);
- $recur_data[] = $next_date_time;
- }
- }
- break;
- case 'YEARLY':
- if (!isset($bymonth)) $bymonth[] = date('m', $start_date_time);
- foreach($bymonth as $month) {
- $year = date('Y', $next_range_time);
- if ((isset($byday)) && (is_array($byday))) {
- $checkdate_time = mktime(0,0,0,$month,1,$year);
+ // our other case
+ } else {
+ // loop through the days on which this event happens
foreach($byday as $day) {
ereg ('([-\+]{0,1})([0-9]{1})([A-Z]{2})', $day, $byday_arr);
$nth = $byday_arr[2]-1;
$on_day = two2threeCharDays($byday_arr[3]);
+ $on_day_num = two2threeCharDays($byday_arr[3],false);
if ($byday_arr[1] == '-') {
- $last_day_tmp = date('t',$checkdate_time);
- $checkdate_time = strtotime(date('Y-m-'.$last_day_tmp, $checkdate_time));
- $last_tmp = (date('w',$checkdate_time) == $on_day_num) ? '' : 'last ';
- $next_date_time = strtotime($last_tmp.$on_day.' -'.$nth.' week', $checkdate_time);
- } else {
- $next_date_time = strtotime($on_day.' +'.$nth.' week', $checkdate_time);
+ $last_day_tmp = date('t',$next_range_time);
+ $next_range_time = strtotime(date('Y-m-'.$last_day_tmp, $next_range_time));
+ $last_tmp = (date('w',$next_range_time) == $on_day_num) ? '' : 'last ';
+ $next_date_time = strtotime($last_tmp.$on_day.' -'.$nth.' week', $next_range_time);
+ } else {
+ $next_date_time = strtotime($on_day.' +'.$nth.' week', $next_range_time);
}
+ $next_date = date('Ymd', $next_date_time);
+ $recur_data[] = $next_date_time;
}
- } else {
- $day = date('d', $start_date_time);
- $next_date_time = mktime(0,0,0,$month,$day,$year);
}
- $recur_data[] = $next_date_time;
- }
- break;
- default:
- // anything else we need to end the loop
- $next_range_time = $end_range_time_tmp + 100;
- $count_to = $count;
+ break;
+ case 'YEARLY':
+ if (!isset($bymonth)) $bymonth[] = date('m', $start_date_time);
+ foreach($bymonth as $month) {
+ $year = date('Y', $next_range_time);
+ if ((isset($byday)) && (is_array($byday))) {
+ $checkdate_time = mktime(0,0,0,$month,1,$year);
+ foreach($byday as $day) {
+ ereg ('([-\+]{0,1})([0-9]{1})([A-Z]{2})', $day, $byday_arr);
+ $nth = $byday_arr[2]-1;
+ $on_day = two2threeCharDays($byday_arr[3]);
+ if ($byday_arr[1] == '-') {
+ $last_day_tmp = date('t',$checkdate_time);
+ $checkdate_time = strtotime(date('Y-m-'.$last_day_tmp, $checkdate_time));
+ $last_tmp = (date('w',$checkdate_time) == $on_day_num) ? '' : 'last ';
+ $next_date_time = strtotime($last_tmp.$on_day.' -'.$nth.' week', $checkdate_time);
+ } else {
+ $next_date_time = strtotime($on_day.' +'.$nth.' week', $checkdate_time);
+ }
+ }
+ } else {
+ $day = date('d', $start_date_time);
+ $next_date_time = mktime(0,0,0,$month,$day,$year);
+ }
+ $recur_data[] = $next_date_time;
+ }
+ break;
+ default:
+ // anything else we need to end the loop
+ $next_range_time = $end_range_time_tmp + 100;
+ $count_to = $count;
+ }
+ } else {
+ $interval = 1;
}
+ $next_range_time = strtotime('+'.$interval.' '.$freq_type, $next_range_time);
} else {
- $interval = 1;
+ // end the loop because we aren't going to write this event anyway
+ $count_to = $count;
}
- $next_range_time = strtotime('+'.$interval.' '.$freq_type, $next_range_time);
- } else {
- // end the loop because we aren't going to write this event anyway
- $count_to = $count;
- }
- // use the same code to write the data instead of always changing it 5 times
- if (isset($recur_data) && is_array($recur_data)) {
- $recur_data_hour = substr($start_time,0,2);
- $recur_data_minute = substr($start_time,2,2);
- foreach($recur_data as $recur_data_time) {
- $recur_data_year = date('Y', $recur_data_time);
- $recur_data_month = date('m', $recur_data_time);
- $recur_data_day = date('d', $recur_data_time);
- $recur_data_date = $recur_data_year.$recur_data_month.$recur_data_day;
-
- if (($recur_data_time > $start_date_time) && ($recur_data_time <= $end_date_time) && ($count_to != $count) && !in_array($recur_data_date, $except_dates)) {
- if (isset($allday_start) && $allday_start != '') {
- $start_time2 = $recur_data_time;
- $end_time2 = strtotime('+'.$diff_allday_days.' days', $recur_data_time);
- while ($start_time2 < $end_time2) {
- $start_date2 = date('Ymd', $start_time2);
- $master_array[($start_date2)][('-1')][]= array ('event_text' => $summary, 'description' => $description);
- $start_time2 = strtotime('+1 day', $start_time2);
- }
- } else {
- $start_unixtime_tmp = mktime($recur_data_hour,$recur_data_minute,0,$recur_data_month,$recur_data_day,$recur_data_year);
- $end_unixtime_tmp = $start_unixtime_tmp + $length;
-
- if ($spans_day) {
- $start_tmp = strtotime(date('Ymd',$start_unixtime_tmp));
- $end_date_tmp = date('Ymd',$end_unixtime_tmp);
- while ($start_tmp < $end_unixtime_tmp) {
- $start_date_tmp = date('Ymd',$start_tmp);
- if ($start_date_tmp == $start_date) {
- $time_tmp = $hour.$minute;
- $start_time_tmp = $start_time;
- } else {
- $time_tmp = '0000';
- $start_time_tmp = '0000';
- }
- if ($start_date_tmp == $end_date_tmp) {
- $end_time_tmp = $end_time;
- } else {
- $end_time_tmp = '2400';
- }
- $nbrOfOverlaps = checkOverlap($start_date_tmp, $start_time_tmp, $end_time_tmp, $uid);
- $master_array[$start_date_tmp][$time_tmp][$uid] = array ('event_start' => $start_time_tmp, 'event_end' => $end_time_tmp, 'start_unixtime' => $start_unixtime_tmp, 'end_unixtime' => $end_unixtime_tmp, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => true);
- $start_tmp = strtotime('+1 day',$start_tmp);
+ // use the same code to write the data instead of always changing it 5 times
+ if (isset($recur_data) && is_array($recur_data)) {
+ $recur_data_hour = substr($start_time,0,2);
+ $recur_data_minute = substr($start_time,2,2);
+ foreach($recur_data as $recur_data_time) {
+ $recur_data_year = date('Y', $recur_data_time);
+ $recur_data_month = date('m', $recur_data_time);
+ $recur_data_day = date('d', $recur_data_time);
+ $recur_data_date = $recur_data_year.$recur_data_month.$recur_data_day;
+
+ if (($recur_data_time > $start_date_time) && ($recur_data_time <= $end_date_time) && ($count_to != $count) && !in_array($recur_data_date, $except_dates)) {
+ if (isset($allday_start) && $allday_start != '') {
+ $start_time2 = $recur_data_time;
+ $end_time2 = strtotime('+'.$diff_allday_days.' days', $recur_data_time);
+ while ($start_time2 < $end_time2) {
+ $start_date2 = date('Ymd', $start_time2);
+ $master_array[($start_date2)][('-1')][]= array ('event_text' => $summary, 'description' => $description, 'calnumber' => $calnumber);
+ $start_time2 = strtotime('+1 day', $start_time2);
}
} else {
- $nbrOfOverlaps = checkOverlap($recur_data_date, $start_time, $end_time, $uid);
- $master_array[($recur_data_date)][($hour.$minute)][$uid] = array ('event_start' => $start_time, 'event_end' => $end_time, 'start_unixtime' => $start_unixtime_tmp, 'end_unixtime' => $end_unixtime_tmp, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => false);
+ $start_unixtime_tmp = mktime($recur_data_hour,$recur_data_minute,0,$recur_data_month,$recur_data_day,$recur_data_year);
+ $end_unixtime_tmp = $start_unixtime_tmp + $length;
+
+ if ($spans_day) {
+ $start_tmp = strtotime(date('Ymd',$start_unixtime_tmp));
+ $end_date_tmp = date('Ymd',$end_unixtime_tmp);
+ while ($start_tmp < $end_unixtime_tmp) {
+ $start_date_tmp = date('Ymd',$start_tmp);
+ if ($start_date_tmp == $start_date) {
+ $time_tmp = $hour.$minute;
+ $start_time_tmp = $start_time;
+ } else {
+ $time_tmp = '0000';
+ $start_time_tmp = '0000';
+ }
+ if ($start_date_tmp == $end_date_tmp) {
+ $end_time_tmp = $end_time;
+ } else {
+ $end_time_tmp = '2400';
+ }
+ $nbrOfOverlaps = checkOverlap($start_date_tmp, $start_time_tmp, $end_time_tmp, $uid);
+ $master_array[$start_date_tmp][$time_tmp][$uid] = array ('event_start' => $start_time_tmp, 'event_end' => $end_time_tmp, 'start_unixtime' => $start_unixtime_tmp, 'end_unixtime' => $end_unixtime_tmp, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => true, 'calnumber' => $calnumber);
+ $start_tmp = strtotime('+1 day',$start_tmp);
+ }
+ } else {
+ $nbrOfOverlaps = checkOverlap($recur_data_date, $start_time, $end_time, $uid);
+ $master_array[($recur_data_date)][($hour.$minute)][$uid] = array ('event_start' => $start_time, 'event_end' => $end_time, 'start_unixtime' => $start_unixtime_tmp, 'end_unixtime' => $end_unixtime_tmp, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => false, 'calnumber' => $calnumber);
+ }
}
}
}
+ unset($recur_data);
}
- unset($recur_data);
}
}
- }
- }
+ }
+ }
}
- }
-
- // Begin VTODO Support
- } elseif ($line == 'END:VTODO') {
- if ((!$vtodo_priority) && ($status == 'COMPLETED')) {
- $vtodo_sort = 11;
- } elseif (!$vtodo_priority) {
- $vtodo_sort = 10;
+
+ // Begin VTODO Support
+ } elseif ($line == 'END:VTODO') {
+ if ((!$vtodo_priority) && ($status == 'COMPLETED')) {
+ $vtodo_sort = 11;
+ } elseif (!$vtodo_priority) {
+ $vtodo_sort = 10;
+ } else {
+ $vtodo_sort = $vtodo_priority;
+ }
+ $master_array['-2']["$vtodo_sort"]["$uid"] = array ('start_date' => $start_date, 'start_time' => $start_time, 'vtodo_text' => $summary, 'due_date'=> $due_date, 'due_time'=> $due_time, 'completed_date' => $completed_date, 'completed_time' => $completed_time, 'priority' => $vtodo_priority, 'status' => $status, 'class' => $class, 'categories' => $vtodo_categories);
+ unset ($due_date, $due_time, $completed_date, $completed_time, $vtodo_priority, $status, $class, $vtodo_categories, $summary);
+ $vtodo_set = FALSE;
+ } elseif ($line == 'BEGIN:VTODO') {
+ $vtodo_set = TRUE;
+ } elseif ($line == 'BEGIN:VALARM') {
+ $valarm_set = TRUE;
+ } elseif ($line == 'END:VALARM') {
+ $valarm_set = FALSE;
} else {
- $vtodo_sort = $vtodo_priority;
- }
- $master_array['-2']["$vtodo_sort"]["$uid"] = array ('start_date' => $start_date, 'start_time' => $start_time, 'vtodo_text' => $summary, 'due_date'=> $due_date, 'due_time'=> $due_time, 'completed_date' => $completed_date, 'completed_time' => $completed_time, 'priority' => $vtodo_priority, 'status' => $status, 'class' => $class, 'categories' => $vtodo_categories);
- unset ($due_date, $due_time, $completed_date, $completed_time, $vtodo_priority, $status, $class, $vtodo_categories, $summary);
- $vtodo_set = FALSE;
- } elseif ($line == 'BEGIN:VTODO') {
- $vtodo_set = TRUE;
- } elseif ($line == 'BEGIN:VALARM') {
- $valarm_set = TRUE;
- } elseif ($line == 'END:VALARM') {
- $valarm_set = FALSE;
- } else {
-
- unset ($field, $data, $prop_pos, $property);
- ereg ("([^:]+):(.*)", $line, $line);
- $field = $line[1];
- $data = $line[2];
+
+ unset ($field, $data, $prop_pos, $property);
+ ereg ("([^:]+):(.*)", $line, $line);
+ $field = $line[1];
+ $data = $line[2];
+
+ $property = $field;
+ $prop_pos = strpos($property,';');
+ if ($prop_pos !== false) $property = substr($property,0,$prop_pos);
+ $property = strtoupper($property);
+
+ switch ($property) {
+
+ // Start VTODO Parsing
+ //
+ case 'DUE':
+ $zulu_time = false;
+ if (substr($data,-1) == 'Z') $zulu_time = true;
+ $data = ereg_replace('T', '', $data);
+ $data = ereg_replace('Z', '', $data);
+ if (preg_match("/^DUE;VALUE=DATE/i", $field)) {
+ $allday_start = $data;
+ $start_date = $allday_start;
+ } 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';
+ }
- $property = $field;
- $prop_pos = strpos($property,';');
- if ($prop_pos !== false) $property = substr($property,0,$prop_pos);
- $property = strtoupper($property);
+ ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $data, $regs);
+ $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]);
- switch ($property) {
-
- // Start VTODO Parsing
- //
- case 'DUE':
- $zulu_time = false;
- if (substr($data,-1) == 'Z') $zulu_time = true;
- $data = ereg_replace('T', '', $data);
- $data = ereg_replace('Z', '', $data);
- if (preg_match("/^DUE;VALUE=DATE/i", $field)) {
- $allday_start = $data;
- $start_date = $allday_start;
- } 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);
- $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_due)) {
- if (array_key_exists($tz_due, $tz_array)) {
- $offset_tmp = $tz_array[$tz_due][$dlst];
+ $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 = '+0000';
+ $offset_tmp = $server_offset_tmp;
}
- } elseif (isset($calendar_tz)) {
- if (array_key_exists($calendar_tz, $tz_array)) {
- $offset_tmp = $tz_array[$calendar_tz][$dlst];
+ $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);
+ }
+ break;
+
+ case 'COMPLETED':
+ $zulu_time = false;
+ if (substr($data,-1) == 'Z') $zulu_time = true;
+ $data = ereg_replace('T', '', $data);
+ $data = ereg_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);
+ $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_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 = '+0000';
+ $offset_tmp = $server_offset_tmp;
}
- } 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);
}
- $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);
- }
- break;
+ break;
- case 'COMPLETED':
- $zulu_time = false;
- if (substr($data,-1) == 'Z') $zulu_time = true;
- $data = ereg_replace('T', '', $data);
- $data = ereg_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);
- $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_completed)) {
- if (array_key_exists($tz_completed, $tz_array)) {
- $offset_tmp = $tz_array[$tz_completed][$dlst];
- } else {
- $offset_tmp = '+0000';
+ case 'PRIORITY':
+ $vtodo_priority = "$data";
+ break;
+
+ case 'STATUS':
+ // VEVENT: TENTATIVE, CONFIRMED, CANCELLED
+ // VTODO: NEEDS-ACTION, COMPLETED, IN-PROCESS, CANCELLED
+ $status = "$data";
+ break;
+
+ case 'CLASS':
+ // VEVENT, VTODO: PUBLIC, PRIVATE, CONFIDENTIAL
+ $class = "$data";
+ break;
+
+ case 'CATEGORIES':
+ $vtodo_categories = "$data";
+ break;
+ //
+ // End VTODO Parsing
+
+ case 'DTSTART':
+ $zulu_time = false;
+ if (substr($data,-1) == 'Z') $zulu_time = true;
+ $data = ereg_replace('T', '', $data);
+ $data = ereg_replace('Z', '', $data);
+ $field = ereg_replace(';VALUE=DATE-TIME', '', $field);
+ if (preg_match("/^DTSTART;VALUE=DATE/i", $field)) {
+ $allday_start = $data;
+ $start_date = $allday_start;
+ } 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';
}
- } elseif (isset($calendar_tz)) {
- if (array_key_exists($calendar_tz, $tz_array)) {
- $offset_tmp = $tz_array[$calendar_tz][$dlst];
+
+ ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $data, $regs);
+ $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 = '+0000';
+ $offset_tmp = $server_offset_tmp;
}
- } 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);
}
- $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;
-
- case 'PRIORITY':
- $vtodo_priority = "$data";
- break;
-
- case 'STATUS':
- // VEVENT: TENTATIVE, CONFIRMED, CANCELLED
- // VTODO: NEEDS-ACTION, COMPLETED, IN-PROCESS, CANCELLED
- $status = "$data";
- break;
-
- case 'CLASS':
- // VEVENT, VTODO: PUBLIC, PRIVATE, CONFIDENTIAL
- $class = "$data";
- break;
-
- case 'CATEGORIES':
- $vtodo_categories = "$data";
- break;
- //
- // End VTODO Parsing
-
- case 'DTSTART':
- $zulu_time = false;
- if (substr($data,-1) == 'Z') $zulu_time = true;
- $data = ereg_replace('T', '', $data);
- $data = ereg_replace('Z', '', $data);
- $field = ereg_replace(';VALUE=DATE-TIME', '', $field);
- if (preg_match("/^DTSTART;VALUE=DATE/i", $field)) {
- $allday_start = $data;
- $start_date = $allday_start;
- } 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';
- }
-
- ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $data, $regs);
- $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';
+ break;
+
+ case 'DTEND';
+ $zulu_time = false;
+ if (substr($data,-1) == 'Z') $zulu_time = true;
+ $data = ereg_replace('T', '', $data);
+ $data = ereg_replace('Z', '', $data);
+ $field = ereg_replace(';VALUE=DATE-TIME', '', $field);
+ if (preg_match("/^DTEND;VALUE=DATE/i", $field)) {
+ $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';
}
- } elseif (isset($calendar_tz)) {
- if (array_key_exists($calendar_tz, $tz_array)) {
+
+ ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $data, $regs);
+ $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 = '+0000';
+ $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);
+
+ }
+ break;
+
+ case 'EXDATE':
+ $data = split(",", $data);
+ foreach ($data as $exdata) {
+ $exdata = ereg_replace('T', '', $exdata);
+ $exdata = ereg_replace('Z', '', $exdata);
+ ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $exdata, $regs);
+ $except_dates[] = $regs[1] . $regs[2] . $regs[3];
+ $except_times[] = $regs[4] . $regs[5];
+ }
+ break;
+
+ case 'SUMMARY':
+ $data = str_replace("\\n", "<br>", $data);
+ $data = str_replace("\\r", "<br>", $data);
+ $data = htmlentities(urlencode($data));
+ if ($valarm_set == FALSE) {
+ $summary = $data;
} else {
- $offset_tmp = $server_offset_tmp;
+ $valarm_summary = $data;
}
- $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);
- }
- break;
-
- case 'DTEND';
- $zulu_time = false;
- if (substr($data,-1) == 'Z') $zulu_time = true;
- $data = ereg_replace('T', '', $data);
- $data = ereg_replace('Z', '', $data);
- $field = ereg_replace(';VALUE=DATE-TIME', '', $field);
- if (preg_match("/^DTEND;VALUE=DATE/i", $field)) {
- $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';
+ break;
+
+ case 'DESCRIPTION':
+ $data = str_replace("\\n", "<br>", $data);
+ $data = str_replace("\\r", "<br>", $data);
+ $data = htmlentities(urlencode($data));
+ if ($valarm_set == FALSE) {
+ $description = $data;
+ } else {
+ $valarm_description = $data;
}
+ break;
+ case 'RECURRENCE-ID':
+ $parts = explode(';', $field);
+ foreach($parts as $part) {
+ $eachval = split('=',$part);
+ if ($eachval[0] == 'RECURRENCE-ID') {
+ // do nothing
+ } elseif ($eachval[0] == 'TZID') {
+ $recurrence_id['tzid'] = $eachval[1];
+ } elseif ($eachval[0] == 'RANGE') {
+ $recurrence_id['range'] = $eachval[1];
+ } elseif ($eachval[0] == 'VALUE') {
+ $recurrence_id['value'] = $eachval[1];
+ } else {
+ $recurrence_id[] = $eachval[1];
+ }
+ }
+ unset($parts, $part, $eachval);
+
+ $data = ereg_replace('T', '', $data);
+ $data = ereg_replace('Z', '', $data);
ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $data, $regs);
- $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];
+ $recurrence_id['date'] = $regs[1] . $regs[2] . $regs[3];
+ $recurrence_id['time'] = $regs[4] . $regs[5];
+
+ $recur_unixtime = mktime($regs[4], $regs[5], 0, $regs[2], $regs[3], $regs[1]);
+
+ $dlst = date('I', $recur_unixtime);
+ $server_offset_tmp = chooseOffset($recur_unixtime);
+ if (isset($recurrence_id['tzid'])) {
+ $tz_tmp = $recurrence_id['tzid'];
+ $offset_tmp = $tz_array[$tz_tmp][$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);
+ $recur_unixtime = calcTime($offset_tmp, $server_offset_tmp, $recur_unixtime);
+ $recurrence_id['date'] = date('Ymd', $recur_unixtime);
+ $recurrence_id['time'] = date('Hi', $recur_unixtime);
+ $recurrence_d = date('Ymd', $recur_unixtime);
+ $recurrence_t = date('Hi', $recur_unixtime);
unset($server_offset_tmp);
-
- }
- break;
-
- case 'EXDATE':
- $data = split(",", $data);
- foreach ($data as $exdata) {
- $exdata = ereg_replace('T', '', $exdata);
- $exdata = ereg_replace('Z', '', $exdata);
- ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $exdata, $regs);
- $except_dates[] = $regs[1] . $regs[2] . $regs[3];
- $except_times[] = $regs[4] . $regs[5];
- }
- break;
-
- case 'SUMMARY':
- $data = str_replace("\\n", "<br>", $data);
- $data = str_replace("\\r", "<br>", $data);
- $data = htmlentities(urlencode($data));
- if ($valarm_set == FALSE) {
- $summary = $data;
- } else {
- $valarm_summary = $data;
- }
- break;
-
- case 'DESCRIPTION':
- $data = str_replace("\\n", "<br>", $data);
- $data = str_replace("\\r", "<br>", $data);
- $data = htmlentities(urlencode($data));
- if ($valarm_set == FALSE) {
- $description = $data;
- } else {
- $valarm_description = $data;
- }
- break;
-
- case 'RECURRENCE-ID':
- $parts = explode(';', $field);
- foreach($parts as $part) {
- $eachval = split('=',$part);
- if ($eachval[0] == 'RECURRENCE-ID') {
- // do nothing
- } elseif ($eachval[0] == 'TZID') {
- $recurrence_id['tzid'] = $eachval[1];
- } elseif ($eachval[0] == 'RANGE') {
- $recurrence_id['range'] = $eachval[1];
- } elseif ($eachval[0] == 'VALUE') {
- $recurrence_id['value'] = $eachval[1];
- } else {
- $recurrence_id[] = $eachval[1];
- }
- }
- unset($parts, $part, $eachval);
-
- $data = ereg_replace('T', '', $data);
- $data = ereg_replace('Z', '', $data);
- ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $data, $regs);
- $recurrence_id['date'] = $regs[1] . $regs[2] . $regs[3];
- $recurrence_id['time'] = $regs[4] . $regs[5];
-
- $recur_unixtime = mktime($regs[4], $regs[5], 0, $regs[2], $regs[3], $regs[1]);
-
- $dlst = date('I', $recur_unixtime);
- $server_offset_tmp = chooseOffset($recur_unixtime);
- if (isset($recurrence_id['tzid'])) {
- $tz_tmp = $recurrence_id['tzid'];
- $offset_tmp = $tz_array[$tz_tmp][$dlst];
- } elseif (isset($calendar_tz)) {
- $offset_tmp = $tz_array[$calendar_tz][$dlst];
- } else {
- $offset_tmp = $server_offset_tmp;
- }
- $recur_unixtime = calcTime($offset_tmp, $server_offset_tmp, $recur_unixtime);
- $recurrence_id['date'] = date('Ymd', $recur_unixtime);
- $recurrence_id['time'] = date('Hi', $recur_unixtime);
- $recurrence_d = date('Ymd', $recur_unixtime);
- $recurrence_t = date('Hi', $recur_unixtime);
- unset($server_offset_tmp);
- break;
-
- case 'UID':
- $uid = $data;
- break;
- case 'X-WR-CALNAME':
- $calendar_name = $data;
- $master_array['calendar_name'] = $calendar_name;
- break;
- case 'X-WR-TIMEZONE':
- $calendar_tz = $data;
- $master_array['calendar_tz'] = $calendar_tz;
- break;
- case 'DURATION':
- if (($first_duration == TRUE) && (!stristr($field, '=DURATION'))) {
- ereg ('^P([0-9]{1,2})?([W,D]{0,1}[T])?([0-9]{1,2}[H])?([0-9]{1,2}[M])?([0-9]{1,2}[S])?', $data, $duration);
- if ($duration[2] = 'W') {
- $weeks = $duration[1];
- $days = 0;
- } else {
- $days = $duration[1];
- $weeks = 0;
+ break;
+
+ case 'UID':
+ $uid = $data;
+ break;
+ case 'X-WR-CALNAME':
+ $calendar_name = $data;
+ $master_array['calendar_name'] = $calendar_name;
+ break;
+ case 'X-WR-TIMEZONE':
+ $calendar_tz = $data;
+ $master_array['calendar_tz'] = $calendar_tz;
+ break;
+ case 'DURATION':
+ if (($first_duration == TRUE) && (!stristr($field, '=DURATION'))) {
+ ereg ('^P([0-9]{1,2})?([W,D]{0,1}[T])?([0-9]{1,2}[H])?([0-9]{1,2}[M])?([0-9]{1,2}[S])?', $data, $duration);
+ if ($duration[2] = 'W') {
+ $weeks = $duration[1];
+ $days = 0;
+ } else {
+ $days = $duration[1];
+ $weeks = 0;
+ }
+ $hours = ereg_replace('H', '', $duration[3]);
+ $minutes = ereg_replace('M', '', $duration[4]);
+ $seconds = ereg_replace('S', '', $duration[5]);
+ $the_duration = ($weeks * 60 * 60 * 24 * 7) + ($days * 60 * 60 * 24) + ($hours * 60 * 60) + ($minutes * 60) + ($seconds);
+ $end_unixtime = $start_unixtime + $the_duration;
+ $end_time = date ('Hi', $end_unixtime);
+ $first_duration = FALSE;
+ }
+ break;
+ case 'RRULE':
+ $data = ereg_replace ('RRULE:', '', $data);
+ $rrule = split (';', $data);
+ foreach ($rrule as $recur) {
+ ereg ('(.*)=(.*)', $recur, $regs);
+ $rrule_array[$regs[1]] = $regs[2];
}
- $hours = ereg_replace('H', '', $duration[3]);
- $minutes = ereg_replace('M', '', $duration[4]);
- $seconds = ereg_replace('S', '', $duration[5]);
- $the_duration = ($weeks * 60 * 60 * 24 * 7) + ($days * 60 * 60 * 24) + ($hours * 60 * 60) + ($minutes * 60) + ($seconds);
- $end_unixtime = $start_unixtime + $the_duration;
- $end_time = date ('Hi', $end_unixtime);
- $first_duration = FALSE;
- }
- break;
- case 'RRULE':
- $data = ereg_replace ('RRULE:', '', $data);
- $rrule = split (';', $data);
- foreach ($rrule as $recur) {
- ereg ('(.*)=(.*)', $recur, $regs);
- $rrule_array[$regs[1]] = $regs[2];
- }
- break;
- // Attendee support only testing in Apple iCal 1.0.2
- case 'ATTENDEE':
- $field = ereg_replace("ATTENDEE;CN=", "", $field);
- $data = ereg_replace ("mailto:", "", $data);
- $attendee[] = array ('name' => $field, 'email' => $data);
- #print_r($attendee);
- break;
- case 'ORGANIZER':
- $field = ereg_replace("ORGANIZER;CN=", "", $field);
- $data = ereg_replace ("mailto:", "", $data);
- $organizer[] = array ('name' => $field, 'email' => $data);
- break;
- case 'LOCATION':
- $data = $location;
- break;
+ break;
+ // Attendee support only testing in Apple iCal 1.0.2
+ case 'ATTENDEE':
+ $field = ereg_replace("ATTENDEE;CN=", "", $field);
+ $data = ereg_replace ("mailto:", "", $data);
+ $attendee[] = array ('name' => $field, 'email' => $data);
+ #print_r($attendee);
+ break;
+ case 'ORGANIZER':
+ $field = ereg_replace("ORGANIZER;CN=", "", $field);
+ $data = ereg_replace ("mailto:", "", $data);
+ $organizer[] = array ('name' => $field, 'email' => $data);
+ break;
+ case 'LOCATION':
+ $data = $location;
+ break;
+ }
}
}
- }
-
- /*
- //print '<pre>';
- // Remove pesky recurrences
- if (is_array($recurrence_delete)) {
- foreach ($recurrence_delete as $delete => $delete_key) {
- foreach ($delete_key as $key => $val) {
- #echo "Before Delete:: $delete $key $val<br>";
- #print_r($master_array["$delete"]);
- if (is_array($master_array[($delete)][($key)][($val)])) {
- removeOverlap($delete, $key, $val);
- unset($master_array["$delete"]["$key"]["$val"]);
- // Remove date from array if no events
- if (sizeof($master_array["$delete"]["$key"] = 1)) {
- #echo "deleting $delete $key $val<br>";
- unset($master_array["$delete"]["$key"]);
- if (!sizeof($master_array["$delete"] > 1)) {
+
+ /*
+ //print '<pre>';
+ // Remove pesky recurrences
+ if (is_array($recurrence_delete)) {
+ foreach ($recurrence_delete as $delete => $delete_key) {
+ foreach ($delete_key as $key => $val) {
+ #echo "Before Delete:: $delete $key $val<br>";
+ #print_r($master_array["$delete"]);
+ if (is_array($master_array[($delete)][($key)][($val)])) {
+ removeOverlap($delete, $key, $val);
+ unset($master_array["$delete"]["$key"]["$val"]);
+ // Remove date from array if no events
+ if (sizeof($master_array["$delete"]["$key"] = 1)) {
#echo "deleting $delete $key $val<br>";
- unset($master_array["$delete"]);
+ unset($master_array["$delete"]["$key"]);
+ if (!sizeof($master_array["$delete"] > 1)) {
+ #echo "deleting $delete $key $val<br>";
+ unset($master_array["$delete"]);
+ }
}
- }
- #print_r($master_array["$delete"]);
- // Check for overlaps and rewrite them
- foreach($master_array["$delete"] as $overlap_time => $overlap_val) {
- $recur_data_date = $delete;
- foreach ($overlap_val as $uid => $val) {
- $start_time = $val['event_start'];
- $end_time = $val['event_end'];
- #$nbrOfOverlaps = checkOverlap($recur_data_date, $start_time, $end_time, $uid);
- #$master_array[($recur_data_date)][($start_time)][($uid)]['event_overlap'] = 0;
- #echo "$recur_data_date - $uid - $start_time - $end_time - $nbrOfOverlaps<br>";
- #print_r($val);
+ #print_r($master_array["$delete"]);
+ // Check for overlaps and rewrite them
+ foreach($master_array["$delete"] as $overlap_time => $overlap_val) {
+ $recur_data_date = $delete;
+ foreach ($overlap_val as $uid => $val) {
+ $start_time = $val['event_start'];
+ $end_time = $val['event_end'];
+ #$nbrOfOverlaps = checkOverlap($recur_data_date, $start_time, $end_time, $uid);
+ #$master_array[($recur_data_date)][($start_time)][($uid)]['event_overlap'] = 0;
+ #echo "$recur_data_date - $uid - $start_time - $end_time - $nbrOfOverlaps<br>";
+ #print_r($val);
+ }
}
}
}
}
}
- }
-
- */
- // Sort the array by absolute date.
- if (isset($master_array) && is_array($master_array)) {
- ksort($master_array);
- reset($master_array);
- // sort the sub (day) arrays so the times are in order
- foreach (array_keys($master_array) as $k) {
- if (isset($master_array[$k]) && is_array($master_array[$k])) {
- ksort($master_array[$k]);
- reset($master_array[$k]);
+ */
+ }
+ $calnumber = $calnumber + 1;
+}
+
+
+if ($parse_file) {
+ // Sort the array by absolute date.
+ if (isset($master_array) && is_array($master_array)) {
+ ksort($master_array);
+ reset($master_array);
+
+ // sort the sub (day) arrays so the times are in order
+ foreach (array_keys($master_array) as $k) {
+ if (isset($master_array[$k]) && is_array($master_array[$k])) {
+ ksort($master_array[$k]);
+ reset($master_array[$k]);
+ }
}
}
- }
-
- // write the new master array to the file
- if (isset($master_array) && is_array($master_array) && $save_parsed_cals == 'yes' && $is_webcal == FALSE) {
- $write_me = serialize($master_array);
- $fd = fopen($parsedcal, 'w');
- fwrite($fd, $write_me);
- fclose($fd);
- touch($parsedcal, $realcal_mtime);
- }
+
+ // write the new master array to the file
+ if (isset($master_array) && is_array($master_array) && $save_parsed_cals == 'yes' && $is_webcal == FALSE) {
+ $write_me = serialize($master_array);
+ $fd = fopen($parsedcal, 'w');
+ fwrite($fd, $write_me);
+ fclose($fd);
+ touch($parsedcal, $realcal_mtime);
+ }
}
+
+
//If you want to see the values in the arrays, uncomment below.
-//print '<pre>';
-//print_r($master_array);
-//print_r($overlap_array);
+/*
+print '<pre>';
+print_r($master_array);
+print_r($overlap_array);
//print_r($day_array);
//print_r($rrule);
//print_r($recurrence_delete);
-//print '</pre>';
-
+print '</pre>';
+*/
+
+// Set a calender name for all calenders combined
+if ($cal == 'all_calenders_combined971') {
+ $calendar_name = $all_cal_comb_lang;
+}
?>
diff --git a/functions/init.inc.php b/functions/init.inc.php
index 1d8af84..3033e76 100644
--- a/functions/init.inc.php
+++ b/functions/init.inc.php
@@ -62,12 +62,16 @@ if (isset($HTTP_GET_VARS['cal']) && $HTTP_GET_VARS['cal'] != '') {
}
} else {
if (isset($default_cal_check)) {
- $calcheck = $calendar_path.'/'.$default_cal_check.'.ics';
- $calcheckopen = @fopen($calcheck, "r");
- if ($calcheckopen == FALSE) {
- $cal_filename = $default_cal;
+ if ($default_cal_check != 'all_calenders_combined971') {
+ $calcheck = $calendar_path.'/'.$default_cal_check.'.ics';
+ $calcheckopen = @fopen($calcheck, "r");
+ if ($calcheckopen == FALSE) {
+ $cal_filename = $default_cal;
+ } else {
+ $cal_filename = $default_cal_check;
+ }
} else {
- $cal_filename = $default_cal_check;
+ $cal_filename = 'all_calenders_combined971';
}
} else {
$cal_filename = $default_cal;
@@ -91,16 +95,35 @@ if ($is_webcal) {
exit(error($error_restrictedcal_lang, $cal_filename));
} else {
if (!isset($filename)) {
- $filename = $calendar_path.'/'.$cal_filename.'.ics';
- if (true == false) {
+ // empty the filelist array
+ $cal_filelist = array();
+ if ($cal == 'all_calenders_combined971') { // Create an array with the paths to all files to be combined
+ // Note: code here is similar to code in list_icals.php
+ // open directory
$dir_handle = @opendir($calendar_path) or die(error(sprintf($error_path_lang, $calendar_path), $cal_filename));
- while ($file = readdir($dir_handle)) {
- if (substr($file, -4) == '.ics') {
- $cal = urlencode(substr($file, 0, -4));
- $filename = $calendar_path.'/'.$file;
- break;
+
+
+ // build the array
+ while (false != ($file = readdir($dir_handle))) {
+ if (substr($file, -4) == ".ics") {
+ $file = $calendar_path.'/'.$file;
+ array_push($cal_filelist, $file);
+ }
+ }
+ natcasesort($cal_filelist);
+ } else { // Handle a single file
+ $filename = $calendar_path.'/'.$cal_filename.'.ics';
+ if (true == false) {
+ $dir_handle = @opendir($calendar_path) or die(error(sprintf($error_path_lang, $calendar_path), $cal_filename));
+ while ($file = readdir($dir_handle)) {
+ if (substr($file, -4) == '.ics') {
+ $cal = urlencode(substr($file, 0, -4));
+ $filename = $calendar_path.'/'.$file;
+ break;
+ }
}
}
+ array_push($cal_filelist, $filename);
}
}
diff --git a/functions/list_icals.php b/functions/list_icals.php
index 8c21c3d..75d85b4 100644
--- a/functions/list_icals.php
+++ b/functions/list_icals.php
@@ -35,9 +35,17 @@ if ($display_ical_list == "yes") {
print "<option value=\"$current_view.php?cal=$cal_tmp\" selected>$cal_displayname_tmp $calendar_lang</option>\n";
} else {
print "<option value=\"$current_view.php?cal=$cal_tmp\">$cal_displayname_tmp $calendar_lang</option>\n";
- }
+ }
}
}
+
+ // option to open all (non-web) calenders together
+ if ($cal == 'all_calenders_combined971') {
+ print "<option value=\"$current_view.php?cal=all_calenders_combined971\" selected>$all_cal_comb_lang</option>\n";
+ } else {
+ print "<option value=\"$current_view.php?cal=all_calenders_combined971\">$all_cal_comb_lang</option>\n";
+ }
+
foreach($list_webcals as $cal_tmp) {
if ($cal_tmp != '') {
$cal_displayname_tmp = basename($cal_tmp);
@@ -51,8 +59,7 @@ if ($display_ical_list == "yes") {
}
}
}
-
-
+
// close file
closedir($dir_handle);
diff --git a/functions/overlapping_events.php b/functions/overlapping_events.php
index b90dd04..659a0cb 100644
--- a/functions/overlapping_events.php
+++ b/functions/overlapping_events.php
@@ -160,23 +160,27 @@ function checkOverlap($ol_start_date, $ol_start_time, $ol_end_time, $ol_uid) {
}
// drei 20021126: function for checking and removing overlapping events
-function removeOverlap($ol_start_date, $ol_start_time, $ol_key = 0) {
+//function removeOverlap($ol_start_date, $ol_start_time, $ol_key = 0) {
+function removeOverlap($ol_start_date, $ol_start_time, $ol_key) {
global $master_array, $overlap_array;
if (isset($overlap_array[$ol_start_date])) {
if (sizeof($overlap_array[$ol_start_date]) > 0) {
$ol_end_time = $master_array[$ol_start_date][$ol_start_time][$ol_key]["event_end"];
foreach ($overlap_array[$ol_start_date] as $keyBlock => $blockId) {
- if (($blockId["blockStart"] <= $ol_start_time) or ($blockId["blockEnd"] >= $ol_start_time)) {
+// if (($blockId["blockStart"] <= $ol_start_time) or ($blockId["blockEnd"] >= $ol_start_time)) {
+ if (($blockId["blockStart"] <= $ol_start_time) and ($blockId["blockEnd"] > $ol_start_time)) {
foreach ($blockId["events"] as $keyEvent => $ol_event) {
$master_array[$ol_start_date][$ol_event["time"]][$ol_event["key"]]["event_overlap"] -= 1;
if (($ol_event["time"] == $ol_start_time) and ($ol_event["key"] == $ol_key)) {
unset ($overlap_array[$ol_start_date][$keyBlock]["events"][$keyEvent]);
}
}
- if ($blockId["maxOverlaps"] = 1) {
+ if ($blockId["maxOverlaps"] == 1) {
unset ($overlap_array[$ol_start_date][$keyBlock]);
} else {
- $blockId["maxOverlaps"] -= 1;
+ $overlap_array[$ol_start_date][$keyBlock]["maxOverlaps"] -= 1;
+ //$blockId["maxOverlaps"] -= 1;
+ // SJBO: Shouldn't something be done with [overlapRanges] as well?
}
}
}

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