From 725c1919cf83a7a9037af8e03f657c2d0013ac81 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Mon, 2 Oct 2023 13:40:48 +0700 Subject: [PATCH] Added support for webp avatars (#926) --- library/config.php | 23 ++++++++++++++--------- src/Legacy/Common/Upload.php | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/library/config.php b/library/config.php index ef9068969..0a2dcbd46 100644 --- a/library/config.php +++ b/library/config.php @@ -542,15 +542,20 @@ $bb_cfg['sitemap_sending'] = [ // Extensions $bb_cfg['file_id_ext'] = [ + // Images 1 => 'gif', - 2 => 'gz', - 3 => 'jpg', - 4 => 'png', - 5 => 'rar', - 6 => 'tar', - 7 => 'tiff', - 8 => 'torrent', + 2 => 'jpg', + 3 => 'png', + 4 => 'bmp', + 5 => 'webp', + // Archives + 6 => 'gz', + 7 => '7z', + 8 => 'rar', 9 => 'zip', + 10 => 'tar', + // Other + 11 => 'torrent', ]; // Attachments @@ -564,7 +569,7 @@ $bb_cfg['gen_forums_allowed_ext'] = ['zip', 'rar']; // TODO: для обычны // Avatars $bb_cfg['avatars'] = [ - 'allowed_ext' => ['gif', 'jpg', 'jpeg', 'png', 'bmp'], // разрешенные форматы файлов + 'allowed_ext' => ['gif', 'jpg', 'png', 'bmp', 'webp'], // разрешенные форматы файлов (При добавлении нового расширения, продублируйте в $bb_cfg['file_id_ext']) 'bot_avatar' => '/gallery/bot.gif', // аватара бота 'max_size' => 100 * 1024, // размер аватары в байтах 'max_height' => 100, // высота аватара в px @@ -577,7 +582,7 @@ $bb_cfg['avatars'] = [ // Group avatars $bb_cfg['group_avatars'] = [ - 'allowed_ext' => ['gif', 'jpg', 'jpeg', 'png', 'bmp'], // разрешенные форматы файлов + 'allowed_ext' => ['gif', 'jpg', 'png', 'bmp', 'webp'], // разрешенные форматы файлов (При добавлении нового расширения, продублируйте в $bb_cfg['file_id_ext']) 'max_size' => 300 * 1024, // размер аватары в байтах 'max_height' => 300, // высота аватара в px 'max_width' => 300, // ширина аватара в px diff --git a/src/Legacy/Common/Upload.php b/src/Legacy/Common/Upload.php index b1a772d33..5cd212cf0 100644 --- a/src/Legacy/Common/Upload.php +++ b/src/Legacy/Common/Upload.php @@ -37,13 +37,18 @@ class Upload public $file_size = ''; public $ext_ids = []; // array_flip($bb_cfg['file_id_ext']) public $errors = []; - public $img_types = [ - 1 => 'gif', - 2 => 'jpg', - 3 => 'png', - 6 => 'bmp', - 7 => 'tiff', - 8 => 'tiff', + + /** + * Image types array + * + * @var array|string[] + */ + public array $img_types = [ + IMAGETYPE_GIF => 'gif', + IMAGETYPE_JPEG => 'jpg', + IMAGETYPE_PNG => 'png', + IMAGETYPE_BMP => 'bmp', + IMAGETYPE_WEBP => 'webp' ]; /**