7Dec/0712
Google Calendar MediaWiki plugin
Ever find yourself needing to embed a Google Calendar in a MediaWiki page? Well, now you can.
Usage
<googlecalendar>umhappyhours@gmail.com</googlecalendar>
Code
<?php
# Google Calendar Extension
#
# Purpose:
# Embed a Google Calendar in a MediaWiki page
# Tag/Wikitext :
# <googlecalendar>docid</googlecalendar>
# Example :
# from <iframe src="http://www.google.com/calendar/embed?src=umhappyhours%40gmail.com"
# style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
# 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 = '<iframe src="http://www.google.com/calendar/embed?src=' . $input;
$output .= '" style="border: 0" width="' . $width;
$output .= '" height="' . $height . '" frameborder="0" scrolling="no"></iframe>';
return $output;
}
?>
This page made possible by the Code Markup WordPress plugin. Thank you!
Filed under: Code, Social Computing, Technology, Wikis, adSense
Leave a comment
Blog Post Categories
Blog Archives
other versions of me
recommended blogs
- BietzMe
- Bitch, PhD
- david ribes
- Elisabeth Jones
- food in the library
- ghetto of our mind
- jeff woelker
- mad mission
- many-to-many
- mossberger
- Nora Ephron
- Research Dasein
- slog
- the f word
- together, in a sense
- tsudoblog
- UC ASC
- uchiblogo
- verfremdungseffekt
- Viscous Platypus
- Words, get out of my head
December 7th, 2007 - 21:24
You’re welcome (for Code Markup). And thanks for this extension! Google Calendar + Mediawiki might be useful at work; I will have to give it a try.
February 26th, 2008 - 01:43
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!
April 8th, 2008 - 17:07
where do I save this file in mediawiki and how do i get the calendar to display on the page
April 12th, 2008 - 16:39
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.
October 2nd, 2008 - 11:53
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
October 2nd, 2008 - 12:01
Rats, your blog ate my formatting.
Altered callback function reproduced at http://pastebin.com/f2bcc15f1
Dave
April 14th, 2009 - 15:34
$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!
April 21st, 2009 - 13:44
Michelle – can you point me to your wiki where you’re trying to use the plugin? I’m not sure which part isn’t working.
April 21st, 2009 - 16:06
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.
April 22nd, 2009 - 09:59
Michelle – I’m not sure how new you are to PHP or code in general, but w3schools has a good PHP syntax guide here. Hope that helps!
January 3rd, 2010 - 09:42
Where do you put this code, and what do you call the file??????????
January 4th, 2010 - 13:10
Add the following line to
LocalSettings.php:require_once('extensions/googleCalendar.php');Then, create
extensions/googleCalendar.phpwith the code above.