Skip to content

Commit

Permalink
Merge pull request #8 from iMattPro/fixes
Browse files Browse the repository at this point in the history
Code improvements
  • Loading branch information
iMattPro authored Dec 28, 2024
2 parents 8342398 + 8d4cc39 commit fea60da
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion controller/admin_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function display_settings(): void
'SITE_NAME_SHORT' => $this->config->offsetGet('sitename_short'),
'PWA_BG_COLOR' => $this->config->offsetGet('pwa_bg_color'),
'PWA_THEME_COLOR' => $this->config->offsetGet('pwa_theme_color'),
'PWA_IMAGES_DIR' => $this->config->offsetGet('storage\\phpbb_pwakit\\config\\path'),
'PWA_IMAGES_DIR' => $this->helper->get_storage_path(),
'PWA_KIT_ICONS' => $this->helper->get_icons($this->phpbb_root_path),
'U_ACTION' => $this->u_action,
]);
Expand Down
20 changes: 15 additions & 5 deletions helper/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ public function __construct(ext_manager $extension_manager, FastImageSize $image
}

/**
* Get an array of icons (icons are cached for an hour)
* Get the storage path for the current storage definition
*
* @return string
*/
public function get_storage_path(): string
{
return $this->storage_helper->get_current_definition($this->storage->get_name(), 'path');
}

/**
* Get an array of icons
*
* @param string $use_path Optional path to use for icons, for example ./
* @return array Array of icons
Expand All @@ -70,7 +80,7 @@ public function get_icons(string $use_path = ''): array
*/
public function resync_icons(): void
{
$path = $this->storage_helper->get_current_definition('phpbb_pwakit', 'path') . '/';
$path = $this->get_storage_path() . '/';

// Get both arrays at once and pre-process paths
$untracked_files = array_map(static function($file) use ($path) {
Expand Down Expand Up @@ -111,7 +121,7 @@ public function resync_icons(): void
*/
protected function get_stored_images(): array
{
$path = $this->storage_helper->get_current_definition('phpbb_pwakit', 'path');
$path = $this->get_storage_path();
$images = $this->storage->get_tracked_files();

$result = [];
Expand Down Expand Up @@ -140,8 +150,8 @@ protected function get_images(): array
$finder = $this->extension_manager->get_finder();
$images = $finder
->set_extensions([])
->suffix(".png")
->core_path($this->storage_helper->get_current_definition('phpbb_pwakit', 'path') . '/')
->suffix('.png')
->core_path($this->get_storage_path() . '/')
->find();
}

Expand Down
9 changes: 4 additions & 5 deletions migrations/m2_storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,20 @@ public function add_tracked_files(): void
$this->tables['storage']
);

$path = $this->phpbb_root_path . ext::PWA_ICON_DIR . '/';

// Get all files at once
$files = $extension_manager->get_finder()
->set_extensions([])
->suffix('.png')
->core_path(ext::PWA_ICON_DIR . '/')
->get_files();

$files_to_track = array_map(static function($image) use ($path) {
return str_replace($path, '', $image);
// Extract just the file names
$files = array_map(static function($image) {
return basename($image);
}, $files);

// Track each file
foreach ($files_to_track as $file)
foreach ($files as $file)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions storage/storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
class storage extends \phpbb\storage\storage
{
/**
* Gets tracked files in the storage table for phpbb_pwakit stuff
* Gets tracked files in the storage table
*
* @return array
*/
public function get_tracked_files(): array
{
$sql = 'SELECT file_path FROM ' . $this->storage_table . "
WHERE storage = 'phpbb_pwakit'
WHERE storage = '" . $this->db->sql_escape($this->get_name()) . "'
ORDER BY file_path";
$result = $this->db->sql_query($sql);
$files = $this->db->sql_fetchrowset($result);
Expand Down
8 changes: 6 additions & 2 deletions styles/all/template/event/overall_header_head_append.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
<link rel="apple-touch-icon" href="{{ ROOT_PATH ~ touchIcon }}">
{% endfor %}

{% if PWA_THEME_COLOR %}<meta name="theme-color" content="{{ PWA_THEME_COLOR }}">{% endif %}
{% if PWA_BG_COLOR %}<meta name="background-color" content="{{ PWA_BG_COLOR }}">{% endif %}
{% if PWA_THEME_COLOR -%}
<meta name="theme-color" content="{{ PWA_THEME_COLOR }}">
{% endif %}
{% if PWA_BG_COLOR -%}
<meta name="background-color" content="{{ PWA_BG_COLOR }}">
{%- endif %}

0 comments on commit fea60da

Please sign in to comment.