' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message;
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,
));
}
trigger_error($message);
}
}
/**
* 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;
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_interface::POST);
$request->overwrite('confirm_key', null, phpbb_request_interface::POST);
$request->overwrite('confirm_key', null, phpbb_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');
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
);
}
}
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'],
);
}
}
// 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_once($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)
{
add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason);
}
}
$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_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
}
else
{
$success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
}
}
else
{
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
display_reasons($reason_id);
$show_notify = false;
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_APPROVE' => false,
'REASON' => $reason,
'ADDITIONAL_MSG' => $additional_msg)
);
confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
}
$redirect = $request->variable('redirect', "index.$phpEx");
$redirect = reapply_sid($redirect);
if (!$success_msg)
{
redirect($redirect);
}
else
{
$message = $user->lang[$success_msg] . '