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

This commit is contained in:
Eloy Lafuente (stronk7) 2012-09-05 00:52:17 +02:00
commit 4bab07c68c
2 changed files with 14 additions and 7 deletions

View File

@ -57,6 +57,9 @@ class filter_mediaplugin_testcase extends advanced_testcase {
'<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 File

@ -526,8 +526,7 @@ OET;
*/
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 @@ class core_media_player_youtube extends core_media_player_external {
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 @@ OET;
}
public function get_embeddable_markers() {
return array('youtube');
return array('youtube.com', 'youtube-nocookie.com', 'youtu.be', 'y2u.be');
}
}