MDL-30303 fix media playback from URLs with ? query parts

Credit for the rawurlencode() fix goes to Eloy.
This commit is contained in:
Petr Skoda 2011-11-19 18:15:18 +01:00
parent fe41ba7489
commit 7f86bee330
2 changed files with 30 additions and 8 deletions

View file

@ -171,10 +171,32 @@ class filter_mediaplugin extends moodle_text_filter {
///=========================== ///===========================
/// utility functions /// utility functions
/**
* Get mimetype of given url, useful for # alternative urls.
*
* @private
* @param string $url
* @return string $mimetype
*/
function filter_mediaplugin_get_mimetype($url) {
$matches = null;
if (preg_match("|^(.*)/[a-z]*file.php(\?file=)?(/[^&\?#]*)|", $url, $matches)) {
// remove the special moodle file serving hacks so that the *file.php is ignored
$url = $matches[1].$matches[3];
} else {
$url = preg_replace('/[#\?].*$/', '', $url);
}
$mimetype = mimeinfo('type', $url);
return $mimetype;
}
/** /**
* Parse list of alternative URLs * Parse list of alternative URLs
* @param string $url urls separated with '#', size specified as ?d=640x480 or #d=640x480 * @param string $url urls separated with '#', size specified as ?d=640x480 or #d=640x480
* @param int $defaultwidth
* @param int $defaultheight
* @return array (urls, width, height) * @return array (urls, width, height)
*/ */
function filter_mediaplugin_parse_alternatives($url, $defaultwidth = 0, $defaultheight = 0) { function filter_mediaplugin_parse_alternatives($url, $defaultwidth = 0, $defaultheight = 0) {
@ -252,7 +274,7 @@ function filter_mediaplugin_html5audio_callback(array $link) {
$fallbacklink = null; $fallbacklink = null;
foreach ($urls as $url) { foreach ($urls as $url) {
$mimetype = mimeinfo('type', $url); $mimetype = filter_mediaplugin_get_mimetype($url);
if (strpos($mimetype, 'audio/') !== 0) { if (strpos($mimetype, 'audio/') !== 0) {
continue; continue;
} }
@ -344,7 +366,7 @@ function filter_mediaplugin_html5video_callback(array $link) {
$fallbacklink = null; $fallbacklink = null;
foreach ($urls as $url) { foreach ($urls as $url) {
$mimetype = mimeinfo('type', $url); $mimetype = filter_mediaplugin_get_mimetype($url);
if (strpos($mimetype, 'video/') !== 0) { if (strpos($mimetype, 'video/') !== 0) {
continue; continue;
} }
@ -546,7 +568,7 @@ function filter_mediaplugin_flv_callback($link) {
$sources = array(); $sources = array();
foreach ($urls as $url) { foreach ($urls as $url) {
$mimetype = mimeinfo('type', $url); $mimetype = filter_mediaplugin_get_mimetype($url);
if (strpos($mimetype, 'video/') !== 0) { if (strpos($mimetype, 'video/') !== 0) {
continue; continue;
} }
@ -559,7 +581,7 @@ function filter_mediaplugin_flv_callback($link) {
} }
if ($flashurl === null) { if ($flashurl === null) {
$flashurl = str_replace('&', '&', $url); $flashurl = $url;
} }
} }
if (!$sources) { if (!$sources) {
@ -592,7 +614,7 @@ OET;
// note: no need to print "this is flv link" because it is printed automatically if JS or Flash not available // note: no need to print "this is flv link" because it is printed automatically if JS or Flash not available
$output = html_writer::tag('span', $printlink, array('id'=>$id, 'class'=>'mediaplugin mediaplugin_flv')); $output = html_writer::tag('span', $printlink, array('id'=>$id, 'class'=>'mediaplugin mediaplugin_flv'));
$output .= html_writer::script(js_writer::function_call('M.util.add_video_player', array($id, $flashurl, $width, $height, $autosize))); // we can not use standard JS init because this may be cached $output .= html_writer::script(js_writer::function_call('M.util.add_video_player', array($id, rawurlencode($flashurl), $width, $height, $autosize))); // we can not use standard JS init because this may be cached
return $output; return $output;
} }
@ -799,7 +821,7 @@ function filter_mediaplugin_wmp_callback($link) {
$mpsize = 'width="'.$link[4].'" height="'.($link[5] + 64).'"'; $mpsize = 'width="'.$link[4].'" height="'.($link[5] + 64).'"';
$autosize = 'false'; $autosize = 'false';
} }
$mimetype = mimeinfo('type', $url); $mimetype = filter_mediaplugin_get_mimetype($url);
@ -861,7 +883,7 @@ function filter_mediaplugin_qt_callback($link) {
} else { } else {
$size = 'width="'.$link[4].'" height="'.($link[5]+15).'"'; $size = 'width="'.$link[4].'" height="'.($link[5]+15).'"';
} }
$mimetype = mimeinfo('type', $url); $mimetype = filter_mediaplugin_get_mimetype($url);
// this is the safest fallback for incomplete or missing browser support for this format // this is the safest fallback for incomplete or missing browser support for this format
return <<<OET return <<<OET

View file

@ -280,7 +280,7 @@ function resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen) {
} }
$output = '<div class="resourcecontent resourceflv">'; $output = '<div class="resourcecontent resourceflv">';
$output .= html_writer::tag('span', $clicktoopen, array('id'=>$id, 'class'=>'resourcemediaplugin resourcemediaplugin_flv', 'title'=>$title)); $output .= html_writer::tag('span', $clicktoopen, array('id'=>$id, 'class'=>'resourcemediaplugin resourcemediaplugin_flv', 'title'=>$title));
$output .= html_writer::script(js_writer::function_call('M.util.add_video_player', array($id, $fullurl, $width, $height, $autosize))); $output .= html_writer::script(js_writer::function_call('M.util.add_video_player', array($id, rawurlencode($fullurl), $width, $height, $autosize)));
$output .= '</div>'; $output .= '</div>';
return $output; return $output;