diff --git a/lib/tests/medialib_test.php b/lib/tests/medialib_test.php index 20e5d6d734e..7a0ca53ce7d 100644 --- a/lib/tests/medialib_test.php +++ b/lib/tests/medialib_test.php @@ -413,6 +413,16 @@ class core_medialib_testcase extends advanced_testcase { $this->assertEquals($webm, $result[1]->out(false)); $this->assertEquals(400, $w); $this->assertEquals(280, $h); + + // Support for rtmp. + $rtmp = 'rtmp://rtmpsite.net/somestream'; + $result = $mediamanager->split_alternatives($rtmp, $w, $h); + $this->assertEquals($rtmp, $result[0]->out(false)); + + // Invalid URL is not supported. + $invalid = 'mailto:user@example.com'; + $result = $mediamanager->split_alternatives($invalid, $w, $h); + $this->assertEmpty($result); } /** diff --git a/media/classes/manager.php b/media/classes/manager.php index cab7edb7586..71c268977ed 100644 --- a/media/classes/manager.php +++ b/media/classes/manager.php @@ -425,11 +425,17 @@ final class core_media_manager { $url = str_replace($matches[0], '', $url); } - // Clean up url. + // Clean up url. Allow rtmp:// protocol even though it's not allowed by clean_param(..., PARAM_URL). + if ($isrtmp = preg_match('|^(rtmp://)(.*)$|i', trim($url), $matches)) { + $url = "http://" . $matches[2]; + } $url = clean_param($url, PARAM_URL); if (empty($url)) { continue; } + if ($isrtmp) { + $url = preg_replace('|^http://|', $matches[1], $url); + } // Turn it into moodle_url object. $returnurls[] = new moodle_url($url);