1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-06 07:35:29 +02:00

[feature/soft-delete] Fix display_user_activity()

The Logic of $forum_ary was inverted, so if the array is empty, we can skip
the queries. We also should not merge passworded forums into the $forum_ary
as we removed them from that array right before that.

PHPBB3-9567
This commit is contained in:
Joas Schilling 2012-10-09 12:08:17 +02:00
parent 9441774288
commit 2841ecc44f

View File

@ -996,54 +996,54 @@ function display_user_activity(&$userdata)
} }
} }
$forum_ary = array_diff($forum_ary, $user->get_passworded_forums());; $forum_ary = array_diff($forum_ary, $user->get_passworded_forums());
// Obtain active forum $active_f_row = $active_t_row = array();
$sql = 'SELECT forum_id, COUNT(post_id) AS num_posts if (!empty($forum_ary))
FROM ' . POSTS_TABLE . '
WHERE poster_id = ' . $userdata['user_id'] . '
AND post_postcount = 1
AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . '
GROUP BY forum_id
ORDER BY num_posts DESC';
$result = $db->sql_query_limit($sql, 1);
$active_f_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!empty($active_f_row))
{ {
$sql = 'SELECT forum_name // Obtain active forum
FROM ' . FORUMS_TABLE . ' $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
WHERE forum_id = ' . $active_f_row['forum_id']; FROM ' . POSTS_TABLE . '
$result = $db->sql_query($sql, 3600); WHERE poster_id = ' . $userdata['user_id'] . '
$active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name'); AND post_postcount = 1
AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . '
GROUP BY forum_id
ORDER BY num_posts DESC';
$result = $db->sql_query_limit($sql, 1);
$active_f_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
}
// Obtain active topic if (!empty($active_f_row))
// We need to exclude passworded forums here so we do not leak the topic title {
$forum_ary_topic = array_unique(array_merge($forum_ary, $user->get_passworded_forums())); $sql = 'SELECT forum_name
$forum_sql_topic = (!empty($forum_ary_topic)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary_topic, true) : ''; FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $active_f_row['forum_id'];
$result = $db->sql_query($sql, 3600);
$active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
$db->sql_freeresult($result);
}
$sql = 'SELECT topic_id, COUNT(post_id) AS num_posts // Obtain active topic
FROM ' . POSTS_TABLE . ' $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
WHERE poster_id = ' . $userdata['user_id'] . ' FROM ' . POSTS_TABLE . '
AND post_postcount = 1 WHERE poster_id = ' . $userdata['user_id'] . '
AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' AND post_postcount = 1
GROUP BY topic_id AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . '
ORDER BY num_posts DESC'; GROUP BY topic_id
$result = $db->sql_query_limit($sql, 1); ORDER BY num_posts DESC';
$active_t_row = $db->sql_fetchrow($result); $result = $db->sql_query_limit($sql, 1);
$db->sql_freeresult($result); $active_t_row = $db->sql_fetchrow($result);
if (!empty($active_t_row))
{
$sql = 'SELECT topic_title
FROM ' . TOPICS_TABLE . '
WHERE topic_id = ' . $active_t_row['topic_id'];
$result = $db->sql_query($sql);
$active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
$db->sql_freeresult($result); $db->sql_freeresult($result);
if (!empty($active_t_row))
{
$sql = 'SELECT topic_title
FROM ' . TOPICS_TABLE . '
WHERE topic_id = ' . $active_t_row['topic_id'];
$result = $db->sql_query($sql);
$active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
$db->sql_freeresult($result);
}
} }
$userdata['active_t_row'] = $active_t_row; $userdata['active_t_row'] = $active_t_row;