Commit b9ffa401 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Bug 1572825: added Voki html filter for embed code"

parents 8859fb86 207889a5
function Old_AC_Voki_Embed(){
AC_Voki_Embed.apply(this, arguments);
}
jQuery(function($) {
var xWidth = 0;
var xHeight = 0;
var htmldiv;
var checkExist = setInterval(function() {
if ($('#initvoki').parent().find('div').length == 1) {
// When first div created but before others exist
htmldiv = $('#initvoki').parent().find('div');
xWidth = htmldiv.width();
}
if ($('#initvoki').parent().find('div').length > 1) {
if (htmldiv.width() > xWidth) {
// Try and resize it to fit the block
xHeight = htmldiv.height() * (xWidth / htmldiv.width());
htmldiv.css('width', xWidth + 'px').css('height', xHeight + 'px');
htmldiv.find('div.main_container').css('width', xWidth + 'px').css('height', xHeight + 'px');
htmldiv.find('div.processing-outer').css('width', xWidth + 'px').css('height', xHeight + 'px');
htmldiv.find('canvas').width(xWidth); // only need to do width as the ratio scales automatically
}
clearInterval(checkExist);
}
}, 1000); // check every 1000ms to allow for some of the voki js to execute
});
......@@ -458,4 +458,12 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function get_instance_javascript(BlockInstance $bi) {
return array(
array(
'file' => 'js/voki.js',
)
);
}
}
......@@ -77,7 +77,36 @@
});
swapNodes(oldblock.get()[0], newblock.get()[0]); // using DOM objects, not jQuery objects so we needn't worry about IDs
eval(data.data.javascript);
var embedjs = data.data.javascript;
if (embedjs.includes("AC_Voki_Embed")) {
var paramsstr = embedjs.substring(embedjs.lastIndexOf("(")+1,embedjs.lastIndexOf(")"));
var params = paramsstr.split(',');
if (params.length == 7 ) { // old voki embed code has only 7 parameters
// change the last parameter to 1 so it returns the embed code instead of showing it
var newScript = 'AC_Voki_Embed(';
for (var i = 0; i<params.length-1; i++) {
newScript += params[i] + ', ';
}
newScript += "1)";
var embedCode = get_string_ajax('reloadtoview', 'mahara');
if (window['AC_Voki_Embed']) {
embedCode = eval(newScript);
}
// add embed code to already loaded page
var newChild = document.createElement('div');
newChild.innerHTML = embedCode;
newblock.get()[0].getElementsByClassName('mediaplayer')[0].appendChild(newChild);
}
else {
// patch for new voki code, need to reload page so it shows the embed code
$(window).trigger('embednewvoki');
}
}
else {
eval(data.data.javascript);
}
rewriteConfigureButton(newblock.find('.configurebutton'));
rewriteDeleteButton(newblock.find('.deletebutton'));
}
......@@ -191,6 +220,10 @@
equalHeights();
});
$(window).on('embednewvoki', function() {
location.reload();
});
// images need time to load before height can be properly calculated
window.setTimeout(function(){
$(window).trigger('colresize');
......
......@@ -437,6 +437,7 @@ $string['passwordsaved'] = 'Your new password has been saved';
$string['passwordsdonotmatch'] = 'The passwords do not match.';
$string['passwordtooeasy'] = 'Your password is too easy. Please choose a harder password.';
$string['register'] = 'Register';
$string['reloadtoview'] = 'Reload the page to view';
$string['sessiontimedout'] = 'Your session has timed out. Please enter your login details to continue.';
$string['sessiontimedoutpublic'] = 'Your session has timed out. You may <a href="%s">log in</a> to continue browsing.';
$string['sessiontimedoutreload'] = 'Your session has timed out. Reload the page to log in again.';
......
......@@ -5424,5 +5424,10 @@ function xmldb_core_upgrade($oldversion=0) {
delete_records('usr_account_preference','field','mobileuploadtoken');
}
if ($oldversion < 2017110600) {
log_debug('Add Voki filters to DB');
reload_html_filters();
}
return $status;
}
<?php
class HTMLPurifier_Filter_Voki extends HTMLPurifier_Filter
{
public $name = 'Voki';
public function preFilter($html, $config, $context) {
$pre_regex = '#<script\b[^>]+?\bsrc="(?:http:|https:)?\/\/vhss-d.oddcast.com\/voki_embed_functions.php"[^<>]*>\s*<\/script>\s*<script\b[^>]+?>'.
'(AC_Voki_Embed\((?:[^<>,]*,){6}(?:[^<>,]*)(?:,\s)?([^<>]*)?\);)<\/script>#s';
// span new_voki shows if it is a new voki embed code,
// function will have 8 parameters and the last one will be = 1
$pre_replace = '<span class="voki-embed"><span class="function">\1</span><span class="new_voki">\2</span></span>';
return preg_replace($pre_regex, $pre_replace, $html);
}
public function postFilter($html, $config, $context) {
// if its a new voki embed code, create normal code
if ( strpos( $html, '<span class="new_voki">1</span>' ) !== false ) {
$post_regex = '#<span class="voki-embed"><span class="function">(AC_Voki_Embed\([^<>]*;)</span><span class="new_voki">1</span></span>#';
$post_replace = '<script language="JavaScript" type="text/javascript" src="//vhss-d.oddcast.com/voki_embed_functions.php"></script>'.
'<script id="initvoki" language="JavaScript" type="text/javascript">'.
'\1</script>';
}
else {
// if its not new voki embed code, add a blank space before the function,
// to deal with voki bug when there is new and old voki embed code in same page
$post_regex = '#<span class="voki-embed"><span class="function">(AC_Voki_Embed\([^<>]*;)</span><span class="new_voki">(?:[^<>]*)?</span></span>#';
$post_replace = '<script language="JavaScript" type="text/javascript" src="//vhss-d.oddcast.com/voki_embed_functions.php"></script>'.
'<script language="JavaScript" type="text/javascript">'.
'Old_\1</script>';
}
return preg_replace($post_regex, $post_replace, $html);
}
}
......@@ -8,4 +8,8 @@
<filename>Twitter</filename>
<site>http://twitter.com</site>
</filter>
<filter>
<filename>Voki</filename>
<site>http://www.voki.com</site>
</filter>
</filters>
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2017103100;
$config->version = 2017110600;
$config->series = '18.04';
$config->release = '18.04dev';
$config->minupgradefrom = 2015030409;
......
......@@ -2366,7 +2366,7 @@ class View {
// is lost on block move so we need to referesh the block with its original content
$configdata = $bi->get('configdata');
$html = null;
if ($bi->get('blocktype') == 'externalvideo' && $configdata['embed']['service'] == 'embedly') {
if ($bi->get('blocktype') == 'externalvideo' && isset($configdata['embed']) && $configdata['embed']['service'] == 'embedly') {
$html = PluginBlocktypeExternalvideo::render_instance($bi, true);
}
return array('html' => $html);
......
......@@ -2,7 +2,7 @@
position: fixed;
top: 0;
width: 100%;
z-index: 11;
z-index: 1001;
.site-message.alert {
margin-bottom: 0;
border-radius: 0;
......
......@@ -39,6 +39,9 @@
.logo,
.logoxs {
top: 0px;
right: 0px;
position: relative;
img {
height: 100%;
max-width: none;
......
......@@ -2,7 +2,7 @@
position: fixed;
top: 0;
width: 100%;
z-index: 11;
z-index: 1001;
.site-message.alert {
margin-bottom: 0;
border-radius: 0;
......
......@@ -39,6 +39,9 @@
.logo,
.logoxs {
top: 0px;
right: 0px;
position: relative;
img {
height: 100%;
max-width: none;
......
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