Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-34997-master' of git://github.com/FMCorz/moodle

  • Loading branch information...
commit 4bab07c68c68cbf0bfdcd36753e90db30b45fbaf 2 parents 5c27678 + 1ba43a9
@stronk7 stronk7 authored
Showing with 14 additions and 7 deletions.
  1. +3 −0  filter/mediaplugin/tests/filter_test.php
  2. +11 −7 lib/medialib.php
View
3  filter/mediaplugin/tests/filter_test.php
@@ -57,6 +57,9 @@ function test_filter_mediaplugin_link() {
'<a id="movie player" class="center" href="http://moodle.org/testfile/test.mpg">test mpg</a>',
'<a href="http://moodle.org/testfile/test.ram">test</a>',
'<a href="http://www.youtube.com/watch?v=JghQgA2HMX8" class="href=css">test file</a>',
+ '<a href="http://www.youtube-nocookie.com/watch?v=JghQgA2HMX8" class="href=css">test file</a>',
+ '<a href="http://youtu.be/JghQgA2HMX8" class="href=css">test file</a>',
+ '<a href="http://y2u.be/JghQgA2HMX8" class="href=css">test file</a>',
'<a class="youtube" href="http://www.youtube.com/watch?v=JghQgA2HMX8">test file</a>',
'<a class="_blanktarget" href="http://moodle.org/testfile/test.flv?d=100x100">test flv</a>',
'<a class="hrefcss" href="http://www.youtube.com/watch?v=JghQgA2HMX8">test file</a>',
View
18 lib/medialib.php
@@ -526,8 +526,7 @@ public function get_embeddable_markers() {
*/
class core_media_player_youtube extends core_media_player_external {
protected function embed_external(moodle_url $url, $name, $width, $height, $options) {
- $site = $this->matches[1];
- $videoid = $this->matches[3];
+ $videoid = end($this->matches);
$info = trim($name);
if (empty($info) or strpos($info, 'http') === 0) {
@@ -540,17 +539,22 @@ protected function embed_external(moodle_url $url, $name, $width, $height, $opti
return <<<OET
<span class="mediaplugin mediaplugin_youtube">
<iframe title="$info" width="$width" height="$height"
- src="https://$site/embed/$videoid?rel=0&wmode=transparent" frameborder="0" allowfullscreen="1"></iframe>
+ src="https://www.youtube.com/embed/$videoid?rel=0&wmode=transparent" frameborder="0" allowfullscreen="1"></iframe>
</span>
OET;
}
protected function get_regex() {
+ // Regex for standard youtube link
+ $link = '(youtube(-nocookie)?\.com/(?:watch\?v=|v/))';
+ // Regex for shortened youtube link
+ $shortlink = '((youtu|y2u)\.be/)';
+
// Initial part of link.
- $start = '~^https?://(www\.youtube(-nocookie)?\.com)/';
- // Middle bit: either watch?v= or v/.
- $middle = '(?:watch\?v=|v/)([a-z0-9\-_]+)';
+ $start = '~^https?://(www\.)?(' . $link . '|' . $shortlink . ')';
+ // Middle bit: Video key value
+ $middle = '([a-z0-9\-_]+)';
return $start . $middle . core_media_player_external::END_LINK_REGEX_PART;
}
@@ -561,7 +565,7 @@ public function get_rank() {
}
public function get_embeddable_markers() {
- return array('youtube');
+ return array('youtube.com', 'youtube-nocookie.com', 'youtu.be', 'y2u.be');
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.