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 | |
18 | function 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&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&waitForPlay=yes&'; |
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 <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 <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 <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 <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 <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 | |
bcb2c37a |
192 | $replace = '\\0<p class="mediaplugin ram"><script type="text/javascript">//<![CDATA['."\n". |
193 | 'document.write(\'<object width="240" height="180">'; |
d539ccf3 |
194 | $replace .= '<param name="src" value="\\2.ram" />'; |
bcb2c37a |
195 | $replace .= '<param name="autoStart" value="true" />'; |
d539ccf3 |
196 | $replace .= '<param name="controls" value="imagewindow" />'; |
197 | $replace .= '<param name="console" value="video" />'; |
198 | $replace .= '<param name="loop" value="true" />'; |
bcb2c37a |
199 | $replace .= '<embed src="\\2.ram" width=240" height="180" loop="true" type="audio/x-pn-realaudio-plugin" controls="imagewindow" console="video" autostart="true" />'; |
200 | $replace .= '<\/object><br />'; |
d539ccf3 |
201 | |
bcb2c37a |
202 | $replace .= '<object width="240" height="30">'; |
d539ccf3 |
203 | $replace .= '<param name="src" value="\\2.ram" />'; |
bcb2c37a |
204 | $replace .= '<param name="autoStart" value="true" />'; |
d539ccf3 |
205 | $replace .= '<param name="controls" value="ControlPanel" />'; |
206 | $replace .= '<param name="console" value="video" />'; |
bcb2c37a |
207 | $replace .= '<embed src="\\2.ram" width="240" height="30" controls="ControlPanel" type="audio/x-pn-realaudio-plugin" console="video" autostart="true" />'; |
208 | $replace .= '<\/object>\')'."\n".'//]]>'."\n".'</script></p>'; |
d539ccf3 |
209 | |
210 | $text = preg_replace($search, $replace, $text); |
211 | } |
03d843b2 |
212 | |
213 | if ($CFG->filter_mediaplugin_enable_rpm) { |
214 | $search = '/<a(.*?)href=\"([^<]+)\.rpm\"([^>]*)>(.*?)<\/a>/is'; |
215 | |
bcb2c37a |
216 | $replace = '\\0<p class="mediaplugin rpm"><script type="text/javascript">//<![CDATA['."\n". |
217 | 'document.write(\'<object width="240" height="180">'; |
03d843b2 |
218 | $replace .= '<param name="src" value="\\2.rpm" />'; |
219 | $replace .= '<param name="autostart" value="true" />'; |
220 | $replace .= '<param name="controls" value="imagewindow" />'; |
221 | $replace .= '<param name="console" value="video" />'; |
222 | $replace .= '<param name="loop" value="true" />'; |
bcb2c37a |
223 | $replace .= '<embed src="\\2.rpm" width=240" height="180" loop="true" type="audio/x-pn-realaudio-plugin" controls="imagewindow" console="video" autostart="true" />'; |
03d843b2 |
224 | $replace .= '</object><br />'; |
225 | |
bcb2c37a |
226 | $replace .= '<object width="240" height="30">'; |
03d843b2 |
227 | $replace .= '<param name="src" value="\\2.rpm" />'; |
228 | $replace .= '<param name="autostart" value="true" />'; |
229 | $replace .= '<param name="controls" value="ControlPanel" />'; |
230 | $replace .= '<param name="console" value="video" />'; |
bcb2c37a |
231 | $replace .= '<embed src="\\2.rpm" width="240" height="30" controls="ControlPanel" type="audio/x-pn-realaudio-plugin" console="video" autostart="true" />'; |
232 | $replace .= '</object>\')'."\n".'//]]>'."\n".'</script></p>'; |
03d843b2 |
233 | |
234 | $text = preg_replace($search, $replace, $text); |
235 | } |
d539ccf3 |
236 | |
f73eb30b |
237 | if ($CFG->filter_mediaplugin_enable_rm) { |
238 | $search = '/<a(.*?)href=\"([^<]+)\.rm\"([^>]*)>(.*?)<\/a>/is'; |
239 | |
bcb2c37a |
240 | $replace = '\\0<p class="mediaplugin rm"><script type="text/javascript">//<![CDATA['."\n". |
241 | 'document.write(\'<object width="240" height="180">'; |
f73eb30b |
242 | $replace .= '<param name="src" value="\\2.rm" />'; |
243 | $replace .= '<param name="autostart" value="true" />'; |
244 | $replace .= '<param name="controls" value="imagewindow" />'; |
245 | $replace .= '<param name="console" value="video" />'; |
246 | $replace .= '<param name="loop" value="true" />'; |
bcb2c37a |
247 | $replace .= '<embed src="\\2.rm" width=240" height="180" loop="true" type="audio/x-pn-realaudio-plugin" controls="imagewindow" console="video" autostart="true" />'; |
f73eb30b |
248 | $replace .= '</object><br />'; |
249 | |
bcb2c37a |
250 | $replace .= '<object width="240" height="30">'; |
f73eb30b |
251 | $replace .= '<param name="src" value="\\2.rm" />'; |
252 | $replace .= '<param name="autostart" value="true" />'; |
253 | $replace .= '<param name="controls" value="ControlPanel" />'; |
254 | $replace .= '<param name="console" value="video" />'; |
bcb2c37a |
255 | $replace .= '<embed src="\\2.rm" width="240" height="30" controls="ControlPanel" type="audio/x-pn-realaudio-plugin" console="video" autostart="true" />'; |
256 | $replace .= '</object>\')'."\n".'//]]>'."\n".'</script></p>'; |
f73eb30b |
257 | |
258 | $text = preg_replace($search, $replace, $text); |
259 | } |
f73eb30b |
260 | |
1b090b2f |
261 | return $text; |
6de17fde |
262 | } |
263 | |
264 | |
265 | ?> |