Update.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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\Controllers;
  10. use ForkBB\Core\Container;
  11. use ForkBB\Models\Page;
  12. class Update
  13. {
  14. /**
  15. * Контейнер
  16. * @var Container
  17. */
  18. protected $c;
  19. public function __construct(Container $container)
  20. {
  21. $this->c = $container;
  22. }
  23. /**
  24. * Маршрутиризация
  25. */
  26. public function routing(): Page
  27. {
  28. // fix for Router
  29. if ($this->c->config->i_fork_revision < 17) {
  30. $confChange = [
  31. 'shared' => [
  32. 'Router' => [
  33. 'class' => \ForkBB\Core\Router::class,
  34. 'base_url' => '%BASE_URL%',
  35. 'csrf' => '@Csrf'
  36. ],
  37. ],
  38. ];
  39. $this->c->config($confChange);
  40. }
  41. if ($this->c->config->i_fork_revision < 20) {
  42. $confChange = [
  43. 'shared' => [
  44. 'Cache' => [
  45. 'class' => \ForkBB\Core\Cache\FileCache::class,
  46. 'cache_dir' => '%DIR_CACHE%',
  47. ],
  48. ],
  49. ];
  50. $this->c->config($confChange);
  51. }
  52. if ($this->c->config->i_fork_revision < 35) {
  53. $confChange = [
  54. 'shared' => [
  55. 'HTMLCleaner' => [
  56. 'calss' => \ForkBB\Core\HTMLCleaner::class,
  57. 'config' => '%DIR_APP%/config/jevix.default.php',
  58. ],
  59. 'VLhtml' => \ForkBB\Models\Validators\Html::class,
  60. ],
  61. ];
  62. $this->c->config($confChange);
  63. }
  64. $uri = $_SERVER['REQUEST_URI'];
  65. if (false !== ($pos = \strpos($uri, '?'))) {
  66. $uri = \substr($uri, 0, $pos);
  67. }
  68. $uri = \rawurldecode($uri);
  69. $this->c->user = $this->c->users->create(['id' => 2, 'group_id' => $this->c->GROUP_ADMIN]); //???? id?
  70. $this->c->Lang->load('common');
  71. $r = $this->c->Router;
  72. $r->add(
  73. $r::GET,
  74. '/admin/update/{uid}/{stage|i:\d+}[/{start|i:\d+}]',
  75. 'AdminUpdate:stage',
  76. 'AdminUpdateStage'
  77. );
  78. $r->add(
  79. $r::DUO,
  80. '/admin/update',
  81. 'AdminUpdate:view',
  82. 'AdminUpdate'
  83. );
  84. $method = $_SERVER['REQUEST_METHOD'];
  85. $route = $r->route($method, $uri);
  86. $page = null;
  87. switch ($route[0]) {
  88. case $r::OK:
  89. // ... 200 OK
  90. list($page, $action) = \explode(':', $route[1], 2);
  91. $page = $this->c->$page->$action($route[2], $method);
  92. break;
  93. default:
  94. $page = $this->c->AdminUpdate->view([], 'GET');
  95. break;
  96. }
  97. return $page;
  98. }
  99. }