sabre-io / Baikal

Baïkal is a Calendar+Contacts server
https://sabre.io/baikal/
GNU General Public License v3.0
2.42k stars 281 forks source link

calling VEVENT/VTODO in XML and getting its properties #1226

Open gstlouisgit opened 7 months ago

gstlouisgit commented 7 months ago

Baikal version: 0.9.4

Problem you are having: I hope it is ok to ask this request here. I am a big fan of baikal as a calendar and for years I've had this integrated into a calendar for an application I develop and support using FullCalendar. It is great.

My challenge is I do not think I'm efficiently pulling data from a user VEVENT/VTODO. It is old code years ago when I was learning, but it is an ajax request calling curl from a PHP file using XML components.

Example:

` $model = ['VEVENT', 'VTODO'];

foreach ($model as $component){

$request = '<?xml version="1.0" encoding="UTF-8" ?>
        <L:calendar-query xmlns:L="urn:ietf:params:xml:ns:caldav">
            <D:prop xmlns:D="DAV:">
                <D:getcontenttype/>
                <D:resourcetype/>
                <D:getetag/>
                <L:calendar-data/>
            </D:prop>
            <L:filter>
                <L:comp-filter name="VCALENDAR"><L:comp-filter name="' . $component . '">
                    <L:time-range start="'.$start.'" end="'.$end.'"/>
                    </L:comp-filter>
                    </L:comp-filter>
            </L:filter>
        </L:calendar-query>';

$ch = curl_init();
foreach ($accounts['accounts'] as $account){

    $url = CALDAV . '/cal.php/calendars/' . $account['caldav-username'] . '/default/';
    $userpwd = $account['caldav-username'] . ':' . $account['caldav-password'];

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'REPORT');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    //$response[$account['caldav-username']] = curl_exec($ch);
    $construct['events'][][$component] = array('username' => $account['caldav-username'],
                    'color' => $account['caldav-color'],
                    'component' => $component,
                    'data' => curl_exec($ch));
}//foreach ($accounts['accounts'] as $account)

}//foreach ($model as $component)`

Suggested solution:

The problem I am having is dealing with the XML in javascript. When I am at the '' which the properties are a string, it is difficult to break them apart.

example:

PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN VERSION:2.0 BEGIN:VTIMEZONE TZID:America/Toronto BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:19700308T020000 RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:19701101T020000 RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU END:STANDARD END:VTIMEZONE BEGIN:VEVENT CREATED:20221212T135415Z LAST-MODIFIED:20230609T172856Z DTSTAMP:20230609T172856Z UID:0099d7ed-06cb-4422-9e61-6486d656f635 SUMMARY: title text X-MOZ-LASTACK:20230609T172856Z DTSTART;TZID=America/Toronto:20230609T080000 DTEND;TZID=America/Toronto:20230609T090000 TRANSP:OPAQUE DESCRIPTION;ALTREP="data:text/html,":text...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...texttext...text SEQUENCE:1 X-MOZ-GENERATION:2 BEGIN:VALARM ACTION:DISPLAY TRIGGER:-PT15M DESCRIPTION:Default Mozilla Description END:VALARM END:VEVENT END:VCALENDAR I cannot breakdown the properties properly. I was actually using `.split('\n')`, but DESCRIPTION property with DESCRIPTION;ALTREP= hold HTML that can screw this up, and I am sure this really is the best idea. So I was thinking that maybe my best approach is from the PHP file and use similar to this example: `use Sabre\VObject; include 'vendor/autoload.php'; $vcalendar = VObject\Reader::read( fopen('party.ics','r') ); echo $vcalendar->VEVENT->SUMMARY;` How can I use this with the XML I get back instead of putting the ics in there? IS there more documentation somewhere for this?