-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcallback.php
101 lines (85 loc) · 3.09 KB
/
callback.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
<?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/>.
/**
*
* @package mod_onlyoffice
* @subpackage
* @copyright 2018 Olumuyiwa Taiwo <[email protected]>
* @author Olumuyiwa Taiwo {@link https://moodle.org/user/view.php?id=416594}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* @todo Log disconnection (editor close) for respective user. note, editor open (connection) is logged in view.php
*/
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
defined('AJAX_SCRIPT') or define('AJAX_SCRIPT', true);
$doc = required_param('doc', PARAM_RAW);
header('Content-Type: application/json; charset=utf-8');
header('X-Content-Type-Options: nosniff');
header('X-Robots-Tag: noindex');
header('Content-Encoding: UTF-8');
header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . 'GMT');
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$response = [];
$response['status'] = 'success';
$response['error'] = 1;
if (empty($doc)) {
$response['error'] = 'Bad request';
die(json_encode($response));
}
$crypt = new \mod_onlyoffice\crypt();
list($hash, $error) = $crypt->read_hash($doc);
if ($error || $hash == null) {
die(json_encode($response));
}
$request = file_get_contents('php://input');
if ($request === false) {
die(json_encode($response));
}
$data = json_decode($request, true);
if ($data === null) {
die(json_encode($response));
}
if (isset($data['status'])) {
$status = (int) $data['status'];
switch ($status) {
case mod_onlyoffice\util::STATUS_NOTFOUND:
$response['error'] = 1;
break;
case mod_onlyoffice\util::STATUS_MUSTSAVE:
case mod_onlyoffice\util::STATUS_FORCESAVE:
// Save to Moodle.
if (mod_onlyoffice\util::save_document_to_moodle($data, $hash)) {
$response['error'] = 0;
} else {
$response['error'] = 1;
}
break;
case mod_onlyoffice\util::STATUS_ERRORSAVING:
case mod_onlyoffice\util::STATUS_ERRORFORCESAVE:
$response['error'] = 1;
break;
case mod_onlyoffice\util::STATUS_EDITING:
case mod_onlyoffice\util::STATUS_CLOSEDNOCHANGES:
$response['error'] = 0;
break;
default:
$response['error'] = 1;
}
}
die(json_encode($response));