From 41710c745d5507aa71e25b125b0ae1485cc7ecc1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 6 Jan 2013 21:09:07 +0100 Subject: [PATCH] [feature/avatars] Add function for localizing errors PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 18 ++-------------- phpBB/includes/acp/acp_users.php | 13 +----------- phpBB/includes/avatar/manager.php | 33 ++++++++++++++++++++++++++---- phpBB/includes/ucp/ucp_groups.php | 14 +------------ phpBB/includes/ucp/ucp_profile.php | 15 ++------------ 5 files changed, 35 insertions(+), 58 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 3a72a8c7ef..d9452a902e 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -550,22 +550,8 @@ class acp_groups $avatar = phpbb_get_group_avatar($group_row, 'GROUP_AVATAR', true); - /* - * Merge any avatar errors into the primary error array - * Drivers use language constants, so we need to map to the actual strings - */ - foreach ($avatar_error as $lang) - { - if (is_array($lang)) - { - $key = array_shift($lang); - $error[] = vsprintf($user->lang($key), $lang); - } - else - { - $error[] = $user->lang("$lang"); - } - } + // Merge any avatar errors into the primary error array + $error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error)); $back_link = request_var('back_link', ''); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index d742cad9f4..5960f33741 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1831,18 +1831,7 @@ class acp_users } // Replace "error" strings with their real, localised form - foreach ($error as $key => $lang) - { - if (is_array($lang)) - { - $lang_key = array_shift($lang); - $error[$key] = vsprintf($user->lang($lang_key), $lang); - } - else - { - $error[$key] = $user->lang($lang); - } - } + $error = $phpbb_avatar_manager->localize_errors($user, $error); $avatar = phpbb_get_user_avatar($user_row, 'USER_AVATAR', true); diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 7c2d03f07b..f91b0c4317 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -44,11 +44,7 @@ class phpbb_avatar_manager /** * Construct an avatar manager object * - * @param string $phpbb_root_path Path to the phpBB root - * @param string $phpEx PHP file extension * @param phpbb_config $config phpBB configuration - * @param phpbb_request $request Request object - * @param phpbb_cache_driver_interface $cache Cache driver * @param array $avatar_drivers Avatar drivers passed via the service container * @param object $container Container object */ @@ -260,4 +256,33 @@ class phpbb_avatar_manager { return preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); } + + /** + * Replace "error" strings with their real, localized form + * + * @param phpbb_user phpBB User object + * @param array $error Array containing error strings + * Key values can either be a string with a language key or an array + * that will be passed to vsprintf() with the language key in the + * first array key. + * + * @return array Array containing the localized error strings + */ + public function localize_errors(phpbb_user $user, $error) + { + foreach ($error as $key => $lang) + { + if (is_array($lang)) + { + $lang_key = array_shift($lang); + $error[$key] = vsprintf($user->lang($lang_key), $lang); + } + else + { + $error[$key] = $user->lang("$lang"); + } + } + + return $error; + } } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index b3e07cc7b9..86c02b5bcc 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -674,19 +674,7 @@ class ucp_groups } // Merge any avatars errors into the primary error array - // Drivers use lang constants, so we need to map to the actual strings - foreach ($avatar_error as $lang) - { - if (is_array($lang)) - { - $key = array_shift($lang); - $error[] = vsprintf($user->lang($key), $lang); - } - else - { - $error[] = $user->lang("$lang"); - } - } + $error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error)); $template->assign_vars(array( 'S_EDIT' => true, diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 598314a035..36d59e7854 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -659,19 +659,8 @@ class ucp_profile } // Replace "error" strings with their real, localised form - foreach ($error as $key => $lang) - { - if (is_array($lang)) - { - $key = array_shift($lang); - $error[$key] = vsprintf($user->lang($key), $lang); - } - else - { - $error[$key] = $user->lang("$lang"); - } - } - + $error = $phpbb_avatar_manager->localize_errors($user, $error); + $avatar = phpbb_get_user_avatar($user->data, 'USER_AVATAR', true); $template->assign_vars(array(