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 | |
15 | /// These lines are important - the variable must match the name |
16 | /// of the actual function below |
17 | |
18 | $textfilter_function = 'mediaplugin_filter'; |
19 | |
20 | if (function_exists($textfilter_function)) { |
21 | return; |
22 | } |
23 | |
24 | |
25 | /// This is the filtering function itself. It accepts the |
26 | /// courseid and the text to be filtered (in HTML form). |
27 | |
28 | function mediaplugin_filter($courseid, $text) { |
29 | global $CFG; |
30 | |
1b090b2f |
31 | if (empty($CFG->filter_mediaplugin_ignore_mp3)) { |
32 | $search = '/<a(.*?)href=\"(.*?)\.mp3\"([^>]*)>(.*?)<\/a>/i'; |
33 | |
34 | $replace = '\\0 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'; |
35 | $replace .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '; |
36 | $replace .= ' width="35" height="18" id="mp3player" align="">'; |
37 | $replace .= " <param name=movie value=\"$CFG->wwwroot/filter/mediaplugin/mp3player.swf?src=\\2.mp3\">"; |
38 | $replace .= ' <param name=quality value=high>'; |
39 | $replace .= ' <param name=bgcolor value="#333333">'; |
40 | $replace .= " <embed src=\"$CFG->wwwroot/filter/mediaplugin/mp3player.swf?src=\\2.mp3\" "; |
41 | $replace .= " quality=high bgcolor=\"#333333\" width=\"35\" height=\"18\" name=\"mp3player\" "; |
42 | $replace .= ' type="application/x-shockwave-flash" '; |
43 | $replace .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">'; |
44 | $replace .= '</embed>'; |
45 | $replace .= '</object> '; |
46 | |
47 | $text = preg_replace($search, $replace, $text); |
48 | } |
49 | |
50 | if (empty($CFG->filter_mediaplugin_ignore_mov)) { |
51 | $search = '/<a(.*?)href=\"(.*?)\.mov\"([^>]*)>(.*?)<\/a>/i'; |
52 | |
53 | $replace = '\\0<br /><object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"'; |
54 | $replace .= ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" '; |
a72170fb |
55 | $replace .= ' height="240" width="300"'; |
1b090b2f |
56 | $replace .= ' id="quicktime" align="" type="application/x-oleobject">'; |
57 | $replace .= "<param name=\"src\" value=\"\\2.mov\" />"; |
58 | $replace .= '<param name="autoplay" value=true />'; |
59 | $replace .= '<param name="loop" value=true />'; |
60 | $replace .= '<param name="controller" value=true />'; |
a72170fb |
61 | $replace .= '<param name="scale" value="tofit" />'; |
1b090b2f |
62 | $replace .= "\n<embed src=\"\\2.mov\" name=\"quicktime\" type=\"video/quicktime\" "; |
a72170fb |
63 | $replace .= ' height="240" width="300" scale="tofit" '; |
1b090b2f |
64 | $replace .= ' autoplay="true" controller="true" loop="true" '; |
65 | $replace .= ' pluginspage="http://quicktime.apple.com/">'; |
66 | $replace .= '</embed>'; |
67 | $replace .= '</object><br />'; |
68 | |
69 | $text = preg_replace($search, $replace, $text); |
70 | } |
71 | |
72 | if (empty($CFG->filter_mediaplugin_ignore_wmv)) { |
73 | $search = '/<a(.*?)href=\"(.*?)\.wmv\"([^>]*)>(.*?)<\/a>/i'; |
74 | |
75 | $replace = '\\0<br /><object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"'; |
76 | $replace .= ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" '; |
77 |