Admin.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Pages;
  10. use ForkBB\Core\Container;
  11. use ForkBB\Models\Page;
  12. use function \ForkBB\__;
  13. abstract class Admin extends Page
  14. {
  15. /**
  16. * @var array
  17. */
  18. protected $aCrumbs = [];
  19. public function __construct(Container $container)
  20. {
  21. parent::__construct($container);
  22. $this->aIndex = 'index'; # string Указатель на активный пункт навигации в меню админки
  23. $this->fIndex = self::FI_ADMIN;
  24. $this->onlinePos = 'admin';
  25. $this->onlineDetail = null;
  26. $this->robots = 'noindex, nofollow';
  27. $this->hhsLevel = 'secure';
  28. $container->Lang->load('admin');
  29. $this->pageHeader('adminStyle', 'link', 9000, [
  30. 'rel' => 'stylesheet',
  31. 'type' => 'text/css',
  32. 'href' => $this->publicLink("/style/{$this->user->style}/admin.css"),
  33. ]);
  34. }
  35. /**
  36. * Подготовка страницы к отображению
  37. */
  38. public function prepare(): void
  39. {
  40. $this->aNavigation = $this->aNavigation();
  41. $this->crumbs = $this->crumbs(...$this->aCrumbs);
  42. parent::prepare();
  43. }
  44. /**
  45. * Возвращает массив ссылок с описанием для построения навигации админки
  46. */
  47. protected function aNavigation(): array
  48. {
  49. $r = $this->c->Router;
  50. $nav = [
  51. 'index' => [$r->link('Admin'), 'Admin index'],
  52. 'users' => [$r->link('AdminUsers'), 'Users'],
  53. ];
  54. if ($this->c->userRules->banUsers) {
  55. $nav['bans'] = [$r->link('AdminBans'), 'Bans'];
  56. }
  57. if (
  58. $this->user->isAdmin
  59. || 0 === $this->c->config->i_report_method
  60. || 2 === $this->c->config->i_report_method
  61. ) {
  62. $nav['reports'] = [$r->link('AdminReports'), 'Reports'];
  63. }
  64. if ($this->user->isAdmin) {
  65. $nav += [
  66. 'options' => [$r->link('AdminOptions'), 'Admin options'],
  67. 'parser' => [$r->link('AdminParser'), 'Parser settings'],
  68. 'categories' => [$r->link('AdminCategories'), 'Categories'],
  69. 'forums' => [$r->link('AdminForums'), 'Forums'],
  70. 'groups' => [$r->link('AdminGroups'), 'User groups'],
  71. 'censoring' => [$r->link('AdminCensoring'), 'Censoring'],
  72. 'logs' => [$r->link('AdminLogs'), 'Logs'],
  73. 'maintenance' => [$r->link('AdminMaintenance'), 'Maintenance'],
  74. ];
  75. }
  76. return $nav;
  77. }
  78. /**
  79. * Возвращает массив хлебных крошек
  80. * Заполняет массив титула страницы
  81. */
  82. protected function crumbs(/* mixed */ ...$crumbs): array
  83. {
  84. if ('index' !== $this->aIndex) {
  85. if (isset($this->aNavigation[$this->aIndex])) {
  86. $crumbs[] = $this->aNavigation[$this->aIndex];
  87. } else {
  88. $crumbs[] = [null, ['%s', 'unknown']];
  89. }
  90. }
  91. $crumbs[] = [$this->c->Router->link('Admin'), 'Admin title'];
  92. return parent::crumbs(...$crumbs);
  93. }
  94. }