Commit b1074c71 authored by Jono Mingard's avatar Jono Mingard Committed by Robert Lyon

Use iframe to embed Prezi presentations (Bug #1239928)

Also upgrades the old <object> syntax to use iframes Change-Id: I1d58c1a42ddf0e3db52a19c185ff64242f926cd2 Signed-off-by: 's avatarJono Mingard <jonom@catalyst.net.nz>
parent 14bb34a5
<?php
/**
*
* @package mahara
* @subpackage blocktype-textbox
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
defined('INTERNAL') || die();
safe_require('blocktype', 'externalvideo');
function xmldb_blocktype_externalvideo_upgrade($oldversion=0) {
if ($oldversion < 2014030500) {
$urlpattern = '#\b(https?://)prezi\.com/bin/preziloader\.swf\?prezi_id=([a-z0-9]+)\b#';
$matches = array();
$sql = "SELECT id, configdata FROM {block_instance} WHERE blocktype='externalvideo'";
$records = get_records_sql_array($sql, array());
if ($records) {
foreach ($records as $r) {
$configdata = unserialize($r->configdata);
if (isset($configdata['html'])) {
preg_match($urlpattern, $configdata['html'], $matches);
}
else if (isset($configdata['videoid'])) {
preg_match($urlpattern, $configdata['videoid'], $matches);
}
if (count($matches) >= 3) {
$newurl = $matches[1] . 'prezi.com/embed/' . $matches[2];
$width = (!empty($configdata['width'])) ? $configdata['width'] : 0;
$height = (!empty($configdata['height'])) ? $configdata['height'] : 0;
$configdata['html'] = $configdata['videoid'] = PluginBlocktypeExternalvideo::iframe_code($newurl, $width, $height);
set_field('block_instance', 'configdata', serialize($configdata), 'id', $r->id);
}
}
}
ensure_record_exists('iframe_source_icon', (object) array('name' => 'Prezi', 'domain' => 'prezi.com'), (object) array('name' => 'Prezi', 'domain' => 'prezi.com'));
ensure_record_exists('iframe_source', (object) array('prefix' => 'prezi.com/embed/', 'name' => 'Prezi'), (object) array('prefix' => 'prezi.com/embed/', 'name' => 'Prezi'));
update_safe_iframe_regex();
}
return true;
}
......@@ -225,6 +225,8 @@ class PluginBlocktypeExternalvideo extends SystemBlocktype {
if (!filter_var($values['videoid'], FILTER_VALIDATE_URL)) {
// Not a url, treat the input as html to be sanitised when rendered.
$httpstr = is_https() ? 'https' : 'http';
$values['videoid'] = preg_replace('#https?://#', $httpstr . '://', $values['videoid']);
$values['html'] = $values['videoid'];
return $values;
}
......@@ -316,4 +318,12 @@ class PluginBlocktypeExternalvideo extends SystemBlocktype {
return 'full';
}
public static function postinst($prevversion) {
if ($prevversion == 0) {
ensure_record_exists('iframe_source_icon', (object) array('name' => 'Prezi', 'domain' => 'prezi.com'), (object) array('name' => 'Prezi', 'domain' => 'prezi.com'));
ensure_record_exists('iframe_source', (object) array('prefix' => 'prezi.com/embed/', 'name' => 'Prezi'), (object) array('prefix' => 'prezi.com/embed/', 'name' => 'Prezi'));
update_safe_iframe_regex();
}
}
}
......@@ -10,17 +10,17 @@ class Media_prezi implements MediaBase {
private static $default_width = 550;
private static $default_height = 400;
private static $embed_sources;
private static $iframe_sources;
function __construct() {
$this->httpstr = is_https() ? 'https' : 'http';
self::$base_url = $this->httpstr . '://www.prezi.com/';
self::$embed_sources = array(
self::$iframe_sources = array(
array(
'match' => '#https?://prezi.com/([a-zA-Z0-9\-_]+)/.*#',
'url' => $this->httpstr . '://prezi.com/bin/preziloader.swf?prezi_id=$1',
'url' => $this->httpstr . '://prezi.com/embed/$1/',
),
);
}
......@@ -33,12 +33,12 @@ class Media_prezi implements MediaBase {
$width = $width ? (int)$width : self::$default_width;
$height = $height ? (int)$height : self::$default_height;
foreach (self::$embed_sources as $source) {
foreach (self::$iframe_sources as $source) {
if (preg_match($source['match'], $input)) {
$output = preg_replace($source['match'], $source['url'], $input);
$result = array(
'videoid' => $output,
'type' => 'embed',
'type' => 'iframe',
'width' => $width,
'height' => $height,
);
......@@ -49,7 +49,7 @@ class Media_prezi implements MediaBase {
}
public function validate_url($input) {
foreach (self::$embed_sources as $source) {
foreach (self::$iframe_sources as $source) {
if (preg_match($source['match'], $input)) {
return true;
}
......
......@@ -28,5 +28,5 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010061800;
$config->release = '1.0.0';
$config->version = 2014030500;
$config->release = '1.0.1';
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