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. )

63 thoughts on “Google Calendar Widget”

  1. 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!

  2. @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!

  3. @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!

  4. 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

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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++;
    }
    }
    }

  10. 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!

  11. 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!

  12. 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

  13. 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!

  14. 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.

  15. 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! ๐Ÿ™‚

  16. 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.

  17. 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!

  18. 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’);

  19. 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’);

  20. 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.

  21. 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.

  22. Pingback: PoliticalWarez
  23. 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.

  24. 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?

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

  26. 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.

  27. 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!

  28. 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! ๐Ÿ™‚

  29. 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?

  30. 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!

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

  32. 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

Leave a Reply to Ken Martin Cancel reply

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

css.php