function calendar_get_ics_invitation_string

6.x calendar.module calendar_get_ics_invitation_string($event_title, $location, $description = "", $start_dt = 0, $end_dt = 0)

Return back an ics file (as a string) to be used as an attachment for emails, which will facilitate a calendar invitation.

Inspired from: https://gist.github.com/jakebellacera/635416/3c81643cc236a5efdf535fcbf3f...

start_dt and end_dt should look like Ymd\THis\Z (in UTC format)

2 calls to calendar_get_ics_invitation_string()
calendar_appointment_content_form_validate in modules/calendar/calendar.module
Custom validate handler for when we save an appointment form. We want to confirm the student is valid, and also store ONLY the cwid.
calendar_schedule_appointment_confirm_form_submit in modules/calendar/calendar.module
We passed validation, it's time to actually submit now!

File

modules/calendar/calendar.module, line 3482

Code

function calendar_get_ics_invitation_string($event_title, $location, $description = "", $start_dt = 0, $end_dt = 0) {
  $rtn = "";

  if ($description == "") {
    $description = $event_title;
  }
  $description = strip_tags($description);

  $description = str_replace("\r\n", "\n", $description); // Convert from windows to unix style linebreaks.
  $description = str_replace("\n", "\\n", $description); // required if we have line breaks in the description.  We have to escape the slash.
  $description = str_replace(";", "\\;", $description); // We have to escape semi-colons the same way
  $description = str_replace(",", "\\,", $description); // And commas.

  // We have to do "line folding" for the description if it is longer than 75 chars.  See: https://icalendar.org/iCalendar-RFC-5545/3-1-content-lines.html


  $rtn .= "BEGIN:VCALENDAR\n";
  $rtn .= "VERSION:2.0\n";
  $rtn .= "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\n";
  $rtn .= "CALSCALE:GREGORIAN\n";
  $rtn .= "BEGIN:VEVENT\n";
  $rtn .= "DTEND:$end_dt\n";
  $rtn .= "UID:" . md5($event_title . $start_dt . $end_dt) . "\n";
  $rtn .= "DTSTAMP:" . date("Ymd\THis\Z", time()) . "\n";
  $rtn .= "LOCATION:$location\n";
  $rtn .= "DESCRIPTION:" . calendar_ics_split("DESCRIPTION:", $description) . "\n";
  //$rtn .= "URL;VALUE=URI: http://mydomain.com/events/blah\n";
  $rtn .= "SUMMARY:$event_title\n";
  $rtn .= "DTSTART:$start_dt\n";
  $rtn .= "END:VEVENT\n";
  $rtn .= "END:VCALENDAR";


  return $rtn;
}