From c03d692a98fafa921a832e063c76a3d844632ca7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 Aug 2012 22:57:00 +0200 Subject: [feature/soft-delete] Fix some more usages of _approved column names PHPBB3-9657 --- phpBB/includes/functions_display.php | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'phpBB/includes/functions_display.php') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 881c95907b..2781f1a7bb 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -987,33 +987,25 @@ function display_user_activity(&$userdata) $forum_ary = array(); - // Do not include those forums the user is not having read access to... - $forum_read_ary = $auth->acl_getf('!f_read'); - - foreach ($forum_read_ary as $forum_id => $not_allowed) + $forum_read_ary = $auth->acl_getf('f_read'); + foreach ($forum_read_ary as $forum_id => $allowed) { - if ($not_allowed['f_read']) + if ($allowed['f_read']) { $forum_ary[] = (int) $forum_id; } } - $forum_ary = array_unique($forum_ary); - $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : ''; - - $fid_m_approve = $auth->acl_getf('m_approve', true); - $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', array_keys($fid_m_approve)) : ''; + $forum_ary = array_diff($forum_ary, $user->get_passworded_forums());; // Obtain active forum $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . " + WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND (post_approved = 1 - $sql_m_approve) - $forum_sql + AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' GROUP BY forum_id - ORDER BY num_posts DESC"; + ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); $active_f_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1035,13 +1027,11 @@ function display_user_activity(&$userdata) $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . " + WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND (post_approved = 1 - $sql_m_approve) - $forum_sql_topic + AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' GROUP BY topic_id - ORDER BY num_posts DESC"; + ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); $active_t_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); -- cgit v1.2.1 From 4a65940e6206aef6b85a0aacfb5324ecabf76e12 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Oct 2012 22:14:04 +0200 Subject: [feature/soft-delete] Add unit tests for get_forums_visibility_sql() PHPBB3-9657 --- phpBB/includes/functions_display.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_display.php') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 2781f1a7bb..5849f5cf4c 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1003,7 +1003,7 @@ function display_user_activity(&$userdata) FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' + 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); @@ -1029,7 +1029,7 @@ function display_user_activity(&$userdata) FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' + AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' GROUP BY topic_id ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); -- cgit v1.2.1 From 2841ecc44f2c9773fe3eb19134f52bfcf4beb05e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Oct 2012 12:08:17 +0200 Subject: [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 --- phpBB/includes/functions_display.php | 84 ++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'phpBB/includes/functions_display.php') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 5849f5cf4c..10f07bfbf1 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -996,54 +996,54 @@ function display_user_activity(&$userdata) } } - $forum_ary = array_diff($forum_ary, $user->get_passworded_forums());; - - // Obtain active forum - $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts - 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); + $forum_ary = array_diff($forum_ary, $user->get_passworded_forums()); - if (!empty($active_f_row)) + $active_f_row = $active_t_row = array(); + if (!empty($forum_ary)) { - $sql = 'SELECT forum_name - 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'); + // Obtain active forum + $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts + 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); - } - // Obtain active topic - // 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())); - $forum_sql_topic = (!empty($forum_ary_topic)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary_topic, true) : ''; - - $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts - 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 topic_id - ORDER BY num_posts DESC'; - $result = $db->sql_query_limit($sql, 1); - $active_t_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + if (!empty($active_f_row)) + { + $sql = 'SELECT forum_name + 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); + } - 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'); + // Obtain active topic + $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts + 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 topic_id + ORDER BY num_posts DESC'; + $result = $db->sql_query_limit($sql, 1); + $active_t_row = $db->sql_fetchrow($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; -- cgit v1.2.1 From 6c39563e9f7fad18f1425292dca652861f5e1cb6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 21 Oct 2012 23:38:55 +0200 Subject: [feature/soft-delete] Add a function to calculate the actual post/topic count PHPBB3-9567 --- phpBB/includes/functions_display.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_display.php') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 10f07bfbf1..ed91d9ad1c 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -200,8 +200,9 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } // Count the difference of real to public topics, so we can display an information to moderators - $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0; - $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics']; + $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved']) ? $forum_id : 0; + $row['forum_posts'] = phpbb_content_visibility::get_count('forum_posts', $row, $forum_id); + $row['forum_topics'] = phpbb_content_visibility::get_count('forum_topics', $row, $forum_id); // Display active topics from this forum? if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) -- cgit v1.2.1 From 334265fc839f95d24cce44ec675ae8cef7b4bfaa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 Nov 2012 22:57:49 +0100 Subject: [feature/soft-delete] Fix displaying the button/permission When the post is already softdeleted the options should only be available if *_delete is granted. PHPBB3-9567 --- phpBB/includes/functions_display.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_display.php') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index ed91d9ad1c..6f166e2a14 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -788,7 +788,7 @@ function gen_forum_auth_level($mode, $forum_id, $forum_status) ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'], ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'], ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'], - ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'], + ($user->data['is_registered'] && ($auth->acl_gets('f_delete', 'm_delete', $forum_id) || $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'], ); if ($config['allow_attachments']) -- cgit v1.2.1 From 9aed758c1397c31b979f4aca51249c73d21bd6f5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 14:24:07 +0200 Subject: [ticket/9657] Use the service instead of the static class PHPBB3-9657 --- phpBB/includes/functions_display.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/functions_display.php') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 797ca718d8..143813e4ed 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -22,7 +22,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod { global $db, $auth, $user, $template; global $phpbb_root_path, $phpEx, $config; - global $request, $phpbb_dispatcher; + global $request, $phpbb_dispatcher, $phpbb_container; $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array(); $parent_id = $visible_forums = 0; @@ -149,6 +149,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_tracking_info = array(); $branch_root_id = $root_data['forum_id']; + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + while ($row = $db->sql_fetchrow($result)) { /** @@ -215,8 +217,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod // Count the difference of real to public topics, so we can display an information to moderators $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved']) ? $forum_id : 0; - $row['forum_posts'] = phpbb_content_visibility::get_count('forum_posts', $row, $forum_id); - $row['forum_topics'] = phpbb_content_visibility::get_count('forum_topics', $row, $forum_id); + $row['forum_posts'] = $phpbb_content_visibility->get_count('forum_posts', $row, $forum_id); + $row['forum_topics'] = $phpbb_content_visibility->get_count('forum_topics', $row, $forum_id); // Display active topics from this forum? if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) @@ -1006,7 +1008,7 @@ function display_reasons($reason_id = 0) function display_user_activity(&$userdata) { global $auth, $template, $db, $user; - global $phpbb_root_path, $phpEx; + global $phpbb_root_path, $phpEx, $phpbb_container; // Do not display user activity for users having more than 5000 posts... if ($userdata['user_posts'] > 5000) @@ -1030,12 +1032,14 @@ function display_user_activity(&$userdata) $active_f_row = $active_t_row = array(); if (!empty($forum_ary)) { + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + // Obtain active forum $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' + 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); @@ -1057,7 +1061,7 @@ function display_user_activity(&$userdata) FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' + AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' GROUP BY topic_id ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); -- cgit v1.2.1