Skip to content

Commit

Permalink
MDL-23870: Replace flash and mp3 multimedia filter with flowplayer.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwijaya committed Sep 9, 2010
1 parent b95e743 commit 3a42ad1
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 90 deletions.
109 changes: 69 additions & 40 deletions filter/mediaplugin/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,61 +49,61 @@ function filter($text) {
$newtext = $text; // fullclone is slow and not needed here

if ($CFG->filter_mediaplugin_enable_mp3) {
$search = '/<a.*?href="([^<]+\.mp3)"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.mp3)"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_mp3_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_swf) {
$search = '/<a.*?href="([^<]+\.swf)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.swf)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_swf_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_flv) {
$search = '/<a.*?href="([^<]+\.flv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.flv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_flv_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_mov) {
$search = '/<a.*?href="([^<]+\.mov)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.mov)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);

$search = '/<a.*?href="([^<]+\.mp4)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.mp4)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);

$search = '/<a.*?href="([^<]+\.m4v)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.m4v)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);

$search = '/<a.*?href="([^<]+\.m4a)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.m4a)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_wmv) {
$search = '/<a.*?href="([^<]+\.wmv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.wmv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_wmp_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_mpg) {
$search = '/<a.*?href="([^<]+\.mpe?g)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.mpe?g)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_avi) {
$search = '/<a.*?href="([^<]+\.avi)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.avi)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_wmp_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_ram) {
$search = '/<a.*?href="([^<]+\.ram)"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.ram)"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_real_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_rpm) {
$search = '/<a.*?href="([^<]+\.rpm)"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.rpm)"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_real_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_rm) {
$search = '/<a.*?href="([^<]+\.rm)"[^>]*>.*?<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.rm)"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_real_callback', $newtext);
}

Expand All @@ -118,11 +118,11 @@ function filter($text) {
}

if (!empty($CFG->filter_mediaplugin_enable_img)) {
$search = '/<a.*?href="([^<]+\.jpg)"[^>]*>(.*?)<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.jpg)"[^>]*>(.*?)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_img_callback', $newtext);
$search = '/<a.*?href="([^<]+\.png)"[^>]*>(.*?)<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.png)"[^>]*>(.*?)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_img_callback', $newtext);
$search = '/<a.*?href="([^<]+\.gif)"[^>]*>(.*?)<\/a>/is';
$search = '/<a[^>]*?href="([^<]+\.gif)"[^>]*>(.*?)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_img_callback', $newtext);
}

Expand Down Expand Up @@ -155,18 +155,42 @@ function filter_mediaplugin_mp3_callback($link) {

$url = addslashes_js($link[1]);

$args = Array();
$args['movie'] = $CFG->wwwroot.'/filter/mediaplugin/mp3player.swf?src='.$url;
$args['width'] = 90;
$args['height'] = 15;
$args['majorversion'] = 6;
$args['build'] = 40;
$args['flashvars'] = $c;
$args['quality'] = 'high';

$jsoutput = create_ufo_inline($id, $args);
$playerpath = $CFG->wwwroot.'/filter/mediaplugin/mp3player.swf';
$audioplayerpath = $CFG->wwwroot .'/filter/mediaplugin/flowplayer.audio.swf';
$colors = explode('&', $c);
$playercolors = array();
foreach ($colors as $color) {
$color = explode('=', $color);
$playercolors[$color[0]] = $color[1];
}

$output = $link[0].'<span class="mediaplugin mediaplugin_mp3" id="'.$id.'">('.get_string('mp3audio', 'filter_mediaplugin').')</span>'.$jsoutput;
$output = <<<OET
<span class="mediaplugin mediaplugin_mp3" id="$id"></span>
<noscript>
<object width="100" height="15" id="nonjsmp3plugin" name="undefined" data="$playerpath" type="application/x-shockwave-flash">
<param name="movie" value="$playerpath" />
<param name="allowfullscreen" value="false" />
<param name="allowscriptaccess" value="always" />
<param name="flashvars" value='config={"plugins": {"controls": {
"fullscreen": false,
"height": 15,
"autoHide": false,
"all": false,
"play": true,
"pause": true,
"scrubber": true
},
"audio": {"url": "$audioplayerpath"}
},
"clip":{"url":"$url",
"autoPlay": false},
"content":{"url":"$playerpath"}}}' />
</object>
</noscript>
OET;

$jsoutput = create_flowplayer($id, $url, 'mp3', $playercolors);
$output .= $jsoutput;

return $output;
}
Expand Down Expand Up @@ -208,19 +232,24 @@ function filter_mediaplugin_flv_callback($link) {
$height = empty($link[4]) ? '360' : $link[4];
$url = addslashes_js($link[1]);

$args = Array();
$args['movie'] = $CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file='.$url;
$args['width'] = $width;
$args['height'] = $height;
$args['majorversion'] = 6;
$args['build'] = 40;
$args['allowscriptaccess'] = 'never';
$args['quality'] = 'high';
$args['allowfullscreen'] = 'true';
$jsoutput = create_ufo_inline($id, $args);

$output = $link[0].'<span class="mediaplugin mediaplugin_flv" id="'.$id.'">('.get_string('flashvideo', 'filter_mediaplugin').')</span>'.$jsoutput;

$playerpath = $CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf';

$output = <<<EOT
<span class="mediaplugin mediaplugin_flv" id="$id"></span>
<noscript>
<object width="800" height="600" id="undefined" name="undefined" data="$playerpath" type="application/x-shockwave-flash">
<param name="movie" value="$playerpath" />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="flashvars" value='config={"clip":{"url":"$url",
"autoPlay": false},
"content":{"url":"$playerpath"}}}' />
</object>
</noscript>
EOT;

$jsoutput = create_flowplayer($id, $url, 'flv');
$output .= $jsoutput;
return $output;
}

Expand Down
Binary file added filter/mediaplugin/flowplayer.audio.swf
Binary file not shown.
Binary file added filter/mediaplugin/flowplayer.controls.swf
Binary file not shown.
Binary file modified filter/mediaplugin/flvplayer.swf
Binary file not shown.
Binary file modified filter/mediaplugin/mp3player.swf
Binary file not shown.
Loading

0 comments on commit 3a42ad1

Please sign in to comment.