From d651cccc76244d16463ddd90dbc6c04822000401 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 2 Jul 2024 20:22:09 -0700 Subject: [PATCH 1/3] [ticket/17363] Add web app manifest PHPBB-17363 Signed-off-by: Matt Friedman --- phpBB/config/default/container/services.yml | 9 ++ phpBB/config/default/routing/routing.yml | 4 + phpBB/includes/acp/acp_board.php | 2 + phpBB/includes/functions.php | 1 + phpBB/install/schemas/schema_data.sql | 1 + phpBB/language/en/acp/board.php | 2 + phpBB/phpbb/manifest.php | 95 +++++++++++++++++++ .../prosilver/template/overall_header.html | 5 + 8 files changed, 119 insertions(+) create mode 100644 phpBB/phpbb/manifest.php diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index 14c0d40263..253a70342a 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -157,6 +157,15 @@ services: - '%core.php_ext%' - '%tables.log%' + manifest.controller: + class: phpbb\manifest + arguments: + - '@config' + - '@language' + - '@path_helper' + - '@event_dispatcher' + - '@user' + path_helper: class: phpbb\path_helper arguments: diff --git a/phpBB/config/default/routing/routing.yml b/phpBB/config/default/routing/routing.yml index 7fff9204f0..46d20e4527 100644 --- a/phpBB/config/default/routing/routing.yml +++ b/phpBB/config/default/routing/routing.yml @@ -24,6 +24,10 @@ phpbb_help_routing: resource: help.yml prefix: /help +phpbb_manifest_controller: + path: /manifest + defaults: { _controller: manifest.controller:handle } + phpbb_mention_controller: path: /mention methods: [GET, POST] diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index d2076ce086..a632253c52 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -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_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), + '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_msg' => false, '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 $config_name_ary = [ 'sitename', + 'sitename_short', 'site_desc', 'site_home_text', 'board_index_text', diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 0e52fb37d6..8cee5a6ba0 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -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')), '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_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_MENTION_NAMES_LIMIT' => $config['mention_names_limit'], diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index ba8f654a90..40240213d3 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -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_url', ''); 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_per_page', '50'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('smtp_allow_self_signed', '0'); diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 3228db126b..def1b01c60 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -69,6 +69,8 @@ $lang = array_merge($lang, array( 'SITE_HOME_URL' => 'Main website URL', 'SITE_HOME_URL_EXPLAIN' => 'If specified, a link to this URL will be prepended to your board’s breadcrumbs and the board logo will link to this URL instead of the forum index. An absolute URL is required, e.g. http://www.phpbb.com.', '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 device’s home screen. It can not exceed 12 characters (Emoji is supported).', '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.', 'WARNINGS_EXPIRE' => 'Warning duration', diff --git a/phpBB/phpbb/manifest.php b/phpBB/phpbb/manifest.php new file mode 100644 index 0000000000..e5808c4c9a --- /dev/null +++ b/phpBB/phpbb/manifest.php @@ -0,0 +1,95 @@ + + * @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'] || $this->user->data['user_type'] == USER_INACTIVE) + { + 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 config values to display and process + * @var string board_path Mode of the config page we are displaying + * @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); + } +} diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index 790f793d8f..49f2d3bff6 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -4,6 +4,9 @@ + + + {META} <!-- 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 --> @@ -57,6 +60,8 @@ + + {$STYLESHEETS} From fe40b0d3a389c82a08af8095c351317f53fdd57d Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 2 Jul 2024 21:53:45 -0700 Subject: [PATCH 2/3] [ticket/17363] Add functional test PHPBB-17363 Signed-off-by: Matt Friedman --- tests/functional/manifest_test.php | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/functional/manifest_test.php diff --git a/tests/functional/manifest_test.php b/tests/functional/manifest_test.php new file mode 100644 index 0000000000..f100d9bdff --- /dev/null +++ b/tests/functional/manifest_test.php @@ -0,0 +1,47 @@ + +* @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()); + } +} From e0cf35c5888334a85dd765916b246263e44fc136 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 3 Jul 2024 07:30:07 -0700 Subject: [PATCH 3/3] [ticket/17363] Remove and fix leftover code PHPBB-17363 Signed-off-by: Matt Friedman --- phpBB/phpbb/manifest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/manifest.php b/phpBB/phpbb/manifest.php index e5808c4c9a..1a7d0148e5 100644 --- a/phpBB/phpbb/manifest.php +++ b/phpBB/phpbb/manifest.php @@ -62,7 +62,7 @@ class manifest */ public function handle(): JsonResponse { - if ($this->user->data['is_bot'] || $this->user->data['user_type'] == USER_INACTIVE) + if ($this->user->data['is_bot']) { throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION'); } @@ -83,8 +83,8 @@ class manifest * Event to modify manifest data before it is outputted * * @event core.modify_manifest - * @var array manifest Array of config values to display and process - * @var string board_path Mode of the config page we are displaying + * @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');