Skip to content

Commit

Permalink
Merge pull request #12 from iMattPro/delete-icons
Browse files Browse the repository at this point in the history
Miscellaneous improvements
iMattPro authored Dec 30, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 293c1e0 + 8898316 commit ffa7482
Showing 5 changed files with 42 additions and 10 deletions.
28 changes: 26 additions & 2 deletions controller/admin_controller.php
Original file line number Diff line number Diff line change
@@ -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(),
@@ -253,7 +253,7 @@ public function upload(): void
return;
}

$this->success('CONFIG_UPDATED');
$this->success('ACP_PWA_IMG_UPLOAD_SUCCESS');
}

/**
@@ -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
*
12 changes: 6 additions & 6 deletions event/main_listener.php
Original file line number Diff line number Diff line change
@@ -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))
{
1 change: 1 addition & 0 deletions language/en/acp_pwa.php
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@
'ACP_PWA_KIT_NO_ICONS' => 'No icons are available. Click <strong>Upload</strong> to add new icons or click <strong>Resync</strong> 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 <samp>%s</samp>.',
'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',
7 changes: 7 additions & 0 deletions styles/all/theme/acp.css
Original file line number Diff line number Diff line change
@@ -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 {
4 changes: 2 additions & 2 deletions tests/unit/event_listener_test.php
Original file line number Diff line number Diff line change
@@ -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',
],
],
[

0 comments on commit ffa7482

Please sign in to comment.