IcsGenerator by thausmann

This module can generate ICS files.

ICSGenerator

The module can generate basic ICS calendar strings and files.

The module simply extends WireData. It has these properties and default values:

$this->set('date', 'now');
$this->set('dateEnd', 'now + 60 minutes');
$this->set('summary', 'ICS Calendar File');
$this->set('description', '');
$this->set('location', '');
$this->set('url', '');
$this->set('timezone', new \DateTimeZone(date_default_timezone_get()));
  • date / dateEnd should be a PHP DateTime object or a string.
  • Date strings will be passed to DateTime constructor.
  • Date strings will use the set timezone.
  • Final output will be converted to UTC (Z timestamp)
// get the module
$icsgen = wire()->modules->IcsGenerator;

// set single properties (date strings)
$icsgen->set('date',    '2033-12-24 12:00');
$icsgen->set('dateEnd', '2033-12-24 14:00');

// set single properties (DateTime)
$icsgen->set('date',    new \DateTime('2033-12-24 12:00'));
$icsgen->set('dateEnd', new \DateTime('2033-12-24 14:00'));

// the set timezone will only impact time strings!
$icsgen->set('timezone', new \DateTimeZone('Europe/Berlin'));
$icsgen->set('date',    'now');
$icsgen->set('dateEnd', 'now + 60 minutes');

// set timezone will be ignored when string is a unix timestamp or contains a timezone
$icsgen->set('date',    '@946684800');
$icsgen->set('date',    '2010-01-28T15:00:00+02:00');

// set timezone will not impact DateTime!
// construct your DateTime with DateTimeZone instead
$icsgen->set('date',    new \DateTime('2033-12-24 12:00', new \DateTimeZone('Asia/Dubai')));
$icsgen->set('dateEnd', new \DateTime('2033-12-24 12:00', new \DateTimeZone('Europe/Paris')));

// set multiple properties at once
$icsgen->setArray(array(
    'date' => '2033-12-24 12:00',
    'dateEnd' => '2033-12-24 14:00',
    'summary' => 'Event Title',
    'description' => 'Event Description',
));

// get ICS string
$str = $icsgen->getString();

// get ICS object
$ics = $icsgen->getICS();

// get path to a temporary .ics file
// using wire()->files->tempDir
$path = $icsgen->getFile();

// get path to a temporary .ics file by ID
// this is useful if you need the same ICS multiple times in one request
// (same file id will only be created once)
$path = $icsgen->getFileByID('christmas-2033');

// example: send email with ics file
$mail = wireMail();
$mail->attachment($path, 'calendar.ics');
$mail->to($user->email);
$mail->subject('ICS Demo');
$mail->body('This is a ICS demo.');
$numSent = $mail->send();

Code is heavily based on https://gist.github.com/jakebellacera/635416 with some improvements.

PRs are open.

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

Latest news

  • ProcessWire Weekly #523
    In the 523rd issue of ProcessWire Weekly we'll check out what's new in the core this week, share some new module related news, and more. Read on!
    Weekly.pw / 18 May 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK