Permalink
Browse files

MDL-34997 - Allow shortened url youtu.be and y2u.be for Youtube filter

  • Loading branch information...
1 parent 8f3c8e7 commit 1a73d34c10643d0b997836641afe1393dae666b8 @gaudreaj gaudreaj committed with FMCorz Aug 22, 2012
Showing with 18 additions and 0 deletions.
  1. +15 −0 filter/mediaplugin/filter.php
  2. +3 −0 filter/mediaplugin/simpletest/testfiltermediaplugin.php
@@ -90,6 +90,9 @@ function filter($text, array $options = array()) {
$search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/v\/([a-z0-9\-_]+)[^"#]*(#d=([\d]{1,4})x([\d]{1,4}))?[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_callback', $newtext);
+ $search = '/<a\s[^>]*href="(https?:\/\/(www\.)?(youtu|y2u)\.be)\/([a-z0-9\-_]+)"[^>]*>([^>]*)<\/a>/is';
+ $newtext = preg_replace_callback($search, 'filter_mediaplugin_shortened_youtube_callback', $newtext);
+
$search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/view_play_list\?p=([a-z0-9\-_]+)[^"#]*(#d=([\d]{1,4})x([\d]{1,4}))?[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_playlist_callback', $newtext);
@@ -758,6 +761,18 @@ function filter_mediaplugin_youtube_playlist_callback($link) {
return $output;
}
+/**
+ * Change shortened links to YouTube into embedded YouTube videos
+ *
+ * @param $link
+ * @return string
+ */
+function filter_mediaplugin_shortened_youtube_callback($link) {
+ $newlink = array($link[0], 'https://www.youtube.com','',$link[4],'','','',$link[5]);
+ return filter_mediaplugin_youtube_callback($newlink);
+}
+
+
/**
* Change links to Vimeo into embedded Vimeo videos
*
@@ -58,7 +58,10 @@ 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 class="youtube" href="http://www.youtube.com/watch?v=JghQgA2HMX8">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="_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>',
'<a class="content" href="http://moodle.org/testfile/test.avi">test mp3</a>',

0 comments on commit 1a73d34

Please sign in to comment.