PMTopic.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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\PM;
  10. use ForkBB\Models\Page;
  11. use ForkBB\Models\Pages\PM\AbstractPM;
  12. use ForkBB\Models\Pages\PostFormTrait;
  13. use ForkBB\Models\PM\Cnst;
  14. use ForkBB\Models\PM\PPost;
  15. use ForkBB\Models\PM\PTopic;
  16. use function \ForkBB\__;
  17. class PMTopic extends AbstractPM
  18. {
  19. use PostFormTrait;
  20. /**
  21. * Отображает приватный диалог по номеру поста
  22. */
  23. public function post(array $args, string $method): Page
  24. {
  25. if (
  26. ! isset($args['more1'])
  27. || isset($args['more2'])
  28. ) {
  29. return $this->c->Message->message('Bad request');
  30. }
  31. $post = $this->pms->load(Cnst::PPOST, $args['more1']);
  32. if (! $post instanceof PPost) {
  33. return $this->c->Message->message('Not Found', true, 404);
  34. }
  35. $this->model = $post->parent;
  36. $this->model->calcPage($post->id);
  37. return $this->view($args, $method);
  38. }
  39. /**
  40. * Отображает приватный диалог по его номеру
  41. */
  42. public function topic(array $args, string $method): Page
  43. {
  44. if (! isset($args['more1'])) {
  45. return $this->c->Message->message('Bad request');
  46. }
  47. $this->model = $this->pms->load(Cnst::PTOPIC, $args['more1']);
  48. if (! $this->model instanceof PTopic) {
  49. return $this->c->Message->message('Not Found', true, 404);
  50. }
  51. if (! isset($args['more2'])) {
  52. $this->model->page = 1;
  53. } elseif ('new' === $args['more2']) {
  54. $new = $this->model->firstNew;
  55. if ($new > 0) {
  56. $new = $this->pms->load(Cnst::PPOST, $new);
  57. }
  58. if ($new instanceof PPost) {
  59. return $this->c->Redirect->url($new->link);
  60. } else {
  61. return $this->c->Redirect->url($this->model->linkLast);
  62. }
  63. } elseif ('' === \trim($args['more2'], '1234567890')) {
  64. $this->model->page = (int) $args['more2'];
  65. } else {
  66. return $this->c->Message->message('Not Found', true, 404);
  67. }
  68. return $this->view($args, $method);
  69. }
  70. /**
  71. * Подготовка данных для шаблона
  72. */
  73. protected function view(array $args, string $method): Page
  74. {
  75. if (! $this->model->hasPage()) {
  76. return $this->c->Message->message('Not Found', true, 404);
  77. }
  78. $this->posts = $this->model->pageData();
  79. if (
  80. empty($this->posts)
  81. && $this->model->page > 1
  82. ) {
  83. return $this->c->Redirect->url($this->model->link);
  84. }
  85. $this->c->Lang->load('topic');
  86. $this->args = $args;
  87. $this->targetUser = $this->model->ztUser;
  88. $this->pms->area = $this->pms->inArea($this->model);
  89. $this->pmIndex = $this->pms->area;
  90. $this->nameTpl = 'pm/topic';
  91. $this->pmCrumbs[] = $this->model;
  92. if (
  93. $this->model->canReply
  94. && '1' == $this->c->config->o_quickpost
  95. ) {
  96. $form = $this->messageForm(null, 'PMAction', $this->model->dataReply, false, false, true);
  97. if (Cnst::ACTION_ARCHIVE === $this->pmIndex) {
  98. $form['btns']['submit']['value'] = __('Save');
  99. }
  100. $this->form = $form;
  101. }
  102. $this->model->updateVisit();
  103. return $this;
  104. }
  105. }