-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathserver.php
More file actions
114 lines (92 loc) · 2.56 KB
/
server.php
File metadata and controls
114 lines (92 loc) · 2.56 KB
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
<?php
/**
* Plugin BatchEdit: AJAX server
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Mykola Ostrovskyy <dwpforge@gmail.com>
*/
require_once(DOKU_PLUGIN . 'batchedit/engine.php');
class BatcheditServer {
const AJAX_COOKIE = '{7b4e584c-bf85-4f7b-953b-15e327df08ff}';
private $plugin;
/**
*
*/
public function __construct($plugin) {
$this->plugin = $plugin;
}
/**
*
*/
public function handle() {
try {
$this->verifyAdminRights();
switch ($_REQUEST['command']) {
case 'cancel':
$this->handleCancel();
break;
case 'progress':
$this->handleProgress();
break;
}
}
catch (Exception $error) {
$this->sendResponse(array('error' => 'server_error', 'message' => $error->getMessage()));
}
}
/**
*
*/
private function verifyAdminRights() {
global $conf;
if (auth_quickaclcheck($conf['start']) < AUTH_ADMIN) {
throw new Exception('Access denied');
}
}
/**
*
*/
private function verifySession() {
if (!isset($_REQUEST['session']) || preg_match('/^[0-9a-f]+$/', $_REQUEST['session']) != 1) {
throw new Exception('Invalid session identifier');
}
}
/**
*
*/
private function handleCancel() {
$this->verifySession();
BatcheditEngine::cancelOperation($_REQUEST['session']);
}
/**
*
*/
private function handleProgress() {
$this->verifySession();
$progress = new BatcheditProgress($_REQUEST['session']);
list($operation, $progress) = $progress->get();
if ($operation == BatcheditProgress::UNKNOWN) {
throw new Exception('Progress unknown');
}
$this->sendResponse(array('operation' => $this->getProgressLabel($operation), 'progress' => $progress));
}
/**
*
*/
private function getProgressLabel($operation) {
switch ($operation) {
case BatcheditProgress::SEARCH:
return $this->plugin->getLang('lbl_searching');
case BatcheditProgress::APPLY:
return $this->plugin->getLang('lbl_applying');
}
return '';
}
/**
*
*/
private function sendResponse($data) {
header('Content-Type: application/json');
print(self::AJAX_COOKIE . json_encode($data) . self::AJAX_COOKIE);
}
}