forked from Ghostthinker/moodle-mod_ivs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.php
116 lines (91 loc) · 3.42 KB
/
backend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* File for the backend
*
* @package mod_ivs
* @author Ghostthinker GmbH <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2017 onwards Ghostthinker GmbH (https://ghostthinker.de/)
*/
use mod_ivs\MediaController;
use mod_ivs\MoodleMatchController;
define('AJAX_SCRIPT', true);
require('../../config.php');
require_login(null, false);
$action = optional_param('action', false, PARAM_ALPHA);
$view = optional_param('view', false, PARAM_ALPHA);
// Security.
$PAGE->set_context(context_system::instance());
error_reporting(error_reporting() & ~E_NOTICE);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
$wwwroot = $CFG->wwwroot;
$pathendpoint = $wwwroot . "/mod/ivs/backend.php/";
$httpschema = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$backendService = new \mod_ivs\BackendService();
if (!isset($_SERVER['HTTP_HOST'])) {
$backendService->ivs_backend_error_exit();
}
$httphost = $_SERVER['HTTP_HOST'];
if (!isset($_SERVER['REQUEST_URI'])) {
$backendService->ivs_backend_error_exit();
}
$requesturi = strtok($_SERVER["REQUEST_URI"], '?');
$actualurl = $httpschema . '://' . $httphost . $requesturi;
$url = str_replace($pathendpoint, "", $actualurl);
$args = explode("/", $url);
$endpoint = $args[0];
$videoid = $args[1];
$postdata = array();
if (!\mod_ivs\IvsHelper::access_player($videoid)) {
$backendService->ivs_backend_error_exit();
}
if (!isset($_SERVER['REQUEST_METHOD'])) {
$backendService->ivs_backend_error_exit();
}
$requestmethod = $_SERVER['REQUEST_METHOD'];
switch ($endpoint) {
case 'comments':
if ($requestbody = file_get_contents('php://input')) {
$postdata = json_decode($requestbody);
}
$backendService->ivs_backend_comments($args, $postdata, $requestmethod);
break;
case 'playbackcommands':
if ($requestbody = file_get_contents('php://input')) {
$postdata = json_decode($requestbody);
}
$backendService->ivs_backend_playbackcommands($args, $postdata, $requestmethod);
break;
case 'match_questions':
case 'match_answers':
case "match_context":
$mc = new MoodleMatchController();
array_shift($args);
if ($requestbody = file_get_contents('php://input')) {
$postdata = json_decode($requestbody, true);
}
$mc->handle_request($endpoint, $args, $requestmethod, $postdata);
break;
case "media":
$mc = new MediaController();
array_shift($args);
if ($requestbody = file_get_contents('php://input')) {
$postdata = json_decode($requestbody, true);
}
$mc->handle_request($args, $requestmethod, $_FILES);
}