Skip to content

Instantly share code, notes, and snippets.

@ronnieduke
Created May 1, 2014 22:52
Show Gist options
  • Save ronnieduke/98e69f8fd730b1568591 to your computer and use it in GitHub Desktop.
Save ronnieduke/98e69f8fd730b1568591 to your computer and use it in GitHub Desktop.
Create iCal files from Mura Events - **Note: some variables in these functions reference extended attributes in the event nodes themselves and will need to be created or altered to make the methods work
<cffunction name="onAfterPageEventSave" output="true">
<cfargument name="$" required="true" hint="mura scope" />
<cfset cfcpath1 = Replace($.siteConfig('themeAssetPath'), "/", ".", "all")>
<cfset cfcpath = Replace(cfcpath1, ".", "")>
<cfscript>
var cBean = $.getBean('content').loadBy(contentID=$.content().getContentID());
var event = StructNew();
var loc = '';
// make sure an ics folder exists in your theme
var filepath = ExpandPath('#$.siteConfig('themeAssetPath')#') & "/ics";
event.startTime = cBean.getDisplayStart();
event.endTime = cBean.getDisplayStop();
event.organizerName = 'John Doe';
event.organizerEmail = '[email protected]';
event.description = cBean.getSummary();
event.subject = cBean.getTitle();
event.priority = 1;
</cfscript>
<!---
ICS Stuff
========================================== --->
<cfsavecontent variable="loc"><cfoutput>
#cBean.getEventAddressName()#<br>
#cBean.getEventAddress1()#<br>
Buliding #cBean.getEventBuilding()#, Room #cBean.getEventRoom()#<br>
#cBean.getEventCity()#, #cBean.getEventState()# #cBean.getEventZip()#</cfoutput>
</cfsavecontent>
<cfset event.location = loc>
<cfset var fileoutput = "#filepath#/#cBean.getContentID()#.ics">
<cfset var result = iCalUS(stEvent=event)>
<cfif NOT DirectoryExists(filepath)>
<cfdirectory action="create" directory="#filepath#">
</cfif>
<cfif FileExists(fileoutput)>
<cffile action="delete" file="#fileoutput#">
</cfif>
<cffile action="write" file="#fileoutput#" output="#result#">
</cffunction>
<!--- /onAfterPageEventSave --->
<!---
This library is part of the Common Function Library Project. An open source
collection of UDF libraries designed for ColdFusion 5.0 and higher. For more information,
please see the web site at:
http://www.cflib.org
Warning:
You may not need all the functions in this library. If speed
is _extremely_ important, you may want to consider deleting
functions you do not plan on using. Normally you should not
have to worry about the size of the library.
License:
This code may be used freely.
You may modify this code as you see fit, however, this header, and the header
for the functions must remain intact.
This code is provided as is. We make no warranty or guarantee. Use of this code is at your own risk.
--->
<!---
/**
* Pass a formatted structure containing the event properties and get back a string in the iCalendar format (correctly offset for daylight savings time in U.S.) that can be saved to a file or returned to the browser with MIME type=&quot;text/calendar&quot;.
* v2 updated by Dan Russel
*
* @param stEvent Structure of data for the event. (Required)
* @return Returns a string.
* @author Troy Pullis ([email protected])
* @version 2, December 18, 2008
*/
--->
<cffunction name="iCalUS" output="false" access="public" returntype="any">
<cfargument name="stEvent" type="any" required="true">
<cfscript>
var vCal = "";
var CRLF = chr(13) & chr(10);
var date_now = Now();
var eventDesc = stEvent.description;
var eventDesc = REReplaceNoCase(eventDesc,"<[^>]*>","","ALL");
var eventSummary = stEvent.subject;
var eventSummary = REReplaceNoCase(eventSummary,"<[^>]*>","","ALL");
vCal = "BEGIN:VCALENDAR" & CRLF;
vCal = vCal & "PRODID: -//CFLIB.ORG//iCalUS()//EN" & CRLF;
vCal = vCal & "VERSION:2.0" & CRLF;
vCal = vCal & "METHOD:REQUEST" & CRLF;
vCal = vCal & "BEGIN:VTIMEZONE" & CRLF;
vCal = vCal & "TZID:Eastern Time" & CRLF;
vCal = vCal & "BEGIN:STANDARD" & CRLF;
vCal = vCal & "DTSTART:20061101T020000" & CRLF;
vCal = vCal & "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11" & CRLF;
vCal = vCal & "TZOFFSETFROM:-0400" & CRLF;
vCal = vCal & "TZOFFSETTO:-0500" & CRLF;
vCal = vCal & "TZNAME:Standard Time" & CRLF;
vCal = vCal & "END:STANDARD" & CRLF;
vCal = vCal & "BEGIN:DAYLIGHT" & CRLF;
vCal = vCal & "DTSTART:20060301T020000" & CRLF;
vCal = vCal & "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3" & CRLF;
vCal = vCal & "TZOFFSETFROM:-0500" & CRLF;
vCal = vCal & "TZOFFSETTO:-0400" & CRLF;
vCal = vCal & "TZNAME:Daylight Savings Time" & CRLF;
vCal = vCal & "END:DAYLIGHT" & CRLF;
vCal = vCal & "END:VTIMEZONE" & CRLF;
vCal = vCal & "BEGIN:VEVENT" & CRLF;
vCal = vCal & "UID:#date_now.getTime()#.CFLIB.ORG" & CRLF; // creates a unique identifier
vCal = vCal & "ORGANIZER;CN=#stEvent.organizerName#:MAILTO:#stEvent.organizerEmail#" & CRLF;
vCal = vCal & "DTSTAMP:" &
DateFormat(date_now,"yyyymmdd") & "T" &
TimeFormat(date_now, "HHmmss") & CRLF;
vCal = vCal & "DTSTART;TZID=Eastern Time:" &
DateFormat(stEvent.startTime,"yyyymmdd") & "T" &
TimeFormat(stEvent.startTime, "HHmmss") & CRLF;
vCal = vCal & "DTEND;TZID=Eastern Time:" &
DateFormat(stEvent.endTime,"yyyymmdd") & "T" &
TimeFormat(stEvent.endTime, "HHmmss") & CRLF;
vCal = vCal & "SUMMARY:#eventSummary#" & CRLF;
vCal = vCal & "LOCATION:#stEvent.location#" & CRLF;
vCal = vCal & "DESCRIPTION:#eventDesc#" & CRLF;
vCal = vCal & "PRIORITY:#stEvent.priority#" & CRLF;
vCal = vCal & "TRANSP:OPAQUE" & CRLF;
vCal = vCal & "CLASS:PUBLIC" & CRLF;
vCal = vCal & "BEGIN:VALARM" & CRLF;
vCal = vCal & "TRIGGER:-PT30M" & CRLF; // alert user 30 minutes before meeting begins
vCal = vCal & "ACTION:DISPLAY" & CRLF;
vCal = vCal & "DESCRIPTION:Reminder" & CRLF;
vCal = vCal & "END:VALARM" & CRLF;
vCal = vCal & "END:VEVENT" & CRLF;
vCal = vCal & "END:VCALENDAR";
return Trim(vCal);
</cfscript>
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment