:::: MENU ::::

Google Calendar MediaWiki plugin

Ever find yourself needing to embed a Google Calendar in a MediaWiki page? Well, now you can.

Usage


umhappyhours@gmail.com

Code


docid
# Example :
#   from 
# Instructions :
#	set $input to the Google Account that owns the calendar you want to embed
#	set $width & $height to the proportions appropriate for your wiki page
#
# Credits
# 	This code is adapted from Kasper Souren's original extension, sometimes available at 
#	http://wiki.couchsurfing.com/wiki/index.php?title=Google_Calendar_MediaWiki_plugin
# License
# 	GNU Public


$wgExtensionFunctions[] = 'wfGoogleCalendar';
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'Google Calendar',
        'description' => 'Display Google Calendar',
        'author' => 'Libby Hemphill',
        'url' => ''
);

function wfGoogleCalendar() {
        global $wgParser;
        $wgParser->setHook('googlecalendar', 'renderGoogleCalendar');
}

# The callback function for converting the input text to HTML output
function renderGoogleCalendar($input) {
        $input = htmlspecialchars($input);
        //$input = "umhappyhours@gmail.com"
        $width = 425;
        $height = 350;

		$output = '';

        return $output;
}
?>

This page made possible by the Code Markup WordPress plugin. Thank you!


13 Comments

  • jeffrey |

    awesome! really elegant. just a note: i’m a total newbie at this and was able to get this to work, so anyone more advanced than i will catch this in an instant; however, i’d just note that the second $input (the one that is preceded by the // and meant to be edited in the above code) needs a ‘;’ at the end of the line. thanks again!

  • libbyh |

    Chris – you stick the code in a file and put the file in the “extensions” folder. Then, use the “usage” line above in the MediaWiki page where you want the calendar to display. You need the part of the calendars URL that comes after “src=”; in my example, that’s umhappyhours@gmail.com. Hope that helps.

  • Dave |

    Hi Libby,
    Thanks very much for this extension!
    I made a few changes so that it is possible to view events from multiple calendars in one widget, with user defined colours for each. The format for this is:
    umhappyhours@gmail.com:0060FF,umhappyhours@gmail.com:000000
    That will show two calendars, the first with blue wording, the second black.

    The edited callback function is:
    function renderGoogleCalendar($input) {
    $input = htmlspecialchars($input);
    /*
    * Next line separates out pairs of calendar:colourCode
    * from the input string in the tag.
    */
    $initCalArray = split(‘,’, $input);
    /*
    * For each pair of calendar:colourCode, we want to split
    * the pair on the colon, then build a string for each pair
    * which we can pass to google later on.
    */
    foreach($initCalArray as $cal) {
    $calendarItem = split(‘:’, $cal);
    $calArray[] = $calendarItem[0] . ‘&color=%23’ . $calendarItem[1];
    }
    $width = 1050;
    $height = 650;

    $output = ”;

    return $output;
    }

    Hope that helps someone!
    Dave

  • Michelle |

    $output = ”

    I’m struggling a bit with the code above – I am very, VERY new to php code. Does someone have an example of what the code looks like – so I know exactly how the substitute is supposed to look? I’ve got the calendars working on my wiki but some of the functionality is suffering because I haven’t been able to get this part down pat.

    Thanks for any help!

  • Michelle |

    LibbyH – Well, it’s a private wiki, so I can’t. I’ve made progress since the last posting…am still working on getting multiple calenders to display on one page of the wiki. Thanks so much! I’m so new to the coding that I’m still determining which symbol means what…any good cheat sheets/webpages you could share would be great.

    • libbyh |

      Add the following line to LocalSettings.php:
      require_once('extensions/googleCalendar.php');

      Then, create extensions/googleCalendar.php with the code above.

  • Corey |

    Dave,

    I’m having trouble actually changing the color. I copied the modified php and it shows multiple calendars but the colors are non responsive. Any idea?

    Thanks,
    Corey

So, what do you think ?

You must be logged in to post a comment.