Forum.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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\Models\Page;
  11. use ForkBB\Models\Forum\Forum as ForumModel;
  12. use function \ForkBB\__;
  13. class Forum extends Page
  14. {
  15. /**
  16. * Подготовка данных для шаблона
  17. */
  18. public function view(array $args): Page
  19. {
  20. $this->c->Lang->load('forum');
  21. $this->c->Lang->load('subforums');
  22. $forum = $this->c->forums->loadTree($args['id']);
  23. if (! $forum instanceof ForumModel) {
  24. return $this->c->Message->message('Bad request');
  25. }
  26. // редирект, если раздел это ссылка
  27. if ($forum->redirect_url) {
  28. return $this->c->Redirect->url($forum->redirect_url);
  29. }
  30. $forum->page = $args['page'] ?? 1;
  31. if (! $forum->hasPage()) {
  32. return $this->c->Message->message('Not Found', true, 404);
  33. }
  34. $this->nameTpl = 'forum';
  35. $this->onlinePos = 'forum-' . $args['id'];
  36. $this->canonical = $this->c->Router->link(
  37. 'Forum',
  38. [
  39. 'id' => $args['id'],
  40. 'name' => $forum->forum_name,
  41. 'page' => $forum->page,
  42. ]
  43. );
  44. $this->model = $forum;
  45. $this->topics = $forum->pageData();
  46. $this->crumbs = $this->crumbs($forum);
  47. if (empty($this->topics)) {
  48. $this->fIswev = ['i', 'Empty forum'];
  49. } elseif (
  50. $this->user->isAdmin
  51. || $this->user->isModerator($forum)
  52. ) {
  53. $this->c->Lang->load('misc');
  54. $this->enableMod = true;
  55. $this->formMod = $this->formMod($forum);
  56. }
  57. if ($this->c->config->i_feed_type > 0) {
  58. $feedType = 2 === $this->c->config->i_feed_type ? 'atom' : 'rss';
  59. $this->pageHeader('feed', 'link', 0, [
  60. 'rel' => 'alternate',
  61. 'type' => "application/{$feedType}+xml",
  62. 'href' => $this->c->Router->link('Feed', ['type' => $feedType, 'fid' => $forum->id]),
  63. ]);
  64. }
  65. return $this;
  66. }
  67. /**
  68. * Создает массив данных для формы модерации
  69. */
  70. protected function formMod(ForumModel $forum): array
  71. {
  72. $form = [
  73. 'id' => 'id-form-mod',
  74. 'action' => $this->c->Router->link('Moderate'),
  75. 'hidden' => [
  76. 'token' => $this->c->Csrf->create('Moderate'),
  77. 'forum' => $forum->id,
  78. 'page' => $forum->page,
  79. 'step' => 1,
  80. ],
  81. 'sets' => [],
  82. 'btns' => [
  83. 'open' => [
  84. 'class' => ['origin'],
  85. 'type' => 'submit',
  86. 'value' => __('Open'),
  87. ],
  88. 'close' => [
  89. 'class' => ['origin'],
  90. 'type' => 'submit',
  91. 'value' => __('Close'),
  92. ],
  93. 'delete' => [
  94. 'class' => ['origin'],
  95. 'type' => 'submit',
  96. 'value' => __('Delete'),
  97. ],
  98. 'move' => [
  99. 'class' => ['origin'],
  100. 'type' => 'submit',
  101. 'value' => __('Move'),
  102. ],
  103. 'merge' => [
  104. 'class' => ['origin'],
  105. 'type' => 'submit',
  106. 'value' => __('Merge'),
  107. ],
  108. ],
  109. ];
  110. return $form;
  111. }
  112. }