Processing Calendar Feed onto Website
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Processing Calendar Feed onto Website
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?
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
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
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
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Processing Calendar Feed onto Website
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!
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!
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Processing Calendar Feed onto Website
Fixed it! %40....
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Processing Calendar Feed onto Website
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:
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:
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?
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/>";
}
If I test run the UDT I get:
And this repeats itself for each event - great! So, my test works.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/>
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
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:
Don't know how to get the root_path but I would try 'root_path' 
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'];

-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Processing Calendar Feed onto Website
Velden...
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.

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.
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Processing Calendar Feed onto Website
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.
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.
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Processing Calendar Feed onto Website
Thanks Velden.
I am running this calendar feed into various items on the 'Products' module.
My UDT now looks like this:
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:
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:
Any ideas what I've done wrong?
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>";
}
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}
You can also see that at the bottom of the page, in the 'cart' section, we get:
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.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
Any ideas what I've done wrong?
Re: Processing Calendar Feed onto Website
No idea why and how, but it looks like a typo in the core file /lib/classes/module_support/modtemplates.inc.phpNotice: Undefined variable: smsrty in /home/storm/public_html/lib/classes/module_support/modtemplates.inc.php on line 23
$smsrty should be $smarty I guess. But how that got corrupted...?
Re: Processing Calendar Feed onto Website
Some ftp programs like Filezilla are known to make files corrupt.
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Processing Calendar Feed onto Website
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.
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.