Index: weblib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/weblib.php,v
retrieving revision 1.970.2.126
diff -u -r1.970.2.126 weblib.php
--- weblib.php	17 Jan 2009 18:09:38 -0000	1.970.2.126
+++ weblib.php	19 Jan 2009 11:28:32 -0000
@@ -2005,6 +2005,24 @@
                 $text = preg_replace('/(&#[0-9]+)(;?)/', "\\1;", $text);
                 $text = preg_replace('/(&#x[0-9a-fA-F]+)(;?)/', "\\1;", $text);
 
+                if ( $CFG->allowvideoembedding ) {
+                    // youtube
+                    $pre_regex = '#<object[^>]+>.+?'.
+                        'http://www.youtube.com/v/([A-Za-z0-9\-_]+).+</object>#s';
+                    $pre_replace = '<span class="youtube-embed">\1</span>';
+                    $text = preg_replace($pre_regex, $pre_replace, $text);
+
+                    // googlevideo
+                    $pre_regex   = '#<embed [^>]+src="http://video.google.es/googleplayer.swf\?docid=(-?[0-9]+)([^/>]|/[^>])+(/>|>[^>]*</embed>)#s';
+                    $pre_replace = '<span class="googlevideo-embed">\1</span>';
+                    $text = preg_replace($pre_regex, $pre_replace, $text);
+
+                    // teachertube
+                    $pre_regex = '#<embed [^>]+file=http://www.teachertube.com/flvideo/([0-9]+)\.flv([^/>]|/[^>])+(/>|>[^>]*</embed>)#s';
+                    $pre_replace = '<span class="teachertube-embed">\1</span>';
+                    $text = preg_replace($pre_regex, $pre_replace, $text);
+                }
+
             /// Remove tags that are not allowed
                 $text = strip_tags($text, $ALLOWED_TAGS);
 
@@ -2014,6 +2032,34 @@
             /// Again remove tags that are not allowed
                 $text = strip_tags($text, $ALLOWED_TAGS);
 
+                if ( $CFG->allowvideoembedding ) {
+                    // youtube
+                    $post_regex = '#<span class="youtube-embed">([A-Za-z0-9\-_]+)</span>#';
+                    $post_replace = '<object width="425" height="350" '.
+                        'data="http://www.youtube.com/v/\1">'.
+                        '<param name="movie" value="http://www.youtube.com/v/\1"></param>'.
+                        '<param name="wmode" value="transparent"></param>'.
+                        '<!--[if IE]>'.
+                        '<embed src="http://www.youtube.com/v/\1"'.
+                        'type="application/x-shockwave-flash"'.
+                        'wmode="transparent" width="425"
+                        height="350" />'.
+                        '<![endif]-->'.
+                        '</object>';
+                    $text = preg_replace($post_regex, $post_replace, $text);
+
+                    // googlevideo
+                    $post_regex = '#<span class="googlevideo-embed">(-?[0-9]+)</span>#';
+                    $post_replace = '<embed id="VideoPlayback" src="http://video.google.es/googleplayer.swf?docid=\1&hl=en" style="width:425px;height:350px" allowFullScreen="true" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>';
+                    $text = preg_replace($post_regex, $post_replace, $text);
+
+                    // teachertube
+                    $post_regex = '#<span class="teachertube-embed">([0-9]+)</span>#';
+                    $post_replace = '<embed src="http://www.teachertube.com/player/search/mediaplayer.swf" width="425" height="350"
+                        type="application/x-shockwave-flash" allowfullscreen="true"
+                        flashvars="height=350&width=425&file=http://www.teachertube.com/flvideo/\1.flv&autostart=false&overstretch=fit"></embed>';
+                    $text = preg_replace($post_regex, $post_replace, $text);
+                }
             }
 
         /// Remove potential script events - some extra protection for undiscovered bugs in our code

