-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPlugins.php
More file actions
136 lines (113 loc) · 4.49 KB
/
Plugins.php
File metadata and controls
136 lines (113 loc) · 4.49 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Controller\Admin;
use FeatherBB\Core\AdminUtils;
use FeatherBB\Core\Error;
use FeatherBB\Core\Interfaces\Cache;
use FeatherBB\Core\Interfaces\Container;
use FeatherBB\Core\Interfaces\ForumEnv;
use FeatherBB\Core\Interfaces\ForumSettings;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\Lang;
use FeatherBB\Core\Interfaces\Request;
use FeatherBB\Core\Interfaces\Router;
use FeatherBB\Core\Interfaces\User;
use FeatherBB\Core\Interfaces\View;
use FeatherBB\Core\Lister;
use FeatherBB\Core\Utils;
class Plugins
{
public function __construct()
{
$this->model = new \FeatherBB\Model\Admin\Plugins();
Lang::load('admin/plugins');
if (!User::isAdmin()) {
throw new Error(__('No permission'), '403');
}
}
/**
* Download a plugin, unzip it and rename it
*/
public function download($req, $res, $args)
{
Hooks::fire('controller.admin.plugins.download');
return $this->model->download($args);
}
public function index($req, $res, $args)
{
Hooks::fire('controller.admin.plugins.index');
if (Request::isPost()) {
return $this->model->uploadPlugin($_fILES);
}
View::addAsset('js', 'style/imports/common.js', ['type' => 'text/javascript']);
$availablePlugins = Lister::getPlugins();
$activePlugins = Cache::isCached('activePlugins') ? Cache::retrieve('activePlugins') : [];
$officialPlugins = Lister::getOfficialPlugins();
AdminUtils::generateAdminMenu('plugins');
View::setPageInfo([
'admin_console' => true,
'active_page' => 'admin',
'availablePlugins' => $availablePlugins,
'activePlugins' => $activePlugins,
'officialPlugins' => $officialPlugins,
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Extension')],
]
)->addTemplate('@forum/admin/plugins')->display();
}
public function activate($req, $res, $args)
{
Hooks::fire('controller.admin.plugins.activate');
if (!$args['name'] || !is_dir(ForumEnv::get('FEATHER_ROOT').'plugins'.DIRECTORY_SEPARATOR.$args['name'])) {
throw new Error(__('Bad request'), 400);
}
$this->model->activate($args['name']);
// Plugin has been activated, confirm and redirect
return Router::redirect(Router::pathFor('adminPlugins'), sprintf(__('Plugin activated'), $args['name']));
}
public function deactivate($req, $res, $args)
{
Hooks::fire('controller.admin.plugins.deactivate');
if (!$args['name'] || !is_dir(ForumEnv::get('FEATHER_ROOT').'plugins'.DIRECTORY_SEPARATOR.$args['name'])) {
throw new Error(__('Bad request'), 400);
}
$this->model->deactivate($args['name']);
// Plugin has been deactivated, confirm and redirect
return Router::redirect(Router::pathFor('adminPlugins'), ['warning', sprintf(__('Plugin deactivated'), $args['name'])]);
}
public function uninstall($req, $res, $args)
{
Hooks::fire('controller.admin.plugins.uninstall');
if (!$args['name'] || !is_dir(ForumEnv::get('FEATHER_ROOT').'plugins'.DIRECTORY_SEPARATOR.$args['name'])) {
throw new Error(__('Bad request'), 400);
}
$this->model->uninstall($args['name']);
// Plugin has been uninstalled, confirm and redirect
return Router::redirect(Router::pathFor('adminPlugins'), ['warning', sprintf(__('Plugin uninstalled'), $args['name'])]);
}
/**
* Load plugin info if it exists
* @param null $pluginName
* @throws Error
*/
public function info($req, $res, $args)
{
$formattedPluginName = str_replace(' ', '', ucwords(str_replace('-', ' ', $args['name'])));
$new = '\FeatherBB\Plugins\Controller\\'.$formattedPluginName;
if (class_exists($new)) {
$plugin = new $new;
if (method_exists($plugin, 'info')) {
AdminUtils::generateAdminMenu($args['name']);
return $plugin->info($req, $res, $args);
} else {
throw new Error(__('Bad request'), 400);
}
} else {
throw new Error(__('Bad request'), 400);
}
}
}