[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/includes/acp/ -> acp_ban.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  class acp_ban
  23  {
  24      var $u_action;
  25  
  26  	function main($id, $mode)
  27      {
  28          global $user, $template, $request, $phpbb_dispatcher;
  29          global $phpbb_root_path, $phpEx;
  30  
  31          if (!function_exists('user_ban'))
  32          {
  33              include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  34          }
  35  
  36          $bansubmit    = $request->is_set_post('bansubmit');
  37          $unbansubmit = $request->is_set_post('unbansubmit');
  38  
  39          $user->add_lang(array('acp/ban', 'acp/users'));
  40          $this->tpl_name = 'acp_ban';
  41          $form_key = 'acp_ban';
  42          add_form_key($form_key);
  43  
  44          if (($bansubmit || $unbansubmit) && !check_form_key($form_key))
  45          {
  46              trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  47          }
  48  
  49          // Ban submitted?
  50          if ($bansubmit)
  51          {
  52              // Grab the list of entries
  53              $ban                = $request->variable('ban', '', true);
  54              $ban_length            = $request->variable('banlength', 0);
  55              $ban_length_other    = $request->variable('banlengthother', '');
  56              $ban_exclude        = $request->variable('banexclude', 0);
  57              $ban_reason            = $request->variable('banreason', '', true);
  58              $ban_give_reason    = $request->variable('bangivereason', '', true);
  59  
  60              if ($ban)
  61              {
  62                  $abort_ban = false;
  63                  /**
  64                  * Use this event to modify the ban details before the ban is performed
  65                  *
  66                  * @event core.acp_ban_before
  67                  * @var    string    mode                One of the following: user, ip, email
  68                  * @var    string    ban                    Either string or array with usernames, ips or email addresses
  69                  * @var    int        ban_length            Ban length in minutes
  70                  * @var    string    ban_length_other    Ban length as a date (YYYY-MM-DD)
  71                  * @var    bool    ban_exclude            Are we banning or excluding from another ban
  72                  * @var    string    ban_reason            Ban reason displayed to moderators
  73                  * @var    string    ban_give_reason        Ban reason displayed to the banned user
  74                  * @var    mixed    abort_ban            Either false, or an error message that is displayed to the user.
  75                  *                                    If a string is given the bans are not issued.
  76                  * @since 3.1.0-RC5
  77                  */
  78                  $vars = array(
  79                      'mode',
  80                      'ban',
  81                      'ban_length',
  82                      'ban_length_other',
  83                      'ban_exclude',
  84                      'ban_reason',
  85                      'ban_give_reason',
  86                      'abort_ban',
  87                  );
  88                  extract($phpbb_dispatcher->trigger_event('core.acp_ban_before', compact($vars)));
  89  
  90                  if ($abort_ban)
  91                  {
  92                      trigger_error($abort_ban . adm_back_link($this->u_action));
  93                  }
  94                  user_ban($mode, $ban, $ban_length, $ban_length_other, $ban_exclude, $ban_reason, $ban_give_reason);
  95  
  96                  /**
  97                  * Use this event to perform actions after the ban has been performed
  98                  *
  99                  * @event core.acp_ban_after
 100                  * @var    string    mode                One of the following: user, ip, email
 101                  * @var    string    ban                    Either string or array with usernames, ips or email addresses
 102                  * @var    int        ban_length            Ban length in minutes
 103                  * @var    string    ban_length_other    Ban length as a date (YYYY-MM-DD)
 104                  * @var    bool    ban_exclude            Are we banning or excluding from another ban
 105                  * @var    string    ban_reason            Ban reason displayed to moderators
 106                  * @var    string    ban_give_reason        Ban reason displayed to the banned user
 107                  * @since 3.1.0-RC5
 108                  */
 109                  $vars = array(
 110                      'mode',
 111                      'ban',
 112                      'ban_length',
 113                      'ban_length_other',
 114                      'ban_exclude',
 115                      'ban_reason',
 116                      'ban_give_reason',
 117                  );
 118                  extract($phpbb_dispatcher->trigger_event('core.acp_ban_after', compact($vars)));
 119  
 120                  trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
 121              }
 122          }
 123          else if ($unbansubmit)
 124          {
 125              $ban = $request->variable('unban', array(''));
 126  
 127              if ($ban)
 128              {
 129                  user_unban($mode, $ban);
 130  
 131                  trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
 132              }
 133          }
 134  
 135          // Define language vars
 136          $this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
 137  
 138          $l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
 139          $l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
 140          $l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
 141          $l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
 142          $l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
 143  
 144          switch ($mode)
 145          {
 146              case 'user':
 147                  $l_ban_cell = $user->lang['USERNAME'];
 148              break;
 149  
 150              case 'ip':
 151                  $l_ban_cell = $user->lang['IP_HOSTNAME'];
 152              break;
 153  
 154              case 'email':
 155                  $l_ban_cell = $user->lang['EMAIL_ADDRESS'];
 156              break;
 157          }
 158  
 159          self::display_ban_options($mode);
 160  
 161          $template->assign_vars(array(
 162              'L_TITLE'                => $this->page_title,
 163              'L_EXPLAIN'                => $l_ban_explain,
 164              'L_UNBAN_TITLE'            => $l_unban_title,
 165              'L_UNBAN_EXPLAIN'        => $l_unban_explain,
 166              'L_BAN_CELL'            => $l_ban_cell,
 167              'L_BAN_EXCLUDE_EXPLAIN'    => $l_ban_exclude_explain,
 168              'L_NO_BAN_CELL'            => $l_no_ban_cell,
 169  
 170              'S_USERNAME_BAN'    => ($mode == 'user') ? true : false,
 171  
 172              'U_ACTION'            => $this->u_action,
 173              'U_FIND_USERNAME'    => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=acp_ban&amp;field=ban'),
 174          ));
 175      }
 176  
 177      /**
 178      * Display ban options
 179      */
 180  	static public function display_ban_options($mode)
 181      {
 182          global $user, $db, $template;
 183  
 184          // Ban length options
 185          $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'] . ' -&gt; ');
 186  
 187          $ban_end_options = '';
 188          foreach ($ban_end_text as $length => $text)
 189          {
 190              $ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
 191          }
 192  
 193          switch ($mode)
 194          {
 195              case 'user':
 196  
 197                  $field = 'username';
 198  
 199                  $sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
 200                      FROM ' . BANLIST_TABLE . ' b, ' . USERS_TABLE . ' u
 201                      WHERE (b.ban_end >= ' . time() . '
 202                              OR b.ban_end = 0)
 203                          AND u.user_id = b.ban_userid
 204                      ORDER BY u.username_clean ASC';
 205              break;
 206  
 207              case 'ip':
 208  
 209                  $field = 'ban_ip';
 210  
 211                  $sql = 'SELECT *
 212                      FROM ' . BANLIST_TABLE . '
 213                      WHERE (ban_end >= ' . time() . "
 214                              OR ban_end = 0)
 215                          AND ban_ip <> ''
 216                      ORDER BY ban_ip";
 217              break;
 218  
 219              case 'email':
 220  
 221                  $field = 'ban_email';
 222  
 223                  $sql = 'SELECT *
 224                      FROM ' . BANLIST_TABLE . '
 225                      WHERE (ban_end >= ' . time() . "
 226                              OR ban_end = 0)
 227                          AND ban_email <> ''
 228                      ORDER BY ban_email";
 229              break;
 230          }
 231          $result = $db->sql_query($sql);
 232  
 233          $banned_options = $excluded_options = array();
 234          while ($row = $db->sql_fetchrow($result))
 235          {
 236              $option = '<option value="' . $row['ban_id'] . '">' . $row[$field] . '</option>';
 237  
 238              if ($row['ban_exclude'])
 239              {
 240                  $excluded_options[] = $option;
 241              }
 242              else
 243              {
 244                  $banned_options[] = $option;
 245              }
 246  
 247              $time_length = ($row['ban_end']) ? ($row['ban_end'] - $row['ban_start']) / 60 : 0;
 248  
 249              if ($time_length == 0)
 250              {
 251                  // Banned permanently
 252                  $ban_length = $user->lang['PERMANENT'];
 253              }
 254              else if (isset($ban_end_text[$time_length]))
 255              {
 256                  // Banned for a given duration
 257                  $ban_length = $user->lang('BANNED_UNTIL_DURATION', $ban_end_text[$time_length], $user->format_date($row['ban_end'], false, true));
 258              }
 259              else
 260              {
 261                  // Banned until given date
 262                  $ban_length = $user->lang('BANNED_UNTIL_DATE', $user->format_date($row['ban_end'], false, true));
 263              }
 264  
 265              $template->assign_block_vars('bans', array(
 266                  'BAN_ID'        => (int) $row['ban_id'],
 267                  'LENGTH'        => $ban_length,
 268                  'A_LENGTH'        => addslashes($ban_length),
 269                  'REASON'        => $row['ban_reason'],
 270                  'A_REASON'        => addslashes($row['ban_reason']),
 271                  'GIVE_REASON'    => $row['ban_give_reason'],
 272                  'A_GIVE_REASON'    => addslashes($row['ban_give_reason']),
 273              ));
 274          }
 275          $db->sql_freeresult($result);
 276  
 277          $options = '';
 278          if ($excluded_options)
 279          {
 280              $options .= '<optgroup label="' . $user->lang['OPTIONS_EXCLUDED'] . '">';
 281              $options .= implode('', $excluded_options);
 282              $options .= '</optgroup>';
 283          }
 284  
 285          if ($banned_options)
 286          {
 287              $options .= '<optgroup label="' . $user->lang['OPTIONS_BANNED'] . '">';
 288              $options .= implode('', $banned_options);
 289              $options .= '</optgroup>';
 290          }
 291  
 292          $template->assign_vars(array(
 293              'S_BAN_END_OPTIONS'    => $ban_end_options,
 294              'S_BANNED_OPTIONS'    => ($banned_options || $excluded_options) ? true : false,
 295              'BANNED_OPTIONS'    => $options,
 296          ));
 297      }
 298  }


Generated: Sat Oct 26 11:28:42 2019 Cross-referenced by PHPXref 0.7.1