mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
do not use the sync function if post get deleted. added topic_last_post_id information to viewtopic, for determining delete permission correctly.
git-svn-id: file:///svn/phpbb/trunk@3887 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
92141c3e35
commit
68deb6cbfd
3 changed files with 152 additions and 12 deletions
|
@ -369,6 +369,77 @@ function format_display($message, $html, $bbcode, $uid, $url, $smilies, $sig)
|
|||
return($message);
|
||||
}
|
||||
|
||||
// Update Last Post Informations
|
||||
function update_last_post_information($type, $id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'forum':
|
||||
$sql_select_add = ', f.forum_parents';
|
||||
// $sql_select_add = ', f.left_id';
|
||||
$sql_table_add = ', ' . FORUMS_TABLE . ' f';
|
||||
$sql_where_add = 'AND (t.forum_id = f.forum_id) AND (f.forum_id = ' . $id . ')';
|
||||
$sql_update_table = FORUMS_TABLE;
|
||||
break;
|
||||
|
||||
case 'topic':
|
||||
$sql_select_add = '';
|
||||
$sql_table_add = '';
|
||||
$sql_where_add = 'AND (t.topic_id = ' . $id . ')';
|
||||
$sql_update_table = TOPICS_TABLE;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "SELECT p.post_id, p.poster_id, p.post_time, u.username, p.post_username " . $sql_select_add . "
|
||||
FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . TOPICS_TABLE . " t " . $sql_table_add . "
|
||||
WHERE p.post_approved = 1
|
||||
AND t.topic_approved = 1
|
||||
AND p.poster_id = u.user_id
|
||||
AND t.topic_id = p.topic_id
|
||||
$sql_where_add
|
||||
ORDER BY p.post_time DESC";
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
|
||||
$row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'forum':
|
||||
// Update forums: last post info, topics, posts ... we need to update
|
||||
// each parent too ...
|
||||
|
||||
$forum_ids = $id;
|
||||
$forum_parents = get_forum_parents($row);
|
||||
|
||||
foreach ($forum_parents as $parent_forum_id => $parent_name)
|
||||
{
|
||||
$forum_ids .= ', ' . $parent_forum_id;
|
||||
}
|
||||
|
||||
$where_clause = 'forum_id IN (' . $forum_ids . ')';
|
||||
break;
|
||||
|
||||
case 'topic':
|
||||
$where_clause = 'topic_id = ' . $id;
|
||||
break;
|
||||
}
|
||||
|
||||
$update_sql = array(
|
||||
$type . '_last_post_id' => intval($row['post_id']),
|
||||
$type . '_last_post_time' => intval($row['post_time']),
|
||||
$type . '_last_poster_id' => intval($row['poster_id']),
|
||||
$type . '_last_poster_name' => (intval($row['poster_id']) == ANONYMOUS) ? trim($row['post_username']) : trim($row['username'])
|
||||
);
|
||||
|
||||
$sql = 'UPDATE ' . $sql_update_table . ' SET ' . $db->sql_build_array('UPDATE', $update_sql) . ' WHERE ' . $where_clause;
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
// Submit Post
|
||||
function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_uid, $poll, $attachment_data, $post_data)
|
||||
{
|
||||
|
@ -389,7 +460,7 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
|
|||
'topic_title' => stripslashes($subject),
|
||||
'topic_time' => $current_time,
|
||||
'topic_type' => $topic_type,
|
||||
'topic_approved' => (($post_data['enable_moderate']) && !$auth->acl_get('f_ignorequeue', $post_data['forum_id'])) ? 0 : 1,
|
||||
'topic_approved' => ($auth->acl_get('f_moderate', $post_data['forum_id']) && !$auth->acl_get('f_ignorequeue', $post_data['forum_id'])) ? 0 : 1,
|
||||
'icon_id' => $post_data['icon_id'],
|
||||
'topic_attachment' => (sizeof($attachment_data['physical_filename'])) ? 1 : 0,
|
||||
'topic_poster' => intval($user->data['user_id']),
|
||||
|
@ -421,7 +492,7 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
|
|||
'icon_id' => $post_data['icon_id'],
|
||||
'poster_ip' => $user->ip,
|
||||
'post_time' => $current_time,
|
||||
'post_approved' => ($post_data['enable_moderate'] && !$auth->acl_get('f_ignorequeue', $post_data['forum_id'])) ? 0 : 1,
|
||||
'post_approved' => ($auth->acl_get('f_moderate', $post_data['forum_id']) && !$auth->acl_get('f_ignorequeue', $post_data['forum_id'])) ? 0 : 1,
|
||||
'post_edit_time' => ($mode == 'edit' && $post_data['poster_id'] == $user->data['user_id']) ? $current_time : 0,
|
||||
'enable_sig' => $post_data['enable_sig'],
|
||||
'enable_bbcode' => $post_data['enable_bbcode'],
|
||||
|
@ -599,8 +670,7 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
|
|||
$db->sql_query($sql);
|
||||
|
||||
// Update user post count ... if appropriate
|
||||
// TODO: alter to use the ACL
|
||||
if (!empty($post_data['enable_post_count']) && $user->data['user_id'] != ANONYMOUS)
|
||||
if ($user->data['user_id'] != ANONYMOUS && $auth->acl_get('f_postcount', $post_data['forum_id']))
|
||||
{
|
||||
$sql = 'UPDATE ' . USERS_TABLE . '
|
||||
SET user_posts = user_posts + 1
|
||||
|
@ -648,7 +718,7 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
|
|||
'META' => '<meta http-equiv="refresh" content="5; url=viewtopic.' . $phpEx . $SID . '&f=' . $post_data['forum_id'] . '&p=' . $post_data['post_id'] . '#' . $post_data['post_id'] . '">')
|
||||
);
|
||||
|
||||
$message = ($post_data['enable_moderate']) ? 'POST_STORED_MOD' : 'POST_STORED';
|
||||
$message = ($auth->acl_get('f_moderate', $post_data['forum_id']) && !$auth->acl_get('f_ignorequeue', $post_data['forum_id'])) ? 'POST_STORED_MOD' : 'POST_STORED';
|
||||
$message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="viewtopic.' . $phpEx . $SID .'&p=' . $post_data['post_id'] . '#' . $post_data['post_id'] . '">', '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID .'&f=' . $post_data['forum_id'] . '">', '</a>');
|
||||
trigger_error($message);
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ $topic_validate = false;
|
|||
$post_validate = false;
|
||||
|
||||
// Easier validation
|
||||
$forum_fields = array('forum_name' => 's', 'parent_id' => 'i', 'forum_parents' => 's', 'forum_status' => 'i', 'forum_postable' => 'i', 'enable_icons' => 'i', 'enable_post_count' => 'i', 'enable_moderate' => 'i');
|
||||
$forum_fields = array('forum_name' => 's', 'parent_id' => 'i', 'forum_parents' => 's', 'forum_status' => 'i', 'forum_postable' => 'i', 'enable_icons' => 'i');
|
||||
|
||||
$topic_fields = array('topic_status' => 'i', 'topic_first_post_id' => 'i', 'topic_last_post_id' => 'i', 'topic_type' => 'i', 'topic_title' => 's', 'poll_last_vote' => 'i', 'poll_start' => 'i', 'poll_title' => 's', 'poll_length' => 'i');
|
||||
|
||||
|
@ -388,7 +388,6 @@ if ( ($mode == 'delete') && ((($poster_id == $user->data['user_id']) && ($user->
|
|||
$post_data = array(
|
||||
'topic_first_post_id' => $topic_first_post_id,
|
||||
'topic_last_post_id' => $topic_last_post_id,
|
||||
'enable_post_count' => $enable_post_count,
|
||||
'user_id' => $poster_id
|
||||
);
|
||||
|
||||
|
@ -396,8 +395,13 @@ if ( ($mode == 'delete') && ((($poster_id == $user->data['user_id']) && ($user->
|
|||
|
||||
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
||||
|
||||
$topic_sql = array();
|
||||
$forum_update_sql = '';
|
||||
$user_update_sql = '';
|
||||
$topic_update_sql = 'topic_replies = topic_replies - 1, topic_replies_real = topic_replies_real - 1';
|
||||
|
||||
// User tries to delete the post twice ? Exit... we do not want the topics table screwed up.
|
||||
if (!delete_posts('post_id', array($post_id)))
|
||||
if (!delete_posts('post_id', array($post_id), FALSE))
|
||||
{
|
||||
trigger_error($user->lang['ALREADY_DELETED']);
|
||||
}
|
||||
|
@ -405,12 +409,80 @@ if ( ($mode == 'delete') && ((($poster_id == $user->data['user_id']) && ($user->
|
|||
// Only one post... delete topic
|
||||
if ($post_data['topic_first_post_id'] == $post_data['topic_last_post_id'])
|
||||
{
|
||||
delete_topics('topic_id', array($topic_id));
|
||||
delete_topics('topic_id', array($topic_id), FALSE);
|
||||
$forum_update_sql .= ($forum_update_sql != '') ? ', ' : '';
|
||||
$forum_update_sql .= 'forum_topics = forum_topics - 1, forum_topics_real = forum_topics_real - 1';
|
||||
}
|
||||
|
||||
// TODO: delete common words... maybe just call search_tidy ?
|
||||
// $search->del_words($post_id);
|
||||
|
||||
// Sync last post informations
|
||||
$db->sql_transaction();
|
||||
|
||||
$forum_update_sql .= ($forum_update_sql != '') ? ', forum_posts = forum_posts - 1' : 'forum_posts = forum_posts - 1';
|
||||
|
||||
if ($auth->acl_get('f_postcount', $forum_id))
|
||||
{
|
||||
$user_update_sql .= ($user_update_sql != '') ? ', user_posts = user_posts - 1' : 'user_posts = user_posts - 1';
|
||||
}
|
||||
|
||||
$sql = "SELECT p.post_id, p.poster_id, p.post_username, u.username
|
||||
FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u
|
||||
WHERE p.topic_id = " . $topic_id . "
|
||||
AND p.poster_id = u.user_id
|
||||
AND p.post_approved = 1
|
||||
ORDER BY p.post_time DESC";
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
|
||||
$row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// If Post is first post, but not the only post... make next post the topic starter one. ;)
|
||||
if (($post_data['topic_first_post_id'] != $post_data['topic_last_post_id']) && ($post_id == $post_data['topic_first_post_id']))
|
||||
{
|
||||
$topic_sql = array(
|
||||
'topic_first_post_id' => intval($row['post_id']),
|
||||
'topic_first_poster_name' => ( intval($row['poster_id']) == ANONYMOUS) ? trim($row['post_username']) : trim($row['username'])
|
||||
);
|
||||
}
|
||||
|
||||
$post_data['next_post_id'] = intval($row['post_id']);
|
||||
|
||||
// Update Forum, Topic and User with the gathered Informations
|
||||
if ($forum_update_sql != '')
|
||||
{
|
||||
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
||||
SET ' . $forum_update_sql . '
|
||||
WHERE forum_id = ' . $forum_id;
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
if ($topic_update_sql != '' || count($topic_sql) > 0)
|
||||
{
|
||||
$sql = 'UPDATE ' . TOPICS_TABLE . '
|
||||
SET ' . ( (count($topic_sql) > 0) ? $db->sql_build_array('UPDATE', $topic_sql) : '') . ( ($topic_update_sql != '') ? ((count($topic_sql) > 0) ? ', ' . $topic_update_sql : $topic_update_sql) : '') . '
|
||||
WHERE topic_id = ' . $topic_id;
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
if ($user_update_sql != '')
|
||||
{
|
||||
$sql = 'UPDATE ' . USERS_TABLE . '
|
||||
SET ' . $user_update_sql . '
|
||||
WHERE user_id = ' . $post_data['user_id'];
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
// Update Forum stats...
|
||||
if ($post_data['topic_first_post_id'] != $post_data['topic_last_post_id'])
|
||||
{
|
||||
update_last_post_information('topic', $topic_id);
|
||||
}
|
||||
update_last_post_information('forum', $forum_id);
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
|
||||
if ($post_data['topic_first_post_id'] == $post_data['topic_last_post_id'])
|
||||
{
|
||||
$meta_info = '<meta http-equiv="refresh" content="5; url=viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '">';
|
||||
|
@ -681,7 +753,6 @@ if (($submit) || ($preview) || ($refresh))
|
|||
'post_id' => $post_id,
|
||||
'topic_id' => $topic_id,
|
||||
'forum_id' => $forum_id,
|
||||
'enable_moderate' => $enable_moderate,
|
||||
'icon_id' => $icon_id,
|
||||
'poster_id' => $poster_id,
|
||||
'enable_sig' => $enable_sig,
|
||||
|
@ -689,7 +760,6 @@ if (($submit) || ($preview) || ($refresh))
|
|||
'enable_html' => $enable_html,
|
||||
'enable_smilies' => $enable_smilies,
|
||||
'enable_urls' => $enable_urls,
|
||||
'enable_post_count' => $enable_post_count,
|
||||
'message_md5' => $message_md5,
|
||||
'post_checksum' => $post_checksum,
|
||||
'forum_parents' => $forum_parents,
|
||||
|
|
|
@ -160,7 +160,7 @@ if (!$forum_id)
|
|||
{
|
||||
$forum_id = 2;
|
||||
}
|
||||
$sql = "SELECT t.topic_id, t.forum_id AS real_forum_id, t.topic_title, t.topic_attachment, t.topic_status, " . (($auth->acl_get('m_approve')) ? 't.topic_replies_real AS topic_replies' : 't.topic_replies') . ", t.topic_time, t.topic_type, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_id, f.forum_style" . $extra_fields . "
|
||||
$sql = "SELECT t.topic_id, t.forum_id AS real_forum_id, t.topic_title, t.topic_attachment, t.topic_status, " . (($auth->acl_get('m_approve')) ? 't.topic_replies_real AS topic_replies' : 't.topic_replies') . ", t.topic_last_post_id, t.topic_time, t.topic_type, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_id, f.forum_style" . $extra_fields . "
|
||||
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
|
||||
WHERE $join_sql
|
||||
AND (f.forum_id = t.forum_id
|
||||
|
|
Loading…
Add table
Reference in a new issue