From 4a839f72b749deaa5128cf1ca1051856d50f2ac3 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 9 Dec 2024 14:10:47 -0800 Subject: [PATCH 01/11] Move PWA icons to unique images dir --- controller/manifest.php | 4 +- event/listener.php | 6 +- ext.php | 5 + language/en/info_acp_webpushnotifications.php | 7 +- .../en/webpushnotifications_common_acp.php | 4 +- language/ru/info_acp_webpushnotifications.php | 7 +- .../ru/webpushnotifications_common_acp.php | 4 +- migrations/move_site_icons.php | 114 ++++++++++++++++++ .../event/overall_header_head_append.html | 4 +- tests/event/listener_test.php | 11 +- 10 files changed, 147 insertions(+), 19 deletions(-) create mode 100644 migrations/move_site_icons.php diff --git a/controller/manifest.php b/controller/manifest.php index 05058f8..d1ebff7 100644 --- a/controller/manifest.php +++ b/controller/manifest.php @@ -82,12 +82,12 @@ public function handle(): JsonResponse { $manifest['icons'] = [ [ - 'src' => $board_url . '/' . $this->config['icons_path'] . '/' . $this->config['pwa_icon_small'], + 'src' => $board_url . '/' . ext::PWA_ICON_DIR . '/' . $this->config['pwa_icon_small'], 'sizes' => '192x192', 'type' => 'image/png' ], [ - 'src' => $board_url . '/' . $this->config['icons_path'] . '/' . $this->config['pwa_icon_large'], + 'src' => $board_url . '/' . ext::PWA_ICON_DIR . '/' . $this->config['pwa_icon_large'], 'sizes' => '512x512', 'type' => 'image/png' ] diff --git a/event/listener.php b/event/listener.php index c235e6e..c557ccd 100644 --- a/event/listener.php +++ b/event/listener.php @@ -144,7 +144,7 @@ public function pwa_manifest() { $this->template->assign_vars([ 'U_MANIFEST_URL' => $this->controller_helper->route('phpbb_webpushnotifications_manifest_controller'), - 'U_TOUCH_ICON' => $this->config['pwa_icon_small'], + 'U_TOUCH_ICON' => $this->config['pwa_icon_small'] ? ext::PWA_ICON_DIR . '/' . $this->config['pwa_icon_small'] : null, 'SHORT_SITE_NAME' => $this->config['pwa_short_name'] ?: $this->trim_shortname($this->config['sitename']), ]); } @@ -201,7 +201,7 @@ public function acp_pwa_allow_emoji($event) */ public function pwa_icon_name($value, $key) { - return $this->config['icons_path'] . '/'; + return ext::PWA_ICON_DIR . '/'; } /** @@ -272,7 +272,7 @@ public function validate_pwa_options($event) } // Check if image is valid - $image = $this->root_path . $this->config['icons_path'] . '/' . $value; + $image = $this->root_path . ext::PWA_ICON_DIR . '/' . $value; $image_info = $this->imagesize->getImageSize($image); if ($image_info !== false) { diff --git a/ext.php b/ext.php index bb19ddc..56f2872 100644 --- a/ext.php +++ b/ext.php @@ -15,6 +15,11 @@ */ class ext extends \phpbb\extension\base { + /** + * Location for storing PWA touch/app icons. + */ + public const PWA_ICON_DIR = 'images/site_icons'; + /** * Require phpBB 3.3.12 due to new template and core events. */ diff --git a/language/en/info_acp_webpushnotifications.php b/language/en/info_acp_webpushnotifications.php index 77aafef..7e01c05 100644 --- a/language/en/info_acp_webpushnotifications.php +++ b/language/en/info_acp_webpushnotifications.php @@ -42,6 +42,9 @@ 'ACP_WEBPUSH_REMOVE_WARNING' => 'Web Push Notifications are now built into phpBB', 'ACP_WEBPUSH_REMOVE_NOTICE' => 'The extension “phpBB Browser Push Notifications” is no longer needed and should be uninstalled and removed.
All settings and user preferences associated with the extension will be migrated into phpBB’s built-in push notifications when you uninstall the extension.', 'LOG_CONFIG_WEBPUSH' => 'Altered Web Push settings', - 'LOG_WEBPUSH_MESSAGE_FAIL' => 'Web Push message could not be sent: %s', - 'LOG_WEBPUSH_SUBSCRIPTION_REMOVED' => 'Removed Web Push subscription:» %s', + 'LOG_WEBPUSH_MESSAGE_FAIL' => 'Web Push message could not be sent:
» %s', + 'LOG_WEBPUSH_SUBSCRIPTION_REMOVED' => 'Removed Web Push subscription:
» %s', + 'LOG_WEBPUSH_ICON_DIR_FAIL' => 'Webpush Notifications could not migrate the following item in phpBB’s images directory:
» %1$s » %2$s', + 'LOG_WEBPUSH_ICON_DIR_SUCCESS' => 'Webpush Notifications added the following directory:
» %s', + 'LOG_WEBPUSH_ICON_COPY_SUCCESS' => 'Webpush Notifications copied existing PWA touch icons to:
» %s', ]); diff --git a/language/en/webpushnotifications_common_acp.php b/language/en/webpushnotifications_common_acp.php index 4e408ef..c1ce66f 100644 --- a/language/en/webpushnotifications_common_acp.php +++ b/language/en/webpushnotifications_common_acp.php @@ -43,9 +43,9 @@ 'PWA_SHORT_NAME_EXPLAIN' => 'Your site name in 12 characters or fewer, which may be used as a label for an icon on a mobile device’s home screen. (If this field is left empty, the first 12 characters of the Site name will be used.)', 'PWA_SHORT_NAME_INVALID' => '“Short site name” exceeds the 12 character limit.', 'PWA_ICON_SMALL' => 'Small mobile device icon', - 'PWA_ICON_SMALL_EXPLAIN' => 'File name of a 192px x 192px PNG image. This file must be uploaded to your board’s icons directory.', + 'PWA_ICON_SMALL_EXPLAIN' => 'File name of a 192px x 192px PNG image. This file must be uploaded to your board’s ' . \phpbb\webpushnotifications\ext::PWA_ICON_DIR . ' directory.', 'PWA_ICON_LARGE' => 'Large mobile device icon', - 'PWA_ICON_LARGE_EXPLAIN' => 'File name of a 512px x 512px PNG image. This file must be uploaded to your board’s icons directory.', + 'PWA_ICON_LARGE_EXPLAIN' => 'File name of a 512px x 512px PNG image. This file must be uploaded to your board’s ' . \phpbb\webpushnotifications\ext::PWA_ICON_DIR . ' directory.', 'PWA_ICON_SIZE_INVALID' => '“%s” does not have the correct image dimensions.', 'PWA_ICON_MIME_INVALID' => '“%s” must be a PNG image file.', 'PWA_IMAGE_INVALID' => '“%s” does not appear to be a valid image file.', diff --git a/language/ru/info_acp_webpushnotifications.php b/language/ru/info_acp_webpushnotifications.php index 20eb690..cbf4edc 100644 --- a/language/ru/info_acp_webpushnotifications.php +++ b/language/ru/info_acp_webpushnotifications.php @@ -42,6 +42,9 @@ 'ACP_WEBPUSH_REMOVE_WARNING' => 'Браузерные push—уведомления теперь встроены в phpBB', 'ACP_WEBPUSH_REMOVE_NOTICE' => 'Расширение «phpBB Browser Push Notifications» больше не требуется и должно быть удалено.
Все системные и пользовательские настройки, связанные с данным расширением, будут перенесены в соответствующие настройки браузерных push—уведомлений конференции автоматически при удалении данного расширения.', 'LOG_CONFIG_WEBPUSH' => 'Изменены настройки браузерных push—уведомлений', - 'LOG_WEBPUSH_MESSAGE_FAIL' => 'Не удалось отправить браузерное push—уведомление: %s', - 'LOG_WEBPUSH_SUBSCRIPTION_REMOVED' => 'Удалена подписка на браузерные push—уведомления:» %s', + 'LOG_WEBPUSH_MESSAGE_FAIL' => 'Не удалось отправить браузерное push—уведомление:
» %s', + 'LOG_WEBPUSH_SUBSCRIPTION_REMOVED' => 'Удалена подписка на браузерные push—уведомления:
» %s', + 'LOG_WEBPUSH_ICON_DIR_FAIL' => 'Webpush Notifications could not migrate the following item in phpBB’s images directory:
» %1$s » %2$s', + 'LOG_WEBPUSH_ICON_DIR_SUCCESS' => 'Webpush Notifications added the following directory:
» %s', + 'LOG_WEBPUSH_ICON_COPY_SUCCESS' => 'Webpush Notifications copied existing PWA touch icons to:
» %s', ]); diff --git a/language/ru/webpushnotifications_common_acp.php b/language/ru/webpushnotifications_common_acp.php index 7cc67c9..e3e7e13 100644 --- a/language/ru/webpushnotifications_common_acp.php +++ b/language/ru/webpushnotifications_common_acp.php @@ -43,9 +43,9 @@ 'PWA_SHORT_NAME_EXPLAIN' => 'Краткое имя сайта длиной не более 12 символов, которое будет использовано в качестве подписи к значку на домашнем экране мобильного устройства. Если оставить пустым, будут использованы первые 12 символов значения настройки, заданной в поле Название конференции.', 'PWA_SHORT_NAME_INVALID' => 'Заданное значение в поле «Краткое имя сайта» превышает 12 символов.', 'PWA_ICON_SMALL' => 'Маленький значок для мобильного устройства', - 'PWA_ICON_SMALL_EXPLAIN' => 'Имя файла изображения формата PNG размером 192 x 192 пикселя. Файл изображения должен быть загружен на сервер в папку images/icons.', + 'PWA_ICON_SMALL_EXPLAIN' => 'Имя файла изображения формата PNG размером 192 x 192 пикселя. Файл изображения должен быть загружен на сервер в папку ' . \phpbb\webpushnotifications\ext::PWA_ICON_DIR . '.', 'PWA_ICON_LARGE' => 'Большой значок для мобильного устройства', - 'PWA_ICON_LARGE_EXPLAIN' => 'Имя файла изображения формата PNG размером 512 x 512 пикселей. Файл изображения должен быть загружен на сервер в папку images/icons.', + 'PWA_ICON_LARGE_EXPLAIN' => 'Имя файла изображения формата PNG размером 512 x 512 пикселей. Файл изображения должен быть загружен на сервер в папку ' . \phpbb\webpushnotifications\ext::PWA_ICON_DIR . '.', 'PWA_ICON_SIZE_INVALID' => 'Изображение «%s» имеет некорректные размеры.', 'PWA_ICON_MIME_INVALID' => 'Файл изображения «%s» должен иметь формат PNG.', 'PWA_IMAGE_INVALID' => 'Файл «%s» не яввляется файлом изображения.', diff --git a/migrations/move_site_icons.php b/migrations/move_site_icons.php new file mode 100644 index 0000000..819e7d2 --- /dev/null +++ b/migrations/move_site_icons.php @@ -0,0 +1,114 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + */ + +namespace phpbb\webpushnotifications\migrations; + +use phpbb\db\migration\container_aware_migration; +use phpbb\filesystem\exception\filesystem_exception; +use phpbb\filesystem\filesystem; + +class move_site_icons extends container_aware_migration +{ + private const NEW_ICON_DIR = 'images/site_icons'; + private const OLD_ICON_DIR = 'images/icons'; + + /* @var filesystem $filesystem */ + private $filesystem; + + public function effectively_installed() + { + return $this->get_filesystem()->exists($this->container->getParameter('core.root_path') . self::NEW_ICON_DIR); + } + + public static function depends_on() + { + return ['\phpbb\webpushnotifications\migrations\add_acp_pwa_configs']; + } + + public function update_data(): array + { + return [ + ['custom', [[$this, 'configure_site_icons']]], + ]; + } + + /** + * Create a site_icons directory in the images directory (and copy existing PWA the icons there) + * + * @return void + */ + public function configure_site_icons() + { + // Cache frequently used services and values + $filesystem = $this->get_filesystem(); + $root_path = $this->container->getParameter('core.root_path'); + $user = $this->container->get('user'); + $logger = $this->container->get('log'); + + // Prepare paths once + $new_icon_path = $root_path . self::NEW_ICON_DIR; + $old_icon_path = $root_path . self::OLD_ICON_DIR; + + // Batch get config values + $icons = [ + 'small' => $this->config->offsetGet('pwa_icon_small'), + 'large' => $this->config->offsetGet('pwa_icon_large') + ]; + + try + { + // Create directory only if needed + if (!$filesystem->exists($new_icon_path)) + { + $filesystem->mkdir($new_icon_path); + } + + // Process icons + $copied = false; + foreach ($icons as $icon) + { + $old_file = $old_icon_path . '/' . $icon; + $new_file = $new_icon_path . '/' . $icon; + + if (!empty($icon) && $filesystem->exists($old_file)) + { + $filesystem->copy($old_file, $new_file); + $copied = true; + } + } + + // Set up a log message result + $message = $copied ? 'LOG_WEBPUSH_ICON_COPY_SUCCESS' : 'LOG_WEBPUSH_ICON_DIR_SUCCESS'; + $result = [$message => [self::NEW_ICON_DIR]]; + } + catch (filesystem_exception $e) + { + $result = ['LOG_WEBPUSH_ICON_DIR_FAIL' => [$e->get_filename(), $e->getMessage()]]; + } + + // Log result + $logger->add('admin', $user->data['user_id'], $user->ip, key($result), false, current($result)); + } + + /** + * Get the filesystem object + * + * @return filesystem + */ + protected function get_filesystem() + { + if ($this->filesystem === null) + { + $this->filesystem = $this->container->get('filesystem'); + } + + return $this->filesystem; + } +} diff --git a/styles/all/template/event/overall_header_head_append.html b/styles/all/template/event/overall_header_head_append.html index e655585..77c4466 100644 --- a/styles/all/template/event/overall_header_head_append.html +++ b/styles/all/template/event/overall_header_head_append.html @@ -16,8 +16,10 @@ +{% if U_TOUCH_ICON %} -{% if U_TOUCH_ICON %}{% endif %} + +{% endif %} {% if NOTIFICATIONS_WEBPUSH_ENABLE %} {% include '@phpbb_webpushnotifications/ucp_notifications_webpush.html' %} diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php index 714d547..70a4a6f 100644 --- a/tests/event/listener_test.php +++ b/tests/event/listener_test.php @@ -10,6 +10,8 @@ namespace phpbb\webpushnotifications\tests\event; +use phpbb\webpushnotifications\ext; + require_once __DIR__ . '/../../../../../includes/functions_acp.php'; class listener_test extends \phpbb_database_test_case @@ -320,7 +322,7 @@ public function test_pwa_manifest() ->method('assign_vars') ->with([ 'U_MANIFEST_URL' => $this->controller_helper->route('phpbb_webpushnotifications_manifest_controller'), - 'U_TOUCH_ICON' => 'icon-192x192.png', + 'U_TOUCH_ICON' => ext::PWA_ICON_DIR . '/icon-192x192.png', 'SHORT_SITE_NAME' => 'Test', ]); @@ -450,7 +452,6 @@ public function validate_pwa_options_data() */ public function test_validate_pwa_options($validate, $cfg_array, $expected_error) { - $this->config['icons_path'] = 'images/icons'; $config_name = key($cfg_array); $config_definition = ['validate' => $validate]; @@ -467,9 +468,9 @@ public function test_validate_pwa_options($validate, $cfg_array, $expected_error $this->imagesize->expects($pwa_icon_small && $pwa_icon_large ? self::once() : self::never()) ->method('getImageSize') ->willReturnMap([ - [$this->root_path . $this->config['icons_path'] . '/', '', false], - [$this->root_path . $this->config['icons_path'] . '/' . $pwa_icon_small, '', ['width' => (int) $small_image_name, 'height' => (int) $small_image_name, 'type' => $small_image_ext === 'png' ? IMAGETYPE_PNG : IMAGETYPE_UNKNOWN]], - [$this->root_path . $this->config['icons_path'] . '/' . $pwa_icon_large, '', ['width' => (int) $large_image_name, 'height' => (int) $large_image_name, 'type' => $large_image_ext === 'png' ? IMAGETYPE_PNG : IMAGETYPE_UNKNOWN]], + [$this->root_path . ext::PWA_ICON_DIR . '/', '', false], + [$this->root_path . ext::PWA_ICON_DIR . '/' . $pwa_icon_small, '', ['width' => (int) $small_image_name, 'height' => (int) $small_image_name, 'type' => $small_image_ext === 'png' ? IMAGETYPE_PNG : IMAGETYPE_UNKNOWN]], + [$this->root_path . ext::PWA_ICON_DIR . '/' . $pwa_icon_large, '', ['width' => (int) $large_image_name, 'height' => (int) $large_image_name, 'type' => $large_image_ext === 'png' ? IMAGETYPE_PNG : IMAGETYPE_UNKNOWN]], ]); $dispatcher = new \phpbb\event\dispatcher(); From d8767894dbb2a54837f15ea8dd4576bf999b50b4 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 9 Dec 2024 20:55:02 -0800 Subject: [PATCH 02/11] Rename migration --- migrations/{move_site_icons.php => setup_site_icons.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename migrations/{move_site_icons.php => setup_site_icons.php} (97%) diff --git a/migrations/move_site_icons.php b/migrations/setup_site_icons.php similarity index 97% rename from migrations/move_site_icons.php rename to migrations/setup_site_icons.php index 819e7d2..b1274f0 100644 --- a/migrations/move_site_icons.php +++ b/migrations/setup_site_icons.php @@ -14,7 +14,7 @@ use phpbb\filesystem\exception\filesystem_exception; use phpbb\filesystem\filesystem; -class move_site_icons extends container_aware_migration +class setup_site_icons extends container_aware_migration { private const NEW_ICON_DIR = 'images/site_icons'; private const OLD_ICON_DIR = 'images/icons'; From b65e539de4d4665d26acfff884e2006f28170389 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 10 Dec 2024 08:06:05 -0800 Subject: [PATCH 03/11] Add an empty index.htm to prevent unwanted peeping in new dir --- migrations/setup_site_icons.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migrations/setup_site_icons.php b/migrations/setup_site_icons.php index b1274f0..538d86e 100644 --- a/migrations/setup_site_icons.php +++ b/migrations/setup_site_icons.php @@ -64,10 +64,11 @@ public function configure_site_icons() try { - // Create directory only if needed + // Create directory only if needed (give an empty index.htm too) if (!$filesystem->exists($new_icon_path)) { $filesystem->mkdir($new_icon_path); + $filesystem->touch($new_icon_path . '/index.htm'); } // Process icons From a46a71545e08d2f6b208bff9d5ca3a1252730686 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 10 Dec 2024 13:09:03 -0800 Subject: [PATCH 04/11] Improve unfound valid image text --- event/listener.php | 2 +- language/en/webpushnotifications_common_acp.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/event/listener.php b/event/listener.php index c557ccd..822c1bf 100644 --- a/event/listener.php +++ b/event/listener.php @@ -64,7 +64,7 @@ class listener implements EventSubscriberInterface * @param template $template Template object * @param user $user * @param manager $phpbb_notifications Notifications manager object - * @param $root_path + * @param string $root_path */ public function __construct(config $config, controller_helper $controller_helper, FastImageSize $imagesize, form_helper $form_helper, language $language, template $template, user $user, manager $phpbb_notifications, $root_path) { diff --git a/language/en/webpushnotifications_common_acp.php b/language/en/webpushnotifications_common_acp.php index c1ce66f..6617c4b 100644 --- a/language/en/webpushnotifications_common_acp.php +++ b/language/en/webpushnotifications_common_acp.php @@ -48,6 +48,6 @@ 'PWA_ICON_LARGE_EXPLAIN' => 'File name of a 512px x 512px PNG image. This file must be uploaded to your board’s ' . \phpbb\webpushnotifications\ext::PWA_ICON_DIR . ' directory.', 'PWA_ICON_SIZE_INVALID' => '“%s” does not have the correct image dimensions.', 'PWA_ICON_MIME_INVALID' => '“%s” must be a PNG image file.', - 'PWA_IMAGE_INVALID' => '“%s” does not appear to be a valid image file.', + 'PWA_IMAGE_INVALID' => '“%s” does not appear to be a valid image file. Verify the file name and location are correct.', 'PWA_IMAGE_NOT_PROVIDED' => '%s field must not be empty. All icon fields must contain an image.', ]); From 890e2a21cee48c6be7e0706d2ef8d00720a7b8dd Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 11 Dec 2024 08:33:39 -0800 Subject: [PATCH 05/11] Reword missing image text --- language/en/webpushnotifications_common_acp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language/en/webpushnotifications_common_acp.php b/language/en/webpushnotifications_common_acp.php index 6617c4b..ec5ed50 100644 --- a/language/en/webpushnotifications_common_acp.php +++ b/language/en/webpushnotifications_common_acp.php @@ -48,6 +48,6 @@ 'PWA_ICON_LARGE_EXPLAIN' => 'File name of a 512px x 512px PNG image. This file must be uploaded to your board’s ' . \phpbb\webpushnotifications\ext::PWA_ICON_DIR . ' directory.', 'PWA_ICON_SIZE_INVALID' => '“%s” does not have the correct image dimensions.', 'PWA_ICON_MIME_INVALID' => '“%s” must be a PNG image file.', - 'PWA_IMAGE_INVALID' => '“%s” does not appear to be a valid image file. Verify the file name and location are correct.', + 'PWA_IMAGE_INVALID' => '“%s” is not a valid image file or is missing from the expected location. Verify the file name and location are correct.', 'PWA_IMAGE_NOT_PROVIDED' => '%s field must not be empty. All icon fields must contain an image.', ]); From 732a9ad6c86be1375876af4a97f04365110ae425 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 11 Dec 2024 08:45:56 -0800 Subject: [PATCH 06/11] Make lang keys consistent --- event/listener.php | 4 ++-- language/en/webpushnotifications_common_acp.php | 4 ++-- language/ru/webpushnotifications_common_acp.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/event/listener.php b/event/listener.php index 822c1bf..9d1098e 100644 --- a/event/listener.php +++ b/event/listener.php @@ -267,7 +267,7 @@ public function validate_pwa_options($event) // Don't allow empty values, if one icon is set, both must be set. if (empty($value)) { - $this->add_error($event, 'PWA_IMAGE_NOT_PROVIDED', $this->language->lang(strtoupper($event['config_name']))); + $this->add_error($event, 'PWA_ICON_NOT_PROVIDED', $this->language->lang(strtoupper($event['config_name']))); return; } @@ -289,7 +289,7 @@ public function validate_pwa_options($event) } else { - $this->add_error($event, 'PWA_IMAGE_INVALID', $value); + $this->add_error($event, 'PWA_ICON_INVALID', $value); } break; } diff --git a/language/en/webpushnotifications_common_acp.php b/language/en/webpushnotifications_common_acp.php index ec5ed50..7cfb060 100644 --- a/language/en/webpushnotifications_common_acp.php +++ b/language/en/webpushnotifications_common_acp.php @@ -48,6 +48,6 @@ 'PWA_ICON_LARGE_EXPLAIN' => 'File name of a 512px x 512px PNG image. This file must be uploaded to your board’s ' . \phpbb\webpushnotifications\ext::PWA_ICON_DIR . ' directory.', 'PWA_ICON_SIZE_INVALID' => '“%s” does not have the correct image dimensions.', 'PWA_ICON_MIME_INVALID' => '“%s” must be a PNG image file.', - 'PWA_IMAGE_INVALID' => '“%s” is not a valid image file or is missing from the expected location. Verify the file name and location are correct.', - 'PWA_IMAGE_NOT_PROVIDED' => '%s field must not be empty. All icon fields must contain an image.', + 'PWA_ICON_INVALID' => '“%s” is not a valid image file or is missing from the expected location. Verify the file name and location are correct.', + 'PWA_ICON_NOT_PROVIDED' => '%s field must not be empty. All icon fields must contain an image.', ]); diff --git a/language/ru/webpushnotifications_common_acp.php b/language/ru/webpushnotifications_common_acp.php index e3e7e13..9153691 100644 --- a/language/ru/webpushnotifications_common_acp.php +++ b/language/ru/webpushnotifications_common_acp.php @@ -48,6 +48,6 @@ 'PWA_ICON_LARGE_EXPLAIN' => 'Имя файла изображения формата PNG размером 512 x 512 пикселей. Файл изображения должен быть загружен на сервер в папку ' . \phpbb\webpushnotifications\ext::PWA_ICON_DIR . '.', 'PWA_ICON_SIZE_INVALID' => 'Изображение «%s» имеет некорректные размеры.', 'PWA_ICON_MIME_INVALID' => 'Файл изображения «%s» должен иметь формат PNG.', - 'PWA_IMAGE_INVALID' => 'Файл «%s» не яввляется файлом изображения.', - 'PWA_IMAGE_NOT_PROVIDED' => 'Настройка «%s» не может быть пустой. Необходимо задать все пути к значкам для мобильного устройства.', + 'PWA_ICON_INVALID' => 'Файл «%s» не яввляется файлом изображения.', + 'PWA_ICON_NOT_PROVIDED' => 'Настройка «%s» не может быть пустой. Необходимо задать все пути к значкам для мобильного устройства.', ]); From d8a667dda62cb6dc1ab73a8150c49adfdca5aaca Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 11 Dec 2024 09:03:26 -0800 Subject: [PATCH 07/11] Improve code readability --- migrations/setup_site_icons.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/migrations/setup_site_icons.php b/migrations/setup_site_icons.php index 538d86e..4814c66 100644 --- a/migrations/setup_site_icons.php +++ b/migrations/setup_site_icons.php @@ -50,7 +50,7 @@ public function configure_site_icons() $filesystem = $this->get_filesystem(); $root_path = $this->container->getParameter('core.root_path'); $user = $this->container->get('user'); - $logger = $this->container->get('log'); + $log = $this->container->get('log'); // Prepare paths once $new_icon_path = $root_path . self::NEW_ICON_DIR; @@ -86,16 +86,21 @@ public function configure_site_icons() } // Set up a log message result - $message = $copied ? 'LOG_WEBPUSH_ICON_COPY_SUCCESS' : 'LOG_WEBPUSH_ICON_DIR_SUCCESS'; - $result = [$message => [self::NEW_ICON_DIR]]; + $result = [ + 'lang_key' => $copied ? 'LOG_WEBPUSH_ICON_COPY_SUCCESS' : 'LOG_WEBPUSH_ICON_DIR_SUCCESS', + 'params' => [$new_icon_path], + ]; } catch (filesystem_exception $e) { - $result = ['LOG_WEBPUSH_ICON_DIR_FAIL' => [$e->get_filename(), $e->getMessage()]]; + $result = [ + 'lang_key' => 'LOG_WEBPUSH_ICON_DIR_FAIL', + 'params' => [$e->get_filename(), $e->getMessage()] + ]; } // Log result - $logger->add('admin', $user->data['user_id'], $user->ip, key($result), false, current($result)); + $log->add('admin', $user->data['user_id'], $user->ip, $result['lang_key'], false, $result['params']); } /** From 7bfe60a23d12365e55a30364285bebc3b311b90b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 11 Dec 2024 11:17:08 -0800 Subject: [PATCH 08/11] Create new dir with more secure permissions --- migrations/setup_site_icons.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/setup_site_icons.php b/migrations/setup_site_icons.php index 4814c66..59fafa1 100644 --- a/migrations/setup_site_icons.php +++ b/migrations/setup_site_icons.php @@ -67,7 +67,7 @@ public function configure_site_icons() // Create directory only if needed (give an empty index.htm too) if (!$filesystem->exists($new_icon_path)) { - $filesystem->mkdir($new_icon_path); + $filesystem->mkdir($new_icon_path, 0755); $filesystem->touch($new_icon_path . '/index.htm'); } From 2df220d6c42c68fb205ab72d201eed8fd883e790 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 11 Dec 2024 11:28:29 -0800 Subject: [PATCH 09/11] Fix log message (accidentally changed param value) --- migrations/setup_site_icons.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/setup_site_icons.php b/migrations/setup_site_icons.php index 59fafa1..dd77d6c 100644 --- a/migrations/setup_site_icons.php +++ b/migrations/setup_site_icons.php @@ -88,7 +88,7 @@ public function configure_site_icons() // Set up a log message result $result = [ 'lang_key' => $copied ? 'LOG_WEBPUSH_ICON_COPY_SUCCESS' : 'LOG_WEBPUSH_ICON_DIR_SUCCESS', - 'params' => [$new_icon_path], + 'params' => [self::NEW_ICON_DIR], ]; } catch (filesystem_exception $e) From bef150347c3cfde9aedcb396c05a99d39a34d781 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 12 Dec 2024 18:02:59 -0800 Subject: [PATCH 10/11] Update language/ru/info_acp_webpushnotifications.php Co-authored-by: rxu --- language/ru/info_acp_webpushnotifications.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/language/ru/info_acp_webpushnotifications.php b/language/ru/info_acp_webpushnotifications.php index cbf4edc..b1c1564 100644 --- a/language/ru/info_acp_webpushnotifications.php +++ b/language/ru/info_acp_webpushnotifications.php @@ -44,7 +44,7 @@ 'LOG_CONFIG_WEBPUSH' => 'Изменены настройки браузерных push—уведомлений', 'LOG_WEBPUSH_MESSAGE_FAIL' => 'Не удалось отправить браузерное push—уведомление:
» %s', 'LOG_WEBPUSH_SUBSCRIPTION_REMOVED' => 'Удалена подписка на браузерные push—уведомления:
» %s', - 'LOG_WEBPUSH_ICON_DIR_FAIL' => 'Webpush Notifications could not migrate the following item in phpBB’s images directory:
» %1$s » %2$s', - 'LOG_WEBPUSH_ICON_DIR_SUCCESS' => 'Webpush Notifications added the following directory:
» %s', - 'LOG_WEBPUSH_ICON_COPY_SUCCESS' => 'Webpush Notifications copied existing PWA touch icons to:
» %s', + 'LOG_WEBPUSH_ICON_DIR_FAIL' => 'Не удалось перенести в папку изображений файл значка прогрессивного веб—приложения (PWA):
» %1$s » %2$s', + 'LOG_WEBPUSH_ICON_DIR_SUCCESS' => 'Папка изображений прогрессивного веб—приложения (PWA) успешно создана:
» %s', + 'LOG_WEBPUSH_ICON_COPY_SUCCESS' => 'Файлы значков прогрессивного веб—приложения (PWA) успешно скопированы в папку:
» %s', ]); From 6c87f5b0a3fbea272ed65827707d3a436dadb60b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 12 Dec 2024 18:03:07 -0800 Subject: [PATCH 11/11] Update language/ru/webpushnotifications_common_acp.php Co-authored-by: rxu --- language/ru/webpushnotifications_common_acp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/language/ru/webpushnotifications_common_acp.php b/language/ru/webpushnotifications_common_acp.php index 9153691..7107b4f 100644 --- a/language/ru/webpushnotifications_common_acp.php +++ b/language/ru/webpushnotifications_common_acp.php @@ -48,6 +48,6 @@ 'PWA_ICON_LARGE_EXPLAIN' => 'Имя файла изображения формата PNG размером 512 x 512 пикселей. Файл изображения должен быть загружен на сервер в папку ' . \phpbb\webpushnotifications\ext::PWA_ICON_DIR . '.', 'PWA_ICON_SIZE_INVALID' => 'Изображение «%s» имеет некорректные размеры.', 'PWA_ICON_MIME_INVALID' => 'Файл изображения «%s» должен иметь формат PNG.', - 'PWA_ICON_INVALID' => 'Файл «%s» не яввляется файлом изображения.', - 'PWA_ICON_NOT_PROVIDED' => 'Настройка «%s» не может быть пустой. Необходимо задать все пути к значкам для мобильного устройства.', + 'PWA_ICON_INVALID' => 'Файл «%s» не является файлом изображения или отсутствует по указанному пути. Проверьте правильность имени файла и его расположения.', + 'PWA_ICON_NOT_PROVIDED' => 'Настройка «%s» не может быть пустой. Необходимо задать все пути к файлам значков для мобильных устройств.', ]);