forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-29624 Media embedding system, part 1: new API and filter changes
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
1 parent
ffe4de9
commit daefd6e
Showing
17 changed files
with
2,462 additions
and
925 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> \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> \n", | ||
"<p>Just thought I'd drop a line to see how everyone is managing generally?</p> \n", | ||
"<p>Feb '12 - Oct '12 AA100</p> \n<p>Nov '12 - April '13 - A150</p> \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(); |
Oops, something went wrong.