clean the filenames to make sure there aren't funny characters
[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
522e2249 31 $search = '/<a(.*?)href=\"(.*?)\.mp3\"([^>]*)>(.*?)<\/a>/i';
6de17fde 32
d6021c77 33 $replace = '\\0&nbsp;<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
ae2aa3c8 34 $replace .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
7a38bf28 35 $replace .= ' width="35" height="18" id="mp3player" align="">';
d6021c77 36 $replace .= " <param name=movie value=\"$CFG->wwwroot/filter/mediaplugin/mp3player.swf?src=\\2.mp3\">";
ae2aa3c8 37 $replace .= ' <param name=quality value=high>';
38 $replace .= ' <param name=bgcolor value="#333333">';
7a38bf28 39 $replace .= " <embed src=\"$CFG->wwwroot/filter/mediaplugin/mp3player.swf?src=\\2.mp3\" ";
40 $replace .= " quality=high bgcolor=\"#333333\" width=\"35\" height=\"18\" name=\"mp3player\" ";
6de17fde 41 $replace .= ' type="application/x-shockwave-flash" ';
42 $replace .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
43 $replace .= '</embed>';
ae2aa3c8 44 $replace .= '</object>&nbsp;';
6de17fde 45
46 return preg_replace($search, $replace, $text);
47}
48
49
50?>