[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/includes/acp/ -> acp_attachments.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_attachments
  23  {
  24      /** @var \phpbb\db\driver\driver_interface */
  25      protected $db;
  26  
  27      /** @var \phpbb\config\config */
  28      protected $config;
  29  
  30      /** @var \phpbb\language\language */
  31      protected $language;
  32  
  33      /** @var ContainerBuilder */
  34      protected $phpbb_container;
  35  
  36      /** @var \phpbb\template\template */
  37      protected $template;
  38  
  39      /** @var \phpbb\user */
  40      protected $user;
  41  
  42      /** @var  \phpbb\filesystem\filesystem_interface */
  43      protected $filesystem;
  44  
  45      /** @var \phpbb\attachment\manager */
  46      protected $attachment_manager;
  47  
  48      public $id;
  49      public $u_action;
  50      protected $new_config;
  51  
  52  	function main($id, $mode)
  53      {
  54          global $db, $user, $auth, $template, $cache, $phpbb_container, $phpbb_filesystem, $phpbb_dispatcher;
  55          global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx, $phpbb_log, $request;
  56  
  57          $this->id = $id;
  58          $this->db = $db;
  59          $this->config = $config;
  60          $this->language = $phpbb_container->get('language');
  61          $this->template = $template;
  62          $this->user = $user;
  63          $this->phpbb_container = $phpbb_container;
  64          $this->filesystem = $phpbb_filesystem;
  65          $this->attachment_manager = $phpbb_container->get('attachment.manager');
  66  
  67          $user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
  68  
  69          $error = $notify = array();
  70          $submit = (isset($_POST['submit'])) ? true : false;
  71          $action = $request->variable('action', '');
  72  
  73          $form_key = 'acp_attach';
  74          add_form_key($form_key);
  75  
  76          if ($submit && !check_form_key($form_key))
  77          {
  78              trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  79          }
  80  
  81          switch ($mode)
  82          {
  83              case 'attach':
  84                  $l_title = 'ACP_ATTACHMENT_SETTINGS';
  85              break;
  86  
  87              case 'extensions':
  88                  $l_title = 'ACP_MANAGE_EXTENSIONS';
  89              break;
  90  
  91              case 'ext_groups':
  92                  $l_title = 'ACP_EXTENSION_GROUPS';
  93              break;
  94  
  95              case 'orphan':
  96                  $l_title = 'ACP_ORPHAN_ATTACHMENTS';
  97              break;
  98  
  99              case 'manage':
 100                  $l_title = 'ACP_MANAGE_ATTACHMENTS';
 101              break;
 102  
 103              default:
 104                  trigger_error('NO_MODE', E_USER_ERROR);
 105              break;
 106          }
 107  
 108          $this->tpl_name = 'acp_attachments';
 109          $this->page_title = $l_title;
 110  
 111          $template->assign_vars(array(
 112              'L_TITLE'            => $user->lang[$l_title],
 113              'L_TITLE_EXPLAIN'    => $user->lang[$l_title . '_EXPLAIN'],
 114              'U_ACTION'            => $this->u_action)
 115          );
 116  
 117          switch ($mode)
 118          {
 119              case 'attach':
 120  
 121                  if (!function_exists('get_supported_image_types'))
 122                  {
 123                      include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 124                  }
 125  
 126                  $sql = 'SELECT group_name, cat_id
 127                      FROM ' . EXTENSION_GROUPS_TABLE . '
 128                      WHERE cat_id > 0
 129                      ORDER BY cat_id';
 130                  $result = $db->sql_query($sql);
 131  
 132                  $s_assigned_groups = array();
 133                  while ($row = $db->sql_fetchrow($result))
 134                  {
 135                      $row['group_name'] = $this->language->is_set('EXT_GROUP_' . utf8_strtoupper($row['group_name'])) ? $this->language->lang('EXT_GROUP_' . utf8_strtoupper($row['group_name'])) : $row['group_name'];
 136                      $s_assigned_groups[$row['cat_id']][] = $row['group_name'];
 137                  }
 138                  $db->sql_freeresult($result);
 139  
 140                  $l_legend_cat_images = $user->lang['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang['ASSIGNED_GROUP'] . ': ' . ((!empty($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE])) ? implode($user->lang['COMMA_SEPARATOR'], $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) : $user->lang['NO_EXT_GROUP']) . ']';
 141  
 142                  $display_vars = array(
 143                      'title'    => 'ACP_ATTACHMENT_SETTINGS',
 144                      'vars'    => array(
 145                          'legend1'                => 'ACP_ATTACHMENT_SETTINGS',
 146  
 147                          'img_max_width'            => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
 148                          'img_max_height'        => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
 149                          'img_link_width'        => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
 150                          'img_link_height'        => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
 151  
 152                          'allow_attachments'        => array('lang' => 'ALLOW_ATTACHMENTS',        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => false),
 153                          'allow_pm_attach'        => array('lang' => 'ALLOW_PM_ATTACHMENTS',    'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => false),
 154                          'upload_path'            => array('lang' => 'UPLOAD_DIR',            'validate' => 'wpath',    'type' => 'text:25:100', 'explain' => true),
 155                          'display_order'            => array('lang' => 'DISPLAY_ORDER',            'validate' => 'bool',    'type' => 'custom', 'method' => 'display_order', 'explain' => true),
 156                          'attachment_quota'        => array('lang' => 'ATTACH_QUOTA',            'validate' => 'string',    'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
 157                          'max_filesize'            => array('lang' => 'ATTACH_MAX_FILESIZE',    'validate' => 'string',    'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
 158                          'max_filesize_pm'        => array('lang' => 'ATTACH_MAX_PM_FILESIZE','validate' => 'string',    'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
 159                          'max_attachments'        => array('lang' => 'MAX_ATTACHMENTS',        'validate' => 'int:0:999',    'type' => 'number:0:999', 'explain' => false),
 160                          'max_attachments_pm'    => array('lang' => 'MAX_ATTACHMENTS_PM',    'validate' => 'int:0:999',    'type' => 'number:0:999', 'explain' => false),
 161                          'secure_downloads'        => array('lang' => 'SECURE_DOWNLOADS',        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
 162                          'secure_allow_deny'        => array('lang' => 'SECURE_ALLOW_DENY',        'validate' => 'int',    'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),
 163                          'secure_allow_empty_referer'    => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
 164                          'check_attachment_content'         => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
 165  
 166                          'legend2'                    => $l_legend_cat_images,
 167                          'img_display_inlined'        => array('lang' => 'DISPLAY_INLINED',        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
 168                          'img_create_thumbnail'        => array('lang' => 'CREATE_THUMBNAIL',        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
 169                          'img_max_thumb_width'        => array('lang' => 'MAX_THUMB_WIDTH',        'validate' => 'int:0:999999999999999',    'type' => 'number:0:999999999999999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
 170                          'img_min_thumb_filesize'    => array('lang' => 'MIN_THUMB_FILESIZE',    'validate' => 'int:0:999999999999999',    'type' => 'number:0:999999999999999', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
 171                          'img_max'                    => array('lang' => 'MAX_IMAGE_SIZE',        'validate' => 'int:0:9999',    'type' => 'dimension:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
 172                          'img_link'                    => array('lang' => 'IMAGE_LINK_SIZE',        'validate' => 'int:0:9999',    'type' => 'dimension:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
 173                      )
 174                  );
 175  
 176                  /**
 177                  * Event to add and/or modify acp_attachement configurations
 178                  *
 179                  * @event core.acp_attachments_config_edit_add
 180                  * @var    array    display_vars    Array of config values to display and process
 181                  * @var    string    mode            Mode of the config page we are displaying
 182                  * @var    boolean    submit            Do we display the form or process the submission
 183                  * @since 3.1.11-RC1
 184                  */
 185                  $vars = array('display_vars', 'mode', 'submit');
 186                  extract($phpbb_dispatcher->trigger_event('core.acp_attachments_config_edit_add', compact($vars)));
 187  
 188                  $this->new_config = $config;
 189                  $cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', array('' => '')) : $this->new_config;
 190                  $error = array();
 191  
 192                  // We validate the complete config if whished
 193                  validate_config_vars($display_vars['vars'], $cfg_array, $error);
 194  
 195                  // Do not write values if there is an error
 196                  if (count($error))
 197                  {
 198                      $submit = false;
 199                  }
 200  
 201                  // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
 202                  foreach ($display_vars['vars'] as $config_name => $null)
 203                  {
 204                      if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
 205                      {
 206                          continue;
 207                      }
 208  
 209                      $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
 210  
 211                      if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm')))
 212                      {
 213                          $size_var = $request->variable($config_name, '');
 214                          $this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
 215                      }
 216  
 217                      if ($submit)
 218                      {
 219                          $config->set($config_name, $config_value);
 220                      }
 221                  }
 222  
 223                  $this->perform_site_list();
 224  
 225                  if ($submit)
 226                  {
 227                      $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_ATTACH');
 228  
 229                      // Check Settings
 230                      $this->test_upload($error, $this->new_config['upload_path'], false);
 231  
 232                      if (!count($error))
 233                      {
 234                          trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
 235                      }
 236                  }
 237  
 238                  $template->assign_var('S_ATTACHMENT_SETTINGS', true);
 239  
 240                  // Secure Download Options - Same procedure as with banning
 241                  $allow_deny = ($this->new_config['secure_allow_deny']) ? 'ALLOWED' : 'DISALLOWED';
 242  
 243                  $sql = 'SELECT *
 244                      FROM ' . SITELIST_TABLE;
 245                  $result = $db->sql_query($sql);
 246  
 247                  $defined_ips = '';
 248                  $ips = array();
 249  
 250                  while ($row = $db->sql_fetchrow($result))
 251                  {
 252                      $value = ($row['site_ip']) ? $row['site_ip'] : $row['site_hostname'];
 253                      if ($value)
 254                      {
 255                          $defined_ips .= '<option' . (($row['ip_exclude']) ? ' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>';
 256                          $ips[$row['site_id']] = $value;
 257                      }
 258                  }
 259                  $db->sql_freeresult($result);
 260  
 261                  $template->assign_vars(array(
 262                      'S_SECURE_DOWNLOADS'    => $this->new_config['secure_downloads'],
 263                      'S_DEFINED_IPS'            => ($defined_ips != '') ? true : false,
 264                      'S_WARNING'                => (count($error)) ? true : false,
 265  
 266                      'WARNING_MSG'            => implode('<br />', $error),
 267                      'DEFINED_IPS'            => $defined_ips,
 268  
 269                      'L_SECURE_TITLE'        => $user->lang['DEFINE_' . $allow_deny . '_IPS'],
 270                      'L_IP_EXCLUDE'            => $user->lang['EXCLUDE_FROM_' . $allow_deny . '_IP'],
 271                      'L_REMOVE_IPS'            => $user->lang['REMOVE_' . $allow_deny . '_IPS'])
 272                  );
 273  
 274                  // Output relevant options
 275                  foreach ($display_vars['vars'] as $config_key => $vars)
 276                  {
 277                      if (!is_array($vars) && strpos($config_key, 'legend') === false)
 278                      {
 279                          continue;
 280                      }
 281  
 282                      if (strpos($config_key, 'legend') !== false)
 283                      {
 284                          $template->assign_block_vars('options', array(
 285                              'S_LEGEND'        => true,
 286                              'LEGEND'        => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
 287                          );
 288  
 289                          continue;
 290                      }
 291  
 292                      $type = explode(':', $vars['type']);
 293  
 294                      $l_explain = '';
 295                      if ($vars['explain'] && isset($vars['lang_explain']))
 296                      {
 297                          $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
 298                      }
 299                      else if ($vars['explain'])
 300                      {
 301                          $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
 302                      }
 303  
 304                      $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
 305                      if (empty($content))
 306                      {
 307                          continue;
 308                      }
 309  
 310                      $template->assign_block_vars('options', array(
 311                          'KEY'            => $config_key,
 312                          'TITLE'            => $user->lang[$vars['lang']],
 313                          'S_EXPLAIN'        => $vars['explain'],
 314                          'TITLE_EXPLAIN'    => $l_explain,
 315                          'CONTENT'        => $content,
 316                          )
 317                      );
 318  
 319                      unset($display_vars['vars'][$config_key]);
 320                  }
 321  
 322              break;
 323  
 324              case 'extensions':
 325  
 326                  if ($submit || isset($_POST['add_extension_check']))
 327                  {
 328                      if ($submit)
 329                      {
 330                          // Change Extensions ?
 331                          $extension_change_list    = $request->variable('extension_change_list', array(0));
 332                          $group_select_list        = $request->variable('group_select', array(0));
 333  
 334                          // Generate correct Change List
 335                          $extensions = array();
 336  
 337                          for ($i = 0, $size = count($extension_change_list); $i < $size; $i++)
 338                          {
 339                              $extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i];
 340                          }
 341  
 342                          $sql = 'SELECT *
 343                              FROM ' . EXTENSIONS_TABLE . '
 344                              ORDER BY extension_id';
 345                          $result = $db->sql_query($sql);
 346  
 347                          while ($row = $db->sql_fetchrow($result))
 348                          {
 349                              if ($row['group_id'] != $extensions[$row['extension_id']]['group_id'])
 350                              {
 351                                  $sql = 'UPDATE ' . EXTENSIONS_TABLE . '
 352                                      SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . '
 353                                      WHERE extension_id = ' . $row['extension_id'];
 354                                  $db->sql_query($sql);
 355  
 356                                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXT_UPDATE', false, array($row['extension']));
 357                              }
 358                          }
 359                          $db->sql_freeresult($result);
 360  
 361                          // Delete Extension?
 362                          $extension_id_list = $request->variable('extension_id_list', array(0));
 363  
 364                          if (count($extension_id_list))
 365                          {
 366                              $sql = 'SELECT extension
 367                                  FROM ' . EXTENSIONS_TABLE . '
 368                                  WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
 369                              $result = $db->sql_query($sql);
 370  
 371                              $extension_list = '';
 372                              while ($row = $db->sql_fetchrow($result))
 373                              {
 374                                  $extension_list .= ($extension_list == '') ? $row['extension'] : ', ' . $row['extension'];
 375                              }
 376                              $db->sql_freeresult($result);
 377  
 378                              $sql = 'DELETE
 379                                  FROM ' . EXTENSIONS_TABLE . '
 380                                  WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
 381                              $db->sql_query($sql);
 382  
 383                              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXT_DEL', false, array($extension_list));
 384                          }
 385                      }
 386  
 387                      // Add Extension?
 388                      $add_extension            = strtolower($request->variable('add_extension', ''));
 389                      $add_extension_group    = $request->variable('add_group_select', 0);
 390                      $add                    = (isset($_POST['add_extension_check'])) ? true : false;
 391  
 392                      if ($add_extension && $add)
 393                      {
 394                          if (!count($error))
 395                          {
 396                              $sql = 'SELECT extension_id
 397                                  FROM ' . EXTENSIONS_TABLE . "
 398                                  WHERE extension = '" . $db->sql_escape($add_extension) . "'";
 399                              $result = $db->sql_query($sql);
 400  
 401                              if ($row = $db->sql_fetchrow($result))
 402                              {
 403                                  $error[] = sprintf($user->lang['EXTENSION_EXIST'], $add_extension);
 404                              }
 405                              $db->sql_freeresult($result);
 406  
 407                              if (!count($error))
 408                              {
 409                                  $sql_ary = array(
 410                                      'group_id'    =>    $add_extension_group,
 411                                      'extension'    =>    $add_extension
 412                                  );
 413  
 414                                  $db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
 415  
 416                                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXT_ADD', false, array($add_extension));
 417                              }
 418                          }
 419                      }
 420  
 421                      if (!count($error))
 422                      {
 423                          $notify[] = $user->lang['EXTENSIONS_UPDATED'];
 424                      }
 425  
 426                      $cache->destroy('_extensions');
 427                  }
 428  
 429                  $template->assign_vars(array(
 430                      'S_EXTENSIONS'            => true,
 431                      'ADD_EXTENSION'            => (isset($add_extension)) ? $add_extension : '',
 432                      'GROUP_SELECT_OPTIONS'    => (isset($_POST['add_extension_check'])) ? $this->group_select('add_group_select', $add_extension_group, 'extension_group') : $this->group_select('add_group_select', false, 'extension_group'))
 433                  );
 434  
 435                  $sql = 'SELECT *
 436                      FROM ' . EXTENSIONS_TABLE . '
 437                      ORDER BY group_id, extension';
 438                  $result = $db->sql_query($sql);
 439  
 440                  if ($row = $db->sql_fetchrow($result))
 441                  {
 442                      $old_group_id = $row['group_id'];
 443                      do
 444                      {
 445                          $s_spacer = false;
 446  
 447                          $current_group_id = $row['group_id'];
 448                          if ($old_group_id != $current_group_id)
 449                          {
 450                              $s_spacer = true;
 451                              $old_group_id = $current_group_id;
 452                          }
 453  
 454                          $template->assign_block_vars('extensions', array(
 455                              'S_SPACER'        => $s_spacer,
 456                              'EXTENSION_ID'    => $row['extension_id'],
 457                              'EXTENSION'        => $row['extension'],
 458                              'GROUP_OPTIONS'    => $this->group_select('group_select[]', $row['group_id']))
 459                          );
 460                      }
 461                      while ($row = $db->sql_fetchrow($result));
 462                  }
 463                  $db->sql_freeresult($result);
 464  
 465              break;
 466  
 467              case 'ext_groups':
 468  
 469                  $template->assign_var('S_EXTENSION_GROUPS', true);
 470  
 471                  if ($submit)
 472                  {
 473                      $action = $request->variable('action', '');
 474                      $group_id = $request->variable('g', 0);
 475  
 476                      if ($action != 'add' && $action != 'edit')
 477                      {
 478                          trigger_error('NO_MODE', E_USER_ERROR);
 479                      }
 480  
 481                      if (!$group_id && $action == 'edit')
 482                      {
 483                          trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
 484                      }
 485  
 486                      if ($group_id)
 487                      {
 488                          $sql = 'SELECT *
 489                              FROM ' . EXTENSION_GROUPS_TABLE . "
 490                              WHERE group_id = $group_id";
 491                          $result = $db->sql_query($sql);
 492                          $ext_row = $db->sql_fetchrow($result);
 493                          $db->sql_freeresult($result);
 494  
 495                          if (!$ext_row)
 496                          {
 497                              trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
 498                          }
 499                      }
 500                      else
 501                      {
 502                          $ext_row = array();
 503                      }
 504  
 505                      $group_name = $request->variable('group_name', '', true);
 506                      $new_group_name = ($action == 'add') ? $group_name : (($ext_row['group_name'] != $group_name) ? $group_name : '');
 507  
 508                      if (!$group_name)
 509                      {
 510                          $error[] = $user->lang['NO_EXT_GROUP_NAME'];
 511                      }
 512  
 513                      // Check New Group Name
 514                      if ($new_group_name)
 515                      {
 516                          $sql = 'SELECT group_id
 517                              FROM ' . EXTENSION_GROUPS_TABLE . "
 518                              WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";
 519                          if ($group_id)
 520                          {
 521                              $sql .= ' AND group_id <> ' . $group_id;
 522                          }
 523                          $result = $db->sql_query($sql);
 524  
 525                          if ($db->sql_fetchrow($result))
 526                          {
 527                              $error[] = sprintf($user->lang['EXTENSION_GROUP_EXIST'], $new_group_name);
 528                          }
 529                          $db->sql_freeresult($result);
 530                      }
 531  
 532                      if (!count($error))
 533                      {
 534                          // Ok, build the update/insert array
 535                          $upload_icon    = $request->variable('upload_icon', 'no_image');
 536                          $size_select    = $request->variable('size_select', 'b');
 537                          $forum_select    = $request->variable('forum_select', false);
 538                          $allowed_forums    = $request->variable('allowed_forums', array(0));
 539                          $allow_in_pm    = (isset($_POST['allow_in_pm'])) ? true : false;
 540                          $max_filesize    = $request->variable('max_filesize', 0);
 541                          $max_filesize    = ($size_select == 'kb') ? round($max_filesize * 1024) : (($size_select == 'mb') ? round($max_filesize * 1048576) : $max_filesize);
 542                          $allow_group    = (isset($_POST['allow_group'])) ? true : false;
 543  
 544                          if ($max_filesize == $config['max_filesize'])
 545                          {
 546                              $max_filesize = 0;
 547                          }
 548  
 549                          if (!count($allowed_forums))
 550                          {
 551                              $forum_select = false;
 552                          }
 553  
 554                          $group_ary = array(
 555                              'group_name'    => $group_name,
 556                              'cat_id'        => $request->variable('special_category', ATTACHMENT_CATEGORY_NONE),
 557                              'allow_group'    => ($allow_group) ? 1 : 0,
 558                              'upload_icon'    => ($upload_icon == 'no_image') ? '' : $upload_icon,
 559                              'max_filesize'    => $max_filesize,
 560                              'allowed_forums'=> ($forum_select) ? serialize($allowed_forums) : '',
 561                              'allow_in_pm'    => ($allow_in_pm) ? 1 : 0,
 562                          );
 563  
 564                          if ($action == 'add')
 565                          {
 566                              $group_ary['download_mode'] = INLINE_LINK;
 567                          }
 568  
 569                          $sql = ($action == 'add') ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ';
 570                          $sql .= $db->sql_build_array((($action == 'add') ? 'INSERT' : 'UPDATE'), $group_ary);
 571                          $sql .= ($action == 'edit') ? " WHERE group_id = $group_id" : '';
 572  
 573                          $db->sql_query($sql);
 574  
 575                          if ($action == 'add')
 576                          {
 577                              $group_id = $db->sql_nextid();
 578                          }
 579  
 580                          $group_name = $this->language->is_set('EXT_GROUP_' . utf8_strtoupper($group_name)) ? $this->language->lang('EXT_GROUP_' . utf8_strtoupper($group_name)) : $group_name;
 581                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), false, array($group_name));
 582                      }
 583  
 584                      $extension_list = $request->variable('extensions', array(0));
 585  
 586                      if ($action == 'edit' && count($extension_list))
 587                      {
 588                          $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
 589                              SET group_id = 0
 590                              WHERE group_id = $group_id";
 591                          $db->sql_query($sql);
 592                      }
 593  
 594                      if (count($extension_list))
 595                      {
 596                          $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
 597                              SET group_id = $group_id
 598                              WHERE " . $db->sql_in_set('extension_id', $extension_list);
 599                          $db->sql_query($sql);
 600                      }
 601  
 602                      $cache->destroy('_extensions');
 603  
 604                      if (!count($error))
 605                      {
 606                          $notify[] = $user->lang['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)];
 607                      }
 608                  }
 609  
 610                  $cat_lang = array(
 611                      ATTACHMENT_CATEGORY_NONE        => $user->lang['NO_FILE_CAT'],
 612                      ATTACHMENT_CATEGORY_IMAGE        => $user->lang['CAT_IMAGES'],
 613                      ATTACHMENT_CATEGORY_FLASH        => $user->lang['CAT_FLASH_FILES'],
 614                  );
 615  
 616                  $group_id = $request->variable('g', 0);
 617                  $action = (isset($_POST['add'])) ? 'add' : $action;
 618  
 619                  switch ($action)
 620                  {
 621                      case 'delete':
 622  
 623                          if (confirm_box(true))
 624                          {
 625                              $sql = 'SELECT group_name
 626                                  FROM ' . EXTENSION_GROUPS_TABLE . "
 627                                  WHERE group_id = $group_id";
 628                              $result = $db->sql_query($sql);
 629                              $group_name = (string) $db->sql_fetchfield('group_name');
 630                              $db->sql_freeresult($result);
 631  
 632                              $sql = 'DELETE
 633                                  FROM ' . EXTENSION_GROUPS_TABLE . "
 634                                  WHERE group_id = $group_id";
 635                              $db->sql_query($sql);
 636  
 637                              // Set corresponding Extensions to a pending Group
 638                              $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
 639                                  SET group_id = 0
 640                                  WHERE group_id = $group_id";
 641                              $db->sql_query($sql);
 642  
 643                              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXTGROUP_DEL', false, array($group_name));
 644  
 645                              $cache->destroy('_extensions');
 646  
 647                              trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action));
 648                          }
 649                          else
 650                          {
 651                              confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 652                                  'i'            => $id,
 653                                  'mode'        => $mode,
 654                                  'group_id'    => $group_id,
 655                                  'action'    => 'delete',
 656                              )));
 657                          }
 658  
 659                      break;
 660  
 661                      case 'edit':
 662  
 663                          if (!$group_id)
 664                          {
 665                              trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
 666                          }
 667  
 668                          $sql = 'SELECT *
 669                              FROM ' . EXTENSION_GROUPS_TABLE . "
 670                              WHERE group_id = $group_id";
 671                          $result = $db->sql_query($sql);
 672                          $ext_group_row = $db->sql_fetchrow($result);
 673                          $db->sql_freeresult($result);
 674  
 675                          $forum_ids = (!$ext_group_row['allowed_forums']) ? array() : unserialize(trim($ext_group_row['allowed_forums']));
 676  
 677                      // no break;
 678  
 679                      case 'add':
 680  
 681                          if ($action == 'add')
 682                          {
 683                              $ext_group_row = array(
 684                                  'group_name'    => $request->variable('group_name', '', true),
 685                                  'cat_id'        => 0,
 686                                  'allow_group'    => 1,
 687                                  'allow_in_pm'    => 1,
 688                                  'upload_icon'    => '',
 689                                  'max_filesize'    => 0,
 690                              );
 691  
 692                              $forum_ids = array();
 693                          }
 694  
 695                          $sql = 'SELECT *
 696                              FROM ' . EXTENSIONS_TABLE . "
 697                              WHERE group_id = $group_id
 698                                  OR group_id = 0
 699                              ORDER BY extension";
 700                          $result = $db->sql_query($sql);
 701                          $extensions = $db->sql_fetchrowset($result);
 702                          $db->sql_freeresult($result);
 703  
 704                          if ($ext_group_row['max_filesize'] == 0)
 705                          {
 706                              $ext_group_row['max_filesize'] = (int) $config['max_filesize'];
 707                          }
 708  
 709                          $max_filesize = get_formatted_filesize($ext_group_row['max_filesize'], false, array('mb', 'kb', 'b'));
 710                          $size_format = $max_filesize['si_identifier'];
 711                          $ext_group_row['max_filesize'] = $max_filesize['value'];
 712  
 713                          $img_path = $config['upload_icons_path'];
 714  
 715                          $filename_list = '';
 716                          $no_image_select = false;
 717  
 718                          $imglist = filelist($phpbb_root_path . $img_path);
 719  
 720                          if (!empty($imglist['']))
 721                          {
 722                              $imglist = array_values($imglist);
 723                              $imglist = $imglist[0];
 724  
 725                              foreach ($imglist as $key => $img)
 726                              {
 727                                  if (!$ext_group_row['upload_icon'])
 728                                  {
 729                                      $no_image_select = true;
 730                                      $selected = '';
 731                                  }
 732                                  else
 733                                  {
 734                                      $selected = ($ext_group_row['upload_icon'] == $img) ? ' selected="selected"' : '';
 735                                  }
 736  
 737                                  if (strlen($img) > 255)
 738                                  {
 739                                      continue;
 740                                  }
 741  
 742                                  $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
 743                              }
 744                          }
 745  
 746                          $i = 0;
 747                          $assigned_extensions = '';
 748                          foreach ($extensions as $num => $row)
 749                          {
 750                              if ($row['group_id'] == $group_id && $group_id)
 751                              {
 752                                  $assigned_extensions .= ($i) ? ', ' . $row['extension'] : $row['extension'];
 753                                  $i++;
 754                              }
 755                          }
 756  
 757                          $s_extension_options = '';
 758                          foreach ($extensions as $row)
 759                          {
 760                              $s_extension_options .= '<option' . ((!$row['group_id']) ? ' class="disabled"' : '') . ' value="' . $row['extension_id'] . '"' . (($row['group_id'] == $group_id && $group_id) ? ' selected="selected"' : '') . '>' . $row['extension'] . '</option>';
 761                          }
 762  
 763                          $template->assign_vars(array(
 764                              'IMG_PATH'                => $img_path,
 765                              'ACTION'                => $action,
 766                              'GROUP_ID'                => $group_id,
 767                              'GROUP_NAME'            => $ext_group_row['group_name'],
 768                              'ALLOW_GROUP'            => $ext_group_row['allow_group'],
 769                              'ALLOW_IN_PM'            => $ext_group_row['allow_in_pm'],
 770                              'UPLOAD_ICON_SRC'        => $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'],
 771                              'EXTGROUP_FILESIZE'        => $ext_group_row['max_filesize'],
 772                              'ASSIGNED_EXTENSIONS'    => $assigned_extensions,
 773  
 774                              'S_CATEGORY_SELECT'            => $this->category_select('special_category', $group_id, 'category'),
 775                              'S_EXT_GROUP_SIZE_OPTIONS'    => size_select_options($size_format),
 776                              'S_EXTENSION_OPTIONS'        => $s_extension_options,
 777                              'S_FILENAME_LIST'            => $filename_list,
 778                              'S_EDIT_GROUP'                => true,
 779                              'S_NO_IMAGE'                => $no_image_select,
 780                              'S_FORUM_IDS'                => (count($forum_ids)) ? true : false,
 781  
 782                              'U_EXTENSIONS'        => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=extensions"),
 783                              'U_BACK'            => $this->u_action,
 784  
 785                              'L_LEGEND'            => $user->lang[strtoupper($action) . '_EXTENSION_GROUP'])
 786                          );
 787  
 788                          $s_forum_id_options = '';
 789  
 790                          /** @todo use in-built function **/
 791  
 792                          $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
 793                              FROM ' . FORUMS_TABLE . '
 794                              ORDER BY left_id ASC';
 795                          $result = $db->sql_query($sql, 600);
 796  
 797                          $right = $cat_right = $padding_inc = 0;
 798                          $padding = $forum_list = $holding = '';
 799                          $padding_store = array('0' => '');
 800  
 801                          while ($row = $db->sql_fetchrow($result))
 802                          {
 803                              if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
 804                              {
 805                                  // Non-postable forum with no subforums, don't display
 806                                  continue;
 807                              }
 808  
 809                              if (!$auth->acl_get('f_list', $row['forum_id']))
 810                              {
 811                                  // if the user does not have permissions to list this forum skip
 812                                  continue;
 813                              }
 814  
 815                              if ($row['left_id'] < $right)
 816                              {
 817                                  $padding .= '&nbsp; &nbsp;';
 818                                  $padding_store[$row['parent_id']] = $padding;
 819                              }
 820                              else if ($row['left_id'] > $right + 1)
 821                              {
 822                                  $padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']];
 823                              }
 824  
 825                              $right = $row['right_id'];
 826  
 827                              $selected = (in_array($row['forum_id'], $forum_ids)) ? ' selected="selected"' : '';
 828  
 829                              if ($row['left_id'] > $cat_right)
 830                              {
 831                                  // make sure we don't forget anything
 832                                  $s_forum_id_options .= $holding;
 833                                  $holding = '';
 834                              }
 835  
 836                              if ($row['right_id'] - $row['left_id'] > 1)
 837                              {
 838                                  $cat_right = max($cat_right, $row['right_id']);
 839  
 840                                  $holding .= '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
 841                              }
 842                              else
 843                              {
 844                                  $s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
 845                                  $holding = '';
 846                              }
 847                          }
 848  
 849                          if ($holding)
 850                          {
 851                              $s_forum_id_options .= $holding;
 852                          }
 853  
 854                          $db->sql_freeresult($result);
 855                          unset($padding_store);
 856  
 857                          $template->assign_vars(array(
 858                              'S_FORUM_ID_OPTIONS'    => $s_forum_id_options)
 859                          );
 860  
 861                      break;
 862                  }
 863  
 864                  $sql = 'SELECT *
 865                      FROM ' . EXTENSION_GROUPS_TABLE . '
 866                      ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
 867                  $result = $db->sql_query($sql);
 868  
 869                  $old_allow_group = $old_allow_pm = 1;
 870                  while ($row = $db->sql_fetchrow($result))
 871                  {
 872                      $s_add_spacer = ($old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm']) ? true : false;
 873  
 874                      $template->assign_block_vars('groups', array(
 875                          'S_ADD_SPACER'        => $s_add_spacer,
 876                          'S_ALLOWED_IN_PM'    => ($row['allow_in_pm']) ? true : false,
 877                          'S_GROUP_ALLOWED'    => ($row['allow_group']) ? true : false,
 878  
 879                          'U_EDIT'        => $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}",
 880                          'U_DELETE'        => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}",
 881  
 882                          'GROUP_NAME'    => $this->language->is_set('EXT_GROUP_' . utf8_strtoupper($row['group_name'])) ? $this->language->lang('EXT_GROUP_' . utf8_strtoupper($row['group_name'])) : $row['group_name'],
 883                          'CATEGORY'        => $cat_lang[$row['cat_id']],
 884                          )
 885                      );
 886  
 887                      $old_allow_group = $row['allow_group'];
 888                      $old_allow_pm = $row['allow_in_pm'];
 889                  }
 890                  $db->sql_freeresult($result);
 891  
 892              break;
 893  
 894              case 'orphan':
 895  
 896                  /* @var $pagination \phpbb\pagination */
 897                  $pagination = $this->phpbb_container->get('pagination');
 898  
 899                  if ($submit)
 900                  {
 901                      $delete_files = (isset($_POST['delete'])) ? array_keys($request->variable('delete', array('' => 0))) : array();
 902                      $add_files = (isset($_POST['add'])) ? array_keys($request->variable('add', array('' => 0))) : array();
 903                      $post_ids = $request->variable('post_id', array('' => 0));
 904  
 905                      if (count($delete_files))
 906                      {
 907                          $sql = 'SELECT *
 908                              FROM ' . ATTACHMENTS_TABLE . '
 909                              WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
 910                                  AND is_orphan = 1';
 911                          $result = $db->sql_query($sql);
 912  
 913                          $delete_files = array();
 914                          while ($row = $db->sql_fetchrow($result))
 915                          {
 916                              $this->attachment_manager->unlink($row['physical_filename'], 'file');
 917  
 918                              if ($row['thumbnail'])
 919                              {
 920                                  $this->attachment_manager->unlink($row['physical_filename'], 'thumbnail');
 921                              }
 922  
 923                              $delete_files[$row['attach_id']] = $row['real_filename'];
 924                          }
 925                          $db->sql_freeresult($result);
 926                      }
 927  
 928                      if (count($delete_files))
 929                      {
 930                          $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
 931                              WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
 932                          $db->sql_query($sql);
 933  
 934                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_ORPHAN_DEL', false, array(implode(', ', $delete_files)));
 935                          $notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode($user->lang['COMMA_SEPARATOR'], $delete_files));
 936                      }
 937  
 938                      $upload_list = array();
 939                      foreach ($add_files as $attach_id)
 940                      {
 941                          if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id]))
 942                          {
 943                              $upload_list[$attach_id] = $post_ids[$attach_id];
 944                          }
 945                      }
 946                      unset($add_files);
 947  
 948                      if (count($upload_list))
 949                      {
 950                          $template->assign_var('S_UPLOADING_FILES', true);
 951  
 952                          $sql = 'SELECT forum_id, forum_name
 953                              FROM ' . FORUMS_TABLE;
 954                          $result = $db->sql_query($sql);
 955  
 956                          $forum_names = array();
 957                          while ($row = $db->sql_fetchrow($result))
 958                          {
 959                              $forum_names[$row['forum_id']] = $row['forum_name'];
 960                          }
 961                          $db->sql_freeresult($result);
 962  
 963                          $sql = 'SELECT forum_id, topic_id, post_id, poster_id
 964                              FROM ' . POSTS_TABLE . '
 965                              WHERE ' . $db->sql_in_set('post_id', $upload_list);
 966                          $result = $db->sql_query($sql);
 967  
 968                          $post_info = array();
 969                          while ($row = $db->sql_fetchrow($result))
 970                          {
 971                              $post_info[$row['post_id']] = $row;
 972                          }
 973                          $db->sql_freeresult($result);
 974  
 975                          // Select those attachments we want to change...
 976                          $sql = 'SELECT *
 977                              FROM ' . ATTACHMENTS_TABLE . '
 978                              WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
 979                                  AND is_orphan = 1';
 980                          $result = $db->sql_query($sql);
 981  
 982                          $files_added = $space_taken = 0;
 983                          while ($row = $db->sql_fetchrow($result))
 984                          {
 985                              $post_row = $post_info[$upload_list[$row['attach_id']]];
 986  
 987                              $template->assign_block_vars('upload', array(
 988                                  'FILE_INFO'        => sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']),
 989                                  'S_DENIED'        => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? true : false,
 990                                  'L_DENIED'        => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : '')
 991                              );
 992  
 993                              if (!$auth->acl_get('f_attach', $post_row['forum_id']))
 994                              {
 995                                  continue;
 996                              }
 997  
 998                              // Adjust attachment entry
 999                              $sql_ary = array(
1000                                  'in_message'    => 0,
1001                                  'is_orphan'        => 0,
1002                                  'poster_id'        => $post_row['poster_id'],
1003                                  'post_msg_id'    => $post_row['post_id'],
1004                                  'topic_id'        => $post_row['topic_id'],
1005                              );
1006  
1007                              $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
1008                                  SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
1009                                  WHERE attach_id = ' . $row['attach_id'];
1010                              $db->sql_query($sql);
1011  
1012                              $sql = 'UPDATE ' . POSTS_TABLE . '
1013                                  SET post_attachment = 1
1014                                  WHERE post_id = ' . $post_row['post_id'];
1015                              $db->sql_query($sql);
1016  
1017                              $sql = 'UPDATE ' . TOPICS_TABLE . '
1018                                  SET topic_attachment = 1
1019                                  WHERE topic_id = ' . $post_row['topic_id'];
1020                              $db->sql_query($sql);
1021  
1022                              $space_taken += $row['filesize'];
1023                              $files_added++;
1024  
1025                              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_FILEUPLOAD', false, array($post_row['post_id'], $row['real_filename']));
1026                          }
1027                          $db->sql_freeresult($result);
1028  
1029                          if ($files_added)
1030                          {
1031                              $config->increment('upload_dir_size', $space_taken, false);
1032                              $config->increment('num_files', $files_added, false);
1033                          }
1034                      }
1035                  }
1036  
1037                  $template->assign_vars(array(
1038                      'S_ORPHAN'        => true)
1039                  );
1040  
1041                  $attachments_per_page = (int) $config['topics_per_page'];
1042  
1043                  // Get total number or orphans older than 3 hours
1044                  $sql = 'SELECT COUNT(attach_id) as num_files, SUM(filesize) as total_size
1045                      FROM ' . ATTACHMENTS_TABLE . '
1046                      WHERE is_orphan = 1
1047                          AND filetime < ' . (time() - 3*60*60);
1048                  $result = $this->db->sql_query($sql);
1049                  $row = $this->db->sql_fetchrow($result);
1050                  $num_files = (int) $row['num_files'];
1051                  $total_size = (int) $row['total_size'];
1052                  $this->db->sql_freeresult($result);
1053  
1054                  $start = $request->variable('start', 0);
1055                  $start = $pagination->validate_start($start, $attachments_per_page, $num_files);
1056  
1057                  // Just get the files with is_orphan set and older than 3 hours
1058                  $sql = 'SELECT *
1059                      FROM ' . ATTACHMENTS_TABLE . '
1060                      WHERE is_orphan = 1
1061                          AND filetime < ' . (time() - 3*60*60) . '
1062                      ORDER BY filetime DESC';
1063                  $result = $db->sql_query_limit($sql, $attachments_per_page, $start);
1064  
1065                  while ($row = $db->sql_fetchrow($result))
1066                  {
1067                      $template->assign_block_vars('orphan', array(
1068                          'FILESIZE'            => get_formatted_filesize($row['filesize']),
1069                          'FILETIME'            => $user->format_date($row['filetime']),
1070                          'REAL_FILENAME'        => utf8_basename($row['real_filename']),
1071                          'PHYSICAL_FILENAME'    => utf8_basename($row['physical_filename']),
1072                          'ATTACH_ID'            => $row['attach_id'],
1073                          'POST_IDS'            => (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
1074                          'U_FILE'            => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))
1075                      );
1076                  }
1077                  $db->sql_freeresult($result);
1078  
1079                  $pagination->generate_template_pagination(
1080                      $this->u_action,
1081                      'pagination',
1082                      'start',
1083                      $num_files,
1084                      $attachments_per_page,
1085                      $start
1086                  );
1087  
1088                  $template->assign_vars(array(
1089                      'TOTAL_FILES'        => $num_files,
1090                      'TOTAL_SIZE'        => get_formatted_filesize($total_size),
1091                  ));
1092  
1093              break;
1094  
1095              case 'manage':
1096  
1097                  if ($submit)
1098                  {
1099                      $delete_files = (isset($_POST['delete'])) ? array_keys($request->variable('delete', array('' => 0))) : array();
1100  
1101                      if (count($delete_files))
1102                      {
1103                          // Select those attachments we want to delete...
1104                          $sql = 'SELECT real_filename
1105                              FROM ' . ATTACHMENTS_TABLE . '
1106                              WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
1107                                  AND is_orphan = 0';
1108                          $result = $db->sql_query($sql);
1109                          while ($row = $db->sql_fetchrow($result))
1110                          {
1111                              $deleted_filenames[] = $row['real_filename'];
1112                          }
1113                          $db->sql_freeresult($result);
1114  
1115                          if ($num_deleted = $this->attachment_manager->delete('attach', $delete_files))
1116                          {
1117                              if (count($delete_files) != $num_deleted)
1118                              {
1119                                  $error[] = $user->lang['FILES_GONE'];
1120                              }
1121  
1122                              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACHMENTS_DELETED', false, array(implode(', ', $deleted_filenames)));
1123                              $notify[] = sprintf($user->lang['LOG_ATTACHMENTS_DELETED'], implode($user->lang['COMMA_SEPARATOR'], $deleted_filenames));
1124                          }
1125                          else
1126                          {
1127                              $error[] = $user->lang['NO_FILES_TO_DELETE'];
1128                          }
1129                      }
1130                  }
1131  
1132                  if ($action == 'stats')
1133                  {
1134                      $this->handle_stats_resync();
1135                  }
1136  
1137                  $stats_error = $this->check_stats_accuracy();
1138  
1139                  if ($stats_error)
1140                  {
1141                      $error[] = $stats_error;
1142                  }
1143  
1144                  $template->assign_vars(array(
1145                      'S_MANAGE'        => true,
1146                  ));
1147  
1148                  $start        = $request->variable('start', 0);
1149  
1150                  // Sort keys
1151                  $sort_days    = $request->variable('st', 0);
1152                  $sort_key    = $request->variable('sk', 't');
1153                  $sort_dir    = $request->variable('sd', 'd');
1154  
1155                  // Sorting
1156                  $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
1157                  $sort_by_text = array('f' => $user->lang['FILENAME'], 't' => $user->lang['FILEDATE'], 's' => $user->lang['FILESIZE'], 'x' => $user->lang['EXTENSION'], 'd' => $user->lang['DOWNLOADS'],'p' => $user->lang['ATTACH_POST_TYPE'], 'u' => $user->lang['AUTHOR']);
1158                  $sort_by_sql = array('f' => 'a.real_filename', 't' => 'a.filetime', 's' => 'a.filesize', 'x' => 'a.extension', 'd' => 'a.download_count', 'p' => 'a.in_message', 'u' => 'u.username');
1159  
1160                  $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
1161                  gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
1162  
1163                  $min_filetime = ($sort_days) ? (time() - ($sort_days * 86400)) : '';
1164                  $limit_filetime = ($min_filetime) ? " AND a.filetime >= $min_filetime " : '';
1165                  $start = ($sort_days && isset($_POST['sort'])) ? 0 : $start;
1166  
1167                  $attachments_per_page = (int) $config['topics_per_page'];
1168  
1169                  $stats = $this->get_attachment_stats($limit_filetime);
1170                  $num_files = $stats['num_files'];
1171                  $total_size = $stats['upload_dir_size'];
1172  
1173                  // Make sure $start is set to the last page if it exceeds the amount
1174                  /* @var $pagination \phpbb\pagination */
1175                  $pagination = $phpbb_container->get('pagination');
1176                  $start = $pagination->validate_start($start, $attachments_per_page, $num_files);
1177  
1178                  // If the user is trying to reach the second half of the attachments list, fetch it starting from the end
1179                  $store_reverse = false;
1180                  $sql_limit = $attachments_per_page;
1181  
1182                  if ($start > $num_files / 2)
1183                  {
1184                      $store_reverse = true;
1185  
1186                      // Select the sort order. Add time sort anchor for non-time sorting cases
1187                      $sql_sort_anchor = ($sort_key != 't') ? ', a.filetime ' . (($sort_dir == 'd') ? 'ASC' : 'DESC') : '';
1188                      $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC') . $sql_sort_anchor;
1189                      $sql_limit = $pagination->reverse_limit($start, $sql_limit, $num_files);
1190                      $sql_start = $pagination->reverse_start($start, $sql_limit, $num_files);
1191                  }
1192                  else
1193                  {
1194                      // Select the sort order. Add time sort anchor for non-time sorting cases
1195                      $sql_sort_anchor = ($sort_key != 't') ? ', a.filetime ' . (($sort_dir == 'd') ? 'DESC' : 'ASC') : '';
1196                      $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC') . $sql_sort_anchor;
1197                      $sql_start = $start;
1198                  }
1199  
1200                  $attachments_list = array();
1201  
1202                  // Just get the files
1203                  $sql = 'SELECT a.*, u.username, u.user_colour, t.topic_title
1204                      FROM ' . ATTACHMENTS_TABLE . ' a
1205                      LEFT JOIN ' . USERS_TABLE . ' u ON (u.user_id = a.poster_id)
1206                      LEFT JOIN ' . TOPICS_TABLE . " t ON (a.topic_id = t.topic_id)
1207                      WHERE a.is_orphan = 0
1208                          $limit_filetime
1209                      ORDER BY $sql_sort_order";
1210                  $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
1211  
1212                  $i = ($store_reverse) ? $sql_limit - 1 : 0;
1213  
1214                  // Store increment value in a variable to save some conditional calls
1215                  $i_increment = ($store_reverse) ? -1 : 1;
1216                  while ($attachment_row = $db->sql_fetchrow($result))
1217                  {
1218                      $attachments_list[$i] = $attachment_row;
1219                      $i = $i + $i_increment;
1220                  }
1221                  $db->sql_freeresult($result);
1222  
1223                  $base_url = $this->u_action . "&amp;$u_sort_param";
1224                  $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_files, $attachments_per_page, $start);
1225  
1226                  $template->assign_vars(array(
1227                      'TOTAL_FILES'        => $num_files,
1228                      'TOTAL_SIZE'        => get_formatted_filesize($total_size),
1229  
1230                      'S_LIMIT_DAYS'        => $s_limit_days,
1231                      'S_SORT_KEY'        => $s_sort_key,
1232                      'S_SORT_DIR'        => $s_sort_dir)
1233                  );
1234  
1235                  // Grab extensions
1236                  $extensions = $cache->obtain_attach_extensions(true);
1237  
1238                  for ($i = 0, $end = count($attachments_list); $i < $end; ++$i)
1239                  {
1240                      $row = $attachments_list[$i];
1241  
1242                      $row['extension'] = strtolower(trim((string) $row['extension']));
1243                      $comment = ($row['attach_comment'] && !$row['in_message']) ? str_replace(array("\n", "\r"), array('<br />', "\n"), $row['attach_comment']) : '';
1244                      $display_cat = isset($extensions[$row['extension']]['display_cat']) ? $extensions[$row['extension']]['display_cat'] : ATTACHMENT_CATEGORY_NONE;
1245                      $l_downloaded_viewed = ($display_cat == ATTACHMENT_CATEGORY_NONE) ? 'DOWNLOAD_COUNTS' : 'VIEWED_COUNTS';
1246  
1247                      $template->assign_block_vars('attachments', array(
1248                          'ATTACHMENT_POSTER'    => get_username_string('full', (int) $row['poster_id'], (string) $row['username'], (string) $row['user_colour'], (string) $row['username']),
1249                          'FILESIZE'            => get_formatted_filesize((int) $row['filesize']),
1250                          'FILETIME'            => $user->format_date((int) $row['filetime']),
1251                          'REAL_FILENAME'        => utf8_basename((string) $row['real_filename']),
1252                          'EXT_GROUP_NAME'    => $this->language->is_set('EXT_GROUP_' . utf8_strtoupper($extensions[$row['extension']]['group_name'])) ?  $this->language->lang('EXT_GROUP_' . utf8_strtoupper($extensions[$row['extension']]['group_name'])) : $extensions[$row['extension']]['group_name'],
1253                          'COMMENT'            => $comment,
1254                          'TOPIC_TITLE'        => (!$row['in_message']) ? (string) $row['topic_title'] : '',
1255                          'ATTACH_ID'            => (int) $row['attach_id'],
1256  
1257                          'L_DOWNLOAD_COUNT'    => $user->lang($l_downloaded_viewed, (int) $row['download_count']),
1258  
1259                          'S_IN_MESSAGE'        => (bool) $row['in_message'],
1260  
1261                          'U_VIEW_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}",
1262                          'U_FILE'            => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))
1263                      );
1264                  }
1265  
1266              break;
1267          }
1268  
1269          if (count($error))
1270          {
1271              $template->assign_vars(array(
1272                  'S_WARNING'        => true,
1273                  'WARNING_MSG'    => implode('<br />', $error))
1274              );
1275          }
1276  
1277          if (count($notify))
1278          {
1279              $template->assign_vars(array(
1280                  'S_NOTIFY'        => true,
1281                  'NOTIFY_MSG'    => implode('<br />', $notify))
1282              );
1283          }
1284      }
1285  
1286      /**
1287      * Get attachment file count and size of upload directory
1288      *
1289      * @param $limit string    Additional limit for WHERE clause to filter stats by.
1290      * @return array Returns array with stats: num_files and upload_dir_size
1291      */
1292  	public function get_attachment_stats($limit = '')
1293      {
1294          $sql = 'SELECT COUNT(a.attach_id) AS num_files, SUM(a.filesize) AS upload_dir_size
1295              FROM ' . ATTACHMENTS_TABLE . " a
1296              WHERE a.is_orphan = 0
1297                  $limit";
1298          $result = $this->db->sql_query($sql);
1299          $row = $this->db->sql_fetchrow($result);
1300          $this->db->sql_freeresult($result);
1301  
1302          return array(
1303              'num_files'            => (int) $row['num_files'],
1304              'upload_dir_size'    => (float) $row['upload_dir_size'],
1305          );
1306      }
1307  
1308      /**
1309      * Set config attachment stat values
1310      *
1311      * @param $stats array    Array of config key => value pairs to set.
1312      * @return null
1313      */
1314  	public function set_attachment_stats($stats)
1315      {
1316          foreach ($stats as $key => $value)
1317          {
1318              $this->config->set($key, $value, true);
1319          }
1320      }
1321  
1322      /**
1323      * Check accuracy of attachment statistics.
1324      *
1325      * @return bool|string    Returns false if stats are correct or error message
1326      *    otherwise.
1327      */
1328  	public function check_stats_accuracy()
1329      {
1330          // Get fresh stats.
1331          $stats = $this->get_attachment_stats();
1332  
1333          // Get current files stats
1334          $num_files = (int) $this->config['num_files'];
1335          $total_size = (float) $this->config['upload_dir_size'];
1336  
1337          if (($num_files != $stats['num_files']) || ($total_size != $stats['upload_dir_size']))
1338          {
1339              $u_resync = $this->u_action . '&amp;action=stats';
1340  
1341              return $this->user->lang(
1342                  'FILES_STATS_WRONG',
1343                  (int) $stats['num_files'],
1344                  get_formatted_filesize($stats['upload_dir_size']),
1345                  '<a href="' . $u_resync . '">',
1346                  '</a>'
1347              );
1348          }
1349          return false;
1350      }
1351  
1352      /**
1353      * Handle stats resync.
1354      *
1355      * @return null
1356      */
1357  	public function handle_stats_resync()
1358      {
1359          if (!confirm_box(true))
1360          {
1361              confirm_box(false, $this->user->lang['RESYNC_FILES_STATS_CONFIRM'], build_hidden_fields(array(
1362                  'i'            => $this->id,
1363                  'mode'        => 'manage',
1364                  'action'    => 'stats',
1365              )));
1366          }
1367          else
1368          {
1369              $this->set_attachment_stats($this->get_attachment_stats());
1370  
1371              /* @var $log \phpbb\log\log_interface */
1372              $log = $this->phpbb_container->get('log');
1373              $log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_RESYNC_FILES_STATS');
1374          }
1375  
1376      }
1377  
1378      /**
1379      * Build Select for category items
1380      */
1381  	function category_select($select_name, $group_id = false, $key = '')
1382      {
1383          global $db, $user;
1384  
1385          $types = array(
1386              ATTACHMENT_CATEGORY_NONE        => $user->lang['NO_FILE_CAT'],
1387              ATTACHMENT_CATEGORY_IMAGE        => $user->lang['CAT_IMAGES'],
1388              ATTACHMENT_CATEGORY_FLASH        => $user->lang['CAT_FLASH_FILES'],
1389          );
1390  
1391          if ($group_id)
1392          {
1393              $sql = 'SELECT cat_id
1394                  FROM ' . EXTENSION_GROUPS_TABLE . '
1395                  WHERE group_id = ' . (int) $group_id;
1396              $result = $db->sql_query($sql);
1397  
1398              $cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE : $row['cat_id'];
1399  
1400              $db->sql_freeresult($result);
1401          }
1402          else
1403          {
1404              $cat_type = ATTACHMENT_CATEGORY_NONE;
1405          }
1406  
1407          $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
1408  
1409          foreach ($types as $type => $mode)
1410          {
1411              $selected = ($type == $cat_type) ? ' selected="selected"' : '';
1412              $group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>';
1413          }
1414  
1415          $group_select .= '</select>';
1416  
1417          return $group_select;
1418      }
1419  
1420      /**
1421      * Extension group select
1422      */
1423  	function group_select($select_name, $default_group = false, $key = '')
1424      {
1425          global $db, $user;
1426  
1427          $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
1428  
1429          $sql = 'SELECT group_id, group_name
1430              FROM ' . EXTENSION_GROUPS_TABLE . '
1431              ORDER BY group_name';
1432          $result = $db->sql_query($sql);
1433  
1434          $group_name = array();
1435          while ($row = $db->sql_fetchrow($result))
1436          {
1437              $row['group_name'] = $this->language->is_set('EXT_GROUP_' . utf8_strtoupper($row['group_name'])) ? $this->language->lang('EXT_GROUP_' . utf8_strtoupper($row['group_name'])) : $row['group_name'];
1438              $group_name[] = $row;
1439          }
1440          $db->sql_freeresult($result);
1441  
1442          $row['group_id'] = 0;
1443          $row['group_name'] = $user->lang['NOT_ASSIGNED'];
1444          $group_name[] = $row;
1445  
1446          for ($i = 0, $groups_size = count($group_name); $i < $groups_size; $i++)
1447          {
1448              if ($default_group === false)
1449              {
1450                  $selected = ($i == 0) ? ' selected="selected"' : '';
1451              }
1452              else
1453              {
1454                  $selected = ($group_name[$i]['group_id'] == $default_group) ? ' selected="selected"' : '';
1455              }
1456  
1457              $group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>';
1458          }
1459  
1460          $group_select .= '</select>';
1461  
1462          return $group_select;
1463      }
1464  
1465      /**
1466      * Test Settings
1467      */
1468  	function test_upload(&$error, $upload_dir, $create_directory = false)
1469      {
1470          global $user, $phpbb_root_path;
1471  
1472          // Does the target directory exist, is it a directory and writable.
1473          if ($create_directory)
1474          {
1475              if (!file_exists($phpbb_root_path . $upload_dir))
1476              {
1477                  @mkdir($phpbb_root_path . $upload_dir, 0777);
1478  
1479                  try
1480                  {
1481                      $this->filesystem->phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);
1482                  }
1483                  catch (\phpbb\filesystem\exception\filesystem_exception $e)
1484                  {
1485                      // Do nothing
1486                  }
1487              }
1488          }
1489  
1490          if (!file_exists($phpbb_root_path . $upload_dir))
1491          {
1492              $error[] = sprintf($user->lang['NO_UPLOAD_DIR'], $upload_dir);
1493              return;
1494          }
1495  
1496          if (!is_dir($phpbb_root_path . $upload_dir))
1497          {
1498              $error[] = sprintf($user->lang['UPLOAD_NOT_DIR'], $upload_dir);
1499              return;
1500          }
1501  
1502          if (!$this->filesystem->is_writable($phpbb_root_path . $upload_dir))
1503          {
1504              $error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
1505              return;
1506          }
1507      }
1508  
1509      /**
1510      * Perform operations on sites for external linking
1511      */
1512  	function perform_site_list()
1513      {
1514          global $db, $user, $request, $phpbb_log;
1515  
1516          if (isset($_REQUEST['securesubmit']))
1517          {
1518              // Grab the list of entries
1519              $ips = $request->variable('ips', '');
1520              $ip_list = array_unique(explode("\n", $ips));
1521              $ip_list_log = implode(', ', $ip_list);
1522  
1523              $ip_exclude = (int) $request->variable('ipexclude', false, false, \phpbb\request\request_interface::POST);
1524  
1525              $iplist = array();
1526              $hostlist = array();
1527  
1528              foreach ($ip_list as $item)
1529              {
1530                  if (preg_match('#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})[ ]*\-[ ]*([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#', trim($item), $ip_range_explode))
1531                  {
1532                      // Don't ask about all this, just don't ask ... !
1533                      $ip_1_counter = $ip_range_explode[1];
1534                      $ip_1_end = $ip_range_explode[5];
1535  
1536                      while ($ip_1_counter <= $ip_1_end)
1537                      {
1538                          $ip_2_counter = ($ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[2] : 0;
1539                          $ip_2_end = ($ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[6];
1540  
1541                          if ($ip_2_counter == 0 && $ip_2_end == 254)
1542                          {
1543                              $ip_2_counter = 256;
1544  
1545                              $iplist[] = "'$ip_1_counter.*'";
1546                          }
1547  
1548                          while ($ip_2_counter <= $ip_2_end)
1549                          {
1550                              $ip_3_counter = ($ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[3] : 0;
1551                              $ip_3_end = ($ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[7];
1552  
1553                              if ($ip_3_counter == 0 && $ip_3_end == 254)
1554                              {
1555                                  $ip_3_counter = 256;
1556  
1557                                  $iplist[] = "'$ip_1_counter.$ip_2_counter.*'";
1558                              }
1559  
1560                              while ($ip_3_counter <= $ip_3_end)
1561                              {
1562                                  $ip_4_counter = ($ip_3_counter == $ip_range_explode[3] && $ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[4] : 0;
1563                                  $ip_4_end = ($ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end) ? 254 : $ip_range_explode[8];
1564  
1565                                  if ($ip_4_counter == 0 && $ip_4_end == 254)
1566                                  {
1567                                      $ip_4_counter = 256;
1568  
1569                                      $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.*'";
1570                                  }
1571  
1572                                  while ($ip_4_counter <= $ip_4_end)
1573                                  {
1574                                      $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter'";
1575                                      $ip_4_counter++;
1576                                  }
1577                                  $ip_3_counter++;
1578                              }
1579                              $ip_2_counter++;
1580                          }
1581                          $ip_1_counter++;
1582                      }
1583                  }
1584                  else if (preg_match('#^([0-9]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})$#', trim($item)) || preg_match('#^[a-f0-9:]+\*?$#i', trim($item)))
1585                  {
1586                      $iplist[] = "'" . trim($item) . "'";
1587                  }
1588                  else if (preg_match('#^([\w\-_]\.?){2,}$#is', trim($item)))
1589                  {
1590                      $hostlist[] = "'" . trim($item) . "'";
1591                  }
1592                  else if (preg_match("#^([a-z0-9\-\*\._/]+?)$#is", trim($item)))
1593                  {
1594                      $hostlist[] = "'" . trim($item) . "'";
1595                  }
1596              }
1597  
1598              $sql = 'SELECT site_ip, site_hostname
1599                  FROM ' . SITELIST_TABLE . "
1600                  WHERE ip_exclude = $ip_exclude";
1601              $result = $db->sql_query($sql);
1602  
1603              if ($row = $db->sql_fetchrow($result))
1604              {
1605                  $iplist_tmp = array();
1606                  $hostlist_tmp = array();
1607                  do
1608                  {
1609                      if ($row['site_ip'])
1610                      {
1611                          if (strlen($row['site_ip']) > 40)
1612                          {
1613                              continue;
1614                          }
1615  
1616                          $iplist_tmp[] = "'" . $row['site_ip'] . "'";
1617                      }
1618                      else if ($row['site_hostname'])
1619                      {
1620                          if (strlen($row['site_hostname']) > 255)
1621                          {
1622                              continue;
1623                          }
1624  
1625                          $hostlist_tmp[] = "'" . $row['site_hostname'] . "'";
1626                      }
1627                      // break;
1628                  }
1629                  while ($row = $db->sql_fetchrow($result));
1630  
1631                  $iplist = array_unique(array_diff($iplist, $iplist_tmp));
1632                  $hostlist = array_unique(array_diff($hostlist, $hostlist_tmp));
1633                  unset($iplist_tmp);
1634                  unset($hostlist_tmp);
1635              }
1636              $db->sql_freeresult($result);
1637  
1638              if (count($iplist))
1639              {
1640                  foreach ($iplist as $ip_entry)
1641                  {
1642                      $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_ip, ip_exclude)
1643                          VALUES ($ip_entry, $ip_exclude)";
1644                      $db->sql_query($sql);
1645                  }
1646              }
1647  
1648              if (count($hostlist))
1649              {
1650                  foreach ($hostlist as $host_entry)
1651                  {
1652                      $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_hostname, ip_exclude)
1653                          VALUES ($host_entry, $ip_exclude)";
1654                      $db->sql_query($sql);
1655                  }
1656              }
1657  
1658              if (!empty($ip_list_log))
1659              {
1660                  // Update log
1661                  $log_entry = ($ip_exclude) ? 'LOG_DOWNLOAD_EXCLUDE_IP' : 'LOG_DOWNLOAD_IP';
1662                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log_entry, false, array($ip_list_log));
1663              }
1664  
1665              trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
1666          }
1667          else if (isset($_POST['unsecuresubmit']))
1668          {
1669              $unip_sql = $request->variable('unip', array(0));
1670  
1671              if (count($unip_sql))
1672              {
1673                  $l_unip_list = '';
1674  
1675                  // Grab details of ips for logging information later
1676                  $sql = 'SELECT site_ip, site_hostname
1677                      FROM ' . SITELIST_TABLE . '
1678                      WHERE ' . $db->sql_in_set('site_id', $unip_sql);
1679                  $result = $db->sql_query($sql);
1680  
1681                  while ($row = $db->sql_fetchrow($result))
1682                  {
1683                      $l_unip_list .= (($l_unip_list != '') ? ', ' : '') . (($row['site_ip']) ? $row['site_ip'] : $row['site_hostname']);
1684                  }
1685                  $db->sql_freeresult($result);
1686  
1687                  $sql = 'DELETE FROM ' . SITELIST_TABLE . '
1688                      WHERE ' . $db->sql_in_set('site_id', $unip_sql);
1689                  $db->sql_query($sql);
1690  
1691                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DOWNLOAD_REMOVE_IP', false, array($l_unip_list));
1692              }
1693  
1694              trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
1695          }
1696      }
1697  
1698      /**
1699      * Write display_order config field
1700      */
1701  	function display_order($value, $key = '')
1702      {
1703          $radio_ary = array(0 => 'DESCENDING', 1 => 'ASCENDING');
1704  
1705          return h_radio('config[display_order]', $radio_ary, $value, $key);
1706      }
1707  
1708      /**
1709      * Adjust all three max_filesize config vars for display
1710      */
1711  	function max_filesize($value, $key = '')
1712      {
1713          // Determine size var and adjust the value accordingly
1714          $filesize = get_formatted_filesize($value, false, array('mb', 'kb', 'b'));
1715          $size_var = $filesize['si_identifier'];
1716          $value = $filesize['value'];
1717  
1718          // size and maxlength must not be specified for input of type number
1719          return '<input type="number" id="' . $key . '" min="0" max="999999999999999" step="any" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
1720      }
1721  
1722      /**
1723      * Write secure_allow_deny config field
1724      */
1725  	function select_allow_deny($value, $key = '')
1726      {
1727          $radio_ary = array(1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW');
1728  
1729          return h_radio('config[' . $key . ']', $radio_ary, $value, $key);
1730      }
1731  
1732  }


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