Additions to support units for numerical questions,
[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
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
28function mediaplugin_filter($courseid, $text) {
29 global $CFG;
30
1b090b2f 31 if (empty($CFG->filter_mediaplugin_ignore_mp3)) {
dcc0c135 32 $search = '/<a(.*?)href=\"([^<]+)\.mp3\"([^>]*)>(.*?)<\/a>/i';
1b090b2f 33
34 $replace = '\\0&nbsp;<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>&nbsp;';
46
47 $text = preg_replace($search, $replace, $text);
48 }
49
cce96a89 50 if (empty($CFG->filter_mediaplugin_ignore_swf)) {
dcc0c135 51 $search = '/<a(.*?)href=\"([^<]+)\.swf\"([^>]*)>(.*?)<\/a>/i';
cce96a89 52
53 $replace = '\\0<p class="mediaplugin"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
54 $replace .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
55 $replace .= ' width="400" height="300" id="mp3player" align="">';
56 $replace .= " <param name=movie value=\"\\2.swf\">";
57 $replace .= ' <param name=quality value=high>';
58 $replace .= " <embed src=\"\\2.swf\" ";
59 $replace .= " quality=high width=\"400\" height=\"300\" name=\"flashfilter\" ";
60 $replace .= ' type="application/x-shockwave-flash" ';
61 $replace .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
62 $replace .= '</embed>';
63 $replace .= '</object></p>';
64
65 $text = preg_replace($search, $replace, $text);
66 }
67
1b090b2f 68 if (empty($CFG->filter_mediaplugin_ignore_mov)) {
dcc0c135 69 $search = '/<a(.*?)href=\"([^<]+)\.mov\"([^>]*)>(.*?)<\/a>/i';
1b090b2f 70
cce96a89 71 $replace = '\\0<p class="mediaplugin"><object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
1b090b2f 72 $replace .= ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
16bc83d6 73 $replace .= ' height="300" width="400"';
1b090b2f 74 $replace .= ' id="quicktime" align="" type="application/x-oleobject">';
75 $replace .= "<param name=\"src\" value=\"\\2.mov\" />";
5da09684 76 $replace .= '<param name="autoplay" value=false />';
1b090b2f 77 $replace .= '<param name="loop" value=true />';
78 $replace .= '<param name="controller" value=true />';
16bc83d6 79 $replace .= '<param name="scale" value="aspect" />';
1b090b2f 80 $replace .= "\n<embed src=\"\\2.mov\" name=\"quicktime\" type=\"video/quicktime\" ";
16bc83d6 81 $replace .= ' height="300" width="400" scale="aspect" ';
5da09684 82 $replace .= ' autoplay="false" controller="true" loop="true" ';
1b090b2f 83 $replace .= ' pluginspage="http://quicktime.apple.com/">';
84 $replace .= '</embed>';
cce96a89 85 $replace .= '</object></p>';
1b090b2f 86
87 $text = preg_replace($search, $replace, $text);
88 }
89
90 if (empty($CFG->filter_mediaplugin_ignore_wmv)) {
dcc0c135 91 $search = '/<a(.*?)href=\"([^<]+)\.wmv\"([^>]*)>(.*?)<\/a>/i';
1b090b2f 92
cce96a89 93 $replace = '\\0<p class="mediaplugin"><object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
1b090b2f 94 $replace .= ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
95