From 02e8fc40213d9c37c52929d332e2acf94306b03c Mon Sep 17 00:00:00 2001 From: Visman Date: Wed, 5 Jul 2023 23:14:53 +0700 Subject: [PATCH] Add file uploads 1/... --- app/Controllers/Routing.php | 6 ++++++ app/Models/Pages/Admin.php | 1 + app/Models/Pages/Admin/Install.php | 6 ++++++ app/Models/Pages/Admin/Update.php | 31 +++++++++++++++++++++++++++++- app/config/main.dist.php | 1 + app/lang/en/admin.po | 3 +++ app/lang/ru/admin.po | 3 +++ public/upload/index.html | 1 + 8 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 public/upload/index.html diff --git a/app/Controllers/Routing.php b/app/Controllers/Routing.php index 5353d1fa..f42a8b86 100644 --- a/app/Controllers/Routing.php +++ b/app/Controllers/Routing.php @@ -780,6 +780,12 @@ class Routing 'AdminLogs:action', 'AdminLogsAction' ); + $r->add( + $r::DUO, + '/admin/uploads', + 'AdminUploads:view', + 'AdminUploads' + ); } $uri = $_SERVER['REQUEST_URI']; diff --git a/app/Models/Pages/Admin.php b/app/Models/Pages/Admin.php index 7a14e7bc..532b0c2c 100644 --- a/app/Models/Pages/Admin.php +++ b/app/Models/Pages/Admin.php @@ -81,6 +81,7 @@ abstract class Admin extends Page 'censoring' => [$r->link('AdminCensoring'), 'Censoring'], 'logs' => [$r->link('AdminLogs'), 'Logs'], 'maintenance' => [$r->link('AdminMaintenance'), 'Maintenance'], + 'uploads' => [$r->link('AdminUploads'), 'Uploads'], ]; } diff --git a/app/Models/Pages/Admin/Install.php b/app/Models/Pages/Admin/Install.php index bdd5bee2..75fd546f 100644 --- a/app/Models/Pages/Admin/Install.php +++ b/app/Models/Pages/Admin/Install.php @@ -116,6 +116,7 @@ class Install extends Admin $this->c->DIR_CONFIG . '/db', $this->c->DIR_CACHE, $this->c->DIR_PUBLIC . '/img/avatars', + $this->c->DIR_PUBLIC . '/upload', ]; foreach ($folders as $folder) { @@ -829,6 +830,9 @@ class Install extends Admin 'g_pm_limit' => ['INT(10) UNSIGNED', false, 100], 'g_sig_length' => ['SMALLINT UNSIGNED', false, 400], 'g_sig_lines' => ['TINYINT UNSIGNED', false, 4], + 'g_up_ext' => ['VARCHAR(255)', false, 'webp,jpg,jpeg,png,gif,avif'], + 'g_up_size_kb' => ['INT(10) UNSIGNED', false, 0], + 'g_up_limit_mb' => ['INT(10) UNSIGNED', false, 0], ], 'PRIMARY KEY' => ['g_id'], 'ENGINE' => $this->DBEngine, @@ -1517,6 +1521,8 @@ class Install extends Admin ], FORK_JSON_ENCODE ), 's_РЕГИСТР' => 'Ok', + 'b_upload' => 1, + 'i_upload_img_quality' => 75, ]; foreach ($forkConfig as $name => $value) { diff --git a/app/Models/Pages/Admin/Update.php b/app/Models/Pages/Admin/Update.php index 79d6e4e2..bc2ae5c3 100644 --- a/app/Models/Pages/Admin/Update.php +++ b/app/Models/Pages/Admin/Update.php @@ -25,7 +25,7 @@ class Update extends Admin { const PHP_MIN = '8.0.0'; const REV_MIN_FOR_UPDATE = 53; - const LATEST_REV_WITH_DB_CHANGES = 55; + const LATEST_REV_WITH_DB_CHANGES = 59; const LOCK_NAME = 'lock_update'; const LOCK_TTL = 1800; const CONFIG_FILE = 'main.php'; @@ -602,4 +602,33 @@ class Update extends Admin return null; } + + /** + * rev.58 to rev.59 + */ + protected function stageNumber58(array $args): ?int + { + $config = $this->c->config; + + $config->b_upload = 1; + $config->i_upload_img_quality = 75; + + $config->save(); + + $this->c->DB->addField('::groups', 'g_up_ext', 'VARCHAR(255)', false, 'webp,jpg,jpeg,png,gif,avif'); + $this->c->DB->addField('::groups', 'g_up_size_kb', 'INT(10) UNSIGNED', false, 0); + $this->c->DB->addField('::groups', 'g_up_limit_mb', 'INT(10) UNSIGNED', false, 0); + + $coreConfig = new CoreConfig($this->configFile); + + $coreConfig->add( + 'multiple=>AdminUploads', + '\\ForkBB\\Models\\Pages\\Admin\\Uploads::class', + 'AdminLogs' + ); + + $coreConfig->save(); + + return null; + } } diff --git a/app/config/main.dist.php b/app/config/main.dist.php index f59849a1..d0e8ec14 100644 --- a/app/config/main.dist.php +++ b/app/config/main.dist.php @@ -390,6 +390,7 @@ return [ 'AdminParserSmilies' => \ForkBB\Models\Pages\Admin\Parser\Smilies::class, 'AdminParserBBCode' => \ForkBB\Models\Pages\Admin\Parser\BBCode::class, 'AdminLogs' => \ForkBB\Models\Pages\Admin\Logs::class, + 'AdminUploads' => \ForkBB\Models\Pages\Admin\Uploads::class, 'AdminListModel' => \ForkBB\Models\AdminList\AdminList::class, 'BanListModel' => \ForkBB\Models\BanList\BanList::class, diff --git a/app/lang/en/admin.po b/app/lang/en/admin.po index 11cb018e..110bb95b 100644 --- a/app/lang/en/admin.po +++ b/app/lang/en/admin.po @@ -77,3 +77,6 @@ msgstr "Logs" msgid "Admin menu" msgstr "Admin menu" + +msgid "Uploads" +msgstr "Uploads" diff --git a/app/lang/ru/admin.po b/app/lang/ru/admin.po index f051e821..186ac4a1 100644 --- a/app/lang/ru/admin.po +++ b/app/lang/ru/admin.po @@ -77,3 +77,6 @@ msgstr "Логи" msgid "Admin menu" msgstr "Меню админки" + +msgid "Uploads" +msgstr "Загрузки" diff --git a/public/upload/index.html b/public/upload/index.html new file mode 100644 index 00000000..03d0b25b --- /dev/null +++ b/public/upload/index.html @@ -0,0 +1 @@ +..