2018-04-18

This commit is contained in:
Visman 2018-04-18 16:09:50 +07:00
parent 6f603fd923
commit 385a3d20af
18 changed files with 90 additions and 102 deletions

View file

@ -278,4 +278,62 @@ abstract class Page extends Model
$this->a['fIswev'] = \array_merge_recursive((array) $this->a['fIswev'], $val);
}
}
/**
* Возвращает массив хлебных крошек
* Заполняет массив титула страницы
*
* @param mixed $crumbs
*
* @return array
*/
protected function crumbs(...$crumbs)
{
$result = [];
$active = true;
foreach ($crumbs as $crumb) {
// модель
if ($crumb instanceof Model) {
do {
// для поиска
if (isset($crumb->name)) {
$name = $crumb->name;
// для раздела
} elseif (isset($crumb->forum_name)) {
$name = $crumb->forum_name;
// для темы
} elseif (isset($crumb->subject)) {
$name = \ForkBB\cens($crumb->subject);
// все остальное
} else {
$name = 'no name';
}
$result[] = [$crumb->link, $name, $active];
$active = null;
if ($crumb->page > 1) {
$name .= ' ' . \ForkBB\__('Page %s', $crumb->page);
}
$this->titles = $name;
$crumb = $crumb->parent;
} while ($crumb instanceof Model && null !== $crumb->parent);
// ссылка (передана массивом)
} elseif (\is_array($crumb) && isset($crumb[0], $crumb[1])) {
$result[] = [$crumb[0], $crumb[1], $active];
$this->titles = $crumb[1];
// строка
} else {
$result[] = [null, (string) $crumb, $active];
$this->titles = (string) $crumb;
}
$active = null;
}
// главная страница
$result[] = [$this->c->Router->link('Index'), \ForkBB\__('Index'), $active];
return \array_reverse($result);
}
}

View file

@ -1,70 +0,0 @@
<?php
namespace ForkBB\Models\Pages;
use ForkBB\Models\Model;
use ForkBB\Models\Search\Model as Search;
trait CrumbTrait
{
/**
* Возвращает массив хлебных крошек
* Заполняет массив титула страницы
*
* @param mixed $args
*
* @return array
*/
protected function crumbs(...$args)
{
$crumbs = [];
$active = true;
foreach ($args as $arg) {
// поиск
if ($arg instanceof Search) {
if ($arg->page > 1) {
$this->titles = $arg->name . ' ' . \ForkBB\__('Page %s', $arg->page);
} else {
$this->titles = $arg->name;
}
$crumbs[] = [$arg->link, $arg->name, $active];
$this->titles = \ForkBB\__('Search');
$crumbs[] = [$this->c->Router->link('Search'), \ForkBB\__('Search'), null];
// раздел или топик
} elseif ($arg instanceof Model) {
while (null !== $arg->parent && $arg->link) {
if (isset($arg->forum_name)) {
$name = $arg->forum_name;
} elseif (isset($arg->subject)) {
$name = \ForkBB\cens($arg->subject);
} else {
$name = 'no name';
}
if ($arg->page > 1) {
$this->titles = $name . ' ' . \ForkBB\__('Page %s', $arg->page);
} else {
$this->titles = $name;
}
$crumbs[] = [$arg->link, $name, $active];
$active = null;
$arg = $arg->parent;
}
// ссылка
} elseif (\is_array($arg)) {
$this->titles = $arg[1];
$crumbs[] = [$arg[0], $arg[1], $active];
// строка
} else {
$this->titles = (string) $arg;
$crumbs[] = [null, (string) $arg, $active];
}
$active = null;
}
// главная страница
$crumbs[] = [$this->c->Router->link('Index'), \ForkBB\__('Index'), $active];
return \array_reverse($crumbs);
}
}

View file

@ -6,8 +6,6 @@ use ForkBB\Models\Page;
class Delete extends Page
{
use CrumbTrait;
/**
* Удаление сообщения/темы
*

View file

@ -8,7 +8,6 @@ use ForkBB\Models\Page;
class Edit extends Page
{
use CrumbTrait;
use PostFormTrait;
use PostValidatorTrait;

View file

@ -6,8 +6,6 @@ use ForkBB\Models\Page;
class Forum extends Page
{
use CrumbTrait;
/**
* Подготовка данных для шаблона
*

View file

@ -10,7 +10,6 @@ use ForkBB\Models\Page;
class Post extends Page
{
use CrumbTrait;
use PostFormTrait;
use PostValidatorTrait;

View file

@ -8,8 +8,6 @@ use ForkBB\Models\User\Model as User;
abstract class Profile extends Page
{
use CrumbTrait;
/**
* Инициализирует профиль
*
@ -55,18 +53,19 @@ abstract class Profile extends Page
}
/**
* Возвращает хлебные крошки
* Возвращает массив хлебных крошек
* Заполняет массив титула страницы
*
* @param mixed ...$args
* @param mixed $crumbs
*
* @return array
*/
protected function crumbsExt(...$args)
protected function crumbs(...$crumbs)
{
$args[] = [$this->curUser->link, \ForkBB\__('User %s', $this->curUser->username)];
$args[] = [$this->c->Router->link('Userlist'), \ForkBB\__('User list')];
$crumbs[] = [$this->curUser->link, \ForkBB\__('User %s', $this->curUser->username)];
$crumbs[] = [$this->c->Router->link('Userlist'), \ForkBB\__('User list')];
return $this->crumbs(...$args);
return parent::crumbs(...$crumbs);
}
/**

View file

@ -78,7 +78,7 @@ class Config extends Profile
$this->fIswev = $v->getErrors();
}
$this->crumbs = $this->crumbsExt([$this->c->Router->link('EditUserBoardConfig', ['id' => $this->curUser->id]), \ForkBB\__('Board configuration')]);
$this->crumbs = $this->crumbs([$this->c->Router->link('EditUserBoardConfig', ['id' => $this->curUser->id]), \ForkBB\__('Board configuration')]);
$this->form = $this->form();
$this->actionBtns = $this->btns('config');

View file

@ -132,7 +132,7 @@ class Edit extends Profile
}
}
$this->crumbs = $this->crumbsExt([$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), \ForkBB\__('Editing profile')]);
$this->crumbs = $this->crumbs([$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), \ForkBB\__('Editing profile')]);
$this->form = $this->form();
$this->actionBtns = $this->btns('edit');
@ -200,7 +200,7 @@ class Edit extends Profile
// имя, титул и аватара
$fields = [];
$fields[] = [
$fields['usertitle'] = [
'class' => 'usertitle',
'type' => 'wrap',
];

View file

@ -124,7 +124,7 @@ class Email extends Profile
}
$this->crumbs = $this->crumbsExt(
$this->crumbs = $this->crumbs(
[$this->c->Router->link('EditUserEmail', ['id' => $this->curUser->id]), \ForkBB\__('Change email')],
[$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), \ForkBB\__('Editing profile')]
);

View file

@ -61,7 +61,7 @@ class Pass extends Profile
$this->fIswev = $v->getErrors();
}
$this->crumbs = $this->crumbsExt(
$this->crumbs = $this->crumbs(
[$this->c->Router->link('EditUserPass', ['id' => $this->curUser->id]), \ForkBB\__('Change pass')],
[$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), \ForkBB\__('Editing profile')]
);

View file

@ -22,7 +22,7 @@ class View extends Profile
$this->canonical = $this->curUser->link;
$this->robots = null;
$this->crumbs = $this->crumbsExt();
$this->crumbs = $this->crumbs();
$this->form = $this->form();
$this->actionBtns = $this->btns('view');
@ -42,7 +42,7 @@ class View extends Profile
// имя, титул и аватара
$fields = [];
$fields[] = [
$fields['usertitle'] = [
'class' => 'usertitle',
'type' => 'wrap',
];

View file

@ -6,8 +6,6 @@ use ForkBB\Models\Page;
class Rules extends Page
{
use CrumbTrait;
/**
* Подготавливает данные для шаблона
*

View file

@ -10,8 +10,6 @@ use InvalidArgumentException;
class Search extends Page
{
use CrumbTrait;
/**
* Составление списка категорий/разделов для выбора
*/
@ -274,7 +272,7 @@ class Search extends Page
$this->canonical = $this->c->Router->link('Search');
$this->robots = 'noindex';
$this->form = $form;
$this->crumbs = $this->crumbs([$this->c->Router->link('Search'), \ForkBB\__('Search')]);
$this->crumbs = $this->crumbs();
return $this;
}
@ -484,4 +482,18 @@ class Search extends Page
return $this;
}
/**
* Возвращает массив хлебных крошек
* Заполняет массив титула страницы
*
* @param mixed $crumbs
*
* @return array
*/
protected function crumbs(...$crumbs)
{
$crumbs[] = [$this->c->Router->link('Search'), \ForkBB\__('Search')];
return parent::crumbs(...$crumbs);
}
}

View file

@ -7,7 +7,6 @@ use ForkBB\Models\Topic\Model as ModelTopic;
class Topic extends Page
{
use CrumbTrait;
use PostFormTrait;
/**

View file

@ -9,8 +9,6 @@ use InvalidArgumentException;
class Userlist extends Page
{
use CrumbTrait;
/**
* Список пользователей
*

View file

@ -11,7 +11,7 @@
<dl class="f-stusers">
<dt>{!! __('User info') !!}</dt>
@if ($p->stats)
@if (is_string($p->stats->userLast))
@if (\is_string($p->stats->userLast))
<dd>{!! __('Newest user') !!} {{ $p->stats->userLast }}</dd>
@else
<dd>{!! __('Newest user') !!} <a href="{!! $p->stats->userLast[0] !!}">{{ $p->stats->userLast[1] }}</a></dd>
@ -28,7 +28,7 @@
<dl class="f-inline f-onlinelist"><!-- inline -->
<dt>{!! __('Online users') !!}</dt>
@foreach ($p->online->info as $cur)
@if (is_string($cur))
@if (\is_string($cur))
<dd>{{ $cur }}</dd>
@else
<dd><a href="{!! $cur[0] !!}">{{ $cur[1] }}</a></dd>

View file

@ -37,7 +37,7 @@
<dl class="f-inline f-modlist"><!-- inline -->
<dt>{!! __('Moderated by', count($cur->moderators)) !!}</dt>
@foreach ($cur->moderators as $mod)
@if (is_string($mod))
@if (\is_string($mod))
<dd>{{ $mod }}</dd>
@else
<dd><a href="{!! $mod[0] !!}">{{ $mod[1] }}</a></dd>