diff --git a/app/Models/Page.php b/app/Models/Page.php index cd43fefd..fbaf337c 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -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); + } } diff --git a/app/Models/Pages/CrumbTrait.php b/app/Models/Pages/CrumbTrait.php deleted file mode 100644 index 242bcc9e..00000000 --- a/app/Models/Pages/CrumbTrait.php +++ /dev/null @@ -1,70 +0,0 @@ -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); - } -} diff --git a/app/Models/Pages/Delete.php b/app/Models/Pages/Delete.php index e521c50f..fd814410 100644 --- a/app/Models/Pages/Delete.php +++ b/app/Models/Pages/Delete.php @@ -6,8 +6,6 @@ use ForkBB\Models\Page; class Delete extends Page { - use CrumbTrait; - /** * Удаление сообщения/темы * diff --git a/app/Models/Pages/Edit.php b/app/Models/Pages/Edit.php index 9e8237df..e3f599d3 100644 --- a/app/Models/Pages/Edit.php +++ b/app/Models/Pages/Edit.php @@ -8,7 +8,6 @@ use ForkBB\Models\Page; class Edit extends Page { - use CrumbTrait; use PostFormTrait; use PostValidatorTrait; diff --git a/app/Models/Pages/Forum.php b/app/Models/Pages/Forum.php index 5c21e6c1..51982f0e 100644 --- a/app/Models/Pages/Forum.php +++ b/app/Models/Pages/Forum.php @@ -6,8 +6,6 @@ use ForkBB\Models\Page; class Forum extends Page { - use CrumbTrait; - /** * Подготовка данных для шаблона * diff --git a/app/Models/Pages/Post.php b/app/Models/Pages/Post.php index d38b8551..4cb9a221 100644 --- a/app/Models/Pages/Post.php +++ b/app/Models/Pages/Post.php @@ -10,7 +10,6 @@ use ForkBB\Models\Page; class Post extends Page { - use CrumbTrait; use PostFormTrait; use PostValidatorTrait; diff --git a/app/Models/Pages/Profile.php b/app/Models/Pages/Profile.php index 1097bba2..ca080ad5 100644 --- a/app/Models/Pages/Profile.php +++ b/app/Models/Pages/Profile.php @@ -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); } /** diff --git a/app/Models/Pages/Profile/Config.php b/app/Models/Pages/Profile/Config.php index ad995637..2f59a109 100644 --- a/app/Models/Pages/Profile/Config.php +++ b/app/Models/Pages/Profile/Config.php @@ -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'); diff --git a/app/Models/Pages/Profile/Edit.php b/app/Models/Pages/Profile/Edit.php index abaead60..a79aed70 100644 --- a/app/Models/Pages/Profile/Edit.php +++ b/app/Models/Pages/Profile/Edit.php @@ -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', ]; diff --git a/app/Models/Pages/Profile/Email.php b/app/Models/Pages/Profile/Email.php index ad96cde3..e45f649e 100644 --- a/app/Models/Pages/Profile/Email.php +++ b/app/Models/Pages/Profile/Email.php @@ -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')] ); diff --git a/app/Models/Pages/Profile/Pass.php b/app/Models/Pages/Profile/Pass.php index 33d509d7..ef8dbd8e 100644 --- a/app/Models/Pages/Profile/Pass.php +++ b/app/Models/Pages/Profile/Pass.php @@ -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')] ); diff --git a/app/Models/Pages/Profile/View.php b/app/Models/Pages/Profile/View.php index f941744e..d6561aab 100644 --- a/app/Models/Pages/Profile/View.php +++ b/app/Models/Pages/Profile/View.php @@ -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', ]; diff --git a/app/Models/Pages/Rules.php b/app/Models/Pages/Rules.php index 85552e25..484b6448 100644 --- a/app/Models/Pages/Rules.php +++ b/app/Models/Pages/Rules.php @@ -6,8 +6,6 @@ use ForkBB\Models\Page; class Rules extends Page { - use CrumbTrait; - /** * Подготавливает данные для шаблона * diff --git a/app/Models/Pages/Search.php b/app/Models/Pages/Search.php index edbf24a0..23ebaca9 100644 --- a/app/Models/Pages/Search.php +++ b/app/Models/Pages/Search.php @@ -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); + } } diff --git a/app/Models/Pages/Topic.php b/app/Models/Pages/Topic.php index 1d591c7f..ff904794 100644 --- a/app/Models/Pages/Topic.php +++ b/app/Models/Pages/Topic.php @@ -7,7 +7,6 @@ use ForkBB\Models\Topic\Model as ModelTopic; class Topic extends Page { - use CrumbTrait; use PostFormTrait; /** diff --git a/app/Models/Pages/Userlist.php b/app/Models/Pages/Userlist.php index 9f527a9d..6fb1c3c9 100644 --- a/app/Models/Pages/Userlist.php +++ b/app/Models/Pages/Userlist.php @@ -9,8 +9,6 @@ use InvalidArgumentException; class Userlist extends Page { - use CrumbTrait; - /** * Список пользователей * diff --git a/app/templates/layouts/stats.forkbb.php b/app/templates/layouts/stats.forkbb.php index bee80f1a..57917890 100644 --- a/app/templates/layouts/stats.forkbb.php +++ b/app/templates/layouts/stats.forkbb.php @@ -11,7 +11,7 @@
{!! __('User info') !!}
@if ($p->stats) - @if (is_string($p->stats->userLast)) + @if (\is_string($p->stats->userLast))
{!! __('Newest user') !!} {{ $p->stats->userLast }}
@else
{!! __('Newest user') !!} {{ $p->stats->userLast[1] }}
@@ -28,7 +28,7 @@
{!! __('Online users') !!}
@foreach ($p->online->info as $cur) - @if (is_string($cur)) + @if (\is_string($cur))
{{ $cur }}
@else
{{ $cur[1] }}
diff --git a/app/templates/layouts/subforums.forkbb.php b/app/templates/layouts/subforums.forkbb.php index 8066e45c..57d39ac0 100644 --- a/app/templates/layouts/subforums.forkbb.php +++ b/app/templates/layouts/subforums.forkbb.php @@ -37,7 +37,7 @@
{!! __('Moderated by', count($cur->moderators)) !!}
@foreach ($cur->moderators as $mod) - @if (is_string($mod)) + @if (\is_string($mod))
{{ $mod }}
@else
{{ $mod[1] }}