Commit 18e2efdc authored by Hugh Davenport's avatar Hugh Davenport
Browse files

blocktype/googleapps: Initial import



Initial import of a contrib plugin for a
googleapps blocktype.

Change-Id: Ib49a83965b1e17bec9f2f79b6b0e41235d9b5a91
Author: Gregor Anželj <gregor.anzelj@gmail.com>
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 1c7481ac
This diff is collapsed.
This plugin is developed by Gregor Anželj <gregor.anzelj@gmail.com>
The plugin itself is licenced under the same terms as Mahara,
though the images in this plugin are licenced as follows.
The images come from the Crystal Clear set by Everaldo, and are
licenced under the LGPL, which is available in the LGPL-2.1 file
or at http://www.everaldo.com/crystal/?action=license
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-googleapps
* @author Gregor Anželj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2010 Gregor Anželj, gregor.anzelj@gmail.com
*
*/
defined('INTERNAL') || die();
$string['title'] = 'Google Apps';
$string['description'] = 'Embed Google calendar or docs';
$string['appscodeorurl'] = 'Embed code or URL';
$string['appscodeorurldesc'] = 'Paste the embed code or the URL of the page where Google Apps is publicly viewable.';
$string['height'] = 'Height';
<h3>How to embed?</h3>
<h4>Google Docs</h4>
<p>Google Apps for Educational domains: Sharing of individual files is identical as on a regular Google Apps account.</p>
<p>Your institution's administrator may have set the Google Apps so that only members of your institution can view your shared files.<br>In that case, a viewer will be presented with a Google Apps login screen and upon logging into Google Apps, the embedded files will become visible in the view.</p>
<p><strong>Documents</strong></p>
<ol>
<li>Open Google Docs document</li>
<li>Click <em>Share</em> and than <em>Publish to the Web</em> (upper right corner)</li>
<li>Click <em>Start publishing</em> button</li>
<li>Copy <em>Document link</em> or <em>Embed code</em></li>
<li>Paste it to the GoogleApps block</li>
</ol>
<p><strong>Spreadsheets</strong></p>
<ol>
<li>Open Google Docs spreadsheet</li>
<li>Click <em>Share</em> and than <em>Publish as a web page</em> (upper right corner)</li>
<li>Click <em>Start publishing</em> button</li>
<li>Copy link from texarea</li>
<li>Paste it to the GoogleApps block</li>
</ol>
<p><strong>Presentations</strong></p>
<ol>
<li>Open Google Docs presentation</li>
<li>Click <em>Share</em> and than <em>Publish / embed</em> (upper right corner)</li>
<li>Click <em>Publish document</em> button</li>
<li>Copy link or embed code from textarea</li>
<li>Paste it to the GoogleApps block</li>
</ol>
<p><strong>Collections</strong></p>
<ol>
<li>In Google Docs click <em>My collections</em> or <em>Collections shared with me</em> (list on left side)</li>
<li>Click and select the Collection that you wish to embed</li>
<li>Click <em>Sharing - Settings</em> link (on right side)</li>
<li>Change Permissions to Public and save changes</li>
<li>Copy link from textbox</li>
<li>Paste it to the GoogleApps block</li>
</ol>
<p><strong>Google Docs Viewer</strong></p>
<p>This functionality works like the preview functionality in Gmail. You can embed the file, which is <em>directly</em> accessible over the Internet. You just have to paste the complete URL (including the filename) on which the file is accessible to the GoogleApps block.</p>
<p>Google Docs Viewer currently supports embedding of the following file types: PDF, TIFF, PPT, DOC, DOCX.</p>
<p><strong>Note:</strong> The files you've uploaded to Mahara are not directly accessible, so you can't embed those files.</p>
<h4>Google Calendar</h4>
<ol>
<li>Open Google Calendar</li>
<li>Click <em>Settings</em> and than <em>Calendar settings</em> (top right on the menu)</li>
<li>Click <em>Calendars</em> link on the left upper side</li>
<li>Click the name of the calendar that you wish to embed</li>
<li>On <em>Calendar details</em> tab you'll find <em>Embed This Calendar</em></li>
<li>Customize calendar apperance and than copy embed code from textarea</li>
<li>Paste it to the GoogleApps block</li>
</ol>
<h4>Google Maps</h4>
<ol>
<li>Open Google Maps</li>
<li>Click <em>My Maps</em> link on the left upper side</li>
<li>Click the name of the map that you wish to embed</li>
<li>Click on <em>Link</em> link on right upper side</li>
<li>Customize the apperance of the map and copy embed code</li>
<li>Paste it to the GoogleApps block</li>
</ol>
<strong>Note:</strong> Use steps 2 and 3 only if you wish to embed <strong>your</strong> Google Map. If you wish to embed any Google Map, then you can skip steps 2 and 3.
<h4>Google Books</h4>
<ol>
<li>Open Google Books</li>
<li>Find the book that you wish to embed</li>
<li>Click on <em>Preview this book</em> link or button</li>
<li>Click on <em>Link</em> link on right upper side</li>
<li>Copy the embed code of the book</li>
<li>Paste it to the GoogleApps block</li>
</ol>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-googleapps
* @author Gregor Anželj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2010 Gregor Anželj, gregor.anzelj@gmail.com
*
*/
defined('INTERNAL') || die();
class PluginBlocktypeGoogleApps extends SystemBlocktype {
private static $default_height = 500;
public static function get_title() {
return get_string('title', 'blocktype.googleapps');
}
public static function get_description() {
return get_string('description', 'blocktype.googleapps');
}
public static function get_categories() {
return array('fileimagevideo');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
$configdata = $instance->get('configdata');
if (!isset($configdata['appsid'])) {
return;
}
$apps = self::make_apps_url($configdata['appsid']);
$url = hsc($apps['url']);
$type = hsc($apps['type']);
$height = (!empty($configdata['height'])) ? hsc($configdata['height']) : self::$default_height;
if (isset($configdata['appsid'])) {
$smarty = smarty_core();
$smarty->assign('url', $apps['url']);
switch ($type) {
case 'iframe':
// Google Docs (documents, presentations, spreadsheets, forms), Google Calendar, Google Maps
$smarty->assign('height', $height);
return $smarty->fetch('blocktype:googleapps:iframe.tpl');
case 'spanicon':
// Google Docs collections (folder icon)
$smarty->assign('img', get_config('wwwroot') . 'blocktype/googleapps/images/folder_documents.png');
return $smarty->fetch('blocktype:googleapps:spanicon.tpl');
case 'image':
// Google Docs drawing
$smarty->assign('height', $height);
return $smarty->fetch('blocktype:googleapps:image.tpl');
}
}
return '';
}
public static function has_instance_config() {
return true;
}
public static function instance_config_form($instance) {
$configdata = $instance->get('configdata');
return array(
'appsid' => array(
'type' => 'textarea',
'title' => get_string('appscodeorurl','blocktype.googleapps'),
'description' => get_string('appscodeorurldesc','blocktype.googleapps') . self::get_html_of_supported_googleapps(),
'rows' => 5,
'cols' => 80,
'defaultvalue' => (!empty($configdata['appsid']) ? $configdata['appsid'] : null),
'rules' => array(
'required' => true
),
'help' => true,
),
'height' => array(
'type' => 'text',
'title' => get_string('height','blocktype.googleapps'),
'size' => 3,
'rules' => array(
'required' => true,
'integer' => true,
),
'defaultvalue' => (!empty($configdata['height'])) ? $configdata['height'] : self::$default_height,
),
);
}
private static function make_apps_url($url) {
static $embedsources = array(
// docs.google.com/leaf - Google collections
// $1 - domain, e.g. /a/domainname/
// $2 - id, key, etc. of the collection
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)leaf\?id=([a-zA-Z0-9]+).*#',
'url' => 'http://docs.google.com/$1leaf?id=$2',
'type' => 'spanicon',
),
// docs.google.com/present - Google presentation incl. custom domain presentation
// $1 - domain, e.g. /a/domainname/
// $2 - mode, e.g. view or embed
// $3 - id, key, etc. of the presentation
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)present/([a-z]+).*id=([a-zA-Z0-9\_\-\&\=]+).*#',
'url' => 'http://docs.google.com/$1present/embed?id=$3',
'type' => 'iframe',
),
// docs.google.com/drawings - Google drawing incl. custom domain drawing
// $1 - domain, e.g. /a/domainname/
// $2 - id, key, etc. of the drawing
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)drawings.*id=([a-zA-Z0-9\_\-\&\=]+).*#',
'url' => 'http://docs.google.com/$1drawings/pub?id=$2',
'type' => 'image',
),
// docs.google.com - Google document (before July 2010) incl. custom domain document
// $1 - domain, e.g. /a/domainname/
// $2 - id, key, etc. of the document
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)View.*id=([a-zA-Z0-9\_\-]+).*#',
'url' => 'http://docs.google.com/$1View?id=$2',
'type' => 'iframe',
),
// docs.google.com - Google document (after July 2010) incl. custom domain document
// $1 - domain, e.g. /a/domainname/
// $2 - id, key, etc. of the document
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)document/pub.*id=([a-zA-Z0-9\_\-]+).*#',
'url' => 'http://docs.google.com/$1document/pub?id=$2',
'type' => 'iframe',
),
// spreadsheets.google.com/viewform - Google form incl. custom domain form
// $1 - domain, e.g. /a/domainname/
// $2 - id, key, etc. of the form
array(
'match' => '#.*spreadsheets[0-9]?.google.com/([a-zA-Z0-9\_\-\.\/]*)viewform.*formkey=([a-zA-Z0-9\_\-]+).*#',
'url' => 'https://spreadsheets.google.com/$1embeddedform?formkey=$2',
'type' => 'iframe',
),
// spreadsheets.google.com/embeddedform - Google form incl. custom domain form
// $1 - domain, e.g. /a/domainname/
// $2 - id, key, etc. of the form
array(
'match' => '#.*spreadsheets[0-9]?.google.com/([a-zA-Z0-9\_\-\.\/]*)embeddedform.*formkey=([a-zA-Z0-9\_\-]+).*#',
'url' => 'https://spreadsheets.google.com/$1embeddedform?formkey=$2',
'type' => 'iframe',
),
// spreadsheets.google.com - Google spreadsheet incl. custom domain spreadsheet
// $1 - domain, e.g. /a/domainname/
// $2 - id, key, etc. of the spreadsheet
array(
'match' => '#.*spreadsheets[0-9]?.google.com/([a-zA-Z0-9\_\-\.\/]*)pub.*key=([a-zA-Z0-9\_\-]+).*#',
'url' => 'http://spreadsheets.google.com/$1pub?key=$2',
'type' => 'iframe',
),
// www.google.com/calendar - Google calendar
array(
'match' => '#.*www.google.com/calendar.*src=([a-zA-Z0-9\.\_\-\&\%\=/]+).*#',
'url' => 'http://www.google.com/calendar/embed?src=$1',
'type' => 'iframe',
),
// maps.google.com - Google My Maps (IMPORTANT: this is ONLY for My Maps)
array(
'match' => '#.*maps.google.[^/]*/maps/ms\?([a-zA-Z0-9\.\,\;\_\-\&\%\=\+/]+).*#',
'url' => 'http://maps.google.com/maps/ms?$1',
'type' => 'iframe',
),
// maps.google.com - Google Maps (IMPORTANT: this is for ANY Maps EXCEPT My Maps)
array(
'match' => '#.*maps.google.[^/]*/(maps)?\?([a-zA-Z0-9\.\,\;\_\-\&\%\=\+/]+).*#',
'url' => 'http://maps.google.com/maps?$1',
'type' => 'iframe',
),
// books.google.com - Google Books
array(
'match' => '#.*books.google.[^/]*/books.*id=([a-zA-Z0-9\_\-\&\%\=]+).*#',
'url' => 'http://books.google.com/books?id=$1',
'type' => 'iframe',
),
// If everything else fails, match if it is a valid link to a file... and than show that file with Google Dovs Viewer
// Google Docs Viewer supported files: PDF, TIFF, PPT, DOC, DOCX
array(
'match' => '#http([a-zA-Z0-9\.\,\;\_\-\&\%\=\+/\:]+)\.(pdf|tif|tiff|ppt|doc|docx)#',
'url' => 'http://docs.google.com/gview?url=http$1.$2&embedded=true',
'type' => 'iframe',
),
);
foreach ($embedsources as $source) {
$url = htmlspecialchars_decode($url); // convert &amp; back to &, etc.
if (preg_match($source['match'], $url)) {
$apps_url = preg_replace($source['match'], $source['url'], $url);
// For correctly embed Google maps...
$apps_url = str_replace('source=embed', 'output=embed', $apps_url);
$apps_type = $source['type'];
return array('url' => $apps_url, 'type' => $apps_type);
}
}
// TODO handle failure case
}
/**
* Returns a block of HTML that the Google Apps block can use to list
* which Google services are supported.
*/
private static function get_html_of_supported_googleapps() {
$smarty = smarty_core();
$smarty->assign('lang', substr(get_config('lang'), 0, 2));
return $smarty->fetch('blocktype:googleapps:supported.tpl');
}
public static function default_copy_type() {
return 'full';
}
}
<div class="googleapps-container center"><div class="googleapps">
<iframe width="100%" height="{$height}" frameborder="0" src="{$url}"></iframe>
</div></div>
<div class="googleapps-container center"><div class="googleapps">
<img width="100%" height="{$height}" border="0" src="{$url}">
</div></div>
<div class="googleapps-container center"><div class="googleapps">
<span width="100%" height="115" align="center" style="width:100px;heigh:115px;padding:0;background-color:#fcfcfc;">
<a href="{$url}">
<img src="{$img}" width="96" height="96" border="0"></img>
</a>
</span>
</div></div>
<ul style="list-style-type: none;">
<li>
<a href="http://books.google.com/" target="_blank">
<img src="http://books.google.com/intl/{$lang}/googlebooks/images/books_logo_sm.gif" border="0" height="20">
</a>
</li>
<li>
<a href="http://www.google.com/calendar" target="_blank">
<img src="http://calendar.google.com/googlecalendar/images/calendar_logo_sm_{$lang}.gif" border="0" height="20">
</a>
</li>
<li>
<a href="http://docs.google.com/" target="_blank">
<img src="http://docs.google.com/images/doclist/docs_logo_sm.gif" border="0" height="20">
</a>
</li>
<li>
<a href="http://maps.google.com/" target="_blank">
<img src="http://maps.google.com/intl/{$lang}/images/logos/maps_logo.gif" border="0" height="20">
</a>
</li>
</ul>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-googleapps
* @author Gregor Anželj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2010 Gregor Anželj, gregor.anzelj@gmail.com
*
*/
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011051700;
$config->release = '1.0.8';
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment