示例#1
0
function format_event_ical($ev)
{
    $o = '';
    $o .= "\nBEGIN:VEVENT";
    if ($ev['start']) {
        $o .= "\nDTSTART:" . datetime_convert('UTC', 'UTC', $ev['start'], 'Ymd\\THis' . ($ev['adjust'] ? '\\Z' : ''));
    }
    if ($ev['finish'] && !$ev['nofinish']) {
        $o .= "\nDTEND:" . datetime_convert('UTC', 'UTC', $ev['finish'], 'Ymd\\THis' . ($ev['adjust'] ? '\\Z' : ''));
    }
    if ($ev['summary']) {
        $o .= "\nSUMMARY:" . format_ical_text($ev['summary']);
    }
    if ($ev['location']) {
        $o .= "\nLOCATION:" . format_ical_text($ev['location']);
    }
    if ($ev['description']) {
        $o .= "\nDESCRIPTION:" . format_ical_text($ev['description']);
    }
    $o .= "\nEND:VEVENT\n";
    return $o;
}
示例#2
0
function format_todo_ical($ev)
{
    $o = '';
    $o .= "\r\nBEGIN:VTODO";
    $o .= "\r\nCREATED:" . datetime_convert('UTC', 'UTC', $ev['created'], 'Ymd\\THis\\Z');
    $o .= "\r\nLAST-MODIFIED:" . datetime_convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z');
    $o .= "\r\nDTSTAMP:" . datetime_convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z');
    if ($ev['dtstart']) {
        $o .= "\r\nDTSTART:" . datetime_convert('UTC', 'UTC', $ev['dtstart'], 'Ymd\\THis' . ($ev['adjust'] ? '\\Z' : ''));
    }
    if ($ev['dtend'] && !$ev['nofinish']) {
        $o .= "\r\nDUE:" . datetime_convert('UTC', 'UTC', $ev['dtend'], 'Ymd\\THis' . ($ev['adjust'] ? '\\Z' : ''));
    }
    if ($ev['summary']) {
        $o .= "\r\nSUMMARY:" . format_ical_text($ev['summary']);
    }
    if ($ev['event_status']) {
        $o .= "\r\nSTATUS:" . $ev['event_status'];
        if ($ev['event_status'] === 'COMPLETED') {
            $o .= "\r\nCOMPLETED:" . datetime_convert('UTC', 'UTC', $ev['event_status_date'], 'Ymd\\THis\\Z');
        }
    }
    if (intval($ev['event_percent'])) {
        $o .= "\r\nPERCENT-COMPLETE:" . $ev['event_percent'];
    }
    if (intval($ev['event_sequence'])) {
        $o .= "\r\nSEQUENCE:" . $ev['event_sequence'];
    }
    if ($ev['location']) {
        $o .= "\r\nLOCATION:" . format_ical_text($ev['location']);
    }
    if ($ev['description']) {
        $o .= "\r\nDESCRIPTION:" . format_ical_text($ev['description']);
    }
    $o .= "\r\nUID:" . $ev['event_hash'];
    if ($ev['event_priority']) {
        $o .= "\r\nPRIORITY:" . intval($ev['event_priority']);
    }
    $o .= "\r\nEND:VTODO\r\n";
    return $o;
}
示例#3
0
function format_ical($event)
{
    $icsOptions = get_option(ADMIN_OPTIONS_NAME);
    $fevent['raw'] = $event['RAW'];
    // Start and end time
    $fevent['StartTime'] = icaldate_to_timestamp($event['dtstart']);
    if (isset($event['dtend'])) {
        $fevent['EndTime'] = icaldate_to_timestamp($event['dtend']);
    } else {
        if (isset($event['duration'])) {
            $fevent['EndTime'] = $fevent['StartTime'] + $event['duration'] * 60;
        } else {
            $fevent['EndTime'] = $fevent['StartTime'];
        }
    }
    // Calculate duration in minutes
    if (isset($event['duration'])) {
        $fevent['Duration'] = $event['duration'];
    } else {
        if (empty($fevent['Duration'])) {
            $fevent['Duration'] = ($fevent['EndTime'] - $fevent['StartTime']) / 60;
        }
    }
    if ($fevent['Duration'] == '1440') {
        // All day event... nothing to do here :-)
    } else {
        if (preg_match("/\\d{8}\$/", $event['dtstart'], $pmatch)) {
            // Untimed event
            $fevent['Duration'] = 0;
            $fevent['Untimed'] = 1;
        }
    }
    if ($icsOptions['privacy_mode'] == '1') {
        $fevent['Summary'] = empty($event['summary']) ? '' : $icsOptions['privacy_mode_name'];
        $fevent['Description'] = empty($event['description']) ? '' : $icsOptions['privacy_mode_name'];
        $fevent['Location'] = empty($event['location']) ? '' : $icsOptions['privacy_mode_name'];
    } else {
        $fevent['Summary'] = format_ical_text($event['summary']);
        $fevent['Description'] = format_ical_text($event['description']);
        $fevent['Location'] = format_ical_text($event['location']);
    }
    $fevent['URL'] = format_ical_text($event['url']);
    $fevent['Private'] = preg_match("/private|confidential/i", $event['class']) ? '1' : '0';
    $fevent['UID'] = $event['uid'];
    $fevent['Status'] = format_ical_text($event['status']);
    if (isset($event['recurrence-id'])) {
        $fevent['RecurrenceID'] = icaldate_to_timestamp($event['recurrence-id']);
    }
    // Repeats
    //
    // Handle RRULE
    if ($event['rrule']) {
        // first remove and EndTime that may have been calculated above
        unset($fevent['Repeat']['EndTime']);
        //split into pieces
        //echo "RRULE line: $event[rrule] <br />\n";
        $RR = explode(";", $event['rrule']);
        // create an associative array of key-value paris in $RR2[]
        for ($i = 0; $i < count($RR); $i++) {
            $ar = explode("=", $RR[$i]);
            $RR2[$ar[0]] = $ar[1];
        }
        for ($i = 0; $i < count($RR); $i++) {
            //echo "RR $i = $RR[$i] <br />";
            if (preg_match("/^FREQ=(.+)\$/i", $RR[$i], $match)) {
                if (preg_match("/YEARLY/i", $match[1], $submatch)) {
                    $fevent['Repeat']['Interval'] = 5;
                } else {
                    if (preg_match("/MONTHLY/i", $match[1], $submatch)) {
                        $fevent['Repeat']['Interval'] = 3;
                    } else {
                        if (preg_match("/WEEKLY/i", $match[1], $submatch)) {
                            $fevent['Repeat']['Interval'] = 2;
                        } else {
                            if (preg_match("/DAILY/i", $match[1], $submatch)) {
                                $fevent['Repeat']['Interval'] = 1;
                            } else {
                                // not supported :-(
                                if (ICAL_EVENTS_DEBUG) {
                                    echo "Unsupported iCal FREQ value \"{$match['1']}\"<br />\n";
                                }
                            }
                        }
                    }
                }
            } else {
                if (preg_match("/^INTERVAL=(.+)\$/i", $RR[$i], $match)) {
                    $fevent['Repeat']['Frequency'] = $match[1];
                } else {
                    if (preg_match("/^UNTIL=(.+)\$/i", $RR[$i], $match)) {
                        // specifies an end date
                        $fevent['Repeat']['EndTime'] = icaldate_to_timestamp($match[1]);
                    } else {
                        if (preg_match("/^COUNT=(.+)\$/i", $RR[$i], $match)) {
                            $fevent['Repeat']['Count'] = $match[1];
                        } else {
                            if (preg_match("/^BYSECOND=(.+)\$/i", $RR[$i], $match)) {
                                // NOT YET SUPPORTED -- TODO
                                if (ICAL_EVENTS_DEBUG) {
                                    echo "Unsupported iCal BYSECOND value \"{$RR[$i]}\"<br />\n";
                                }
                            } else {
                                if (preg_match("/^BYMINUTE=(.+)\$/i", $RR[$i], $match)) {
                                    // NOT YET SUPPORTED -- TODO
                                    if (ICAL_EVENTS_DEBUG) {
                                        echo "Unsupported iCal BYMINUTE value \"{$RR[$i]}\"<br />\n";
                                    }
                                } else {
                                    if (preg_match("/^BYHOUR=(.+)\$/i", $RR[$i], $match)) {
                                        // NOT YET SUPPORTED -- TODO
                                        if (ICAL_EVENTS_DEBUG) {
                                            echo "Unsupported iCal BYHOUR value \"{$RR[$i]}\"<br />\n";
                                        }
                                    } else {
                                        if (preg_match("/^BYMONTH=(.+)\$/i", $RR[$i], $match)) {
                                            // this event repeats during the specified months
                                            $months = explode(",", $match[1]);
                                            if (count($months) == 1) {
                                                // Change this to a monthly event so we can support repeat by
                                                // day of month (if needed)
                                                // Frequency = 3 (by day), 4 (by date), 6 (by day reverse)
                                                if (!empty($RR2['BYDAY'])) {
                                                    if (preg_match("/^-/", $RR2['BYDAY'], $junk)) {
                                                        $fevent['Repeat']['Interval'] = 6;
                                                    } else {
                                                        $fevent['Repeat']['Interval'] = 3;
                                                    }
                                                    // monthly by day
                                                    $fevent['Repeat']['Frequency'] = 12;
                                                    // once every 12 months
                                                } else {
                                                    // could convert this to monthly by date, but we will just
                                                    // leave it as yearly.
                                                    //$fevent['Repeat']['Interval'] = 4; // monthly by date
                                                }
                                            } else {
                                                // WebCalendar does not support this
                                                if (ICAL_EVENTS_DEBUG) {
                                                    echo "Unsupported iCal BYMONTH value \"{$match['1']}\"<br />\n";
                                                }
                                            }
                                        } else {
                                            if (preg_match("/^BYDAY=(.+)\$/i", $RR[$i], $match)) {
                                                $fevent['Repeat']['RepeatDays'] = rrule_repeat_days(explode(',', $match[1]));
                                                //$fevent['Repeat']['ByDay'] = $match[1];
                                            } else {
                                                if (preg_match("/^BYMONTHDAY=(.+)\$/i", $RR[$i], $match)) {
                                                    $fevent['Repeat']['ByMonthDay'] = $match[1];
                                                } else {
                                                    if (preg_match("/^BYSETPOS=(.+)\$/i", $RR[$i], $match)) {
                                                        // NOT YET SUPPORTED -- TODO
                                                        if (ICAL_EVENTS_DEBUG) {
                                                            echo "Unsupported iCal BYSETPOS value \"{$RR[$i]}\"<br />\n";
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // Repeating exceptions?
        if ($event['exdate']) {
            $fevent['Repeat']['Exceptions'] = array();
            $EX = explode(",", $event['exdate']);
            foreach ($EX as $exdate) {
                if (!empty($exdate)) {
                    $fevent['Repeat']['Exceptions'][] = icaldate_to_timestamp($exdate);
                }
            }
        }
    }
    // end if rrule
    return $fevent;
}