Page 1 of 1

Processing Calendar Feed onto Website

Posted: Fri Nov 22, 2013 11:04 am
by JimboDavies
Our management system (Administrate - www.getadministrate.com) has just released a feature that streams courses in a Calendar format (.ics). I've found various modules that publish .ics from CMS Made Simple, but I want to do something slightly different - I want to take the calendar feed from Administrate, and display the dates on CMSMS (either as a list, or in a calendar box itself, like a booking/availability system).

Assuming there isn't already a module that does this that I've missed, is this something that's feasible? Are any developers already working on something like this?

Re: Processing Calendar Feed onto Website

Posted: Fri Nov 22, 2013 11:18 am
by JohnnyB
I would try some PHP in a User Defined Tag. Something like this parser could help get the data needed to create a list of events from your .ics file:

http://code.google.com/p/ics-parser/

Save the class.iCalReader.php file in your CMSMS installation path and then call it from the UDT like the example provided here:
http://code.google.com/p/ics-parser/sou ... vn%2Ftrunk

Re: Processing Calendar Feed onto Website

Posted: Sat Nov 23, 2013 8:51 pm
by JimboDavies
Cheers JohnnyB, that's a great help.

It seems all our calendars have to be authenticated by a user, and most usernames are an e-mail address, so that's something I'm going to have to work on - I thought if you replaced @ with + in the e-mail address that might work, but it doesn't seem to. Back to the drawing board!

Re: Processing Calendar Feed onto Website

Posted: Sat Nov 23, 2013 8:54 pm
by JimboDavies
Fixed it! %40....

Re: Processing Calendar Feed onto Website

Posted: Tue Nov 26, 2013 2:36 pm
by JimboDavies
So, I've deposited class.iCalReader.php into my cmsms site, and set up a user defined tag. In the interests of simplicity, my UDT produces quite a stripped down version of the results, and it looks like:

Code: Select all

require '../class.iCalReader.php';

$calendar = isset($params['calendar']) ? $params['calendar'] : '1';  
$ical = new ICal('https://USERNAME:PASSWORD@stormforce.administrateapp.com/cal/' . $calendar . '.ics');
$events = $ical->events();

foreach ($events as $event) {
    echo "SUMMARY: ".$event['SUMMARY']."<br/>";
    echo "DTSTART: ".$event['DTSTART']." - UNIX-Time: ".$ical->iCalDateToUnixTimestamp($event['DTSTART'])."<br/>";
    echo "DTEND: ".$event['DTEND']."<br/>";
    echo "DESCRIPTION: ".$event['DESCRIPTION']."<br/>";
    echo "LOCATION: ".$event['LOCATION']."<br/>";
    echo "<hr/>";
}
This enables me to set which calendar I want in a variable, and if I don't, obviously it will generate calendar number 1 (the Administrate system generates each calendar as a number, from 1 upwards).

If I test run the UDT I get:
SUMMARY: PB L2 RYA Powerboat Level 2 / ICC<br/>DTSTART: 20131130T093000Z - UNIX-Time: 1385803800<br/>DTEND: 20131130T170000Z<br/>DESCRIPTION: Event Type: Public\n\nRegistrations: None / 6\n\nResources: None booked to this event.<br/>LOCATION: Base - Shamrock Quay<br/><hr/>
And this repeats itself for each event - great! So, my test works.

When I call the UDT in a page content, I get nothing. It breaks the page content (so it breaks out of the stylesheet & template) and occasionally generates  symbols on the page.

Any thoughts on where I'm going wrong?

Re: Processing Calendar Feed onto Website

Posted: Tue Nov 26, 2013 3:50 pm
by velden
To start: maybe don't use relative paths in UDT.

Admin runs from: <webroot>/<admin>/index.php where frontend runs from: <webroot>/index.php.

For example in a UDT I use this code to get the UPLOADS_path value:

Code: Select all

$gCms = cmsms();
  $uploadspath = $gCms->config['uploads_path'];
Don't know how to get the root_path but I would try 'root_path' :)

Re: Processing Calendar Feed onto Website

Posted: Tue Nov 26, 2013 4:00 pm
by JimboDavies
Velden... 8)

One simple error. Works great now - I can pull what I want from the .ics feed, and now work on displaying and styling it how I want.

Brilliant, cheers.

Re: Processing Calendar Feed onto Website

Posted: Thu Dec 05, 2013 3:12 pm
by JimboDavies
Ok, so my calendar feed publishes the events, and I can customise them however I like which is great.

Newbie question though - it produces dates in a string format, that looks like "DTSTART: 20140210T093000Z" I can also use the inbuilt parser to convert them to a UNIX Time string, which generates "UNIX-Time: 1392024600".

Can anyone offer some guidance on how to take this strings and translate them into time, day, date, month, and year - i.e. make the one above render as 09:30, Saturday 1st February 2014 or similar.

Re: Processing Calendar Feed onto Website

Posted: Thu Dec 05, 2013 3:38 pm
by velden

Re: Processing Calendar Feed onto Website

Posted: Thu Dec 05, 2013 8:25 pm
by JimboDavies
Thanks Velden.

I am running this calendar feed into various items on the 'Products' module.

My UDT now looks like this:

Code: Select all

require 'class.iCalReader.php';

$course = isset($params['course']) ? $params['course'] : 'Course Enquiry';
$calendar = isset($params['calendar']) ? $params['calendar'] : '1';  
$ical = new ICal('https://USERNAME:PASSWORD@stormforce.administrateapp.com/cal/' . $calendar . '.ics');
$events = $ical->events();

foreach ($events as $event) {
    echo "<p>";
    echo "".date('H:i l jS F Y',$ical->iCalDateToUnixTimestamp($event['DTSTART']))." at ";
    echo $event['LOCATION'];
    echo "<span style='float: right;'><a href='mailto:coaching@stormforce.biz?Subject=". $course ." on ".date('l jS F Y',$ical->iCalDateToUnixTimestamp($event['DTSTART']))."'>Click to e-mail us about this course</a></span>";
    echo "</p>";
}
For various reasons the parameter of 'course' is passed to it as product_name. The parameter of 'calendar' is passed to it from the Product Manager itself - this is a custom field I have. The Product Manager code is:

Code: Select all

{if $entry->fields.iCalNo->value}
<h3>View available dates and send a booking e-mail:</h3>
{displaycal calendar="{$entry->fields.iCalNo->value}" course="{$entry->product_name}"}
{/if}
This comes out quite nicely - it pulls the correct calendar feed in, and displays it as an (almost) workable template. I've put it on one of our lesser viewed products to test how it plays with the Products module - you can see that at http://www.stormforce.biz/Products/84/RYA-Radar.html

You can also see that at the bottom of the page, in the 'cart' section, we get:
Notice: Undefined variable: smsrty in /home/storm/public_html/lib/classes/module_support/modtemplates.inc.php on line 237

Notice: Trying to get property of non-object in /home/storm/public_html/lib/classes/module_support/modtemplates.inc.php on line 237
This only comes up when my UDT is invoked. If the UDT isn't called, I don't get these errors. Likewise, if I integrate my UDT into a page that isn't a product, it's fine.

Any ideas what I've done wrong?

Re: Processing Calendar Feed onto Website

Posted: Thu Dec 05, 2013 9:06 pm
by velden
Notice: Undefined variable: smsrty in /home/storm/public_html/lib/classes/module_support/modtemplates.inc.php on line 23
No idea why and how, but it looks like a typo in the core file /lib/classes/module_support/modtemplates.inc.php

$smsrty should be $smarty I guess. But how that got corrupted...?

Re: Processing Calendar Feed onto Website

Posted: Fri Dec 06, 2013 4:09 am
by chandra
Some ftp programs like Filezilla are known to make files corrupt.

Re: Processing Calendar Feed onto Website

Posted: Fri Dec 06, 2013 8:58 am
by JimboDavies
Interesting. I've modified that to smarty, and it all works.

Not sure how that can have been corrupted (I haven't been anywhere near that file) - looks more like a typo.

Weird that it only comes up when that UDT is pulled in.

Ah well, all up and running! Thanks for all your help guys.