fixed capitalization and quoting of attribute values
[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) {
19 global $CFG;
20
1b090b2f 21 if (empty($CFG->filter_mediaplugin_ignore_mp3)) {
dcc0c135 22 $search = '/<a(.*?)href=\"([^<]+)\.mp3\"([^>]*)>(.*?)<\/a>/i';
1b090b2f 23
24 $replace = '\\0&nbsp;<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
25 $replace .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
26 $replace .= ' width="35" height="18" id="mp3player" align="">';
27 $replace .= " <param name=movie value=\"$CFG->wwwroot/filter/mediaplugin/mp3player.swf?src=\\2.mp3\">";
28 $replace .= ' <param name=quality value=high>';
29 $replace .= ' <param name=bgcolor value="#333333">';
30 $replace .= " <embed src=\"$CFG->wwwroot/filter/mediaplugin/mp3player.swf?src=\\2.mp3\" ";
31 $replace .= " quality=high bgcolor=\"#333333\" width=\"35\" height=\"18\" name=\"mp3player\" ";
32 $replace .= ' type="application/x-shockwave-flash" ';
33 $replace .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
34 $replace .= '</embed>';
35 $replace .= '</object>&nbsp;';
36
37 $text = preg_replace($search, $replace, $text);
38 }
39
cce96a89 40 if (empty($CFG->filter_mediaplugin_ignore_swf)) {
dcc0c135 41 $search = '/<a(.*?)href=\"([^<]+)\.swf\"([^>]*)>(.*?)<\/a>/i';
cce96a89 42
43 $replace = '\\0<p class="mediaplugin"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
44 $replace .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
45 $replace .= ' width="400" height="300" id="mp3player" align="">';
46 $replace .= " <param name=movie value=\"\\2.swf\">";
47 $replace .= ' <param name=quality value=high>';
48 $replace .= " <embed src=\"\\2.swf\" ";
49 $replace .= " quality=high width=\"400\" height=\"300\" name=\"flashfilter\" ";
50 $replace .= ' type="application/x-shockwave-flash" ';
51 $replace .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
52 $replace .= '</embed>';
53 $replace .= '</object></p>';
54
55 $text = preg_replace($search, $replace, $text);
56 }
57
1b090b2f 58 if (empty($CFG->filter_mediaplugin_ignore_mov)) {
dcc0c135 59 $search = '/<a(.*?)href=\"([^<]+)\.mov\"([^>]*)>(.*?)<\/a>/i';
1b090b2f 60
cce96a89 61 $replace = '\\0<p class="mediaplugin"><object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
1b090b2f 62 $replace .= ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
16bc83d6 63 $replace .= ' height="300" width="400"';
1b090b2f 64 $replace .= ' id="quicktime" align="" type="application/x-oleobject">';
65 $replace .= "<param name=\"src\" value=\"\\2.mov\" />";
5da09684 66 $replace .= '<param name="autoplay" value=false />';
1b090b2f 67 $replace .= '<param name="loop" value=true />';
68 $replace .= '<param name="controller" value=true />';
16bc83d6 69 $replace .= '<param name="scale" value="aspect" />';
1b090b2f 70 $replace .= "\n<embed src=\"\\2.mov\" name=\"quicktime\" type=\"video/quicktime\" ";
16bc83d6 71 $replace .= ' height="300" width="400" scale="aspect" ';
5da09684 72 $replace .= ' autoplay="false" controller="true" loop="true" ';
1b090b2f 73 $replace .= ' pluginspage="http://quicktime.apple.com/">';
74 $replace .= '</embed>';
cce96a89 75 $replace .= '</object></p>';
1b090b2f 76
77 $text = preg_replace($search, $replace, $text);
78 }
79
80 if (empty($CFG->filter_mediaplugin_ignore_wmv)) {
dcc0c135 81 $search = '/<a(.*?)href=\"([^<]+)\.wmv\"([^>]*)>(.*?)<\/a>/i';
1b090b2f 82
cce96a89 83 $replace = '\\0<p class="mediaplugin"><object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
1b090b2f 84 $replace .= ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
85