From 5c7cd99d1c52d0e6ca8b337cd50a44e3fa817916 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 30 Dec 2024 09:24:00 -0800 Subject: [PATCH 1/4] Have a way to show empty short name --- controller/admin_controller.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/controller/admin_controller.php b/controller/admin_controller.php index 3ad9919..e3683ea 100644 --- a/controller/admin_controller.php +++ b/controller/admin_controller.php @@ -149,7 +149,7 @@ public function display_settings(): void { $this->template->assign_vars([ 'SITE_NAME' => $this->config->offsetGet('sitename'), - 'SITE_NAME_SHORT' => $this->config->offsetGet('sitename_short'), + 'SITE_NAME_SHORT' => $this->config->offsetGet('sitename_short') ?: $this->trim_name($this->config->offsetGet('sitename'), 0, 12), 'PWA_BG_COLOR' => $this->config->offsetGet('pwa_bg_color'), 'PWA_THEME_COLOR' => $this->config->offsetGet('pwa_theme_color'), 'PWA_IMAGES_DIR' => $this->helper->get_storage_path(), @@ -288,6 +288,30 @@ public function delete(): void } } + /** + * Trim name, accounting for multibyte and emoji chars + * + * @param string $string + * @param int $start + * @param int $length + * @return string + */ + protected function trim_name(string $string, int $start, int $length): string + { + // Check if string contains any HTML entities + if (str_contains($string, '&') && preg_match('/&[#a-zA-Z0-9]+;/', $string)) + { + $decoded = html_entity_decode($string, ENT_QUOTES | ENT_HTML5, 'UTF-8'); + + $trimmed = utf8_substr($decoded, $start, $length); + + return htmlspecialchars($trimmed, ENT_QUOTES | ENT_HTML5, 'UTF-8'); + } + + // If no HTML entities, just trim the string directly + return utf8_substr($string, $start, $length); + } + /** * Trigger success message * From d537d3bd2576c92c8edbaebe03e0e0a551e746f3 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 30 Dec 2024 09:24:27 -0800 Subject: [PATCH 2/4] Improve appearance of color pickers --- styles/all/theme/acp.css | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/styles/all/theme/acp.css b/styles/all/theme/acp.css index 90d38e4..d2c80b5 100644 --- a/styles/all/theme/acp.css +++ b/styles/all/theme/acp.css @@ -32,8 +32,15 @@ input[type="color"] { background-color: transparent; border: solid 1px #d3d3d3; border-radius: 2px; + width: 48px; + height: 24px; padding: 0; cursor: pointer; + -webkit-appearance: none; +} + +input[type="color"]::-webkit-color-swatch-wrapper { + padding: 0; } .delete-btn-container { From 36a362d690c5e6cb8c7c690e88d99b4f0ca0112f Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 30 Dec 2024 09:24:48 -0800 Subject: [PATCH 3/4] Improve image upload message --- controller/admin_controller.php | 2 +- language/en/acp_pwa.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/controller/admin_controller.php b/controller/admin_controller.php index e3683ea..c5889d9 100644 --- a/controller/admin_controller.php +++ b/controller/admin_controller.php @@ -253,7 +253,7 @@ public function upload(): void return; } - $this->success('CONFIG_UPDATED'); + $this->success('ACP_PWA_IMG_UPLOAD_SUCCESS'); } /** diff --git a/language/en/acp_pwa.php b/language/en/acp_pwa.php index b50e11f..ebdcbaf 100644 --- a/language/en/acp_pwa.php +++ b/language/en/acp_pwa.php @@ -53,6 +53,7 @@ 'ACP_PWA_KIT_NO_ICONS' => 'No icons are available. Click Upload to add new icons or click Resync to find existing icons that were previously uploaded.', 'ACP_PWA_IMG_UPLOAD' => 'Upload web application icons', 'ACP_PWA_IMG_UPLOAD_EXPLAIN' => 'Upload PNG images to %s.', + 'ACP_PWA_IMG_UPLOAD_SUCCESS' => 'Image uploaded successfully.', 'ACP_PWA_IMG_DELETE' => 'Delete image', 'ACP_PWA_IMG_DELETE_CONFIRM' => 'Are you sure you want to delete this image?', 'ACP_PWA_IMG_DELETE_ERROR' => 'An error occurred while trying to remove the image. %s', From 889831664348c497789f87ff783325482eb3ab7f Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 30 Dec 2024 09:25:18 -0800 Subject: [PATCH 4/4] Ensure colors come before icons in the manifest, just for looks --- event/main_listener.php | 12 ++++++------ tests/unit/event_listener_test.php | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/event/main_listener.php b/event/main_listener.php index 97e1c19..a1087bf 100644 --- a/event/main_listener.php +++ b/event/main_listener.php @@ -77,12 +77,6 @@ public function manifest_updates(data $event): void // Prepare manifest updates array $manifest_updates = []; - // Add icons if available - if (!empty($icons = $this->pwa_helper->get_icons($event['board_path']))) - { - $manifest_updates['icons'] = $icons; - } - // Add theme and background colors if configured if (!empty($this->config['pwa_theme_color'])) { @@ -93,6 +87,12 @@ public function manifest_updates(data $event): void $manifest_updates['background_color'] = $this->config['pwa_bg_color']; } + // Add icons if available + if (!empty($icons = $this->pwa_helper->get_icons($event['board_path']))) + { + $manifest_updates['icons'] = $icons; + } + // Update manifest only if there are changes if (!empty($manifest_updates)) { diff --git a/tests/unit/event_listener_test.php b/tests/unit/event_listener_test.php index 47268c3..1f345da 100644 --- a/tests/unit/event_listener_test.php +++ b/tests/unit/event_listener_test.php @@ -180,6 +180,8 @@ public function manifest_updates_test_data(): array 'pwa_bg_color' => '#000000', ], [ + 'theme_color' => '#ffffff', + 'background_color' => '#000000', 'icons' => [ [ 'src' => './../images/site_icons/touch-icon-192.png', @@ -192,8 +194,6 @@ public function manifest_updates_test_data(): array 'type' => 'image/png' ] ], - 'theme_color' => '#ffffff', - 'background_color' => '#000000', ], ], [