1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Internal library of functions for module eduplayer
|
|
|
19 |
*
|
|
|
20 |
* All the eduplayer specific functions, needed to implement the module
|
|
|
21 |
* logic, should go here. Never include this file from your lib.php!
|
|
|
22 |
*
|
|
|
23 |
* @package mod
|
|
|
24 |
* @subpackage eduplayer
|
|
|
25 |
* @author Humanage Srl <info@humanage.it>
|
|
|
26 |
* @copyright 2013 Humanage Srl <info@humanage.it>
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
defined('MOODLE_INTERNAL') || die();
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Define type of media to serve
|
|
|
34 |
* @return array
|
|
|
35 |
*/
|
|
|
36 |
function eduplayer_list_type() {
|
|
|
37 |
return array(
|
|
|
38 |
'video' => get_string('video','eduplayer'),
|
|
|
39 |
'audio' => get_string('audio','eduplayer'),
|
|
|
40 |
'vplaylist' => get_string('vplaylist','eduplayer'),
|
|
|
41 |
'youtube' => get_string('youtube','eduplayer'),
|
|
|
42 |
'ytplaylist' => get_string('ytplaylist','eduplayer'),
|
|
|
43 |
'vimeo' => get_string('vimeo','eduplayer'),
|
|
|
44 |
'url' => get_string('full_url','eduplayer'),
|
|
|
45 |
'rtmp' => get_string('rtmp','eduplayer')
|
|
|
46 |
);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Define the path to the skin configuration xml file
|
|
|
51 |
* @return array
|
|
|
52 |
*/
|
|
|
53 |
function eduplayer_list_skins(){
|
|
|
54 |
$skinlist = array('default'=>'default');
|
|
|
55 |
if ($h = opendir( dirname(__FILE__).'/skins')) {
|
|
|
56 |
while (false !== ($e = readdir($h)) ) {
|
|
|
57 |
if( $e != '.' && $e != '..' ){
|
|
|
58 |
if( is_dir( dirname(__FILE__)."/skins/$e" ) ){
|
|
|
59 |
//get the xml file inside skin directory
|
|
|
60 |
$hh = scandir( dirname(__FILE__)."/skins/$e" ) ;
|
|
|
61 |
$u = array_values(preg_grep("/(.xml)$/i", $hh));
|
|
|
62 |
if( !empty( $u ) ){
|
|
|
63 |
$n = basename($u[0],".xml");
|
|
|
64 |
$skinlist[$e.'/'.$n] = $n;
|
|
|
65 |
}
|
|
|
66 |
}else{
|
|
|
67 |
$n = basename($e,".xml");
|
|
|
68 |
$skinlist[$n] = $n;
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
closedir($h);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
return $skinlist;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/*
|
|
|
79 |
* eduplayer helper
|
|
|
80 |
*/
|
|
|
81 |
function eduplayer_player_helper($eduplayer, $cm, $context) {
|
|
|
82 |
global $CFG, $COURSE, $CFG;
|
|
|
83 |
|
|
|
84 |
$fs = get_file_storage();
|
|
|
85 |
$videofiles = $fs->get_area_files($context->id, 'mod_eduplayer', 'file', false, '', false);
|
|
|
86 |
$captionsfiles = $fs->get_area_files($context->id, 'mod_eduplayer', 'captionsfile', false, '', false);
|
|
|
87 |
switch($eduplayer->type):
|
|
|
88 |
case 'video':
|
|
|
89 |
return eduplayer_player($eduplayer, $context, $videofiles, $captionsfiles);
|
|
|
90 |
break;
|
|
|
91 |
case 'audio':
|
|
|
92 |
return eduplayer_player($eduplayer, $context, $videofiles, $captionsfiles);
|
|
|
93 |
break;
|
|
|
94 |
case 'vplaylist':
|
|
|
95 |
return eduplayer_player_playlist($eduplayer, $context, $videofiles, $captionsfiles);
|
|
|
96 |
break;
|
|
|
97 |
case 'youtube':
|
|
|
98 |
return eduplayer_player($eduplayer, $context, $videofiles, $captionsfiles);
|
|
|
99 |
break;
|
|
|
100 |
case 'ytplaylist':
|
|
|
101 |
return eduplayer_player_playlist($eduplayer, $context, $videofiles, $captionsfiles);
|
|
|
102 |
break;
|
|
|
103 |
case 'vimeo':
|
|
|
104 |
return eduplayer_player_vimeo($eduplayer);
|
|
|
105 |
break;
|
|
|
106 |
case 'url':
|
|
|
107 |
return eduplayer_player($eduplayer, $context, $videofiles, $captionsfiles);
|
|
|
108 |
break;
|
|
|
109 |
case 'rss':
|
|
|
110 |
return eduplayer_player_playlist($eduplayer, $context, $videofiles, $captionsfiles);
|
|
|
111 |
break;
|
|
|
112 |
case 'rtmp':
|
|
|
113 |
return eduplayer_player($eduplayer, $context, $videofiles, $captionsfiles);
|
|
|
114 |
break;
|
|
|
115 |
endswitch;
|
|
|
116 |
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
/*
|
|
|
120 |
* Embed video player
|
|
|
121 |
*/
|
|
|
122 |
function eduplayer_player($eduplayer, $context, $videofiles, $captionsfiles) {
|
|
|
123 |
global $CFG, $COURSE, $CFG;
|
|
|
124 |
|
|
|
125 |
$videos = array();
|
|
|
126 |
$captions = array();
|
|
|
127 |
$general_options = array();
|
|
|
128 |
$playlist_options = '';
|
|
|
129 |
$caption_settings = '';
|
|
|
130 |
$caption_attribute = '';
|
|
|
131 |
$videourl = '';
|
|
|
132 |
$img_attribute = '';
|
|
|
133 |
$attributes=array('showlogo:'. showlogo() .'');
|
|
|
134 |
|
|
|
135 |
//Videos
|
|
|
136 |
if ($eduplayer->urltype == 1) {
|
|
|
137 |
foreach($videofiles as $videofile) {
|
|
|
138 |
$videolabel = explode('.', $videofile->get_filename());
|
|
|
139 |
$videourl = moodle_url::make_file_url('/pluginfile.php', '/'.$context->id.'/mod_eduplayer/file/0/'.$videofile->get_filename());
|
|
|
140 |
$videos[] = '{ file: "'.$videourl.'", label: "'.$videolabel[0].'" }';
|
|
|
141 |
}
|
|
|
142 |
} else {
|
|
|
143 |
$videofiles = $eduplayer->streamer.$eduplayer->eduplayerfile;
|
|
|
144 |
$videos[] = '{ file: "'.$videofiles.'" }';
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
//Start image (Does not work for Vimeo)
|
|
|
148 |
if ($eduplayer->image) {
|
|
|
149 |
$imgurl = moodle_url::make_file_url('/pluginfile.php', '/'.$context->id.'/mod_eduplayer/image/0/'.$eduplayer->image);
|
|
|
150 |
$img_attribute = ' image: "'.$imgurl.'", ';
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
//Captions
|
|
|
154 |
if ($eduplayer->captionsstate != 'false') {
|
|
|
155 |
foreach($captionsfiles as $captionsfile) {
|
|
|
156 |
$captionlabel = explode('.', $captionsfile->get_filename());
|
|
|
157 |
$captionsurl = moodle_url::make_file_url('/pluginfile.php', '/'.$context->id.'/mod_eduplayer/captionsfile/0/'.$captionsfile->get_filename());
|
|
|
158 |
$captions[] = '{ file: "'.$captionsurl.'", label: "'.$captionlabel[0].'" }';
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
//Add captions to params
|
|
|
162 |
if (count($captionsfiles) >= 1) {
|
|
|
163 |
$caption_settings .= 'captions: {'.
|
|
|
164 |
'back: '.$eduplayer->captionsback.', '.
|
|
|
165 |
'fontsize: '.$eduplayer->captionsfontsize.
|
|
|
166 |
'} ';
|
|
|
167 |
$caption_attribute .= 'captions: ['.
|
|
|
168 |
implode(',',$captions).
|
|
|
169 |
'], ';
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
$playlist_attributes = array('title');
|
|
|
173 |
$general_attributes = array('controls', 'eduplayerrepeat', 'autostart', 'stretching', 'mute', 'width', 'height');
|
|
|
174 |
|
|
|
175 |
foreach($eduplayer as $key => $value) {
|
|
|
176 |
if (in_array($key, $playlist_attributes)) {
|
|
|
177 |
$playlist_options .= $key.': "'.$value.'", ';
|
|
|
178 |
}
|
|
|
179 |
if (in_array($key, $general_attributes)) {
|
|
|
180 |
if ($key == 'eduplayerrepeat') {
|
|
|
181 |
$key = 'repeat';
|
|
|
182 |
}
|
|
|
183 |
$general_options[] = $key.': "'.$value.'"';
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
$attributes[] = 'playlist: [{'.
|
|
|
188 |
$img_attribute.
|
|
|
189 |
$caption_attribute.
|
|
|
190 |
$playlist_options.
|
|
|
191 |
'sources: ['. implode( ',', $videos ) .']'.
|
|
|
192 |
'}]';
|
|
|
193 |
if( $caption_settings != '' )
|
|
|
194 |
$attributes[] = $caption_settings;
|
|
|
195 |
$attributes[] = implode(',', $general_options);
|
|
|
196 |
|
|
|
197 |
if( isset($eduplayer->skinxml ) || $eduplayer->eduplayerskin=='')
|
|
|
198 |
$attributes[] = " skin:'skins/default.xml'";
|
|
|
199 |
else
|
|
|
200 |
$attributes[] = " skin:'skins/".$eduplayer->eduplayerskin.".xml'";
|
|
|
201 |
//Player
|
|
|
202 |
$player = html_writer::tag('div', '..Loading..', array('id' => 'videoElement'));
|
|
|
203 |
//JS
|
|
|
204 |
$jscode = 'jwplayer("videoElement").setup({'.
|
|
|
205 |
implode( ',', $attributes ).
|
|
|
206 |
'});';
|
|
|
207 |
$player .= html_writer::script($jscode);
|
|
|
208 |
|
|
|
209 |
return $player;
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
/*
|
|
|
213 |
* Embed Playlist player
|
|
|
214 |
*/
|
|
|
215 |
function eduplayer_player_playlist($eduplayer, $context, $videofiles, $captionsfiles) {
|
|
|
216 |
global $CFG, $COURSE, $CFG, $OUTPUT;
|
|
|
217 |
|
|
|
218 |
$videos = '';
|
|
|
219 |
$captions = '';
|
|
|
220 |
$general_options = '';
|
|
|
221 |
$playlist_options = '';
|
|
|
222 |
$caption_settings = '';
|
|
|
223 |
$caption_attribute = '';
|
|
|
224 |
$img_attribute = '';
|
|
|
225 |
$videourl = '';
|
|
|
226 |
$default_image = $OUTPUT->pix_url('icon_large', 'eduplayer');
|
|
|
227 |
|
|
|
228 |
//Videos
|
|
|
229 |
if ($eduplayer->urltype == 1) {
|
|
|
230 |
foreach($videofiles as $videofile) {
|
|
|
231 |
$videolabel = explode('.', $videofile->get_filename());
|
|
|
232 |
$videourl = moodle_url::make_file_url('/pluginfile.php', '/'.$context->id.'/mod_eduplayer/file/0/'.$videofile->get_filename());
|
|
|
233 |
$videos[] = '{ file: "'.$videourl.'", title: "'.$videolabel[0].'", image: "'.$default_image.'" }';
|
|
|
234 |
}
|
|
|
235 |
} else {
|
|
|
236 |
$videofiles = $eduplayer->eduplayerfile;
|
|
|
237 |
$videos[]= '{ file: "'.$videofiles.'" }';
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
$general_attributes = array('title', 'controls', 'eduplayerrepeat', 'autostart', 'stretching', 'mute', 'width', 'height');
|
|
|
241 |
|
|
|
242 |
foreach($eduplayer as $key => $value) {
|
|
|
243 |
if (in_array($key, $general_attributes)) {
|
|
|
244 |
if ($key == 'eduplayerrepeat') {
|
|
|
245 |
$key = 'repeat';
|
|
|
246 |
}
|
|
|
247 |
$general_options .= $key.': "'.$value.'", ';
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
//Playlist differences
|
|
|
252 |
if ($eduplayer->type == 'ytplaylist') {
|
|
|
253 |
if (stristr($eduplayer->eduplayerfile, 'youtube.com')) {
|
|
|
254 |
$playlistid = explode('list=', $eduplayer->eduplayerfile);
|
|
|
255 |
$playlistid = explode('&', $playlistid[1]);
|
|
|
256 |
$eduplayer->eduplayerfile = $playlistid[0];
|
|
|
257 |
}
|
|
|
258 |
$playlist_options .= 'playlist: "http://gdata.youtube.com/feeds/api/playlists/'.$eduplayer->eduplayerfile.'?alt=rss", ';
|
|
|
259 |
} else if ($eduplayer->type == 'rss') {
|
|
|
260 |
$playlist_options .= 'playlist: "'.$videourl.'", ';
|
|
|
261 |
} else if ($eduplayer->type == 'vplaylist') {
|
|
|
262 |
$playlist_options .= 'playlist: ['. implode(',', $videos ) .'], ';
|
|
|
263 |
}
|
|
|
264 |
$playlist_options .= 'listbar: { position: "'.$eduplayer->playlistposition.'", size: "'.$eduplayer->playlistsize.'" }, ';
|
|
|
265 |
// $playlist_options .= 'primary: "flash", ';
|
|
|
266 |
|
|
|
267 |
$playlist_options .= "flashplayer:'./jwplayer.flash.swf',";
|
|
|
268 |
$playlist_options .= "primary:'flash',";
|
|
|
269 |
$playlist_options .= "fallback:false";
|
|
|
270 |
|
|
|
271 |
$attributes = $general_options;
|
|
|
272 |
$attributes .= $caption_settings;
|
|
|
273 |
$attributes .= $playlist_options;
|
|
|
274 |
if( isset($eduplayer->skinxml ) || $eduplayer->eduplayerskin=='')
|
|
|
275 |
$attributes.= ",skin:'skins/default.xml'";
|
|
|
276 |
else
|
|
|
277 |
$attributes.= ",skin:'skins/".$eduplayer->eduplayerskin.".xml'";
|
|
|
278 |
//Player
|
|
|
279 |
$player = html_writer::tag('div', '..Loading..', array('id' => 'videoElement'));
|
|
|
280 |
//JS
|
|
|
281 |
$jscode = 'jwplayer("videoElement").setup({'.
|
|
|
282 |
$attributes.
|
|
|
283 |
'});';
|
|
|
284 |
$player .= html_writer::script($jscode);
|
|
|
285 |
|
|
|
286 |
return $player;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
/*
|
|
|
290 |
* Vimeo Player(iframe)
|
|
|
291 |
*/
|
|
|
292 |
function eduplayer_player_vimeo($eduplayer) {
|
|
|
293 |
global $CFG, $COURSE, $CFG;
|
|
|
294 |
if (stristr($eduplayer->eduplayerfile, 'vimeo.com')) {
|
|
|
295 |
$videoid = explode('vimeo.com/', $eduplayer->eduplayerfile);
|
|
|
296 |
$eduplayer->eduplayerfile = $videoid[1];
|
|
|
297 |
}
|
|
|
298 |
$content = '<iframe id="videoPlayer" src="https://player.vimeo.com/video/'.$eduplayer->eduplayerfile.'?api=1&player_id=videoPlayer" width="'.$eduplayer->width.'" height="'.$eduplayer->height.'" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
|
|
|
299 |
$player = html_writer::tag('div', $content, array('id' => 'videoElement'));
|
|
|
300 |
|
|
|
301 |
return $player;
|
|
|
302 |
}
|