Skip to content

Commit e3e4255

Browse files
committed
Make icon management dependent on local storage provider
1 parent 672e39b commit e3e4255

File tree

6 files changed

+55
-30
lines changed

6 files changed

+55
-30
lines changed

adm/style/acp_pwakit.html

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,36 +69,40 @@ <h1>{{ lang('ACP_PWA_KIT_APP_ICONS') }}</h1>
6969
<p>{{ lang('ACP_PWA_KIT_APP_ICONS_EXPLAIN') }}</p>
7070
<fieldset>
7171
<legend>{{ lang('ACP_PWA_KIT_LEGEND_ICONS') }}</legend>
72-
<dl>
73-
<dt><label for="pwa_upload">{{ lang('ACP_PWA_IMG_UPLOAD') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_PWA_IMG_UPLOAD_EXPLAIN', PWA_IMAGES_DIR, U_STORAGE_SETTINGS) }}</span></dt>
74-
<dd>
75-
<input type="file" accept="image/*" class="inputbox autowidth" id="pwa_upload" name="pwa_upload">
76-
<button class="button2 pwakit-button" id="upload" name="upload" value="{{ lang('ACP_PWA_IMG_UPLOAD_BTN') }}">{{ Icon('font', 'upload', lang('ACP_PWA_IMG_UPLOAD_BTN')) }}</button>
77-
<button class="button2 pwakit-button" id="resync" name="resync" value="{{ lang('ACP_PWA_IMG_RESYNC_BTN') }}">{{ Icon('font', 'sync', lang('ACP_PWA_IMG_RESYNC_BTN')) }}</button>
78-
</dd>
79-
</dl>
80-
<dl>
81-
<dt><label>{{ lang('ACP_PWA_KIT_ICONS') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_PWA_KIT_ICONS_EXPLAIN') }}</span></dt>
82-
<dd>
83-
{% for icon in PWA_KIT_ICONS %}
84-
{% set iconName = icon.src|split('/')|last %}
85-
<p style="position: relative;">
86-
<span class="pwa-icon-container">
87-
<img src="{{ icon.src }}" alt="{{ iconName|e("html") }}">
88-
<button class="delete-btn" name="delete" value="{{ icon.src }}" title="{{ lang('ACP_PWA_IMG_DELETE') }}">
89-
<span class="fa-stack fa-2x">
90-
{{ Icon('font', 'circle', '', true, 'fa-stack-2x fa-inverse') }}
91-
{{ Icon('font', 'trash-can', '', true, 'fa-stack-1x') }}
92-
</span>
93-
</button>
94-
</span><br>
95-
{{ iconName }}<br>{{ icon.sizes }}
96-
</p>
97-
{% else %}
98-
{{ lang('ACP_PWA_KIT_NO_ICONS') }}
99-
{% endfor %}
100-
</dd>
101-
</dl>
72+
{% if S_STORAGE_LOCAL %}
73+
<dl>
74+
<dt><label for="pwa_upload">{{ lang('ACP_PWA_IMG_UPLOAD') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_PWA_IMG_UPLOAD_EXPLAIN', PWA_IMAGES_DIR, U_STORAGE_SETTINGS) }}</span></dt>
75+
<dd>
76+
<input type="file" accept="image/*" class="inputbox autowidth" id="pwa_upload" name="pwa_upload">
77+
<button class="button2 pwakit-button" id="upload" name="upload" value="{{ lang('ACP_PWA_IMG_UPLOAD_BTN') }}">{{ Icon('font', 'upload', lang('ACP_PWA_IMG_UPLOAD_BTN')) }}</button>
78+
<button class="button2 pwakit-button" id="resync" name="resync" value="{{ lang('ACP_PWA_IMG_RESYNC_BTN') }}">{{ Icon('font', 'sync', lang('ACP_PWA_IMG_RESYNC_BTN')) }}</button>
79+
</dd>
80+
</dl>
81+
<dl>
82+
<dt><label>{{ lang('ACP_PWA_KIT_ICONS') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_PWA_KIT_ICONS_EXPLAIN') }}</span></dt>
83+
<dd>
84+
{% for icon in PWA_KIT_ICONS %}
85+
{% set iconName = icon.src|split('/')|last %}
86+
<p style="position: relative;">
87+
<span class="pwa-icon-container">
88+
<img src="{{ icon.src }}" alt="{{ iconName|e("html") }}">
89+
<button class="delete-btn" name="delete" value="{{ icon.src }}" title="{{ lang('ACP_PWA_IMG_DELETE') }}">
90+
<span class="fa-stack fa-2x">
91+
{{ Icon('font', 'circle', '', true, 'fa-stack-2x fa-inverse') }}
92+
{{ Icon('font', 'trash-can', '', true, 'fa-stack-1x') }}
93+
</span>
94+
</button>
95+
</span><br>
96+
{{ iconName }}<br>{{ icon.sizes }}
97+
</p>
98+
{% else %}
99+
{{ lang('ACP_PWA_KIT_NO_ICONS') }}
100+
{% endfor %}
101+
</dd>
102+
</dl>
103+
{% else %}
104+
<p>{{ lang('ACP_PWA_STORAGE_INCOMPATIBLE', U_STORAGE_SETTINGS) }}</p>
105+
{% endif %}
102106
</fieldset>
103107
</form>
104108

controller/admin_controller.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ protected function display_settings(): void
189189
'PWA_IMAGES_DIR' => $this->helper->get_storage_path(),
190190
'PWA_KIT_ICONS' => $this->helper->get_icons($this->phpbb_root_path),
191191
'STYLES' => $this->get_styles(),
192+
193+
'S_STORAGE_LOCAL' => $this->helper->is_storage_compatible(),
194+
192195
'U_BOARD_SETTINGS' => append_sid("{$this->phpbb_admin_path}index.$this->php_ext", 'i=acp_board&amp;mode=settings'),
193196
'U_STORAGE_SETTINGS'=> append_sid("{$this->phpbb_admin_path}index.$this->php_ext", 'i=acp_storage&amp;mode=settings'),
194197
'U_ACTION' => $this->u_action,

helper/helper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ public function __construct(ext_manager $extension_manager, FastImageSize $image
5252
$this->root_path = $root_path;
5353
}
5454

55+
/**
56+
* Storage compatibility requires the local provider
57+
*
58+
* @return bool
59+
*/
60+
public function is_storage_compatible(): bool
61+
{
62+
return str_ends_with($this->storage_helper->get_current_provider($this->storage->get_name()), '\local');
63+
}
64+
5565
/**
5666
* Get the storage path for the current storage definition
5767
*

language/en/acp_pwa.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
'ACP_PWA_KIT_APP_ICONS_EXPLAIN' => 'Used to specify the touch-icon for your web application. This icon will be used when your web application is added to the home screen. Multiple sizes are preferred for compatibility with various devices. Note that when adding or removing icons, you may need to clear your web app/browser cache to see them update.',
5555
'ACP_PWA_KIT_ICONS' => 'Web application icons',
5656
'ACP_PWA_KIT_ICONS_EXPLAIN' => 'PNG image files that represent your web application. Multiple sizes are preferred for compatibility with various devices.',
57+
'ACP_PWA_STORAGE_INCOMPATIBLE' => 'To manage icons you must set <strong>Web app icons storage</strong> to <strong>Local</strong> in <a href="%s">General » Storage settings</a>.',
5758
'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. Recommended PNG sizes include 180x180, 192x192 and 512x512.',
5859
'ACP_PWA_IMG_UPLOAD' => 'Upload web application icons',
5960
'ACP_PWA_IMG_UPLOAD_EXPLAIN' => 'Upload PNG images. Images are currently being stored in <samp>%1$s</samp>. This can be changed at any time to another location in <a href="%2$s">General » Storage settings</a>.',

tests/unit/admin_controller_test.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ protected function setUp(): void
9191
$this->helper = $this->getMockBuilder(helper::class)
9292
->disableOriginalConstructor()
9393
->getMock();
94+
$this->helper->method('is_storage_compatible')->willReturn(true);
9495
$this->helper->method('get_storage_path')->willReturn('images/site_icons');
9596
$this->helper->method('get_icons')->willReturn([]);
9697

@@ -247,6 +248,7 @@ public function test_display_settings($configs, $expected)
247248
'PWA_IMAGES_DIR' => 'images/site_icons',
248249
'PWA_KIT_ICONS' => [],
249250
'STYLES' => $expected_style_data,
251+
'S_STORAGE_LOCAL' => true,
250252
'U_BOARD_SETTINGS' => "{$this->phpbb_root_path}adm/index.php?i=acp_board&amp;mode=settings",
251253
'U_STORAGE_SETTINGS'=> "{$this->phpbb_root_path}adm/index.php?i=acp_storage&amp;mode=settings",
252254
'U_ACTION' => '',

tests/unit/helper_test.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ public function test_get_tracked_files()
153153
$this->assertEquals(['foo.png'], $this->storage->get_tracked_files());
154154
}
155155

156+
public function test_is_storage_compatible()
157+
{
158+
$this->assertTrue($this->helper->is_storage_compatible());
159+
}
160+
156161
public function test_get_storage_path()
157162
{
158163
$this->assertEquals($this->storage_path, $this->helper->get_storage_path());

0 commit comments

Comments
 (0)