From 6a278248e59acf9f347431712276b1fb0c70f5d0 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Thu, 21 Nov 2013 15:34:40 -0800 Subject: [PATCH 01/11] [ticket/11959] Use plurals for the language strings. PHPBB3-11959 --- phpBB/language/en/common.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 360d6be1e0..c171ae5874 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -425,17 +425,23 @@ $lang = array_merge($lang, array( 'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.', 'NOTIFICATIONS' => 'Notifications', 'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.', - 'NOTIFICATION_BOOKMARK_TRIMMED' => '%1$s and %3$d others replied to the topic “%2$s” you have bookmarked.', + 'NOTIFICATION_BOOKMARK_TRIMMED' => array( + 2 => '%1$s and %3$d others replied to the topic “%2$s” you have bookmarked.', + ), 'NOTIFICATION_GROUP_REQUEST' => '%1$s is requesting to join the group %2$s.', 'NOTIFICATION_GROUP_REQUEST_APPROVED' => 'Your request to join the group %1$s has been approved.', 'NOTIFICATION_PM' => '%1$s sent you a Private Message "%2$s".', 'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".', - 'NOTIFICATION_POST_TRIMMED' => '%1$s and %3$d others replied to the topic “%2$s”', + 'NOTIFICATION_POST_TRIMMED' => array( + 2 => '%1$s and %3$d others replied to the topic “%2$s”', + ), 'NOTIFICATION_POST_APPROVED' => 'Your post was approved "%2$s".', 'NOTIFICATION_POST_DISAPPROVED' => 'Your post "%1$s" was disapproved for reason: "%2$s".', 'NOTIFICATION_POST_IN_QUEUE' => 'A new post titled "%2$s" was posted by %1$s and needs approval.', 'NOTIFICATION_QUOTE' => '%1$s quoted you in the post "%2$s".', - 'NOTIFICATION_QUOTE_TRIMMED' => '%1$s and %3$d others replied to the topic “%2$s”', + 'NOTIFICATION_QUOTE_TRIMMED' => array( + 2 => '%1$s and %3$d others replied to the topic “%2$s”', + ), 'NOTIFICATION_REPORT_PM' => '%1$s reported a Private Message "%2$s" for reason: "%3$s".', 'NOTIFICATION_REPORT_POST' => '%1$s reported a post "%2$s" for reason: "%3$s".', 'NOTIFICATION_REPORT_CLOSED' => '%1$s closed the report you made for "%2$s".', From 7e4b7a154214f1663a28244282e551beb59d7d8b Mon Sep 17 00:00:00 2001 From: Cesar G Date: Thu, 21 Nov 2013 18:47:40 -0800 Subject: [PATCH 02/11] [ticket/11959] Fix the NOTIFICATION_QUOTE_TRIMMED text. PHPBB3-11959 --- phpBB/language/en/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index c171ae5874..eb8f7ce2a6 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -440,7 +440,7 @@ $lang = array_merge($lang, array( 'NOTIFICATION_POST_IN_QUEUE' => 'A new post titled "%2$s" was posted by %1$s and needs approval.', 'NOTIFICATION_QUOTE' => '%1$s quoted you in the post "%2$s".', 'NOTIFICATION_QUOTE_TRIMMED' => array( - 2 => '%1$s and %3$d others replied to the topic “%2$s”', + 2 => '%1$s and %3$d quoted you in the post “%2$s”', ), 'NOTIFICATION_REPORT_PM' => '%1$s reported a Private Message "%2$s" for reason: "%3$s".', 'NOTIFICATION_REPORT_POST' => '%1$s reported a post "%2$s" for reason: "%3$s".', From 126ee37f6692a7c52fd8f6527af2dc06cda50a8b Mon Sep 17 00:00:00 2001 From: Cesar G Date: Sun, 1 Dec 2013 11:25:54 -0800 Subject: [PATCH 03/11] [ticket/11959] Use the plurals system for the untrimmed language strings. PHPBB3-11959 --- phpBB/language/en/common.php | 12 +++++++++--- phpBB/phpbb/notification/type/post.php | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index eb8f7ce2a6..437f3a190f 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -424,21 +424,27 @@ $lang = array_merge($lang, array( 'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.', 'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.', 'NOTIFICATIONS' => 'Notifications', - 'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.', + 'NOTIFICATION_BOOKMARK' => array( + 1 => '%1$s replied to the topic “%2$s” you have bookmarked.', + ), 'NOTIFICATION_BOOKMARK_TRIMMED' => array( 2 => '%1$s and %3$d others replied to the topic “%2$s” you have bookmarked.', ), 'NOTIFICATION_GROUP_REQUEST' => '%1$s is requesting to join the group %2$s.', 'NOTIFICATION_GROUP_REQUEST_APPROVED' => 'Your request to join the group %1$s has been approved.', 'NOTIFICATION_PM' => '%1$s sent you a Private Message "%2$s".', - 'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".', + 'NOTIFICATION_POST' => array( + 1 => '%1$s replied to the topic “%2$s”.', + ), 'NOTIFICATION_POST_TRIMMED' => array( 2 => '%1$s and %3$d others replied to the topic “%2$s”', ), 'NOTIFICATION_POST_APPROVED' => 'Your post was approved "%2$s".', 'NOTIFICATION_POST_DISAPPROVED' => 'Your post "%1$s" was disapproved for reason: "%2$s".', 'NOTIFICATION_POST_IN_QUEUE' => 'A new post titled "%2$s" was posted by %1$s and needs approval.', - 'NOTIFICATION_QUOTE' => '%1$s quoted you in the post "%2$s".', + 'NOTIFICATION_QUOTE' => array( + 1 => '%1$s quoted you in the post “%2$s”.', + ), 'NOTIFICATION_QUOTE_TRIMMED' => array( 2 => '%1$s and %3$d quoted you in the post “%2$s”', ), diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index bc42c4422b..a883e67bd4 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -210,13 +210,18 @@ class post extends \phpbb\notification\type\base if ($trimmed_responders_cnt) { $lang_key .= '_TRIMMED'; + $lang_user_cnt = $trimmed_responders_cnt; + } + else + { + $lang_user_cnt = $responders_cnt; } return $this->user->lang( $lang_key, implode($this->user->lang['COMMA_SEPARATOR'], $usernames), censor_text($this->get_data('topic_title')), - $trimmed_responders_cnt + $lang_user_cnt ); } From b32a66ca78b6170c0d90b7776dabdf8f343c557a Mon Sep 17 00:00:00 2001 From: Cesar G Date: Sun, 1 Dec 2013 12:20:43 -0800 Subject: [PATCH 04/11] [ticket/11959] List the last user with "and" instead of a comma. PHPBB3-11959 --- phpBB/language/en/common.php | 21 +++++++++++++++------ phpBB/phpbb/notification/type/post.php | 7 +++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 437f3a190f..42965c460f 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -424,29 +424,38 @@ $lang = array_merge($lang, array( 'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.', 'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.', 'NOTIFICATIONS' => 'Notifications', + // This is used for a list of up to 4 users. 5 users or more uses _TRIMMED. 'NOTIFICATION_BOOKMARK' => array( - 1 => '%1$s replied to the topic “%2$s” you have bookmarked.', + 1 => '%1$s replied to the topic “%3$s” you have bookmarked.', + 2 => '%1$s and %2$s replied to the topic “%3$s” you have bookmarked.', ), + // X, Y, Z and 2 others replied to the topic “Test” you have bookmarked. 'NOTIFICATION_BOOKMARK_TRIMMED' => array( - 2 => '%1$s and %3$d others replied to the topic “%2$s” you have bookmarked.', + 2 => '%1$s and %4$d others replied to the topic “%3$s” you have bookmarked.', ), 'NOTIFICATION_GROUP_REQUEST' => '%1$s is requesting to join the group %2$s.', 'NOTIFICATION_GROUP_REQUEST_APPROVED' => 'Your request to join the group %1$s has been approved.', 'NOTIFICATION_PM' => '%1$s sent you a Private Message "%2$s".', + // This is used for a list of up to 4 users. 5 users or more uses _TRIMMED. 'NOTIFICATION_POST' => array( - 1 => '%1$s replied to the topic “%2$s”.', + 1 => '%1$s replied to the topic “%3$s”.', + 2 => '%1$s and %2$s replied to the topic “%3$s”.', ), + // X, Y, Z and 2 others replied to the topic “Test”. 'NOTIFICATION_POST_TRIMMED' => array( - 2 => '%1$s and %3$d others replied to the topic “%2$s”', + 2 => '%1$s and %4$d others replied to the topic “%3$s”', ), 'NOTIFICATION_POST_APPROVED' => 'Your post was approved "%2$s".', 'NOTIFICATION_POST_DISAPPROVED' => 'Your post "%1$s" was disapproved for reason: "%2$s".', 'NOTIFICATION_POST_IN_QUEUE' => 'A new post titled "%2$s" was posted by %1$s and needs approval.', + // This is used for a list of up to 4 users. 5 users or more uses _TRIMMED. 'NOTIFICATION_QUOTE' => array( - 1 => '%1$s quoted you in the post “%2$s”.', + 1 => '%1$s quoted you in the post “%3$s”.', + 2 => '%1$s and %2$s quoted you in the post “%3$s”.', ), + // X, Y, Z and 2 others quoted you in the post “Re: Test”. 'NOTIFICATION_QUOTE_TRIMMED' => array( - 2 => '%1$s and %3$d quoted you in the post “%2$s”', + 2 => '%1$s and %4$d quoted you in the post “%3$s”', ), 'NOTIFICATION_REPORT_PM' => '%1$s reported a Private Message "%2$s" for reason: "%3$s".', 'NOTIFICATION_REPORT_POST' => '%1$s reported a post "%2$s" for reason: "%3$s".', diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index a883e67bd4..944023cba4 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -205,6 +205,7 @@ class post extends \phpbb\notification\type\base $usernames[] = $this->user_loader->get_username($responder['poster_id'], 'no_profile'); } } + $last_user = ''; $lang_key = $this->language_key; if ($trimmed_responders_cnt) @@ -215,11 +216,17 @@ class post extends \phpbb\notification\type\base else { $lang_user_cnt = $responders_cnt; + + if ($responders_cnt > 1) + { + $last_user = array_pop($usernames); + } } return $this->user->lang( $lang_key, implode($this->user->lang['COMMA_SEPARATOR'], $usernames), + $last_user, censor_text($this->get_data('topic_title')), $lang_user_cnt ); From 7cc1a8d224b8c53530bba89fbb756a0518b04a91 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Sun, 1 Dec 2013 12:28:37 -0800 Subject: [PATCH 05/11] [ticket/11959] Add samples for the untrimmed strings. PHPBB3-11959 --- phpBB/language/en/common.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 42965c460f..e84033f1b7 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -427,6 +427,7 @@ $lang = array_merge($lang, array( // This is used for a list of up to 4 users. 5 users or more uses _TRIMMED. 'NOTIFICATION_BOOKMARK' => array( 1 => '%1$s replied to the topic “%3$s” you have bookmarked.', + // X, Y, and Z replied to the topic “Test” you have bookmarked. 2 => '%1$s and %2$s replied to the topic “%3$s” you have bookmarked.', ), // X, Y, Z and 2 others replied to the topic “Test” you have bookmarked. @@ -439,6 +440,7 @@ $lang = array_merge($lang, array( // This is used for a list of up to 4 users. 5 users or more uses _TRIMMED. 'NOTIFICATION_POST' => array( 1 => '%1$s replied to the topic “%3$s”.', + // X, Y, and Z replied to the topic “Test”. 2 => '%1$s and %2$s replied to the topic “%3$s”.', ), // X, Y, Z and 2 others replied to the topic “Test”. @@ -451,6 +453,7 @@ $lang = array_merge($lang, array( // This is used for a list of up to 4 users. 5 users or more uses _TRIMMED. 'NOTIFICATION_QUOTE' => array( 1 => '%1$s quoted you in the post “%3$s”.', + // X, Y, and Z quoted you in the post “Re: Test”. 2 => '%1$s and %2$s quoted you in the post “%3$s”.', ), // X, Y, Z and 2 others quoted you in the post “Re: Test”. From f0a85a90cc61859d1821960b8e3c50a8187202a7 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Fri, 7 Feb 2014 14:55:47 -0800 Subject: [PATCH 06/11] [ticket/11959] Add function to create a string list. PHPBB3-11959 --- phpBB/includes/functions_display.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index cd2c9e5ae6..6bffaeaa44 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1499,3 +1499,25 @@ function phpbb_gen_download_links($param_key, $param_val, $phpbb_root_path, $php return $links; } + +/** +* Concatenate an array into a string list. +* +* @param array $items Array of items to concatenate +* @param object $user The phpBB $user object. +* +* @return string String list. Examples: "A"; "A and B"; "A, B and C" +*/ +function phpbb_gen_string_list($items, $user) +{ + $count = sizeof($items); + $last_item = ''; + + if ($count > 1) + { + $last_item = array_pop($items); + } + $list = implode($user->lang['COMMA_SEPARATOR'], $items); + + return $user->lang('STRING_LIST', $list, $last_item, $count); +} From 285ad0f6faac275c56576616ed6a880a7f88e94b Mon Sep 17 00:00:00 2001 From: Cesar G Date: Fri, 7 Feb 2014 14:56:14 -0800 Subject: [PATCH 07/11] [ticket/11959] Simplify how the users are trimmed. PHPBB3-11959 --- phpBB/language/en/common.php | 44 ++++++++++++-------------- phpBB/phpbb/notification/type/post.php | 22 ++++--------- 2 files changed, 27 insertions(+), 39 deletions(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index e84033f1b7..757e421759 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -424,41 +424,28 @@ $lang = array_merge($lang, array( 'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.', 'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.', 'NOTIFICATIONS' => 'Notifications', - // This is used for a list of up to 4 users. 5 users or more uses _TRIMMED. + // This applies for NOTIFICATION_BOOKMARK, NOTIFICATION_POST, and NOTIFICATION_QUOTE. + // %1$s will return a list of users that's concatenated using "," and "and" - see STRING_LIST + // Once the user count reaches 5 users or more, the list is trimmed using NOTIFICATION_X_OTHERS + // Examples: + // A replied... + // A and B replied... + // A, B and C replied... + // A, B, C and 2 others replied... 'NOTIFICATION_BOOKMARK' => array( - 1 => '%1$s replied to the topic “%3$s” you have bookmarked.', - // X, Y, and Z replied to the topic “Test” you have bookmarked. - 2 => '%1$s and %2$s replied to the topic “%3$s” you have bookmarked.', - ), - // X, Y, Z and 2 others replied to the topic “Test” you have bookmarked. - 'NOTIFICATION_BOOKMARK_TRIMMED' => array( - 2 => '%1$s and %4$d others replied to the topic “%3$s” you have bookmarked.', + 1 => '%1$s replied to the topic “%2$s” you have bookmarked.', ), 'NOTIFICATION_GROUP_REQUEST' => '%1$s is requesting to join the group %2$s.', 'NOTIFICATION_GROUP_REQUEST_APPROVED' => 'Your request to join the group %1$s has been approved.', 'NOTIFICATION_PM' => '%1$s sent you a Private Message "%2$s".', - // This is used for a list of up to 4 users. 5 users or more uses _TRIMMED. 'NOTIFICATION_POST' => array( - 1 => '%1$s replied to the topic “%3$s”.', - // X, Y, and Z replied to the topic “Test”. - 2 => '%1$s and %2$s replied to the topic “%3$s”.', - ), - // X, Y, Z and 2 others replied to the topic “Test”. - 'NOTIFICATION_POST_TRIMMED' => array( - 2 => '%1$s and %4$d others replied to the topic “%3$s”', + 1 => '%1$s replied to the topic “%2$s”.', ), 'NOTIFICATION_POST_APPROVED' => 'Your post was approved "%2$s".', 'NOTIFICATION_POST_DISAPPROVED' => 'Your post "%1$s" was disapproved for reason: "%2$s".', 'NOTIFICATION_POST_IN_QUEUE' => 'A new post titled "%2$s" was posted by %1$s and needs approval.', - // This is used for a list of up to 4 users. 5 users or more uses _TRIMMED. 'NOTIFICATION_QUOTE' => array( - 1 => '%1$s quoted you in the post “%3$s”.', - // X, Y, and Z quoted you in the post “Re: Test”. - 2 => '%1$s and %2$s quoted you in the post “%3$s”.', - ), - // X, Y, Z and 2 others quoted you in the post “Re: Test”. - 'NOTIFICATION_QUOTE_TRIMMED' => array( - 2 => '%1$s and %4$d quoted you in the post “%3$s”', + 1 => '%1$s quoted you in the post “%2$s”.', ), 'NOTIFICATION_REPORT_PM' => '%1$s reported a Private Message "%2$s" for reason: "%3$s".', 'NOTIFICATION_REPORT_POST' => '%1$s reported a post "%2$s" for reason: "%3$s".', @@ -469,6 +456,10 @@ $lang = array_merge($lang, array( 'NOTIFICATION_TOPIC_IN_QUEUE' => 'A new topic titled "%2$s" was posted by %1$s and needs approval.', 'NOTIFICATION_TYPE_NOT_EXIST' => 'The notification type "%s" is missing from the file system.', 'NOTIFICATION_ADMIN_ACTIVATE_USER' => 'The user “%1$s” is newly registered and requires activation.', + // Used in conjuction with NOTIFICATION_BOOKMARK, NOTIFICATION_POST, and NOTIFICATION_QUOTE. + 'NOTIFICATION_X_OTHERS' => array( + 2 => '%d others', + ), 'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.', 'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: %1$s', 'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.', @@ -692,6 +683,11 @@ $lang = array_merge($lang, array( 'START_WATCHING_TOPIC' => 'Subscribe topic', 'STOP_WATCHING_FORUM' => 'Unsubscribe forum', 'STOP_WATCHING_TOPIC' => 'Unsubscribe topic', + 'STRING_LIST' => array( + 1 => '%1$s', + 2 => '%1$s and %2$s', + // At 3 or more, %1$s returns comma separated items. So output would be: X, Y and Z + ), 'SUBFORUM' => 'Subforum', 'SUBFORUMS' => 'Subforums', 'SUBJECT' => 'Subject', diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 944023cba4..62c8bd52cb 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -205,30 +205,22 @@ class post extends \phpbb\notification\type\base $usernames[] = $this->user_loader->get_username($responder['poster_id'], 'no_profile'); } } - $last_user = ''; - $lang_key = $this->language_key; if ($trimmed_responders_cnt) { - $lang_key .= '_TRIMMED'; - $lang_user_cnt = $trimmed_responders_cnt; + $usernames[] = $this->user->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt); } - else - { - $lang_user_cnt = $responders_cnt; - if ($responders_cnt > 1) - { - $last_user = array_pop($usernames); - } + if (!function_exists('phpbb_gen_string_list')) + { + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ex); } return $this->user->lang( - $lang_key, - implode($this->user->lang['COMMA_SEPARATOR'], $usernames), - $last_user, + $this->language_key, + phpbb_gen_string_list($usernames, $this->user), censor_text($this->get_data('topic_title')), - $lang_user_cnt + $responders_cnt ); } From 3da1f6d989357c9076ffde532cfbbd3d6375aa3c Mon Sep 17 00:00:00 2001 From: Cesar G Date: Fri, 14 Mar 2014 19:19:39 -0700 Subject: [PATCH 08/11] [ticket/11959] Rename phpbb_gen_string_list() & fix incorrect var name. PHPBB3-11959 --- phpBB/includes/functions_display.php | 2 +- phpBB/phpbb/notification/type/post.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 6bffaeaa44..311f86296d 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1508,7 +1508,7 @@ function phpbb_gen_download_links($param_key, $param_val, $phpbb_root_path, $php * * @return string String list. Examples: "A"; "A and B"; "A, B and C" */ -function phpbb_gen_string_list($items, $user) +function phpbb_generate_string_list($items, $user) { $count = sizeof($items); $last_item = ''; diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 62c8bd52cb..d3491a3f5e 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -211,14 +211,14 @@ class post extends \phpbb\notification\type\base $usernames[] = $this->user->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt); } - if (!function_exists('phpbb_gen_string_list')) + if (!function_exists('phpbb_generate_string_list')) { - include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ex); + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); } return $this->user->lang( $this->language_key, - phpbb_gen_string_list($usernames, $this->user), + phpbb_generate_string_list($usernames, $this->user), censor_text($this->get_data('topic_title')), $responders_cnt ); From 7c1ab5f79d621f210fa1bdea0e9b217a10c20fa9 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Wed, 19 Mar 2014 03:03:20 -0700 Subject: [PATCH 09/11] [ticket/11959] Remove use of plurals and make it possible to use Oxford comma. PHPBB3-11959 --- phpBB/includes/functions_display.php | 24 +++++++++++++++++------- phpBB/language/en/common.php | 7 ++----- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 311f86296d..d760f09dcd 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1506,18 +1506,28 @@ function phpbb_gen_download_links($param_key, $param_val, $phpbb_root_path, $php * @param array $items Array of items to concatenate * @param object $user The phpBB $user object. * -* @return string String list. Examples: "A"; "A and B"; "A, B and C" +* @return string String list. Examples: "A"; "A and B"; "A, B, and C" */ function phpbb_generate_string_list($items, $user) { - $count = sizeof($items); - $last_item = ''; - - if ($count > 1) + if (empty($items)) { - $last_item = array_pop($items); + return ''; + } + + $count = sizeof($items); + $last_item = array_pop($items); + $lang_key = 'STRING_LIST_MULTI'; + + if ($count == 1) + { + return $last_item; + } + else if ($count == 2) + { + $lang_key = 'STRING_LIST_SIMPLE'; } $list = implode($user->lang['COMMA_SEPARATOR'], $items); - return $user->lang('STRING_LIST', $list, $last_item, $count); + return $user->lang($lang_key, $list, $last_item); } diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 757e421759..f073954817 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -683,11 +683,8 @@ $lang = array_merge($lang, array( 'START_WATCHING_TOPIC' => 'Subscribe topic', 'STOP_WATCHING_FORUM' => 'Unsubscribe forum', 'STOP_WATCHING_TOPIC' => 'Unsubscribe topic', - 'STRING_LIST' => array( - 1 => '%1$s', - 2 => '%1$s and %2$s', - // At 3 or more, %1$s returns comma separated items. So output would be: X, Y and Z - ), + 'STRING_LIST_MULTI' => '%1$s, and %2$s', + 'STRING_LIST_SIMPLE' => '%1$s and %2$s', 'SUBFORUM' => 'Subforum', 'SUBFORUMS' => 'Subforums', 'SUBJECT' => 'Subject', From 2a822931c6d95fe9e6066752ec59ab614189837e Mon Sep 17 00:00:00 2001 From: Cesar G Date: Wed, 19 Mar 2014 03:05:36 -0700 Subject: [PATCH 10/11] [ticket/11959] Add unit tests. PHPBB3-11959 --- tests/functions/generate_string_list.php | 60 ++++++++ tests/mock/notification_type_post.php | 36 +++++ .../notification/fixtures/user_list_trim.xml | 51 +++++++ tests/notification/user_list_trim_test.php | 139 ++++++++++++++++++ 4 files changed, 286 insertions(+) create mode 100644 tests/functions/generate_string_list.php create mode 100644 tests/mock/notification_type_post.php create mode 100644 tests/notification/fixtures/user_list_trim.xml create mode 100644 tests/notification/user_list_trim_test.php diff --git a/tests/functions/generate_string_list.php b/tests/functions/generate_string_list.php new file mode 100644 index 0000000000..60269b5656 --- /dev/null +++ b/tests/functions/generate_string_list.php @@ -0,0 +1,60 @@ +user = new \phpbb\user(); + $this->user->data = array('user_lang' => 'en'); + $this->user->add_lang('common'); + } + + public function generate_string_list_data() + { + return array( + array( + array(), + '', + ), + array( + array('A'), + 'A', + ), + array( + array(2 => 'A', 3 => 'B'), + 'A and B', + ), + array( + array('A' => 'A', 'B' => 'B', 'C' => 'C'), + 'A, B, and C', + ), + array( + array('A', 'B', 'C', 'D'), + 'A, B, C, and D', + ) + ); + } + + /** + * @dataProvider generate_string_list_data + */ + public function test_generate_string_list($items, $expected_result) + { + $result = phpbb_generate_string_list($items, $this->user); + $this->assertEquals($expected_result, $result); + } +} diff --git a/tests/mock/notification_type_post.php b/tests/mock/notification_type_post.php new file mode 100644 index 0000000000..80f2afbae0 --- /dev/null +++ b/tests/mock/notification_type_post.php @@ -0,0 +1,36 @@ +user_loader = $user_loader; + $this->db = $db; + $this->cache = $cache; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->notification_types_table = $notification_types_table; + $this->notifications_table = $notifications_table; + $this->user_notifications_table = $user_notifications_table; + } +} diff --git a/tests/notification/fixtures/user_list_trim.xml b/tests/notification/fixtures/user_list_trim.xml new file mode 100644 index 0000000000..4f708714da --- /dev/null +++ b/tests/notification/fixtures/user_list_trim.xml @@ -0,0 +1,51 @@ + + + + user_id + username + username_clean + user_colour + user_permissions + user_sig + + 2 + A + a + + + + + + 3 + B + b + + + + + + 4 + C + c + + + + + + 5 + D + d + + + + + + 6 + E + e + + + + +
+
diff --git a/tests/notification/user_list_trim_test.php b/tests/notification/user_list_trim_test.php new file mode 100644 index 0000000000..a8422f80b5 --- /dev/null +++ b/tests/notification/user_list_trim_test.php @@ -0,0 +1,139 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/user_list_trim.xml'); + } + + public function setUp() + { + global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $user, $cache, $auth; + + parent::setUp(); + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $db = $this->new_dbal(); + + $config = new \phpbb\config\config(array()); + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + + $cache = new \phpbb\cache\service( + new \phpbb\cache\driver\null(), + $config, + $db, + $phpbb_root_path, + $phpEx + ); + + $auth = $this->getMock('\phpbb\auth\auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap(array( + array('u_viewprofile', 1, false), + ))); + + $user = new \phpbb\user(); + $user->data = array('user_lang' => 'en'); + $user->add_lang('common'); + + $user_loader = new phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); + $user_loader->load_users(array(2, 3, 4, 5, 6)); + + $this->notification = new phpbb_mock_notification_type_post( + $user_loader, null, null, $user, null, null, $phpbb_root_path, $phpEx, null, null, null + ); + } + + public function user_list_trim_data() + { + return array( + array( + array( + 'topic_title' => 'Test', + 'poster_id' => 2, + 'post_username' => 'A', + 'responders' => null, + ), + 'A replied to the topic “Test”.', + ), + array( + array( + 'topic_title' => 'Test', + 'poster_id' => 2, + 'post_username' => 'A', + 'responders' => array( + array('username' => '', 'poster_id' => 3), + ), + ), + 'A and B replied to the topic “Test”.', + ), + array( + array( + 'topic_title' => 'Test', + 'poster_id' => 2, + 'post_username' => 'A', + 'responders' => array( + array('username' => '', 'poster_id' => 3), + array('username' => '', 'poster_id' => 4), + ), + ), + 'A, B, and C replied to the topic “Test”.', + ), + array( + array( + 'topic_title' => 'Test', + 'poster_id' => 2, + 'post_username' => 'A', + 'responders' => array( + array('username' => '', 'poster_id' => 3), + array('username' => '', 'poster_id' => 4), + array('username' => '', 'poster_id' => 5), + ), + ), + 'A, B, C, and D replied to the topic “Test”.', + ), + array( + array( + 'topic_title' => 'Test', + 'poster_id' => 2, + 'post_username' => 'A', + 'responders' => array( + array('username' => '', 'poster_id' => 3), + array('username' => '', 'poster_id' => 4), + array('username' => '', 'poster_id' => 5), + array('username' => '', 'poster_id' => 6), + ), + ), + 'A, B, C, and 2 others replied to the topic “Test”.', + ), + ); + } + + /** + * @dataProvider user_list_trim_data + */ + public function test_user_list_trim($data, $expected_result) + { + $data = array('notification_data' => serialize($data)); + $this->notification->set_initial_data($data); + + $this->assertEquals($expected_result, $this->notification->get_title()); + } +} From b893dae105f72b7c34abe855e24f0dec35206208 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Sat, 29 Mar 2014 09:29:47 -0700 Subject: [PATCH 11/11] [ticket/11959] Move phpbb_generate_string_list() to functions_content.php. PHPBB3-11959 --- phpBB/includes/functions_content.php | 32 ++++++++++++++++++++++++ phpBB/includes/functions_display.php | 32 ------------------------ phpBB/phpbb/notification/type/post.php | 5 ---- tests/functions/generate_string_list.php | 2 +- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 8122b87e4b..dd9201165b 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1414,6 +1414,38 @@ function phpbb_add_quickmod_option($option, $lang_string) )); } +/** +* Concatenate an array into a string list. +* +* @param array $items Array of items to concatenate +* @param object $user The phpBB $user object. +* +* @return string String list. Examples: "A"; "A and B"; "A, B, and C" +*/ +function phpbb_generate_string_list($items, $user) +{ + if (empty($items)) + { + return ''; + } + + $count = sizeof($items); + $last_item = array_pop($items); + $lang_key = 'STRING_LIST_MULTI'; + + if ($count == 1) + { + return $last_item; + } + else if ($count == 2) + { + $lang_key = 'STRING_LIST_SIMPLE'; + } + $list = implode($user->lang['COMMA_SEPARATOR'], $items); + + return $user->lang($lang_key, $list, $last_item); +} + /** * @package phpBB3 */ diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index d760f09dcd..cd2c9e5ae6 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1499,35 +1499,3 @@ function phpbb_gen_download_links($param_key, $param_val, $phpbb_root_path, $php return $links; } - -/** -* Concatenate an array into a string list. -* -* @param array $items Array of items to concatenate -* @param object $user The phpBB $user object. -* -* @return string String list. Examples: "A"; "A and B"; "A, B, and C" -*/ -function phpbb_generate_string_list($items, $user) -{ - if (empty($items)) - { - return ''; - } - - $count = sizeof($items); - $last_item = array_pop($items); - $lang_key = 'STRING_LIST_MULTI'; - - if ($count == 1) - { - return $last_item; - } - else if ($count == 2) - { - $lang_key = 'STRING_LIST_SIMPLE'; - } - $list = implode($user->lang['COMMA_SEPARATOR'], $items); - - return $user->lang($lang_key, $list, $last_item); -} diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index d3491a3f5e..140c0ad82a 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -211,11 +211,6 @@ class post extends \phpbb\notification\type\base $usernames[] = $this->user->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt); } - if (!function_exists('phpbb_generate_string_list')) - { - include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); - } - return $this->user->lang( $this->language_key, phpbb_generate_string_list($usernames, $this->user), diff --git a/tests/functions/generate_string_list.php b/tests/functions/generate_string_list.php index 60269b5656..cfc150c1f4 100644 --- a/tests/functions/generate_string_list.php +++ b/tests/functions/generate_string_list.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_display.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_generate_string_list_test extends phpbb_test_case