function main($id, $mode)
{
global $db, $user, $auth, $template, $request, $phpbb_dispatcher;
global $phpbb_root_path, $phpEx;
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
// Include the admin banning interface...
include $phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx;
$bansubmit = $request->is_set_post('bansubmit');
$unbansubmit = $request->is_set_post('unbansubmit');
$user->add_lang(array('acp/ban', 'acp/users'));
$this->tpl_name = 'mcp_ban';
/**
* Use this event to pass perform actions when a ban is issued or revoked
*
* @event core.mcp_ban_main
* @var bool bansubmit True if a ban is issued
* @var bool unbansubmit True if a ban is removed
* @var string mode Mode of the ban that is being worked on
* @since 3.1.0-RC5
*/
$vars = array('bansubmit', 'unbansubmit', 'mode');
extract($phpbb_dispatcher->trigger_event('core.mcp_ban_main', compact($vars)));
// Ban submitted?
if ($bansubmit) {
// Grab the list of entries
$ban = $request->variable('ban', '', $mode === 'user');
$ban_length = $request->variable('banlength', 0);
$ban_length_other = $request->variable('banlengthother', '');
$ban_exclude = $request->variable('banexclude', 0);
$ban_reason = $request->variable('banreason', '', true);
$ban_give_reason = $request->variable('bangivereason', '', true);
if ($ban) {
if (confirm_box(true)) {
$abort_ban = false;
/**
* Use this event to modify the ban details before the ban is performed
*
* @event core.mcp_ban_before
* @var string mode One of the following: user, ip, email
* @var string ban Either string or array with usernames, ips or email addresses
* @var int ban_length Ban length in minutes
* @var string ban_length_other Ban length as a date (YYYY-MM-DD)
* @var bool ban_exclude Are we banning or excluding from another ban
* @var string ban_reason Ban reason displayed to moderators
* @var string ban_give_reason Ban reason displayed to the banned user
* @var mixed abort_ban Either false, or an error message that is displayed to the user.
* If a string is given the bans are not issued.
* @since 3.1.0-RC5
*/
$vars = array('mode', 'ban', 'ban_length', 'ban_length_other', 'ban_exclude', 'ban_reason', 'ban_give_reason', 'abort_ban');
extract($phpbb_dispatcher->trigger_event('core.mcp_ban_before', compact($vars)));
if ($abort_ban) {
trigger_error($abort_ban);
}
user_ban($mode, $ban, $ban_length, $ban_length_other, $ban_exclude, $ban_reason, $ban_give_reason);
/**
* Use this event to perform actions after the ban has been performed
*
* @event core.mcp_ban_after
* @var string mode One of the following: user, ip, email
* @var string ban Either string or array with usernames, ips or email addresses
* @var int ban_length Ban length in minutes
* @var string ban_length_other Ban length as a date (YYYY-MM-DD)
* @var bool ban_exclude Are we banning or excluding from another ban
* @var string ban_reason Ban reason displayed to moderators
* @var string ban_give_reason Ban reason displayed to the banned user
* @since 3.1.0-RC5
*/
$vars = array('mode', 'ban', 'ban_length', 'ban_length_other', 'ban_exclude', 'ban_reason', 'ban_give_reason');
extract($phpbb_dispatcher->trigger_event('core.mcp_ban_after', compact($vars)));
trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">« ' . $user->lang['BACK_TO_PREV'] . '</a>');
} else {
$hidden_fields = array('mode' => $mode, 'ban' => $ban, 'bansubmit' => true, 'banlength' => $ban_length, 'banlengthother' => $ban_length_other, 'banexclude' => $ban_exclude, 'banreason' => $ban_reason, 'bangivereason' => $ban_give_reason);
/**
* Use this event to pass data from the ban form to the confirmation screen
*
* @event core.mcp_ban_confirm
* @var array hidden_fields Hidden fields that are passed through the confirm screen
* @since 3.1.0-RC5
*/
$vars = array('hidden_fields');
extract($phpbb_dispatcher->trigger_event('core.mcp_ban_confirm', compact($vars)));
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($hidden_fields));
}
}
} else {
if ($unbansubmit) {
$ban = $request->variable('unban', array(''));
if ($ban) {
if (confirm_box(true)) {
user_unban($mode, $ban);
trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">« ' . $user->lang['BACK_TO_PREV'] . '</a>');
} else {
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mode' => $mode, 'unbansubmit' => true, 'unban' => $ban)));
}
}
}
}
// Ban length options
$ban_end_text = array(0 => $user->lang['PERMANENT'], 30 => $user->lang['30_MINS'], 60 => $user->lang['1_HOUR'], 360 => $user->lang['6_HOURS'], 1440 => $user->lang['1_DAY'], 10080 => $user->lang['7_DAYS'], 20160 => $user->lang['2_WEEKS'], 40320 => $user->lang['1_MONTH'], -1 => $user->lang['UNTIL'] . ' -> ');
//.........这里部分代码省略.........
function main($id, $mode)
{
global $user, $template, $request, $phpbb_dispatcher;
global $phpbb_root_path, $phpEx;
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
$bansubmit = $request->is_set_post('bansubmit');
$unbansubmit = $request->is_set_post('unbansubmit');
$user->add_lang(array('acp/ban', 'acp/users'));
$this->tpl_name = 'acp_ban';
$form_key = 'acp_ban';
add_form_key($form_key);
if (($bansubmit || $unbansubmit) && !check_form_key($form_key)) {
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
// Ban submitted?
if ($bansubmit) {
// Grab the list of entries
$ban = $request->variable('ban', '', true);
$ban_length = $request->variable('banlength', 0);
$ban_length_other = $request->variable('banlengthother', '');
$ban_exclude = $request->variable('banexclude', 0);
$ban_reason = $request->variable('banreason', '', true);
$ban_give_reason = $request->variable('bangivereason', '', true);
if ($ban) {
$abort_ban = false;
/**
* Use this event to modify the ban details before the ban is performed
*
* @event core.acp_ban_before
* @var string mode One of the following: user, ip, email
* @var string ban Either string or array with usernames, ips or email addresses
* @var int ban_length Ban length in minutes
* @var string ban_length_other Ban length as a date (YYYY-MM-DD)
* @var bool ban_exclude Are we banning or excluding from another ban
* @var string ban_reason Ban reason displayed to moderators
* @var string ban_give_reason Ban reason displayed to the banned user
* @var mixed abort_ban Either false, or an error message that is displayed to the user.
* If a string is given the bans are not issued.
* @since 3.1.0-RC5
*/
$vars = array('mode', 'ban', 'ban_length', 'ban_length_other', 'ban_exclude', 'ban_reason', 'ban_give_reason', 'abort_ban');
extract($phpbb_dispatcher->trigger_event('core.acp_ban_before', compact($vars)));
if ($abort_ban) {
trigger_error($abort_ban . adm_back_link($this->u_action));
}
user_ban($mode, $ban, $ban_length, $ban_length_other, $ban_exclude, $ban_reason, $ban_give_reason);
/**
* Use this event to perform actions after the ban has been performed
*
* @event core.acp_ban_after
* @var string mode One of the following: user, ip, email
* @var string ban Either string or array with usernames, ips or email addresses
* @var int ban_length Ban length in minutes
* @var string ban_length_other Ban length as a date (YYYY-MM-DD)
* @var bool ban_exclude Are we banning or excluding from another ban
* @var string ban_reason Ban reason displayed to moderators
* @var string ban_give_reason Ban reason displayed to the banned user
* @since 3.1.0-RC5
*/
$vars = array('mode', 'ban', 'ban_length', 'ban_length_other', 'ban_exclude', 'ban_reason', 'ban_give_reason');
extract($phpbb_dispatcher->trigger_event('core.acp_ban_after', compact($vars)));
trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
}
} else {
if ($unbansubmit) {
$ban = $request->variable('unban', array(''));
if ($ban) {
user_unban($mode, $ban);
trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
}
}
}
// Define language vars
$this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
$l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
$l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
$l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
$l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
$l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
switch ($mode) {
case 'user':
$l_ban_cell = $user->lang['USERNAME'];
break;
case 'ip':
$l_ban_cell = $user->lang['IP_HOSTNAME'];
break;
case 'email':
$l_ban_cell = $user->lang['EMAIL_ADDRESS'];
break;
}
self::display_ban_options($mode);
$template->assign_vars(array('L_TITLE' => $this->page_title, 'L_EXPLAIN' => $l_ban_explain, 'L_UNBAN_TITLE' => $l_unban_title, 'L_UNBAN_EXPLAIN' => $l_unban_explain, 'L_BAN_CELL' => $l_ban_cell, 'L_BAN_EXCLUDE_EXPLAIN' => $l_ban_exclude_explain, 'L_NO_BAN_CELL' => $l_no_ban_cell, 'S_USERNAME_BAN' => $mode == 'user' ? true : false, 'U_ACTION' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=acp_ban&field=ban')));
}
private function ban_by_ip($ip)
{
if (!function_exists('user_ban')) {
include $this->root_path . 'includes/functions_user.' . $this->php_ext;
}
// ban the nub for one hour
user_ban('ip', $ip, 60, 0, false, $this->user->lang['SFS_BANNED'], $this->user->lang['SFS_BANNED']);
return;
}
/**
* Ban user by minimum karma;
*/
function ban_user($user_id = ANONYMOUS)
{
// Ban by minimum karma is disabled
if (!$this->config['ban']) {
return;
}
// We don't have user id
if ($user_id == ANONYMOUS) {
return;
}
global $db, $user;
// Catch username
$sql = 'SELECT username_clean, user_karma, user_karma_powered
FROM ' . USERS_TABLE . '
WHERE user_id = ' . $user_id;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$clean_name = $row['username_clean'];
$karma = $this->config['power'] ? $row['user_karma'] : $row['user_karma_powered'];
$db->sql_freeresult($result);
// User doesn't have enought karma, so don't ban
if ($karma > $this->config['ban_karma']) {
return;
}
// You can't ban yourself
if ($clean_name == $user->data['username_clean']) {
return;
}
// Create a list of founder...
$sql = 'SELECT user_id, user_email, username_clean
FROM ' . USERS_TABLE . '
WHERE user_type = ' . USER_FOUNDER;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$founder[$row['user_id']] = $row['user_email'];
$founder_names[$row['user_id']] = $row['username_clean'];
}
$db->sql_freeresult($result);
// You can't ban founder
if (in_array($clean_name, $founder_names)) {
return;
}
// Okay, all tests passed and we'll ban user
$mode = 'ban_userid';
// Ban by user id
$ban = $clean_name;
// Banned user
$ban_len = 0;
// Permanent ban
$ben_len_other = '';
// This field user, if baning not permanent
$ban_exclude = '';
// We don't have excludes from banning
$ban_reason = $this->config['ban_reason'];
// Ban reason showed at ACP/MCP
$ban_give_reason = $this->config['ban_give_reason'];
// Ban reason showed to user
// Ban!
user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
}
请发表评论