2018-01-08 Pages\Admin
This commit is contained in:
parent
894008ac14
commit
07b6589b76
4 changed files with 189 additions and 19 deletions
app/Models/Pages/Admin
130
app/Models/Pages/Admin/Censoring.php
Normal file
130
app/Models/Pages/Admin/Censoring.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace ForkBB\Models\Pages\Admin;
|
||||
|
||||
use ForkBB\Models\Pages\Admin;
|
||||
|
||||
class Censoring extends Admin
|
||||
{
|
||||
/**
|
||||
* Просмотр, редактирвоание и добавление запрещенных слов
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $method
|
||||
*
|
||||
* @return Page
|
||||
*/
|
||||
public function edit(array $args, $method)
|
||||
{
|
||||
$this->c->Lang->load('admin_censoring');
|
||||
|
||||
if ('POST' === $method) {
|
||||
$v = $this->c->Validator->setRules([
|
||||
'token' => 'token:AdminCensoring',
|
||||
'o_censoring' => 'required|integer|in:0,1',
|
||||
'form.*.search_for' => 'string:trim|max:60',
|
||||
'form.*.replace_with' => 'string:trim|max:60',
|
||||
])->setArguments([
|
||||
])->setMessages([
|
||||
]);
|
||||
|
||||
if ($v->validation($_POST)) {
|
||||
$this->c->DB->beginTransaction();
|
||||
|
||||
$this->c->config->o_censoring = $v->o_censoring;
|
||||
$this->c->config->save();
|
||||
|
||||
$this->c->censorship->save($v->form);
|
||||
|
||||
$this->c->DB->commit();
|
||||
|
||||
$this->c->Cache->delete('censorship'); //????
|
||||
|
||||
return $this->c->Redirect->page('AdminCensoring')->message('Data updated redirect');
|
||||
}
|
||||
|
||||
$this->fIswev = $v->getErrors();
|
||||
}
|
||||
|
||||
$form = [
|
||||
'action' => $this->c->Router->link('AdminCensoring'),
|
||||
'hidden' => [
|
||||
'token' => $this->c->Csrf->create('AdminCensoring'),
|
||||
],
|
||||
'sets' => [
|
||||
[
|
||||
'fields' => [
|
||||
'o_censoring' => [
|
||||
'type' => 'radio',
|
||||
'value' => $this->c->config->o_censoring,
|
||||
'values' => [1 => \ForkBB\__('Yes'), 0 => \ForkBB\__('No')],
|
||||
'title' => \ForkBB\__('Censor words label'),
|
||||
'info' => \ForkBB\__('Censor words help'),
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'info' => [
|
||||
'info1' => [
|
||||
'type' => '', //????
|
||||
'value' => \ForkBB\__('Censoring info'),
|
||||
'html' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'btns' => [
|
||||
'sva' => [
|
||||
'type' => 'submit',
|
||||
'value' => \ForkBB\__('Save changes'),
|
||||
'accesskey' => 's',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$fieldset = [];
|
||||
foreach ($this->c->censorship->load() as $id => $row) {
|
||||
$fieldset["form[{$id}][search_for]"] = [
|
||||
'dl' => ['censor', 'inline'],
|
||||
'type' => 'text',
|
||||
'maxlength' => 60,
|
||||
'value' => $row['search_for'],
|
||||
'title' => \ForkBB\__('Censored word label'),
|
||||
];
|
||||
$fieldset["form[{$id}][replace_with]"] = [
|
||||
'dl' => ['censor', 'inline'],
|
||||
'type' => 'text',
|
||||
'maxlength' => 60,
|
||||
'value' => $row['replace_with'],
|
||||
'title' => \ForkBB\__('Replacement label'),
|
||||
];
|
||||
}
|
||||
$fieldset["form[0][search_for]"] = [
|
||||
'dl' => ['censor', 'inline'],
|
||||
'type' => 'text',
|
||||
'maxlength' => 60,
|
||||
'value' => '',
|
||||
'title' => \ForkBB\__('Censored word label'),
|
||||
];
|
||||
$fieldset["form[0][replace_with]"] = [
|
||||
'dl' => ['censor', 'inline'],
|
||||
'type' => 'text',
|
||||
'maxlength' => 60,
|
||||
'value' => '',
|
||||
'title' => \ForkBB\__('Replacement label'),
|
||||
];
|
||||
|
||||
$form['sets'][] = [
|
||||
'fields' => $fieldset,
|
||||
];
|
||||
|
||||
$this->nameTpl = 'admin/form';
|
||||
$this->aIndex = 'censoring';
|
||||
$this->titles = \ForkBB\__('Censoring');
|
||||
$this->form = $form;
|
||||
$this->classForm = 'editcensorship';
|
||||
$this->titleForm = \ForkBB\__('Censoring');
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -70,6 +70,34 @@ class Forums extends Admin
|
|||
$this->listForOptions = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Вычисление позиции для (нового) раздела
|
||||
*
|
||||
* @param Forum $forum
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function forumPos(Forum $forum)
|
||||
{
|
||||
if (is_int($forum->disp_position)) {
|
||||
return $forum->disp_position;
|
||||
}
|
||||
|
||||
$root = $this->c->forums->get(0);
|
||||
|
||||
if (! $root instanceof Forum) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$max = 0;
|
||||
foreach ($root->descendants as $f) {
|
||||
if ($f->disp_position > $max) {
|
||||
$max = $f->disp_position;
|
||||
}
|
||||
}
|
||||
return $max + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Просмотр, редактирвоание и добавление разделов
|
||||
*
|
||||
|
@ -365,6 +393,7 @@ class Forums extends Admin
|
|||
} else {
|
||||
if (empty($args['id'])) {
|
||||
$message = 'Forum added redirect';
|
||||
$forum->disp_position = $this->forumPos($forum);
|
||||
$this->c->forums->insert($forum);
|
||||
} else {
|
||||
$message = 'Forum updated redirect';
|
||||
|
|
|
@ -160,13 +160,13 @@ class Groups extends Admin
|
|||
$next = true;
|
||||
}
|
||||
|
||||
$group = $this->c->groups->get($gid);
|
||||
$baseGroup = $this->c->groups->get($gid);
|
||||
|
||||
if (null === $group) {
|
||||
if (! $baseGroup instanceof Group) {
|
||||
return $this->c->Message->message('Bad request');
|
||||
}
|
||||
|
||||
$group = clone $group;
|
||||
$group = clone $baseGroup;
|
||||
$notNext = $this->c->GROUP_ADMIN . ',' . $this->c->GROUP_GUEST;
|
||||
|
||||
if (isset($args['id'])) {
|
||||
|
@ -231,7 +231,7 @@ class Groups extends Admin
|
|||
]);
|
||||
|
||||
if ($v->validation($_POST)) {
|
||||
return $this->save($group, $v->getData());
|
||||
return $this->save($group, $baseGroup, $v->getData());
|
||||
}
|
||||
|
||||
$this->fIswev = $v->getErrors();
|
||||
|
@ -248,11 +248,12 @@ class Groups extends Admin
|
|||
* Запись данных по новой/измененной группе
|
||||
*
|
||||
* @param Group $group
|
||||
* @param Group $baseGroup
|
||||
* @param array $args
|
||||
*
|
||||
* @return Page
|
||||
*/
|
||||
public function save(Group $group, array $data)
|
||||
public function save(Group $group, Group $baseGroup, array $data)
|
||||
{
|
||||
if (empty($data['g_moderator'])) {
|
||||
$data['g_mod_edit_users'] = 0;
|
||||
|
@ -275,9 +276,8 @@ class Groups extends Admin
|
|||
if (null === $group->g_id) {
|
||||
$message = \ForkBB\__('Group added redirect');
|
||||
$newId = $this->c->groups->insert($group);
|
||||
//????
|
||||
$this->c->DB->exec('INSERT INTO ::forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) SELECT ?i:new, forum_id, read_forum, post_replies, post_topics FROM ::forum_perms WHERE group_id=?i:old', [':new' => $newId, ':old' => $args['base']]);
|
||||
//????
|
||||
|
||||
$this->c->groups->Perm->copy($baseGroup, $group);
|
||||
} else {
|
||||
$message = \ForkBB\__('Group edited redirect');
|
||||
$this->c->groups->update($group);
|
||||
|
|
|
@ -26,6 +26,7 @@ class Options extends Admin
|
|||
$v = $this->c->Validator->addValidators([
|
||||
'check_timeout' => [$this, 'vCheckTimeout'],
|
||||
'check_dir' => [$this, 'vCheckDir'],
|
||||
'check_empty' => [$this, 'vCheckEmpty'],
|
||||
])->setRules([
|
||||
'token' => 'token:AdminOptions',
|
||||
'o_board_title' => 'required|string:trim|max:255',
|
||||
|
@ -51,7 +52,6 @@ class Options extends Admin
|
|||
'o_quote_depth' => 'required|integer|min:0|max:9',
|
||||
'o_quickpost' => 'required|integer|in:0,1',
|
||||
'o_users_online' => 'required|integer|in:0,1',
|
||||
'o_censoring' => 'required|integer|in:0,1',
|
||||
'o_signatures' => 'required|integer|in:0,1',
|
||||
'o_show_dot' => 'required|integer|in:0,1',
|
||||
'o_topic_views' => 'required|integer|in:0,1',
|
||||
|
@ -80,12 +80,12 @@ class Options extends Admin
|
|||
'o_regs_allow' => 'required|integer|in:0,1',
|
||||
'o_regs_verify' => 'required|integer|in:0,1',
|
||||
'o_regs_report' => 'required|integer|in:0,1',
|
||||
'o_rules' => 'required|integer|in:0,1',
|
||||
'o_rules' => 'required|integer|in:0,1|check_empty:o_rules_message',
|
||||
'o_rules_message' => 'string:trim|max:65000 bytes',
|
||||
'o_default_email_setting' => 'required|integer|in:0,1,2',
|
||||
'o_announcement' => 'required|integer|in:0,1',
|
||||
'o_announcement' => 'required|integer|in:0,1|check_empty:o_announcement_message',
|
||||
'o_announcement_message' => 'string:trim|max:65000 bytes',
|
||||
'o_maintenance' => 'required|integer|in:0,1',
|
||||
'o_maintenance' => 'required|integer|in:0,1|check_empty:o_maintenance_message',
|
||||
'o_maintenance_message' => 'string:trim|max:65000 bytes',
|
||||
])->setArguments([
|
||||
])->setMessages([
|
||||
|
@ -156,6 +156,23 @@ class Options extends Admin
|
|||
return $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Дополнительная проверка на пустоту другого поля
|
||||
*
|
||||
* @param Validator $v
|
||||
* @param int $value
|
||||
* @param string $attr
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function vCheckEmpty(Validator $v, $value, $attr)
|
||||
{
|
||||
if (0 !== $value && 0 === strlen($v->$attr)) {
|
||||
$value = 0;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Формирует данные для формы
|
||||
*
|
||||
|
@ -424,13 +441,6 @@ class Options extends Admin
|
|||
'title' => \ForkBB\__('Users online label'),
|
||||
'info' => \ForkBB\__('Users online help'),
|
||||
],
|
||||
'o_censoring' => [
|
||||
'type' => 'radio',
|
||||
'value' => $config->o_censoring,
|
||||
'values' => $yn,
|
||||
'title' => \ForkBB\__('Censor words label'),
|
||||
'info' => \ForkBB\__('Censor words help', $this->c->Router->link('AdminCensoring')),
|
||||
],
|
||||
'o_signatures' => [
|
||||
'type' => 'radio',
|
||||
'value' => $config->o_signatures,
|
||||
|
@ -725,6 +735,7 @@ class Options extends Admin
|
|||
];
|
||||
|
||||
$form['sets'][] = [
|
||||
'id' => 'Maintenance',
|
||||
'legend' => \ForkBB\__('Maintenance subhead'),
|
||||
'fields' => [
|
||||
'o_maintenance' => [
|
||||
|
|
Loading…
Add table
Reference in a new issue