mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/16350] Move shared code to functions.php
PHPBB3-16350
This commit is contained in:
parent
0641c209d7
commit
e2cc1aec26
3 changed files with 134 additions and 133 deletions
|
@ -156,7 +156,8 @@ class acp_ban
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
self::display_ban_options($mode);
|
display_ban_end_options();
|
||||||
|
display_ban_options($mode);
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'L_TITLE' => $this->page_title,
|
'L_TITLE' => $this->page_title,
|
||||||
|
@ -173,126 +174,4 @@ class acp_ban
|
||||||
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_ban&field=ban'),
|
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_ban&field=ban'),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Display ban options
|
|
||||||
*/
|
|
||||||
static public function display_ban_options($mode)
|
|
||||||
{
|
|
||||||
global $user, $db, $template;
|
|
||||||
|
|
||||||
// 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'] . ' -> ');
|
|
||||||
|
|
||||||
$ban_end_options = '';
|
|
||||||
foreach ($ban_end_text as $length => $text)
|
|
||||||
{
|
|
||||||
$ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($mode)
|
|
||||||
{
|
|
||||||
case 'user':
|
|
||||||
|
|
||||||
$field = 'username';
|
|
||||||
|
|
||||||
$sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
|
|
||||||
FROM ' . BANLIST_TABLE . ' b, ' . USERS_TABLE . ' u
|
|
||||||
WHERE (b.ban_end >= ' . time() . '
|
|
||||||
OR b.ban_end = 0)
|
|
||||||
AND u.user_id = b.ban_userid
|
|
||||||
ORDER BY u.username_clean ASC';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'ip':
|
|
||||||
|
|
||||||
$field = 'ban_ip';
|
|
||||||
|
|
||||||
$sql = 'SELECT *
|
|
||||||
FROM ' . BANLIST_TABLE . '
|
|
||||||
WHERE (ban_end >= ' . time() . "
|
|
||||||
OR ban_end = 0)
|
|
||||||
AND ban_ip <> ''
|
|
||||||
ORDER BY ban_ip";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'email':
|
|
||||||
|
|
||||||
$field = 'ban_email';
|
|
||||||
|
|
||||||
$sql = 'SELECT *
|
|
||||||
FROM ' . BANLIST_TABLE . '
|
|
||||||
WHERE (ban_end >= ' . time() . "
|
|
||||||
OR ban_end = 0)
|
|
||||||
AND ban_email <> ''
|
|
||||||
ORDER BY ban_email";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$result = $db->sql_query($sql);
|
|
||||||
|
|
||||||
$banned_options = $excluded_options = array();
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$option = '<option value="' . $row['ban_id'] . '">' . $row[$field] . '</option>';
|
|
||||||
|
|
||||||
if ($row['ban_exclude'])
|
|
||||||
{
|
|
||||||
$excluded_options[] = $option;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$banned_options[] = $option;
|
|
||||||
}
|
|
||||||
|
|
||||||
$time_length = ($row['ban_end']) ? ($row['ban_end'] - $row['ban_start']) / 60 : 0;
|
|
||||||
|
|
||||||
if ($time_length == 0)
|
|
||||||
{
|
|
||||||
// Banned permanently
|
|
||||||
$ban_length = $user->lang['PERMANENT'];
|
|
||||||
}
|
|
||||||
else if (isset($ban_end_text[$time_length]))
|
|
||||||
{
|
|
||||||
// Banned for a given duration
|
|
||||||
$ban_length = $user->lang('BANNED_UNTIL_DURATION', $ban_end_text[$time_length], $user->format_date($row['ban_end'], false, true));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Banned until given date
|
|
||||||
$ban_length = $user->lang('BANNED_UNTIL_DATE', $user->format_date($row['ban_end'], false, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
$template->assign_block_vars('bans', array(
|
|
||||||
'BAN_ID' => (int) $row['ban_id'],
|
|
||||||
'LENGTH' => $ban_length,
|
|
||||||
'A_LENGTH' => addslashes($ban_length),
|
|
||||||
'REASON' => $row['ban_reason'],
|
|
||||||
'A_REASON' => addslashes($row['ban_reason']),
|
|
||||||
'GIVE_REASON' => $row['ban_give_reason'],
|
|
||||||
'A_GIVE_REASON' => addslashes($row['ban_give_reason']),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
$db->sql_freeresult($result);
|
|
||||||
|
|
||||||
$options = '';
|
|
||||||
if ($excluded_options)
|
|
||||||
{
|
|
||||||
$options .= '<optgroup label="' . $user->lang['OPTIONS_EXCLUDED'] . '">';
|
|
||||||
$options .= implode('', $excluded_options);
|
|
||||||
$options .= '</optgroup>';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($banned_options)
|
|
||||||
{
|
|
||||||
$options .= '<optgroup label="' . $user->lang['OPTIONS_BANNED'] . '">';
|
|
||||||
$options .= implode('', $banned_options);
|
|
||||||
$options .= '</optgroup>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$template->assign_vars(array(
|
|
||||||
'S_BAN_END_OPTIONS' => $ban_end_options,
|
|
||||||
'S_BANNED_OPTIONS' => ($banned_options || $excluded_options) ? true : false,
|
|
||||||
'BANNED_OPTIONS' => $options,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4941,3 +4941,133 @@ function phpbb_get_board_contact_link(\phpbb\config\config $config, $phpbb_root_
|
||||||
return 'mailto:' . htmlspecialchars($config['board_contact']);
|
return 'mailto:' . htmlspecialchars($config['board_contact']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function display_ban_end_options()
|
||||||
|
{
|
||||||
|
global $user, $template;
|
||||||
|
|
||||||
|
// 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'] . ' -> ');
|
||||||
|
|
||||||
|
$ban_end_options = '';
|
||||||
|
foreach ($ban_end_text as $length => $text)
|
||||||
|
{
|
||||||
|
$ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$template->assign_vars(array(
|
||||||
|
'S_BAN_END_OPTIONS' => $ban_end_options
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display ban options
|
||||||
|
*/
|
||||||
|
function display_ban_options($mode)
|
||||||
|
{
|
||||||
|
global $user, $db, $template;
|
||||||
|
|
||||||
|
switch ($mode)
|
||||||
|
{
|
||||||
|
case 'user':
|
||||||
|
|
||||||
|
$field = 'username';
|
||||||
|
|
||||||
|
$sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
|
||||||
|
FROM ' . BANLIST_TABLE . ' b, ' . USERS_TABLE . ' u
|
||||||
|
WHERE (b.ban_end >= ' . time() . '
|
||||||
|
OR b.ban_end = 0)
|
||||||
|
AND u.user_id = b.ban_userid
|
||||||
|
ORDER BY u.username_clean ASC';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'ip':
|
||||||
|
|
||||||
|
$field = 'ban_ip';
|
||||||
|
|
||||||
|
$sql = 'SELECT *
|
||||||
|
FROM ' . BANLIST_TABLE . '
|
||||||
|
WHERE (ban_end >= ' . time() . "
|
||||||
|
OR ban_end = 0)
|
||||||
|
AND ban_ip <> ''
|
||||||
|
ORDER BY ban_ip";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'email':
|
||||||
|
|
||||||
|
$field = 'ban_email';
|
||||||
|
|
||||||
|
$sql = 'SELECT *
|
||||||
|
FROM ' . BANLIST_TABLE . '
|
||||||
|
WHERE (ban_end >= ' . time() . "
|
||||||
|
OR ban_end = 0)
|
||||||
|
AND ban_email <> ''
|
||||||
|
ORDER BY ban_email";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
|
$banned_options = $excluded_options = array();
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$option = '<option value="' . $row['ban_id'] . '">' . $row[$field] . '</option>';
|
||||||
|
|
||||||
|
if ($row['ban_exclude'])
|
||||||
|
{
|
||||||
|
$excluded_options[] = $option;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$banned_options[] = $option;
|
||||||
|
}
|
||||||
|
|
||||||
|
$time_length = ($row['ban_end']) ? ($row['ban_end'] - $row['ban_start']) / 60 : 0;
|
||||||
|
|
||||||
|
if ($time_length == 0)
|
||||||
|
{
|
||||||
|
// Banned permanently
|
||||||
|
$ban_length = $user->lang['PERMANENT'];
|
||||||
|
}
|
||||||
|
else if (isset($ban_end_text[$time_length]))
|
||||||
|
{
|
||||||
|
// Banned for a given duration
|
||||||
|
$ban_length = $user->lang('BANNED_UNTIL_DURATION', $ban_end_text[$time_length], $user->format_date($row['ban_end'], false, true));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Banned until given date
|
||||||
|
$ban_length = $user->lang('BANNED_UNTIL_DATE', $user->format_date($row['ban_end'], false, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
$template->assign_block_vars('bans', array(
|
||||||
|
'BAN_ID' => (int) $row['ban_id'],
|
||||||
|
'LENGTH' => $ban_length,
|
||||||
|
'A_LENGTH' => addslashes($ban_length),
|
||||||
|
'REASON' => $row['ban_reason'],
|
||||||
|
'A_REASON' => addslashes($row['ban_reason']),
|
||||||
|
'GIVE_REASON' => $row['ban_give_reason'],
|
||||||
|
'A_GIVE_REASON' => addslashes($row['ban_give_reason']),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$options = '';
|
||||||
|
if ($excluded_options)
|
||||||
|
{
|
||||||
|
$options .= '<optgroup label="' . $user->lang['OPTIONS_EXCLUDED'] . '">';
|
||||||
|
$options .= implode('', $excluded_options);
|
||||||
|
$options .= '</optgroup>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($banned_options)
|
||||||
|
{
|
||||||
|
$options .= '<optgroup label="' . $user->lang['OPTIONS_BANNED'] . '">';
|
||||||
|
$options .= implode('', $banned_options);
|
||||||
|
$options .= '</optgroup>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$template->assign_vars(array(
|
||||||
|
'S_BANNED_OPTIONS' => ($banned_options || $excluded_options) ? true : false,
|
||||||
|
'BANNED_OPTIONS' => $options,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
|
@ -185,15 +185,6 @@ class mcp_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'] . ' -> ');
|
|
||||||
|
|
||||||
$ban_end_options = '';
|
|
||||||
foreach ($ban_end_text as $length => $text)
|
|
||||||
{
|
|
||||||
$ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define language vars
|
// Define language vars
|
||||||
$this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
|
$this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
|
||||||
|
|
||||||
|
@ -218,7 +209,8 @@ class mcp_ban
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
acp_ban::display_ban_options($mode);
|
display_ban_end_options();
|
||||||
|
display_ban_options($mode);
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'L_TITLE' => $this->page_title,
|
'L_TITLE' => $this->page_title,
|
||||||
|
|
Loading…
Add table
Reference in a new issue