blob: 2ed6e7aeccb464bd5a6e88480b864e30bb19473c (
plain)
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
|
<?php
require_once('Login.class.php');
require_once('Plugin.class.php');
require_once('PluginManager.class.php');
require_once('Auth.class.php');
require_once('Database.class.php');
Router::register('plugins', 'Plugins');
class Plugins extends Controller {
public function index($routed, $remainder) {
$uid = Login::isLoggedIn();
if ($uid===false || !Auth::getInstance($uid)->isAdmin()) {
$this->http401($routed, $remainder);
return;
}
$method = $_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'PUT': $_POST = $_PUT;
case 'POST':
// We're PUTing an updated user index.
$this->update();
break;
}
$this->show_index();
}
private function update() {
$db = Database::getInstance();
if (isset($_POST['plugins'])) {
$string = $db->arrayToValue($_POST['plugins']);
$db->setSysConf('plugins', $string);
}
if (isset($_POST['config'])) {
foreach ($_POST['config'] as $plugin_name => $plugin) {
foreach ($plugin as $param => $value) {
$db->setPluginConf($plugin_name,
$param,
$value);
}
}
}
}
private function show_index() {
$pm = PluginManager::getInstance();
$all_plugins = $pm->listPlugins();
$enabled_plugins = $pm->getActivePlugins();
$plugin_data = array();
foreach ($all_plugins as $plugin_name) {
$plugin = array();
$plugin['name'] = $plugin_name;
$plugin['key'] = 'config['.$plugin_name.']';
$plugin['active'] =
in_array($plugin_name, $enabled_plugins);
$plugin['description'] =
$pm->staticHook($plugin_name, 'description');
$plugin['config'] =
$pm->staticHook($plugin_name, 'configList');
$plugin_data[] = $plugin;
}
$vars = array();
$vars['plugins'] = $plugin_data;
$this->showView('plugins/index', $vars);
}
public function http401($routed, $remainder) {
$this->showView('plugins/401');
}
}
|