[feature/soft-delete] Lay the groundwork for a soft-delete feature

So far, I've added no new functionality.  The biggest change here is adjusting the DB column names to "visibility" rather than "approved".  Some things here are pretty likely to change, for example the name and location of the topic_visibility class. Happy birthday phpBB :)

PHPBB3-9657
This commit is contained in:
Josh Woody 2010-06-17 23:58:18 -05:00 committed by Joas Schilling
parent 1128ff1e58
commit b8c55291ed
36 changed files with 9164 additions and 9149 deletions

View file

@ -82,6 +82,9 @@ require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
include($phpbb_root_path . 'includes/class_visibility.'.$phpEx);
// Set PHP error handler to ours // Set PHP error handler to ours
set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');

View file

@ -1331,7 +1331,7 @@ function get_schema_struct()
'icon_id' => array('UINT', 0), 'icon_id' => array('UINT', 0),
'poster_ip' => array('VCHAR:40', ''), 'poster_ip' => array('VCHAR:40', ''),
'post_time' => array('TIMESTAMP', 0), 'post_time' => array('TIMESTAMP', 0),
'post_approved' => array('BOOL', 1), 'post_visibility' => array('TINT:3', 0),
'post_reported' => array('BOOL', 0), 'post_reported' => array('BOOL', 0),
'enable_bbcode' => array('BOOL', 1), 'enable_bbcode' => array('BOOL', 1),
'enable_smilies' => array('BOOL', 1), 'enable_smilies' => array('BOOL', 1),
@ -1357,7 +1357,7 @@ function get_schema_struct()
'topic_id' => array('INDEX', 'topic_id'), 'topic_id' => array('INDEX', 'topic_id'),
'poster_ip' => array('INDEX', 'poster_ip'), 'poster_ip' => array('INDEX', 'poster_ip'),
'poster_id' => array('INDEX', 'poster_id'), 'poster_id' => array('INDEX', 'poster_id'),
'post_approved' => array('INDEX', 'post_approved'), 'post_visibility' => array('INDEX', 'post_visibility'),
'post_username' => array('INDEX', 'post_username'), 'post_username' => array('INDEX', 'post_username'),
'tid_post_time' => array('INDEX', array('topic_id', 'post_time')), 'tid_post_time' => array('INDEX', array('topic_id', 'post_time')),
), ),
@ -1673,7 +1673,7 @@ function get_schema_struct()
'forum_id' => array('UINT', 0), 'forum_id' => array('UINT', 0),
'icon_id' => array('UINT', 0), 'icon_id' => array('UINT', 0),
'topic_attachment' => array('BOOL', 0), 'topic_attachment' => array('BOOL', 0),
'topic_approved' => array('BOOL', 1), 'topic_visibility' => array('TINT:3', 0),
'topic_reported' => array('BOOL', 0), 'topic_reported' => array('BOOL', 0),
'topic_title' => array('STEXT_UNI', '', 'true_sort'), 'topic_title' => array('STEXT_UNI', '', 'true_sort'),
'topic_poster' => array('UINT', 0), 'topic_poster' => array('UINT', 0),
@ -1709,8 +1709,8 @@ function get_schema_struct()
'forum_id' => array('INDEX', 'forum_id'), 'forum_id' => array('INDEX', 'forum_id'),
'forum_id_type' => array('INDEX', array('forum_id', 'topic_type')), 'forum_id_type' => array('INDEX', array('forum_id', 'topic_type')),
'last_post_time' => array('INDEX', 'topic_last_post_time'), 'last_post_time' => array('INDEX', 'topic_last_post_time'),
'topic_approved' => array('INDEX', 'topic_approved'), 'topic_visibility' => array('INDEX', 'topic_visibility'),
'forum_appr_last' => array('INDEX', array('forum_id', 'topic_approved', 'topic_last_post_id')), 'forum_appr_last' => array('INDEX', array('forum_id', 'topic_visibility', 'topic_last_post_id')),
'fid_time_moved' => array('INDEX', array('forum_id', 'topic_last_post_time', 'topic_moved_id')), 'fid_time_moved' => array('INDEX', array('forum_id', 'topic_last_post_time', 'topic_moved_id')),
), ),
); );

View file

@ -768,7 +768,7 @@ function get_schema_struct()
'icon_id' => array('UINT', 0), 'icon_id' => array('UINT', 0),
'poster_ip' => array('VCHAR:40', ''), 'poster_ip' => array('VCHAR:40', ''),
'post_time' => array('TIMESTAMP', 0), 'post_time' => array('TIMESTAMP', 0),
'post_approved' => array('BOOL', 1), 'post_visibility' => array('TINT:3', 0),
'post_reported' => array('BOOL', 0), 'post_reported' => array('BOOL', 0),
'enable_bbcode' => array('BOOL', 1), 'enable_bbcode' => array('BOOL', 1),
'enable_smilies' => array('BOOL', 1), 'enable_smilies' => array('BOOL', 1),
@ -794,7 +794,7 @@ function get_schema_struct()
'topic_id' => array('INDEX', 'topic_id'), 'topic_id' => array('INDEX', 'topic_id'),
'poster_ip' => array('INDEX', 'poster_ip'), 'poster_ip' => array('INDEX', 'poster_ip'),
'poster_id' => array('INDEX', 'poster_id'), 'poster_id' => array('INDEX', 'poster_id'),
'post_approved' => array('INDEX', 'post_approved'), 'post_visibility' => array('INDEX', 'post_visibility'),
'post_username' => array('INDEX', 'post_username'), 'post_username' => array('INDEX', 'post_username'),
'tid_post_time' => array('INDEX', array('topic_id', 'post_time')), 'tid_post_time' => array('INDEX', array('topic_id', 'post_time')),
), ),
@ -1107,7 +1107,7 @@ function get_schema_struct()
'forum_id' => array('UINT', 0), 'forum_id' => array('UINT', 0),
'icon_id' => array('UINT', 0), 'icon_id' => array('UINT', 0),
'topic_attachment' => array('BOOL', 0), 'topic_attachment' => array('BOOL', 0),
'topic_approved' => array('BOOL', 1), 'topic_visibility' => array('TINT:3', 0),
'topic_reported' => array('BOOL', 0), 'topic_reported' => array('BOOL', 0),
'topic_title' => array('STEXT_UNI', '', 'true_sort'), 'topic_title' => array('STEXT_UNI', '', 'true_sort'),
'topic_poster' => array('UINT', 0), 'topic_poster' => array('UINT', 0),
@ -1143,8 +1143,8 @@ function get_schema_struct()
'forum_id' => array('INDEX', 'forum_id'), 'forum_id' => array('INDEX', 'forum_id'),
'forum_id_type' => array('INDEX', array('forum_id', 'topic_type')), 'forum_id_type' => array('INDEX', array('forum_id', 'topic_type')),
'last_post_time' => array('INDEX', 'topic_last_post_time'), 'last_post_time' => array('INDEX', 'topic_last_post_time'),
'topic_approved' => array('INDEX', 'topic_approved'), 'topic_visibility' => array('INDEX', 'topic_visibility'),
'forum_appr_last' => array('INDEX', array('forum_id', 'topic_approved', 'topic_last_post_id')), 'forum_appr_last' => array('INDEX', array('forum_id', 'topic_visibility', 'topic_last_post_id')),
'fid_time_moved' => array('INDEX', array('forum_id', 'topic_last_post_time', 'topic_moved_id')), 'fid_time_moved' => array('INDEX', array('forum_id', 'topic_last_post_time', 'topic_moved_id')),
), ),
); );

View file

@ -324,11 +324,7 @@
<p>Please remember that running any application on a developmental version of PHP can lead to strange/unexpected results which may appear to be bugs in the application (which may not be true). Therefore we recommend you upgrade to the newest stable version of PHP before running phpBB3. If you are running a developmental version of PHP please check any bugs you find on a system running a stable release before submitting.</p> <p>Please remember that running any application on a developmental version of PHP can lead to strange/unexpected results which may appear to be bugs in the application (which may not be true). Therefore we recommend you upgrade to the newest stable version of PHP before running phpBB3. If you are running a developmental version of PHP please check any bugs you find on a system running a stable release before submitting.</p>
<<<<<<< HEAD
<p>This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 8.x, Oracle 8, SQLite and Firebird. Versions of PHP used range from 5.3.x to 5.4.x without problem.</p> <p>This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 8.x, Oracle 8, SQLite and Firebird. Versions of PHP used range from 5.3.x to 5.4.x without problem.</p>
=======
<p>This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 7.x, Oracle 8, SQLite 2 and Firebird. Versions of PHP used range from 4.3.3 to 5.4.x without problem. </p>
>>>>>>> develop-olympus
<a name="phpsec"></a><h3>7.i. Notice on PHP security issues</h3> <a name="phpsec"></a><h3>7.i. Notice on PHP security issues</h3>

View file

@ -681,7 +681,7 @@ class phpbb_feed_post_base extends phpbb_feed_base
{ {
$item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row)
. ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('published')]) . ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('published')])
. (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $user->lang['POST_UNAPPROVED'] : ''); . (($this->is_moderator_approve_forum($row['forum_id']) && $row['post_visibility'] !== ITEM_APPROVED) ? ' ' . $this->separator_stats . ' ' . $user->lang['POST_UNAPPROVED'] : '');
} }
} }
} }
@ -760,8 +760,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
AND topic_moved_id = 0 AND topic_moved_id = 0
AND (topic_approved = 1 AND ' . topic_visibility::get_visibility_sql_global('topic') . '
' . $sql_m_approve . ')
ORDER BY topic_last_post_time DESC'; ORDER BY topic_last_post_time DESC';
$result = $db->sql_query_limit($sql, $this->num_items); $result = $db->sql_query_limit($sql, $this->num_items);
@ -783,7 +782,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base
// Get the actual data // Get the actual data
$this->sql = array( $this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, ' . 'SELECT' => 'f.forum_id, f.forum_name, ' .
'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'u.username, u.user_id', 'u.username, u.user_id',
'FROM' => array( 'FROM' => array(
USERS_TABLE => 'u', USERS_TABLE => 'u',
@ -796,8 +795,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base
), ),
), ),
'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . '
AND (p.post_approved = 1 AND ' . topic_visibility::get_visibility_sql('post', array(), 'p.') . '
' . str_replace('forum_id', 'p.forum_id', $sql_m_approve) . ')
AND p.post_time >= ' . $min_post_time . ' AND p.post_time >= ' . $min_post_time . '
AND u.user_id = p.poster_id', AND u.user_id = p.poster_id',
'ORDER_BY' => 'p.post_time DESC', 'ORDER_BY' => 'p.post_time DESC',
@ -894,7 +892,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE forum_id = ' . $this->forum_id . ' WHERE forum_id = ' . $this->forum_id . '
AND topic_moved_id = 0 AND topic_moved_id = 0
' . ((!$m_approve) ? 'AND topic_approved = 1' : '') . ' AND ' . topic_visibility::get_visibility_sql('topic', $this->forum_id) . '
ORDER BY topic_last_post_time DESC'; ORDER BY topic_last_post_time DESC';
$result = $db->sql_query_limit($sql, $this->num_items); $result = $db->sql_query_limit($sql, $this->num_items);
@ -914,14 +912,14 @@ class phpbb_feed_forum extends phpbb_feed_post_base
} }
$this->sql = array( $this->sql = array(
'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'u.username, u.user_id', 'u.username, u.user_id',
'FROM' => array( 'FROM' => array(
POSTS_TABLE => 'p', POSTS_TABLE => 'p',
USERS_TABLE => 'u', USERS_TABLE => 'u',
), ),
'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . '
' . ((!$m_approve) ? 'AND p.post_approved = 1' : '') . ' AND ' . topic_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . '
AND p.post_time >= ' . $min_post_time . ' AND p.post_time >= ' . $min_post_time . '
AND p.poster_id = u.user_id', AND p.poster_id = u.user_id',
'ORDER_BY' => 'p.post_time DESC', 'ORDER_BY' => 'p.post_time DESC',
@ -967,7 +965,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base
{ {
global $auth, $db, $user; global $auth, $db, $user;
$sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_approved, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_type $sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_visibility, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_type
FROM ' . TOPICS_TABLE . ' t FROM ' . TOPICS_TABLE . ' t
LEFT JOIN ' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TABLE . ' f
ON (f.forum_id = t.forum_id) ON (f.forum_id = t.forum_id)
@ -1020,14 +1018,14 @@ class phpbb_feed_topic extends phpbb_feed_post_base
global $auth, $db; global $auth, $db;
$this->sql = array( $this->sql = array(
'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'u.username, u.user_id', 'u.username, u.user_id',
'FROM' => array( 'FROM' => array(
POSTS_TABLE => 'p', POSTS_TABLE => 'p',
USERS_TABLE => 'u', USERS_TABLE => 'u',
), ),
'WHERE' => 'p.topic_id = ' . $this->topic_id . ' 'WHERE' => 'p.topic_id = ' . $this->topic_id . '
' . ($this->forum_id && !$auth->acl_get('m_approve', $this->forum_id) ? 'AND p.post_approved = 1' : '') . ' AND ' . topic_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . '
AND p.poster_id = u.user_id', AND p.poster_id = u.user_id',
'ORDER_BY' => 'p.post_time DESC', 'ORDER_BY' => 'p.post_time DESC',
); );
@ -1163,7 +1161,7 @@ class phpbb_feed_news extends phpbb_feed_topic_base
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . ' WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . '
AND topic_moved_id = 0 AND topic_moved_id = 0
AND topic_approved = 1 AND topic_visibility = ' . ITEM_APPROVED . '
ORDER BY topic_time DESC'; ORDER BY topic_time DESC';
$result = $db->sql_query_limit($sql, $this->num_items); $result = $db->sql_query_limit($sql, $this->num_items);
@ -1233,7 +1231,7 @@ class phpbb_feed_topics extends phpbb_feed_topic_base
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . ' WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . '
AND topic_moved_id = 0 AND topic_moved_id = 0
AND topic_approved = 1 AND topic_visibility = ' . ITEM_APPROVED .'
ORDER BY topic_time DESC'; ORDER BY topic_time DESC';
$result = $db->sql_query_limit($sql, $this->num_items); $result = $db->sql_query_limit($sql, $this->num_items);
@ -1325,7 +1323,7 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . ' WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . '
AND topic_moved_id = 0 AND topic_moved_id = 0
AND topic_approved = 1 AND topic_visibility = ' . ITEM_APPROVED . '
' . $last_post_time_sql . ' ' . $last_post_time_sql . '
ORDER BY topic_last_post_time DESC'; ORDER BY topic_last_post_time DESC';
$result = $db->sql_query_limit($sql, $this->num_items); $result = $db->sql_query_limit($sql, $this->num_items);

View file

@ -314,7 +314,7 @@ class acp_forums
$end = $start + $batch_size; $end = $start + $batch_size;
// Sync all topics in batch mode... // Sync all topics in batch mode...
sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false); sync('topic_visibility', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true); sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
if ($end < $row2['max_topic_id']) if ($end < $row2['max_topic_id'])
@ -1793,7 +1793,7 @@ class acp_forums
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE forum_id = ' . $forum_id . ' WHERE forum_id = ' . $forum_id . '
AND post_postcount = 1 AND post_postcount = 1
AND post_approved = 1'; AND post_visibility = ' . ITEM_APPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$post_counts = array(); $post_counts = array();
@ -1931,7 +1931,7 @@ class acp_forums
// Make sure the overall post/topic count is correct... // Make sure the overall post/topic count is correct...
$sql = 'SELECT COUNT(post_id) AS stat $sql = 'SELECT COUNT(post_id) AS stat
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE post_approved = 1'; WHERE post_visibility = ' . ITEM_APPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -1940,7 +1940,7 @@ class acp_forums
$sql = 'SELECT COUNT(topic_id) AS stat $sql = 'SELECT COUNT(topic_id) AS stat
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE topic_approved = 1'; WHERE topic_visibility = ' . ITEM_APPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);

View file

@ -144,14 +144,14 @@ class acp_main
$sql = 'SELECT COUNT(post_id) AS stat $sql = 'SELECT COUNT(post_id) AS stat
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE post_approved = 1'; WHERE post_visibility = ' . ITEM_APPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
set_config('num_posts', (int) $db->sql_fetchfield('stat'), true); set_config('num_posts', (int) $db->sql_fetchfield('stat'), true);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$sql = 'SELECT COUNT(topic_id) AS stat $sql = 'SELECT COUNT(topic_id) AS stat
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE topic_approved = 1'; WHERE topic_visibility = ' . ITEM_APPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
set_config('num_topics', (int) $db->sql_fetchfield('stat'), true); set_config('num_topics', (int) $db->sql_fetchfield('stat'), true);
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -232,7 +232,7 @@ class acp_main
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . ' WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
AND post_postcount = 1 AND post_approved = 1 AND post_postcount = 1 AND post_visibility = ' . ITEM_APPROVED . '
GROUP BY poster_id'; GROUP BY poster_id';
$result = $db->sql_query($sql); $result = $db->sql_query($sql);

View file

@ -676,7 +676,7 @@ class acp_users
'topic_time' => time(), 'topic_time' => time(),
'forum_id' => $new_forum_id, 'forum_id' => $new_forum_id,
'icon_id' => 0, 'icon_id' => 0,
'topic_approved' => 1, 'topic_visibility' => ITEM_APPROVED,
'topic_title' => $post_ary['title'], 'topic_title' => $post_ary['title'],
'topic_first_poster_name' => $user_row['username'], 'topic_first_poster_name' => $user_row['username'],
'topic_type' => POST_NORMAL, 'topic_type' => POST_NORMAL,
@ -1033,7 +1033,7 @@ class acp_users
$sql = 'SELECT COUNT(post_id) as posts_in_queue $sql = 'SELECT COUNT(post_id) as posts_in_queue
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE poster_id = ' . $user_id . ' WHERE poster_id = ' . $user_id . '
AND post_approved = 0'; AND post_visibility = ' . ITEM_UNAPPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue'); $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
$db->sql_freeresult($result); $db->sql_freeresult($result);

View file

@ -87,6 +87,10 @@ define('ITEM_UNLOCKED', 0);
define('ITEM_LOCKED', 1); define('ITEM_LOCKED', 1);
define('ITEM_MOVED', 2); define('ITEM_MOVED', 2);
define('ITEM_UNAPPROVED', 0); // => has not yet been approved
define('ITEM_APPROVED', 1); // => has been approved, and has not been soft deleted
define('ITEM_DELETED', 2); // => has been soft deleted
// Forum Flags // Forum Flags
define('FORUM_FLAG_LINK_TRACK', 1); define('FORUM_FLAG_LINK_TRACK', 1);
define('FORUM_FLAG_PRUNE_POLL', 2); define('FORUM_FLAG_PRUNE_POLL', 2);

View file

@ -644,7 +644,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s
'posts' => ($call_delete_posts) ? delete_posts($where_type, $where_ids, false, true, $post_count_sync, false) : 0, 'posts' => ($call_delete_posts) ? delete_posts($where_type, $where_ids, false, true, $post_count_sync, false) : 0,
); );
$sql = 'SELECT topic_id, forum_id, topic_approved, topic_moved_id $sql = 'SELECT topic_id, forum_id, topic_visibility, topic_moved_id
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE ' . $where_clause; WHERE ' . $where_clause;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -654,7 +654,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s
$forum_ids[] = $row['forum_id']; $forum_ids[] = $row['forum_id'];
$topic_ids[] = $row['topic_id']; $topic_ids[] = $row['topic_id'];
if ($row['topic_approved'] && !$row['topic_moved_id']) if ($row['topic_visibility'] == ITEM_APPROVED && !$row['topic_moved_id'])
{ {
$approved_topics++; $approved_topics++;
} }
@ -767,7 +767,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
$approved_posts = 0; $approved_posts = 0;
$post_ids = $topic_ids = $forum_ids = $post_counts = $remove_topics = array(); $post_ids = $topic_ids = $forum_ids = $post_counts = $remove_topics = array();
$sql = 'SELECT post_id, poster_id, post_approved, post_postcount, topic_id, forum_id $sql = 'SELECT post_id, poster_id, post_visibility, post_postcount, topic_id, forum_id
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE ' . $where_clause; WHERE ' . $where_clause;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -779,12 +779,12 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
$topic_ids[] = (int) $row['topic_id']; $topic_ids[] = (int) $row['topic_id'];
$forum_ids[] = (int) $row['forum_id']; $forum_ids[] = (int) $row['forum_id'];
if ($row['post_postcount'] && $post_count_sync && $row['post_approved']) if ($row['post_postcount'] && $post_count_sync && $row['post_visibility'] == ITEM_APPROVED)
{ {
$post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1; $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1;
} }
if ($row['post_approved']) if ($row['post_visibility'] == ITEM_APPROVED)
{ {
$approved_posts++; $approved_posts++;
} }
@ -1274,7 +1274,7 @@ function phpbb_unlink($filename, $mode = 'file', $entry_removed = false)
* - forum Resync complete forum * - forum Resync complete forum
* - topic Resync topics * - topic Resync topics
* - topic_moved Removes topic shadows that would be in the same forum as the topic they link to * - topic_moved Removes topic shadows that would be in the same forum as the topic they link to
* - topic_approved Resyncs the topic_approved flag according to the status of the first post * - topic_visibility Resyncs the topic_visibility flag according to the status of the first post
* - post_reported Resyncs the post_reported flag, relying on actual reports * - post_reported Resyncs the post_reported flag, relying on actual reports
* - topic_reported Resyncs the topic_reported flag, relying on post_reported flags * - topic_reported Resyncs the topic_reported flag, relying on post_reported flags
* - post_attachement Same as post_reported, but with attachment flags * - post_attachement Same as post_reported, but with attachment flags
@ -1294,7 +1294,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$where_ids = ($where_ids) ? array((int) $where_ids) : array(); $where_ids = ($where_ids) ? array((int) $where_ids) : array();
} }
if ($mode == 'forum' || $mode == 'topic' || $mode == 'topic_approved' || $mode == 'topic_reported' || $mode == 'post_reported') if ($mode == 'forum' || $mode == 'topic' || $mode == 'topic_visibility' || $mode == 'topic_reported' || $mode == 'post_reported')
{ {
if (!$where_type) if (!$where_type)
{ {
@ -1380,7 +1380,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$db->sql_transaction('commit'); $db->sql_transaction('commit');
break; break;
case 'topic_approved': case 'topic_visibility':
$db->sql_transaction('begin'); $db->sql_transaction('begin');
switch ($db->sql_layer) switch ($db->sql_layer)
@ -1388,22 +1388,22 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
case 'mysql4': case 'mysql4':
case 'mysqli': case 'mysqli':
$sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p $sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
SET t.topic_approved = p.post_approved SET t.topic_visibility = p.post_visibility
$where_sql_and t.topic_first_post_id = p.post_id"; $where_sql_and t.topic_first_post_id = p.post_id";
$db->sql_query($sql); $db->sql_query($sql);
break; break;
default: default:
$sql = 'SELECT t.topic_id, p.post_approved $sql = 'SELECT t.topic_id, p.post_visibility
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
$where_sql_and p.post_id = t.topic_first_post_id $where_sql_and p.post_id = t.topic_first_post_id
AND p.post_approved <> t.topic_approved"; AND p.post_visibility <> t.topic_visibility";
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$topic_ids = array(); $topic_ids = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$topic_ids[] = $row['topic_id']; $topic_ids[$row['topic_id']] = $row['post_visibility'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -1412,10 +1412,13 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
return; return;
} }
$sql = 'UPDATE ' . TOPICS_TABLE . ' foreach ($topic_ids as $topic_id => $visibility)
SET topic_approved = 1 - topic_approved {
WHERE ' . $db->sql_in_set('topic_id', $topic_ids); $sql = 'UPDATE ' . TOPICS_TABLE . '
$db->sql_query($sql); SET topic_visibility = ' . $visibility . '
WHERE topic_id' . $topic_id;
$db->sql_query($sql);
}
break; break;
} }
@ -1680,10 +1683,10 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// 2: Get topic counts for each forum (optional) // 2: Get topic counts for each forum (optional)
if ($sync_extra) if ($sync_extra)
{ {
$sql = 'SELECT forum_id, topic_approved, COUNT(topic_id) AS forum_topics $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS forum_topics
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
GROUP BY forum_id, topic_approved'; GROUP BY forum_id, topic_visibility';
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
@ -1691,7 +1694,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$forum_id = (int) $row['forum_id']; $forum_id = (int) $row['forum_id'];
$forum_data[$forum_id]['topics_real'] += $row['forum_topics']; $forum_data[$forum_id]['topics_real'] += $row['forum_topics'];
if ($row['topic_approved']) if ($row['topic_visibility'] == ITEM_APPROVED)
{ {
$forum_data[$forum_id]['topics'] = $row['forum_topics']; $forum_data[$forum_id]['topics'] = $row['forum_topics'];
} }
@ -1707,7 +1710,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$sql = 'SELECT SUM(t.topic_replies + 1) AS forum_posts $sql = 'SELECT SUM(t.topic_replies + 1) AS forum_posts
FROM ' . TOPICS_TABLE . ' t FROM ' . TOPICS_TABLE . ' t
WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
AND t.topic_approved = 1 AND t.topic_visibility = ' . ITEM_APPROVED . '
AND t.topic_status <> ' . ITEM_MOVED; AND t.topic_status <> ' . ITEM_MOVED;
} }
else else
@ -1715,7 +1718,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$sql = 'SELECT t.forum_id, SUM(t.topic_replies + 1) AS forum_posts $sql = 'SELECT t.forum_id, SUM(t.topic_replies + 1) AS forum_posts
FROM ' . TOPICS_TABLE . ' t FROM ' . TOPICS_TABLE . ' t
WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
AND t.topic_approved = 1 AND t.topic_visibility = ' . ITEM_APPROVED . '
AND t.topic_status <> ' . ITEM_MOVED . ' AND t.topic_status <> ' . ITEM_MOVED . '
GROUP BY t.forum_id'; GROUP BY t.forum_id';
} }
@ -1737,14 +1740,14 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$sql = 'SELECT MAX(t.topic_last_post_id) as last_post_id $sql = 'SELECT MAX(t.topic_last_post_id) as last_post_id
FROM ' . TOPICS_TABLE . ' t FROM ' . TOPICS_TABLE . ' t
WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
AND t.topic_approved = 1'; AND t.topic_visibility = ' . ITEM_APPROVED;
} }
else else
{ {
$sql = 'SELECT t.forum_id, MAX(t.topic_last_post_id) as last_post_id $sql = 'SELECT t.forum_id, MAX(t.topic_last_post_id) as last_post_id
FROM ' . TOPICS_TABLE . ' t FROM ' . TOPICS_TABLE . ' t
WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
AND t.topic_approved = 1 AND t.topic_visibility = ' . ITEM_APPROVED . '
GROUP BY t.forum_id'; GROUP BY t.forum_id';
} }
@ -1846,7 +1849,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$db->sql_transaction('begin'); $db->sql_transaction('begin');
$sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_approved, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time
FROM ' . TOPICS_TABLE . " t FROM ' . TOPICS_TABLE . " t
$where_sql"; $where_sql";
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -1880,10 +1883,10 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// Use "t" as table alias because of the $where_sql clause // Use "t" as table alias because of the $where_sql clause
// NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown. // NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown.
$sql = 'SELECT t.topic_id, t.post_approved, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id $sql = 'SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id
FROM ' . POSTS_TABLE . " t FROM ' . POSTS_TABLE . " t
$where_sql $where_sql
GROUP BY t.topic_id, t.post_approved"; GROUP BY t.topic_id, t.post_visibility";
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
@ -1907,7 +1910,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$topic_data[$topic_id]['replies_real'] += $row['total_posts']; $topic_data[$topic_id]['replies_real'] += $row['total_posts'];
$topic_data[$topic_id]['first_post_id'] = (!$topic_data[$topic_id]['first_post_id']) ? $row['first_post_id'] : min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']); $topic_data[$topic_id]['first_post_id'] = (!$topic_data[$topic_id]['first_post_id']) ? $row['first_post_id'] : min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']);
if ($row['post_approved'] || !$topic_data[$topic_id]['last_post_id']) if ($row['post_visibility'] || !$topic_data[$topic_id]['last_post_id'])
{ {
$topic_data[$topic_id]['replies'] = $row['total_posts'] - 1; $topic_data[$topic_id]['replies'] = $row['total_posts'] - 1;
$topic_data[$topic_id]['last_post_id'] = $row['last_post_id']; $topic_data[$topic_id]['last_post_id'] = $row['last_post_id'];
@ -1952,7 +1955,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
unset($delete_topics, $delete_topic_ids); unset($delete_topics, $delete_topic_ids);
} }
$sql = 'SELECT p.post_id, p.topic_id, p.post_approved, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour $sql = 'SELECT p.post_id, p.topic_id, p.post_visibility, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
AND u.user_id = p.poster_id'; AND u.user_id = p.poster_id';
@ -1965,9 +1968,9 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
if ($row['post_id'] == $topic_data[$topic_id]['first_post_id']) if ($row['post_id'] == $topic_data[$topic_id]['first_post_id'])
{ {
if ($topic_data[$topic_id]['topic_approved'] != $row['post_approved']) if ($topic_data[$topic_id]['topic_visibility'] != $row['post_visibility'])
{ {
$approved_unapproved_ids[] = $topic_id; $approved_unapproved_ids[$topic_id] = $row['post_visibility'];
} }
$topic_data[$topic_id]['time'] = $row['post_time']; $topic_data[$topic_id]['time'] = $row['post_time'];
$topic_data[$topic_id]['poster'] = $row['poster_id']; $topic_data[$topic_id]['poster'] = $row['poster_id'];
@ -2029,7 +2032,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$sync_shadow_topics = array(); $sync_shadow_topics = array();
if (sizeof($post_ids)) if (sizeof($post_ids))
{ {
$sql = 'SELECT p.post_id, p.topic_id, p.post_approved, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour $sql = 'SELECT p.post_id, p.topic_id, p.post_visibility, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
AND u.user_id = p.poster_id'; AND u.user_id = p.poster_id';
@ -2099,10 +2102,14 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// approved becomes unapproved, and vice-versa // approved becomes unapproved, and vice-versa
if (sizeof($approved_unapproved_ids)) if (sizeof($approved_unapproved_ids))
{ {
$sql = 'UPDATE ' . TOPICS_TABLE . ' foreach ($approved_unapproved_ids as $update_topic_id => $status)
SET topic_approved = 1 - topic_approved {
WHERE ' . $db->sql_in_set('topic_id', $approved_unapproved_ids); // @TODO: Consider grouping by $status and only running 3 queries
$db->sql_query($sql); $sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_visibility = ' . $status . '
WHERE topic_id = ' . $update_topic_id;
$db->sql_query($sql);
}
} }
unset($approved_unapproved_ids); unset($approved_unapproved_ids);

View file

@ -1768,7 +1768,7 @@ function sync_post_count($offset, $limit)
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE post_postcount = 1 WHERE post_postcount = 1
AND post_approved = 1 AND post_visibility = ' . ITEM_APPROVED . '
GROUP BY poster_id GROUP BY poster_id
ORDER BY poster_id'; ORDER BY poster_id';
$result = $db->sql_query_limit($sql, $limit, $offset); $result = $db->sql_query_limit($sql, $limit, $offset);
@ -1941,7 +1941,7 @@ function update_dynamic_config()
$sql = 'SELECT COUNT(post_id) AS stat $sql = 'SELECT COUNT(post_id) AS stat
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE post_approved = 1'; WHERE post_visibility = ' . ITEM_APPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -1950,7 +1950,7 @@ function update_dynamic_config()
$sql = 'SELECT COUNT(topic_id) AS stat $sql = 'SELECT COUNT(topic_id) AS stat
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE topic_approved = 1'; WHERE topic_visibility = ' . ITEM_APPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);

View file

@ -176,7 +176,7 @@ function update_post_information($type, $ids, $return_update_sql = false)
if ($type != 'topic') if ($type != 'topic')
{ {
$topic_join = ', ' . TOPICS_TABLE . ' t'; $topic_join = ', ' . TOPICS_TABLE . ' t';
$topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_approved = 1'; $topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_visibility = ' . ITEM_APPROVED;
} }
else else
{ {
@ -190,7 +190,7 @@ function update_post_information($type, $ids, $return_update_sql = false)
FROM ' . POSTS_TABLE . " p $topic_join FROM ' . POSTS_TABLE . " p $topic_join
WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . "
$topic_condition $topic_condition
AND p.post_approved = 1"; AND p.post_visibility = " . ITEM_APPROVED;
} }
else else
{ {
@ -198,7 +198,7 @@ function update_post_information($type, $ids, $return_update_sql = false)
FROM ' . POSTS_TABLE . " p $topic_join FROM ' . POSTS_TABLE . " p $topic_join
WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . "
$topic_condition $topic_condition
AND p.post_approved = 1 AND p.post_visibility = " . ITEM_APPROVED . "
GROUP BY p.{$type}_id"; GROUP BY p.{$type}_id";
} }
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -993,7 +993,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id
$sql = 'SELECT p.post_id $sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p' . " FROM ' . POSTS_TABLE . ' p' . "
WHERE p.topic_id = $topic_id WHERE p.topic_id = $topic_id
" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . ' AND " . topic_visibility::get_visibility_sql('post', $forum_id, 'p.') . '
' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . '
' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . '
ORDER BY p.post_time '; ORDER BY p.post_time ';
@ -1489,7 +1489,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
delete_topics('topic_id', array($topic_id), false); delete_topics('topic_id', array($topic_id), false);
$sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1';
$sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; $sql_data[FORUMS_TABLE] .= ($data['topic_visibility'] == ITEM_APPROVED) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : '';
$update_sql = update_post_information('forum', $forum_id, true); $update_sql = update_post_information('forum', $forum_id, true);
if (sizeof($update_sql)) if (sizeof($update_sql))
@ -1509,18 +1509,18 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : '';
$sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time']; $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time'];
// Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply" // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply"
$sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : '');
$next_post_id = (int) $row['post_id']; $next_post_id = (int) $row['post_id'];
break; break;
case 'delete_last_post': case 'delete_last_post':
$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : '';
$update_sql = update_post_information('forum', $forum_id, true); $update_sql = update_post_information('forum', $forum_id, true);
if (sizeof($update_sql)) if (sizeof($update_sql))
@ -1529,7 +1529,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
$sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
} }
$sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : '');
$update_sql = update_post_information('topic', $topic_id, true); $update_sql = update_post_information('topic', $topic_id, true);
if (sizeof($update_sql)) if (sizeof($update_sql))
@ -1541,8 +1541,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
{ {
$sql = 'SELECT MAX(post_id) as last_post_id $sql = 'SELECT MAX(post_id) as last_post_id
FROM ' . POSTS_TABLE . " FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id " . WHERE topic_id = $topic_id
((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : ''); AND " . topic_visibility::get_visibility_sql('post', $forum_id);
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -1554,17 +1554,17 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
case 'delete': case 'delete':
$sql = 'SELECT post_id $sql = 'SELECT post_id
FROM ' . POSTS_TABLE . " FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id " . WHERE topic_id = $topic_id
((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : '') . ' AND " . topic_visibility::get_visibility_sql('post', $forum_id) . '
AND post_time > ' . $data['post_time'] . ' AND post_time > ' . $data['post_time'] . '
ORDER BY post_time ASC'; ORDER BY post_time ASC';
$result = $db->sql_query_limit($sql, 1); $result = $db->sql_query_limit($sql, 1);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : '';
$sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : '');
$next_post_id = (int) $row['post_id']; $next_post_id = (int) $row['post_id'];
break; break;
} }
@ -1674,9 +1674,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
$poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id']; $poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id'];
// Retrieve some additional information if not present // Retrieve some additional information if not present
if ($mode == 'edit' && (!isset($data['post_approved']) || !isset($data['topic_approved']) || $data['post_approved'] === false || $data['topic_approved'] === false)) if ($mode == 'edit' && (!isset($data['post_visibility']) || !isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false))
{ {
$sql = 'SELECT p.post_approved, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_approved $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_visibility
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
WHERE t.topic_id = p.topic_id WHERE t.topic_id = p.topic_id
AND p.post_id = ' . $data['post_id']; AND p.post_id = ' . $data['post_id'];
@ -1684,8 +1684,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
$topic_row = $db->sql_fetchrow($result); $topic_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$data['topic_approved'] = $topic_row['topic_approved']; $data['topic_visibility'] = $topic_row['topic_visibility'];
$data['post_approved'] = $topic_row['post_approved']; $data['post_visibility'] = $topic_row['post_visibility'];
} }
// This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval
@ -1719,7 +1719,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
'icon_id' => $data['icon_id'], 'icon_id' => $data['icon_id'],
'poster_ip' => $user->ip, 'poster_ip' => $user->ip,
'post_time' => $current_time, 'post_time' => $current_time,
'post_approved' => $post_approval, 'post_visibility' => $post_approval,
'enable_bbcode' => $data['enable_bbcode'], 'enable_bbcode' => $data['enable_bbcode'],
'enable_smilies' => $data['enable_smilies'], 'enable_smilies' => $data['enable_smilies'],
'enable_magic_url' => $data['enable_urls'], 'enable_magic_url' => $data['enable_urls'],
@ -1785,7 +1785,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
'forum_id' => $data['forum_id'], 'forum_id' => $data['forum_id'],
'poster_id' => $data['poster_id'], 'poster_id' => $data['poster_id'],
'icon_id' => $data['icon_id'], 'icon_id' => $data['icon_id'],
'post_approved' => (!$post_approval) ? 0 : $data['post_approved'], 'post_visibility' => (!$post_approval) ? 0 : $data['post_visibility'],
'enable_bbcode' => $data['enable_bbcode'], 'enable_bbcode' => $data['enable_bbcode'],
'enable_smilies' => $data['enable_smilies'], 'enable_smilies' => $data['enable_smilies'],
'enable_magic_url' => $data['enable_urls'], 'enable_magic_url' => $data['enable_urls'],
@ -1807,7 +1807,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
break; break;
} }
$post_approved = $sql_data[POSTS_TABLE]['sql']['post_approved']; $post_approved = $sql_data[POSTS_TABLE]['sql']['post_visibility'];
$topic_row = array(); $topic_row = array();
// And the topic ladies and gentlemen // And the topic ladies and gentlemen
@ -1820,7 +1820,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
'topic_last_view_time' => $current_time, 'topic_last_view_time' => $current_time,
'forum_id' => $data['forum_id'], 'forum_id' => $data['forum_id'],
'icon_id' => $data['icon_id'], 'icon_id' => $data['icon_id'],
'topic_approved' => $post_approval, 'topic_visibility' => $post_approval,
'topic_title' => $subject, 'topic_title' => $subject,
'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''),
'topic_first_poster_colour' => $user->data['user_colour'], 'topic_first_poster_colour' => $user->data['user_colour'],
@ -1897,7 +1897,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
$sql_data[TOPICS_TABLE]['sql'] = array( $sql_data[TOPICS_TABLE]['sql'] = array(
'forum_id' => $data['forum_id'], 'forum_id' => $data['forum_id'],
'icon_id' => $data['icon_id'], 'icon_id' => $data['icon_id'],
'topic_approved' => (!$post_approval) ? 0 : $data['topic_approved'], 'topic_visibility' => (!$post_approval) ? 0 : $data['topic_visibility'],
'topic_title' => $subject, 'topic_title' => $subject,
'topic_first_poster_name' => $username, 'topic_first_poster_name' => $username,
'topic_type' => $topic_type, 'topic_type' => $topic_type,
@ -1913,12 +1913,12 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
); );
// Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved
if (!$post_approval && $data['topic_approved']) if (!$post_approval && $data['topic_visibility'] == ITEM_APPROVED)
{ {
// Do we need to grab some topic informations? // Do we need to grab some topic informations?
if (!sizeof($topic_row)) if (!sizeof($topic_row))
{ {
$sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_approved $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_visibility
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE topic_id = ' . $data['topic_id']; WHERE topic_id = ' . $data['topic_id'];
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -1949,7 +1949,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
case 'edit_last_post': case 'edit_last_post':
// Correctly set back the topic replies and forum posts... but only if the post was approved before. // Correctly set back the topic replies and forum posts... but only if the post was approved before.
if (!$post_approval && $data['post_approved']) if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED)
{ {
$sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time;
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1';
@ -2173,7 +2173,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
// we need to update the last forum information // we need to update the last forum information
// only applicable if the topic is approved // only applicable if the topic is approved
if ($post_approved || !$data['post_approved']) if ($post_approved || $data['post_visibility'] != ITEM_APPROVED)
{ {
// the last post makes us update the forum table. This can happen if... // the last post makes us update the forum table. This can happen if...
// We make a new topic // We make a new topic
@ -2219,13 +2219,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'";
} }
} }
else if ($data['post_approved'] !== $post_approved) else if ($data['post_visibility'] !== $post_approved)
{ {
// we need a fresh change of socks, everything has become invalidated // we need a fresh change of socks, everything has become invalidated
$sql = 'SELECT MAX(topic_last_post_id) as last_post_id $sql = 'SELECT MAX(topic_last_post_id) as last_post_id
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE forum_id = ' . (int) $data['forum_id'] . ' WHERE forum_id = ' . (int) $data['forum_id'] . '
AND topic_approved = 1'; AND topic_visibility = ' . ITEM_APPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -2290,13 +2290,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
} }
} }
} }
else if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) else if (!$data['post_visibility'] == ITEM_APPROVED && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])))
{ {
// like having the rug pulled from under us // like having the rug pulled from under us
$sql = 'SELECT MAX(post_id) as last_post_id $sql = 'SELECT MAX(post_id) as last_post_id
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE topic_id = ' . (int) $data['topic_id'] . ' WHERE topic_id = ' . (int) $data['topic_id'] . '
AND post_approved = 1'; AND post_visibility = ' . ITEM_APPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);

View file

@ -154,7 +154,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
$sql = 'SELECT t.topic_id $sql = 'SELECT t.topic_id
FROM ' . TOPICS_TABLE . ' t FROM ' . TOPICS_TABLE . ' t
WHERE t.forum_id = ' . $forum_id . ' WHERE t.forum_id = ' . $forum_id . '
' . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . " ' . topic_visibility::get_visibility_sql('topic', $forum_id, 't.') . "
$limit_time_sql $limit_time_sql
ORDER BY t.topic_type DESC, $sort_order_sql"; ORDER BY t.topic_type DESC, $sort_order_sql";
$result = $db->sql_query_limit($sql, $topics_per_page, $start); $result = $db->sql_query_limit($sql, $topics_per_page, $start);
@ -220,9 +220,10 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
$topic_title = censor_text($row['topic_title']); $topic_title = censor_text($row['topic_title']);
$topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false;
$posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false;
$u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&amp;i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&amp;t=' . $row['topic_id'] : ''; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&amp;i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&amp;t=' . $row['topic_id'] : '';
$topic_deleted = ($row['topic_visibility'] == ITEM_DELETED) ? true : false;
$topic_row = array( $topic_row = array(
'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
@ -232,6 +233,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '', 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
'DELETED_IMG' => ($topic_deleted) ? $user->img(/*TODO*/) : '',
'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
@ -254,7 +256,9 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && empty($row['topic_moved_id']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false, 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && empty($row['topic_moved_id']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false,
'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved,
'S_TOPIC_DELETED' => $topic_deleted,
'S_UNREAD_TOPIC' => $unread_topic, 'S_UNREAD_TOPIC' => $unread_topic,
); );
if ($row['topic_status'] == ITEM_MOVED) if ($row['topic_status'] == ITEM_MOVED)

View file

@ -39,7 +39,7 @@ function mcp_front_view($id, $mode, $action)
$sql = 'SELECT COUNT(post_id) AS total $sql = 'SELECT COUNT(post_id) AS total
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list) . '
AND post_approved = 0'; AND post_visibility = ' . ITEM_UNAPPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$total = (int) $db->sql_fetchfield('total'); $total = (int) $db->sql_fetchfield('total');
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -60,7 +60,7 @@ function mcp_front_view($id, $mode, $action)
$sql = 'SELECT post_id $sql = 'SELECT post_id
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list) . '
AND post_approved = 0 AND post_visibility = ' . ITEM_UNAPPROVED . '
ORDER BY post_time DESC'; ORDER BY post_time DESC';
$result = $db->sql_query_limit($sql, 5); $result = $db->sql_query_limit($sql, 5);

View file

@ -475,7 +475,7 @@ function mcp_move_topic($topic_ids)
foreach ($topic_data as $topic_id => $topic_info) foreach ($topic_data as $topic_id => $topic_info)
{ {
if ($topic_info['topic_approved']) if ($topic_info['topic_visibility'] == ITEM_APPROVED)
{ {
$topics_authed_moved++; $topics_authed_moved++;
$topic_posts_added++; $topic_posts_added++;
@ -486,7 +486,7 @@ function mcp_move_topic($topic_ids)
$topics_removed++; $topics_removed++;
$topic_posts_removed += $topic_info['topic_replies']; $topic_posts_removed += $topic_info['topic_replies'];
if ($topic_info['topic_approved']) if ($topic_info['topic_visibility'] == ITEM_APPROVED)
{ {
$topics_authed_removed++; $topics_authed_removed++;
$topic_posts_removed++; $topic_posts_removed++;
@ -528,13 +528,13 @@ function mcp_move_topic($topic_ids)
add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']); add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']);
// Leave a redirection if required and only if the topic is visible to users // Leave a redirection if required and only if the topic is visible to users
if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL) if ($leave_shadow && $row['topic_visibility'] == ITEM_APPROVED && $row['topic_type'] != POST_GLOBAL)
{ {
$shadow = array( $shadow = array(
'forum_id' => (int) $row['forum_id'], 'forum_id' => (int) $row['forum_id'],
'icon_id' => (int) $row['icon_id'], 'icon_id' => (int) $row['icon_id'],
'topic_attachment' => (int) $row['topic_attachment'], 'topic_attachment' => (int) $row['topic_attachment'],
'topic_approved' => 1, // a shadow topic is always approved 'topic_visibliity' => ITEM_APPROVED, // a shadow topic is always approved
'topic_reported' => 0, // a shadow topic is never reported 'topic_reported' => 0, // a shadow topic is never reported
'topic_title' => (string) $row['topic_title'], 'topic_title' => (string) $row['topic_title'],
'topic_poster' => (int) $row['topic_poster'], 'topic_poster' => (int) $row['topic_poster'],
@ -932,7 +932,7 @@ function mcp_fork_topic($topic_ids)
'forum_id' => (int) $to_forum_id, 'forum_id' => (int) $to_forum_id,
'icon_id' => (int) $topic_row['icon_id'], 'icon_id' => (int) $topic_row['icon_id'],
'topic_attachment' => (int) $topic_row['topic_attachment'], 'topic_attachment' => (int) $topic_row['topic_attachment'],
'topic_approved' => 1, 'topic_visibility' => ITEM_APPROVED,
'topic_reported' => 0, 'topic_reported' => 0,
'topic_title' => (string) $topic_row['topic_title'], 'topic_title' => (string) $topic_row['topic_title'],
'topic_poster' => (int) $topic_row['topic_poster'], 'topic_poster' => (int) $topic_row['topic_poster'],
@ -1009,7 +1009,7 @@ function mcp_fork_topic($topic_ids)
'icon_id' => (int) $row['icon_id'], 'icon_id' => (int) $row['icon_id'],
'poster_ip' => (string) $row['poster_ip'], 'poster_ip' => (string) $row['poster_ip'],
'post_time' => (int) $row['post_time'], 'post_time' => (int) $row['post_time'],
'post_approved' => 1, 'post_visibility' => ITEM_APPROVED,
'post_reported' => 0, 'post_reported' => 0,
'enable_bbcode' => (int) $row['enable_bbcode'], 'enable_bbcode' => (int) $row['enable_bbcode'],
'enable_smilies' => (int) $row['enable_smilies'], 'enable_smilies' => (int) $row['enable_smilies'],

View file

@ -185,7 +185,7 @@ function mcp_post_details($id, $mode, $action)
'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']), 'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']),
'S_POST_REPORTED' => ($post_info['post_reported']) ? true : false, 'S_POST_REPORTED' => ($post_info['post_reported']) ? true : false,
'S_POST_UNAPPROVED' => (!$post_info['post_approved']) ? true : false, 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED) ? true : false,
'S_POST_LOCKED' => ($post_info['post_edit_locked']) ? true : false, 'S_POST_LOCKED' => ($post_info['post_edit_locked']) ? true : false,
'S_USER_NOTES' => true, 'S_USER_NOTES' => true,
'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false, 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false,
@ -415,7 +415,7 @@ function change_poster(&$post_info, $userdata)
} }
// Adjust post counts... only if the post is approved (else, it was not added the users post count anyway) // Adjust post counts... only if the post is approved (else, it was not added the users post count anyway)
if ($post_info['post_postcount'] && $post_info['post_approved']) if ($post_info['post_postcount'] && $post_info['post_visibility'] == ITEM_APPROVED)
{ {
$sql = 'UPDATE ' . USERS_TABLE . ' $sql = 'UPDATE ' . USERS_TABLE . '
SET user_posts = user_posts - 1 SET user_posts = user_posts - 1

View file

@ -183,7 +183,7 @@ class mcp_queue
'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f=$forum_id"), 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f=$forum_id"),
'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']),
'S_POST_REPORTED' => $post_info['post_reported'], 'S_POST_REPORTED' => $post_info['post_reported'],
'S_POST_UNAPPROVED' => !$post_info['post_approved'], 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED) ,
'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_POST_LOCKED' => $post_info['post_edit_locked'],
'S_USER_NOTES' => true, 'S_USER_NOTES' => true,
@ -309,7 +309,7 @@ class mcp_queue
$sql = 'SELECT p.post_id $sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . ' FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . '
WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . ' WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . '
AND p.post_approved = 0 AND p.post_visibility = ' . ITEM_UNAPPROVED . '
' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
AND t.topic_id = p.topic_id AND t.topic_id = p.topic_id
@ -361,7 +361,7 @@ class mcp_queue
$sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_attachment AS post_attachment, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_attachment AS post_attachment, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour
FROM ' . TOPICS_TABLE . " t FROM ' . TOPICS_TABLE . " t
WHERE " . $db->sql_in_set('forum_id', $forum_list) . " WHERE " . $db->sql_in_set('forum_id', $forum_list) . "
AND topic_approved = 0 AND topic_visibility = " . ITEM_UNAPPROVED . "
$limit_time_sql $limit_time_sql
ORDER BY $sort_order_sql"; ORDER BY $sort_order_sql";
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
@ -484,7 +484,7 @@ function approve_post($post_id_list, $id, $mode)
foreach ($post_info as $post_id => $post_data) foreach ($post_info as $post_id => $post_data)
{ {
if ($post_data['post_approved']) if ($post_data['post_visibility'] == ITEM_APPROVED)
{ {
$post_approved_list[] = $post_id; $post_approved_list[] = $post_id;
continue; continue;
@ -544,7 +544,7 @@ function approve_post($post_id_list, $id, $mode)
if (sizeof($topic_approve_sql)) if (sizeof($topic_approve_sql))
{ {
$sql = 'UPDATE ' . TOPICS_TABLE . ' $sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_approved = 1 SET topic_visibility = ' . ITEM_APPROVED . '
WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql); WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql);
$db->sql_query($sql); $db->sql_query($sql);
} }
@ -552,7 +552,7 @@ function approve_post($post_id_list, $id, $mode)
if (sizeof($post_approve_sql)) if (sizeof($post_approve_sql))
{ {
$sql = 'UPDATE ' . POSTS_TABLE . ' $sql = 'UPDATE ' . POSTS_TABLE . '
SET post_approved = 1 SET post_visibility = ' . ITEM_APPROVED . '
WHERE ' . $db->sql_in_set('post_id', $post_approve_sql); WHERE ' . $db->sql_in_set('post_id', $post_approve_sql);
$db->sql_query($sql); $db->sql_query($sql);
} }

View file

@ -190,7 +190,7 @@ class mcp_reports
'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id), 'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id),
'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']),
'S_POST_REPORTED' => $post_info['post_reported'], 'S_POST_REPORTED' => $post_info['post_reported'],
'S_POST_UNAPPROVED' => !$post_info['post_approved'], 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == POST_UNAPPROVED),
'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_POST_LOCKED' => $post_info['post_edit_locked'],
'S_USER_NOTES' => true, 'S_USER_NOTES' => true,

View file

@ -145,8 +145,8 @@ function mcp_topic_view($id, $mode, $action)
$sql = 'SELECT u.username, u.username_clean, u.user_colour, p.* $sql = 'SELECT u.username, u.username_clean, u.user_colour, p.*
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . ' WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . '
p.topic_id = ' . $topic_id . ' ' . p.topic_id = ' . $topic_id . '
((!$auth->acl_get('m_approve', $topic_info['forum_id'])) ? ' AND p.post_approved = 1 ' : '') . ' AND ' . topic_visibility::get_visibility_sql('post', $topic_info['forum_id'], 'p.') . '
AND p.poster_id = u.user_id ' . AND p.poster_id = u.user_id ' .
$limit_time_sql . ' $limit_time_sql . '
ORDER BY ' . $sort_order_sql; ORDER BY ' . $sort_order_sql;
@ -227,7 +227,7 @@ function mcp_topic_view($id, $mode, $action)
parse_attachments($topic_info['forum_id'], $message, $attachments[$row['post_id']], $update_count); parse_attachments($topic_info['forum_id'], $message, $attachments[$row['post_id']], $update_count);
} }
if (!$row['post_approved']) if ($row['post_visibility'] == ITEM_UNAPPROVED)
{ {
$has_unapproved_posts = true; $has_unapproved_posts = true;
} }
@ -249,7 +249,7 @@ function mcp_topic_view($id, $mode, $action)
'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $topic_info['forum_id'])), 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $topic_info['forum_id'])),
'S_POST_UNAPPROVED' => (!$row['post_approved'] && $auth->acl_get('m_approve', $topic_info['forum_id'])), 'S_POST_UNAPPROVED' => ($row['post_visibility'] != ITEM_APPROVED && $auth->acl_get('m_approve', $topic_info['forum_id'])),
'S_CHECKED' => (($submitted_id_list && !in_array(intval($row['post_id']), $submitted_id_list)) || in_array(intval($row['post_id']), $checked_ids)) ? true : false, 'S_CHECKED' => (($submitted_id_list && !in_array(intval($row['post_id']), $submitted_id_list)) || in_array(intval($row['post_id']), $checked_ids)) ? true : false,
'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false, 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
@ -448,7 +448,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject)
if ($sort_order_sql[0] == 'u') if ($sort_order_sql[0] == 'u')
{ {
$sql = 'SELECT p.post_id, p.forum_id, p.post_approved $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
WHERE p.topic_id = $topic_id WHERE p.topic_id = $topic_id
AND p.poster_id = u.user_id AND p.poster_id = u.user_id
@ -457,7 +457,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject)
} }
else else
{ {
$sql = 'SELECT p.post_id, p.forum_id, p.post_approved $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
FROM ' . POSTS_TABLE . " p FROM ' . POSTS_TABLE . " p
WHERE p.topic_id = $topic_id WHERE p.topic_id = $topic_id
$limit_time_sql $limit_time_sql
@ -470,7 +470,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject)
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
// If split from selected post (split_beyond), we split the unapproved items too. // If split from selected post (split_beyond), we split the unapproved items too.
if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) if ($row['post_visibility'] == ITEM_UNAPPROVED && !$auth->acl_get('m_approve', $row['forum_id']))
{ {
// continue; // continue;
} }
@ -497,10 +497,10 @@ function split_topic($action, $topic_id, $to_forum_id, $subject)
$icon_id = request_var('icon', 0); $icon_id = request_var('icon', 0);
$sql_ary = array( $sql_ary = array(
'forum_id' => $to_forum_id, 'forum_id' => $to_forum_id,
'topic_title' => $subject, 'topic_title' => $subject,
'icon_id' => $icon_id, 'icon_id' => $icon_id,
'topic_approved'=> 1 'topic_visibility' => 1
); );
$sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);

View file

@ -265,7 +265,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
* @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_dir is either a or d representing ASC and DESC
* @param string $sort_days specifies the maximum amount of days a post may be old * @param string $sort_days specifies the maximum amount of days a post may be old
* @param array $ex_fid_ary specifies an array of forum ids which should not be searched * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
* @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts * @param array $m_approve_fid_sql specifies which types of posts a user may view, based on permissions
* @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
* @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty
* @param string $author_name specifies the author match, when ANONYMOUS is also a search-match * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
@ -292,7 +292,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$sort_key, $sort_key,
$topic_id, $topic_id,
implode(',', $ex_fid_ary), implode(',', $ex_fid_ary),
implode(',', $m_approve_fid_ary), // @TODO implode(',', $m_approve_fid_ary),
implode(',', $author_ary) implode(',', $author_ary)
))); )));
@ -354,7 +354,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
break; break;
} }
if (!sizeof($m_approve_fid_ary)) /* if (!sizeof($m_approve_fid_ary))
{ {
$m_approve_fid_sql = ' AND p.post_approved = 1'; $m_approve_fid_sql = ' AND p.post_approved = 1';
} }
@ -366,6 +366,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
{ {
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
} }
*/
$sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : ''; $sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : '';
$sql_select = ($type == 'posts') ? $sql_select . 'p.post_id' : 'DISTINCT ' . $sql_select . 't.topic_id'; $sql_select = ($type == 'posts') ? $sql_select . 'p.post_id' : 'DISTINCT ' . $sql_select . 't.topic_id';
@ -445,7 +446,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
* @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_dir is either a or d representing ASC and DESC
* @param string $sort_days specifies the maximum amount of days a post may be old * @param string $sort_days specifies the maximum amount of days a post may be old
* @param array $ex_fid_ary specifies an array of forum ids which should not be searched * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
* @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts * @param array $m_approve_fid_sql specifies which types of posts a user may view, based on permissions
* @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
* @param array $author_ary an array of author ids * @param array $author_ary an array of author ids
* @param string $author_name specifies the author match, when ANONYMOUS is also a search-match * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
@ -473,7 +474,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$sort_key, $sort_key,
$topic_id, $topic_id,
implode(',', $ex_fid_ary), implode(',', $ex_fid_ary),
implode(',', $m_approve_fid_ary), // @TODO implode(',', $m_approve_fid_ary),
implode(',', $author_ary), implode(',', $author_ary),
$author_name, $author_name,
))); )));
@ -523,7 +524,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
break; break;
} }
if (!sizeof($m_approve_fid_ary)) /* if (!sizeof($m_approve_fid_ary))
{ {
$m_approve_fid_sql = ' AND p.post_approved = 1'; $m_approve_fid_sql = ' AND p.post_approved = 1';
} }
@ -535,6 +536,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
{ {
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
} }
*/
// If the cache was completely empty count the results // If the cache was completely empty count the results
$calc_results = ($result_count) ? '' : 'SQL_CALC_FOUND_ROWS '; $calc_results = ($result_count) ? '' : 'SQL_CALC_FOUND_ROWS ';

View file

@ -414,7 +414,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
* @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_dir is either a or d representing ASC and DESC
* @param string $sort_days specifies the maximum amount of days a post may be old * @param string $sort_days specifies the maximum amount of days a post may be old
* @param array $ex_fid_ary specifies an array of forum ids which should not be searched * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
* @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts * @param array $m_approve_fid_sql specifies which types of posts the user can view
* @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
* @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty
* @param string $author_name specifies the author match, when ANONYMOUS is also a search-match * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
@ -451,7 +451,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$sort_key, $sort_key,
$topic_id, $topic_id,
implode(',', $ex_fid_ary), implode(',', $ex_fid_ary),
implode(',', $m_approve_fid_ary), // @TODO implode(',', $m_approve_fid_ary),
implode(',', $author_ary), implode(',', $author_ary),
$author_name, $author_name,
))); )));
@ -628,7 +628,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$sql_where[] = '(' . implode(' OR ', $is_null_joins) . ')'; $sql_where[] = '(' . implode(' OR ', $is_null_joins) . ')';
} }
if (!sizeof($m_approve_fid_ary)) /* if (!sizeof($m_approve_fid_ary))
{ {
$sql_where[] = 'p.post_approved = 1'; $sql_where[] = 'p.post_approved = 1';
} }
@ -636,6 +636,8 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{ {
$sql_where[] = '(p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; $sql_where[] = '(p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
} }
*/
$sql_where[] = $m_approve_fid_sql;
if ($topic_id) if ($topic_id)
{ {
@ -808,7 +810,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
* @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_dir is either a or d representing ASC and DESC
* @param string $sort_days specifies the maximum amount of days a post may be old * @param string $sort_days specifies the maximum amount of days a post may be old
* @param array $ex_fid_ary specifies an array of forum ids which should not be searched * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
* @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts * @param array $m_approve_fid_sql specifies which posts a user can view, based on permissions
* @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
* @param array $author_ary an array of author ids * @param array $author_ary an array of author ids
* @param string $author_name specifies the author match, when ANONYMOUS is also a search-match * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
@ -836,7 +838,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$sort_key, $sort_key,
$topic_id, $topic_id,
implode(',', $ex_fid_ary), implode(',', $ex_fid_ary),
implode(',', $m_approve_fid_ary), // @TODO implode(',', $m_approve_fid_ary),
implode(',', $author_ary), implode(',', $author_ary),
$author_name, $author_name,
))); )));
@ -886,7 +888,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
break; break;
} }
if (!sizeof($m_approve_fid_ary)) /* if (!sizeof($m_approve_fid_ary))
{ {
$m_approve_fid_sql = ' AND p.post_approved = 1'; $m_approve_fid_sql = ' AND p.post_approved = 1';
} }
@ -898,6 +900,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{ {
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
} }
*/
$select = ($type == 'posts') ? 'p.post_id' : 't.topic_id'; $select = ($type == 'posts') ? 'p.post_id' : 't.topic_id';
$is_mysql = false; $is_mysql = false;

View file

@ -1465,7 +1465,7 @@ class install_convert extends module
$end = ($sync_batch + $batch_size - 1); $end = ($sync_batch + $batch_size - 1);
// Sync all topics in batch mode... // Sync all topics in batch mode...
sync('topic_approved', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, false); sync('topic_visibility', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, false);
sync('topic', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, true); sync('topic', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, true);
$template->assign_block_vars('checks', array( $template->assign_block_vars('checks', array(

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -314,6 +314,7 @@ INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_subscribe', 1);
INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_user_lock', 1); INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_user_lock', 1);
INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_vote', 1); INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_vote', 1);
INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_votechg', 1); INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_votechg', 1);
INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_restore', 1);
# -- Moderator related auth options # -- Moderator related auth options
INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_', 1, 1); INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_', 1, 1);
@ -327,6 +328,7 @@ INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_merg
INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_move', 1, 1); INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_move', 1, 1);
INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_report', 1, 1); INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_report', 1, 1);
INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_split', 1, 1); INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_split', 1, 1);
INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_restore', 1, 1);
# -- Global moderator auth option (not a local option) # -- Global moderator auth option (not a local option)
INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_ban', 0, 1); INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_ban', 0, 1);

File diff suppressed because it is too large Load diff

View file

@ -483,7 +483,7 @@ function get_post_data($post_ids, $acl_list = false, $read_tracking = false)
continue; continue;
} }
if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) if ($row['post_visibility'] == ITEM_UNAPPROVED && !$auth->acl_get('m_approve', $row['forum_id']))
{ {
// Moderators without the permission to approve post should at least not see them. ;) // Moderators without the permission to approve post should at least not see them. ;)
continue; continue;
@ -619,7 +619,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql,
if (!$auth->acl_get('m_approve', $forum_id)) if (!$auth->acl_get('m_approve', $forum_id))
{ {
$sql .= 'AND topic_approved = 1'; $sql .= 'AND post_visibility = ' . ITEM_APPROVED;
} }
break; break;
@ -635,7 +635,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql,
if (!$auth->acl_get('m_approve', $forum_id)) if (!$auth->acl_get('m_approve', $forum_id))
{ {
$sql .= 'AND post_approved = 1'; $sql .= 'AND post_visibility = ' . ITEM_APPROVED;
} }
break; break;
@ -648,7 +648,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql,
$sql = 'SELECT COUNT(p.post_id) AS total $sql = 'SELECT COUNT(p.post_id) AS total
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
$where_sql " . $db->sql_in_set('p.forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . ' $where_sql " . $db->sql_in_set('p.forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . '
AND p.post_approved = 0 AND p.post_visibility = ' . ITEM_UNAPPROVED . '
AND t.topic_id = p.topic_id AND t.topic_id = p.topic_id
AND t.topic_first_post_id <> p.post_id'; AND t.topic_first_post_id <> p.post_id';
@ -666,7 +666,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql,
$sql = 'SELECT COUNT(topic_id) AS total $sql = 'SELECT COUNT(topic_id) AS total
FROM ' . TOPICS_TABLE . " FROM ' . TOPICS_TABLE . "
$where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . ' $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . '
AND topic_approved = 0'; AND topic_visibility = ' . ITEM_UNAPPROVED;
if ($min_time) if ($min_time)
{ {

View file

@ -613,7 +613,7 @@ switch ($mode)
$sql = 'SELECT COUNT(post_id) as posts_in_queue $sql = 'SELECT COUNT(post_id) as posts_in_queue
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE poster_id = ' . $user_id . ' WHERE poster_id = ' . $user_id . '
AND post_approved = 0'; AND post_visibility = ' . ITEM_UNAPPROVED;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue'); $member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
$db->sql_freeresult($result); $db->sql_freeresult($result);

View file

@ -86,8 +86,8 @@ switch ($mode)
$sql = 'SELECT f.*, t.* $sql = 'SELECT f.*, t.*
FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
WHERE t.topic_id = $topic_id WHERE t.topic_id = $topic_id
AND f.forum_id = t.forum_id" . AND f.forum_id = t.forum_id
(($auth->acl_get('m_approve', $forum_id)) ? '' : ' AND t.topic_approved = 1'); AND " . topic_visibility::get_visibility_sql('topic', $forum_id, 't.');
break; break;
case 'quote': case 'quote':
@ -114,8 +114,8 @@ switch ($mode)
WHERE p.post_id = $post_id WHERE p.post_id = $post_id
AND t.topic_id = p.topic_id AND t.topic_id = p.topic_id
AND u.user_id = p.poster_id AND u.user_id = p.poster_id
AND f.forum_id = t.forum_id" . AND f.forum_id = t.forum_id
(($auth->acl_get('m_approve', $forum_id)) ? '' : ' AND p.post_approved = 1'); AND " . topic_visibility::get_visibility_sql('topic', $forum_id, 't.');
break; break;
case 'smilies': case 'smilies':
@ -163,7 +163,7 @@ if (!$post_data)
// Not able to reply to unapproved posts/topics // Not able to reply to unapproved posts/topics
// TODO: add more descriptive language key // TODO: add more descriptive language key
if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && !$post_data['topic_approved']) || ($mode == 'quote' && !$post_data['post_approved']))) if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && $post_data['topic_visibility'] == ITEM_UNAPPROVED) || ($mode == 'quote' && $post_data['post_visibility'] == ITEM_UNAPPROVED)))
{ {
trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED'); trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED');
} }
@ -1063,8 +1063,8 @@ if ($submit || $preview || $refresh)
'attachment_data' => $message_parser->attachment_data, 'attachment_data' => $message_parser->attachment_data,
'filename_data' => $message_parser->filename_data, 'filename_data' => $message_parser->filename_data,
'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false, 'topic_visibility' => (isset($post_data['topic_visibility'])) ? $post_data['topic_visibility'] : false,
'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false, 'post_visibility' => (isset($post_data['post_visibility'])) ? $post_data['post_visibility'] : false,
); );
if ($mode == 'edit') if ($mode == 'edit')
@ -1514,9 +1514,9 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data)
'topic_first_post_id' => $post_data['topic_first_post_id'], 'topic_first_post_id' => $post_data['topic_first_post_id'],
'topic_last_post_id' => $post_data['topic_last_post_id'], 'topic_last_post_id' => $post_data['topic_last_post_id'],
'topic_replies_real' => $post_data['topic_replies_real'], 'topic_replies_real' => $post_data['topic_replies_real'],
'topic_approved' => $post_data['topic_approved'], 'topic_visibility' => $post_data['topic_visibility'],
'topic_type' => $post_data['topic_type'], 'topic_type' => $post_data['topic_type'],
'post_approved' => $post_data['post_approved'], 'post_visibility' => $post_data['post_visibility'],
'post_reported' => $post_data['post_reported'], 'post_reported' => $post_data['post_reported'],
'post_time' => $post_data['post_time'], 'post_time' => $post_data['post_time'],
'poster_id' => $post_data['poster_id'], 'poster_id' => $post_data['poster_id'],

View file

@ -249,7 +249,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
// find out in which forums the user is allowed to view approved posts /* // find out in which forums the user is allowed to view approved posts
if ($auth->acl_get('m_approve')) if ($auth->acl_get('m_approve'))
{ {
$m_approve_fid_ary = array(-1); $m_approve_fid_ary = array(-1);
@ -265,6 +265,8 @@ if ($keywords || $author || $author_id || $search_id || $submit)
$m_approve_fid_ary = array(); $m_approve_fid_ary = array();
$m_approve_fid_sql = ' AND p.post_approved = 1'; $m_approve_fid_sql = ' AND p.post_approved = 1';
} }
*/
$m_approve_fid_sql = ' AND ' . topic_visibility::get_visibility_sql_global('post', $ex_fid_ary, 'p.');
if ($reset_search_forum) if ($reset_search_forum)
{ {
@ -523,17 +525,17 @@ if ($keywords || $author || $author_id || $search_id || $submit)
// make sure that some arrays are always in the same order // make sure that some arrays are always in the same order
sort($ex_fid_ary); sort($ex_fid_ary);
sort($m_approve_fid_ary); // @TODO sort($m_approve_fid_ary);
sort($author_id_ary); sort($author_id_ary);
if (!empty($search->search_query)) if (!empty($search->search_query))
{ {
$total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_sql, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);
} }
else if (sizeof($author_id_ary)) else if (sizeof($author_id_ary))
{ {
$firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false; $firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false;
$total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_sql, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);
} }
// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options. // For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options.
@ -548,7 +550,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
{ {
$sql_where .= $db->sql_in_set(($show_results == 'posts') ? 'p.post_id' : 't.topic_id', $id_ary); $sql_where .= $db->sql_in_set(($show_results == 'posts') ? 'p.post_id' : 't.topic_id', $id_ary);
$sql_where .= (sizeof($ex_fid_ary)) ? ' AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL)' : ''; $sql_where .= (sizeof($ex_fid_ary)) ? ' AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL)' : '';
$sql_where .= ($show_results == 'posts') ? $m_approve_fid_sql : str_replace(array('p.post_approved', 'p.forum_id'), array('t.topic_approved', 't.forum_id'), $m_approve_fid_sql); $sql_where .= ($show_results == 'posts') ? $m_approve_fid_sql : str_replace(array('p.post_visibility', 'p.forum_id'), array('t.topic_visibility', 't.forum_id'), $m_approve_fid_sql);
} }
if ($show_results == 'posts') if ($show_results == 'posts')
@ -882,8 +884,9 @@ if ($keywords || $author || $author_id || $search_id || $submit)
$unread_topic = (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false; $unread_topic = (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false;
$topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $forum_id)) ? true : false;
$posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
$topic_deleted = ($row['topic_visibility'] == ITEM_DELETED) ? true : false;
$u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$result_topic_id", true, $user->session_id) : ''; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$result_topic_id", true, $user->session_id) : '';
$row['topic_title'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['topic_title']); $row['topic_title'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['topic_title']);
@ -911,6 +914,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '', 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
'DELETED_IMG' => ($topic_deleted) ? $user->img(/*TODO*/) : '',
'S_TOPIC_TYPE' => $row['topic_type'], 'S_TOPIC_TYPE' => $row['topic_type'],
'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false, 'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false,
@ -919,6 +923,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false, 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false,
'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved,
'S_TOPIC_DELETED' => $topic_deleted,
'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),

View file

@ -241,7 +241,7 @@ if ($sort_days)
AND (topic_last_post_time >= $min_post_time AND (topic_last_post_time >= $min_post_time
OR topic_type = " . POST_ANNOUNCE . ' OR topic_type = " . POST_ANNOUNCE . '
OR topic_type = ' . POST_GLOBAL . ') OR topic_type = ' . POST_GLOBAL . ')
' . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1'); AND ' . topic_visibility::get_visibility_sql('topic', $forum_id);
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$topics_count = (int) $db->sql_fetchfield('num_topics'); $topics_count = (int) $db->sql_fetchfield('num_topics');
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -353,7 +353,7 @@ $sql_array = array(
'LEFT_JOIN' => array(), 'LEFT_JOIN' => array(),
); );
$sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'; $sql_approved = 'AND ' . topic_visibility::get_visibility_sql('topic', $forum_id, 't.');
if ($user->data['is_registered']) if ($user->data['is_registered'])
{ {
@ -685,8 +685,9 @@ if (sizeof($topic_list))
$view_topic_url_params = 'f=' . $row['forum_id'] . '&amp;t=' . $topic_id; $view_topic_url_params = 'f=' . $row['forum_id'] . '&amp;t=' . $topic_id;
$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params); $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
$topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $row['forum_id']));
$posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id']));
$topic_deleted = ($row['topic_visibility'] == ITEM_DELETED);
$u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$topic_id", true, $user->session_id) : ''; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$topic_id", true, $user->session_id) : '';
// Send vars to template // Send vars to template
@ -719,6 +720,7 @@ if (sizeof($topic_list))
'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '', 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
'DELETED_IMG' => ($topic_deleted) ? $user->img(/*TODO*/) : '',
'S_TOPIC_TYPE' => $row['topic_type'], 'S_TOPIC_TYPE' => $row['topic_type'],
'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false, 'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
@ -726,6 +728,7 @@ if (sizeof($topic_list))
'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false, 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false,
'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved,
'S_TOPIC_DELETED' => $topic_deleted,
'S_HAS_POLL' => ($row['poll_start']) ? true : false, 'S_HAS_POLL' => ($row['poll_start']) ? true : false,
'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false, 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false,
'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false, 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false,

View file

@ -83,7 +83,7 @@ if ($view && !$post_id)
$sql = 'SELECT post_id, topic_id, forum_id $sql = 'SELECT post_id, topic_id, forum_id
FROM ' . POSTS_TABLE . " FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id WHERE topic_id = $topic_id
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1') . " AND " . topic_visibility::get_visibility_sql('post', $forum_id) . "
AND post_time > $topic_last_read AND post_time > $topic_last_read
AND forum_id = $forum_id AND forum_id = $forum_id
ORDER BY post_time ASC"; ORDER BY post_time ASC";
@ -137,7 +137,7 @@ if ($view && !$post_id)
WHERE forum_id = ' . $row['forum_id'] . " WHERE forum_id = ' . $row['forum_id'] . "
AND topic_moved_id = 0 AND topic_moved_id = 0
AND topic_last_post_time $sql_condition {$row['topic_last_post_time']} AND topic_last_post_time $sql_condition {$row['topic_last_post_time']}
" . (($auth->acl_get('m_approve', $row['forum_id'])) ? '' : 'AND topic_approved = 1') . " AND" . topic_visibility::get_visibility_sql('topic', $row['forum_id']) . "
ORDER BY topic_last_post_time $sql_ordering"; ORDER BY topic_last_post_time $sql_ordering";
$result = $db->sql_query_limit($sql, 1); $result = $db->sql_query_limit($sql, 1);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
@ -174,7 +174,7 @@ $sql_array = array(
// The FROM-Order is quite important here, else t.* columns can not be correctly bound. // The FROM-Order is quite important here, else t.* columns can not be correctly bound.
if ($post_id) if ($post_id)
{ {
$sql_array['SELECT'] .= ', p.post_approved, p.post_time, p.post_id'; $sql_array['SELECT'] .= ', p.post_visibility, p.post_time, p.post_id';
$sql_array['FROM'][POSTS_TABLE] = 'p'; $sql_array['FROM'][POSTS_TABLE] = 'p';
} }
@ -249,7 +249,7 @@ $forum_id = (int) $topic_data['forum_id'];
if ($post_id) if ($post_id)
{ {
// are we where we are supposed to be? // are we where we are supposed to be?
if (!$topic_data['post_approved'] && !$auth->acl_get('m_approve', $topic_data['forum_id'])) if ($topic_data['post_visibility'] == ITEM_UNAPPROVED && !$auth->acl_get('m_approve', $topic_data['forum_id']))
{ {
// If post_id was submitted, we try at least to display the topic as a last resort... // If post_id was submitted, we try at least to display the topic as a last resort...
if ($topic_id) if ($topic_id)
@ -277,7 +277,7 @@ if ($post_id)
$sql = 'SELECT COUNT(p.post_id) AS prev_posts $sql = 'SELECT COUNT(p.post_id) AS prev_posts
FROM ' . POSTS_TABLE . " p FROM ' . POSTS_TABLE . " p
WHERE p.topic_id = {$topic_data['topic_id']} WHERE p.topic_id = {$topic_data['topic_id']}
" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : ''); " . topic_visibility::get_visibility_sql('post', $forum_id, 'p');
if ($sort_dir == 'd') if ($sort_dir == 'd')
{ {
@ -315,7 +315,13 @@ if (($topic_data['topic_type'] == POST_STICKY || $topic_data['topic_type'] == PO
// Setup look and feel // Setup look and feel
$user->setup('viewtopic', $topic_data['forum_style']); $user->setup('viewtopic', $topic_data['forum_style']);
if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id)) /* the topic "does not exist":
* if the topic is unapproved and the user cannot approve it
* if the topic is deleted and the user cannot restore it
* NB: restoring a topic has two cases: moderator restore and poster restore.
*/
if (($topic_data['topic_visibility'] == ITEM_UNAPPROVED && !$auth->acl_get('m_approve', $forum_id))
|| ($topic_data['topic_visibility'] == ITEM_DELETED && (!$auth->acl_get('m_restore', $forum_id) || ($user->data['user_id'] == $topic_data['topic_poster'] && $auth->acl_get('f_restore', $forum_id)))))
{ {
trigger_error('NO_TOPIC'); trigger_error('NO_TOPIC');
} }
@ -402,7 +408,7 @@ if ($sort_days)
FROM ' . POSTS_TABLE . " FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id WHERE topic_id = $topic_id
AND post_time >= $min_post_time AND post_time >= $min_post_time
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1'); AND " . topic_visibility::get_visibility_sql('post', $forum_id);
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$total_posts = (int) $db->sql_fetchfield('num_posts'); $total_posts = (int) $db->sql_fetchfield('num_posts');
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -938,7 +944,7 @@ $i = $i_total = 0;
$sql = 'SELECT p.post_id $sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p' . (($join_user_sql[$sort_key]) ? ', ' . USERS_TABLE . ' u': '') . " FROM ' . POSTS_TABLE . ' p' . (($join_user_sql[$sort_key]) ? ', ' . USERS_TABLE . ' u': '') . "
WHERE p.topic_id = $topic_id WHERE p.topic_id = $topic_id
" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . " AND " . topic_visibility::get_visibility_sql('post', $forum_id, 'p.') . "
" . (($join_user_sql[$sort_key]) ? 'AND u.user_id = p.poster_id': '') . " " . (($join_user_sql[$sort_key]) ? 'AND u.user_id = p.poster_id': '') . "
$limit_posts_time $limit_posts_time
ORDER BY $sql_sort_order"; ORDER BY $sql_sort_order";
@ -1020,7 +1026,7 @@ while ($row = $db->sql_fetchrow($result))
{ {
$attach_list[] = (int) $row['post_id']; $attach_list[] = (int) $row['post_id'];
if ($row['post_approved']) if ($row['post_visibility'] == ITEM_UNAPPROVED)
{ {
$has_attachments = true; $has_attachments = true;
} }
@ -1046,7 +1052,7 @@ while ($row = $db->sql_fetchrow($result))
// Make sure the icon actually exists // Make sure the icon actually exists
'icon_id' => (isset($icons[$row['icon_id']]['img'], $icons[$row['icon_id']]['height'], $icons[$row['icon_id']]['width'])) ? $row['icon_id'] : 0, 'icon_id' => (isset($icons[$row['icon_id']]['img'], $icons[$row['icon_id']]['height'], $icons[$row['icon_id']]['width'])) ? $row['icon_id'] : 0,
'post_attachment' => $row['post_attachment'], 'post_attachment' => $row['post_attachment'],
'post_approved' => $row['post_approved'], 'post_visibility' => $row['post_visibility'],
'post_reported' => $row['post_reported'], 'post_reported' => $row['post_reported'],
'post_username' => $row['post_username'], 'post_username' => $row['post_username'],
'post_text' => $row['post_text'], 'post_text' => $row['post_text'],
@ -1313,8 +1319,8 @@ if (sizeof($attach_list))
$sql = 'SELECT a.post_msg_id as post_id $sql = 'SELECT a.post_msg_id as post_id
FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p
WHERE p.topic_id = $topic_id WHERE p.topic_id = $topic_id
AND p.post_approved = 1 AND p.post_visibility = " . ITEM_APPROVED . '
AND p.topic_id = a.topic_id"; AND p.topic_id = a.topic_id';
$result = $db->sql_query_limit($sql, 1); $result = $db->sql_query_limit($sql, 1);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -1605,7 +1611,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false, 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
'S_MULTIPLE_ATTACHMENTS' => !empty($attachments[$row['post_id']]) && sizeof($attachments[$row['post_id']]) > 1, 'S_MULTIPLE_ATTACHMENTS' => !empty($attachments[$row['post_id']]) && sizeof($attachments[$row['post_id']]) > 1,
'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true, 'S_POST_UNAPPROVED' => ($row['post_visibility'] == ITEM_APPROVED) ? false : true,
'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false, 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'], 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'],
'S_FRIEND' => ($row['friend']) ? true : false, 'S_FRIEND' => ($row['friend']) ? true : false,