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..827caa8 100644
--- a/language/en/info_acp_webpushnotifications.php
+++ b/language/en/info_acp_webpushnotifications.php
@@ -42,6 +42,8 @@
'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:
» %s',
+ 'LOG_WEBPUSH_ICON_DIR_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..c1badc4 100644
--- a/language/ru/info_acp_webpushnotifications.php
+++ b/language/ru/info_acp_webpushnotifications.php
@@ -42,6 +42,8 @@
'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:
» %s',
+ 'LOG_WEBPUSH_ICON_DIR_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..1b90ab6
--- /dev/null
+++ b/migrations/move_site_icons.php
@@ -0,0 +1,101 @@
+
+ * @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()
+ {
+ $filesystem = $this->get_filesystem();
+ $root_path = $this->container->getParameter('core.root_path');
+
+ $user = $this->container->get('user');
+
+ $small_icon = $this->config->offsetGet('pwa_icon_small');
+ $large_icon = $this->config->offsetGet('pwa_icon_large');
+
+ try
+ {
+ // Create the new site_icons directory
+ if (!$filesystem->exists($root_path . self::NEW_ICON_DIR))
+ {
+ $filesystem->mkdir($root_path . self::NEW_ICON_DIR);
+ }
+
+ // Copy existing PWA icons to the new site_icons directory
+ foreach ([$small_icon, $large_icon] as $icon)
+ {
+ if (!$filesystem->exists($root_path . self::OLD_ICON_DIR . '/' . $icon))
+ {
+ continue;
+ }
+
+ $filesystem->copy(
+ $root_path . self::OLD_ICON_DIR . '/' . $icon,
+ $root_path . self::NEW_ICON_DIR . '/' . $icon
+ );
+ }
+
+ $this->container->get('log')->add('admin', $user->data['user_id'], $user->ip, 'LOG_WEBPUSH_ICON_DIR_SUCCESS', false, [self::NEW_ICON_DIR]);
+ }
+ catch (filesystem_exception $e)
+ {
+ $this->container->get('log')->add('critical', $user->data['user_id'], $user->ip, 'LOG_WEBPUSH_ICON_DIR_FAIL', false, [$e->get_filename()]);
+ }
+ }
+
+ /**
+ * 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();