MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / lesson / mediafile.php
blobfc52550fb256b30918a098d9caef83f8d1085e79
1 <?php // $Id$
2 /**
3 * This file plays the mediafile set in lesson settings.
5 * Almost all of this code is from /mod/resource/type/file/resource.class.php so major props for resource
7 * If there is a way to use the resource class instead of this code, please change to do so
10 * @version $Id$
11 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 * @package lesson
13 **/
15 require_once('../../config.php');
16 require_once($CFG->libdir.'/filelib.php');
18 $id = required_param('id', PARAM_INT); // Course Module ID
19 $printclose = optional_param('printclose', 0, PARAM_INT);
21 if (! $cm = get_coursemodule_from_id('lesson', $id)) {
22 error('Course Module ID was incorrect');
25 if (! $course = get_record('course', 'id', $cm->course)) {
26 error('Course is misconfigured');
29 if (! $lesson = get_record('lesson', 'id', $cm->instance)) {
30 error('Course module is incorrect');
33 require_login($course->id, false, $cm);
35 // Get the mimetype
36 $mimetype = mimeinfo("type", $lesson->mediafile);
38 if (!is_url($lesson->mediafile) and !in_array($mimetype, array('text/plain', 'text/html'))) {
39 print_header($course->shortname);
42 if ($printclose) { // this is for framesets
43 if ($lesson->mediaclose) {
44 print_header($course->shortname);
45 echo '<div class="lessonmediafilecontrol">
46 <form>
47 <div>
48 <input type="button" onclick="top.close();" value="'.get_string("closewindow").'" />
49 </div>
50 </form>
51 </div>';
52 print_footer();
54 exit();
57 if (is_url($lesson->mediafile)) {
58 $fullurl = $lesson->mediafile;
59 } else {
60 // get the full url to the file while taking into consideration $CFG->slasharguments
61 if ($CFG->slasharguments) {
62 $relativeurl = "/file.php/{$course->id}/{$lesson->mediafile}";
63 } else {
64 $relativeurl = "/file.php?file=/{$course->id}/{$lesson->mediafile}";
66 $fullurl = "$CFG->wwwroot$relativeurl";
69 // find the correct type and print it out
70 if ($mimetype == "audio/mp3") { // It's an MP3 audio file
72 if (!empty($THEME->resource_mp3player_colors)) {
73 $c = $THEME->resource_mp3player_colors; // You can set this up in your theme/xxx/config.php
74 } else {
75 $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'.
76 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'.
77 'font=Arial&fontColour=3333FF&buffer=10&waitForPlay=no&autoPlay=yes';
79 $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
80 $c = htmlentities($c);
81 echo '<div class="mp3player" class="lessonmediafilecontrol">';
82 echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
83 echo ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
84 echo ' width="600" height="70" id="mp3player" align="">';
85 echo '<param name="movie" value="'.$CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.$fullurl.'">';
86 echo '<param name="quality" value="high">';
87 echo '<param name="bgcolor" value="#333333">';
88 echo '<param name="flashvars" value="'.$c.'&amp;" />';
89 echo '<embed src="'.$CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.$fullurl.'" ';
90 echo ' quality="high" bgcolor="#333333" width="600" height="70" name="mp3player" ';
91 echo ' type="application/x-shockwave-flash" ';
92 echo ' flashvars="'.$c.'&amp;" ';
93 echo ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
94 echo '</embed>';
95 echo '</object>';
96 echo '</div>';
98 } else if (substr($mimetype, 0, 10) == "video/x-ms") { // It's a Media Player file
100 echo "<div class=\"lessonmediafilecontrol\"><p>";
101 echo '<object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
102 echo ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
103 echo ' standby="Loading Microsoft(R) Windows(R) Media Player components..." ';
104 echo ' id="msplayer" align="" type="application/x-oleobject">';
105 echo "<param name=\"Filename\" value=\"$fullurl\">";
106 echo '<param name="ShowControls" value="true" />';
107 echo '<param name="AutoRewind" value="true" />';
108 echo '<param name="AutoStart" value="true" />';
109 echo '<param name="Autosize" value="true" />';
110 echo '<param name="EnableContextMenu" value="true" />';
111 echo '<param name="TransparentAtStart" value="false" />';
112 echo '<param name="AnimationAtStart" value="false" />';
113 echo '<param name="ShowGotoBar" value="false" />';
114 echo '<param name="EnableFullScreenControls" value="true" />';
115 echo "\n<embed src=\"$fullurl\" name=\"msplayer\" type=\"$mimetype\" ";
116 echo ' ShowControls="1" AutoRewind="1" AutoStart="1" Autosize="0" EnableContextMenu="1"';
117 echo ' TransparentAtStart="0" AnimationAtStart="0" ShowGotoBar="0" EnableFullScreenControls="1"';
118 echo ' pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/">';
119 echo '</embed>';
120 echo '</object>';
121 echo "</p></div>";
123 } else if ($mimetype == "video/quicktime") { // It's a Quicktime file
125 echo "<div class=\"lessonmediafilecontrol\"><p>";
126 echo '<object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
127 echo ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
128 echo ' height="450" width="600"';
129 echo ' id="quicktime" align="" type="application/x-oleobject">';
130 echo "<param name=\"src\" value=\"$fullurl\" />";
131 echo '<param name="autoplay" value="true" />';
132 echo '<param name="loop" value="true" />';
133 echo '<param name="controller" value="true" />';
134 echo '<param name="scale" value="aspect" />';
135 echo "\n<embed src=\"$fullurl\" name=\"quicktime\" type=\"$mimetype\" ";
136 echo ' height="450" width="600" scale="aspect"';
137 echo ' autoplay="true" controller="true" loop="true" ';
138 echo ' pluginspage="http://quicktime.apple.com/">';
139 echo '</embed>';
140 echo '</object>';
141 echo "</p></div>";
143 //} else if ($mimetype == "application/x-shockwave-flash") { // It's a flash file
145 // error('Flash is not supported yet');
147 } else if ($mimetype == "audio/x-pn-realaudio") { // It's a realmedia file
149 echo '<object id="rvocx" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="600" height="50">';
150 echo "<param name=\"src\" value=\"$fullurl\">";
151 echo '<param name="console" value="video">'; // not sure what the console param should equal
152 echo '<param name="controls" value="ControlPanel">';
153 echo '<param name="autostart" value="true">';
154 echo '<param name="loop" value="true">';
155 echo '<embed name="rvocx" src="'.$fullurl.'" height="50" width="600" autostart="true" loop="true" nojava="true" console="video" controls="ControlPanel"></embed>';
156 echo '<noembed></noembed>';
157 echo '</object>';
159 } else if (is_url($lesson->mediafile) or $mimetype == 'text/html' or $mimetype == 'text/plain') {
160 // might be dangerous to handle all of these in the same fasion. It is being set by a teacher though.
161 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
162 echo "<html dir=\"ltr\">\n";
163 echo '<head>';
164 echo '<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />';
165 echo "<title>{$course->shortname}</title></head>\n";
166 if ($lesson->mediaclose) {
167 echo "<frameset rows=\"90%,*\">";
168 echo "<frame src=\"$fullurl\" />";
169 echo "<frame src=\"mediafile.php?id=$cm->id&amp;printclose=1\" />";
170 echo "</frameset>";
171 } else {
172 echo "<frameset rows=\"100%\">";
173 echo "<frame src=\"$fullurl\" />";
174 echo "</frameset>";
176 echo '</html>';
177 exit();
179 } else if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // Image
181 echo "<div class=\"lessonmediafilecontrol\"><p>";
182 echo '<img class="lessonimage" src="'.s($fullurl).'" alt="" />';
183 echo "</p></div>";
185 } else { // Default
187 // Get the file name
188 $file = pathinfo($lesson->mediafile);
189 $filename = basename($file['basename'], '.'.$file['extension']);
191 echo "<div class=\"lessonmediafilecontrol\"><p>";
192 notify(get_string('clicktodownload', 'lesson'));
193 echo "<a href=\"$fullurl\">".format_string($filename).'</a>';
194 echo "</p></div>";
198 function is_url($test_url) {
199 // the following is barrowed from resource code. Thanks!
200 if (strpos($test_url, '://')) { // eg http:// https:// ftp:// etc
201 return true;
203 if (strpos($test_url, '/') === 0) { // Starts with slash
204 return true;
206 return false;
209 if ($lesson->mediaclose) {
210 echo '<div class="lessonmediafilecontrol">';
211 close_window_button();
212 echo '</div>';
215 print_footer();