Initial dev export (exclude uploads/runtime)
This commit is contained in:
55
modules/plugins/PluginsController.php
Normal file
55
modules/plugins/PluginsController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Plugins;
|
||||
|
||||
use Core\Http\Response;
|
||||
use Core\Services\Auth;
|
||||
use Core\Services\Plugins;
|
||||
use Core\Views\View;
|
||||
|
||||
class PluginsController
|
||||
{
|
||||
private View $view;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->view = new View(__DIR__ . '/views');
|
||||
}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
if ($guard = $this->guard()) {
|
||||
return $guard;
|
||||
}
|
||||
Plugins::sync();
|
||||
return new Response($this->view->render('admin/index.php', [
|
||||
'title' => 'Plugins',
|
||||
'plugins' => Plugins::all(),
|
||||
]));
|
||||
}
|
||||
|
||||
public function toggle(): Response
|
||||
{
|
||||
if ($guard = $this->guard()) {
|
||||
return $guard;
|
||||
}
|
||||
$slug = trim((string)($_POST['slug'] ?? ''));
|
||||
$enabled = isset($_POST['enabled']) && $_POST['enabled'] === '1';
|
||||
if ($slug !== '') {
|
||||
Plugins::toggle($slug, $enabled);
|
||||
}
|
||||
return new Response('', 302, ['Location' => '/admin/plugins']);
|
||||
}
|
||||
|
||||
private function guard(): ?Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return new Response('', 302, ['Location' => '/admin/login']);
|
||||
}
|
||||
if (!Auth::hasRole(['admin'])) {
|
||||
return new Response('', 302, ['Location' => '/admin']);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user