' . $user->lang('RETURN_PAGE', '', '');
// If approving one post, also give links back to post...
if (sizeof($post_info) == 1 && $post_url)
{
$message .= '
' . $user->lang('RETURN_POST', '', '');
}
}
trigger_error($message);
}
else
{
$show_notify = false;
if ($action == 'approve')
{
foreach ($post_info as $post_data)
{
if ($post_data['poster_id'] == ANONYMOUS)
{
continue;
}
else
{
$show_notify = true;
break;
}
}
}
$template->assign_vars(array(
'S_NOTIFY_POSTER' => $show_notify,
'S_' . strtoupper($action) => true,
));
confirm_box(false, strtoupper($action) . '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
}
$redirect = $request->variable('redirect', "index.$phpEx");
$redirect = reapply_sid($redirect);
redirect($redirect);
}
/**
* Approve/Restore topics
*
* @param $action string Action we perform on the posts ('approve' or 'restore')
* @param $topic_id_list array IDs of the topics to approve/restore
* @param $id mixed Category of the current active module
* @param $mode string Active module
* @return null
*/
static public function approve_topics($action, $topic_id_list, $id, $mode)
{
global $db, $template, $user, $config;
global $phpEx, $phpbb_root_path, $request, $phpbb_container;
if (!check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve')))
{
trigger_error('NOT_AUTHORISED');
}
$redirect = $request->variable('redirect', build_url(array('quickmod')));
$success_msg = $topic_url = '';
$approve_log = array();
$s_hidden_fields = build_hidden_fields(array(
'i' => $id,
'mode' => $mode,
'topic_id_list' => $topic_id_list,
'action' => $action,
'redirect' => $redirect,
));
$topic_info = get_topic_data($topic_id_list, 'm_approve');
if (confirm_box(true))
{
$notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false;
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
foreach ($topic_info as $topic_id => $topic_data)
{
$phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '');
$topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&t={$topic_id}");
$approve_log[] = array(
'forum_id' => $topic_data['forum_id'],
'topic_id' => $topic_data['topic_id'],
'topic_title' => $topic_data['topic_title'],
);
}
if (sizeof($topic_info) >= 1)
{
$success_msg = (sizeof($topic_info) == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS';
}
foreach ($approve_log as $log_data)
{
add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_TOPIC_' . strtoupper($action) . 'D', $log_data['topic_title']);
}
// Only send out the mails, when the posts are being approved
if ($action == 'approve')
{
// Handle notifications
$phpbb_notifications = $phpbb_container->get('notification_manager');
foreach ($topic_info as $topic_id => $topic_data)
{
$phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']);
$phpbb_notifications->add_notifications(array(
'quote',
'topic',
), $post_data);
$phpbb_notifications->mark_notifications_read('quote', $post_data['post_id'], $user->data['user_id']);
$phpbb_notifications->mark_notifications_read('topic', $post_data['topic_id'], $user->data['user_id']);
if ($notify_poster)
{
$phpbb_notifications->add_notifications('approve_topic', $post_data);
}
}
}
meta_refresh(3, $redirect);
$message = $user->lang[$success_msg];
if ($request->is_ajax())
{
$json_response = new \phpbb\json_response;
$json_response->send(array(
'MESSAGE_TITLE' => $user->lang['INFORMATION'],
'MESSAGE_TEXT' => $message,
'REFRESH_DATA' => null,
'visible' => true,
));
}
else
{
$message .= '
' . $user->lang('RETURN_PAGE', '', '');
// If approving one topic, also give links back to topic...
if (sizeof($topic_info) == 1 && $topic_url)
{
$message .= '
' . $user->lang('RETURN_TOPIC', '', '');
}
}
trigger_error($message);
}
else
{
$show_notify = false;
if ($action == 'approve')
{
foreach ($topic_info as $topic_data)
{
if ($topic_data['topic_poster'] == ANONYMOUS)
{
continue;
}
else
{
$show_notify = true;
break;
}
}
}
$template->assign_vars(array(
'S_NOTIFY_POSTER' => $show_notify,
'S_' . strtoupper($action) => true,
));
confirm_box(false, strtoupper($action) . '_TOPIC' . ((sizeof($topic_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
}
$redirect = $request->variable('redirect', "index.$phpEx");
$redirect = reapply_sid($redirect);
redirect($redirect);
}
/**
* Disapprove Post
*
* @param $post_id_list array IDs of the posts to disapprove/delete
* @param $id mixed Category of the current active module
* @param $mode string Active module
* @return null
*/
static public function disapprove_posts($post_id_list, $id, $mode)
{
global $db, $template, $user, $config, $phpbb_container;
global $phpEx, $phpbb_root_path, $request;
if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
{
trigger_error('NOT_AUTHORISED');
}
$redirect = $request->variable('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode");
$reason = $request->variable('reason', '', true);
$reason_id = $request->variable('reason_id', 0);
$success_msg = $additional_msg = '';
$s_hidden_fields = build_hidden_fields(array(
'i' => $id,
'mode' => $mode,
'post_id_list' => $post_id_list,
'action' => 'disapprove',
'redirect' => $redirect,
));
$notify_poster = $request->is_set('notify_poster');
$disapprove_reason = '';
if ($reason_id)
{
$sql = 'SELECT reason_title, reason_description
FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_id = $reason_id";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
{
$additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
$request->overwrite('confirm', null, \phpbb\request\request_interface::POST);
$request->overwrite('confirm_key', null, \phpbb\request\request_interface::POST);
$request->overwrite('confirm_key', null, \phpbb\request\request_interface::REQUEST);
}
else
{
// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
$disapprove_reason = (strtolower($row['reason_title']) != 'other') ? ((isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description']) : '';
$disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
{
$disapprove_reason_lang = strtoupper($row['reason_title']);
}
}
}
$post_info = get_post_data($post_id_list, 'm_approve');
$is_disapproving = false;
foreach ($post_info as $post_id => $post_data)
{
if ($post_data['post_visibility'] == ITEM_DELETED)
{
continue;
}
$is_disapproving = true;
}
if (confirm_box(true))
{
$disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array();
$topic_posts_unapproved = $post_disapprove_list = $topic_information = array();
// Build a list of posts to be disapproved and get the related topics real replies count
foreach ($post_info as $post_id => $post_data)
{
$post_disapprove_list[$post_id] = $post_data['topic_id'];
if (!isset($topic_posts_unapproved[$post_data['topic_id']]))
{
$topic_information[$post_data['topic_id']] = $post_data;
$topic_posts_unapproved[$post_data['topic_id']] = 0;
}
$topic_posts_unapproved[$post_data['topic_id']]++;
}
// Now we build the log array
foreach ($post_disapprove_list as $post_id => $topic_id)
{
// If the count of disapproved posts for the topic is equal
// to the number of unapproved posts in the topic, and there are no different
// posts, we disapprove the hole topic
if ($topic_information[$topic_id]['topic_posts_approved'] == 0 &&
$topic_information[$topic_id]['topic_posts_softdeleted'] == 0 &&
$topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id])
{
// Don't write the log more than once for every topic
if (!isset($disapprove_log_topics[$topic_id]))
{
// Build disapproved topics log
$disapprove_log_topics[$topic_id] = array(
'type' => 'topic',
'post_subject' => $post_info[$post_id]['topic_title'],
'forum_id' => $post_info[$post_id]['forum_id'],
'topic_id' => 0, // useless to log a topic id, as it will be deleted
'post_username' => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'],
);
}
}
else
{
// Build disapproved posts log
$disapprove_log_posts[] = array(
'type' => 'post',
'post_subject' => $post_info[$post_id]['post_subject'],
'forum_id' => $post_info[$post_id]['forum_id'],
'topic_id' => $post_info[$post_id]['topic_id'],
'post_username' => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'],
);
}
}
// Get disapproved posts/topics counts separately
$num_disapproved_topics = sizeof($disapprove_log_topics);
$num_disapproved_posts = sizeof($disapprove_log_posts);
// Build the whole log
$disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
// Unset unneeded arrays
unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
// Let's do the job - delete disapproved posts
if (sizeof($post_disapprove_list))
{
if (!function_exists('delete_posts'))
{
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
}
// We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
// Note: function delete_posts triggers related forums/topics sync,
// so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
delete_posts('post_id', array_keys($post_disapprove_list));
foreach ($disapprove_log as $log_data)
{
if ($is_disapproving)
{
$l_log_message = ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED';
add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $disapprove_reason);
}
else
{
$l_log_message = ($log_data['type'] == 'topic') ? 'LOG_DELETE_TOPIC' : 'LOG_DELETE_POST';
add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $log_data['post_username']);
}
}
}
$phpbb_notifications = $phpbb_container->get('notification_manager');
$lang_reasons = array();
foreach ($post_info as $post_id => $post_data)
{
$disapprove_all_posts_in_topic = $topic_information[$topic_id]['topic_posts_approved'] == 0 &&
$topic_information[$topic_id]['topic_posts_softdeleted'] == 0 &&
$topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id];
$phpbb_notifications->delete_notifications('post_in_queue', $post_id);
// Do we disapprove the whole topic? Remove potential notifications
if ($disapprove_all_posts_in_topic)
{
$phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']);
}
// Notify Poster?
if ($notify_poster)
{
if ($post_data['poster_id'] == ANONYMOUS)
{
continue;
}
$post_data['disapprove_reason'] = '';
if (isset($disapprove_reason_lang))
{
// Okay we need to get the reason from the posters language
if (!isset($lang_reasons[$post_data['user_lang']]))
{
// Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
$lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
// Only load up the language pack if the language is different to the current one
if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx))
{
// Load up the language pack
$lang = array();
@include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
// If we find the reason in this language pack use it
if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
{
$lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
}
unset($lang); // Free memory
}
}
$post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']];
$post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : '';
}
if ($disapprove_all_posts_in_topic && $topic_information[$topic_id]['topic_posts_unapproved'] == 1)
{
// If there is only 1 post when disapproving the topic,
// we send the user a "disapprove topic" notification...
$phpbb_notifications->add_notifications('disapprove_topic', $post_data);
}
else
{
// ... otherwise there are multiple unapproved posts and
// all of them are disapproved as posts.
$phpbb_notifications->add_notifications('disapprove_post', $post_data);
}
}
}
unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang);
if ($num_disapproved_topics)
{
$success_msg = ($num_disapproved_topics == 1) ? 'TOPIC' : 'TOPICS';
}
else
{
$success_msg = ($num_disapproved_posts == 1) ? 'POST' : 'POSTS';
}
if ($is_disapproving)
{
$success_msg .= '_DISAPPROVED_SUCCESS';
}
else
{
$success_msg .= '_DELETED_SUCCESS';
}
meta_refresh(3, $redirect);
$message = $user->lang[$success_msg];
if ($request->is_ajax())
{
$json_response = new \phpbb\json_response;
$json_response->send(array(
'MESSAGE_TITLE' => $user->lang['INFORMATION'],
'MESSAGE_TEXT' => $message,
'REFRESH_DATA' => null,
'visible' => false,
));
}
else
{
$message .= '