Merge pull request #6669 from iMattPro/ticket/17363

[ticket/17363] Add web app manifest
This commit is contained in:
Marc Alexander 2024-07-03 22:04:46 +02:00 committed by GitHub
commit f0deb16b0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 166 additions and 0 deletions

View file

@ -157,6 +157,15 @@ services:
- '%core.php_ext%' - '%core.php_ext%'
- '%tables.log%' - '%tables.log%'
manifest.controller:
class: phpbb\manifest
arguments:
- '@config'
- '@language'
- '@path_helper'
- '@event_dispatcher'
- '@user'
path_helper: path_helper:
class: phpbb\path_helper class: phpbb\path_helper
arguments: arguments:

View file

@ -24,6 +24,10 @@ phpbb_help_routing:
resource: help.yml resource: help.yml
prefix: /help prefix: /help
phpbb_manifest_controller:
path: /manifest
defaults: { _controller: manifest.controller:handle }
phpbb_mention_controller: phpbb_mention_controller:
path: /mention path: /mention
methods: [GET, POST] methods: [GET, POST]

View file

@ -78,6 +78,7 @@ class acp_board
'site_home_url' => array('lang' => 'SITE_HOME_URL', 'validate' => 'url', 'type' => 'url:40:255', 'explain' => true), 'site_home_url' => array('lang' => 'SITE_HOME_URL', 'validate' => 'url', 'type' => 'url:40:255', 'explain' => true),
'site_home_text' => array('lang' => 'SITE_HOME_TEXT', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true), 'site_home_text' => array('lang' => 'SITE_HOME_TEXT', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true),
'board_index_text' => array('lang' => 'BOARD_INDEX_TEXT', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true), 'board_index_text' => array('lang' => 'BOARD_INDEX_TEXT', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true),
'sitename_short' => array('lang' => 'SITE_NAME_SHORT', 'validate' => 'string', 'type' => 'text:40:12', 'explain' => true),
'board_disable' => array('lang' => 'DISABLE_BOARD', 'validate' => 'bool', 'type' => 'custom', 'method' => 'board_disable', 'explain' => true), 'board_disable' => array('lang' => 'DISABLE_BOARD', 'validate' => 'bool', 'type' => 'custom', 'method' => 'board_disable', 'explain' => true),
'board_disable_msg' => false, 'board_disable_msg' => false,
'board_disable_access' => array('lang' => 'DISABLE_BOARD_ACCESS', 'validate' => 'int', 'type' => 'select', 'method' => 'board_disable_access', 'explain' => true), 'board_disable_access' => array('lang' => 'DISABLE_BOARD_ACCESS', 'validate' => 'int', 'type' => 'select', 'method' => 'board_disable_access', 'explain' => true),
@ -593,6 +594,7 @@ class acp_board
// Array of emoji-enabled configurations // Array of emoji-enabled configurations
$config_name_ary = [ $config_name_ary = [
'sitename', 'sitename',
'sitename_short',
'site_desc', 'site_desc',
'site_home_text', 'site_home_text',
'board_index_text', 'board_index_text',

View file

@ -3855,6 +3855,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
'UA_PRIVACY' => addslashes(append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=privacy')), 'UA_PRIVACY' => addslashes(append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=privacy')),
'U_RESTORE_PERMISSIONS' => ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm') : '', 'U_RESTORE_PERMISSIONS' => ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm') : '',
'U_FEED' => $controller_helper->route('phpbb_feed_index'), 'U_FEED' => $controller_helper->route('phpbb_feed_index'),
'U_MANIFEST' => $controller_helper->route('phpbb_manifest_controller'),
'S_ALLOW_MENTIONS' => ($config['allow_mentions'] && $auth->acl_get('u_mention') && (empty($forum_id) || $auth->acl_get('f_mention', $forum_id))) ? true : false, 'S_ALLOW_MENTIONS' => ($config['allow_mentions'] && $auth->acl_get('u_mention') && (empty($forum_id) || $auth->acl_get('f_mention', $forum_id))) ? true : false,
'S_MENTION_NAMES_LIMIT' => $config['mention_names_limit'], 'S_MENTION_NAMES_LIMIT' => $config['mention_names_limit'],

View file

@ -284,6 +284,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('site_desc', '{L_CO
INSERT INTO phpbb_config (config_name, config_value) VALUES ('site_home_text', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('site_home_text', '');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('site_home_url', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('site_home_url', '');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('sitename', '{L_CONFIG_SITENAME}'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('sitename', '{L_CONFIG_SITENAME}');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('sitename_short', '');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('smilies_path', 'images/smilies'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('smilies_path', 'images/smilies');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('smilies_per_page', '50'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('smilies_per_page', '50');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('smtp_allow_self_signed', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('smtp_allow_self_signed', '0');

View file

@ -69,6 +69,8 @@ $lang = array_merge($lang, array(
'SITE_HOME_URL' => 'Main website URL', 'SITE_HOME_URL' => 'Main website URL',
'SITE_HOME_URL_EXPLAIN' => 'If specified, a link to this URL will be prepended to your boards breadcrumbs and the board logo will link to this URL instead of the forum index. An absolute URL is required, e.g. <samp>http://www.phpbb.com</samp>.', 'SITE_HOME_URL_EXPLAIN' => 'If specified, a link to this URL will be prepended to your boards breadcrumbs and the board logo will link to this URL instead of the forum index. An absolute URL is required, e.g. <samp>http://www.phpbb.com</samp>.',
'SITE_NAME' => 'Site name', 'SITE_NAME' => 'Site name',
'SITE_NAME_SHORT' => 'Short site name',
'SITE_NAME_SHORT_EXPLAIN' => 'Short name will be used if your site is added to a mobile devices home screen. It can not exceed 12 characters (Emoji is supported).',
'SYSTEM_TIMEZONE' => 'Guest timezone', 'SYSTEM_TIMEZONE' => 'Guest timezone',
'SYSTEM_TIMEZONE_EXPLAIN' => 'Timezone to use for displaying times to users who are not logged in (guests, bots). Logged in users set their timezone during registration and can change it in their user control panel.', 'SYSTEM_TIMEZONE_EXPLAIN' => 'Timezone to use for displaying times to users who are not logged in (guests, bots). Logged in users set their timezone during registration and can change it in their user control panel.',
'WARNINGS_EXPIRE' => 'Warning duration', 'WARNINGS_EXPIRE' => 'Warning duration',

95
phpBB/phpbb/manifest.php Normal file
View file

@ -0,0 +1,95 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb;
use phpbb\config\config;
use phpbb\event\dispatcher_interface;
use phpbb\exception\http_exception;
use phpbb\language\language;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
class manifest
{
/** @var config */
protected $config;
/** @var language */
protected $language;
/** @var path_helper */
protected $path_helper;
/** @var dispatcher_interface */
protected $phpbb_dispatcher;
/** @var user */
protected $user;
/**
* Constructor for manifest controller
*
* @param config $config
* @param language $language
* @param path_helper $path_helper
* @param dispatcher_interface $phpbb_dispatcher
* @param user $user
*/
public function __construct(config $config, language $language, path_helper $path_helper, dispatcher_interface $phpbb_dispatcher, user $user)
{
$this->config = $config;
$this->path_helper = $path_helper;
$this->phpbb_dispatcher = $phpbb_dispatcher;
$this->language = $language;
$this->user = $user;
}
/**
* Handle creation of a manifest json file for progressive web-app support
*
* @return JsonResponse
*/
public function handle(): JsonResponse
{
if ($this->user->data['is_bot'])
{
throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION');
}
$board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path();
$manifest = [
'name' => $this->config['sitename'],
'short_name' => $this->config['sitename_short'] ?: substr($this->config['sitename'], 0, 12),
'display' => 'standalone',
'orientation' => 'portrait',
'dir' => $this->language->lang('DIRECTION'),
'start_url' => $board_path,
'scope' => $board_path,
];
/**
* Event to modify manifest data before it is outputted
*
* @event core.modify_manifest
* @var array manifest Array of manifest members
* @var string board_path Path to the board root
* @since 4.0.0-a1
*/
$vars = array('manifest', 'board_path');
extract($this->phpbb_dispatcher->trigger_event('core.modify_manifest', compact($vars)));
return new JsonResponse($manifest);
}
}

View file

@ -4,6 +4,9 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="{{ SITENAME }}">
{META} {META}
<title><!-- IF UNREAD_NOTIFICATIONS_COUNT -->({UNREAD_NOTIFICATIONS_COUNT}) <!-- ENDIF --><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --></title> <title><!-- IF UNREAD_NOTIFICATIONS_COUNT -->({UNREAD_NOTIFICATIONS_COUNT}) <!-- ENDIF --><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --></title>
@ -57,6 +60,8 @@
<link href="{T_ASSETS_PATH}/cookieconsent/cookieconsent.min.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet"> <link href="{T_ASSETS_PATH}/cookieconsent/cookieconsent.min.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet">
<!-- ENDIF --> <!-- ENDIF -->
<link rel="manifest" href="{{ U_MANIFEST }}">
<!-- EVENT overall_header_head_append --> <!-- EVENT overall_header_head_append -->
{$STYLESHEETS} {$STYLESHEETS}

View file

@ -0,0 +1,47 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
/**
* @group functional
*/
class phpbb_functional_manifest_test extends phpbb_functional_test_case
{
public function test_manifest()
{
$expected = [
'name' => 'yourdomain.com',
'short_name' => 'yourdomain',
'display' => 'standalone',
'orientation' => 'portrait',
'dir' => 'ltr',
'start_url' => '/',
'scope' => '/',
];
$this->login();
$this->admin_login();
$crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid);
$form_data = [
'config[sitename]' => $expected['name'],
'config[sitename_short]' => $expected['short_name'],
];
$form = $crawler->selectButton('submit')->form($form_data);
$crawler = self::submit($form);
$this->assertStringContainsString($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
self::request('GET', 'app.php/manifest', [], false);
$this->assertEquals(json_encode($expected), self::get_content());
}
}