From: skodak Date: Mon, 19 Mar 2007 08:09:09 +0000 (+0000) Subject: MDL-8957 Multimedia filter cleanup; merged from MOODLE_18_STABLE X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7e64d36193d241c4b82404a3d467d2525c9a03fb;p=moodle.git MDL-8957 Multimedia filter cleanup; merged from MOODLE_18_STABLE --- diff --git a/filter/mediaplugin/filter.php b/filter/mediaplugin/filter.php index e109295fcd..e5de22f6ea 100644 --- a/filter/mediaplugin/filter.php +++ b/filter/mediaplugin/filter.php @@ -1,8 +1,8 @@ -libdir.'/filelib.php'); + function mediaplugin_filter($courseid, $text) { - global $CFG, $THEME; + global $CFG; - static $count = 0; + include 'defaultsettings.php'; - $count++; - - include "defaultsettings.php"; + // We're using the UFO technique for flash to attain XHTML Strict 1.0 + // See: http://www.bobbyvandersluis.com/ufo/ if ($CFG->filter_mediaplugin_enable_mp3) { - static $c; - - if (empty($c)) { - 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&'; - } - } - $search = '/]*)>(.*?)<\/a>/is'; - - // We're using the UFO technique to attain XHTML Strict 1.0 - // See: http://www.bobbyvandersluis.com/ufo/ - - $replace = ''."\n". - '\\0 '. - '('.get_string('mp3audio', 'mediaplugin').')'. - ''."\n"; - - $text = preg_replace($search, $replace, $text); + $search = '/]*>.*?<\/a>/is'; + $text = preg_replace_callback($search, 'mediaplugin_filter_mp3_callback', $text); } if ($CFG->filter_mediaplugin_enable_swf) { - $search = array( - '/]*)>(.*?)<\/a>/is', - '/]*)>(.*?)<\/a>/is' - ); - - $replace = array(); - - $replace[0] = ''."\n". - '\\0 '. - '('.get_string('flashanimation', 'mediaplugin').')'. - ''."\n"; - - $replace[1] = ''."\n". - '\\0 '. - '('.get_string('flashanimation', 'mediaplugin').')'. - ''."\n"; - - $text = preg_replace($search, $replace, $text); - + $search = '/]*>.*?<\/a>/is'; + $text = preg_replace_callback($search, 'mediaplugin_filter_swf_callback', $text); } if ($CFG->filter_mediaplugin_enable_flv) { - - $replace = array(); - - $search = array( - '/]*)>(.*?)<\/a>/is', - '/]*)>(.*?)<\/a>/is' - ); - - $replace[0] = ''."\n". - '\\0 '. - '('.get_string('flashvideo', 'mediaplugin').')'. - ''."\n"; - - $replace[1] = ''."\n". - '\\0 '. - '('.get_string('flashvideo', 'mediaplugin').')'. - ''."\n"; - - $text = preg_replace($search, $replace, $text); + $search = '/]*>.*?<\/a>/is'; + $text = preg_replace_callback($search, 'mediaplugin_filter_flv_callback', $text); } if ($CFG->filter_mediaplugin_enable_mov) { - $search = '/]*)>(.*?)<\/a>/is'; - - $replace = '\\0

filter_mediaplugin_enable_wmv) { - $search = '/]*)>(.*?)<\/a>/is'; - - $replace = '\\0

filter_mediaplugin_enable_mpg) { - $search = '/]*)>(.*?)<\/a>/is'; - - $replace = '\\0

'; - $replace .= ''; - $replace .= ''; - $replace .= ''; - $replace .= '

'; - - $text = preg_replace($search, $replace, $text); + $search = '/]*>.*?<\/a>/is'; + $text = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $text); } if ($CFG->filter_mediaplugin_enable_avi) { - $search = '/]*)>(.*?)<\/a>/is'; - - $replace = '\\0

'; - $replace .= ''; - $replace .= ''; - $replace .= ''; - $replace .= '

'; - - $text = preg_replace($search, $replace, $text); + $search = '/]*>.*?<\/a>/is'; + $text = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $text); } - + if ($CFG->filter_mediaplugin_enable_ram) { - $search = '/]*)>(.*?)<\/a>/is'; - - $replace = '\\0

'; - - $text = preg_replace($search, $replace, $text); + $search = '/]*>.*?<\/a>/is'; + $text = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $text); } - + if ($CFG->filter_mediaplugin_enable_rpm) { - $search = '/]*)>(.*?)<\/a>/is'; - - $replace = '\\0

'; - - $text = preg_replace($search, $replace, $text); + $search = '/]*>.*?<\/a>/is'; + $text = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $text); } - + if ($CFG->filter_mediaplugin_enable_rm) { - $search = '/]*)>(.*?)<\/a>/is'; - - $replace = '\\0

'; - - $text = preg_replace($search, $replace, $text); + $search = '/]*>.*?<\/a>/is'; + $text = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $text); } return $text; } +///=========================== +/// 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'; + } + $c = htmlentities($c); + + 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]. +' +'; +} + +/** + * 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]. +' + + + + + + + + + + + + + + + + + + + +'; +} ?> diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 87b181b03e..30bf3747d6 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -703,6 +703,24 @@ table.navbar { margin-left:10px; } +/*** + *** Filters + ***/ +span.mediaplugin { + display:block; + clear:both; + margin-top:5px; + margin-bottom:5px; +} + +span.mediaplugin_mp3 { + display:inline; + clear:none; + margin:0px; + margin-left:0.5em; +} + + /*** *** Admin ***/