summaryrefslogtreecommitdiffstats
path: root/includes/ical_export.php
diff options
context:
space:
mode:
authorAndreaChirulescu <andrea.chirulescu@gmail.com>2022-02-21 21:37:44 +0100
committerAndreaChirulescu <andrea.chirulescu@gmail.com>2022-02-21 21:37:44 +0100
commit0775b984af29855d0a31ba38a30552f997ecf0b7 (patch)
treec3de14e74382a568ecaef6d56c329dbd47833724 /includes/ical_export.php
parentdac8783023971f8ebc057fc5fcf2d28b3cb96490 (diff)
parentef1da20cb88b94d7c4781cb3bcf86ccb67c5005f (diff)
downloadgigologadmin-0775b984af29855d0a31ba38a30552f997ecf0b7.tar.gz
gigologadmin-0775b984af29855d0a31ba38a30552f997ecf0b7.tar.bz2
gigologadmin-0775b984af29855d0a31ba38a30552f997ecf0b7.zip
Merge branch 'ical' of https://code.volse.net/wordpress/plugins/gigologadmin.git into andreaschanges
# Conflicts: # composer.json # composer.lock # giglogadmin.php
Diffstat (limited to 'includes/ical_export.php')
-rw-r--r--includes/ical_export.php176
1 files changed, 176 insertions, 0 deletions
diff --git a/includes/ical_export.php b/includes/ical_export.php
new file mode 100644
index 0000000..4543ce0
--- /dev/null
+++ b/includes/ical_export.php
@@ -0,0 +1,176 @@
+<?php
+
+// SPDX-FileCopyrightText: 2022 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+// SPDX-FileCopyrightText: 2022 Harald Eilertsen <haraldei@anduin.net>
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+use Kigkonsult\Icalcreator\Vcalendar;
+
+if ( ! class_exists( "GiglogAdmin_IcalExport" ) )
+{
+ class Giglogadmin_IcalExport
+ {
+ public static function export_ical()
+ {
+ // create a new calendar
+ $vcalendar = Vcalendar::factory( [ Vcalendar::UNIQUE_ID => "kigkonsult.se", ] )
+ // with calendaring info
+ ->setMethod( Vcalendar::PUBLISH )
+ ->setXprop(
+ Vcalendar::X_WR_CALNAME,
+ "Calendar Sample"
+ )
+ ->setXprop(
+ Vcalendar::X_WR_CALDESC,
+ "This is a demo calendar"
+ )
+ ->setXprop(
+ Vcalendar::X_WR_RELCALID,
+ "3E26604A-50F4-4449-8B3E-E4F4932D05B5"
+ )
+ ->setXprop(
+ Vcalendar::X_WR_TIMEZONE,
+ "Europe/Stockholm"
+ );
+
+ // create a new event
+ $event1 = $vcalendar->newVevent()
+ ->setTransp( Vcalendar::OPAQUE )
+ ->setClass( Vcalendar::P_BLIC )
+ ->setSequence( 1 )
+ // describe the event
+ ->setSummary( 'Scheduled meeting with five occurrences' )
+ ->setDescription(
+ 'Agenda for the the meeting...',
+ [ Vcalendar::ALTREP =>
+ 'CID:<FFFF__=0ABBE548DFE235B58f9e8a93d@coffeebean.com>' ]
+ )
+ ->setComment( 'It\'s going to be fun..' )
+ // place the event
+ ->setLocation( 'Kafé Ekorren Stockholm' )
+ ->setGeo( '59.32206', '18.12485' )
+ // set the time
+ ->setDtstart(
+ new DateTime(
+ '20190421T090000',
+ new DateTimezone( 'Europe/Stockholm' )
+ )
+ )
+ ->setDtend(
+ new DateTime(
+ '20190421T100000',
+ new DateTimezone( 'Europe/Stockholm' )
+ )
+ )
+ // with recurrence rule
+ ->setRrule(
+ [
+ Vcalendar::FREQ => Vcalendar::WEEKLY,
+ Vcalendar::COUNT => 5,
+ ]
+ )
+ // and set another on a specific date
+ ->setRdate(
+ [
+ new DateTime(
+ '20190609T090000',
+ new DateTimezone( 'Europe/Stockholm' )
+ ),
+ new DateTime(
+ '20190609T110000',
+ new DateTimezone( 'Europe/Stockholm' )
+ ),
+ ],
+ [ Vcalendar::VALUE => Vcalendar::PERIOD ]
+ )
+ // and revoke a recurrence date
+ ->setExdate(
+ new DateTime(
+ '2019-05-12 09:00:00',
+ new DateTimezone( 'Europe/Stockholm' )
+ )
+ )
+ // organizer, chair and some participants
+ ->setOrganizer(
+ 'secretary@coffeebean.com',
+ [ Vcalendar::CN => 'Secretary CoffeeBean' ]
+ )
+ ->setAttendee(
+ 'president@coffeebean.com',
+ [
+ Vcalendar::ROLE => Vcalendar::CHAIR,
+ Vcalendar::PARTSTAT => Vcalendar::ACCEPTED,
+ Vcalendar::RSVP => Vcalendar::FALSE,
+ Vcalendar::CN => 'President CoffeeBean',
+ ]
+ )
+ ->setAttendee(
+ 'participant1@coffeebean.com',
+ [
+ Vcalendar::ROLE => Vcalendar::REQ_PARTICIPANT,
+ Vcalendar::PARTSTAT => Vcalendar::NEEDS_ACTION,
+ Vcalendar::RSVP => Vcalendar::TRUE,
+ Vcalendar::CN => 'Participant1 CoffeeBean',
+ ]
+ )
+ ->setAttendee(
+ 'participant2@coffeebean.com',
+ [
+ Vcalendar::ROLE => Vcalendar::REQ_PARTICIPANT,
+ Vcalendar::PARTSTAT => Vcalendar::NEEDS_ACTION,
+ Vcalendar::RSVP => Vcalendar::TRUE,
+ Vcalendar::CN => 'Participant2 CoffeeBean',
+ ]
+ );
+
+ // add alarm for the event
+ $alarm = $event1->newValarm()
+ ->setAction( Vcalendar::DISPLAY )
+ // copy description from event
+ ->setDescription( $event1->getDescription())
+ // fire off the alarm one day before
+ ->setTrigger( '-P1D' );
+
+ // alter day and time for one event in recurrence set
+ $event2 = $vcalendar->newVevent()
+ ->setTransp( Vcalendar::OPAQUE )
+ ->setClass( Vcalendar::P_BLIC )
+ // reference to event in recurrence set
+ ->setUid( $event1->getUid())
+ ->setSequence( 2 )
+ // pointer to event in the recurrence set
+ ->setRecurrenceid( '20190505T090000 Europe/Stockholm' )
+ // reason text
+ ->setDescription(
+ 'Altered day and time for event 2019-05-05',
+ [ Vcalendar::ALTREP =>
+ 'CID:<FFFF__=0ABBE548DFE235B58f9e8a93d@coffeebean.com>' ]
+ )
+ ->setComment( 'Now we are working hard for two hours' )
+ // the altered day and time with duration
+ ->setDtstart(
+ new DateTime(
+ '20190504T100000',
+ new DateTimezone( 'Europe/Stockholm' )
+ )
+ )
+ ->setDuration( 'PT2H' )
+ // add alarm (copy from event1)
+ ->setComponent(
+ $event1->getComponent( Vcalendar::VALARM )
+ );
+
+ $vcalendarString =
+ // apply appropriate Vtimezone with Standard/DayLight components
+ $vcalendar->vtimezonePopulate()
+ // and create the (string) calendar
+ ->createCalendar();
+
+ header( 'Content-Type: text/calendar' );
+ echo $vcalendarString;
+ }
+ }
+
+ add_action( 'wp_ajax_nopriv_giglog_export_ical', [ 'GiglogAdmin_IcalExport', 'export_ical' ] );
+}