开发者

Creating An iCal Event, Without Creating A Calendar

开发者 https://www.devze.com 2023-01-21 02:39 出处:网络
I开发者_运维问答 am using the iCalCreator class to create an event for user to load into their personal calendars. Here\'s the info, for those unfamiliar with it: http://www.kigkonsult.se/iCalcreator/

I开发者_运维问答 am using the iCalCreator class to create an event for user to load into their personal calendars. Here's the info, for those unfamiliar with it: 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. I want the event to go right into your regular calendar.

Does anyone have experience iCalCreator and know how I can make this happen?

Thanks


Since you are using php, you could just write a file out as an ics and save it on your server. The ical event is essentially a text file. You'd just have to update the name, unique ids and update the times to match your event. This way all you're doing is creating a text file and naming it .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. 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. It appears to work with TB/Lightning.


Try this (from 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: /');
}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消