Cant get rss ticker to work with google calander

Asked by Keith Burtt

I have been trying to get the rss ticker to work with Google calendar. I use the xml rss http://www.google.com/calendar/feeds/ford.plymouth.sch.uk_fcbr34ae6jag4pah8oogd7id50%40group.calendar.google.com/public/basic it is a public rss as our parent use it to look at the calander. It is on a windows platform but nothing seems to happen. I have tested the ticker with the xibo feed and it works fine I didnt know if I need to change the tags [title] [discription] etc. any help would be grateful.

Question information

Language:
English Edit question
Status:
Solved
For:
Xibo Edit question
Assignee:
No assignee Edit question
Solved by:
Keith Burtt
Solved:
Last query:
Last reply:
Revision history for this message
Jonathan Pearce (jpearce11) said :
#1

The xml feed that google calendar kicks out doesn't conform to the standard as it has extra data in it.

I use a script called gcalendar.php to strip this out and provide an html output that can be used by xibo. I embed the php script in an iframe as embedded html.

Revision history for this message
Keith Burtt (alonebfg) said :
#2

Have you got a basic howto on this as I am not familiar with PHP am a school network manager have got everything working just not this bit and is driving me mad. Where do i put the gcalander.php script ??
Thanks for your quick response.

Revision history for this message
Jonathan Pearce (jpearce11) said :
#3

Go here http://james.cridland.net/code/google-calendar.html
Copy the script into a file named gcalendar.php
Edit the script so that it is correctly configured for your calendar - the comments in the script are your instructions.
Don't use the cache, you'll probably have more trouble than it is worth.

Save the edited gcalendar.php into a folder on your webserver.
Then call the script by embedding it in an iframe - google will help you.

Revision history for this message
James Doring (doringj) said :
#4

I have a Google calendar as an RSS ticker using this format: https://<email address hidden>/public/basic?alt=rss&futureevents=true&ctz=America/New_York&orderby=starttime&sortorder=ascending&max-results=5

But I also had to minify the URL because I don't think XIBO likes some of the characters in the URL. So I use this as my link: http://goo.gl/x2R6j and it seems to work, although the format of the feed is inflexible. In particular, I cannot get rid of "status: confirmed" portion of each event. But it's a small price to pay. You could use an internal PHP page to parse the results.

Revision history for this message
Keith Burtt (alonebfg) said :
#5

ok I thought I should update on this. I have it working Its very dirty way of doing it. I downloaded simplepie.inc as well as jquery.newsScroll.js and
jquery.newsScroll_comments.js I then created a php file
<?php

require 'simplepie.inc';
function shorten($string, $length)
{
    // By default, an ellipsis will be appended to the end of the text.
    $suffix = '&hellip;';

    // Convert 'smart' punctuation to 'dumb' punctuation, strip the HTML tags,
    // and convert all tabs and line-break characters to single spaces.
    $short_desc = trim(str_replace(array("\r","\n", "\t"), ' ', strip_tags($string)));

    // Cut the string to the requested length, and strip any extraneous spaces
    // from the beginning and end.
    $desc = trim(substr($short_desc, 0, $length));

    // Find out what the last displayed character is in the shortened string
    $lastchar = substr($desc, -1, 1);

    // If the last character is a period, an exclamation point, or a question
    // mark, clear out the appended text.
    if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';

    // Append the text.
    $desc .= $suffix;

    // Send the new description back to the page.
    return $desc;
}
// Create a new class that extends an existing class
class SimplePie_Item_Extras extends SimplePie_Item {
    var $show_past_events = TRUE;

 function set_show_past_events($value = FALSE){
  $this->show_past_events = $value;
 }
 /**
 This is an example of adding a new method to an existing class
 */

// function check_url($url_to_check){
// $tmp = str_replace("/basic","/full",$url_to_check);
// if(!strpos($tmp,'?'))
// $tmp = $this->append($tmp,"?")

// else{
// if(!(substr($tmp, -1) === '&'))
// $tmp = $this->append($tmp,'&');
// }
// if($this->show_past_events)
// $tmp = $this->append($tmp,'futureevents=false&');
// else
// $tmp = $this->append($tmp,'futureevents=true&');
// if($this->sort_ascending)
// $tmp = $this->append($tmp,'sortorder=ascending&');
// else
// $tmp = $this->append($tmp,'sortorder=descending&');
// if($this->orderby_by_start_date)
// $tmp = $this->append($tmp,'orderby=starttime&');
// else
// $tmp = $this->append($tmp,'orderby=lastmodified&');
// if($this->expand_single_events)
// $tmp = $this->append($tmp,'singleevents=true&');
// else
// $tmp = $this->append($tmp,'singleevents=false&');
// return $tmp;
// }
 // Retrieve the <gd:when startTime="" /> value.
 function get_gcal_starttime($format = false)
 {
  // We want to grab the Google-namespaced <gd:when> tag.
  // http://simplepie.org/wiki/tutorial/grab_custom_tags_or_attributes
  $when = $this->get_item_tags('http://schemas.google.com/g/2005', 'when');

  // Once we grab the tag, let's grab the startTime attribute
  $date = $when[0]['attribs']['']['startTime'];

  if ($format)
  {
   // Let's pass it through strtotime() and then format it with date(). This will be the date we display.
   return date($format, strtotime($date));
  }
  else
  {
   // Otherwise we'll return it as-is with no modifications.
   return $date;
  }
 }
 function get_gcal_endtime($format = false)
 {
  // We want to grab the Google-namespaced <gd:when> tag.
  // http://simplepie.org/wiki/tutorial/grab_custom_tags_or_attributes
  $when = $this->get_item_tags('http://schemas.google.com/g/2005', 'when');

  // Once we grab the tag, let's grab the startTime attribute
  $date = $when[0]['attribs']['']['endTime'];

  if ($format)
  {
   // Let's pass it through strtotime() and then format it with date(). This will be the date we display.
   return date($format, strtotime($date));
  }
  else
  {
   // Otherwise we'll return it as-is with no modifications.
   return $date;
  }

 }
 function get_gcal_where()
 {
  // We want to grab the Google-namespaced <gd:when> tag.
  // http://simplepie.org/wiki/tutorial/grab_custom_tags_or_attributes
  $where = $this->get_item_tags('http://schemas.google.com/g/2005','where');

 // Once we grab the tag, let's grab the startTime attribute
  return $where[0]['attribs']['']['valueString'];

 }
 /**
 This is an example of modifying an existing method of an existing class.
  */

 function get_id()
 {
  return $this->__toString();
 }

}
$feed = new SimplePie();
$feed->set_feed_url('http://www.google.com/calendar/feeds/ford.plymouth.sch.uk_fcbr34ae6jag4pah8oogd7id50%40group.calendar.google.com/private-9b334582e4341761e0cc732328184757/full?futureevents=false');
$feed->handle_content_type();
$feed->set_item_class('SimplePie_Item_Extras');
$feed->init();
$feed->handle_content_type();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" charset="utf-8" />
<title>Super Duper News Scroller</title>
</head>

<body>

<div id="container">
  <ul id="widget">
   <?php foreach($feed->get_items(0, 15) as $item) : ?>
   <li>
    <h4><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>
    <p>
     Date <?php echo $item->get_gcal_starttime('j F Y'); ?><br>
     Time <?php if($item->get_gcal_starttime('h:i') =='12:00'){echo "all day";}
     else
     {echo $item->get_gcal_starttime('H:i');echo' - ';echo $item->get_gcal_endtime('H:i');}?><br>
     <?php if($item->get_gcal_where() == ""){echo '';}
     else
     {echo "Location ";echo $item->get_gcal_where();echo nl2br("\r\n");}?>
     Event <?php echo shorten($item->get_content(),50); ?><br>
    </p>
   </li>
   <?php endforeach; ?>
  </ul>
</div><!--end container-->

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.newsScroll.js"></script>

<script type="text/javascript">
 $('#widget').newsScroll({
  speed: 2000,
  delay: 7000
 });

 // or just call it like:
 // $('#widget').newsScroll();
</script>

</body>
</html>

This seems to work I put in a bit of css and embeded it into the xibo and it works like a charm there is a error about strict in php but i just switched the disply errors off. I hope this helps anyone else that wants to scroll dates. Have also fixed it so that it displays all day and not a big time.

Revision history for this message
JonyGreen (jonygreen) said :
#6

i find a free online service to minify js http://www.online-code.net/minify-js.html and compress css http://www.online-code.net/minify-css.html, so it will reduce the size of web page.