Cool thing for the morning - a new filter that will turn any link to
[moodle.git] / filter / mediaplugin / mediaplugin.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//
8// To activate this filter, add his to your list of filters
9// in Admin -> Configuration -> Variables
10//
11// filter/mediaplugin/mediaplugin.php';
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
31 $search = '/<a(.*)href=\"(.*)\.mp3\"(.*)>(.*)<\/a>/i';
32
33 $replace = '\\0 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
34 $replace .= 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
35 $replace .= 'width="200" height="70" id="mp3player" align="">';
36 $replace .= "<param name=movie value=\"$CFG->wwwroot/lib/mp3player/mp3player.swf?src=\\2.mp3&autostart=no\">";
37 $replace .= '<param name=quality value=high>';
38 $replace .= '<param name=bgcolor value="#333333">';
39 $replace .= "<embed src=\"$CFG->wwwroot/lib/mp3player/mp3player.swf?src=\\2.mp3&autostart=no\" ";
40 $replace .= " quality=high bgcolor=\"#333333\" width=\"400\" height=\"50\" name=\"mp3player\" ";
41 $replace .= ' type="application/x-shockwave-flash" ';
42 $replace .= ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
43 $replace .= '</embed>';
44 $replace .= '</object>';
45
46 return preg_replace($search, $replace, $text);
47}
48
49
50?>