2018-01-01
This commit is contained in:
parent
9787288da8
commit
cd259b79ab
8 changed files with 303 additions and 49 deletions
app
Controllers
Core
Models
lang
templates/layouts
public/style/ForkBB
|
@ -110,6 +110,7 @@ class Routing
|
|||
$r->add(['GET', 'POST'], '/admin/categories/{id:[1-9]\d*}/delete', 'AdminCategories:delete', 'AdminCategoriesDelete');
|
||||
|
||||
$r->add(['GET', 'POST'], '/admin/forums', 'AdminForums:view', 'AdminForums' );
|
||||
$r->add(['GET', 'POST'], '/admin/forums/new', 'AdminForums:edit', 'AdminForumsNew' );
|
||||
$r->add(['GET', 'POST'], '/admin/forums/{id:[1-9]\d*}/edit', 'AdminForums:edit', 'AdminForumsEdit' );
|
||||
$r->add(['GET', 'POST'], '/admin/forums/{id:[1-9]\d*}/delete', 'AdminForums:delete', 'AdminForumsDelete' );
|
||||
$r->add('GET', '/admin/groups', 'AdminGroups:view', 'AdminGroups' );
|
||||
|
|
|
@ -167,7 +167,7 @@ class Lang
|
|||
}
|
||||
|
||||
// одиночный
|
||||
} elseif (isset($cur[0]{0})) {
|
||||
} elseif (isset($cur[0])) { // {0}
|
||||
$result[$cur['msgid']] = $cur[0];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,23 @@ class Save extends Action
|
|||
return $forum;
|
||||
}
|
||||
$vars[] = $forum->id;
|
||||
$this->c->DB->query('UPDATE ::forums SET ' . implode(', ', $set) . ' WHERE id=?i', $vars);
|
||||
|
||||
$this->c->DB->exec('UPDATE ::forums SET ' . implode(', ', $set) . ' WHERE id=?i', $vars);
|
||||
|
||||
// модификация категории у потомков при ее изменении
|
||||
if (in_array('cat_id', $modified) && $forum->descendants) {
|
||||
foreach ($forum->descendants as $f) {
|
||||
$f->__cat_id = $values['cat_id'];
|
||||
}
|
||||
$vars = [
|
||||
':ids' => array_keys($forum->descendants),
|
||||
':category' => $values['cat_id'],
|
||||
];
|
||||
$sql = 'UPDATE ::forums SET cat_id=?i:category WHERE id IN (?ai:ids)';
|
||||
|
||||
$this->c->DB->exec($sql, $vars);
|
||||
}
|
||||
|
||||
$forum->resModified();
|
||||
|
||||
return $forum;
|
||||
|
|
|
@ -8,6 +8,65 @@ use ForkBB\Models\Pages\Admin;
|
|||
|
||||
class Forums extends Admin
|
||||
{
|
||||
/**
|
||||
* Получение списка разделов и подразделов
|
||||
*
|
||||
* @param Forum $forum
|
||||
* @param int $depth
|
||||
* @param array $list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function forumsList(Forum $forum, $depth, array $list = [])
|
||||
{
|
||||
++$depth;
|
||||
foreach ($forum->subforums as $sub) {
|
||||
$sub->__depth = $depth;
|
||||
$list[] = $sub;
|
||||
|
||||
$list = $this->forumsList($sub, $depth, $list);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение списка опций для выбора родителя
|
||||
*
|
||||
* @param Forum $forum
|
||||
*/
|
||||
protected function calcList(Forum $forum)
|
||||
{
|
||||
$cid = null;
|
||||
$categories = $this->c->categories->getList();
|
||||
$options = [
|
||||
[0, \ForkBB\__('Not selected')],
|
||||
];
|
||||
$idxs = [];
|
||||
foreach ($this->forumsList($this->c->forums->get(0), 0) as $f) {
|
||||
if ($cid !== $f->cat_id) {
|
||||
$cid = $f->cat_id;
|
||||
$options[] = [-$cid, \ForkBB\__('Category prefix') . $f->cat_name];
|
||||
$idxs[] = -$cid;
|
||||
unset($categories[$cid]);
|
||||
}
|
||||
|
||||
$indent = str_repeat(\ForkBB\__('Forum indent'), $f->depth);
|
||||
|
||||
if ($f->id === $forum->id || isset($forum->descendants[$f->id]) || $f->redirect_url) {
|
||||
$options[] = [$f->id, $indent . \ForkBB\__('Forum prefix') . $f->forum_name, true];
|
||||
} else {
|
||||
$options[] = [$f->id, $indent . \ForkBB\__('Forum prefix') . $f->forum_name];
|
||||
$idxs[] = $f->id;
|
||||
}
|
||||
}
|
||||
foreach ($categories as $key => $row) {
|
||||
$idxs[] = -$key;
|
||||
$options[] = [-$key, \ForkBB\__('Category prefix') . $row['cat_name']];
|
||||
}
|
||||
$this->listOfIndexes = $idxs;
|
||||
$this->listForOptions = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Просмотр, редактирвоание и добавление разделов
|
||||
*
|
||||
|
@ -54,7 +113,7 @@ class Forums extends Admin
|
|||
],
|
||||
'sets' => [],
|
||||
'btns' => [
|
||||
'submit' => [
|
||||
'update' => [
|
||||
'type' => 'submit',
|
||||
'value' => \ForkBB\__('Update positions'),
|
||||
'accesskey' => 'u',
|
||||
|
@ -62,8 +121,7 @@ class Forums extends Admin
|
|||
],
|
||||
];
|
||||
|
||||
$root = $this->c->forums->get(0);
|
||||
$list = $this->createList([], $root, -1);
|
||||
$list = $this->forumsList($this->c->forums->get(0), -1);
|
||||
|
||||
$fieldset = [];
|
||||
$cid = null;
|
||||
|
@ -73,6 +131,7 @@ class Forums extends Admin
|
|||
$form['sets'][] = [
|
||||
'fields' => $fieldset,
|
||||
];
|
||||
$fieldset = [];
|
||||
}
|
||||
|
||||
$form['sets'][] = [
|
||||
|
@ -83,10 +142,8 @@ class Forums extends Admin
|
|||
],
|
||||
],
|
||||
];
|
||||
|
||||
$fieldset = [];
|
||||
$cid = $forum->cat_id;
|
||||
}
|
||||
$cid = $forum->cat_id;
|
||||
|
||||
$fieldset[] = [
|
||||
'dl' => ['name', 'depth' . $forum->depth],
|
||||
|
@ -127,28 +184,7 @@ class Forums extends Admin
|
|||
}
|
||||
|
||||
/**
|
||||
* Получение списка разделов и подразделов
|
||||
*
|
||||
* @param array $list
|
||||
* @param Forum $forum
|
||||
* @param int $depth
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function createList(array $list, Forum $forum, $depth)
|
||||
{
|
||||
++$depth;
|
||||
foreach ($forum->subforums as $sub) {
|
||||
$sub->__depth = $depth;
|
||||
$list[] = $sub;
|
||||
|
||||
$list = $this->createList($list, $sub, $depth);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаление категорий
|
||||
* Удаление раздела
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $method
|
||||
|
@ -240,4 +276,165 @@ class Forums extends Admin
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Редактирование раздела
|
||||
* Создание нового раздела
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $method
|
||||
*
|
||||
* @return Page
|
||||
*/
|
||||
public function edit(array $args, $method)
|
||||
{
|
||||
$this->c->Lang->load('admin_forums');
|
||||
|
||||
if (empty($args['id'])) {
|
||||
$forum = $this->c->forums->create();
|
||||
$marker = 'AdminForumsNew';
|
||||
$this->titles = \ForkBB\__('Add forum head');
|
||||
$this->titleForm = \ForkBB\__('Add forum head');
|
||||
$this->classForm = 'createforum';
|
||||
} else {
|
||||
$forum = $this->c->forums->loadTree((int) $args['id']); //?????
|
||||
$marker = 'AdminForumsEdit';
|
||||
$this->titles = \ForkBB\__('Edit forum head');
|
||||
$this->titleForm = \ForkBB\__('Edit forum head');
|
||||
$this->classForm = 'editforum';
|
||||
}
|
||||
|
||||
if (! $forum instanceof Forum) {
|
||||
return $this->c->Message->message('Bad request');
|
||||
}
|
||||
|
||||
$this->calcList($forum);
|
||||
|
||||
if ('POST' === $method) {
|
||||
$v = $this->c->Validator->setRules([
|
||||
'token' => 'token:' . $marker,
|
||||
'forum_name' => 'required|string:trim|max:80',
|
||||
'forum_desc' => 'string:trim|max:65000 bytes',
|
||||
'parent' => 'required|integer|in:' . implode(',', $this->listOfIndexes),
|
||||
'sort_by' => 'required|integer|in:0,1,2',
|
||||
'redirect_url' => 'string:trim|max:100',
|
||||
])->setArguments([
|
||||
'token' => $args,
|
||||
]);
|
||||
|
||||
$valid = $v->validation($_POST);
|
||||
|
||||
$forum->forum_name = $v->forum_name;
|
||||
$forum->forum_desc = $v->forum_desc;
|
||||
$forum->sort_by = $v->sort_by;
|
||||
$forum->redirect_url = $v->redirect_url; //???? null
|
||||
if ($v->parent > 0) {
|
||||
$forum->parent_forum_id = $v->parent;
|
||||
$forum->cat_id = $this->c->forums->get($v->parent)->cat_id;
|
||||
} elseif ($v->parent < 0) {
|
||||
$forum->cat_id = -$v->parent;
|
||||
$forum->parent_forum_id = 0;
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$this->c->DB->beginTransaction();
|
||||
|
||||
if (empty($args['id'])) {
|
||||
$message = 'Forum added redirect';
|
||||
$this->c->forums->insert($forum);
|
||||
} else {
|
||||
$message = 'Forum updated redirect';
|
||||
$this->c->forums->update($forum);
|
||||
}
|
||||
|
||||
//???? права
|
||||
|
||||
$this->c->DB->commit();
|
||||
|
||||
$this->c->Cache->delete('forums_mark');
|
||||
|
||||
return $this->c->Redirect->page('AdminForums')->message($message);
|
||||
}
|
||||
|
||||
$this->fIswev = $v->getErrors();
|
||||
}
|
||||
|
||||
$this->nameTpl = 'admin/form';
|
||||
$this->aIndex = 'forums';
|
||||
$this->form = $this->viewForm($forum, $marker, $args);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Формирует данные для формы редактирования раздела
|
||||
*
|
||||
* @param Forum $forum
|
||||
* @param string $marker
|
||||
* @param array $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function viewForm(Forum $forum, $marker, array $args)
|
||||
{
|
||||
$form = [
|
||||
'action' => $this->c->Router->link($marker, $args),
|
||||
'hidden' => [
|
||||
'token' => $this->c->Csrf->create($marker, $args),
|
||||
],
|
||||
'sets' => [],
|
||||
'btns' => [
|
||||
'submit' => [
|
||||
'type' => 'submit',
|
||||
'value' => empty($forum->id) ? \ForkBB\__('Add') : \ForkBB\__('Update'),
|
||||
'accesskey' => 's',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$form['sets'][] = [
|
||||
'fields' => [
|
||||
'forum_name' => [
|
||||
'type' => 'text',
|
||||
'maxlength' => 80,
|
||||
'value' => $forum->forum_name,
|
||||
'title' => \ForkBB\__('Forum name label'),
|
||||
'required' => true,
|
||||
],
|
||||
'forum_desc' => [
|
||||
'type' => 'textarea',
|
||||
'value' => $forum->forum_desc,
|
||||
'title' => \ForkBB\__('Forum description label'),
|
||||
],
|
||||
'parent' => [
|
||||
'type' => 'select',
|
||||
'options' => $this->listForOptions,
|
||||
'value' => $forum->parent_forum_id ? $forum->parent_forum_id : -$forum->cat_id,
|
||||
'title' => \ForkBB\__('Parent label'),
|
||||
'info' => \ForkBB\__('Parent help'),
|
||||
'required' => true,
|
||||
],
|
||||
'sort_by' => [
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
0 => \ForkBB\__('Last post option'),
|
||||
1 => \ForkBB\__('Topic start option'),
|
||||
2 => \ForkBB\__('Subject option'),
|
||||
],
|
||||
'value' => $forum->sort_by,
|
||||
'title' => \ForkBB\__('Sort by label'),
|
||||
],
|
||||
'redirect_url' => [
|
||||
'type' => 'text',
|
||||
'maxlength' => 100, //?????
|
||||
'value' => $forum->redirect_url,
|
||||
'title' => \ForkBB\__('Redirect label'),
|
||||
'info' => \ForkBB\__('Redirect help'),
|
||||
'disabled' => $forum->num_topics ? true : null,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,20 +105,20 @@ msgstr "Category"
|
|||
msgid "Sort by label"
|
||||
msgstr "Sort topics by"
|
||||
|
||||
msgid "Last post"
|
||||
msgid "Last post option"
|
||||
msgstr "Last post"
|
||||
|
||||
msgid "Topic start"
|
||||
msgid "Topic start option"
|
||||
msgstr "Topic start"
|
||||
|
||||
msgid "Subject"
|
||||
msgid "Subject option"
|
||||
msgstr "Subject"
|
||||
|
||||
msgid "Redirect label"
|
||||
msgstr "Redirect URL"
|
||||
|
||||
msgid "Redirect help"
|
||||
msgstr "Only available in empty forums"
|
||||
msgstr "Only available in empty forums."
|
||||
|
||||
msgid "Group permissions subhead"
|
||||
msgstr "Edit group permissions for this forum"
|
||||
|
@ -137,3 +137,21 @@ msgstr "Post topics"
|
|||
|
||||
msgid "Revert to default"
|
||||
msgstr "Revert to default"
|
||||
|
||||
msgid "Parent label"
|
||||
msgstr "Parent"
|
||||
|
||||
msgid "Parent help"
|
||||
msgstr "Category or forum for the location of this forum."
|
||||
|
||||
msgid "Not selected"
|
||||
msgstr "Not selected"
|
||||
|
||||
msgid "Category prefix"
|
||||
msgstr "▶ "
|
||||
|
||||
msgid "Forum prefix"
|
||||
msgstr ""
|
||||
|
||||
msgid "Forum indent"
|
||||
msgstr "◦ ◦ "
|
||||
|
|
|
@ -105,20 +105,20 @@ msgstr "Категория"
|
|||
msgid "Sort by label"
|
||||
msgstr "Сортировать темы по"
|
||||
|
||||
msgid "Last post"
|
||||
msgid "Last post option"
|
||||
msgstr "Последнему сообщению"
|
||||
|
||||
msgid "Topic start"
|
||||
msgstr "Дате старта темы"
|
||||
msgid "Topic start option"
|
||||
msgstr "Первому сообщению"
|
||||
|
||||
msgid "Subject"
|
||||
msgid "Subject option"
|
||||
msgstr "Заголовку"
|
||||
|
||||
msgid "Redirect label"
|
||||
msgstr "URL переадресации"
|
||||
|
||||
msgid "Redirect help"
|
||||
msgstr "Доступно только для пустых разделов"
|
||||
msgstr "Доступно только для пустых разделов."
|
||||
|
||||
msgid "Group permissions subhead"
|
||||
msgstr "Изменения прав доступа к разделу"
|
||||
|
@ -137,3 +137,21 @@ msgstr "Создавать темы"
|
|||
|
||||
msgid "Revert to default"
|
||||
msgstr "Вернуть по умолчанию"
|
||||
|
||||
msgid "Parent label"
|
||||
msgstr "Родитель"
|
||||
|
||||
msgid "Parent help"
|
||||
msgstr "Категория или раздел для расположения данного раздела."
|
||||
|
||||
msgid "Not selected"
|
||||
msgstr "Не выбран"
|
||||
|
||||
msgid "Category prefix"
|
||||
msgstr "▶ "
|
||||
|
||||
msgid "Forum prefix"
|
||||
msgstr ""
|
||||
|
||||
msgid "Forum indent"
|
||||
msgstr "◦ ◦ "
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
<dt> @if (isset($cur['title']))<label class="f-child1 @if (isset($cur['required'])) f-req @endif" @if (is_string($key)) for="id-{{ $key }}" @endif>{!! $cur['title'] !!}</label> @endif</dt>
|
||||
<dd>
|
||||
@if ('text' === $cur['type'])
|
||||
<input @if (isset($cur['required'])) required @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}" type="text" @if (! empty($cur['maxlength'])) maxlength="{{ $cur['maxlength'] }}" @endif @if (isset($cur['pattern'])) pattern="{{ $cur['pattern'] }}" @endif @if (isset($cur['value'])) value="{{ $cur['value'] }}" @endif>
|
||||
<input @if (isset($cur['required'])) required @endif @if (isset($cur['disabled'])) disabled @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}" type="text" @if (! empty($cur['maxlength'])) maxlength="{{ $cur['maxlength'] }}" @endif @if (isset($cur['pattern'])) pattern="{{ $cur['pattern'] }}" @endif @if (isset($cur['value'])) value="{{ $cur['value'] }}" @endif>
|
||||
@elseif ('textarea' === $cur['type'])
|
||||
<textarea @if (isset($cur['required'])) required @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}">{{ $cur['value'] or '' }}</textarea>
|
||||
<textarea @if (isset($cur['required'])) required @endif @if (isset($cur['disabled'])) disabled @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}">{{ $cur['value'] or '' }}</textarea>
|
||||
@if (isset($cur['bb']))
|
||||
<ul class="f-child5">
|
||||
@foreach ($cur['bb'] as $val)
|
||||
|
@ -34,21 +34,25 @@
|
|||
</ul>
|
||||
@endif
|
||||
@elseif ('select' === $cur['type'])
|
||||
<select @if (isset($cur['required'])) required @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}">
|
||||
@foreach ($cur['options'] as $v => $n)
|
||||
<option value="{{ $v }}" @if ($v == $cur['value']) selected @endif>{{ $n }}</option>
|
||||
<select @if (isset($cur['required'])) required @endif @if (isset($cur['disabled'])) disabled @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}">
|
||||
@foreach ($cur['options'] as $v => $option)
|
||||
@if (is_array($option))
|
||||
<option value="{{ $option[0] }}" @if ($option[0] == $cur['value']) selected @endif @if (isset($option[2])) disabled @endif>{{ $option[1] }}</option>
|
||||
@else
|
||||
<option value="{{ $v }}" @if ($v == $cur['value']) selected @endif>{{ $option }}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
@elseif ('number' === $cur['type'])
|
||||
<input @if (isset($cur['required'])) required @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}" type="number" min="{{ $cur['min'] }}" max="{{ $cur['max'] }}" @if (isset($cur['value'])) value="{{ $cur['value'] }}" @endif>
|
||||
<input @if (isset($cur['required'])) required @endif @if (isset($cur['disabled'])) disabled @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}" type="number" min="{{ $cur['min'] }}" max="{{ $cur['max'] }}" @if (isset($cur['value'])) value="{{ $cur['value'] }}" @endif>
|
||||
@elseif ('checkbox' === $cur['type'])
|
||||
<label class="f-child2"><input @if (isset($cur['autofocus'])) autofocus @endif type="checkbox" id="id-{{ $key }}" name="{{ $key }}" value="{{ $cur['value'] or '1' }}" @if (! empty($cur['checked'])) checked @endif>{!! $cur['label'] !!}</label>
|
||||
<label class="f-child2"><input @if (isset($cur['autofocus'])) autofocus @endif @if (isset($cur['disabled'])) disabled @endif type="checkbox" id="id-{{ $key }}" name="{{ $key }}" value="{{ $cur['value'] or '1' }}" @if (! empty($cur['checked'])) checked @endif>{!! $cur['label'] !!}</label>
|
||||
@elseif ('radio' === $cur['type'])
|
||||
@foreach ($cur['values'] as $v => $n)
|
||||
<label class="f-label"><input @if (isset($cur['autofocus'])) autofocus @endif type="radio" id="id-{{ $key }}-{{ $v }}" name="{{ $key }}" value="{{ $v }}" @if ($v == $cur['value']) checked @endif>{{ $n }}</label>
|
||||
<label class="f-label"><input @if (isset($cur['autofocus'])) autofocus @endif @if (isset($cur['disabled'])) disabled @endif type="radio" id="id-{{ $key }}-{{ $v }}" name="{{ $key }}" value="{{ $v }}" @if ($v == $cur['value']) checked @endif>{{ $n }}</label>
|
||||
@endforeach
|
||||
@elseif ('password' === $cur['type'])
|
||||
<input @if (isset($cur['required'])) required @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}" type="password" @if (! empty($cur['maxlength'])) maxlength="{{ $cur['maxlength'] }}" @endif @if (isset($cur['pattern'])) pattern="{{ $cur['pattern'] }}" @endif @if (isset($cur['value'])) value="{{ $cur['value'] }}" @endif>
|
||||
<input @if (isset($cur['required'])) required @endif @if (isset($cur['disabled'])) disabled @endif @if (isset($cur['autofocus'])) autofocus @endif class="f-ctrl" id="id-{{ $key }}" name="{{ $key }}" type="password" @if (! empty($cur['maxlength'])) maxlength="{{ $cur['maxlength'] }}" @endif @if (isset($cur['pattern'])) pattern="{{ $cur['pattern'] }}" @endif @if (isset($cur['value'])) value="{{ $cur['value'] }}" @endif>
|
||||
@elseif ('btn' === $cur['type'])
|
||||
<a class="f-btn" href="{!! $cur['link'] !!}">{{ $cur['value'] }}</a>
|
||||
@endif
|
||||
|
|
|
@ -431,7 +431,7 @@ select {
|
|||
|
||||
.f-fdiv .f-ctrl,
|
||||
.f-fdiv .f-btn {
|
||||
line-height: 1.125rem;
|
||||
line-height: 1.25rem;
|
||||
padding: 0.5rem;
|
||||
font-size: 1rem;
|
||||
display: block;
|
||||
|
|
Loading…
Add table
Reference in a new issue