ICS Generator

This module can generate ICS files.

A ProcessWire module to generate ICS calendar strings and files. Events are managed via a standard WireArray.



Quick Start


$icsgen = wire()->modules->IcsGenerator;

// 1. Add Event
$icsgen->events->add([
    'summary'     => 'Christmas 2033',
    'dtstart'     => '2033-12-24 18:00',
    'dtend'       => '2033-12-24 22:00',
    'location'    => 'The North Pole',
    'description' => 'Ho ho ho!',
    'url'         => 'https://example.com'
]);

// 2. Output
echo $icsgen->getString();             // Raw ICS string
$path = $icsgen->getFile('event.ics'); // Path to temp file

Common Tasks


Multiple events

// Add individually
$icsgen->events->add($event1);
$icsgen->events->add($event2);

// Or overwrite all at once
$icsgen->events->setArray([$event1, $event2]);

Save to a ProcessWire file field

$page->of(false);
$page->files_field->add($icsgen->getFile('invite.ics'));
$page->save('files_field');

Send via email

$mail = wireMail()->to($user->email)->subject('Event Invite');
$mail->attachment($icsgen->getFile(), 'invite.ics');
$mail->send();

Event property reference


Some calendar clients may not support all properties.

PropertySanitizerDescription
SUMMARYtextEvent title / headline
DTSTARTtimestampStart time (Required)
DTENDtimestampEnd time
DURATIONtextAlternative to DTEND (e.g., PT2H)
DESCRIPTIONlongtextDetailed event notes
LOCATIONtextPhysical location or address
URLuriEvent or registration website
RRULErawtextRecurrence rule (e.g., FREQ=DAILY;COUNT=10)
STATUStextTENTATIVE, CONFIRMED, CANCELLED
PRIORITYinteger1 (High) to 9 (Low)
ORGANIZERemailOrganizer email address (e.g. jsmith@host1.com or CN=John Smith:MAILTO:jsmith@host1.com)
GEOrawtextLAT;LONG (e.g., 37.38;-122.08)
UIDtextUnique identifier for the event
CLASStextPUBLIC, PRIVATE, CONFIDENTIAL
TRANSPtextTRANSPARENT (Free) or OPAQUE (Busy)
RESOURCESrawtextEquipment or rooms (e.g., Projector)
RECURRENCE-IDtimestampIdentifies a specific instance of a recurring event
DTSTAMPtimestampTime the event was created/modified in the system
CREATEDtimestampOriginal creation timestamp
LAST-MODIFIEDtimestampLast update timestamp
SEQUENCEintegerRevision sequence number
X-*rawtextCustom non-standard properties (completely unsanitized)

Timestamps


  • All timestamp inputs accept PHP DateTime objects or strings (parsed via new DateTime()).
  • All timestamp output is automatically converted to UTC (Z timestamp).

Timezones


Defaults to server timezone.

timezone event property

Will be applied to all date strings in this event:

$icsgen->events->add([
    'timezone' => new \DateTimeZone('Europe/Berlin'),
    'dtstart'  => 'now',
    'dtend'    => 'now + 60 minutes',
]);

Timezone per timestamp

When using DateTime, the timezone property above is ignored. Instead, you can define the timezone in the DateTime constructor:

$icsgen->events->add([
    'dtstart'  => new \DateTime('2033-12-24 12:00', new \DateTimeZone('Asia/Dubai')),
    'dtend'    => new \DateTime('2033-12-24 12:00', new \DateTimeZone('Europe/Paris')),
]);

Timezone via date strings

timezone property will also be ignored when string is a unix timestamp or already contains a timezone:

$icsgen->events->add([
    'dtstart'  => '@946684800',
    'dtend'    => '2010-01-28T15:00:00+02:00',
]);

Credits: Based on jakebellacera's Gist.

More modules by thausmann

  • ICS Generator

    This module can generate ICS files.
  • Minify Page Render

    This module hooks into Page::render and compresses the frontend HTML.

All modules by thausmann

Install and use modules at your own risk. Always have a site and database backup before installing new modules.