diff --git a/controller/admin_controller.php b/controller/admin_controller.php index 3ee03d3..4e5543a 100644 --- a/controller/admin_controller.php +++ b/controller/admin_controller.php @@ -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, ]); diff --git a/helper/helper.php b/helper/helper.php index 8038cd0..620af4a 100644 --- a/helper/helper.php +++ b/helper/helper.php @@ -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 @@ -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) { @@ -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 = []; @@ -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(); } diff --git a/migrations/m2_storage.php b/migrations/m2_storage.php index 24b8a6a..983582d 100644 --- a/migrations/m2_storage.php +++ b/migrations/m2_storage.php @@ -74,8 +74,6 @@ 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([]) @@ -83,12 +81,13 @@ public function add_tracked_files(): void ->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 { diff --git a/storage/storage.php b/storage/storage.php index 24a5a28..85d44ef 100644 --- a/storage/storage.php +++ b/storage/storage.php @@ -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); diff --git a/styles/all/template/event/overall_header_head_append.html b/styles/all/template/event/overall_header_head_append.html index 161badf..aa569f4 100644 --- a/styles/all/template/event/overall_header_head_append.html +++ b/styles/all/template/event/overall_header_head_append.html @@ -5,5 +5,9 @@ {% endfor %} -{% if PWA_THEME_COLOR %}{% endif %} -{% if PWA_BG_COLOR %}{% endif %} +{% if PWA_THEME_COLOR -%} + +{% endif %} +{% if PWA_BG_COLOR -%} + +{%- endif %}