Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

Credit for the rawurlencode() fix goes to Eloy.
  • Loading branch information...
commit 9599370dff25948d5dc15792339a1f8e49f87932 1 parent d81e6cc
Petr Škoda authored November 19, 2011 samhemelryk committed November 23, 2011
36  filter/mediaplugin/filter.php
@@ -171,10 +171,32 @@ function filter($text, array $options = array()) {
171 171
 ///===========================
172 172
 /// utility functions
173 173
 
  174
+/**
  175
+ * Get mimetype of given url, useful for # alternative urls.
  176
+ *
  177
+ * @private
  178
+ * @param string $url
  179
+ * @return string $mimetype
  180
+ */
  181
+function filter_mediaplugin_get_mimetype($url) {
  182
+    $matches = null;
  183
+    if (preg_match("|^(.*)/[a-z]*file.php(\?file=)?(/[^&\?#]*)|", $url, $matches)) {
  184
+        // remove the special moodle file serving hacks so that the *file.php is ignored
  185
+        $url = $matches[1].$matches[3];
  186
+    } else {
  187
+        $url = preg_replace('/[#\?].*$/', '', $url);
  188
+    }
  189
+
  190
+    $mimetype = mimeinfo('type', $url);
  191
+
  192
+    return $mimetype;
  193
+}
174 194
 
175 195
 /**
176 196
  * Parse list of alternative URLs
177 197
  * @param string $url urls separated with '#', size specified as ?d=640x480 or #d=640x480
  198
+ * @param int $defaultwidth
  199
+ * @param int $defaultheight
178 200
  * @return array (urls, width, height)
179 201
  */
180 202
 function filter_mediaplugin_parse_alternatives($url, $defaultwidth = 0, $defaultheight = 0) {
@@ -252,7 +274,7 @@ function filter_mediaplugin_html5audio_callback(array $link) {
252 274
     $fallbacklink = null;
253 275
 
254 276
     foreach ($urls as $url) {
255  
-        $mimetype = mimeinfo('type', $url);
  277
+        $mimetype = filter_mediaplugin_get_mimetype($url);
256 278
         if (strpos($mimetype, 'audio/') !== 0) {
257 279
             continue;
258 280
         }
@@ -344,7 +366,7 @@ function filter_mediaplugin_html5video_callback(array $link) {
344 366
     $fallbacklink = null;
345 367
 
346 368
     foreach ($urls as $url) {
347  
-        $mimetype = mimeinfo('type', $url);
  369
+        $mimetype = filter_mediaplugin_get_mimetype($url);
348 370
         if (strpos($mimetype, 'video/') !== 0) {
349 371
             continue;
350 372
         }
@@ -546,7 +568,7 @@ function filter_mediaplugin_flv_callback($link) {
546 568
     $sources  = array();
547 569
 
548 570
     foreach ($urls as $url) {
549  
-        $mimetype = mimeinfo('type', $url);
  571
+        $mimetype = filter_mediaplugin_get_mimetype($url);
550 572
         if (strpos($mimetype, 'video/') !== 0) {
551 573
             continue;
552 574
         }
@@ -559,7 +581,7 @@ function filter_mediaplugin_flv_callback($link) {
559 581
         }
560 582
 
561 583
         if ($flashurl === null) {
562  
-            $flashurl  = str_replace('&', '&', $url);
  584
+            $flashurl  = $url;
563 585
         }
564 586
     }
565 587
     if (!$sources) {
@@ -592,7 +614,7 @@ function filter_mediaplugin_flv_callback($link) {
592 614
     // note: no need to print "this is flv link" because it is printed automatically if JS or Flash not available
593 615
 
594 616
     $output = html_writer::tag('span', $printlink, array('id'=>$id, 'class'=>'mediaplugin mediaplugin_flv'));
595  
-    $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
  617
+    $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
596 618
 
597 619
     return $output;
598 620
 }
@@ -799,7 +821,7 @@ function filter_mediaplugin_wmp_callback($link) {
799 821
         $mpsize = 'width="'.$link[4].'" height="'.($link[5] + 64).'"';
800 822
         $autosize = 'false';
801 823
     }
802  
-    $mimetype = mimeinfo('type', $url);
  824
+    $mimetype = filter_mediaplugin_get_mimetype($url);
803 825
 
804 826
 
805 827
 
@@ -861,7 +883,7 @@ function filter_mediaplugin_qt_callback($link) {
861 883
     } else {
862 884
         $size = 'width="'.$link[4].'" height="'.($link[5]+15).'"';
863 885
     }
864  
-    $mimetype = mimeinfo('type', $url);
  886
+    $mimetype = filter_mediaplugin_get_mimetype($url);
865 887
 
866 888
     // this is the safest fallback for incomplete or missing browser support for this format
867 889
     return <<<OET
2  lib/resourcelib.php
@@ -280,7 +280,7 @@ function resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen) {
280 280
     }
281 281
     $output = '<div class="resourcecontent resourceflv">';
282 282
     $output .= html_writer::tag('span', $clicktoopen, array('id'=>$id, 'class'=>'resourcemediaplugin resourcemediaplugin_flv', 'title'=>$title));
283  
-    $output .= html_writer::script(js_writer::function_call('M.util.add_video_player', array($id, $fullurl, $width, $height, $autosize)));
  283
+    $output .= html_writer::script(js_writer::function_call('M.util.add_video_player', array($id, rawurlencode($fullurl), $width, $height, $autosize)));
284 284
     $output .= '</div>';
285 285
 
286 286
     return $output;

0 notes on commit 9599370

Please sign in to comment.
Something went wrong with that request. Please try again.