[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/includes/mcp/ -> mcp_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 mcp_ban
  23  {
  24      var $u_action;
  25  
  26  	function main($id, $mode)
  27      {
  28          global $db, $user, $auth, $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          // Include the admin banning interface...
  37          if (!class_exists('acp_ban'))
  38          {
  39              include($phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx);
  40          }
  41  
  42          $bansubmit        = $request->is_set_post('bansubmit');
  43          $unbansubmit    = $request->is_set_post('unbansubmit');
  44  
  45          $user->add_lang(array('acp/ban', 'acp/users'));
  46          $this->tpl_name = 'mcp_ban';
  47  
  48          /**
  49          * Use this event to pass perform actions when a ban is issued or revoked
  50          *
  51          * @event core.mcp_ban_main
  52          * @var    bool    bansubmit    True if a ban is issued
  53          * @var    bool    unbansubmit    True if a ban is removed
  54          * @var    string    mode        Mode of the ban that is being worked on
  55          * @since 3.1.0-RC5
  56          */
  57          $vars = array(
  58              'bansubmit',
  59              'unbansubmit',
  60              'mode',
  61          );
  62          extract($phpbb_dispatcher->trigger_event('core.mcp_ban_main', compact($vars)));
  63  
  64          // Ban submitted?
  65          if ($bansubmit)
  66          {
  67              // Grab the list of entries
  68              $ban                = $request->variable('ban', '', $mode === 'user');
  69              $ban_length            = $request->variable('banlength', 0);
  70              $ban_length_other    = $request->variable('banlengthother', '');
  71              $ban_exclude        = $request->variable('banexclude', 0);
  72              $ban_reason            = $request->variable('banreason', '', true);
  73              $ban_give_reason    = $request->variable('bangivereason', '', true);
  74  
  75              if ($ban)
  76              {
  77                  if (confirm_box(true))
  78                  {
  79                      $abort_ban = false;
  80                      /**
  81                      * Use this event to modify the ban details before the ban is performed
  82                      *
  83                      * @event core.mcp_ban_before
  84                      * @var    string    mode                One of the following: user, ip, email
  85                      * @var    string    ban                    Either string or array with usernames, ips or email addresses
  86                      * @var    int        ban_length            Ban length in minutes
  87                      * @var    string    ban_length_other    Ban length as a date (YYYY-MM-DD)
  88                      * @var    bool    ban_exclude            Are we banning or excluding from another ban
  89                      * @var    string    ban_reason            Ban reason displayed to moderators
  90                      * @var    string    ban_give_reason        Ban reason displayed to the banned user
  91                      * @var    mixed    abort_ban            Either false, or an error message that is displayed to the user.
  92                      *                                    If a string is given the bans are not issued.
  93                      * @since 3.1.0-RC5
  94                      */
  95                      $vars = array(
  96                          'mode',
  97                          'ban',
  98                          'ban_length',
  99                          'ban_length_other',
 100                          'ban_exclude',
 101                          'ban_reason',
 102                          'ban_give_reason',
 103                          'abort_ban',
 104                      );
 105                      extract($phpbb_dispatcher->trigger_event('core.mcp_ban_before', compact($vars)));
 106  
 107                      if ($abort_ban)
 108                      {
 109                          trigger_error($abort_ban);
 110                      }
 111                      user_ban($mode, $ban, $ban_length, $ban_length_other, $ban_exclude, $ban_reason, $ban_give_reason);
 112  
 113                      /**
 114                      * Use this event to perform actions after the ban has been performed
 115                      *
 116                      * @event core.mcp_ban_after
 117                      * @var    string    mode                One of the following: user, ip, email
 118                      * @var    string    ban                    Either string or array with usernames, ips or email addresses
 119                      * @var    int        ban_length            Ban length in minutes
 120                      * @var    string    ban_length_other    Ban length as a date (YYYY-MM-DD)
 121                      * @var    bool    ban_exclude            Are we banning or excluding from another ban
 122                      * @var    string    ban_reason            Ban reason displayed to moderators
 123                      * @var    string    ban_give_reason        Ban reason displayed to the banned user
 124                      * @since 3.1.0-RC5
 125                      */
 126                      $vars = array(
 127                          'mode',
 128                          'ban',
 129                          'ban_length',
 130                          'ban_length_other',
 131                          'ban_exclude',
 132                          'ban_reason',
 133                          'ban_give_reason',
 134                      );
 135                      extract($phpbb_dispatcher->trigger_event('core.mcp_ban_after', compact($vars)));
 136  
 137                      trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>');
 138                  }
 139                  else
 140                  {
 141                      $hidden_fields = array(
 142                          'mode'                => $mode,
 143                          'ban'                => $ban,
 144                          'bansubmit'            => true,
 145                          'banlength'            => $ban_length,
 146                          'banlengthother'    => $ban_length_other,
 147                          'banexclude'        => $ban_exclude,
 148                          'banreason'            => $ban_reason,
 149                          'bangivereason'        => $ban_give_reason,
 150                      );
 151  
 152                      /**
 153                      * Use this event to pass data from the ban form to the confirmation screen
 154                      *
 155                      * @event core.mcp_ban_confirm
 156                      * @var    array    hidden_fields    Hidden fields that are passed through the confirm screen
 157                      * @since 3.1.0-RC5
 158                      */
 159                      $vars = array('hidden_fields');
 160                      extract($phpbb_dispatcher->trigger_event('core.mcp_ban_confirm', compact($vars)));
 161  
 162                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($hidden_fields));
 163                  }
 164              }
 165          }
 166          else if ($unbansubmit)
 167          {
 168              $ban = $request->variable('unban', array(''));
 169  
 170              if ($ban)
 171              {
 172                  if (confirm_box(true))
 173                  {
 174                      user_unban($mode, $ban);
 175  
 176                      trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>');
 177                  }
 178                  else
 179                  {
 180                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 181                          'mode'            => $mode,
 182                          'unbansubmit'    => true,
 183                          'unban'            => $ban)));
 184                  }
 185              }
 186          }
 187  
 188          // Ban length options
 189          $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; ');
 190  
 191          $ban_end_options = '';
 192          foreach ($ban_end_text as $length => $text)
 193          {
 194              $ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
 195          }
 196  
 197          // Define language vars
 198          $this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
 199  
 200          $l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
 201          $l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
 202          $l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
 203          $l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
 204          $l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
 205  
 206          switch ($mode)
 207          {
 208              case 'user':
 209                  $l_ban_cell = $user->lang['USERNAME'];
 210              break;
 211  
 212              case 'ip':
 213                  $l_ban_cell = $user->lang['IP_HOSTNAME'];
 214              break;
 215  
 216              case 'email':
 217                  $l_ban_cell = $user->lang['EMAIL_ADDRESS'];
 218              break;
 219          }
 220  
 221          acp_ban::display_ban_options($mode);
 222  
 223          $template->assign_vars(array(
 224              'L_TITLE'                => $this->page_title,
 225              'L_EXPLAIN'                => $l_ban_explain,
 226              'L_UNBAN_TITLE'            => $l_unban_title,
 227              'L_UNBAN_EXPLAIN'        => $l_unban_explain,
 228              'L_BAN_CELL'            => $l_ban_cell,
 229              'L_BAN_EXCLUDE_EXPLAIN'    => $l_ban_exclude_explain,
 230              'L_NO_BAN_CELL'            => $l_no_ban_cell,
 231  
 232              'S_USERNAME_BAN'    => ($mode == 'user') ? true : false,
 233  
 234              'U_ACTION'            => $this->u_action,
 235              'U_FIND_USERNAME'    => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=mcp_ban&amp;field=ban'),
 236          ));
 237  
 238          if ($mode === 'email' && !$auth->acl_get('a_user'))
 239          {
 240              return;
 241          }
 242  
 243          // As a "service" we will check if any post id is specified and populate the username of the poster id if given
 244          $post_id = $request->variable('p', 0);
 245          $user_id = $request->variable('u', 0);
 246          $pre_fill = false;
 247  
 248          if ($user_id && $user_id <> ANONYMOUS)
 249          {
 250              $sql = 'SELECT username, user_email, user_ip
 251                  FROM ' . USERS_TABLE . '
 252                  WHERE user_id = ' . $user_id;
 253              $result = $db->sql_query($sql);
 254              switch ($mode)
 255              {
 256                  case 'user':
 257                      $pre_fill = (string) $db->sql_fetchfield('username');
 258                  break;
 259  
 260                  case 'ip':
 261                      $pre_fill = (string) $db->sql_fetchfield('user_ip');
 262                  break;
 263  
 264                  case 'email':
 265                      $pre_fill = (string) $db->sql_fetchfield('user_email');
 266                  break;
 267              }
 268              $db->sql_freeresult($result);
 269          }
 270          else if ($post_id)
 271          {
 272              $post_info = phpbb_get_post_data(array($post_id), 'm_ban');
 273  
 274              if (count($post_info) && !empty($post_info[$post_id]))
 275              {
 276                  switch ($mode)
 277                  {
 278                      case 'user':
 279                          $pre_fill = $post_info[$post_id]['username'];
 280                      break;
 281  
 282                      case 'ip':
 283                          $pre_fill = $post_info[$post_id]['poster_ip'];
 284                      break;
 285  
 286                      case 'email':
 287                          $pre_fill = $post_info[$post_id]['user_email'];
 288                      break;
 289                  }
 290  
 291              }
 292          }
 293  
 294          if ($pre_fill)
 295          {
 296              // left for legacy template compatibility
 297              $template->assign_var('USERNAMES', $pre_fill);
 298              $template->assign_var('BAN_QUANTIFIER', $pre_fill);
 299          }
 300      }
 301  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1