Add bbcode management 1
This commit is contained in:
parent
45577959e6
commit
8e215c96a7
5 changed files with 344 additions and 2 deletions
|
@ -539,6 +539,24 @@ class Routing
|
|||
'AdminParserBBCode:view',
|
||||
'AdminBBCode'
|
||||
);
|
||||
$r->add(
|
||||
$r::GET,
|
||||
'/admin/parser/bbcode/delete/{id:[1-9]\d*}/{token}',
|
||||
'AdminParserBBCode:delete',
|
||||
'AdminBBCodeDelete'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/admin/parser/bbcode/edit/{id:[1-9]\d*}',
|
||||
'AdminParserBBCode:edit',
|
||||
'AdminBBCodeEdit'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/admin/parser/bbcode/new',
|
||||
'AdminParserBBCode:edit',
|
||||
'AdminBBCodeNew'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/admin/parser/smilies',
|
||||
|
|
212
app/Models/Pages/Admin/Parser/BBCode.php
Normal file
212
app/Models/Pages/Admin/Parser/BBCode.php
Normal file
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
|
||||
namespace ForkBB\Models\Pages\Admin\Parser;
|
||||
|
||||
use ForkBB\Core\Validator;
|
||||
use ForkBB\Models\Page;
|
||||
use ForkBB\Models\Pages\Admin\Parser;
|
||||
use ForkBB\Models\Config\Model as Config;
|
||||
use function \ForkBB\__;
|
||||
|
||||
class BBCode extends Parser
|
||||
{
|
||||
/**
|
||||
* Редактирование натроек bbcode
|
||||
*/
|
||||
public function view(array $args, string $method): Page
|
||||
{
|
||||
$this->c->bbcode->load();
|
||||
|
||||
if ('POST' === $method) {
|
||||
$v = $this->c->Validator->reset()
|
||||
->addValidators([
|
||||
])->addRules([
|
||||
'token' => 'token:AdminBBCode',
|
||||
'bbcode.*.in_mes' => 'required|integer|min:0|max:2',
|
||||
'bbcode.*.in_sig' => 'required|integer|min:0|max:2',
|
||||
])->addAliases([
|
||||
])->addArguments([
|
||||
])->addMessages([
|
||||
]);
|
||||
|
||||
if ($v->validation($_POST)) {
|
||||
$mesClear = true;
|
||||
$sigClear = true;
|
||||
$white_mes = [];
|
||||
$black_mes = [];
|
||||
$white_sig = [];
|
||||
$black_sig = [];
|
||||
|
||||
foreach ($this->c->bbcode->bbcodeTable as $id => $tagData) {
|
||||
$tag = $tagData['bb_tag'];
|
||||
$bbcode = $v->bbcode;
|
||||
|
||||
if ('ROOT' === $tag) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! isset($bbcode[$tag]['in_mes'], $bbcode[$tag]['in_sig'])) {
|
||||
$mesClear = false;
|
||||
$sigClear = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($bbcode[$tag]['in_mes']) {
|
||||
case 2:
|
||||
$white_mes[] = $tag;
|
||||
break;
|
||||
case 0:
|
||||
$black_mes[] = $tag;
|
||||
default:
|
||||
$mesClear = false;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($bbcode[$tag]['in_sig']) {
|
||||
case 2:
|
||||
$white_sig[] = $tag;
|
||||
break;
|
||||
case 0:
|
||||
$black_sig[] = $tag;
|
||||
default:
|
||||
$sigClear = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->c->config->a_bb_white_mes = $mesClear ? [] : $white_mes;
|
||||
$this->c->config->a_bb_black_mes = $mesClear ? [] : $black_mes;
|
||||
$this->c->config->a_bb_white_sig = $sigClear ? [] : $white_sig;
|
||||
$this->c->config->a_bb_black_sig = $sigClear ? [] : $black_sig;
|
||||
|
||||
$this->c->config->save();
|
||||
|
||||
return $this->c->Redirect->page('AdminBBCode')->message('Parser settings updated redirect');
|
||||
}
|
||||
|
||||
$this->fIswev = $v->getErrors();
|
||||
}
|
||||
|
||||
$this->nameTpl = 'admin/form';
|
||||
$this->aCrumbs[] = [
|
||||
$this->c->Router->link('AdminBBCode'),
|
||||
__('BBCode management'),
|
||||
];
|
||||
$this->form = $this->formView();
|
||||
$this->titleForm = __('BBCode head');
|
||||
$this->classForm = 'bbcode';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Формирует данные для формы
|
||||
*/
|
||||
protected function formView(): array
|
||||
{
|
||||
$form = [
|
||||
'action' => $this->c->Router->link('AdminBBCode'),
|
||||
'hidden' => [
|
||||
'token' => $this->c->Csrf->create('AdminBBCode'),
|
||||
],
|
||||
'sets' => [
|
||||
'bbcode-legend' => [
|
||||
'class' => 'bbcode-legend',
|
||||
'legend' => __('BBCode list subhead'),
|
||||
'fields' => [],
|
||||
],
|
||||
],
|
||||
'btns' => [
|
||||
'save' => [
|
||||
'type' => 'submit',
|
||||
'value' => __('Save changes'),
|
||||
// 'accesskey' => 's',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$selectList = [
|
||||
2 => __('BBCode allowed'),
|
||||
1 => __('BBCode display only'),
|
||||
0 => __('BBCode not allowed'),
|
||||
];
|
||||
|
||||
foreach ($this->c->bbcode->bbcodeTable as $id => $tagData) {
|
||||
$fields = [];
|
||||
$tag = $tagData['bb_tag'];
|
||||
|
||||
$fields["bbcode{$id}-tag"] = [
|
||||
'class' => ['bbcode', 'tag'],
|
||||
'type' => $tagData['bb_edit'] > 0 ? 'link' : 'str',
|
||||
'value' => $tag,
|
||||
'caption' => __('BBCode tag label'),
|
||||
'title' => __('BBCode tag title'),
|
||||
'href' => 1 === $tagData['bb_edit']
|
||||
? $this->c->Router->link('AdminBBCodeEdit', ['id' => $id])
|
||||
: null,
|
||||
];
|
||||
$fields["bbcode[{$tag}][in_mes]"] = [
|
||||
'class' => ['bbcode', 'in_mes'],
|
||||
'type' => 'select',
|
||||
'options' => $selectList,
|
||||
'value' => $this->getValue($tag, $this->c->config->a_bb_white_mes, $this->c->config->a_bb_black_mes),
|
||||
'caption' => __('BBCode mes label'),
|
||||
'disabled' => 'ROOT' === $tag,
|
||||
];
|
||||
$fields["bbcode[{$tag}][in_sig]"] = [
|
||||
'class' => ['bbcode', 'in_sig'],
|
||||
'type' => 'select',
|
||||
'options' => $selectList,
|
||||
'value' => $this->getValue($tag, $this->c->config->a_bb_white_sig, $this->c->config->a_bb_black_sig),
|
||||
'caption' => __('BBCode sig label'),
|
||||
'disabled' => 'ROOT' === $tag,
|
||||
];
|
||||
$fields["bbcode{$id}-del"] = [
|
||||
'class' => ['bbcode', 'delete'],
|
||||
'type' => 'btn',
|
||||
'value' => '❌',
|
||||
'caption' => __('Delete'),
|
||||
'title' => __('Delete'),
|
||||
'link' => $this->c->Router->link(
|
||||
'AdminBBCodeDelete',
|
||||
[
|
||||
'id' => $id,
|
||||
'token' => $this->c->Csrf->create(
|
||||
'AdminBBCodeDelete',
|
||||
[
|
||||
'id' => $id,
|
||||
]
|
||||
),
|
||||
]
|
||||
),
|
||||
'disabled' => 1 !== $tagData['bb_delete'],
|
||||
];
|
||||
|
||||
$form['sets']["bbcode{$id}"] = [
|
||||
'class' => 'bbcode',
|
||||
'legend' => __('BBCode %s', $tag),
|
||||
'fields' => $fields,
|
||||
];
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Вычисляет значение для select на основе белого и черного списков bbcode
|
||||
*/
|
||||
protected function getValue(string $tag, array $white, array $black): int
|
||||
{
|
||||
if ('ROOT' === $tag) {
|
||||
return 1;
|
||||
} elseif (empty($white) && empty($black)) {
|
||||
return 2;
|
||||
} elseif (\in_array($tag, $black)) {
|
||||
return 0;
|
||||
} elseif (\in_array($tag, $white)) {
|
||||
return 2;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,10 +28,10 @@ msgid "BBCode help"
|
|||
msgstr "Allow BBCode in posts (recommended)."
|
||||
|
||||
msgid "BBCode sigs label"
|
||||
msgstr "BBCodes in signatures"
|
||||
msgstr "BBCode in signatures"
|
||||
|
||||
msgid "BBCode sigs help"
|
||||
msgstr "Allow BBCodes in user signatures."
|
||||
msgstr "Allow BBCode in user signatures."
|
||||
|
||||
msgid "Smilies subhead"
|
||||
msgstr "Smilies"
|
||||
|
@ -122,3 +122,33 @@ msgstr "Smilies updated."
|
|||
|
||||
msgid "Smile deleted redirect"
|
||||
msgstr "Smile deleted."
|
||||
|
||||
msgid "BBCode head"
|
||||
msgstr "BBCode"
|
||||
|
||||
msgid "BBCode list subhead"
|
||||
msgstr "BBCode list"
|
||||
|
||||
msgid "BBCode tag label"
|
||||
msgstr "Tag"
|
||||
|
||||
msgid "BBCode tag title"
|
||||
msgstr "Edit BBCode"
|
||||
|
||||
msgid "BBCode %s"
|
||||
msgstr "BBCode '%s'"
|
||||
|
||||
msgid "BBCode allowed"
|
||||
msgstr "Allowed"
|
||||
|
||||
msgid "BBCode display only"
|
||||
msgstr "Display only"
|
||||
|
||||
msgid "BBCode not allowed"
|
||||
msgstr "Not allowed"
|
||||
|
||||
msgid "BBCode mes label"
|
||||
msgstr "In messages"
|
||||
|
||||
msgid "BBCode sig label"
|
||||
msgstr "In signatures"
|
||||
|
|
|
@ -122,3 +122,33 @@ msgstr "Смайлы обновлены."
|
|||
|
||||
msgid "Smile deleted redirect"
|
||||
msgstr "Смайл удален."
|
||||
|
||||
msgid "BBCode head"
|
||||
msgstr "BBCode"
|
||||
|
||||
msgid "BBCode list subhead"
|
||||
msgstr "Список BB-кодов"
|
||||
|
||||
msgid "BBCode tag label"
|
||||
msgstr "Тег"
|
||||
|
||||
msgid "BBCode tag title"
|
||||
msgstr "Редактировать BB-код"
|
||||
|
||||
msgid "BBCode %s"
|
||||
msgstr "BB-код '%s'"
|
||||
|
||||
msgid "BBCode allowed"
|
||||
msgstr "Разрешен"
|
||||
|
||||
msgid "BBCode display only"
|
||||
msgstr "Только отображение"
|
||||
|
||||
msgid "BBCode not allowed"
|
||||
msgstr "Запрещен"
|
||||
|
||||
msgid "BBCode mes label"
|
||||
msgstr "В сообщениях"
|
||||
|
||||
msgid "BBCode sig label"
|
||||
msgstr "В подписях"
|
||||
|
|
|
@ -2956,11 +2956,13 @@ body,
|
|||
margin: 0;
|
||||
}
|
||||
|
||||
#fork .f-bbcode-form .f-field-tag,
|
||||
#fork .f-smilies-form .f-fs-smile > legend,
|
||||
#fork .f-smilies-form .f-fs-new-smile > legend {
|
||||
border-top: 0.0625rem dotted #AA7939;
|
||||
}
|
||||
|
||||
#fork .f-fs-bbcode > legend,
|
||||
#fork .f-images-list .f-fs-image > legend,
|
||||
#fork .f-images-list .f-field-image > dt {
|
||||
display: none;
|
||||
|
@ -3000,6 +3002,56 @@ body,
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
#fork .f-bbcode-form .f-link {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 25rem) {
|
||||
#fork .f-bbcode-form .f-fs-bbcode {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#fork .f-bbcode-form .f-field-bbcode {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
/* justify-content: space-between; */
|
||||
}
|
||||
|
||||
#fork .f-bbcode-form .f-field-tag {
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
#fork .f-bbcode-form .f-field-bbcode > dt {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#fork .f-fs-bbcode-legend + .f-fs-bbcode .f-field-bbcode > dt {
|
||||
display: block;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#fork .f-bbcode-form .f-field-bbcode .f-child1 {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
#fork .f-bbcode-form .f-field-bbcode > dd {
|
||||
width: 100%;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
#fork .f-field-bbcode.f-field-tag,
|
||||
#fork .f-field-bbcode.f-field-in_mes,
|
||||
#fork .f-field-bbcode.f-field-in_sig {
|
||||
width: calc((100% - 3rem) / 3);
|
||||
}
|
||||
|
||||
#fork .f-field-bbcode.f-field-delete {
|
||||
width: 3rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 35rem) {
|
||||
#fork .f-smilies-form .f-fs-smile {
|
||||
display: flex;
|
||||
|
|
Loading…
Add table
Reference in a new issue