Proyectos de Subversion Moodle

Rev

| 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
 * Embed H5P Content
18
 *
19
 * @package    mod_hvp
20
 * @copyright  2016 Joubel AS <contact@joubel.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
require_once("../../config.php");
24
require_once("locallib.php");
25
 
26
global $PAGE, $DB, $CFG, $OUTPUT;
27
 
28
$id = required_param('id', PARAM_INT);
29
 
30
// Allow login through an authentication token.
31
$userid = optional_param('user_id', null, PARAM_ALPHANUMEXT);
32
$secret  = optional_param('secret', null, PARAM_RAW);
33
$disabledownload = false;
34
$disablefullscreen = false;
35
if (\mod_hvp\mobile_auth::has_valid_token($userid, $secret)) {
36
    $user = get_complete_user_data('id', $userid);
37
    complete_user_login($user);
38
    $disabledownload = true;
39
    $disablefullscreen = true;
40
}
41
 
42
// Verify course context.
43
$cm = get_coursemodule_from_id('hvp', $id);
44
if (!$cm) {
45
    print_error('invalidcoursemodule');
46
}
47
$course = $DB->get_record('course', array('id' => $cm->course));
48
if (!$course) {
49
    print_error('coursemisconf');
50
}
51
 
52
try {
53
    require_course_login($course, true, $cm, true, true);
54
} catch (Exception $e) {
55
    $PAGE->set_pagelayout('embedded');
56
    $root = \mod_hvp\view_assets::getsiteroot();
57
    $embedfailedsvg = new \moodle_url("{$root}/mod/hvp/library/images/h5p.svg");
58
    echo '<body style="margin:0">' .
59
         '<div style="background: #fafafa ' .
60
         'url(' . $embedfailedsvg->out() . ') no-repeat center;' .
61
         'background-size: 50% 50%;width: 100%;height: 100%;">' .
62
         '</div>' .
63
         '<div style="width:100%;position:absolute;top:75%;text-align:center;color:#434343;' .
64
         'font-family: Consolas,monaco,monospace"' .
65
         '>' .
66
         get_string('embedloginfailed', 'hvp') .
67
         '</div>' .
68
         '</body>';
69
    return;
70
}
71
$context = context_module::instance($cm->id);
72
require_capability('mod/hvp:view', $context);
73
 
74
// Set up view assets.
75
$view = new \mod_hvp\view_assets($cm, $course, [
76
    'disabledownload'   => $disabledownload,
77
    'disablefullscreen' => $disablefullscreen
78
]);
79
$content = $view->getcontent();
80
$view->validatecontent();
81
 
82
// Release session while loading the rest of our assets.
83
core\session\manager::write_close();
84
 
85
// Configure page.
86
$PAGE->set_url(new \moodle_url('/mod/hvp/embed.php', array('id' => $id)));
87
$PAGE->set_title(format_string($content['title']));
88
$PAGE->set_heading($course->fullname);
89
 
90
// Embed specific page setup.
91
$PAGE->add_body_class('h5p-embed');
92
$PAGE->set_pagelayout('embedded');
93
$root = \mod_hvp\view_assets::getsiteroot();
94
$PAGE->requires->js_call_amd('mod_hvp/embed');
95
// Add H5P assets to page.
96
$view->addassetstopage();
97
$view->logviewed();
98
 
99
// Print page HTML.
100
echo $OUTPUT->header();
101
echo '<div class="clearer"></div>';
102
 
103
// Print any messages.
104
\mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info'));
105
\mod_hvp\framework::printMessages('error', \mod_hvp\framework::messages('error'));
106
 
107
$view->outputview();
108
echo $OUTPUT->footer();