From 3f4b7059cb4903a314565ae448d142121e9e9611 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Tue, 15 Jan 2019 20:50:37 +0100 Subject: [PATCH 1/5] [ticket/15942] Allow array in confirm_box title PHPBB3-15942 --- phpBB/includes/functions.php | 30 ++++++++++++++++++++++-------- phpBB/includes/mcp/mcp_main.php | 4 ++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 99f65a0e92..067f453e6d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2130,7 +2130,7 @@ function check_form_key($form_name, $timespan = false) /** * Build Confirm box * @param boolean $check True for checking if confirmed (without any additional parameters) and false for displaying the confirm box -* @param string $title Title/Message used for confirm box. +* @param string|array $title Title/Message used for confirm box. * message text is _CONFIRM appended to title. * If title cannot be found in user->lang a default one is displayed * If title_CONFIRM cannot be found in user->lang the text given is used. @@ -2182,13 +2182,27 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo // generate activation key $confirm_key = gen_rand_string(10); - if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) + // generate language strings + if (is_array($title)) { - adm_page_header((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]); + $key = array_shift($title); + $count = array_shift($title); + $confirm_title = isset($user->lang[$key]) ? $user->lang($key, $count, $title) : $user->lang('CONFIRM'); + $confirm_text = isset($user->lang[$key . '_CONFIRM']) ? $user->lang($key . '_CONFIRM', $count, $title) : $key; } else { - page_header((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]); + $confirm_title = isset($user->lang[$title]) ? $user->lang($title) : $user->lang('CONFIRM'); + $confirm_text = isset($user->lang[$title . '_CONFIRM']) ? $user->lang($title . '_CONFIRM') : $title; + } + + if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) + { + adm_page_header($confirm_title); + } + else + { + page_header($confirm_title); } $template->set_filenames(array( @@ -2208,8 +2222,8 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo $u_action .= ((strpos($u_action, '?') === false) ? '?' : '&') . 'confirm_key=' . $confirm_key; $template->assign_vars(array( - 'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang($title, 1), - 'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'], + 'MESSAGE_TITLE' => $confirm_title, + 'MESSAGE_TEXT' => $confirm_text, 'YES_VALUE' => $user->lang['YES'], 'S_CONFIRM_ACTION' => $u_action, @@ -2227,8 +2241,8 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo $json_response = new \phpbb\json_response; $json_response->send(array( 'MESSAGE_BODY' => $template->assign_display('body'), - 'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title], - 'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'], + 'MESSAGE_TITLE' => $confirm_title, + 'MESSAGE_TEXT' => $confirm_text, 'YES_VALUE' => $user->lang['YES'], 'S_CONFIRM_ACTION' => str_replace('&', '&', $u_action), //inefficient, rewrite whole function diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index a4e3a74ba7..565839b3ee 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -933,7 +933,7 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' $l_confirm = (count($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; if ($only_softdeleted) { - $l_confirm .= '_PERMANENTLY'; + $l_confirm = array($l_confirm . '_PERMANENTLY', count($topic_ids)); $s_hidden_fields['delete_permanent'] = '1'; } else if ($only_shadow || !$auth->acl_get('m_softdelete', $forum_id)) @@ -1187,7 +1187,7 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', $l_confirm = (count($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS'; if ($only_softdeleted) { - $l_confirm .= '_PERMANENTLY'; + $l_confirm = array($l_confirm . '_PERMANENTLY', (int) count($post_ids)); $s_hidden_fields['delete_permanent'] = '1'; } else if (!$auth->acl_get('m_softdelete', $forum_id)) From a925605b88861eaf21fef0196b21ed46279120a1 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Tue, 15 Jan 2019 20:58:54 +0100 Subject: [PATCH 2/5] [ticket/15942] Optimize count PHPBB3-15942 --- phpBB/includes/mcp/mcp_main.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 565839b3ee..69d5993a73 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -930,10 +930,11 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' 'DELETE_TOPIC_PERMANENTLY_EXPLAIN' => $user->lang('DELETE_TOPIC_PERMANENTLY', count($topic_ids)), )); - $l_confirm = (count($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; + $count = count($topic_ids); + $l_confirm = $count === 1 ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; if ($only_softdeleted) { - $l_confirm = array($l_confirm . '_PERMANENTLY', count($topic_ids)); + $l_confirm = array($l_confirm . '_PERMANENTLY', $count); $s_hidden_fields['delete_permanent'] = '1'; } else if ($only_shadow || !$auth->acl_get('m_softdelete', $forum_id)) @@ -1184,10 +1185,11 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', 'DELETE_POST_PERMANENTLY_EXPLAIN' => $user->lang('DELETE_POST_PERMANENTLY', count($post_ids)), )); - $l_confirm = (count($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS'; + $count = count($post_ids); + $l_confirm = $count === 1 ? 'DELETE_POST' : 'DELETE_POSTS'; if ($only_softdeleted) { - $l_confirm = array($l_confirm . '_PERMANENTLY', (int) count($post_ids)); + $l_confirm = array($l_confirm . '_PERMANENTLY', $count); $s_hidden_fields['delete_permanent'] = '1'; } else if (!$auth->acl_get('m_softdelete', $forum_id)) From 2131adac5c82ec14995f1e2cbcaee74f855b430c Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Tue, 16 Apr 2019 10:15:01 +0200 Subject: [PATCH 3/5] [ticket/15942] Update DocBlock PHPBB3-15942 --- phpBB/includes/functions.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 067f453e6d..01b292f822 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2134,6 +2134,8 @@ function check_form_key($form_name, $timespan = false) * message text is _CONFIRM appended to title. * If title cannot be found in user->lang a default one is displayed * If title_CONFIRM cannot be found in user->lang the text given is used. +* If title is an array, the first array value is used as explained per above, +* all other array values are send as parameters to the language function. * @param string $hidden Hidden variables * @param string $html_body Template used for confirm box * @param string $u_action Custom form action From a16ebf04d397095df3ef4e6ee426df4959468c4f Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Tue, 16 Apr 2019 10:38:26 +0200 Subject: [PATCH 4/5] [ticket/15942] Past tense PHPBB3-15942 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 01b292f822..e55866cb74 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2135,7 +2135,7 @@ function check_form_key($form_name, $timespan = false) * If title cannot be found in user->lang a default one is displayed * If title_CONFIRM cannot be found in user->lang the text given is used. * If title is an array, the first array value is used as explained per above, -* all other array values are send as parameters to the language function. +* all other array values are sent as parameters to the language function. * @param string $hidden Hidden variables * @param string $html_body Template used for confirm box * @param string $u_action Custom form action From 0e38bebaa56dcf8921df99e8eb85e3046721dd13 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 17 Apr 2019 08:22:44 +0200 Subject: [PATCH 5/5] [ticket/15942] Add language to compatibility globals & use in confirm_box PHPBB3-15942 --- phpBB/includes/compatibility_globals.php | 5 ++++- phpBB/includes/functions.php | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/compatibility_globals.php b/phpBB/includes/compatibility_globals.php index 0f403896a7..ad394e3782 100644 --- a/phpBB/includes/compatibility_globals.php +++ b/phpBB/includes/compatibility_globals.php @@ -29,7 +29,7 @@ function register_compatibility_globals() { global $phpbb_container; - global $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log; + global $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $language, $phpbb_log; global $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template; // set up caching @@ -48,6 +48,9 @@ function register_compatibility_globals() /* @var $user \phpbb\user */ $user = $phpbb_container->get('user'); + /* @var \phpbb\language\language $language */ + $language = $phpbb_container->get('language'); + /* @var $auth \phpbb\auth\auth */ $auth = $phpbb_container->get('auth'); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e55866cb74..40b6f7bb45 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2139,18 +2139,20 @@ function check_form_key($form_name, $timespan = false) * @param string $hidden Hidden variables * @param string $html_body Template used for confirm box * @param string $u_action Custom form action +* +* @return bool True if confirmation was successful, false if not */ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_body.html', $u_action = '') { global $user, $template, $db, $request; - global $config, $phpbb_path_helper; + global $config, $language, $phpbb_path_helper; if (isset($_POST['cancel'])) { return false; } - $confirm = ($user->lang['YES'] === $request->variable('confirm', '', true, \phpbb\request\request_interface::POST)); + $confirm = ($language->lang('YES') === $request->variable('confirm', '', true, \phpbb\request\request_interface::POST)); if ($check && $confirm) { @@ -2189,13 +2191,13 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo { $key = array_shift($title); $count = array_shift($title); - $confirm_title = isset($user->lang[$key]) ? $user->lang($key, $count, $title) : $user->lang('CONFIRM'); - $confirm_text = isset($user->lang[$key . '_CONFIRM']) ? $user->lang($key . '_CONFIRM', $count, $title) : $key; + $confirm_title = $language->is_set($key) ? $language->lang($key, $count, $title) : $language->lang('CONFIRM'); + $confirm_text = $language->is_set($key . '_CONFIRM') ? $language->lang($key . '_CONFIRM', $count, $title) : $key; } else { - $confirm_title = isset($user->lang[$title]) ? $user->lang($title) : $user->lang('CONFIRM'); - $confirm_text = isset($user->lang[$title . '_CONFIRM']) ? $user->lang($title . '_CONFIRM') : $title; + $confirm_title = $language->is_set($title) ? $language->lang($title) : $language->lang('CONFIRM'); + $confirm_text = $language->is_set($title . '_CONFIRM') ? $language->lang($title . '_CONFIRM') : $title; } if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) @@ -2227,7 +2229,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo 'MESSAGE_TITLE' => $confirm_title, 'MESSAGE_TEXT' => $confirm_text, - 'YES_VALUE' => $user->lang['YES'], + 'YES_VALUE' => $language->lang('YES'), 'S_CONFIRM_ACTION' => $u_action, 'S_HIDDEN_FIELDS' => $hidden . $s_hidden_fields, 'S_AJAX_REQUEST' => $request->is_ajax(), @@ -2246,7 +2248,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo 'MESSAGE_TITLE' => $confirm_title, 'MESSAGE_TEXT' => $confirm_text, - 'YES_VALUE' => $user->lang['YES'], + 'YES_VALUE' => $language->lang('YES'), 'S_CONFIRM_ACTION' => str_replace('&', '&', $u_action), //inefficient, rewrite whole function 'S_HIDDEN_FIELDS' => $hidden . $s_hidden_fields )); @@ -2260,6 +2262,8 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo { page_footer(); } + + exit; // unreachable, page_footer() above will call exit() } /**