Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions adm/style/acp_pwakit.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,40 @@ <h1>{{ lang('ACP_PWA_KIT_APP_ICONS') }}</h1>
<p>{{ lang('ACP_PWA_KIT_APP_ICONS_EXPLAIN') }}</p>
<fieldset>
<legend>{{ lang('ACP_PWA_KIT_LEGEND_ICONS') }}</legend>
<dl>
<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>
<dd>
<input type="file" accept="image/*" class="inputbox autowidth" id="pwa_upload" name="pwa_upload">
<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>
<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>
</dd>
</dl>
<dl>
<dt><label>{{ lang('ACP_PWA_KIT_ICONS') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_PWA_KIT_ICONS_EXPLAIN') }}</span></dt>
<dd>
{% for icon in PWA_KIT_ICONS %}
{% set iconName = icon.src|split('/')|last %}
<p style="position: relative;">
<span class="pwa-icon-container">
<img src="{{ icon.src }}" alt="{{ iconName|e('html') }}">
<button class="delete-btn" name="delete" value="{{ icon.src }}" title="{{ lang('ACP_PWA_IMG_DELETE') }}">
<span class="fa-stack fa-2x">
{{ Icon('font', 'circle', '', true, 'fa-stack-2x fa-inverse') }}
{{ Icon('font', 'trash-can', '', true, 'fa-stack-1x') }}
</span>
</button>
</span><br>
{{ iconName }}<br>{{ icon.sizes }}
</p>
{% else %}
{{ lang('ACP_PWA_KIT_NO_ICONS') }}
{% endfor %}
</dd>
</dl>
{% if S_STORAGE_LOCAL %}
<dl>
<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>
<dd>
<input type="file" accept="image/*" class="inputbox autowidth" id="pwa_upload" name="pwa_upload">
<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>
<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>
</dd>
</dl>
<dl>
<dt><label>{{ lang('ACP_PWA_KIT_ICONS') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_PWA_KIT_ICONS_EXPLAIN') }}</span></dt>
<dd>
{% for icon in PWA_KIT_ICONS %}
{% set iconName = icon.src|split('/')|last %}
<p style="position: relative;">
<span class="pwa-icon-container">
<img src="{{ icon.src }}" alt="{{ iconName|e('html') }}">
<button class="delete-btn" name="delete" value="{{ icon.src }}" title="{{ lang('ACP_PWA_IMG_DELETE') }}">
<span class="fa-stack fa-2x">
{{ Icon('font', 'circle', '', true, 'fa-stack-2x fa-inverse') }}
{{ Icon('font', 'trash-can', '', true, 'fa-stack-1x') }}
</span>
</button>
</span><br>
{{ iconName }}<br>{{ icon.sizes }}
</p>
{% else %}
{{ lang('ACP_PWA_KIT_NO_ICONS') }}
{% endfor %}
</dd>
</dl>
{% else %}
<p>{{ lang('ACP_PWA_STORAGE_INCOMPATIBLE', U_STORAGE_SETTINGS) }}</p>
{% endif %}
</fieldset>
</form>

Expand Down
1 change: 1 addition & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- '@phpbb.pwakit.storage'
- '@phpbb.pwakit.file_tracker'
- '@storage.helper'
- '@storage.provider_collection'
- '%core.root_path%'

phpbb.pwakit.upload:
Expand Down
3 changes: 3 additions & 0 deletions controller/admin_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ protected function display_settings(): void
'PWA_IMAGES_DIR' => $this->helper->get_storage_path(),
'PWA_KIT_ICONS' => $this->helper->get_icons($this->phpbb_root_path),
'STYLES' => $this->get_styles(),

'S_STORAGE_LOCAL' => $this->helper->is_storage_local(),

'U_BOARD_SETTINGS' => append_sid("{$this->phpbb_admin_path}index.$this->php_ext", 'i=acp_board&amp;mode=settings'),
'U_STORAGE_SETTINGS'=> append_sid("{$this->phpbb_admin_path}index.$this->php_ext", 'i=acp_storage&amp;mode=settings'),
'U_ACTION' => $this->u_action,
Expand Down
30 changes: 29 additions & 1 deletion helper/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
namespace phpbb\pwakit\helper;

use FastImageSize\FastImageSize;
use phpbb\di\service_collection;
use phpbb\exception\runtime_exception;
use phpbb\extension\manager as ext_manager;
use phpbb\pwakit\storage\file_tracker;
use phpbb\storage\storage;
use phpbb\storage\exception\storage_exception;
use phpbb\storage\helper as storage_helper;
use RuntimeException;

class helper
{
Expand All @@ -35,6 +37,9 @@ class helper
/** @var storage_helper */
protected storage_helper $storage_helper;

/** @var service_collection $provider_collection */
protected service_collection $provider_collection;

/** @var string */
protected string $root_path;

Expand All @@ -46,18 +51,41 @@ class helper
* @param storage $storage
* @param file_tracker $file_tracker
* @param storage_helper $storage_helper
* @param service_collection $provider_collection
* @param string $root_path
*/
public function __construct(ext_manager $extension_manager, FastImageSize $imagesize, storage $storage, file_tracker $file_tracker, storage_helper $storage_helper, string $root_path)
public function __construct(ext_manager $extension_manager, FastImageSize $imagesize, storage $storage, file_tracker $file_tracker, storage_helper $storage_helper, service_collection $provider_collection, string $root_path)
{
$this->extension_manager = $extension_manager;
$this->imagesize = $imagesize;
$this->storage = $storage;
$this->file_tracker = $file_tracker;
$this->storage_helper = $storage_helper;
$this->provider_collection = $provider_collection;
$this->root_path = $root_path;
}

/**
* Storage compatibility requires the local provider
*
* @return bool
*/
public function is_storage_local(): bool
{
try
{
$storage_name = $this->storage->get_name();
$provider_class = $this->storage_helper->get_current_provider($storage_name);
$current_provider = $this->provider_collection->get_by_class($provider_class);

return $current_provider && $current_provider->get_name() === 'local';
}
catch (RuntimeException)
{
return false;
}
}

/**
* Get the storage path for the current storage definition
*
Expand Down
1 change: 1 addition & 0 deletions language/en/acp_pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'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.',
'ACP_PWA_KIT_ICONS' => 'Web application icons',
'ACP_PWA_KIT_ICONS_EXPLAIN' => 'PNG image files that represent your web application. Multiple sizes are preferred for compatibility with various devices.',
'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>.',
'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.',
'ACP_PWA_IMG_UPLOAD' => 'Upload web application icons',
'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>.',
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/admin_controller_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protected function setUp(): void
$this->helper = $this->getMockBuilder(helper::class)
->disableOriginalConstructor()
->getMock();
$this->helper->method('is_storage_local')->willReturn(true);
$this->helper->method('get_storage_path')->willReturn('images/site_icons');
$this->helper->method('get_icons')->willReturn([]);

Expand Down Expand Up @@ -239,6 +240,7 @@ public function test_display_settings($configs, $expected)
'PWA_IMAGES_DIR' => 'images/site_icons',
'PWA_KIT_ICONS' => [],
'STYLES' => $expected_style_data,
'S_STORAGE_LOCAL' => true,
'U_BOARD_SETTINGS' => "{$this->phpbb_root_path}adm/index.php?i=acp_board&amp;mode=settings",
'U_STORAGE_SETTINGS'=> "{$this->phpbb_root_path}adm/index.php?i=acp_storage&amp;mode=settings",
'U_ACTION' => '',
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ protected function setUp(): void
$provider_collection,
$adapter_collection
),
$provider_collection,
$phpbb_root_path
);

Expand All @@ -154,6 +155,17 @@ public function test_get_tracked_files()
$this->assertEquals(['foo.png'], $this->file_tracker->get_tracked_files());
}

public function test_is_storage_local()
{
$this->assertTrue($this->helper->is_storage_local());
}

public function test_is_storage_not_local()
{
$this->config->set('storage\phpbb_pwakit\provider', 'foo');
$this->assertFalse($this->helper->is_storage_local());
}

public function test_get_storage_path()
{
$this->assertEquals($this->storage_path, $this->helper->get_storage_path());
Expand Down