Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
/**
19
 * A script to embed vimeo videos via the site (so vimeo privacy restrictions by domain will work in the mobile app).
20
 *
21
 * The site is doing a double frame embedding:
22
 *  - First, the media player replaces the vimeo link with an iframe pointing to vimeo.
23
 *  - Second, the app replaces the previous iframe link with a link to this file that includes again the iframe to vimeo.
24
 *  Thanks to these changes, the video is embedded in a page in the site server so the privacy restrictions will work.
25
 *
26
 *  Note 1: Vimeo privacy restrictions seems to be based on the Referer HTTP header.
27
 *  Note 2: This script works even if the plugin is disabled (some users could be using the vimeo embedding code).
28
 *
29
 * @package    media_vimeo
30
 * @copyright  2017 Juan Leyva
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
 
34
define('NO_MOODLE_COOKIES', true);
35
 
36
require_once(__DIR__ . '/../../../config.php');
37
require_once($CFG->dirroot . '/webservice/lib.php');
38
 
39
global $OUTPUT;
40
 
41
$token = required_param('token', PARAM_ALPHANUM);
42
$video = required_param('video', PARAM_ALPHANUM);   // Video ids are numeric, but it's more solid to expect things like 00001.
43
$width = optional_param('width', 0, PARAM_INT);
44
$height = optional_param('height', 0, PARAM_INT);
45
$h = optional_param('h', '', PARAM_ALPHANUM); // Security hash for restricted videos.
46
 
47
// Authenticate the user.
48
$webservicelib = new webservice();
49
$webservicelib->authenticate_user($token);
50
 
51
$params = ['lang' => current_language()];
52
if (!empty($h)) {
53
    $params['h'] = $h;
54
}
55
 
56
// Add do not track parameter.
57
if (get_config('media_vimeo', 'donottrack')) {
58
    $params['dnt'] = 1;
59
}
60
 
61
$embedurl = new moodle_url("https://player.vimeo.com/video/$video", $params);
62
$context = ['embedurl' => $embedurl->out(false)]; // Template context.
63
 
64
if (empty($width) && empty($height)) {
65
    // Use the full page. The video will keep the ratio.
11 efrain 66
    $context['style'] = "position:absolute; top:0; left:0; width:100%; height:100%;";
1 efrain 67
} else {
68
    $context['width'] = $width;
69
    $context['height'] = $height;
70
}
71
 
72
// Output the rendered template.
73
echo $OUTPUT->render_from_template('media_vimeo/appembed', $context);