PM.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\PM\Cnst;
  12. class PM extends Page
  13. {
  14. /**
  15. * Точка входа для приватных сообщений
  16. */
  17. public function action(array $args, string $method): Page
  18. {
  19. $second = null;
  20. if (isset($args['second'])) {
  21. $second = $args['second'];
  22. if ('' === \trim($second, '1234567890')) {
  23. $second = (int) $second;
  24. if ($second < 1) {
  25. return $this->c->Message->message('Bad request');
  26. }
  27. } elseif (
  28. \strlen($second) < 3
  29. || '"' !== $second[0]
  30. || '"' !== $second[-1]
  31. ) {
  32. return $this->c->Message->message('Bad request');
  33. }
  34. }
  35. $pms = $this->c->pms->init($second);
  36. if (
  37. null !== $second
  38. && empty($pms->idsCurrent)
  39. && empty($pms->idsArchive)
  40. ) {
  41. return $this->c->Message->message('Not Found', true, 404);
  42. }
  43. $this->c->Lang->load('pm');
  44. $action = $args['action'] ?? ($this->user->u_pm_num_new > 0 ? Cnst::ACTION_NEW : Cnst::ACTION_CURRENT);
  45. switch ($action) {
  46. case Cnst::ACTION_NEW:
  47. case Cnst::ACTION_CURRENT:
  48. case Cnst::ACTION_ARCHIVE:
  49. $pms->area = $action;
  50. return $this->c->PMView->view($args, $method);
  51. case Cnst::ACTION_SEND:
  52. $pms->area = Cnst::ACTION_CURRENT;
  53. return $this->c->PMPost->post($args, $method);
  54. case Cnst::ACTION_TOPIC:
  55. return $this->c->PMTopic->topic($args, $method);
  56. case Cnst::ACTION_POST:
  57. return $this->c->PMTopic->post($args, $method);
  58. case Cnst::ACTION_DELETE:
  59. return $this->c->PMDelete->delete($args, $method);
  60. case Cnst::ACTION_EDIT:
  61. return $this->c->PMEdit->edit($args, $method);
  62. case Cnst::ACTION_BLOCK:
  63. return $this->c->PMBlock->block($args, $method);
  64. case Cnst::ACTION_CONFIG:
  65. return $this->c->PMConfig->config($args, $method);
  66. default:
  67. return $this->c->Message->message('Bad request');
  68. }
  69. }
  70. }