Another teaspoon of code for the extension system
This commit is contained in:
parent
95aa1fa7bf
commit
dff71bcace
8 changed files with 245 additions and 56 deletions
|
@ -839,7 +839,7 @@ class Routing
|
|||
'AdminAntispam'
|
||||
);
|
||||
$r->add(
|
||||
$r::GET,
|
||||
$r::DUO,
|
||||
'/admin/extensions',
|
||||
'AdminExtensions:info',
|
||||
'AdminExtensions'
|
||||
|
|
|
@ -39,6 +39,11 @@ class Extension extends Model
|
|||
return $this->dbData['version'] ?? $this->fileData['version'];
|
||||
}
|
||||
|
||||
protected function getfileVersion(): string
|
||||
{
|
||||
return $this->fileData['version'] ?? '-';
|
||||
}
|
||||
|
||||
protected function getname(): string
|
||||
{
|
||||
return $this->dbData['name'] ?? $this->fileData['name'];
|
||||
|
@ -102,4 +107,34 @@ class Extension extends Model
|
|||
throw new RuntimeException("Error in {$this->name} extension status");
|
||||
}
|
||||
}
|
||||
|
||||
protected function getcanInstall(): bool
|
||||
{
|
||||
return self::NOT_INSTALLED === $this->status;
|
||||
}
|
||||
|
||||
protected function getcanUninstall(): bool
|
||||
{
|
||||
return \in_array($this->status, [self::DISABLED, self::DISABLED_DOWN, self::DISABLED_UP], true);
|
||||
}
|
||||
|
||||
protected function getcanUpdate(): bool
|
||||
{
|
||||
return \in_array($this->status, [self::DISABLED_UP, self::ENABLED_UP], true);
|
||||
}
|
||||
|
||||
protected function getcanDowndate(): bool
|
||||
{
|
||||
return \in_array($this->status, [self::DISABLED_DOWN, self::ENABLED_DOWN], true);
|
||||
}
|
||||
|
||||
protected function getcanEnable(): bool
|
||||
{
|
||||
return self::DISABLED === $this->status;
|
||||
}
|
||||
|
||||
protected function getcanDisable(): bool
|
||||
{
|
||||
return \in_array($this->status, [self::ENABLED, self::ENABLED_DOWN, self::ENABLED_UP, self::CRASH], true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,8 @@ class Extensions extends Manager
|
|||
*/
|
||||
protected function prepare(array $files): array
|
||||
{
|
||||
$v = $this->c->Validator->reset()
|
||||
$v = clone $this->c->Validator;
|
||||
$v = $v->reset()
|
||||
->addValidators([
|
||||
])->addRules([
|
||||
'name' => 'required|string',
|
||||
|
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace ForkBB\Models\Pages\Admin;
|
||||
|
||||
use ForkBB\Models\Extension\Extension;
|
||||
use ForkBB\Models\Page;
|
||||
use ForkBB\Models\Pages\Admin;
|
||||
use Throwable;
|
||||
|
@ -20,14 +21,69 @@ class Extensions extends Admin
|
|||
/**
|
||||
* Подготавливает данные для шаблона
|
||||
*/
|
||||
public function info(): Page
|
||||
public function info(array $args, string $method): Page
|
||||
{
|
||||
$this->c->Lang->load('admin_extensions');
|
||||
|
||||
if ('POST' === $method) {
|
||||
return $this->action($args, $method);
|
||||
}
|
||||
|
||||
$this->nameTpl = 'admin/extensions';
|
||||
$this->aIndex = 'extensions';
|
||||
$this->extensions = $this->c->extensions->repository;
|
||||
$this->actionLink = $this->c->Router->link('AdminExtensions');
|
||||
$this->formsToken = $this->c->Csrf->create('AdminExtensions');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function action(array $args, string $method): Page
|
||||
{
|
||||
$v = $this->c->Validator->reset()
|
||||
->addRules([
|
||||
'token' => 'token:AdminExtensions',
|
||||
'name' => 'required|string',
|
||||
'confirm' => 'required|string|in:1',
|
||||
'install' => 'string',
|
||||
'uninstall' => 'string',
|
||||
'update' => 'string',
|
||||
'downdate' => 'string',
|
||||
'enable' => 'string',
|
||||
'disable' => 'string',
|
||||
])->addAliases([
|
||||
])->addMessages([
|
||||
'confirm' => [FORK_MESS_WARN, 'No confirm redirect'],
|
||||
])->addArguments([
|
||||
]);
|
||||
|
||||
if (! $v->validation($_POST)) {
|
||||
$message = $this->c->Message;
|
||||
$message->fIswev = $v->getErrors();
|
||||
|
||||
return $message->message('');
|
||||
}
|
||||
|
||||
$ext = $this->c->extensions->get($v->name);
|
||||
|
||||
if (! $ext instanceof Extension) {
|
||||
return $this->c->Message->message('Extension not found');
|
||||
}
|
||||
|
||||
$actions = $v->getData(false, ['token', 'name', 'confirm']);
|
||||
$action = \array_key_first($actions);
|
||||
|
||||
if (empty($action)) {
|
||||
return $this->c->Message->message('Invalid action');
|
||||
}
|
||||
|
||||
$property = 'can' . \ucfirst($action);
|
||||
|
||||
if (true !== $ext->{$property}) {
|
||||
return $this->c->Message->message('Invalid action');
|
||||
}
|
||||
|
||||
exit(var_dump('<pre>', $_POST, '</pre>'));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ msgstr ""
|
|||
"Language: en\n"
|
||||
|
||||
msgid "Details"
|
||||
msgstr "Details"
|
||||
msgstr "Details:"
|
||||
|
||||
msgid "Name"
|
||||
msgstr "Name of package"
|
||||
|
@ -31,10 +31,10 @@ msgid "Licence"
|
|||
msgstr "Licence"
|
||||
|
||||
msgid "Requirements"
|
||||
msgstr "Requirements"
|
||||
msgstr "Requirements:"
|
||||
|
||||
msgid "Authors"
|
||||
msgstr "Author(s)"
|
||||
msgstr "Author(s):"
|
||||
|
||||
msgid "php"
|
||||
msgstr "PHP version"
|
||||
|
@ -59,3 +59,30 @@ msgstr "Enabled, but package changed!"
|
|||
|
||||
msgid "Crash"
|
||||
msgstr "Crash, package not found!"
|
||||
|
||||
msgid "Install_"
|
||||
msgstr "Install"
|
||||
|
||||
msgid "Uninstall_"
|
||||
msgstr "Uninstall"
|
||||
|
||||
msgid "Enable_"
|
||||
msgstr "Enable"
|
||||
|
||||
msgid "Disable_"
|
||||
msgstr "Disable"
|
||||
|
||||
msgid "Update_"
|
||||
msgstr "Update"
|
||||
|
||||
msgid "Downdate_"
|
||||
msgstr "Downdate"
|
||||
|
||||
msgid "Package version"
|
||||
msgstr "Package version"
|
||||
|
||||
msgid "Extension not found"
|
||||
msgstr "Extension not found."
|
||||
|
||||
msgid "Invalid action"
|
||||
msgstr "Invalid action."
|
||||
|
|
|
@ -13,7 +13,7 @@ msgstr ""
|
|||
"Language: ru\n"
|
||||
|
||||
msgid "Details"
|
||||
msgstr "Подробности"
|
||||
msgstr "Подробности:"
|
||||
|
||||
msgid "Name"
|
||||
msgstr "Имя пакета"
|
||||
|
@ -31,10 +31,10 @@ msgid "Licence"
|
|||
msgstr "Лицензия"
|
||||
|
||||
msgid "Requirements"
|
||||
msgstr "Требования"
|
||||
msgstr "Требования:"
|
||||
|
||||
msgid "Authors"
|
||||
msgstr "Автор(ы)"
|
||||
msgstr "Автор(ы):"
|
||||
|
||||
msgid "php"
|
||||
msgstr "Версия PHP"
|
||||
|
@ -59,3 +59,30 @@ msgstr "Включено, но пакет изменен!"
|
|||
|
||||
msgid "Crash"
|
||||
msgstr "Сломано, пакет не найден!"
|
||||
|
||||
msgid "Install_"
|
||||
msgstr "Установить"
|
||||
|
||||
msgid "Uninstall_"
|
||||
msgstr "Удалить"
|
||||
|
||||
msgid "Enable_"
|
||||
msgstr "Включить"
|
||||
|
||||
msgid "Disable_"
|
||||
msgstr "Выключить"
|
||||
|
||||
msgid "Update_"
|
||||
msgstr "Обновить"
|
||||
|
||||
msgid "Downdate_"
|
||||
msgstr "Откатить"
|
||||
|
||||
msgid "Package version"
|
||||
msgstr "Версия пакета"
|
||||
|
||||
msgid "Extension not found"
|
||||
msgstr "Расширение не найдено."
|
||||
|
||||
msgid "Invalid action"
|
||||
msgstr "Недопустимое действие."
|
||||
|
|
|
@ -38,70 +38,105 @@
|
|||
/<span>
|
||||
</summary>
|
||||
<div class="f-extdata f-fdiv">
|
||||
<fieldset class="f-extfs-details">
|
||||
<legend class="f-fleg">{!! __('Details') !!}</legend>
|
||||
<dl>
|
||||
<dt>{!! __('Name') !!}</dt>
|
||||
<dd>{{ $ext->name }}</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>{!! __('Description') !!}</dt>
|
||||
<dd>{{ $ext->description }}</dd>
|
||||
</dl>
|
||||
<form class="f-form" method="post" action="{{ $p->actionLink }}">
|
||||
<fieldset class="f-extfs-details">
|
||||
<legend class="f-fleg">{!! __('Details') !!}</legend>
|
||||
<dl>
|
||||
<dt>{!! __('Name') !!}</dt>
|
||||
<dd>{{ $ext->name }}</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>{!! __('Package version') !!}</dt>
|
||||
<dd>{{ $ext->fileVersion }}</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>{!! __('Description') !!}</dt>
|
||||
<dd>{{ $ext->description }}</dd>
|
||||
</dl>
|
||||
@if ($ext->time)
|
||||
<dl>
|
||||
<dt>{!! __('Release date') !!}</dt>
|
||||
<dd>{{ $ext->time }}</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>{!! __('Release date') !!}</dt>
|
||||
<dd>{{ $ext->time }}</dd>
|
||||
</dl>
|
||||
@endif
|
||||
@if ($ext->homepage)
|
||||
<dl>
|
||||
<dt>{!! __('Homepage') !!}</dt>
|
||||
<dd><a href="{{ url($ext->homepage) }}">{{ $ext->homepage }}</a></dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>{!! __('Homepage') !!}</dt>
|
||||
<dd><a href="{{ url($ext->homepage) }}">{{ $ext->homepage }}</a></dd>
|
||||
</dl>
|
||||
@endif
|
||||
@if ($ext->license)
|
||||
<dl>
|
||||
<dt>{!! __('Licence') !!}</dt>
|
||||
<dd>{{ $ext->license }}</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>{!! __('Licence') !!}</dt>
|
||||
<dd>{{ $ext->license }}</dd>
|
||||
</dl>
|
||||
@endif
|
||||
</fieldset>
|
||||
<fieldset class="f-extfs-requirements">
|
||||
<legend class="f-fleg">{!! __('Requirements') !!}</legend>
|
||||
</fieldset>
|
||||
<fieldset class="f-extfs-requirements">
|
||||
<legend class="f-fleg">{!! __('Requirements') !!}</legend>
|
||||
@foreach ($ext->requirements as $k => $v)
|
||||
<dl>
|
||||
<dt>{!! __($k) !!}</dt>
|
||||
<dd>{{ $v }}</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>{!! __($k) !!}</dt>
|
||||
<dd>{{ $v }}</dd>
|
||||
</dl>
|
||||
@endforeach
|
||||
</fieldset>
|
||||
<fieldset class="f-extfs-authors">
|
||||
<legend class="f-fleg">{!! __('Authors') !!}</legend>
|
||||
</fieldset>
|
||||
<fieldset class="f-extfs-authors">
|
||||
<legend class="f-fleg">{!! __('Authors') !!}</legend>
|
||||
@foreach ($ext->authors as $author)
|
||||
<dl>
|
||||
<dd class="f-extdd-author">
|
||||
<span>{{ $author['name'] }}</span>
|
||||
<dl>
|
||||
<dd class="f-extdd-author">
|
||||
<span>{{ $author['name'] }}</span>
|
||||
@if (! empty($author['email']) || ! empty($author['homepage']))
|
||||
(
|
||||
(
|
||||
@if ($author['email'])
|
||||
<a href="{{ url('mailto:'.$author['email']) }}">{{ $author['email'] }}</a>
|
||||
<a href="{{ url('mailto:'.$author['email']) }}">{{ $author['email'] }}</a>
|
||||
@endif
|
||||
@if ($author['homepage'])
|
||||
@if ($author['email'])
|
||||
|
|
||||
|
|
||||
@endif
|
||||
<a href="{{ url($author['homepage']) }}">{{ $author['homepage'] }}</a>
|
||||
<a href="{{ url($author['homepage']) }}">{{ $author['homepage'] }}</a>
|
||||
@endif
|
||||
)
|
||||
)
|
||||
@endif
|
||||
@if ($author['role'])
|
||||
[ {{ $author['role'] }} ]
|
||||
[ {{ $author['role'] }} ]
|
||||
@endif
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
@endforeach
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
<fieldset calss="f-extfs-confirm">
|
||||
<dl>
|
||||
<dd>
|
||||
<label class="f-flblch"><input name="confirm" class="f-ychk" type="checkbox" value="1">{!! __('Confirm action') !!}</label>
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
<input type="hidden" name="name" value="{{ $ext->name }}">
|
||||
<input type="hidden" name="token" value="{{ $p->formsToken }}">
|
||||
<p class="f-btns">
|
||||
@if ($ext->canInstall)
|
||||
<button class="f-btn f-fbtn" name="install" value="install" title="{{ __('Install_') }}"><span>{!! __('Install_') !!}</span></button>
|
||||
@endif
|
||||
@if ($ext->canUninstall)
|
||||
<button class="f-btn f-fbtn" name="uninstall" value="uninstall" title="{{ __('Uninstall_') }}"><span>{!! __('Uninstall_') !!}</span></button>
|
||||
@endif
|
||||
@if ($ext->canUpdate)
|
||||
<button class="f-btn f-fbtn" name="update" value="update" title="{{ __('Update_') }}"><span>{!! __('Update_') !!}</span></button>
|
||||
@endif
|
||||
@if ($ext->canDowndate)
|
||||
<button class="f-btn f-fbtn" name="downdate" value="downdate" title="{{ __('Downdate_') }}"><span>{!! __('Downdate_') !!}</span></button>
|
||||
@endif
|
||||
@if ($ext->canEnable)
|
||||
<button class="f-btn f-fbtn" name="enable" value="enable" title="{{ __('Enable_') }}"><span>{!! __('Enable_') !!}</span></button>
|
||||
@endif
|
||||
@if ($ext->canDisable)
|
||||
<button class="f-btn f-fbtn" name="disable" value="disable" title="{{ __('Disable_') }}"><span>{!! __('Disable_') !!}</span></button>
|
||||
@endif
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</details>
|
||||
</li>
|
||||
|
|
|
@ -410,7 +410,7 @@
|
|||
/* Админка/Пользователи */
|
||||
/************************/
|
||||
#fork-ausersrch-rs .f-btns {
|
||||
text-align: end;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
#fork-ausersrch-rs .f-btns .f-fbtn,
|
||||
|
@ -1273,7 +1273,7 @@
|
|||
/****************************************/
|
||||
/* Админка/РАсширения */
|
||||
/****************************************/
|
||||
#fork #fork-extsinfo summary.f-extsu::after {
|
||||
#forka #fork-extsinfo summary.f-extsu::after {
|
||||
content: none;
|
||||
}
|
||||
|
||||
|
@ -1325,5 +1325,13 @@
|
|||
|
||||
#fork-extsinfo .f-ext-status12 {
|
||||
color: var(--c-log-in-c);
|
||||
background-color: #B71C1C;
|
||||
background-color: #D32F2F;
|
||||
}
|
||||
|
||||
#forka #fork-extsinfo .f-fbtn {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#forka .f-fbtn[data-name="uninstall"]:not(.origin) {
|
||||
color: red;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue