Fixed 2 typos identified by Dan (guset instead of guest). MDL-8676
[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
f6994e71 21 static $count = 0;
22
23 $count++;
24
c96bdc02 25 include "defaultsettings.php";
26
27 if ($CFG->filter_mediaplugin_enable_mp3) {
df031f9a 28 static $c;
29
30 if (empty($c)) {
31 if (!empty($THEME->filter_mediaplugin_colors)) {
32 $c = $THEME->filter_mediaplugin_colors; // You can set this up in your theme/xxx/config.php
33 } else {
83703f08 34 $c = 'bgColour=000000&amp;btnColour=ffffff&amp;btnBorderColour=cccccc&amp;iconColour=000000&amp;iconOverColour=00cc00&amp;trackColour=cccccc&amp;handleColour=ffffff&amp;loaderColour=ffffff&amp;waitForPlay=yes&amp;';
df031f9a 35 }
36 }
a625e5eb 37 $search = '/<a(.*?)href=\"([^<]+)\.mp3\"([^>]*)>(.*?)<\/a>/is';
1b090b2f 38
f6994e71 39 // We're using the UFO technique to attain XHTML Strict 1.0
40 // See: http://www.bobbyvandersluis.com/ufo/
41
42 $replace = '<script type="text/javascript">'."\n".
43 '//<![CDATA['."\n".
44 'var FO'.$count.' = { movie:"'.$CFG->wwwroot.'/filter/mediaplugin/mp3player.swf?src=\\2.mp3",'.
45 'width:"90", height:"15", majorversion:"6", build:"40", flashvars:"'.$c.'", quality: "high" };'."\n".
46 'UFO.create(FO'.$count.', "filtermp3'.$count.'");'."\n".
47 '//]]>'."\n".
48 '</script>'."\n".
49 '\\0&nbsp;<span class="mediaplugin mp3" id="filtermp3'.$count.'">'.
50 '('.get_string('mp3audio', 'mediaplugin').')'.
51 '</span>'."\n";
1b090b2f 52
53 $text = preg_replace($search, $replace, $text);
54 }
55
c96bdc02 56 if ($CFG->filter_mediaplugin_enable_swf) {
35da89c2 57 $search = array(
58 '/<a(.*?)href=\"([^<]+)\.swf\?d=([\d]{1,3}%?)x([\d]{1,3}%?)\"([^>]*)>(.*?)<\/a>/is',
59 '/<a(.*?)href=\"([^<]+)\.swf\"([^>]*)>(.*?)<\/a>/is'
60 );
56245248 61
62 $replace = array();
63
f6994e71 64 $replace[0] = '<script type="text/javascript">'."\n".
65 '//<![CDATA['."\n".
66 'var FO'.$count.' = { movie:"\\2.swf", width:"\\3", height:"\\4", majorversion:"6", build:"40", '.
67 'allowscriptaccess:"never", quality: "high" };'."\n".
68 'UFO.create(FO'.$count.', "filterswf'.$count.'");'."\n".
69 '//]]>'."\n".
70 '</script>'."\n".
71 '\\0&nbsp;<span class="mediaplugin swf" id="filterswf'.$count.'">'.
72 '('.get_string('flashanimation', 'mediaplugin').')'.
73 '</span>'."\n";
74
75 $replace[1] = '<script type="text/javascript">'."\n".
76 '//<![CDATA['."\n".
77 'var FO'.$count.' = { movie:"\\2.swf", width:"400", height:"300", majorversion:"6", build:"40", '.
78 'allowscriptaccess:"never", quality: "high" };'."\n".
79 'UFO.create(FO'.$count.', "filterswf'.$count.'");'."\n".
80 '//]]>'."\n".
81 '</script>'."\n".
82 '\\0&nbsp;<span class="mediaplugin swf" id="filterswf'.$count.'">'.
83 '('.get_string('flashanimation', 'mediaplugin').')'.
84 '</span>'."\n";
56245248 85
cce96a89 86 $text = preg_replace($search, $replace, $text);
35da89c2 87
cce96a89 88 }
56245248 89
d07851e1 90 if ($CFG->filter_mediaplugin_enable_flv) {
619c7447 91
92 $replace = array();
93
f6994e71 94 $search = array(
95 '/<a(.*?)href=\"([^<]+)\.flv\?d=([\d]{1,3}%?)x([\d]{1,3}%?)\"([^>]*)>(.*?)<\/a>/is',
96 '/<a(.*?)href=\"([^<]+)\.flv\"([^>]*)>(.*?)<\/a>/is'
97 );
619c7447 98
99 $replace[0] = '<script type="text/javascript">'."\n".
f6994e71 100 '//<![CDATA['."\n".
101 'var FO'.$count.' = { movie:"'.$CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file=\\2.flv", '.
102 'width:"\\3", height:"\\4", majorversion:"6", build:"40", '.
103 'allowscriptaccess:"never", quality: "high" };'."\n".
104 'UFO.create(FO'.$count.', "filterflv'.$count.'");'."\n".
105 '//]]>'."\n".
106 '</script>'."\n".
107 '\\0&nbsp;<span class="mediaplugin flv" id="filterflv'.$count.'">'.
108 '('.get_string('flashvideo', 'mediaplugin').')'.
109 '</span>'."\n";
110
111 $replace[1] = '<script type="text/javascript">'."\n".
112 '//<![CDATA['."\n".
113 'var FO'.$count.' = { movie:"'.$CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file=\\2.flv", '.
114 'width:"480", height:"360", majorversion:"6", build:"40", '.
115 'allowscriptaccess:"never", quality: "high" };'."\n".
116 'UFO.create(FO'.$count.', "filterflv'.$count.'");'."\n".
117 '//]]>'."\n".
118 '</script>'."\n".
119 '\\0&nbsp;<span class="mediaplugin flv" id="filterflv'.$count.'">'.
120 '('.get_string('flashvideo', 'mediaplugin').')'.
121 '</span>'."\n";
122
d07851e1 123 $text = preg_replace($search, $replace, $text);
124 }
cce96a89 125
c96bdc02 126 if ($CFG->filter_mediaplugin_enable_mov) {
a625e5eb 127 $search = '/<a(.*?)href=\"([^<]+)\.mov\"([^>]*)>(.*?)<\/a>/is';
1b090b2f 128
a2df2a1a 129 $replace = '\\0<p class="mediaplugin mov"><object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
1b090b2f 130 $replace .= ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
16bc83d6 131 $replace .= ' height="300" width="400"';
66f99e72 132 $replace .= ' id="quicktime" type="application/x-oleobject">';
f6994e71 133 $replace .= '<param name="src" value="\\2.mov" />';
9a58f7cb 134 $replace .= '<param name="autoplay" value="false" />';
135 $replace .= '<param name="loop" value="true" />';
136 $replace .= '<param name="controller" value="true" />';
16bc83d6 137 $replace .= '<param name="scale" value="aspect" />';
cce96a89 138 $replace .= '</object></p>';
1b090b2f 139
140 $text = preg_replace($search, $replace, $text);
141 }
142
c96bdc02 143 if ($CFG->filter_mediaplugin_enable_wmv) {
a625e5eb 144 $search = '/<a(.*?)href=\"([^<]+)\.wmv\"([^>]*)>(.*?)<\/a>/is';
1b090b2f 145
a2df2a1a 146 $replace = '\\0<p class="mediaplugin wmv"><object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
1b090b2f 147 $replace .= ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
619c7447 148 $replace .= ' standby="Loading Microsoft� Windows� Media Player components..." ';
66f99e72 149 $replace .= ' id="msplayer" type="application/x-oleobject">';
f6994e71 150 $replace .= '<param name="Filename" value="\\2.wmv" />';
9a58f7cb 151 $replace .= '<param name="ShowControls" value="true" />';
152 $replace .= '<param name="AutoRewind" value="true" />';
153 $replace .= '<param name="AutoStart" value="false" />';
154 $replace .= '<param name="Autosize" value="true" />';
155 $replace .= '<param name="EnableContextMenu" value="true" />';
156 $replace .= '<param name="TransparentAtStart" value="false" />';
157 $replace .= '<param name="AnimationAtStart" value="false" />';
158 $replace .= '<param name="ShowGotoBar" value="false" />';
159 $replace .= '<param name="EnableFullScreenControls" value="true" />';
cce96a89 160 $replace .= '</object></p>';
1b090b2f 161
162 $text = preg_replace($search, $replace, $text);
163 }
164
c96bdc02 165 if ($CFG->filter_mediaplugin_enable_mpg) {
a625e5eb 166 $search = '/<a(.*?)href=\"([^<]+)\.(mpe?g)\"([^>]*)>(.*?)<\/a>/is';
59a3122e 167
a2df2a1a 168 $replace = '\\0<p class="mediaplugin mpg"><object width="240" height="180">';
66f99e72 169 $replace .= '<param name="src" value="\\2.\\3" />';
170 $replace .= '<param name="controller" value="true" />';
171 $replace .= '<param name="autoplay" value="false" />';
59a3122e 172 $replace .= '</object></p>';
173
174 $text = preg_replace($search, $replace, $text);
175 }
176
c96bdc02 177 if ($CFG->filter_mediaplugin_enable_avi) {
a625e5eb 178 $search = '/<a(.*?)href=\"([^<]+)\.avi\"([^>]*)>(.*?)<\/a>/is';
59a3122e 179
a2df2a1a 180 $replace = '\\0<p class="mediaplugin avi"><object width="240" height="180">';
66f99e72 181 $replace .= '<param name="src" value="\\2.avi" />';
182 $replace .= '<param name="controller" value="true" />';
183 $replace .= '<param name="autoplay" value="false" />';
59a3122e 184 $replace .= '</object></p>';
185
186 $text = preg_replace($search, $replace, $text);
187 }
d539ccf3 188
189 if ($CFG->filter_mediaplugin_enable_ram) {
190 $search = '/<a(.*?)href=\"([^<]+)\.ram\"([^>]*)>(.*?)<\/a>/is';
59a3122e 191
d539ccf3 192 $replace = '\\0<p class="mediaplugin ram"><object width="240" height="180">';
193 $replace .= '<param name="src" value="\\2.ram" />';
194 $replace .= '<param name="autostart" value="true" />';
195 $replace .= '<param name="controls" value="imagewindow" />';
196 $replace .= '<param name="console" value="video" />';
197 $replace .= '<param name="loop" value="true" />';
d539ccf3 198 $replace .= '</object><br />';
199
200 $replace .= '<object width="320" height="30">';
201 $replace .= '<param name="src" value="\\2.ram" />';
202 $replace .= '<param name="autostart" value="true" />';
203 $replace .= '<param name="controls" value="ControlPanel" />';
204 $replace .= '<param name="console" value="video" />';
d539ccf3 205 $replace .= '</object></p>';
206
207 $text = preg_replace($search, $replace, $text);
208 }
03d843b2 209
210 if ($CFG->filter_mediaplugin_enable_rpm) {
211 $search = '/<a(.*?)href=\"([^<]+)\.rpm\"([^>]*)>(.*?)<\/a>/is';
212
213 $replace = '\\0<p class="mediaplugin rpm"><object width="240" height="180">';
214 $replace .= '<param name="src" value="\\2.rpm" />';
215 $replace .= '<param name="autostart" value="true" />';
216 $replace .= '<param name="controls" value="imagewindow" />';
217 $replace .= '<param name="console" value="video" />';
218 $replace .= '<param name="loop" value="true" />';
03d843b2 219 $replace .= '</object><br />';
220
221 $replace .= '<object width="320" height="30">';
222 $replace .= '<param name="src" value="\\2.rpm" />';
223 $replace .= '<param name="autostart" value="true" />';
224 $replace .= '<param name="controls" value="ControlPanel" />';
225 $replace .= '<param name="console" value="video" />';
03d843b2 226 $replace .= '</object></p>';
227
228 $text = preg_replace($search, $replace, $text);
229 }
d539ccf3 230
f73eb30b 231 if ($CFG->filter_mediaplugin_enable_rm) {
232 $search = '/<a(.*?)href=\"([^<]+)\.rm\"([^>]*)>(.*?)<\/a>/is';
233
234 $replace = '\\0<p class="mediaplugin rm"><object width="240" height="180">';
235 $replace .= '<param name="src" value="\\2.rm" />';
236 $replace .= '<param name="autostart" value="true" />';
237 $replace .= '<param name="controls" value="imagewindow" />';
238 $replace .= '<param name="console" value="video" />';
239 $replace .= '<param name="loop" value="true" />';
f73eb30b 240 $replace .= '</object><br />';
241
242 $replace .= '<object width="320" height="30">';
243 $replace .= '<param name="src" value="\\2.rm" />';
244 $replace .= '<param name="autostart" value="true" />';
245 $replace .= '<param name="controls" value="ControlPanel" />';
246 $replace .= '<param name="console" value="video" />';
f73eb30b 247 $replace .= '</object></p>';
248
249 $text = preg_replace($search, $replace, $text);
250 }
f73eb30b 251
59a3122e 252
1b090b2f 253 return $text;
6de17fde 254}
255
256
257?>