Add bbcode management 3
This commit is contained in:
parent
8a445d6180
commit
0ea771e2ac
6 changed files with 109 additions and 2 deletions
|
@ -557,6 +557,12 @@ class Routing
|
|||
'AdminParserBBCode:edit',
|
||||
'AdminBBCodeNew'
|
||||
);
|
||||
$r->add(
|
||||
$r::GET,
|
||||
'/admin/parser/bbcode/default/{id:[1-9]\d*}/{token}',
|
||||
'AdminParserBBCode:default',
|
||||
'AdminBBCodeDefault'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/admin/parser/smilies',
|
||||
|
|
|
@ -27,6 +27,38 @@ class Structure extends ParentModel
|
|||
];
|
||||
}
|
||||
|
||||
public function isInDefault(): bool
|
||||
{
|
||||
if (empty($this->tag)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bbcode = include $this->c->bbcode->fileDefault;
|
||||
|
||||
foreach ($bbcode as $cur) {
|
||||
if ($this->tag === $cur['tag']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setDefault(): Structure
|
||||
{
|
||||
if (! $this->isInDefault()) {
|
||||
throw new RuntimeException("There is no default for the '{$this->tag}' tag");
|
||||
}
|
||||
|
||||
$bbcode = include $this->c->bbcode->fileDefault;
|
||||
|
||||
foreach ($bbcode as $cur) {
|
||||
if ($this->tag === $cur['tag']) {
|
||||
return $this->setAttrs($cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fromString(string $data): Structure
|
||||
{
|
||||
return $this->setAttrs(\json_decode($data, true, 512, \JSON_THROW_ON_ERROR));
|
||||
|
@ -513,7 +545,7 @@ class Structure extends ParentModel
|
|||
$result = @eval($testCode);
|
||||
|
||||
if (true !== $result) {
|
||||
$error = error_get_last();
|
||||
$error = \error_get_last();
|
||||
$message = $error['message'] ?? 'Unknown error';
|
||||
$line = $error['line'] ?? '';
|
||||
|
||||
|
|
|
@ -117,6 +117,12 @@ class BBCode extends Parser
|
|||
],
|
||||
],
|
||||
'btns' => [
|
||||
'new' => [
|
||||
'type' => 'btn',
|
||||
'value' => __('New BBCode'),
|
||||
'link' => $this->c->Router->link('AdminBBCodeNew'),
|
||||
// 'accesskey' => 'n',
|
||||
],
|
||||
'save' => [
|
||||
'type' => 'submit',
|
||||
'value' => __('Save changes'),
|
||||
|
@ -240,9 +246,11 @@ class BBCode extends Parser
|
|||
}
|
||||
|
||||
$bbTypes = [];
|
||||
$bbNames = [];
|
||||
foreach ($this->c->bbcode->bbcodeTable as $cur) {
|
||||
$type = $this->c->BBStructure->fromString($cur['bb_structure'])->type;
|
||||
$bbTypes[$type] = $type;
|
||||
$bbNames[$cur['bb_tag']] = $cur['bb_tag'];
|
||||
}
|
||||
$this->bbTypes = $bbTypes;
|
||||
|
||||
|
@ -264,7 +272,7 @@ class BBCode extends Parser
|
|||
'check_all' => [$this, 'vCheckAll'],
|
||||
])->addRules([
|
||||
'token' => 'token:' . $page,
|
||||
'tag' => $id > 0 ? 'absent' : 'required|string:trim|regex:%^[a-z\*][a-z\d-]{0,10}$%',
|
||||
'tag' => $id > 0 ? 'absent' : 'required|string:trim|regex:%^[a-z\*][a-z\d-]{0,10}$%|not_in:' . \implode(',', $bbNames),
|
||||
'type' => 'required|string|in:' . \implode(',', $bbTypes),
|
||||
'type_new' => 'string:trim|regex:%^[a-z][a-z\d-]{0,19}$%',
|
||||
'parents.*' => 'required|string|in:' . \implode(',', $bbTypes),
|
||||
|
@ -382,6 +390,18 @@ class BBCode extends Parser
|
|||
],
|
||||
'sets' => [],
|
||||
'btns' => [
|
||||
'reset' => [
|
||||
'type' => 'btn',
|
||||
'value' => __('Default structure'),
|
||||
'link' => $this->c->Router->link(
|
||||
'AdminBBCodeDefault',
|
||||
[
|
||||
'id' => $id,
|
||||
'token' => null,
|
||||
]
|
||||
),
|
||||
// 'accesskey' => 'r',
|
||||
],
|
||||
'save' => [
|
||||
'type' => 'submit',
|
||||
'value' => __('Save'),
|
||||
|
@ -390,6 +410,10 @@ class BBCode extends Parser
|
|||
],
|
||||
];
|
||||
|
||||
if (! $structure->isInDefault()) {
|
||||
unset($form['btns']['reset']);
|
||||
}
|
||||
|
||||
$yn = [1 => __('Yes'), 0 => __('No')];
|
||||
|
||||
$form['sets']['structure'] = [
|
||||
|
@ -600,4 +624,24 @@ class BBCode extends Parser
|
|||
'fields' => $fields,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Устанавливает структуру bb-кода по умолчанию
|
||||
*/
|
||||
public function default(array $args, string $method): Page
|
||||
{
|
||||
if (! $this->c->Csrf->verify($args['token'], 'AdminBBCodeDefault', $args)) {
|
||||
return $this->c->Message->message('Bad token');
|
||||
}
|
||||
|
||||
$id = (int) $args['id'];
|
||||
|
||||
$structure = $this->c->BBStructure
|
||||
->fromString($this->c->bbcode->load()->bbcodeTable[$id]['bb_structure'])
|
||||
->setDefault();
|
||||
|
||||
$this->c->bbcode->update($id, $structure);
|
||||
|
||||
return $this->c->Redirect->page('AdminBBCodeEdit', ['id' => $id])->message('BBCode updated redirect');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -317,3 +317,9 @@ msgstr "BBCode updated."
|
|||
|
||||
msgid "BBCode added redirect"
|
||||
msgstr "BBCode added."
|
||||
|
||||
msgid "New BBCode"
|
||||
msgstr "New BBCode"
|
||||
|
||||
msgid "Default structure"
|
||||
msgstr "Default"
|
||||
|
|
|
@ -317,3 +317,9 @@ msgstr "BB-код обновлен."
|
|||
|
||||
msgid "BBCode added redirect"
|
||||
msgstr "BB-код добавлен."
|
||||
|
||||
msgid "New BBCode"
|
||||
msgstr "Новый BB-код"
|
||||
|
||||
msgid "Default structure"
|
||||
msgstr "По умолчанию"
|
||||
|
|
|
@ -3015,6 +3015,19 @@ body,
|
|||
font-family: "DejaVu Sans Mono", Consolas, "Droid Sans Mono", Monospace, Monaco, "Courier New", Courier;
|
||||
}
|
||||
|
||||
#fork .f-bbcode-form .f-btns,
|
||||
#fork .f-editbbcode-form .f-btns {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
#fork .f-bbcode-form .f-btn[data-name=new],
|
||||
#fork .f-editbbcode-form .f-btn[data-name=reset]{
|
||||
width: auto;
|
||||
margin-bottom: 0.625rem;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 25rem) {
|
||||
#fork .f-bbcode-form .f-fs-bbcode {
|
||||
display: flex;
|
||||
|
|
Loading…
Add table
Reference in a new issue