====== Google Calendar Plugin ====== ---- plugin ---- description: Embeds a Google Calendar into a wiki page author : Kite email : Kite@puzzlers.org type : syntax lastupdate : 2007-05-01 compatible : depends : conflicts : similar : tags : google, calendar ---- With a serious nod to [[plugin:iframe]] by [[chris@jalakai.co.uk|Christopher Smith]]. Minimal changes were made (improvements, I hope). ===== Syntax ===== {{cal>kite@puzzlers.org[614,640]|Kite's Test}} Pretty simple: * an email address with a shared/private calendar. * the [614,640] are width and height -- these are both optional, but must be enclosed in [ , ] if present. If only one value is supplied, it is assumed to be the height. * the | marks the 'alternate text' used for a title; otherwise you get the default configured in Google. ===== Configuration ===== The plugin has one configuration setting, which can be set via the admin/configuration settings page. * $gcal_js_ok --- default value - ''false'', set to ''true'' to enable javascript urls. * [[plugin:iframe]] by [[chris@jalakai.co.uk|Christopher Smith]] uses $js_ok I don't know if it is better to allow one value for both plugins, or not. Also, due to the limited nature of this plugin, I don't think this option will actually make any difference. It has not been tested. ===== Installation ===== Be sure that, while cutting and pasting, no extra spaces or anything are before the **** as this will cause errors while producing headers. Place this file in **lib/plugins/google_cal/syntax.php** , Christopher Smith * @seealso (http://www.dokuwiki.org/plugin:iframe) */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_google_cal extends DokuWiki_Syntax_Plugin { function getInfo(){ return array( 'author1' => 'Kite', 'email1' => 'kite@puzzlers.org', 'author2' => 'Christopher Smith', 'email2' => 'chris@jalakai.co.uk', 'date' => '2007-05-01', 'name' => 'Google Calendar Plugin', 'desc' => 'Adds a Google Calendar iframe syntax: {{cal>name@address[w,h]|alternate text}}', 'url' => 'http://www.dokuwiki.org/plugin:google_cal', ); } function getType() { return 'substition'; } function getPType(){ return 'block'; } function getSort() { return 305; } function connectTo($mode) { $this->Lexer->addSpecialPattern('{{cal>[^}]*?}}',$mode,'plugin_google_cal'); } function handle($match, $state, $pos, &$handler){ if(preg_match('/{{cal>(.*)/', $match)) { // Hook for future features // Handle the simplified style of calendar tag $match = html_entity_decode(substr($match, 6, -2)); @list($url, $alt) = explode('|',$match,2); $matches=array(); // '/^\s*([^\[|]+)(?:\[(?:([^,\]]*),)?([^,\]]*)\])?(?:\s*(?:\|\s*(.*))?)?$/mD' if (preg_match('/(.*)\[(.*)\]$/',trim($url),$matches)) { $url = $matches[1]; if (strpos($matches[2],',') !== false) { @list($w, $h) = explode(',',$matches[2],2); } else { $h = $matches[2]; $w = '98%'; } } else { $w = '98%'; $h = '600'; } if (!isset($alt)) $alt = ''; if (!$this->getConf('js_ok') && substr($url,0,11) == 'javascript:') { return array('error', $this->getLang('gcal_No_JS')); } return array('wiki', hsc(trim("$url")), hsc(trim($alt)), hsc(trim($w)), hsc(trim($h))); } else { return array('error', $this->getLang("gcal_Bad_iFrame")); // this is an error } // matched {{cal>... } function render($mode, &$renderer, $data) { list($style, $url, $alt, $w, $h) = $data; if($mode == 'xhtml'){ // Two styles: wiki and error switch($style) { case 'wiki': $renderer->doc .= "\n"; break; case 'error': $renderer->doc .= "
$url
"; break; default: $renderer->doc .= "
" . $this->getLang('gcal_Invalid_mode') . "
"; break; } return true; } return false; } } ?>
Place this file in **lib/plugins/google_cal/conf/metadata.php** */ $meta['gcal_js_ok'] = array('onoff'); ?> Place this file in **lib/plugins/google_cal/conf/default.php** */ $conf['gcal_js_ok'] = false; ?> ==== Languages ==== Of course, you may need to translate these to your own locale. I prefer to make error messages relatively vague but unique so I can track them back to where the error was found without overloading a user with technical info they shouldn't have or want. Place this file in **lib/plugins/google_cal/lang/en/lang.php** */ $lang['gcal_Bad_calendar'] = 'Invalid Gooogle Calendar request.'; $lang['gcal_No_JS'] = 'The wiki can not display this calendar.'; $lang['gcal_Invalid_mode'] = 'Google Calendar plugin error.'; ?> Place this file in **lib/plugins/google_cal/lang/en/settings.php** */ // for the configuration manager $lang['gcal_js_ok'] = 'Allow javascript urls'; ?> ===== Download ===== Hi, I've translated the error messages to de_DE and uploaded it. Just unpack and use it =) regards Ferhat Dogru [[http://drop.io/google_cal|google_cal.zip]] ===== Discussion ===== First release posted April 26, 2007 by . One improvement over [[plugin:iframe]] by [[chris@jalakai.co.uk|Christopher Smith]] was the regular expression function connectTo($mode) { $this->Lexer->addSpecialPattern('{{cal>[^}]*?}}',$mode,'plugin_google_cal'); } By adding **[^}]%%*%%** the expression is prevented from crossing a boundary into another tag if, for example, you put two calendars on the same page. The lexer patterns are all greedy by nature so this is something I find needs to be in more plugins. > The '?' after the '*' reverses the greediness of the quantifier --- //[[chris@jalakai.co.uk|Christopher Smith]] 2007-08-26 12:02// function getPType(){ return 'block'; } This method was added so that the plugin informs Dokuwiki to close any

tags that are open before this plugin is called so the frame is not bound in a paragraph. > I have several Google Calendars tied to my Gmail account. Is there a way to specify just one calendar, or a sub-group (i.e. 3 out of 5 calendars). --- //[[jungerle@gmail.com|Jason]] 2007-06-08 18:51// > Same for me. I do have several calendards in my account and just some are shared... and I would like to have the specify which calendears should be visible. The quick answer is yes. At the google calendar webpage, click on manage calendars. Then click on the particular calendar that you are interested in using. In the Calendar Address box you should see a calendar id that looks like a randomly generated bunch of letters @group.calendar.google.com. Plug this in as the address instead of {{cal>yourname@gmail.com}}. I.e. {{cal>[randomletters]@group.calendar.google.com}}. Seems to be working for me. Cheers. Ethan Farquhar 2007-08-13 > Nice job ! It work fine ! Just one suggest : I choose different colors for several calendards (i.e. light green for one). I would like to recover the colour of the interested calendar ! --- //[[kh.drakkon@gmail.com|Nicolas]] 2007-24-08 15:26// > Hi - I was wondering if it was possible to login to the calendar automatically when the page loads? Thanks - David > Hi - Is there a working example somewhere ? ==== Future Directions ==== * This should be able to cope with an from Google; wasn't able to make that work this time around due to some parsing and regular expression problems. * This should probably check the user's email but ... since it has to go to Google's calendar engine anyway, I can rely on their response to be "reasonable" for now.