From bcf347420e4fe400d02a6ee58e63839f18a86362 Mon Sep 17 00:00:00 2001 From: Cesar G <prototech91@gmail.com> Date: Thu, 21 Nov 2013 13:02:26 -0800 Subject: [ticket/11959] Trim the list of users from post notifications. PHPBB3-11959 --- phpBB/language/en/common.php | 3 +++ phpBB/phpbb/notification/type/post.php | 31 +++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index a939689f9c..2b1935dfca 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -416,14 +416,17 @@ $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_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_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_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".', diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 9d5c7b0a4c..0d07df8adf 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -183,6 +183,10 @@ class post extends \phpbb\notification\type\base 'username' => $this->get_data('post_username'), )), $responders); + $responders_cnt = sizeof($responders); + $responders = $this->trim_user_ary($responders); + $extra_cnt = $responders_cnt - sizeof($responders); + foreach ($responders as $responder) { if ($responder['username']) @@ -194,11 +198,18 @@ class post extends \phpbb\notification\type\base $usernames[] = $this->user_loader->get_username($responder['poster_id'], 'no_profile'); } } + $lang_key = $this->language_key; + + if ($responders_cnt > 4) + { + $lang_key .= '_TRIMMED'; + } return $this->user->lang( - $this->language_key, + $lang_key, implode(', ', $usernames), - censor_text($this->get_data('topic_title')) + censor_text($this->get_data('topic_title')), + $extra_cnt ); } @@ -272,6 +283,22 @@ class post extends \phpbb\notification\type\base } } + return $this->trim_user_ary($users); + } + + /** + * Trim the user array passed down to 3 users if the array contains + * more than 4 users. + * + * @param array $users Array of users + * @return array Trimmed array of user_ids + */ + public function trim_user_ary($users) + { + if (sizeof($users) > 4) + { + array_splice($users, 3); + } return $users; } -- cgit v1.2.1 From 43f454a6c6347827a01a1e31478a846ad05bc7f4 Mon Sep 17 00:00:00 2001 From: Cesar G <prototech91@gmail.com> Date: Thu, 21 Nov 2013 13:15:08 -0800 Subject: [ticket/11959] Use COMMA_SEPARATOR to join the user list. PHPBB3-11959 --- phpBB/phpbb/notification/type/post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 0d07df8adf..e9f9d48978 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -207,7 +207,7 @@ class post extends \phpbb\notification\type\base return $this->user->lang( $lang_key, - implode(', ', $usernames), + implode($this->user->lang['COMMA_SEPARATOR'], $usernames), censor_text($this->get_data('topic_title')), $extra_cnt ); -- cgit v1.2.1 From e3a28e5e2a451794b322be90e1aef9ad4aee256b Mon Sep 17 00:00:00 2001 From: Cesar G <prototech91@gmail.com> Date: Thu, 21 Nov 2013 13:18:28 -0800 Subject: [ticket/11959] Rename $extra_cnt to something more descriptive. PHPBB3-11959 --- phpBB/phpbb/notification/type/post.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index e9f9d48978..87bd4331b6 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -185,7 +185,7 @@ class post extends \phpbb\notification\type\base $responders_cnt = sizeof($responders); $responders = $this->trim_user_ary($responders); - $extra_cnt = $responders_cnt - sizeof($responders); + $trimmed_responders_cnt = $responders_cnt - sizeof($responders); foreach ($responders as $responder) { @@ -200,7 +200,7 @@ class post extends \phpbb\notification\type\base } $lang_key = $this->language_key; - if ($responders_cnt > 4) + if ($trimmed_responders_cnt) { $lang_key .= '_TRIMMED'; } @@ -209,7 +209,7 @@ class post extends \phpbb\notification\type\base $lang_key, implode($this->user->lang['COMMA_SEPARATOR'], $usernames), censor_text($this->get_data('topic_title')), - $extra_cnt + $trimmed_responders_cnt ); } -- cgit v1.2.1