function rrule_endtime($int, $freq, $start, $end) { // if # then we have to add the difference to the start time if (preg_match("/^#(.+)\$/i", $end, $M)) { $T = $M[1] * $freq; $plus_d = $plus_m = $plus_y = '0'; if ($int == '1') { $plus_d = $T; } elseif ($int == '2') { $plus_d = $T * 7; } elseif ($int == '3') { $plus_m = $T; } elseif ($int == '4') { $plus_m = $T; } elseif ($int == '5') { $plus_y = $T; } elseif ($int == '6') { $plus_m = $T; } $endtime = vcaldate_to_timestamp($start, $plus_d, $plus_m, $plus_y); // if we have the enddate } else { $endtime = vcaldate_to_timestamp($end); } return $endtime; }
function format_vcal($event) { // Start and end time // Set Calendar Type for easier processing later $fevent['CalendarType'] = $event['state']; $fevent['Untimed'] = $fevent['AllDay'] = 0; $fevent['StartTime'] = vcaldate_to_timestamp($event['dtstart']); if ($fevent['StartTime'] == '-1') { return false; } $fevent['EndTime'] = vcaldate_to_timestamp($event['dtend']); if ($fevent['StartTime'] == $fevent['EndTime']) { $fevent['Untimed'] = 1; $fevent['Duration'] = 0; } else { // Calculate duration in minutes $fevent['Duration'] = ($fevent['EndTime'] - $fevent['StartTime']) / 60; if ($fevent['Duration'] == '1440' && date('His', $fevent['StartTime']) == 0) { $fevent['AllDay'] = 1; } } if (!empty($event['summary'])) { $fevent['Summary'] = $event['summary']; } if (!empty($event['description'])) { $fevent['Description'] = $event['description']; } if (!empty($event['descriptionqp'])) { $fevent['Description'] = quoted_printable_decode($event['descriptionqp']); // hack for mozilla sunbird's extra = signs $fevent['Description'] = preg_replace('/^=/', '', $fevent['Description']); $fevent['Description'] = str_replace("\n=", "\n", $fevent['Description']); } if (!empty($event['class'])) { // Added Confidential as new CLASS if (preg_match('/private/i', $event['class'])) { $fevent['Class'] = 'R'; } elseif (preg_match('/confidential/i', $event['class'])) { $fevent['Class'] = 'C'; } else { $fevent['Class'] = 'P'; } } if (!empty($fevent['UID'])) { $fevent['UID'] = $event['uid']; } // Repeats // vcal 1.0 repeats can be very complicated and the webcalendar doesn't // actually support all of the ways repeats can be specified. We will // focus on vcals dumped from Palm Desktop and Lotus Notes, which are simple // and the ones webcalendar should fully support. if (!empty($event['rrule'])) { // split into pieces $RR = explode(' ', $event['rrule']); if (preg_match('/^D(.+)$/i', $RR[0], $match)) { $fevent['Repeat']['Frequency'] = '1'; $fevent['Repeat']['Interval'] = $match[1]; } elseif (preg_match('/^W(.+)$/i', $RR[0], $match)) { $fevent['Repeat']['Frequency'] = '2'; $fevent['Repeat']['Interval'] = $match[1]; $fevent['Repeat']['ByDay'] = rrule_repeat_days($RR); } elseif (preg_match('/^MP(.+)$/i', $RR[0], $match)) { $fevent['Repeat']['Frequency'] = '3'; $fevent['Repeat']['Interval'] = $match[1]; if ($RR[1] == '5+') { $fevent['Repeat']['Frequency'] = '3'; } } elseif (preg_match('/^MD(.+)$/i', $RR[0], $match)) { $fevent['Repeat']['Frequency'] = '4'; $fevent['Repeat']['Interval'] = $match[1]; } elseif (preg_match('/^YM(.+)$/i', $RR[0], $match)) { $fevent['Repeat']['Frequency'] = '6'; $fevent['Repeat']['Interval'] = $match[1]; } elseif (preg_match('/^YD(.+)$/i', $RR[0], $match)) { $fevent['Repeat']['Frequency'] = '6'; $fevent['Repeat']['Interval'] = $match[1]; } $end = end($RR); // No end in Palm is 12-31-2031 if ($end != '20311231' && $end != '#0') { if (preg_match('/^\\#(.+)$/i', $end, $match)) { $fevent['Repeat']['Count'] = $match[1]; } } //. // Repeating exceptions? if (!empty($event['exdate'])) { $fevent['Repeat']['Exceptions'] = array(); $EX = explode(',', $event['exdate']); foreach ($EX as $exdate) { $fevent['Repeat']['Exceptions'][] = vcaldate_to_timestamp($exdate); } } } // end if rrule // TODO // $fevent[Category]; return $fevent; }