From 025de9ee191654825f6ba09a4804e6ef3633b8cb Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 8 Mar 2012 14:57:47 +0800 Subject: [ticket/10684] Send notifications for users with stale bans PHPBB3-10684 --- phpBB/includes/functions_posting.php | 36 +++++++++++++++++++----------------- phpBB/includes/functions_user.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 17 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index f920be9c4b..faf904467f 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1180,28 +1180,23 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id $topic_title = ($topic_notification) ? $topic_title : $subject; $topic_title = censor_text($topic_title); - // Get banned User ID's - $sql = 'SELECT ban_userid - FROM ' . BANLIST_TABLE . ' - WHERE ban_userid <> 0 - AND ban_exclude <> 1'; - $result = $db->sql_query($sql); - - $sql_ignore_users = ANONYMOUS . ', ' . $user->data['user_id']; - while ($row = $db->sql_fetchrow($result)) + // Exclude guests, current user and banned users from notifications + if (!function_exists('phpbb_get_banned_users_ids')) { - $sql_ignore_users .= ', ' . (int) $row['ban_userid']; + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); } - $db->sql_freeresult($result); + $sql_ignore_users = phpbb_get_banned_users_ids(); + $sql_ignore_users[ANONYMOUS] = ANONYMOUS; + $sql_ignore_users[$user->data['user_id']] = $user->data['user_id']; $notify_rows = array(); // -- get forum_userids || topic_userids $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber FROM ' . (($topic_notification) ? TOPICS_WATCH_TABLE : FORUMS_WATCH_TABLE) . ' w, ' . USERS_TABLE . ' u - WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . " - AND w.user_id NOT IN ($sql_ignore_users) - AND w.notify_status = " . NOTIFY_YES . ' + WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . ' + AND ' . $db->sql_in_set('w.user_id', $sql_ignore_users, true) . ' + AND w.notify_status = ' . NOTIFY_YES . ' AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') AND u.user_id = w.user_id'; $result = $db->sql_query($sql); @@ -1225,16 +1220,23 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id // forum notification is sent to those not already receiving topic notifications if ($topic_notification) { + // Add users who has been already notified to ignore list if (sizeof($notify_rows)) { - $sql_ignore_users .= ', ' . implode(', ', array_keys($notify_rows)); + foreach ($notify_rows as $user_id => $row) + { + if (!isset($sql_ignore_users[$user_id])) + { + $sql_ignore_users[$user_id] = $user_id; + } + } } $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u WHERE fw.forum_id = $forum_id - AND fw.user_id NOT IN ($sql_ignore_users) - AND fw.notify_status = " . NOTIFY_YES . ' + AND " . $db->sql_in_set('fw.user_id', $sql_ignore_users, true) . ' + AND fw.notify_status = ' . NOTIFY_YES . ' AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') AND u.user_id = fw.user_id'; $result = $db->sql_query($sql); diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 6b5cca8abb..aea94a0d34 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3587,4 +3587,33 @@ function remove_newly_registered($user_id, $user_data = false) return $user_data['group_id']; } +/** +* Get a list of banned users' ids, ignoring stale buns which were not wiped yet. +* +* @return array Array of banned users' ids if any, empty array otherwise +*/ +function phpbb_get_banned_users_ids() +{ + global $db; + + // Get banned User ID's + // Ignore stale bans which were not wiped yet + $banned_ids_list = array(); + $sql = 'SELECT ban_userid + FROM ' . BANLIST_TABLE . ' + WHERE ban_userid <> 0 + AND ban_exclude <> 1 + AND (ban_end > ' . time() . ' + OR ban_end = 0)'; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $user_id = (int) $row['ban_userid']; + $banned_ids_list[$user_id] = $user_id; + } + $db->sql_freeresult($result); + + return $banned_ids_list; +} + ?> \ No newline at end of file -- cgit v1.2.1 From ee6783109ad7af70665c98d6bbc12d170bc0f892 Mon Sep 17 00:00:00 2001 From: rxu Date: Fri, 9 Mar 2012 16:41:49 +0800 Subject: [ticket/10684] Fix 2 typos in comment lines. PHPBB3-10684 --- phpBB/includes/functions_posting.php | 2 +- phpBB/includes/functions_user.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index faf904467f..ce9762284d 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1220,7 +1220,7 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id // forum notification is sent to those not already receiving topic notifications if ($topic_notification) { - // Add users who has been already notified to ignore list + // Add users who have been already notified to ignore list if (sizeof($notify_rows)) { foreach ($notify_rows as $user_id => $row) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index aea94a0d34..dec8d09082 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3588,7 +3588,7 @@ function remove_newly_registered($user_id, $user_data = false) } /** -* Get a list of banned users' ids, ignoring stale buns which were not wiped yet. +* Get a list of banned users' ids, ignoring stale bans which were not wiped yet. * * @return array Array of banned users' ids if any, empty array otherwise */ -- cgit v1.2.1 From f563647e4b97fc62aa91bc3bf7c81fcc715f17c3 Mon Sep 17 00:00:00 2001 From: rxu Date: Fri, 9 Mar 2012 22:35:13 +0800 Subject: [ticket/10684] Remove isset() for $sql_ignore_users update PHPBB3-10684 --- phpBB/includes/functions_posting.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index ce9762284d..c9b4267c35 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1225,10 +1225,7 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id { foreach ($notify_rows as $user_id => $row) { - if (!isset($sql_ignore_users[$user_id])) - { - $sql_ignore_users[$user_id] = $user_id; - } + $sql_ignore_users[$user_id] = $user_id; } } -- cgit v1.2.1 From 89a6cb2886dfd4659e6db67e27e42c4df763f723 Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 10 Mar 2012 00:17:39 +0800 Subject: [ticket/10684] Refactor $sql_ignore_users array update PHPBB3-10684 --- phpBB/includes/functions_posting.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index c9b4267c35..af26d8ed0f 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1214,21 +1214,15 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id 'method' => $row['user_notify_type'], 'allowed' => false ); + + // Add users who have been already notified to ignore list + $sql_ignore_users[$row['user_id']] = $row['user_id']; } $db->sql_freeresult($result); // forum notification is sent to those not already receiving topic notifications if ($topic_notification) { - // Add users who have been already notified to ignore list - if (sizeof($notify_rows)) - { - foreach ($notify_rows as $user_id => $row) - { - $sql_ignore_users[$user_id] = $user_id; - } - } - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u WHERE fw.forum_id = $forum_id @@ -1272,7 +1266,6 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id } } - // Now, we have to do a little step before really sending, we need to distinguish our users a little bit. ;) $msg_users = $delete_ids = $update_notification = array(); foreach ($notify_rows as $user_id => $row) -- cgit v1.2.1 From a79b3490c2b21d283d7bc1f15c4923180e0f10b2 Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 11 Mar 2012 00:56:07 +0800 Subject: [ticket/10684] Cast user_id to integer PHPBB3-10684 --- phpBB/includes/functions_posting.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index af26d8ed0f..073ce1ff4e 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1203,8 +1203,9 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id while ($row = $db->sql_fetchrow($result)) { - $notify_rows[$row['user_id']] = array( - 'user_id' => $row['user_id'], + $notify_user_id = (int) $row['user_id']; + $notify_rows[$notify_user_id] = array( + 'user_id' => $notify_user_id, 'username' => $row['username'], 'user_email' => $row['user_email'], 'user_jabber' => $row['user_jabber'], @@ -1216,7 +1217,7 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id ); // Add users who have been already notified to ignore list - $sql_ignore_users[$row['user_id']] = $row['user_id']; + $sql_ignore_users[$notify_user_id] = $notify_user_id; } $db->sql_freeresult($result); @@ -1234,8 +1235,9 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id while ($row = $db->sql_fetchrow($result)) { - $notify_rows[$row['user_id']] = array( - 'user_id' => $row['user_id'], + $notify_user_id = (int) $row['user_id']; + $notify_rows[$notify_user_id] = array( + 'user_id' => $notify_user_id, 'username' => $row['username'], 'user_email' => $row['user_email'], 'user_jabber' => $row['user_jabber'], -- cgit v1.2.1 From 321d0d9b56011e049b245b6d54975b6c67b3b15b Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 12 Mar 2012 01:44:00 +0800 Subject: [ticket/10684] Adjust pm_notifications() to handle stale bans - Add parameter (array) to the function phpbb_get_banned_users_ids() - Fix function pm_notification() to handle users with stale bans PHPBB3-10684 --- phpBB/includes/functions_privmsgs.php | 17 ++++++----------- phpBB/includes/functions_user.php | 14 +++++++++----- 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index c40ceb088f..8303fc3754 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1622,6 +1622,7 @@ function pm_notification($mode, $author, $recipients, $subject, $message, $msg_i $subject = censor_text($subject); + // Exclude guests, current user and banned users from notifications unset($recipients[ANONYMOUS], $recipients[$user->data['user_id']]); if (!sizeof($recipients)) @@ -1629,18 +1630,12 @@ function pm_notification($mode, $author, $recipients, $subject, $message, $msg_i return; } - // Get banned User ID's - $sql = 'SELECT ban_userid - FROM ' . BANLIST_TABLE . ' - WHERE ' . $db->sql_in_set('ban_userid', array_map('intval', array_keys($recipients))) . ' - AND ban_exclude = 0'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) + if (!function_exists('phpbb_get_banned_users_ids')) { - unset($recipients[$row['ban_userid']]); + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); } - $db->sql_freeresult($result); + $banned_users = phpbb_get_banned_users_ids(array_keys($recipients)); + $recipients = array_diff(array_map('intval', array_keys($recipients)), $banned_users); if (!sizeof($recipients)) { @@ -1649,7 +1644,7 @@ function pm_notification($mode, $author, $recipients, $subject, $message, $msg_i $sql = 'SELECT user_id, username, user_email, user_lang, user_notify_pm, user_notify_type, user_jabber FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($recipients))); + WHERE ' . $db->sql_in_set('user_id', $recipients); $result = $db->sql_query($sql); $msg_list_ary = array(); diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index dec8d09082..8f40401f0b 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3588,22 +3588,26 @@ function remove_newly_registered($user_id, $user_data = false) } /** -* Get a list of banned users' ids, ignoring stale bans which were not wiped yet. +* Get a list of banned users' ids, ignoring stale bans which were not cleaned yet. * +* @param array $users_ids_array Array of users' ids to check for banning, +* leave empty to get complete list of banned ids * @return array Array of banned users' ids if any, empty array otherwise */ -function phpbb_get_banned_users_ids() +function phpbb_get_banned_users_ids($users_ids_array = array()) { global $db; + $sql_users_ids = (!empty($users_ids_array)) ? $db->sql_in_set('ban_userid', $users_ids_array) : 'ban_userid <> 0'; + // Get banned User ID's // Ignore stale bans which were not wiped yet $banned_ids_list = array(); $sql = 'SELECT ban_userid - FROM ' . BANLIST_TABLE . ' - WHERE ban_userid <> 0 + FROM ' . BANLIST_TABLE . " + WHERE $sql_users_ids AND ban_exclude <> 1 - AND (ban_end > ' . time() . ' + AND (ban_end > " . time() . ' OR ban_end = 0)'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) -- cgit v1.2.1 From da395edbca3e25d1758a6b8c26d14c2e48f112d9 Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 12 Mar 2012 01:47:28 +0800 Subject: [ticket/10684] Remove intval mapping for array keys PHP manual for arrays http://php.net/manual/en/language.types.array.php states that the following key cast will occur: Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. Thus, no intval mapping for numeric array keys is needed. PHPBB3-10684 --- phpBB/includes/functions_privmsgs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 8303fc3754..4ea8f74153 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1635,7 +1635,7 @@ function pm_notification($mode, $author, $recipients, $subject, $message, $msg_i include($phpbb_root_path . 'includes/functions_user.' . $phpEx); } $banned_users = phpbb_get_banned_users_ids(array_keys($recipients)); - $recipients = array_diff(array_map('intval', array_keys($recipients)), $banned_users); + $recipients = array_diff(array_keys($recipients), $banned_users); if (!sizeof($recipients)) { -- cgit v1.2.1 From ff8d5237688beee9ea36848e1ac49565e538c2cd Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 12 Mar 2012 01:57:51 +0800 Subject: [ticket/10684] Rename function phpbb_get_banned_users_ids() parameter PHPBB3-10684 --- phpBB/includes/functions_user.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 8f40401f0b..8c42a5bb42 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3590,15 +3590,15 @@ function remove_newly_registered($user_id, $user_data = false) /** * Get a list of banned users' ids, ignoring stale bans which were not cleaned yet. * -* @param array $users_ids_array Array of users' ids to check for banning, -* leave empty to get complete list of banned ids +* @param array $users_ids Array of users' ids to check for banning, +* leave empty to get complete list of banned ids * @return array Array of banned users' ids if any, empty array otherwise */ -function phpbb_get_banned_users_ids($users_ids_array = array()) +function phpbb_get_banned_users_ids($users_ids = array()) { global $db; - $sql_users_ids = (!empty($users_ids_array)) ? $db->sql_in_set('ban_userid', $users_ids_array) : 'ban_userid <> 0'; + $sql_users_ids = (!empty($users_ids)) ? $db->sql_in_set('ban_userid', $users_ids) : 'ban_userid <> 0'; // Get banned User ID's // Ignore stale bans which were not wiped yet -- cgit v1.2.1 From 5a9dd1994fc20aaebe3145540b630826d7333998 Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 22 Mar 2012 21:19:01 +0800 Subject: [ticket/10684] Adjust function and parameter name, minor changes. PHPBB3-10684 --- phpBB/includes/functions_posting.php | 4 ++-- phpBB/includes/functions_privmsgs.php | 4 ++-- phpBB/includes/functions_user.php | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 073ce1ff4e..7f45b2da8c 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1181,11 +1181,11 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id $topic_title = censor_text($topic_title); // Exclude guests, current user and banned users from notifications - if (!function_exists('phpbb_get_banned_users_ids')) + if (!function_exists('phpbb_get_banned_user_ids')) { include($phpbb_root_path . 'includes/functions_user.' . $phpEx); } - $sql_ignore_users = phpbb_get_banned_users_ids(); + $sql_ignore_users = phpbb_get_banned_user_ids(); $sql_ignore_users[ANONYMOUS] = ANONYMOUS; $sql_ignore_users[$user->data['user_id']] = $user->data['user_id']; diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 4ea8f74153..447920cfd5 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1630,11 +1630,11 @@ function pm_notification($mode, $author, $recipients, $subject, $message, $msg_i return; } - if (!function_exists('phpbb_get_banned_users_ids')) + if (!function_exists('phpbb_get_banned_user_ids')) { include($phpbb_root_path . 'includes/functions_user.' . $phpEx); } - $banned_users = phpbb_get_banned_users_ids(array_keys($recipients)); + $banned_users = phpbb_get_banned_user_ids(array_keys($recipients)); $recipients = array_diff(array_keys($recipients), $banned_users); if (!sizeof($recipients)) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 8c42a5bb42..10fb57ea97 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3588,24 +3588,24 @@ function remove_newly_registered($user_id, $user_data = false) } /** -* Get a list of banned users' ids, ignoring stale bans which were not cleaned yet. +* Gets user ids of currently banned registered users. * -* @param array $users_ids Array of users' ids to check for banning, +* @param array $user_ids Array of users' ids to check for banning, * leave empty to get complete list of banned ids * @return array Array of banned users' ids if any, empty array otherwise */ -function phpbb_get_banned_users_ids($users_ids = array()) +function phpbb_get_banned_user_ids($user_ids = array()) { global $db; - $sql_users_ids = (!empty($users_ids)) ? $db->sql_in_set('ban_userid', $users_ids) : 'ban_userid <> 0'; + $sql_user_ids = (!empty($user_ids)) ? $db->sql_in_set('ban_userid', $user_ids) : 'ban_userid <> 0'; // Get banned User ID's // Ignore stale bans which were not wiped yet $banned_ids_list = array(); $sql = 'SELECT ban_userid FROM ' . BANLIST_TABLE . " - WHERE $sql_users_ids + WHERE $sql_user_ids AND ban_exclude <> 1 AND (ban_end > " . time() . ' OR ban_end = 0)'; -- cgit v1.2.1