One of the features I find it interesting in Google calendar is the possibility to create shared calendars, but also the availability of your calendar as XML or ICAL whatever it's a private or public one. As soon as we have XML of our calendar available I was wondering why not integrating Google calendar directly in website. For example a community that use the service to manage their events, or to display your future trips in your blog ?
First of all I jumped the cross-domain AJAX story since I'm reading data from Google server, I simply written a small PHP script which will read the feeds and resend it again. Then I used my old AJAX RSS Reader, Google calendar don't deliver RSS but it's just XML, it's not a big deal there is just few changes on the code the make it working.
- // Change this with your Google calendar feed
- $calendarURL = 'http://www.google.com/calendar/feeds/';
- // Nothing else to edit
- $feed = file_get_contents($calendarURL);
- header('Content-type: text/xml');
- echo $feed;
- // Parsing Feeds
- var node = RSSRequestObject.responseXML.documentElement;
- // Get the calendar title
- var title = node.getElementsByTagName('title').item(0).firstChild.data;
- content = '<div class="channeltitle">'+title+'</div>';
- // Browse events
- var items = node.getElementsByTagName('entry');
- if (items.length == 0) {
- content += '<ul><li><div class=error>No events</div></li></ul>';
- } else {
- content += '<ul>';
- for (var n=items.length-1; n >= 0; n--)
- {
- var itemTitle = items[n].getElementsByTagName('title').item(0).firstChild.data;
- var Summary = items[n].getElementsByTagName('summary').item(0).firstChild.data;
- var itemLink = items[n].getElementsByTagName('id').item(0).firstChild.data;
- try
- {
- var itemPubDate = '<font color=gray>['+items[n].getElementsByTagName('published').item(0).firstChild.data+'] ';
- }
- catch (e)
- {
- var itemPubDate = '';
- }
- content += '<li>'+itemPubDate+'</font><a href="'+itemLink+'">'+itemTitle+'</a></li>';
- }
- content += '</ul>';
- }
No comments:
Post a Comment