Skip to content

Commit

Permalink
MDL-29624 Media embedding system, part 1: new API and filter changes
Browse files Browse the repository at this point in the history
Includes new API in medialib.php and core_media_renderer in outputrenderers.php.
Enable/disable settings moved from filter to systemwide appearance page.
Filter changed to use new API.

AMOS BEGIN
 MOV [flashanimation,filter_mediaplugin],[flashanimation,core_media]
 MOV [flashanimation_help,filter_mediaplugin],[flashanimation_desc,core_media]
 MOV [flashvideo,filter_mediaplugin],[flashvideo,core_media]
 MOV [flashvideo_help,filter_mediaplugin],[flashvideo_desc,core_media]
 MOV [html5audio,filter_mediaplugin],[html5audio,core_media]
 MOV [html5audio_help,filter_mediaplugin],[html5audio_desc,core_media]
 MOV [html5video,filter_mediaplugin],[html5video,core_media]
 MOV [html5video_help,filter_mediaplugin],[html5video_desc,core_media]
 MOV [mp3audio,filter_mediaplugin],[mp3audio,core_media]
 MOV [mp3audio_help,filter_mediaplugin],[mp3audio_desc,core_media]
 MOV [legacyquicktime,filter_mediaplugin],[legacyquicktime,core_media]
 MOV [legacyquicktime_help,filter_mediaplugin],[legacyquicktime_desc,core_media]
 MOV [legacyreal,filter_mediaplugin],[legacyreal,core_media]
 MOV [legacyreal_help,filter_mediaplugin],[legacyreal_desc,core_media]
 MOV [legacywmp,filter_mediaplugin],[legacywmp,core_media]
 MOV [legacywmp_help,filter_mediaplugin],[legacywmp_desc,core_media]
 MOV [legacyheading,filter_mediaplugin],[legacyheading,core_media]
 MOV [legacyheading_help,filter_mediaplugin],[legacyheading_desc,core_media]
 MOV [sitevimeo,filter_mediaplugin],[sitevimeo,core_media]
 MOV [sitevimeo_help,filter_mediaplugin],[sitevimeo_desc,core_media]
 MOV [siteyoutube,filter_mediaplugin],[siteyoutube,core_media]
 MOV [siteyoutube_help,filter_mediaplugin],[siteyoutube_desc,core_media]
AMOS END
  • Loading branch information
sammarshallou committed May 9, 2012
1 parent ffe4de9 commit daefd6e
Show file tree
Hide file tree
Showing 17 changed files with 2,462 additions and 925 deletions.
43 changes: 43 additions & 0 deletions admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,49 @@
$ADMIN->add('appearance', new admin_externalpage('resetemoticons', new lang_string('emoticonsreset', 'admin'),
new moodle_url('/admin/resetemoticons.php'), 'moodle/site:config', true));


// The "media" subpage.
$temp = new admin_settingpage('mediasettings', get_string('mediasettings', 'core_media'));

$temp->add(new admin_setting_heading('mediaformats', get_string('mediaformats', 'core_media'),
format_text(get_string('mediaformats_desc', 'core_media'), FORMAT_MARKDOWN)));

// External services.
$temp->add(new admin_setting_configcheckbox('core_media_enable_youtube',
get_string('siteyoutube', 'core_media'), get_string('siteyoutube_desc', 'core_media'), 1));
$temp->add(new admin_setting_configcheckbox('core_media_enable_vimeo',
get_string('sitevimeo', 'core_media'), get_string('sitevimeo_desc', 'core_media'), 0));

// Options which require Flash.
$temp->add(new admin_setting_configcheckbox('core_media_enable_mp3',
get_string('mp3audio', 'core_media'), get_string('mp3audio_desc', 'core_media'), 1));
$temp->add(new admin_setting_configcheckbox('core_media_enable_flv',
get_string('flashvideo', 'core_media'), get_string('flashvideo_desc', 'core_media'), 1));
$temp->add(new admin_setting_configcheckbox('core_media_enable_swf',
get_string('flashanimation', 'core_media'), get_string('flashanimation_desc', 'core_media'), 1));

// HTML 5 media.
// Audio now enabled by default so that it can provide a fallback for mp3 on devices without flash.
$temp->add(new admin_setting_configcheckbox('core_media_enable_html5audio',
get_string('html5audio', 'core_media'), get_string('html5audio_desc', 'core_media'), 1));
// Video now enabled by default so it can provide mp4 support.
$temp->add(new admin_setting_configcheckbox('core_media_enable_html5video',
get_string('html5video', 'core_media'), get_string('html5video_desc', 'core_media'), 1));

// Legacy players.
$temp->add(new admin_setting_heading('legacymediaformats',
get_string('legacyheading', 'core_media'), get_string('legacyheading_desc', 'core_media')));

$temp->add(new admin_setting_configcheckbox('core_media_enable_qt',
get_string('legacyquicktime', 'core_media'), get_string('legacyquicktime_desc', 'core_media'), 1));
$temp->add(new admin_setting_configcheckbox('core_media_enable_wmp',
get_string('legacywmp', 'core_media'), get_string('legacywmp_desc', 'core_media'), 1));
$temp->add(new admin_setting_configcheckbox('core_media_enable_rm',
get_string('legacyreal', 'core_media'), get_string('legacyreal_desc', 'core_media'), 1));

$ADMIN->add('appearance', $temp);


// "documentation" settingpage
$temp = new admin_settingpage('documentation', new lang_string('moodledocs'));
$temp->add(new admin_setting_configtext('docroot', new lang_string('docroot', 'admin'), new lang_string('configdocroot', 'admin'), 'http://docs.moodle.org', PARAM_URL));
Expand Down
1 change: 0 additions & 1 deletion filter/mediaplugin/db/install.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down
21 changes: 21 additions & 0 deletions filter/mediaplugin/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,26 @@ function xmldb_filter_mediaplugin_upgrade($oldversion) {
$dbman = $DB->get_manager();


if ($oldversion < 2011121200) {
// Move all the media enable setttings that are now handled by core media renderer.
foreach (array('html5video', 'html5audio', 'mp3', 'flv', 'wmp', 'qt', 'rm',
'youtube', 'vimeo', 'swf') as $type) {
$existingkey = 'filter_mediaplugin_enable_' . $type;
if (array_key_exists($existingkey, $CFG)) {
set_config('core_media_enable_' . $type, $CFG->{$existingkey});
unset_config($existingkey);
}
}

// Override setting for html5 to turn it on (previous default was off; because
// of changes in the way fallbacks are handled, this is now unlikely to cause
// a problem, and is required for mobile a/v support on non-Flash devices, so
// this change is basically needed in order to maintain existing behaviour).
set_config('core_media_enable_html5video', 1);
set_config('core_media_enable_html5audio', 1);

upgrade_plugin_savepoint(true, 2011121200, 'filter', 'mediaplugin');
}

return true;
}
173 changes: 173 additions & 0 deletions filter/mediaplugin/dev/perftest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Media filter performance test script.
*
* For developer test usage only. This can be used to compare performance if
* there are changes to the system in future.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package filter_mediaplugin
*/

require(dirname(__FILE__) . '/../../../config.php');
require_once($CFG->dirroot . '/filter/mediaplugin/filter.php');

// Only available to site admins.
require_login();
if (!is_siteadmin()) {
print_error('nopermissions', 'error', '', 'perftest');
}

// Set up page.
$PAGE->set_context(context_system::instance());
$PAGE->set_url(new moodle_url('/filter/mediaplugin/perftest.php'));
$PAGE->set_heading($SITE->fullname);
print $OUTPUT->header();

// Hack setup to enable all players.
$CFG->core_media_enable_youtube = 1;
$CFG->core_media_enable_vimeo = 1;
$CFG->core_media_enable_mp3 = 1;
$CFG->core_media_enable_flv = 1;
$CFG->core_media_enable_swf = 1;
$CFG->core_media_enable_html5audio = 1;
$CFG->core_media_enable_html5video = 1;
$CFG->core_media_enable_qt = 1;
$CFG->core_media_enable_wmp = 1;
$CFG->core_media_enable_rm = 1;

$CFG->filter_mediaplugin_enable_youtube = 1;
$CFG->filter_mediaplugin_enable_vimeo = 1;
$CFG->filter_mediaplugin_enable_mp3 = 1;
$CFG->filter_mediaplugin_enable_flv = 1;
$CFG->filter_mediaplugin_enable_swf = 1;
$CFG->filter_mediaplugin_enable_html5audio = 1;
$CFG->filter_mediaplugin_enable_html5video = 1;
$CFG->filter_mediaplugin_enable_qt = 1;
$CFG->filter_mediaplugin_enable_wmp = 1;
$CFG->filter_mediaplugin_enable_rm = 1;

// Create plugin.
$filterplugin = new filter_mediaplugin(null, array());

// Note: As this is a developer test page, language strings are not used: all
// text is English-only.

/**
* Starts time counter.
*/
function filter_mediaplugin_perf_start() {
global $filter_mediaplugin_starttime;
$filter_mediaplugin_starttime = microtime(true);
}

/**
* Ends and displays time counter.
* @param string $name Counter name to display
*/
function filter_mediaplugin_perf_stop($name) {
global $filter_mediaplugin_starttime;
$time = microtime(true) - $filter_mediaplugin_starttime;

echo html_writer::tag('li', $name . ': ' . html_writer::tag('strong', round($time, 2)) . 'ms');
}

// 1) Some sample text strings.
// Note: These are from a random sample of real forum data. Just in case there
// are any privacy concerns I have altered names as may be clear.
$samples = array(
"<p>Hi,</p>&#13;\n<p>I've got myself 2 Heaney's \"The Burial at Thebes\"</p>",
"best mark iv heard so far v v good",
"<p>I have a script draft anyone want to look at it?",
"<p>Thanks for your input Legolas and Ghimli!</p>",
"<p>Just to say that I'm thinking of those of you who are working on TMA02.</p>",
"<p><strong>1.</strong> <strong>If someone asks you 'where do you come from?'</strong></p>",
"<p>With regards to Aragorn's question 'what would we do different'?</p>&#13;\n",
"<p>Just thought I'd drop a line to see how everyone is managing generally?</p>&#13;\n",
"<p>Feb '12 - Oct '12  AA100</p>&#13;\n<p>Nov '12 - April '13 - A150</p>&#13;\n",
"<p>So where does that leave the bible???</p>",
);

// 2) Combine sample text strings into one really big (20KB) string.
$length = 0;
$bigstring = '';
$index = 0;
while ($length < 20 * 1024) {
$bigstring .= $samples[$index];
$length += strlen($samples[$index]);
$index++;
if ($index >= count($samples)) {
$index = 0;
}
}

// 3) Make random samples from this. I did the following stats on recent forum
// posts:
// 0-199 characters approx 30%
// 200-1999 approx 60%
// 2000-19999 approx 10%.

$samplebank = array();
foreach (array(100 => 300, 1000 => 600, 10000 => 100) as $chars => $num) {
for ($i = 0; $i < $num; $i++) {
$start = rand(0, $length - $chars - 1);
$samplebank[] = substr($bigstring, $start, $chars);
}
}

echo html_writer::start_tag('ul');

// First test: filter text that doesn't have any links.
filter_mediaplugin_perf_start();
foreach ($samplebank as $sample) {
$filterplugin->filter($sample);
}
filter_mediaplugin_perf_stop('No links');

// Second test: filter text with one link added (that doesn't match).
$link = '<a href="http://www.example.org/another/link/">Link</a>';
$linksamples = array();
foreach ($samplebank as $sample) {
// Make it the same length but with $link replacing the end part.
$linksamples[] = substr($sample, 0, -strlen($link)) . $link;
}

filter_mediaplugin_perf_start();
foreach ($linksamples as $sample) {
$filterplugin->filter($sample);
}
filter_mediaplugin_perf_stop('One link (no match)');

// Third test: filter text with one link added that does match (mp3).
$link = '<a href="http://www.example.org/another/file.mp3">MP3 audio</a>';
$linksamples = array();
foreach ($samplebank as $sample) {
// Make it the same length but with $link replacing the end part.
$linksamples[] = substr($sample, 0, -strlen($link)) . $link;
}

filter_mediaplugin_perf_start();
foreach ($linksamples as $sample) {
$filterplugin->filter($sample);
}
filter_mediaplugin_perf_stop('One link (mp3)');

// End page.
echo html_writer::end_tag('ul');
print $OUTPUT->footer();
Loading

0 comments on commit daefd6e

Please sign in to comment.