2016-12-17 19:52:59 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use View;
|
2017-01-02 12:19:34 +08:00
|
|
|
use Datatables;
|
2016-12-17 19:52:59 +08:00
|
|
|
use App\Events;
|
2018-06-29 16:37:39 +08:00
|
|
|
use App\Services\Plugin;
|
2016-12-17 19:52:59 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Services\PluginManager;
|
|
|
|
|
|
|
|
class PluginController extends Controller
|
|
|
|
{
|
2017-11-16 10:09:58 +08:00
|
|
|
/**
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
2016-12-17 19:52:59 +08:00
|
|
|
public function showMarket()
|
|
|
|
{
|
2017-08-05 14:40:56 +08:00
|
|
|
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-02 10:39:50 +08:00
|
|
|
|
2017-01-17 21:41:20 +08:00
|
|
|
public function config($name, Request $request)
|
|
|
|
{
|
|
|
|
$plugin = plugin($name);
|
2017-01-02 10:39:50 +08:00
|
|
|
|
2017-01-17 21:41:20 +08:00
|
|
|
if ($plugin && $plugin->isEnabled() && $plugin->hasConfigView()) {
|
|
|
|
return $plugin->getConfigView();
|
|
|
|
} else {
|
2017-11-16 10:09:58 +08:00
|
|
|
return abort(404, trans('admin.plugins.operations.no-config-notice'));
|
2017-01-17 21:41:20 +08:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2018-02-16 17:31:04 +08:00
|
|
|
// Pass the plugin title through the translator.
|
2017-01-17 21:41:20 +08:00
|
|
|
$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':
|
2018-06-29 16:37:39 +08:00
|
|
|
if (! $plugins->isRequirementsSatisfied($name)) {
|
|
|
|
$msg = '';
|
|
|
|
|
|
|
|
foreach ($plugins->getUnsatisfiedRequirements($name) as $name => $detail) {
|
|
|
|
if (! $detail['version']) {
|
|
|
|
$msg .= '<li>'.trans('admin.plugins.operations.unsatisfied.disabled', [
|
|
|
|
'name' => "<code>$name</code>"
|
|
|
|
]).'</li>';
|
|
|
|
} else {
|
|
|
|
$msg .= '<li>'.trans('admin.plugins.operations.unsatisfied.version', [
|
|
|
|
'name' => "<code>$name</code>",
|
|
|
|
'constraint' => "<code>{$detail['constraint']}</code>"
|
|
|
|
]).'</li>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return json('<p>'.trans('admin.plugins.operations.unsatisfied.notice')."</p><ul>$msg</ul>", 1);
|
|
|
|
}
|
|
|
|
|
2017-01-17 21:41:20 +08:00
|
|
|
$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
|
|
|
|
2018-06-29 16:37:39 +08:00
|
|
|
case 'requirements':
|
|
|
|
return json($this->getPluginDependencies($plugin));
|
|
|
|
|
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:
|
2017-11-16 10:09:58 +08:00
|
|
|
return json(trans('admin.invalid-action'), 1);
|
2016-12-17 19:52:59 +08:00
|
|
|
}
|
2017-11-16 10:09:58 +08:00
|
|
|
} else {
|
|
|
|
return json(trans('admin.plugins.operations.not-found'), 1);
|
2016-12-17 19:52:59 +08:00
|
|
|
}
|
2017-01-02 12:19:34 +08:00
|
|
|
}
|
2016-12-17 19:52:59 +08:00
|
|
|
|
2017-01-02 12:19:34 +08:00
|
|
|
public function getPluginData(PluginManager $plugins)
|
|
|
|
{
|
|
|
|
$installed = $plugins->getPlugins();
|
|
|
|
|
|
|
|
return Datatables::of($installed)
|
|
|
|
->setRowId('plugin-{{ $name }}')
|
|
|
|
->editColumn('title', function ($plugin) {
|
2018-06-28 12:07:20 +08:00
|
|
|
return trans($plugin->title ?: 'EMPTY');
|
2017-01-02 12:19:34 +08:00
|
|
|
})
|
|
|
|
->editColumn('description', function ($plugin) {
|
2018-06-28 12:07:20 +08:00
|
|
|
return trans($plugin->description ?: 'EMPTY');
|
2017-01-02 12:19:34 +08:00
|
|
|
})
|
2017-01-14 20:26:38 +08:00
|
|
|
->editColumn('author', function ($plugin) {
|
2018-06-28 12:07:20 +08:00
|
|
|
return ['author' => trans($plugin->author ?: 'EMPTY'), 'url' => $plugin->url];
|
2017-01-14 20:26:38 +08:00
|
|
|
})
|
2018-06-29 16:37:39 +08:00
|
|
|
->addColumn('dependencies', function ($plugin) {
|
|
|
|
return $this->getPluginDependencies($plugin);
|
|
|
|
})
|
2017-01-02 12:19:34 +08:00
|
|
|
->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()];
|
2017-01-02 12:19:34 +08:00
|
|
|
})
|
|
|
|
->make(true);
|
2016-12-17 19:52:59 +08:00
|
|
|
}
|
2018-06-29 16:37:39 +08:00
|
|
|
|
|
|
|
protected function getPluginDependencies(Plugin $plugin)
|
|
|
|
{
|
|
|
|
$plugins = app('plugins');
|
|
|
|
|
|
|
|
return [
|
|
|
|
'isRequirementsSatisfied' => $plugins->isRequirementsSatisfied($plugin->name),
|
|
|
|
'requirements' => $plugin->getRequirements(),
|
|
|
|
'unsatisfiedRequirements' => $plugins->getUnsatisfiedRequirements($plugin->name)
|
|
|
|
];
|
|
|
|
}
|
2016-12-17 19:52:59 +08:00
|
|
|
}
|