Redirect.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 function \ForkBB\__;
  12. class Redirect extends Page
  13. {
  14. /**
  15. * Перенаправление на главную страницу форума
  16. */
  17. public function toIndex(): Page
  18. {
  19. return $this->page('Index'); //->message('Redirecting to index');
  20. }
  21. /**
  22. * Задает адрес перехода
  23. */
  24. public function page(string $marker, array $args = []): Page
  25. {
  26. $this->link = $this->c->Router->link($marker, $args);
  27. return $this;
  28. }
  29. /**
  30. * Задает ссылку для перехода
  31. */
  32. public function url(string $url): Page
  33. {
  34. $this->link = $url;
  35. return $this;
  36. }
  37. /**
  38. * Задает сообщение
  39. */
  40. public function message(/* string|array */ $message): Page
  41. {
  42. // переадресация без вывода сообщения
  43. if ($this->c->config->i_redirect_delay < 1) {
  44. return $this;
  45. }
  46. $this->nameTpl = 'layouts/redirect';
  47. $this->robots = 'noindex';
  48. $this->message = $message;
  49. $this->timeout = $this->c->config->i_redirect_delay;
  50. return $this;
  51. }
  52. /**
  53. * Возвращает HTTP заголовки страницы
  54. * $this->httpHeaders
  55. */
  56. protected function getHttpHeaders(): array
  57. {
  58. if (
  59. $this->c->config->i_redirect_delay < 1
  60. || null === $this->nameTpl
  61. ) {
  62. $this->httpStatus = 302;
  63. $this->nameTpl = null;
  64. $this->header('Location', $this->link);
  65. }
  66. return parent::getHttpHeaders();
  67. }
  68. /**
  69. * Подготовка страницы к отображению
  70. */
  71. public function prepare(): void
  72. {
  73. }
  74. }