create youtube playlist filter. Fixed regex, removed addslash_js, use variable param...
authorRossiani Wijaya <rwijaya@moodle.com>
Mon, 31 Jan 2011 07:03:58 +0000 (15:03 +0800)
committerRossiani Wijaya <rwijaya@moodle.com>
Mon, 31 Jan 2011 07:03:58 +0000 (15:03 +0800)
filter/mediaplugin/filter.php

index 59d8151..6a9ec85 100644 (file)
@@ -125,6 +125,9 @@ class filter_mediaplugin extends moodle_text_filter {
 
             $search = '/<a[^>]*href="([^<]*)youtube.com\/v\/([^"]*)"[^>]*>(.*?)<\/a>/is';
             $newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_callback', $newtext);
+
+            $search = '/<a(\s+[^>]+?)?\s+href="((([^"]+)youtube\.com)\/view_play_list\?p=([^"]*))"[^>]*>(.*?)<\/a>/is';
+            $newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_playlist_callback', $newtext);
         }
 
         if (!empty($CFG->filter_mediaplugin_enable_img)) {
@@ -349,6 +352,25 @@ function filter_mediaplugin_youtube_callback($link, $autostart=false) {
            '</object>';
 }
 
+/**
+ * Change Youtube playlist into embedded Youtube playlist videos
+ */
+function filter_mediaplugin_youtube_playlist_callback($link, $autostart=false) {
+
+    $site = s($link[4]);
+    $param = s($link[5]);
+    $info = s($link[6]);
+
+    return '<object title="'.$info.'"
+                    class="mediaplugin mediaplugin_youtube" type="application/x-shockwave-flash"
+                    data="'.$site.'youtube.com/p/'.$param.'&amp;fs=1&amp;rel=0" width="400" height="320">'.
+           '<param name="movie" value="'.$site.'youtube.com/p/'.$param.'&amp;fs=1&amp;rel=0" />'.
+           '<param name="FlashVars" value="playerMode=embedded" />'.
+           '<param name="wmode" value="transparent" />'.
+           '<param name="allowFullScreen" value="true" />'.
+           '</object>';
+}
+
 /**
  * Change links to images into embedded images
  */