在不创建日历的情况下创建iCal事件

时间:2010-10-25 15:11:52

标签: php outlook calendar icalendar

我正在使用iCalCreator类创建一个事件,供用户加载到他们的个人日历中。对于那些不熟悉它的人来说,这是信息:http://www.kigkonsult.se/iCalcreator/

使用文档,在主页上,我可以创建一个事件并将其输出到浏览器。没问题。问题在于,当它被导入时(我在Outlook上进行测试,但我希望它能够持久保存到其他日历软件),它会作为新日历导入,其中包含一个事件。我希望活动能够直接进入您的常规日历。

有没有人有iCalCreator的经验,知道如何实现这一目标?

由于

3 个答案:

答案 0 :(得分:3)

由于您使用的是php,因此您只需将文件写为ics并将其保存在服务器上即可。 ical事件本质上是一个文本文件。您只需更新名称,唯一ID并更新时间以匹配您的活动。这样你所做的就是创建一个文本文件并命名为.ics。希望它有所帮助。

BEGIN:VCALENDAR
CALSCALE:GREGORIAN
VERSION:2.0
X-WR-CALNAME:Test making a generic ical event
METHOD:PUBLISH
PRODID:-//angelfilm entertainment LLC//EN
BEGIN:VTIMEZONE
TZID:America/Los_Angeles
BEGIN:DAYLIGHT
TZOFFSETFROM:-0800
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
DTSTART:20070311T020000
TZNAME:PDT
TZOFFSETTO:-0700
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
DTSTART:20071104T020000
TZNAME:PST
TZOFFSETTO:-0800
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20110720T173758Z
UID:6asdf9-asdfkjasdf-asd-asdf-sdaf33FE
DTEND;TZID=America/Los_Angeles:20110908T120000
TRANSP:OPAQUE
SUMMARY:Test making a generic ical event
DTSTART;TZID=America/Los_Angeles:20110908T110000
DTSTAMP:20110808T174507Z
SEQUENCE:3
BEGIN:VALARM
X-WR-ALARMUID:6asdf9-asdfkjasdf-asd-asdf-sdaf33Fa
TRIGGER;VALUE=DATE-TIME:20110908T105100
ATTACH;VALUE=URI:Basso
ACTION:AUDIO
END:VALARM
END:VEVENT
END:VCALENDAR

将上述文字保存为字符串

$myFile = "myIcalEvent.ics";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "THE ABOVE ICAL TEXT COULD BE SAVED TO THIS VARIABLE";
fwrite($fh, $stringData);
fclose($fh);

然后你可以有一个下载该文件的页面

<?php
// We'll be outputting a ICS
header('Content-type: text/calendar');

// It will be called downloaded.ics
header('Content-Disposition: attachment; filename="downloaded.ics"');

// The PDF source is in myIcalEvent.ics
readfile('myIcalEvent.ics');
?>

答案 1 :(得分:1)

您可以尝试使用METHOD:REQUEST替换行METHOD:PUBLISH。我对RFC2446中的调度协议的理解是模糊的,未经测试的,这是一个邀请,Outlook可能会要求用户接受(并进入日历)或拒绝它。 它似乎适用于TB / Lightning。

答案 2 :(得分:0)

试试这个(来自https://gist.github.com/jakebellacera/635416

<?php
// Fetch vars
$event = array(
    'id' => $_GET['id'],
    'title' => $_GET['title'],
        'address' => $_GET['address'],
    'description' => $_GET['description'],
    'datestart' => $_GET['datestart'],
    'dateend' => $_GET['dateend'],
    'address' => $_GET['stage']
);

// iCal date format: yyyymmddThhiissZ
// PHP equiv format: Ymd\This

// The Function

function dateToCal($time) {
    return date('Ymd\This', $time) . 'Z';
}

// Build the ics file
$ical = 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTEND:' . dateToCal($event['dateend']) . '
UID:' . md5($event['title']) . '
DTSTAMP:' . time() . '
LOCATION:' . addslashes($event['address']) . '
DESCRIPTION:' . addslashes($event['description']) . '
URL;VALUE=URI:http://mohawkaustin.com/events/' . $event['id'] . '
SUMMARY:' . addslashes($event['title']) . '
DTSTART:' . dateToCal($event['datestart']) . '
END:VEVENT
END:VCALENDAR';

//set correct content-type-header
if($event['id']){
    header('Content-type: text/calendar; charset=utf-8');
    header('Content-Disposition: attachment; filename=mohawk-event.ics');
    echo $ical;
} else {
    // If $id isn't set, then kick the user back to home. Do not pass go, and do not collect $200.
    header('Location: /');
}
?>