Visman 7 vuotta sitten
vanhempi
commit
385a3d20af

+ 58 - 0
app/Models/Page.php

@@ -278,4 +278,62 @@ abstract class Page extends Model
             $this->a['fIswev'] = \array_merge_recursive((array) $this->a['fIswev'], $val);
             $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);
+    }
 }
 }

+ 0 - 70
app/Models/Pages/CrumbTrait.php

@@ -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);
-    }
-}

+ 0 - 2
app/Models/Pages/Delete.php

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

+ 0 - 1
app/Models/Pages/Edit.php

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

+ 0 - 2
app/Models/Pages/Forum.php

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

+ 0 - 1
app/Models/Pages/Post.php

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

+ 7 - 8
app/Models/Pages/Profile.php

@@ -8,8 +8,6 @@ use ForkBB\Models\User\Model as User;
 
 
 abstract class Profile extends Page
 abstract class Profile extends Page
 {
 {
-    use CrumbTrait;
-
     /**
     /**
      * Инициализирует профиль
      * Инициализирует профиль
      *
      *
@@ -55,18 +53,19 @@ abstract class Profile extends Page
     }
     }
 
 
     /**
     /**
-     * Возвращает хлебные крошки
+     * Возвращает массив хлебных крошек
+     * Заполняет массив титула страницы
      *
      *
-     * @param mixed ...$args
+     * @param mixed $crumbs
      *
      *
      * @return array
      * @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);
     }
     }
 
 
     /**
     /**

+ 1 - 1
app/Models/Pages/Profile/Config.php

@@ -78,7 +78,7 @@ class Config extends Profile
             $this->fIswev = $v->getErrors();
             $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->form       = $this->form();
         $this->actionBtns = $this->btns('config');
         $this->actionBtns = $this->btns('config');
 
 

+ 2 - 2
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->form       = $this->form();
         $this->actionBtns = $this->btns('edit');
         $this->actionBtns = $this->btns('edit');
 
 
@@ -200,7 +200,7 @@ class Edit extends Profile
 
 
         // имя, титул и аватара
         // имя, титул и аватара
         $fields = [];
         $fields = [];
-        $fields[] = [
+        $fields['usertitle'] = [
             'class' => 'usertitle',
             'class' => 'usertitle',
             'type'  => 'wrap',
             'type'  => 'wrap',
         ];
         ];

+ 1 - 1
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('EditUserEmail', ['id' => $this->curUser->id]), \ForkBB\__('Change email')],
             [$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), \ForkBB\__('Editing profile')]
             [$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), \ForkBB\__('Editing profile')]
         );
         );

+ 1 - 1
app/Models/Pages/Profile/Pass.php

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

+ 2 - 2
app/Models/Pages/Profile/View.php

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

+ 0 - 2
app/Models/Pages/Rules.php

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

+ 15 - 3
app/Models/Pages/Search.php

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

+ 0 - 1
app/Models/Pages/Topic.php

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

+ 0 - 2
app/Models/Pages/Userlist.php

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

+ 2 - 2
app/templates/layouts/stats.forkbb.php

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

+ 1 - 1
app/templates/layouts/subforums.forkbb.php

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