blessing-skin-server/app/Http/Controllers/PluginController.php

91 lines
2.7 KiB
PHP
Raw Normal View History

2016-12-17 19:52:59 +08:00
<?php
namespace App\Http\Controllers;
use View;
use Datatables;
2016-12-17 19:52:59 +08:00
use App\Events;
use Illuminate\Http\Request;
use App\Services\PluginManager;
class PluginController extends Controller
{
public function showMarket()
{
return redirect('/')->setTargetUrl(
'https://github.com/printempw/blessing-skin-server/wiki/Plugins'
);
2016-12-17 19:52:59 +08:00
}
2017-01-17 21:41:20 +08:00
public function showManage()
2016-12-17 19:52:59 +08:00
{
2017-01-17 21:41:20 +08:00
return view('admin.plugins');
}
2017-01-17 21:41:20 +08:00
public function config($name, Request $request)
{
$plugin = plugin($name);
2017-01-17 21:41:20 +08:00
if ($plugin && $plugin->isEnabled() && $plugin->hasConfigView()) {
return $plugin->getConfigView();
} else {
abort(404, trans('admin.plugins.operations.no-config-notice'));
}
}
2016-12-17 19:52:59 +08:00
2017-01-17 21:41:20 +08:00
public function manage(Request $request, PluginManager $plugins)
{
$plugin = plugin($name = $request->get('name'));
2016-12-17 19:52:59 +08:00
2017-01-17 21:41:20 +08:00
if ($plugin) {
// pass the plugin title through the translator
$plugin->title = trans($plugin->title);
2016-12-17 19:52:59 +08:00
2017-01-17 21:41:20 +08:00
switch ($request->get('action')) {
case 'enable':
$plugins->enable($name);
2016-12-17 19:52:59 +08:00
2017-01-17 21:41:20 +08:00
return json(trans('admin.plugins.operations.enabled', ['plugin' => $plugin->title]), 0);
2016-12-17 19:52:59 +08:00
2017-01-17 21:41:20 +08:00
case 'disable':
$plugins->disable($name);
2016-12-17 19:52:59 +08:00
2017-01-17 21:41:20 +08:00
return json(trans('admin.plugins.operations.disabled', ['plugin' => $plugin->title]), 0);
2016-12-17 19:52:59 +08:00
2017-01-17 21:41:20 +08:00
case 'delete':
$plugins->uninstall($name);
2016-12-17 19:52:59 +08:00
2017-01-17 21:41:20 +08:00
return json(trans('admin.plugins.operations.deleted'), 0);
2016-12-17 19:52:59 +08:00
2017-01-17 21:41:20 +08:00
default:
# code...
break;
2016-12-17 19:52:59 +08:00
}
}
}
2016-12-17 19:52:59 +08:00
public function getPluginData(PluginManager $plugins)
{
$installed = $plugins->getPlugins();
return Datatables::of($installed)
->setRowId('plugin-{{ $name }}')
->editColumn('title', function ($plugin) {
return trans($plugin->title);
})
->editColumn('description', function ($plugin) {
return trans($plugin->description);
})
->editColumn('author', function ($plugin) {
2017-04-22 18:36:22 +08:00
return ['author' => trans($plugin->author), 'url' => $plugin->url];
})
->addColumn('status', function ($plugin) {
return trans('admin.plugins.status.'.($plugin->isEnabled() ? 'enabled' : 'disabled'));
})
->addColumn('operations', function ($plugin) {
2017-04-22 18:36:22 +08:00
return ['enabled' => $plugin->isEnabled(), 'hasConfigView' => $plugin->hasConfigView()];
})
->make(true);
2016-12-17 19:52:59 +08:00
}
}