diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2004-07-19 20:13:18 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2004-07-19 20:13:18 +0000 |
commit | bfec4fb8fca43dc46302d44fcfa8c6c4377d4750 (patch) | |
tree | 74de3d4bce8af8db061cd0e7262e378a2bb31014 /phpBB/includes | |
parent | 9dcd7b45cb3b3d82474c0bdf955a1fd753eaa87a (diff) | |
download | forums-bfec4fb8fca43dc46302d44fcfa8c6c4377d4750.tar forums-bfec4fb8fca43dc46302d44fcfa8c6c4377d4750.tar.gz forums-bfec4fb8fca43dc46302d44fcfa8c6c4377d4750.tar.bz2 forums-bfec4fb8fca43dc46302d44fcfa8c6c4377d4750.tar.xz forums-bfec4fb8fca43dc46302d44fcfa8c6c4377d4750.zip |
- approve/disapprove posts/topics
- changed mcp_front to be more moderator friendly
- able to change the forum in mcp_queue (for moderators moderating more than one forum)
git-svn-id: file:///svn/phpbb/trunk@4937 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/bbcode.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 78 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 220 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_forum.php | 4 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_front.php | 45 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_post.php | 5 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_queue.php | 473 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_topic.php | 2 |
8 files changed, 800 insertions, 29 deletions
diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 144dafbb30..92a455ce26 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -458,7 +458,7 @@ class bbcode $code = str_replace("\t", ' ', $code); $code = str_replace(' ', ' ', $code); $code = str_replace(' ', ' ', $code); - $code = preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILE_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '\1', $code); + $code = preg_replace(array('#<!\-\- s(.*?) \-\-><img src="\{SMILE_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '#&(\#[0-9]+;)#'), array('\1', '&\1'), $code); } $code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close'); diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 067f463325..0507d68c40 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2149,6 +2149,84 @@ if (class_exists('auth')) } } +// Update Post Informations (First/Last Post in topic/forum) +// Should be used instead of sync() if only the last post informations are out of sync... faster +function update_post_information($type, $ids) +{ + global $db; + + if (!is_array($ids)) + { + $ids = array($ids); + } + + $update_sql = $empty_forums = array(); + $sql = 'SELECT ' . $type . '_id, MAX(post_id) as last_post_id + FROM ' . POSTS_TABLE . " + WHERE post_approved = 1 + AND {$type}_id IN (" . implode(', ', $ids) . ") + GROUP BY {$type}_id"; + $result = $db->sql_query($sql); + + $last_post_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + if ($type == 'forum') + { + $empty_forums[] = $row['forum_id']; + } + + $last_post_ids[] = $row['last_post_id']; + } + $db->sql_freeresult($result); + + if ($type == 'forum') + { + $empty_forums = array_diff($ids, $empty_forums); + + foreach ($empty_forums as $void => $forum_id) + { + $update_sql[$forum_id][] = 'forum_last_post_id = 0'; + $update_sql[$forum_id][] = 'forum_last_post_time = 0'; + $update_sql[$forum_id][] = 'forum_last_poster_id = 0'; + $update_sql[$forum_id][] = "forum_last_poster_name = ''"; + } + } + + if (sizeof($last_post_ids)) + { + $sql = 'SELECT p.' . $type . '_id, p.post_id, p.post_time, p.poster_id, p.post_username, u.user_id, u.username + FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u + WHERE p.poster_id = u.user_id + AND p.post_id IN (' . implode(', ', $last_post_ids) . ')'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $update_sql[$row["{$type}_id"]][] = $type . '_last_post_id = ' . (int) $row['post_id']; + $update_sql[$row["{$type}_id"]][] = $type . '_last_post_time = ' . (int) $row['post_time']; + $update_sql[$row["{$type}_id"]][] = $type . '_last_poster_id = ' . (int) $row['poster_id']; + $update_sql[$row["{$type}_id"]][] = "{$type}_last_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'"; + } + $db->sql_freeresult($result); + } + unset($empty_forums, $ids, $last_post_ids); + + if (!sizeof($update_sql)) + { + return; + } + + $table = ($type == 'forum') ? FORUMS_TABLE : TOPICS_TABLE; + + foreach ($update_sql as $update_id => $update_sql_ary) + { + $sql = "UPDATE $table + SET " . implode(', ', $update_sql_ary) . " + WHERE {$type}_id = $update_id"; + $db->sql_query($sql); + } +} ?>
\ No newline at end of file diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index d793e66586..4ab2a13157 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1013,4 +1013,224 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id return true; } +// User Notification +function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id) +{ + global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; + + $topic_notification = ($mode == 'reply' || $mode == 'quote'); + $forum_notification = ($mode == 'post'); + + if (!$topic_notification && !$forum_notification) + { + trigger_error('WRONG_NOTIFICATION_MODE'); + } + + $topic_title = ($topic_notification) ? $topic_title : $subject; + decode_text($topic_title); + $topic_title = censor_text($topic_title); + + // Get banned User ID's + $sql = 'SELECT ban_userid + FROM ' . BANLIST_TABLE; + $result = $db->sql_query($sql); + + $sql_ignore_users = ANONYMOUS . ', ' . $user->data['user_id']; + while ($row = $db->sql_fetchrow($result)) + { + if (isset($row['ban_userid'])) + { + $sql_ignore_users .= ', ' . $row['ban_userid']; + } + } + $db->sql_freeresult($result); + + $notify_rows = array(); + + // -- get forum_userids || topic_userids + $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber + FROM ' . (($topic_notification) ? TOPICS_WATCH_TABLE : FORUMS_WATCH_TABLE) . ' w, ' . USERS_TABLE . ' u + WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . " + AND w.user_id NOT IN ($sql_ignore_users) + AND w.notify_status = 0 + AND u.user_id = w.user_id"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $notify_rows[$row['user_id']] = array( + 'user_id' => $row['user_id'], + 'username' => $row['username'], + 'user_email' => $row['user_email'], + 'user_jabber' => $row['user_jabber'], + 'user_lang' => $row['user_lang'], + 'notify_type' => ($topic_notification) ? 'topic' : 'forum', + 'template' => ($topic_notification) ? 'topic_notify' : 'newtopic_notify', + 'method' => $row['user_notify_type'], + 'allowed' => false + ); + } + $db->sql_freeresult($result); + + // forum notification is sent to those not receiving post notification + if ($topic_notification) + { + if (sizeof($notify_rows)) + { + $sql_ignore_users .= ', ' . implode(', ', array_keys($notify_rows)); + } + + $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber + FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u + WHERE fw.forum_id = $forum_id + AND fw.user_id NOT IN ($sql_ignore_users) + AND fw.notify_status = 0 + AND u.user_id = fw.user_id"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $notify_rows[$row['user_id']] = array( + 'user_id' => $row['user_id'], + 'username' => $row['username'], + 'user_email' => $row['user_email'], + 'user_jabber' => $row['user_jabber'], + 'user_lang' => $row['user_lang'], + 'notify_type' => 'forum', + 'template' => 'forum_notify', + 'method' => $row['user_notify_type'], + 'allowed' => false + ); + } + $db->sql_freeresult($result); + } + + if (!sizeof($notify_rows)) + { + return; + } + + foreach ($auth->acl_get_list(array_keys($notify_rows), 'f_read', $forum_id) as $forum_id => $forum_ary) + { + foreach ($forum_ary as $auth_option => $user_ary) + { + foreach ($user_ary as $user_id) + { + $notify_rows[$user_id]['allowed'] = true; + } + } + } + + + // Now, we have to do a little step before really sending, we need to distinguish our users a little bit. ;) + $msg_users = $delete_ids = $update_notification = array(); + foreach ($notify_rows as $user_id => $row) + { + if (!$row['allowed'] || !trim($row['user_email'])) + { + $delete_ids[$row['notify_type']][] = $row['user_id']; + } + else + { + $msg_users[] = $row; + $update_notification[$row['notify_type']][] = $row['user_id']; + } + } + unset($notify_rows); + + // Now, we are able to really send out notifications + if (sizeof($msg_users)) + { + include_once($phpbb_root_path . 'includes/functions_messenger.'.$phpEx); + $messenger = new messenger(); + + $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']); + + $msg_list_ary = array(); + foreach ($msg_users as $row) + { + $pos = sizeof($msg_list_ary[$row['template']]); + + $msg_list_ary[$row['template']][$pos]['method'] = $row['method']; + $msg_list_ary[$row['template']][$pos]['email'] = $row['user_email']; + $msg_list_ary[$row['template']][$pos]['jabber'] = $row['user_jabber']; + $msg_list_ary[$row['template']][$pos]['name'] = $row['username']; + $msg_list_ary[$row['template']][$pos]['lang'] = $row['user_lang']; + } + unset($msg_users); + + foreach ($msg_list_ary as $email_template => $email_list) + { + foreach ($email_list as $addr) + { + $messenger->template($email_template, $addr['lang']); + + $messenger->replyto($config['board_email']); + $messenger->to($addr['email'], $addr['name']); + $messenger->im($addr['jabber'], $addr['name']); + + $messenger->assign_vars(array( + 'EMAIL_SIG' => $email_sig, + 'SITENAME' => $config['sitename'], + 'USERNAME' => $addr['name'], + 'TOPIC_TITLE' => $topic_title, + 'FORUM_NAME' => $forum_name, + + 'U_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id&e=0", + 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&e=0", + 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id", + 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&unwatch=topic", + 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id&unwatch=forum", + )); + + $messenger->send($addr['method']); + $messenger->reset(); + } + } + unset($msg_list_ary); + + if ($messenger->queue) + { + $messenger->queue->save(); + } + } + + // Handle the DB updates + $db->sql_transaction(); + + if (sizeof($update_notification['topic'])) + { + $db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . " + SET notify_status = 1 + WHERE topic_id = $topic_id + AND user_id IN (" . implode(', ', $update_notification['topic']) . ")"); + } + + if (sizeof($update_notification['forum'])) + { + $db->sql_query('UPDATE ' . FORUMS_WATCH_TABLE . " + SET notify_status = 1 + WHERE forum_id = $forum_id + AND user_id IN (" . implode(', ', $update_notification['forum']) . ")"); + } + + // Now delete the user_ids not authorized to receive notifications on this topic/forum + if (sizeof($delete_ids['topic'])) + { + $db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . " + WHERE topic_id = $topic_id + AND user_id IN (" . implode(', ', $delete_ids['topic']) . ")"); + } + + if (sizeof($delete_ids['forum'])) + { + $db->sql_query('DELETE FROM ' . FORUMS_WATCH_TABLE . " + WHERE forum_id = $forum_id + AND user_id IN (" . implode(', ', $delete_ids['forum']) . ")"); + } + + $db->sql_transaction('commit'); + +} + ?>
\ No newline at end of file diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 07f80a87f0..7de44547e3 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -176,11 +176,11 @@ function mcp_forum_view($id, $mode, $action, $url, $forum_info) $topic_title = censor_text($row['topic_title']); $template->assign_block_vars('topicrow', array( - 'U_VIEW_TOPIC' => "mcp.$phpEx$SID&t=" . $row['topic_id'] . '&mode=topic_view', + 'U_VIEW_TOPIC' => "mcp.$phpEx$SID&f=$forum_id&t={$row['topic_id']}&mode=topic_view", 'S_SELECT_TOPIC' => ($action == 'merge_select' && $row['topic_id'] != $topic_id) ? true : false, 'U_SELECT_TOPIC' => $url . '&mode=topic_view&action=merge&to_topic_id=' . $row['topic_id'] . $selected_ids, - 'U_MCP_QUEUE' => $url . '&i=queue&mode=approve&t=' . $row['topic_id'], + 'U_MCP_QUEUE' => $url . '&i=queue&mode=approve_details&t=' . $row['topic_id'], 'U_MCP_REPORT' => "mcp.$phpEx$SID&i=main&mode=topic_view&t={$row['topic_id']}&action=reports", 'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_attach', sprintf($user->lang['TOTAL_ATTACHMENTS'], $row['topic_attachment'])) : '', diff --git a/phpBB/includes/mcp/mcp_front.php b/phpBB/includes/mcp/mcp_front.php index c593e6ae90..b8d6c12b27 100644 --- a/phpBB/includes/mcp/mcp_front.php +++ b/phpBB/includes/mcp/mcp_front.php @@ -62,22 +62,19 @@ function mcp_front_view($id, $mode, $action, $url) while ($row = $db->sql_fetchrow($result)) { - if ($row['poster_id'] == ANONYMOUS) - { - $author = ($row['post_username']) ? $row['post_username'] : $user->lang['GUEST']; - } - else - { - $author = '<a href="memberlist.' . $phpEx . $SID . '&mode=viewprofile&u=' . $row['poster_id'] . '">' . $row['username'] . '</a>'; - } - $template->assign_block_vars('unapproved', array( - 'U_POST_DETAILS' => $url . '&mode=post_details', - 'FORUM' => (!empty($row['forum_id'])) ? '<a href="viewforum.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>' : $user->lang['POST_GLOBAL'], - 'TOPIC' => '<a href="viewtopic.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . '">' . $row['topic_title'] . '</a>', - 'AUTHOR' => $author, - 'SUBJECT' => '<a href="mcp.' . $phpEx . $SID . '&p=' . $row['post_id'] . '&mode=post_details">' . (($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT']) . '</a>', - 'POST_TIME' => $user->format_date($row['post_time'])) + 'U_POST_DETAILS'=> $url . '&p=' . $row['post_id'] . '&mode=post_details', + 'U_MCP_FORUM' => ($row['forum_id']) ? $url . '&f=' . $row['forum_id'] . '&mode=forum_view' : '', + 'U_MCP_TOPIC' => $url . '&t=' . $row['topic_id'] . '&mode=topic_view', + 'U_FORUM' => ($row['forum_id']) ? 'viewforum.' . $phpEx . $SID . '&f=' . $row['forum_id'] : '', + 'U_TOPIC' => 'viewtopic.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '&t=' . $row['topic_id'], + 'U_AUTHOR' => ($row['poster_id'] == ANONYMOUS) ? '' : 'memberlist.' . $phpEx . $SID . '&mode=viewprofile&u=' . $row['poster_id'], + + 'FORUM_NAME' => ($row['forum_id']) ? $row['forum_name'] : $user->lang['POST_GLOBAL'], + 'TOPIC_TITLE' => $row['topic_title'], + 'AUTHOR' => ($row['poster_id'] == ANONYMOUS) ? (($row['post_username']) ? $row['post_username'] : $user->lang['GUEST']) : $row['username'], + 'SUBJECT' => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'], + 'POST_TIME' => $user->format_date($row['post_time'])) ); } } @@ -128,12 +125,18 @@ function mcp_front_view($id, $mode, $action, $url) while ($row = $db->sql_fetchrow($result)) { $template->assign_block_vars('report', array( - 'U_POST_DETAILS' => $url . '&mode=post_details', - 'FORUM' => (!empty($row['forum_id'])) ? '<a href="viewforum.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>' : $user->lang['POST_GLOBAL'], - 'TOPIC' => '<a href="viewtopic.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . '">' . $row['topic_title'] . '</a>', - 'REPORTER' => ($row['user_id'] == ANONYMOUS) ? $user->lang['GUEST'] : '<a href="memberlist.' . $phpEx . $SID . '&mode=viewprofile&u=' . $row['user_id'] . '">' . $row['username'] . '</a>', - 'SUBJECT' => '<a href="mcp.' . $phpEx . $SID . '&p=' . $row['post_id'] . '&mode=post_details">' . (($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT']) . '</a>', - 'REPORT_TIME' => $user->format_date($row['report_time'])) + 'U_POST_DETAILS'=> $url . '&p=' . $row['post_id'] . '&mode=post_details', + 'U_MCP_FORUM' => ($row['forum_id']) ? $url . '&f=' . $row['forum_id'] . '&mode=forum_view' : '', + 'U_MCP_TOPIC' => $url . '&t=' . $row['topic_id'] . '&mode=topic_view', + 'U_FORUM' => ($row['forum_id']) ? 'viewforum.' . $phpEx . $SID . '&f=' . $row['forum_id'] : '', + 'U_TOPIC' => 'viewtopic.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '&t=' . $row['topic_id'], + 'U_REPORTER' => ($row['user_id'] == ANONYMOUS) ? '' : 'memberlist.' . $phpEx . $SID . '&mode=viewprofile&u=' . $row['user_id'], + + 'FORUM_NAME' => ($row['forum_id']) ? $row['forum_name'] : $user->lang['POST_GLOBAL'], + 'TOPIC_TITLE' => $row['topic_title'], + 'REPORTER' => ($row['user_id'] == ANONYMOUS) ? $user->lang['GUEST'] : $row['username'], + 'SUBJECT' => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'], + 'REPORT_TIME' => $user->format_date($row['report_time'])) ); } } diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php index 00a1abd96d..68cceebc66 100644 --- a/phpBB/includes/mcp/mcp_post.php +++ b/phpBB/includes/mcp/mcp_post.php @@ -143,18 +143,21 @@ function mcp_post_details($id, $mode, $action, $url) 'U_VIEW_PROFILE' => "memberlist.$phpEx$SID&mode=viewprofile&u=" . $post_info['user_id'], 'U_MCP_USERNOTES' => "mcp.$phpEx$SID&i=notes&mode=user_notes&u=" . $post_info['user_id'], 'U_MCP_WARNINGS' => "mcp.$phpEx$SID&i=warnings&mode=view_user&u=" . $post_info['user_id'], + 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? "{$phpbb_root_path}posting.$phpEx$SID&mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}" : '', 'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&p=$post_id#$post_id\">", '</a>'), 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], "<a href=\"viewforum.$phpEx$SID&f={$post_info['forum_id']}&start={$start}\">", '</a>'), 'REPORTED_IMG' => $user->img('icon_reported', $user->lang['POST_REPORTED']), 'UNAPPROVED_IMG' => $user->img('icon_unapproved', $user->lang['POST_UNAPPROVED']), + 'EDIT_IMG' => $user->img('btn_edit', $user->lang['EDIT_POST']), 'POSTER_NAME' => $poster, 'POST_PREVIEW' => $message, 'POST_SUBJECT' => $post_info['post_subject'], 'POST_DATE' => $user->format_date($post_info['post_time']), 'POST_IP' => $post_info['poster_ip'], - 'POST_IPADDR' => @gethostbyaddr($post_info['poster_ip'])) + 'POST_IPADDR' => @gethostbyaddr($post_info['poster_ip']), + 'POST_ID' => $post_info['post_id']) ); // Get Reports diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 0106f8c6e2..171751219f 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -26,6 +26,24 @@ class mcp_queue extends module { case 'approve': case 'disapprove': + include_once($phpbb_root_path . 'includes/functions_messenger.'.$phpEx); + include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); + + $post_id_list = get_array('post_id_list', 0); + + if (!$post_id_list) + { + trigger_error('NO_POST_SELECTED'); + } + + if ($mode == 'approve') + { + approve_post($post_id_list); + } + else + { + disapprove_post($post_id_list); + } break; @@ -35,6 +53,14 @@ class mcp_queue extends module include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); $post_id = request_var('p', 0); + $topic_id = request_var('t', 0); + + if ($topic_id) + { + $topic_info = get_topic_data(array($topic_id), 'm_approve'); + $post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; + } + $post_info = get_post_data(array($post_id), 'm_approve'); if (!sizeof($post_info)) @@ -66,6 +92,7 @@ class mcp_queue extends module $message = smilie_text($message); $template->assign_vars(array( + 'S_MCP_QUEUE' => true, 'S_APPROVE_ACTION' => "mcp.$phpEx$SID&i=queue&p=$post_id&f=$forum_id", 'S_CAN_VIEWIP' => $auth->acl_get('m_ip', $post_info['forum_id']), @@ -78,19 +105,22 @@ class mcp_queue extends module 'U_VIEW_PROFILE' => "memberlist.$phpEx$SID&mode=viewprofile&u=" . $post_info['user_id'], 'U_MCP_USERNOTES' => "mcp.$phpEx$SID&i=notes&mode=user_notes&u=" . $post_info['user_id'], 'U_MCP_WARNINGS' => "mcp.$phpEx$SID&i=warnings&mode=view_user&u=" . $post_info['user_id'], + 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? "{$phpbb_root_path}posting.$phpEx$SID&mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}" : '', 'REPORTED_IMG' => $user->img('icon_reported', $user->lang['POST_REPORTED']), 'UNAPPROVED_IMG' => $user->img('icon_unapproved', $user->lang['POST_UNAPPROVED']), + 'EDIT_IMG' => $user->img('btn_edit', $user->lang['EDIT_POST']), 'POSTER_NAME' => $poster, 'POST_PREVIEW' => $message, 'POST_SUBJECT' => $post_info['post_subject'], 'POST_DATE' => $user->format_date($post_info['post_time']), 'POST_IP' => $post_info['poster_ip'], - 'POST_IPADDR' => @gethostbyaddr($post_info['poster_ip'])) + 'POST_IPADDR' => @gethostbyaddr($post_info['poster_ip']), + 'POST_ID' => $post_info['post_id']) ); - $this->display($user->lang['MCP_QUEUE'], 'mcp_approve.html'); + $this->display($user->lang['MCP_QUEUE'], 'mcp_post.html'); break; @@ -221,7 +251,7 @@ class mcp_queue extends module $poster = $row['username']; } - $s_checkbox = ($mode == 'unapproved_posts') ? '<input type="checkbox" name="post_id_list[]" value="' . $row['post_id'] . '" />' : '<input type="checkbox" name="topic_id_list[]" value="' . $row['topic_id'] . '" />'; + $s_checkbox = '<input type="checkbox" name="post_id_list[]" value="' . $row['post_id'] . '" />'; $template->assign_block_vars('postrow', array( 'U_VIEWFORUM' => "viewforum.$phpEx$SID&f=" . $row['forum_id'], @@ -272,4 +302,441 @@ class mcp_queue extends module } } +// Approve Post/Topic +function approve_post($post_id_list) +{ + global $db, $template, $user, $config; + global $_REQUEST, $phpEx, $phpbb_root_path, $SID; + + if (!($forum_id = check_ids($post_id_list, POSTS_TABLE, 'post_id', 'm_approve'))) + { + trigger_error('NOT_AUTHORIZED'); + } + + $redirect = request_var('redirect', $user->data['session_page']); + $success_msg = ''; + + $s_hidden_fields = build_hidden_fields(array( + 'post_id_list' => $post_id_list, + 'f' => $forum_id, + 'mode' => 'approve', + 'redirect' => $redirect) + ); + + if (confirm_box(true)) + { + $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; + + $post_info = get_post_data($post_id_list, 'm_approve'); + + // If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1 + // If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1 + + $total_topics = $total_posts = $forum_topics = $forum_posts = 0; + $topic_approve_sql = $topic_replies_sql = $post_approve_sql = $topic_id_list = array(); + + foreach ($post_info as $post_id => $post_data) + { + $topic_id_list[$post_data['topic_id']] = 1; + + // Topic or Post. ;) + if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id) + { + if ($post_data['forum_id']) + { + $total_topics++; + $forum_topics++; + } + + $topic_approve_sql[] = $post_data['topic_id']; + } + else + { + if (!isset($topic_replies_sql[$post_data['topic_id']])) + { + $topic_replies_sql[$post_data['topic_id']] = 1; + } + else + { + $topic_replies_sql[$post_data['topic_id']]++; + } + } + + if ($post_data['forum_id']) + { + $total_posts++; + $forum_posts++; + } + + $post_approve_sql[] = $post_id; + } + + if (sizeof($topic_approve_sql)) + { + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_approved = 1 + WHERE topic_id IN (' . implode(', ', $topic_approve_sql) . ')'; + $db->sql_query($sql); + } + + if (sizeof($post_approve_sql)) + { + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_approved = 1 + WHERE post_id IN (' . implode(', ', $post_approve_sql) . ')'; + $db->sql_query($sql); + } + + if (sizeof($topic_replies_sql)) + { + foreach ($topic_replies_sql as $topic_id => $num_replies) + { + $sql = 'UPDATE ' . TOPICS_TABLE . " + SET topic_replies = topic_replies + $num_replies + WHERE topic_id = $topic_id"; + $db->sql_query($sql); + } + } + + if ($forum_topics || $forum_posts) + { + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET '; + $sql .= ($forum_topics) ? "forum_topics = forum_topics + $forum_topics" : ''; + $sql .= ($forum_topics && $forum_posts) ? ', ' : ''; + $sql .= ($forum_posts) ? "forum_posts = forum_posts + $forum_posts" : ''; + $sql .= " WHERE forum_id = $forum_id"; + + $db->sql_query($sql); + } + + if ($total_topics) + { + set_config('num_topics', $config['num_topics'] + $total_topics, true); + } + + if ($total_posts) + { + set_config('num_posts', $config['num_posts'] + $total_posts, true); + } + unset($topic_approve_sql, $topic_replies_sql, $post_approve_sql); + + update_post_information('topic', array_keys($topic_id_list)); + update_post_information('forum', $forum_id); + unset($topic_id_list); + + $messenger = new messenger(); + + // Notify Poster? + if ($notify_poster) + { + $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']); + + foreach ($post_info as $post_id => $post_data) + { + if ($post_data['poster_id'] == ANONYMOUS) + { + continue; + } + + $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved'; + + $messenger->template($email_template, $post_data['user_lang']); + + $messenger->replyto($config['board_email']); + $messenger->to($post_data['user_email'], $post_data['username']); + $messenger->im($post_data['user_jabber'], $post_data['username']); + + $messenger->assign_vars(array( + 'EMAIL_SIG' => $email_sig, + 'SITENAME' => $config['sitename'], + 'USERNAME' => $post_data['username'], + 'POST_SUBJECT' => censor_text($post_data['post_subject']), + 'TOPIC_TITLE' => censor_text($post_data['topic_title']), + + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t={$post_data['topic_id']}&e=0", + 'U_VIEW_POST' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t={$post_data['topic_id']}&p=$post_id&e=$post_id") + ); + + $messenger->send($post_data['user_notify_type']); + $messenger->reset(); + + if ($messenger->queue) + { + $messenger->queue->save(); + } + } + } + + // Send out normal user notifications + $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']); + + foreach ($post_info as $post_id => $post_data) + { + if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + { + // Forum Notifications + user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $forum_id, $post_data['topic_id'], $post_id); + } + else + { + // Topic Notifications + user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $forum_id, $post_data['topic_id'], $post_id); + } + } + unset($post_info); + + if ($forum_topics) + { + $success_msg = ($forum_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; + } + else + { + $success_msg = (sizeof($post_id_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS'; + } + } + else + { + $template->assign_vars(array( + 'S_NOTIFY_POSTER' => true, + 'S_APPROVE' => true) + ); + + confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + } + + $redirect = request_var('redirect', "index.$phpEx$SID"); + + if (strpos($redirect, '?') === false) + { + $redirect = substr_replace($redirect, ".$phpEx$SID&", strpos($redirect, '&'), 1); + } + + if (!$success_msg) + { + redirect($redirect); + } + else + { + meta_refresh(3, $redirect); + trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '">', '</a>')); + } +} + +// Disapprove Post/Topic +function disapprove_post($post_id_list) +{ + global $db, $template, $user, $config; + global $_REQUEST, $_POST, $phpEx, $phpbb_root_path, $SID; + + if (!($forum_id = check_ids($post_id_list, POSTS_TABLE, 'post_id', 'm_approve'))) + { + trigger_error('NOT_AUTHORIZED'); + } + + $redirect = request_var('redirect', $user->data['session_page']); + $reason = request_var('reason', ''); + $reason_id = request_var('reason_id', 0); + $success_msg = $additional_msg = ''; + + $s_hidden_fields = build_hidden_fields(array( + 'post_id_list' => $post_id_list, + 'f' => $forum_id, + 'mode' => 'disapprove', + 'redirect' => $redirect) + ); + + $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; + + if ($reason_id) + { + $sql = 'SELECT reason_name + FROM ' . REASONS_TABLE . " + WHERE reason_id = $reason_id"; + $result = $db->sql_query($sql); + + if (!($row = $db->sql_fetchrow($result)) || (!$reason && $row['reason_name'] == 'other')) + { + $additional_msg = 'Please give an appropiate reason for disapproval'; + unset($_POST['confirm']); + } + else + { + $disapprove_reason = ($row['reason_name'] != 'other') ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_name'])] : ''; + $disapprove_reason .= ($reason) ? "\n\n" . $_REQUEST['reason'] : ''; + unset($reason); + } + $db->sql_freeresult($result); + } + + if (confirm_box(true)) + { + $post_info = get_post_data($post_id_list, 'm_approve'); + + // If Topic -> forum_topics_real -= 1 + // If Post -> topic_replies_real -= 1 + + $forum_topics_real = 0; + $topic_replies_real_sql = $post_disapprove_sql = $topic_id_list = array(); + + foreach ($post_info as $post_id => $post_data) + { + $topic_id_list[$post_data['topic_id']] = 1; + + // Topic or Post. ;) + if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id) + { + if ($post_data['forum_id']) + { + $forum_topics_real++; + } + } + else + { + if (!isset($topic_replies_real_sql[$post_data['topic_id']])) + { + $topic_replies_real_sql[$post_data['topic_id']] = 1; + } + else + { + $topic_replies_real_sql[$post_data['topic_id']]++; + } + } + + $post_disapprove_sql[] = $post_id; + } + + if ($forum_topics_real) + { + $sql = 'UPDATE ' . FORUMS_TABLE . " + SET forum_topics_real = forum_topics_real - $forum_topics_real + WHERE forum_id = $forum_id"; + $db->sql_query($sql); + } + + if (sizeof($topic_replies_real_sql)) + { + foreach ($topic_replies_real_sql as $topic_id => $num_replies) + { + $sql = 'UPDATE ' . TOPICS_TABLE . " + SET topic_replies_real = topic_replies_real - $num_replies + WHERE topic_id = $topic_id"; + $db->sql_query($sql); + } + } + + if (sizeof($post_disapprove_sql)) + { + // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts + delete_posts('post_id', $post_disapprove_sql); + } + unset($post_disapprove_sql, $topic_replies_real_sql); + + update_post_information('topic', array_keys($topic_id_list)); + update_post_information('forum', $forum_id); + unset($topic_id_list); + + $messenger = new messenger(); + + // Notify Poster? + if ($notify_poster) + { + $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']); + + foreach ($post_info as $post_id => $post_data) + { + if ($post_data['poster_id'] == ANONYMOUS) + { + continue; + } + + $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved'; + + $messenger->template($email_template, $post_data['user_lang']); + + $messenger->replyto($config['board_email']); + $messenger->to($post_data['user_email'], $post_data['username']); + $messenger->im($post_data['user_jabber'], $post_data['username']); + + $messenger->assign_vars(array( + 'EMAIL_SIG' => $email_sig, + 'SITENAME' => $config['sitename'], + 'USERNAME' => $post_data['username'], + 'REASON' => stripslashes($disapprove_reason), + 'POST_SUBJECT' => censor_text($post_data['post_subject']), + 'TOPIC_TITLE' => censor_text($post_data['topic_title'])) + ); + + $messenger->send($post_data['user_notify_type']); + $messenger->reset(); + + if ($messenger->queue) + { + $messenger->queue->save(); + } + } + } + unset($post_info, $disapprove_reason); + + if ($forum_topics_real) + { + $success_msg = ($forum_topics_real == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS'; + } + else + { + $success_msg = (sizeof($post_id_list) == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS'; + } + } + else + { + $sql = 'SELECT * + FROM ' . REASONS_TABLE . ' + ORDER BY reason_priority ASC'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $row['reason_name'] = strtoupper($row['reason_name']); + + $reason_title = (!empty($user->lang['report_reasons']['TITLE'][$row['reason_name']])) ? $user->lang['report_reasons']['TITLE'][$row['reason_name']] : ucwords(str_replace('_', ' ', $row['reason_name'])); + + $reason_desc = (!empty($user->lang['report_reasons']['DESCRIPTION'][$row['reason_name']])) ? $user->lang['report_reasons']['DESCRIPTION'][$row['reason_name']] : $row['reason_desc']; + + $template->assign_block_vars('reason', array( + 'ID' => $row['reason_id'], + 'NAME' => htmlspecialchars($reason_title), + 'DESCRIPTION' => htmlspecialchars($reason_desc), + 'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false) + ); + } + $db->sql_freeresult($result); + + $template->assign_vars(array( + 'S_NOTIFY_POSTER' => true, + 'S_APPROVE' => false, + 'REASON' => $reason, + 'ADDITIONAL_MSG' => $additional_msg) + ); + + confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + } + + $redirect = request_var('redirect', "index.$phpEx$SID"); + + if (strpos($redirect, '?') === false) + { + $redirect = substr_replace($redirect, ".$phpEx$SID&", strpos($redirect, '&'), 1); + } + + if (!$success_msg) + { + redirect($redirect); + } + else + { + meta_refresh(3, "viewforum.$phpEx$SID&f=$forum_id"); + trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '">', '</a>')); + } +} + ?>
\ No newline at end of file diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 7d1cb201e4..2004e51874 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -144,7 +144,7 @@ function mcp_topic_view($id, $mode, $action, $url) 'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true, 'U_POST_DETAILS' => "$url&p={$row['post_id']}&mode=post_details", - 'U_MCP_APPROVE' => "mcp.$phpEx$SID&i=queue&mode=approve&p=" . $row['post_id']) + 'U_MCP_APPROVE' => "mcp.$phpEx$SID&i=queue&mode=approve&post_id_list[]=" . $row['post_id']) ); unset($rowset[$i]); |