Google Calendar Widget

Note: This widget does NOT work with WordPress 2.1 and up. Don’t bother trying.

————

I created a new widget for my blog. It’s a simple little thing that shows stuff from my Google Calendar. You can find it as my “Upcoming Events” sidebar, bottom left. Okay, so it doesn’t have much there yet, I need to add stuff to the calendar. )

Anyway, here’s a link to it: gcalendar

If anybody has any suggestions on improving it, I’d love to hear ‘em.

——–

Note: I’ve updated the widget to use Google’s Calendar API properly. But in order to do that, I had to modify WordPress’s built in MagpieRSS functions rather heavily. So read the readme.txt file for installation instructions before attempting to use it. Failure to install correctly will break your blog. Heck, it might do that anyway. So read carefully. )

This entry was posted in Geekery, General Spew, Programmery, Thingery. Bookmark the permalink.

0 Responses to Google Calendar Widget

  1. Pingback: 30boxes Widget » Nothing to see here

  2. Matt says:

    Hi Otto – I believe there was a comment up here addressing this at some point, but is there a way to extract the Description field as well? If you could repost that info I’d definitely appreciate it.

    Thanks for all your work!

  3. bboy says:

    @Matt: Thought it was done adding echo $stuff[$iter]['content'];afterecho $stuff[$iter]['title'];in gcalendar.php, but please someone correct me if I’m wrong.I also changed both to:echo htmlentities($stuff[$iter]['title']);echo htmlentities($stuff[$iter]['content']);which took care of some accentuated letter problems I had.Cheers!

  4. bboy says:

    @Matt: Thought it was done adding

    echo $stuff[$iter]['content'];
    after
    echo $stuff[$iter]['title'];

    in gcalendar.php, but please someone correct me if I’m wrong.
    I also changed both to:

    echo htmlentities($stuff[$iter]['title']);
    echo htmlentities($stuff[$iter]['content']);

    which took care of some accentuated letter problems I had.

    Cheers!

  5. Arturo says:

    Hello,

    Thanks for this widget.

    After install it as a widget I get the following error

    Warning: Invalid argument supplied for foreach() in /home/.keanu/cambalache/cambalachemadrid.com/wp/wp-content/plugins/widgets/gcalendar.php on line 166

    Some tip?

    Thanks in advance

  6. Seth says:

    Otto,

    Love the widget; is there a way to control how often it updates? My events are often out of date.

  7. Otto says:

    Seth, it updates once an hour at most. The only way to change this is to modify the rss-functions.php file, because that is built in.

  8. Seth says:

    If you look at my site, you will see the calendar info in the right margin; the dates are up-to-date now, but events that have passed sometimes take almost 24 hours to “fall off” the top of the list.

  9. Otto says:

    I don’t know what to tell you. The code says 60 minutes. Unless you’re using WP-Cache or something, it’ll update once an hour (depending on traffic to your site, of course).

    The relevant piece of code is in rss-functions.php. Search that file for “MAGPIE_CACHE_AGE”. Now, that value can be overriden by something else anywhere in your WordPress system, but my plugin does not override it.

  10. Jess says:

    THANK YOU so much! I’ve spent quite a bit of time trying to get a Google Calendar feed to work on the sidebar of my WordPress blog… but because I am on Dreamhost, most of the plugins gave me an error because of Dreamhost’s security measures with the getfunction (I’m not very technical here, sorry). Yours is the first that I’ve gotten to work and it is indeed loverly and straightforward, so thank you thank you thank you.

  11. Adam says:

    Thank you very much Otto. I had Arturo’s same problem in PHP 4.

    Adding an if (is_array($stuff)){…} check around the foreach loop will fix the error.

    New lines 442-452:

    if (is_array($stuff)) {
    foreach ($stuff as $item)
    {
    $itemdate = getdate($item['date']);
    if ($itemdate['mday'] == $day)
    { // found one
    $todaysItems[$i]=$item;
    $i++;
    }
    }
    }

  12. Torley says:

    Hiya! Who’s currently using Otto’s Google Calendar Widget? I don’t see it on this blog; I’m interested in seeing some actual examples of usage — please provide URLs. Thanx in advance!

  13. Torley says:

    Hiya! Who’s currently using Otto’s Google Calendar Widget? I don’t see it on this blog; I’m interested in seeing some actual examples of usage — please provide URLs. Thanx in advance!

  14. Murad says:

    can we have the date apearance format on the side bar like

    Month

    Startday – FinishDay EventName

    now it shows only start day.

    Murad

  15. Boris says:

    Great! Exactely what I needed for our conference!

  16. Scott says:

    Otto/Adam, I had the same problem as Arturo did (“Invalid argument supplied for foreach()” @ line 166). Tried Adam’s fix but no joy… any other possibilities?

    Thanks

  17. Bob says:

    Otto I installed Gcalendar on my new blog and it is working great. I have WordPress 2.1 and want to install the Mighty Seek Podcast Plugin and was wondering is your rss-functions.php causes problems for any other app that sends or receives RSS.

    Thanks for the Great App!

  18. gryphonent says:

    Installed as advised… get the same error as Arturo and the suggested fix doesn’t do anything.

  19. John V says:

    love the calendar, using it as a plugin (not a widget, though not for any particular reason other than I haven’t used widgets yet). The tooltip is displaying wrong, I assume. it’s causing jitter in Firefox in the whole sidebar. Is there a way to fix this? It also doesn’t seem to be getting the size or color information from the provided CSS (lightyellow & 150)in Firefox or (shudder) IE7.

  20. John V says:

    nevermind, figured it out… it was the copyright symbol in the tooltip script.

  21. Fred Greco says:

    Has anyone confirmed whether this conflicts with Mighty Seek’s Podcast plugin?

  22. Ken Martin says:

    Is there any chance that a future version could: [a] optionally include a direct link to the google calendar (link and link title), and [b] optionally include the small calendar view above or below the list of events (so, show both). Even if not, wonderful plug-in… thanks! :)

  23. Mikael says:

    Any ideas or experience out there how this plugin could be best included on a password-protected page?

    The password protection only protects the content area of the page, so PHP code included in the page template is not protected.

    The PHP execution plugins available seem a bit iffy when used with the rich text exitor.

  24. Bob Wood says:

    I had GCalendar working great for about a month. I just upgraded my WP install to version 2.1.l and now the Widget still shows on the page with “My Claendar” written on top but there is no info showing below the title. Anyone have any ideas?

    Wanted to warn others about the install of WP 2.1.1

    Thanks!

  25. Mikael says:

    Added the following to the end of the gcalendar.php file. Inserting the comment tag to the page content now includes a list of events on that page.

    function add_calendar_to_content($content)
    {
    $tag_for_list = ‘‘;
    // see whether the calendar should be included on this page
    $pos = strpos($content, $tag_for_list);

    if ($pos === false)
    {
    // tag wasn’t found, so leave the content alone
    return $content;
    }
    else
    {
    $calendar_content = widget_do_gcalendar(‘http://www.google.com/calendar/feeds/… blah blah …/basic’,50,’today’,'today + 1 year’,”,’j\.n\.Y\: ‘,true,false);

    return str_replace($tag_for_list, $calendar_content, $content);
    }
    }

    // Add a HTML comment tag for placing calendar in the content – hardwired parameters
    add_filter(‘the_content’, ‘add_calendar_to_content’);

  26. Mikael says:

    Oops. Here’s the correct code. You also need to reactivate the plugin to get this working.

    function add_calendar_to_content($content)
    {
    $tag_for_list = ‘‘;
    $tag_for_calendar = ‘‘;
    // see whether the calendar should be included on this page
    $pos = strpos($content, $tag_for_list);

    if ($pos === false)
    {
    // tag wasn’t found, so leave the content alone
    return $content;
    }
    else
    {
    $calendar_content = widget_do_gcalendar(‘http://www.google.com/calendar/feeds/… blah blah …/basic’,50,’today’,'today + 1 year’,”,’j\.n\.Y\: ‘,true,false);

    return str_replace($tag_for_list, $calendar_content, $content);
    }
    }

    // Add a HTML comment tag for placing calendar in the content – hardwired parameters
    add_filter(‘the_content’, ‘add_calendar_to_content’);

  27. vanessa says:

    hey, great widget! thanks!!

  28. Pingback: Ubuntu NY - LoCo Team Blog » Interesting little note

  29. Bart Simpson says:

    I appreciate all the hard work you put into this, but it sure would help when people create a plugin that they link to an example or two of the thing working. Having to download it, activiate and make it live before seeing what it does is too cumbersome.

  30. Jonathan says:

    Otto/Adam, I too am having the same php 4 problem and the hack isn’t working. Here’s what I changed
    in the code:

    if (is_array($stuff)) {
    foreach ($stuff as $item)
    {
    $itemdate = getdate($item['date']);
    if ($itemdate['mon'] == $thismonth)
    {
    $newstuff[$i]=$item;
    $i++;
    }
    }
    }

    I noticed that the code is slightly different from what Adam had previously shown. I’m not well gifted
    in code and didn’t know if that made a difference.

    Any help would be great as I’m doing this as a volunteer for my church.

  31. Pingback: My ma.gnolia bookmarks for March 14th through March 15th » Interweb World

  32. Pingback: Web Worker Daily » Blog Archive Rock Your Google Calendar in 18 Ways «

  33. Pingback: PoliticalWarez

  34. Pingback: » Blog Archive » Google Agenda/ Calendar Top 10 Tips

  35. Pingback: Guida a Google Calendar | Googlisti.com

  36. Christopher says:

    Hi.
    Thanx for the nice plugin!
    Just wanted to let you know, I had to replace the line
    $stuff[$count]['title']=$row["title"];
    with
    $stuff[$count]['title']=htmlentities($row["title"]);
    to make it display German special characters (ÄÖÜß) in the titles correctly.

  37. gcal says:

    Is there a way to have the user change the month they view? Examaple have a forward and backward button above the calendar to change months?

  38. sadly says:

    no comments about the foreach error? no solutions. unfortunately, a nonworking plugin for a variety of people.

  39. Otto says:

    The foreach error means, basically, that it could not retrieve your feed. Sorry, I’ve kinda slacked off on development for this since I’m working on the picasa widget again.

  40. biohazr says:

    Otto is correct, the foreach problem is because the widget don’t found the feed whith the calendar.

    Why? because php 4.0 change the order getting the widget params and stores the feed url in $option['title'] and the title in $option['feed'] so when the script tries to retieve the feed you get the foreach error because it isn’t a xml archive to browse and get the events.

    So, you have to change the code (lines 129-130):
    $title = $options['title'];
    $basicfeed = $options['feed'];

    with this:
    $title = $options['feed'];
    $basicfeed = $options['title'];

    I know that diferent versions of php changes the order of getting params in a function is a crazy idea but it really works!

  41. dersimli says:

    Nice Widget… i like it..

  42. Ken Martin says:

    Hello. Ken from comment #19. :)

    I was just checking back to see if there were any updates. I made a couple of hacks to a copy of this plug in to add the link to the whole calendar (which I’d requested above), and I added a conditional so that all day events (which currently show up as starting at midnight) do not show a time at all. I’m testing for midnight, so if you actually had a midnight event, my hack won’t work for you. Otto, let me know if you care to see the hacks.

    Thanks for the great plug-in! :)

  43. Ryan says:

    I’m having some trouble having the widget show the correct amount of list items. On my site, I want the list to show 6 items, but it is showing all items for the time span. Any ideas on how to fix this?

  44. Jim says:

    Yes, I’m having the same problem as Ryan. I’ll keep working at it, but so far it’s showing the LONG list of items, not just the number I specify. Otherwise, seems to work well!

  45. Asphodeli says:

    Whoops, words spoken too soon…it was working until I added an event in Google Calendar and now it went nuts…

  46. Pingback: Wordpress + Google Calendar at xijio::blog

  47. bamboo says:

    Got the same foreach trouble, at several lines, i’ve tried everything told here, and it don’t work… Hope that there will be a solution one day ! Thanks for your work

  48. Pingback: kate’s infrastructure » Wordpress to Wordpress migration success

  49. Pingback: WordPress Plugins Database » Plugin Details » Google Calendar widget

  50. Brian Niece says:

    Are you going to update this widget for use in WP 2.2?

  51. Otto says:

    Brian: Probably not anytime soon, no. WordPress has been damnably slow in revamping their RSS reader support. I’ve been trying to introduce better code into the WordPress core so that the rss-functions hacking is not required, but I’m not having much luck.

  52. carl says:

    Sorry if people have asked this before me. But does the new WP 2.3 version change the situation, in terms of updating this plugin? If maybe the rss-support have improved or something like that?
    thanks

  53. Björn says:

    Would like to know that too :-)

  54. Pingback: Ricevere al cellulare le notifiche de… « meustr’s blog

  55. otto, need help here…after uploading everything in the instructions, i got this on my sidebar…

    Fatal error: Cannot redeclare class magpierss in /home/shaikhta/public_html/blog/wp-includes/rss-functions.php on line 14

    help me out?

    oh and pls send me an email…i might not be coming back to your blog so soon…

  56. darkon says:

    I installed everything according to the readme.txt but it won´t show any dates, just the headline. :(

    If i change it to show a monthly calender, i get a lot of “Invalid argument supplied for foreach()…” in lines: 329 and 441

  57. darkon says:

    nevermind, just noticed, that this widget wont work with 2.3.1

    you should disable download for it if it won´t work with an actual release.

  58. JJ says:

    Works fine for me in WP 2.3.2

    Thank you!

  59. Steven says:

    The plugin is great, I love it. Thanks for your work!

    I’m wondering, though, if there’s any way to pull repeating events from google calendar? Right now it skips right over those.

    Or even to specifically display only those events that repeat?

    Thanks!

    -Steven

  60. jwise says:

    It would be wonderful if I could enter multiple calendars. For example, if I have a google calendar for Work, Home, and Church, I’d love it to grab events off of all those calendars and then merge them, or perhaps show:

    Work
    event
    event

    Home
    event
    event

    etc.

  61. Josh Meyer says:

    I second the motion to support multiple calendars.

  62. Diane says:

    Otto, just a note to let you know I have just updated to 2.6 and your plugin still works great. All this time I have kept the original rss-functions.php and with each update rename and then name it back. It is one of the best plugins I have. Thanks!

  63. Luke says:

    As mentioned, multiple calendars would be really great. I have an artist management site, with each artist requiring their own calendar to manage their schedule.

Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>