Subscription Calendar URL in PHP

会有一股神秘感。 提交于 2019-12-23 05:12:21

问题


Hi, I am working on a project based on event management where each user store there event detail with start and end date. Now I want a feature to subscribe to the desktop application (Outlook, Ical for apple and google calendar), so that any new event save in the database it automatically sync to the desktop application. What is the best approach to achieve this functionality?


回答1:


Here's sample code for generating a single event iCal output:

$eventData = array(
        'title'       => $event->getTitle(),
        'address'     => $address,
        'description' => strip_tags($event->getBody()),
        'stage'       => $stage,
        'date'        => $event->getDate()
    );

    // Build the ics file


    $ical= 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTEND:' . $this->dateToCal($eventData['date']) . '
UID:' . md5($eventData['title']) . '
DTSTAMP:' . time() . '
LOCATION:' . $eventData['address'] . '
DESCRIPTION:' . $eventData['description'] . '
URL;VALUE=URI:http://go.okdo.it' . '
SUMMARY:' . $eventData['title'] . '
DTSTART:' . $this->dateToCal($eventData['date']) . '
END:VEVENT
END:VCALENDAR';

Here's the function that formats date objects to iCal format:

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

Before outputting the content, you need to set appropriate headers:

   header('Content-type: text/calendar; charset=utf-8');
   header('Content-Disposition: attachment; filename=' . $task->getTitle());
   echo $ical;


来源:https://stackoverflow.com/questions/20918786/subscription-calendar-url-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!