Added another string for Real Media
[moodle.git] / filter / mediaplugin / filter.php
CommitLineData
6de17fde 1<?php // $id$
2//////////////////////////////////////////////////////////////
3// Media plugin filtering
4//
5// This filter will replace any links to a media file with
6// a media plugin that plays that media inline
7//
4da85078 8// To activate this filter, add a line like this to your
9// list of filters in your Filter configuration:
6de17fde 10//
4da85078 11// filter/mediaplugin/filter.php
6de17fde 12//
13//////////////////////////////////////////////////////////////
14
6de17fde 15/// This is the filtering function itself. It accepts the
16/// courseid and the text to be filtered (in HTML form).
17
18function mediaplugin_filter($courseid, $text) {
df031f9a 19 global $CFG, $THEME;
6de17fde 20
c96bdc02 21 include "defaultsettings.php";
22
23 if ($CFG->filter_mediaplugin_enable_mp3) {
df031f9a 24 static $c;
25
26 if (empty($c)) {
27 if (!empty($THEME->filter_mediaplugin_colors)) {
28 $c = $THEME->filter_mediaplugin_colors; // You can set this up in your theme/xxx/config.php
29 } else {
c2ecfdfc 30 $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&waitForPlay=yes&';
df031f9a 31 }
32 }
c2ecfdfc 33 $c = htmlentities($c);
a625e5eb 34 $search = '/<a(.*?)href=\"([^<]+)\.mp3\"([^>]*)>(.*?)<\/a>/is';
1b090b2f 35
a2df2a1a 36 $replace = '\\0&nbsp;<object class="mediaplugin mp3" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
1b090b2f 37 $replace .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
a2df2a1a 38 $replace .= ' width="90" height="15" id="mp3player">';
66f99e72 39 $replace .= " <param name=\"movie\" value=\"$CFG->wwwroot/filter/mediaplugin/mp3player.swf?src=\\2.mp3\" />";
40 $replace .= ' <param name="quality" value="high" />';
41 $replace .= ' <param name="bgcolor" value="#333333" />';
c2ecfdfc 42 $replace .= ' <param name="flashvars" value="'.$c.'" />';
1b090b2f 43 $replace .= " <embed src=\"$CFG->wwwroot/filter/mediaplugin/mp3player.swf?src=\\2.mp3\" ";
a2df2a1a 44 $replace .= " quality=\"high\" bgcolor=\"#333333\" width=\"90\" height=\"15\" name=\"mp3player\" ";
1b090b2f 45 $replace .= ' type="application/x-shockwave-flash" ';
c2ecfdfc 46 $replace .= ' flashvars="'.$c.'" ';
1b090b2f 47 $replace .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
48 $replace .= '</embed>';
49 $replace .= '</object>&nbsp;';
50
51 $text = preg_replace($search, $replace, $text);
52 }
53
c96bdc02 54 if ($CFG->filter_mediaplugin_enable_swf) {
35da89c2 55 $search = array(
56 '/<a(.*?)href=\"([^<]+)\.swf\?d=([\d]{1,3}%?)x([\d]{1,3}%?)\"([^>]*)>(.*?)<\/a>/is',
57 '/<a(.*?)href=\"([^<]+)\.swf\"([^>]*)>(.*?)<\/a>/is'
58 );
56245248 59
60 $replace = array();
61
62 $replace[0] = '\\0<p class="mediaplugin swf"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
63 $replace[0] .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
35da89c2 64 $replace[0] .= ' width="\\3" height="\\4" id="mp3player">';
56245248 65 $replace[0] .= " <param name=\"movie\" value=\"\\2.swf\" />";
35da89c2 66 $replace[0] .= ' <param name="quality" value="high" />';
67 $replace[0] .= ' <param name="AllowScriptAccess" value="never" />';
56245248 68 $replace[0] .= " <embed src=\"\\2.swf\" ";
35da89c2 69 $replace[0] .= ' quality="high" width="\\3" height="\\4" name="flashfilter" AllowScriptAccess="never" ';
56245248 70 $replace[0] .= ' type="application/x-shockwave-flash" ';
71 $replace[0] .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
72 $replace[0] .= '</embed>';
73 $replace[0] .= '</object></p>';
74
35da89c2 75 $replace[1] = '\\0<p class="mediaplugin swf"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
76 $replace[1] .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
77 $replace[1] .= ' width="400" height="300" id="mp3player">';
56245248 78 $replace[1] .= " <param name=\"movie\" value=\"\\2.swf\" />";
79 $replace[1] .= ' <param name="quality" value="high" />';
80 $replace[1] .= ' <param name="AllowScriptAccess" value="never" />';
81 $replace[1] .= " <embed src=\"\\2.swf\" ";
35da89c2 82 $replace[1] .= ' quality="high" width="400" height="300" name="flashfilter" AllowScriptAccess="never" ';
56245248 83 $replace[1] .= ' type="application/x-shockwave-flash" ';
84 $replace[1] .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
85 $replace[1] .= '</embed>';
86 $replace[1] .= '</object></p>';
87
cce96a89 88 $text = preg_replace($search, $replace, $text);
35da89c2 89
cce96a89 90 }
56245248 91
d07851e1 92 if ($CFG->filter_mediaplugin_enable_flv) {
93 $search = '/<a(.*?)href=\"([^<]+)\.flv\"([^>]*)>(.*?)<\/a>/is';
94
95 $replace = '\\0&nbsp;<object class="mediaplugin flv" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
96 $replace .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
97 $replace .= ' width="480" height="360" id="flvplayer">';
98 $replace .= " <param name=\"movie\" value=\"$CFG->wwwroot/filter/mediaplugin/flvplayer.swf?file=\\2.flv\" />";
99 $replace .= ' <param name="quality" value="high" />';
100 $replace .= ' <param name="bgcolor" value="#FFFFFF" />';
101 $replace .= ' <param name="flashvars" value="'.$c.'" />';
102 $replace .= " <embed src=\"$CFG->wwwroot/filter/mediaplugin/flvplayer.swf?file=\\2.flv\" ";
103 $replace .= " quality=\"high\" bgcolor=\"#FFFFFF\" width=\"480\" height=\"360\" name=\"flvplayer\" ";
104 $replace .= ' type="application/x-shockwave-flash" ';
105 $replace .= ' flashvars="'.$c.'" ';
106 $replace .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
107 $replace .= '</embed>';
108 $replace .= '</object>&nbsp;';
109
110 $text = preg_replace($search, $replace, $text);
111 }
cce96a89 112
c96bdc02 113 if ($CFG->filter_mediaplugin_enable_mov) {
a625e5eb 114 $search = '/<a(.*?)href=\"([^<]+)\.mov\"([^>]*)>(.*?)<\/a>/is';
1b090b2f 115
a2df2a1a 116 $replace = '\\0<p class="mediaplugin mov"><object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
1b090b2f 117 $replace .= ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
16bc83d6 118 $replace .= ' height="300" width="400"';
66f99e72 119 $replace .= ' id="quicktime" type="application/x-oleobject">';
1b090b2f 120 $replace .= "<param name=\"src\" value=\"\\2.mov\" />";
9a58f7cb 121 $replace .= '<param name="autoplay" value="false" />';
122 $replace .= '<param name="loop" value="true" />';
123 $replace .= '<param name="controller" value="true" />';
16bc83d6 124 $replace .= '<param name="scale" value="aspect" />';
1b090b2f 125 $replace .= "\n<embed src=\"\\2.mov\" name=\"quicktime\" type=\"video/quicktime\" ";
16bc83d6 126 $replace .= ' height="300" width="400" scale="aspect" ';
5da09684 127 $replace .= ' autoplay="false" controller="true" loop="true" ';
1b090b2f 128 $replace .= ' pluginspage="http://quicktime.apple.com/">';
129 $replace .= '</embed>';
cce96a89 130 $replace .= '</object></p>';
1b090b2f 131
132 $text = preg_replace($search, $replace, $text);
133 }
134
c96bdc02 135 if ($CFG->filter_mediaplugin_enable_wmv) {
a625e5eb 136 $search = '/<a(.*?)href=\"([^<]+)\.wmv\"([^>]*)>(.*?)<\/a>/is';
1b090b2f 137
a2df2a1a 138 $replace = '\\0<p class="mediaplugin wmv"><object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
1b090b2f 139 $replace .= ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
140