简体   繁体   English

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

[英]Creating An iCal Event, Without Creating A Calendar

I am using the iCalCreator class to create an event for user to load into their personal calendars. 我正在使用iCalCreator类创建一个事件,供用户加载到他们的个人日历中。 Here's the info, for those unfamiliar with it: http://www.kigkonsult.se/iCalcreator/ 以下是对于不熟悉它的人的信息: http//www.kigkonsult.se/iCalcreator/

Using the documentation, right on the homepage, I'm able to create an event and output it to the browser. 使用文档,在主页上,我可以创建一个事件并将其输出到浏览器。 No problems. 没问题。 The issue is that when it is imported (I'm testing on Outlook, but I'm expecting this to persist to other calendar software) it imports as a new calendar, with one event in it. 问题在于,当它被导入时(我在Outlook上进行测试,但我希望它能够持久保存到其他日历软件),它会作为新日历导入,其中包含一个事件。 I want the event to go right into your regular calendar. 我希望活动能够直接进入您的常规日历。

Does anyone have experience iCalCreator and know how I can make this happen? 有没有人有iCalCreator的经验,知道如何实现这一目标?

Thanks 谢谢

Since you are using php, you could just write a file out as an ics and save it on your server. 由于您使用的是php,因此您只需将文件写为ics并将其保存在服务器上即可。 The ical event is essentially a text file. ical事件本质上是一个文本文件。 You'd just have to update the name, unique ids and update the times to match your event. 您只需更新名称,唯一ID并更新时间以匹配您的活动。 This way all you're doing is creating a text file and naming it .ics. 这样你所做的就是创建一个文本文件并命名为.ics。 Hope it helps. 希望能帮助到你。

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

save the above text as a string 将上述文本保存为字符串

$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);

Then you can have a page that downloads that file 然后,您可以拥有一个下载该文件的页面

<?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');
?>

You might try replacing the line METHOD:PUBLISH with METHOD:REQUEST. 您可以尝试使用METHOD:REQUEST替换行METHOD:PUBLISH。 It is my (admittedly vague and untested) understanding of the scheduling protocol in RFC2446 that this is then an invitation, and Outlook may possibly ask the user to accept (and enter into the calendar) or decline it. RFC2446中对调度协议的理解是我的( 无可置疑的模糊和未经测试),这是一个邀请,Outlook可能会要求用户接受(并进入日历)或拒绝它。 It appears to work with TB/Lightning. 它似乎适用于TB / Lightning。

Try this (from https://gist.github.com/jakebellacera/635416 ) 试试这个(来自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: /');
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM