libdir.'/filelib.php'); function mediaplugin_filter($courseid, $text) { global $CFG; static $eolas_fix_applied = false; // You should never modify parameters passed to a method or function, it's BAD practice. Create a copy instead. // The reason is that you must always be able to refer to the original parameter that was passed. // For this reason, I changed $text = preg_replace(..,..,$text) into $newtext = preg.... (NICOLAS CONNAULT) // Thanks to Pablo Etcheverry for pointing this out! MDL-10177 // We're using the UFO technique for flash to attain XHTML Strict 1.0 // See: http://www.bobbyvandersluis.com/ufo/ if (!is_string($text)) { // non string data can not be filtered anyway return $text; } $newtext = $text; // fullclone is slow and not needed here if ($CFG->filter_mediaplugin_enable_mp3) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_mp3_callback', $newtext); } if ($CFG->filter_mediaplugin_enable_swf) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_swf_callback', $newtext); } if ($CFG->filter_mediaplugin_enable_flv) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_flv_callback', $newtext); } if ($CFG->filter_mediaplugin_enable_mov) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext); // MDL-18658 $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext); $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext); $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext); } if ($CFG->filter_mediaplugin_enable_wmv) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext); } if ($CFG->filter_mediaplugin_enable_mpg) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext); } if ($CFG->filter_mediaplugin_enable_avi) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext); } if ($CFG->filter_mediaplugin_enable_ram) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext); } if ($CFG->filter_mediaplugin_enable_rpm) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext); } if ($CFG->filter_mediaplugin_enable_rm) { $search = '/]*>.*?<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext); } if (!empty($CFG->filter_mediaplugin_enable_youtube)) { $search = '/]*?href="([^<]*)youtube.com\/watch\?v=([^"]*)"[^>]*>(.*?)<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_youtube_callback', $newtext); $search = '/]*?href="([^<]*)youtube.com\/v\/([^"]*)"[^>]*>(.*?)<\/a>/is'; $newtext = preg_replace_callback($search, 'mediaplugin_filter_youtube_callback', $newtext); } if (is_null($newtext) or $newtext === $text) { // error or not filtered return $text; } if (!$eolas_fix_applied) { $newtext .= ''; $eolas_fix_applied = true; } return $newtext; } ///=========================== /// callback filter functions function mediaplugin_filter_mp3_callback($link) { global $CFG, $THEME; if (!empty($THEME->filter_mediaplugin_colors)) { $c = $THEME->filter_mediaplugin_colors; // You can set this up in your theme/xxx/config.php } else { $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'. 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'. 'waitForPlay=yes'; } static $count = 0; $count++; $id = 'filter_mp3_'.time().$count; //we need something unique because it might be stored in text cache $url = addslashes_js($link[1]); return $link[0]. '('.get_string('mp3audio', 'mediaplugin').') '; } function mediaplugin_filter_swf_callback($link) { static $count = 0; $count++; $id = 'filter_swf_'.time().$count; //we need something unique because it might be stored in text cache $width = empty($link[3]) ? '400' : $link[3]; $height = empty($link[4]) ? '300' : $link[4]; $url = addslashes_js($link[1]); return $link[0]. '('.get_string('flashanimation', 'mediaplugin').') '; } function mediaplugin_filter_flv_callback($link) { global $CFG; static $count = 0; $count++; $id = 'filter_flv_'.time().$count; //we need something unique because it might be stored in text cache $width = empty($link[3]) ? '480' : $link[3]; $height = empty($link[4]) ? '360' : $link[4]; $url = addslashes_js($link[1]); return $link[0]. '('.get_string('flashvideo', 'mediaplugin').') '; } function mediaplugin_filter_real_callback($link, $autostart=false) { $url = addslashes_js($link[1]); $mimetype = mimeinfo('type', $url); $autostart = $autostart ? 'true' : 'false'; // embed kept for now see MDL-8674 return $link[0]. ' '; } /** * Change links to Youtube into embedded Youtube videos */ function mediaplugin_filter_youtube_callback($link, $autostart=false) { $site = addslashes_js($link[1]); $url = addslashes_js($link[2]); $info = addslashes_js($link[3]); return ''. ''. ''. ''. ''. ''; } /** * Embed video using window media player if available */ function mediaplugin_filter_wmp_callback($link, $autostart=false) { $url = $link[1]; if (empty($link[3]) or empty($link[4])) { $mpsize = ''; $size = 'width="300" height="260"'; $autosize = 'true'; } else { $size = 'width="'.$link[3].'" height="'.$link[4].'"'; $mpsize = $size; $autosize = 'false'; } $mimetype = mimeinfo('type', $url); $autostart = $autostart ? 'true' : 'false'; return $link[0]. ' '; } function mediaplugin_filter_qt_callback($link, $autostart=false) { $url = $link[1]; if (empty($link[3]) or empty($link[4])) { $size = 'width="280" height="210"'; } else { $size = 'width="'.$link[3].'" height="'.$link[4].'"'; } $mimetype = mimeinfo('type', $url); $autostart = $autostart ? 'true' : 'false'; return $link[0]. ' '; } ?>