[ Index ]

PHP Cross Reference of phpBB-3.3.0-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                  );
 614  
 615                  $group_id = $request->variable('g', 0);
 616                  $action = (isset($_POST['add'])) ? 'add' : $action;
 617  
 618                  switch ($action)
 619                  {
 620                      case 'delete':
 621  
 622                          if (confirm_box(true))
 623                          {
 624                              $sql = 'SELECT group_name
 625                                  FROM ' . EXTENSION_GROUPS_TABLE . "
 626                                  WHERE group_id = $group_id";
 627                              $result = $db->sql_query($sql);
 628                              $group_name = (string) $db->sql_fetchfield('group_name');
 629                              $db->sql_freeresult($result);
 630  
 631                              $sql = 'DELETE
 632                                  FROM ' . EXTENSION_GROUPS_TABLE . "
 633                                  WHERE group_id = $group_id";
 634                              $db->sql_query($sql);
 635  
 636                              // Set corresponding Extensions to a pending Group
 637                              $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
 638                                  SET group_id = 0
 639                                  WHERE group_id = $group_id";
 640                              $db->sql_query($sql);
 641  
 642                              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXTGROUP_DEL', false, array($group_name));
 643  
 644                              $cache->destroy('_extensions');
 645  
 646                              trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action));
 647                          }
 648                          else
 649                          {
 650                              confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 651                                  'i'            => $id,
 652                                  'mode'        => $mode,
 653                                  'group_id'    => $group_id,
 654                                  'action'    => 'delete',
 655                              )));
 656                          }
 657  
 658                      break;
 659  
 660                      case 'edit':
 661  
 662                          if (!$group_id)
 663                          {
 664                              trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
 665                          }
 666  
 667                          $sql = 'SELECT *
 668                              FROM ' . EXTENSION_GROUPS_TABLE . "
 669                              WHERE group_id = $group_id";
 670                          $result = $db->sql_query($sql);
 671                          $ext_group_row = $db->sql_fetchrow($result);
 672                          $db->sql_freeresult($result);
 673  
 674                          $forum_ids = (!$ext_group_row['allowed_forums']) ? array() : unserialize(trim($ext_group_row['allowed_forums']));
 675  
 676                      // no break;
 677  
 678                      case 'add':
 679  
 680                          if ($action == 'add')
 681                          {
 682                              $ext_group_row = array(
 683                                  'group_name'    => $request->variable('group_name', '', true),
 684                                  'cat_id'        => 0,
 685                                  'allow_group'    => 1,
 686                                  'allow_in_pm'    => 1,
 687                                  'upload_icon'    => '',
 688                                  'max_filesize'    => 0,
 689                              );
 690  
 691                              $forum_ids = array();
 692                          }
 693  
 694                          $sql = 'SELECT *
 695                              FROM ' . EXTENSIONS_TABLE . "
 696                              WHERE group_id = $group_id
 697                                  OR group_id = 0
 698                              ORDER BY extension";
 699                          $result = $db->sql_query($sql);
 700                          $extensions = $db->sql_fetchrowset($result);
 701                          $db->sql_freeresult($result);
 702  
 703                          if ($ext_group_row['max_filesize'] == 0)
 704                          {
 705                              $ext_group_row['max_filesize'] = (int) $config['max_filesize'];
 706                          }
 707  
 708                          $max_filesize = get_formatted_filesize($ext_group_row['max_filesize'], false, array('mb', 'kb', 'b'));
 709                          $size_format = $max_filesize['si_identifier'];
 710                          $ext_group_row['max_filesize'] = $max_filesize['value'];
 711  
 712                          $img_path = $config['upload_icons_path'];
 713  
 714                          $filename_list = '';
 715                          $no_image_select = false;
 716  
 717                          $imglist = filelist($phpbb_root_path . $img_path);
 718  
 719                          if (!empty($imglist['']))
 720                          {
 721                              $imglist = array_values($imglist);
 722                              $imglist = $imglist[0];
 723  
 724                              foreach ($imglist as $key => $img)
 725                              {
 726                                  if (!$ext_group_row['upload_icon'])
 727                                  {
 728                                      $no_image_select = true;
 729                                      $selected = '';
 730                                  }
 731                                  else
 732                                  {
 733                                      $selected = ($ext_group_row['upload_icon'] == $img) ? ' selected="selected"' : '';
 734                                  }
 735  
 736                                  if (strlen($img) > 255)
 737                                  {
 738                                      continue;
 739                                  }
 740  
 741                                  $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
 742                              }
 743                          }
 744  
 745                          $i = 0;
 746                          $assigned_extensions = '';
 747                          foreach ($extensions as $num => $row)
 748                          {
 749                              if ($row['group_id'] == $group_id && $group_id)
 750                              {
 751                                  $assigned_extensions .= ($i) ? ', ' . $row['extension'] : $row['extension'];
 752                                  $i++;
 753                              }
 754                          }
 755  
 756                          $s_extension_options = '';
 757                          foreach ($extensions as $row)
 758                          {
 759                              $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>';
 760                          }
 761  
 762                          $template->assign_vars(array(
 763                              'IMG_PATH'                => $img_path,
 764                              'ACTION'                => $action,
 765                              'GROUP_ID'                => $group_id,
 766                              'GROUP_NAME'            => $ext_group_row['group_name'],
 767                              'ALLOW_GROUP'            => $ext_group_row['allow_group'],
 768                              'ALLOW_IN_PM'            => $ext_group_row['allow_in_pm'],
 769                              'UPLOAD_ICON_SRC'        => $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'],
 770                              'EXTGROUP_FILESIZE'        => $ext_group_row['max_filesize'],
 771                              'ASSIGNED_EXTENSIONS'    => $assigned_extensions,
 772  
 773                              'S_CATEGORY_SELECT'            => $this->category_select('special_category', $group_id, 'category'),
 774                              'S_EXT_GROUP_SIZE_OPTIONS'    => size_select_options($size_format),
 775                              'S_EXTENSION_OPTIONS'        => $s_extension_options,
 776                              'S_FILENAME_LIST'            => $filename_list,
 777                              'S_EDIT_GROUP'                => true,
 778                              'S_NO_IMAGE'                => $no_image_select,
 779                              'S_FORUM_IDS'                => (count($forum_ids)) ? true : false,
 780  
 781                              'U_EXTENSIONS'        => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=extensions"),
 782                              'U_BACK'            => $this->u_action,
 783  
 784                              'L_LEGEND'            => $user->lang[strtoupper($action) . '_EXTENSION_GROUP'])
 785                          );
 786  
 787                          $s_forum_id_options = '';
 788  
 789                          /** @todo use in-built function **/
 790  
 791                          $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
 792                              FROM ' . FORUMS_TABLE . '
 793                              ORDER BY left_id ASC';
 794                          $result = $db->sql_query($sql, 600);
 795  
 796                          $right = $cat_right = $padding_inc = 0;
 797                          $padding = $forum_list = $holding = '';
 798                          $padding_store = array('0' => '');
 799  
 800                          while ($row = $db->sql_fetchrow($result))
 801                          {
 802                              if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
 803                              {
 804                                  // Non-postable forum with no subforums, don't display
 805                                  continue;
 806                              }
 807  
 808                              if (!$auth->acl_get('f_list', $row['forum_id']))
 809                              {
 810                                  // if the user does not have permissions to list this forum skip
 811                                  continue;
 812                              }
 813  
 814                              if ($row['left_id'] < $right)
 815                              {
 816                                  $padding .= '&nbsp; &nbsp;';
 817                                  $padding_store[$row['parent_id']] = $padding;
 818                              }
 819                              else if ($row['left_id'] > $right + 1)
 820                              {
 821                                  $padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']];
 822                              }
 823  
 824                              $right = $row['right_id'];
 825  
 826                              $selected = (in_array($row['forum_id'], $forum_ids)) ? ' selected="selected"' : '';
 827  
 828                              if ($row['left_id'] > $cat_right)
 829                              {
 830                                  // make sure we don't forget anything
 831                                  $s_forum_id_options .= $holding;
 832                                  $holding = '';
 833                              }
 834  
 835                              if ($row['right_id'] - $row['left_id'] > 1)
 836                              {
 837                                  $cat_right = max($cat_right, $row['right_id']);
 838  
 839                                  $holding .= '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
 840                              }
 841                              else
 842                              {
 843                                  $s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
 844                                  $holding = '';
 845                              }
 846                          }
 847  
 848                          if ($holding)
 849                          {
 850                              $s_forum_id_options .= $holding;
 851                          }
 852  
 853                          $db->sql_freeresult($result);
 854                          unset($padding_store);
 855  
 856                          $template->assign_vars(array(
 857                              'S_FORUM_ID_OPTIONS'    => $s_forum_id_options)
 858                          );
 859  
 860                      break;
 861                  }
 862  
 863                  $sql = 'SELECT *
 864                      FROM ' . EXTENSION_GROUPS_TABLE . '
 865                      ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
 866                  $result = $db->sql_query($sql);
 867  
 868                  $old_allow_group = $old_allow_pm = 1;
 869                  while ($row = $db->sql_fetchrow($result))
 870                  {
 871                      $s_add_spacer = ($old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm']) ? true : false;
 872  
 873                      $template->assign_block_vars('groups', array(
 874                          'S_ADD_SPACER'        => $s_add_spacer,
 875                          'S_ALLOWED_IN_PM'    => ($row['allow_in_pm']) ? true : false,
 876                          'S_GROUP_ALLOWED'    => ($row['allow_group']) ? true : false,
 877  
 878                          'U_EDIT'        => $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}",
 879                          'U_DELETE'        => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}",
 880  
 881                          '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'],
 882                          'CATEGORY'        => $cat_lang[$row['cat_id']],
 883                          )
 884                      );
 885  
 886                      $old_allow_group = $row['allow_group'];
 887                      $old_allow_pm = $row['allow_in_pm'];
 888                  }
 889                  $db->sql_freeresult($result);
 890  
 891              break;
 892  
 893              case 'orphan':
 894  
 895                  /* @var $pagination \phpbb\pagination */
 896                  $pagination = $this->phpbb_container->get('pagination');
 897  
 898                  if ($submit)
 899                  {
 900                      $delete_files = (isset($_POST['delete'])) ? array_keys($request->variable('delete', array('' => 0))) : array();
 901                      $add_files = (isset($_POST['add'])) ? array_keys($request->variable('add', array('' => 0))) : array();
 902                      $post_ids = $request->variable('post_id', array('' => 0));
 903  
 904                      if (count($delete_files))
 905                      {
 906                          $sql = 'SELECT *
 907                              FROM ' . ATTACHMENTS_TABLE . '
 908                              WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
 909                                  AND is_orphan = 1';
 910                          $result = $db->sql_query($sql);
 911  
 912                          $delete_files = array();
 913                          while ($row = $db->sql_fetchrow($result))
 914                          {
 915                              $this->attachment_manager->unlink($row['physical_filename'], 'file');
 916  
 917                              if ($row['thumbnail'])
 918                              {
 919                                  $this->attachment_manager->unlink($row['physical_filename'], 'thumbnail');
 920                              }
 921  
 922                              $delete_files[$row['attach_id']] = $row['real_filename'];
 923                          }
 924                          $db->sql_freeresult($result);
 925                      }
 926  
 927                      if (count($delete_files))
 928                      {
 929                          $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
 930                              WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
 931                          $db->sql_query($sql);
 932  
 933                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_ORPHAN_DEL', false, array(implode(', ', $delete_files)));
 934                          $notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode($user->lang['COMMA_SEPARATOR'], $delete_files));
 935                      }
 936  
 937                      $upload_list = array();
 938                      foreach ($add_files as $attach_id)
 939                      {
 940                          if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id]))
 941                          {
 942                              $upload_list[$attach_id] = $post_ids[$attach_id];
 943                          }
 944                      }
 945                      unset($add_files);
 946  
 947                      if (count($upload_list))
 948                      {
 949                          $template->assign_var('S_UPLOADING_FILES', true);
 950  
 951                          $sql = 'SELECT forum_id, forum_name
 952                              FROM ' . FORUMS_TABLE;
 953                          $result = $db->sql_query($sql);
 954  
 955                          $forum_names = array();
 956                          while ($row = $db->sql_fetchrow($result))
 957                          {
 958                              $forum_names[$row['forum_id']] = $row['forum_name'];
 959                          }
 960                          $db->sql_freeresult($result);
 961  
 962                          $sql = 'SELECT forum_id, topic_id, post_id, poster_id
 963                              FROM ' . POSTS_TABLE . '
 964                              WHERE ' . $db->sql_in_set('post_id', $upload_list);
 965                          $result = $db->sql_query($sql);
 966  
 967                          $post_info = array();
 968                          while ($row = $db->sql_fetchrow($result))
 969                          {
 970                              $post_info[$row['post_id']] = $row;
 971                          }
 972                          $db->sql_freeresult($result);
 973  
 974                          // Select those attachments we want to change...
 975                          $sql = 'SELECT *
 976                              FROM ' . ATTACHMENTS_TABLE . '
 977                              WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
 978                                  AND is_orphan = 1';
 979                          $result = $db->sql_query($sql);
 980  
 981                          $files_added = $space_taken = 0;
 982                          while ($row = $db->sql_fetchrow($result))
 983                          {
 984                              $post_row = $post_info[$upload_list[$row['attach_id']]];
 985  
 986                              $template->assign_block_vars('upload', array(
 987                                  'FILE_INFO'        => sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']),
 988                                  'S_DENIED'        => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? true : false,
 989                                  'L_DENIED'        => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : '')
 990                              );
 991  
 992                              if (!$auth->acl_get('f_attach', $post_row['forum_id']))
 993                              {
 994                                  continue;
 995                              }
 996  
 997                              // Adjust attachment entry
 998                              $sql_ary = array(
 999                                  'in_message'    => 0,
1000                                  'is_orphan'        => 0,
1001                                  'poster_id'        => $post_row['poster_id'],
1002                                  'post_msg_id'    => $post_row['post_id'],
1003                                  'topic_id'        => $post_row['topic_id'],
1004                              );
1005  
1006                              $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
1007                                  SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
1008                                  WHERE attach_id = ' . $row['attach_id'];
1009                              $db->sql_query($sql);
1010  
1011                              $sql = 'UPDATE ' . POSTS_TABLE . '
1012                                  SET post_attachment = 1
1013                                  WHERE post_id = ' . $post_row['post_id'];
1014                              $db->sql_query($sql);
1015  
1016                              $sql = 'UPDATE ' . TOPICS_TABLE . '
1017                                  SET topic_attachment = 1
1018                                  WHERE topic_id = ' . $post_row['topic_id'];
1019                              $db->sql_query($sql);
1020  
1021                              $space_taken += $row['filesize'];
1022                              $files_added++;
1023  
1024                              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_FILEUPLOAD', false, array($post_row['post_id'], $row['real_filename']));
1025                          }
1026                          $db->sql_freeresult($result);
1027  
1028                          if ($files_added)
1029                          {
1030                              $config->increment('upload_dir_size', $space_taken, false);
1031                              $config->increment('num_files', $files_added, false);
1032                          }
1033                      }
1034                  }
1035  
1036                  $template->assign_vars(array(
1037                      'S_ORPHAN'        => true)
1038                  );
1039  
1040                  $attachments_per_page = (int) $config['topics_per_page'];
1041  
1042                  // Get total number or orphans older than 3 hours
1043                  $sql = 'SELECT COUNT(attach_id) as num_files, SUM(filesize) as total_size
1044                      FROM ' . ATTACHMENTS_TABLE . '
1045                      WHERE is_orphan = 1
1046                          AND filetime < ' . (time() - 3*60*60);
1047                  $result = $this->db->sql_query($sql);
1048                  $row = $this->db->sql_fetchrow($result);
1049                  $num_files = (int) $row['num_files'];
1050                  $total_size = (int) $row['total_size'];
1051                  $this->db->sql_freeresult($result);
1052  
1053                  $start = $request->variable('start', 0);
1054                  $start = $pagination->validate_start($start, $attachments_per_page, $num_files);
1055  
1056                  // Just get the files with is_orphan set and older than 3 hours
1057                  $sql = 'SELECT *
1058                      FROM ' . ATTACHMENTS_TABLE . '
1059                      WHERE is_orphan = 1
1060                          AND filetime < ' . (time() - 3*60*60) . '
1061                      ORDER BY filetime DESC';
1062                  $result = $db->sql_query_limit($sql, $attachments_per_page, $start);
1063  
1064                  while ($row = $db->sql_fetchrow($result))
1065                  {
1066                      $template->assign_block_vars('orphan', array(
1067                          'FILESIZE'            => get_formatted_filesize($row['filesize']),
1068                          'FILETIME'            => $user->format_date($row['filetime']),
1069                          'REAL_FILENAME'        => utf8_basename($row['real_filename']),
1070                          'PHYSICAL_FILENAME'    => utf8_basename($row['physical_filename']),
1071                          'ATTACH_ID'            => $row['attach_id'],
1072                          'POST_IDS'            => (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
1073                          'U_FILE'            => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))
1074                      );
1075                  }
1076                  $db->sql_freeresult($result);
1077  
1078                  $pagination->generate_template_pagination(
1079                      $this->u_action,
1080                      'pagination',
1081                      'start',
1082                      $num_files,
1083                      $attachments_per_page,
1084                      $start
1085                  );
1086  
1087                  $template->assign_vars(array(
1088                      'TOTAL_FILES'        => $num_files,
1089                      'TOTAL_SIZE'        => get_formatted_filesize($total_size),
1090                  ));
1091  
1092              break;
1093  
1094              case 'manage':
1095  
1096                  if ($submit)
1097                  {
1098                      $delete_files = (isset($_POST['delete'])) ? array_keys($request->variable('delete', array('' => 0))) : array();
1099  
1100                      if (count($delete_files))
1101                      {
1102                          // Select those attachments we want to delete...
1103                          $sql = 'SELECT real_filename
1104                              FROM ' . ATTACHMENTS_TABLE . '
1105                              WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
1106                                  AND is_orphan = 0';
1107                          $result = $db->sql_query($sql);
1108                          while ($row = $db->sql_fetchrow($result))
1109                          {
1110                              $deleted_filenames[] = $row['real_filename'];
1111                          }
1112                          $db->sql_freeresult($result);
1113  
1114                          if ($num_deleted = $this->attachment_manager->delete('attach', $delete_files))
1115                          {
1116                              if (count($delete_files) != $num_deleted)
1117                              {
1118                                  $error[] = $user->lang['FILES_GONE'];
1119                              }
1120  
1121                              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACHMENTS_DELETED', false, array(implode(', ', $deleted_filenames)));
1122                              $notify[] = sprintf($user->lang['LOG_ATTACHMENTS_DELETED'], implode($user->lang['COMMA_SEPARATOR'], $deleted_filenames));
1123                          }
1124                          else
1125                          {
1126                              $error[] = $user->lang['NO_FILES_TO_DELETE'];
1127                          }
1128                      }
1129                  }
1130  
1131                  if ($action == 'stats')
1132                  {
1133                      $this->handle_stats_resync();
1134                  }
1135  
1136                  $stats_error = $this->check_stats_accuracy();
1137  
1138                  if ($stats_error)
1139                  {
1140                      $error[] = $stats_error;
1141                  }
1142  
1143                  $template->assign_vars(array(
1144                      'S_MANAGE'        => true,
1145                  ));
1146  
1147                  $start        = $request->variable('start', 0);
1148  
1149                  // Sort keys
1150                  $sort_days    = $request->variable('st', 0);
1151                  $sort_key    = $request->variable('sk', 't');
1152                  $sort_dir    = $request->variable('sd', 'd');
1153  
1154                  // Sorting
1155                  $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']);
1156                  $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']);
1157                  $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');
1158  
1159                  $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
1160                  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);
1161  
1162                  $min_filetime = ($sort_days) ? (time() - ($sort_days * 86400)) : '';
1163                  $limit_filetime = ($min_filetime) ? " AND a.filetime >= $min_filetime " : '';
1164                  $start = ($sort_days && isset($_POST['sort'])) ? 0 : $start;
1165  
1166                  $attachments_per_page = (int) $config['topics_per_page'];
1167  
1168                  $stats = $this->get_attachment_stats($limit_filetime);
1169                  $num_files = $stats['num_files'];
1170                  $total_size = $stats['upload_dir_size'];
1171  
1172                  // Make sure $start is set to the last page if it exceeds the amount
1173                  /* @var $pagination \phpbb\pagination */
1174                  $pagination = $phpbb_container->get('pagination');
1175                  $start = $pagination->validate_start($start, $attachments_per_page, $num_files);
1176  
1177                  // If the user is trying to reach the second half of the attachments list, fetch it starting from the end
1178                  $store_reverse = false;
1179                  $sql_limit = $attachments_per_page;
1180  
1181                  if ($start > $num_files / 2)
1182                  {
1183                      $store_reverse = true;
1184  
1185                      // Select the sort order. Add time sort anchor for non-time sorting cases
1186                      $sql_sort_anchor = ($sort_key != 't') ? ', a.filetime ' . (($sort_dir == 'd') ? 'ASC' : 'DESC') : '';
1187                      $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC') . $sql_sort_anchor;
1188                      $sql_limit = $pagination->reverse_limit($start, $sql_limit, $num_files);
1189                      $sql_start = $pagination->reverse_start($start, $sql_limit, $num_files);
1190                  }
1191                  else
1192                  {
1193                      // Select the sort order. Add time sort anchor for non-time sorting cases
1194                      $sql_sort_anchor = ($sort_key != 't') ? ', a.filetime ' . (($sort_dir == 'd') ? 'DESC' : 'ASC') : '';
1195                      $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC') . $sql_sort_anchor;
1196                      $sql_start = $start;
1197                  }
1198  
1199                  $attachments_list = array();
1200  
1201                  // Just get the files
1202                  $sql = 'SELECT a.*, u.username, u.user_colour, t.topic_title
1203                      FROM ' . ATTACHMENTS_TABLE . ' a
1204                      LEFT JOIN ' . USERS_TABLE . ' u ON (u.user_id = a.poster_id)
1205                      LEFT JOIN ' . TOPICS_TABLE . " t ON (a.topic_id = t.topic_id)
1206                      WHERE a.is_orphan = 0
1207                          $limit_filetime
1208                      ORDER BY $sql_sort_order";
1209                  $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
1210  
1211                  $i = ($store_reverse) ? $sql_limit - 1 : 0;
1212  
1213                  // Store increment value in a variable to save some conditional calls
1214                  $i_increment = ($store_reverse) ? -1 : 1;
1215                  while ($attachment_row = $db->sql_fetchrow($result))
1216                  {
1217                      $attachments_list[$i] = $attachment_row;
1218                      $i = $i + $i_increment;
1219                  }
1220                  $db->sql_freeresult($result);
1221  
1222                  $base_url = $this->u_action . "&amp;$u_sort_param";
1223                  $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_files, $attachments_per_page, $start);
1224  
1225                  $template->assign_vars(array(
1226                      'TOTAL_FILES'        => $num_files,
1227                      'TOTAL_SIZE'        => get_formatted_filesize($total_size),
1228  
1229                      'S_LIMIT_DAYS'        => $s_limit_days,
1230                      'S_SORT_KEY'        => $s_sort_key,
1231                      'S_SORT_DIR'        => $s_sort_dir)
1232                  );
1233  
1234                  // Grab extensions
1235                  $extensions = $cache->obtain_attach_extensions(true);
1236  
1237                  for ($i = 0, $end = count($attachments_list); $i < $end; ++$i)
1238                  {
1239                      $row = $attachments_list[$i];
1240  
1241                      $row['extension'] = strtolower(trim((string) $row['extension']));
1242                      $comment = ($row['attach_comment'] && !$row['in_message']) ? str_replace(array("\n", "\r"), array('<br />', "\n"), $row['attach_comment']) : '';
1243                      $display_cat = isset($extensions[$row['extension']]['display_cat']) ? $extensions[$row['extension']]['display_cat'] : ATTACHMENT_CATEGORY_NONE;
1244                      $l_downloaded_viewed = ($display_cat == ATTACHMENT_CATEGORY_NONE) ? 'DOWNLOAD_COUNTS' : 'VIEWED_COUNTS';
1245  
1246                      $template->assign_block_vars('attachments', array(
1247                          'ATTACHMENT_POSTER'    => get_username_string('full', (int) $row['poster_id'], (string) $row['username'], (string) $row['user_colour'], (string) $row['username']),
1248                          'FILESIZE'            => get_formatted_filesize((int) $row['filesize']),
1249                          'FILETIME'            => $user->format_date((int) $row['filetime']),
1250                          'REAL_FILENAME'        => utf8_basename((string) $row['real_filename']),
1251                          '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'],
1252                          'COMMENT'            => $comment,
1253                          'TOPIC_TITLE'        => (!$row['in_message']) ? (string) $row['topic_title'] : '',
1254                          'ATTACH_ID'            => (int) $row['attach_id'],
1255  
1256                          'L_DOWNLOAD_COUNT'    => $user->lang($l_downloaded_viewed, (int) $row['download_count']),
1257  
1258                          'S_IN_MESSAGE'        => (bool) $row['in_message'],
1259  
1260                          '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']}",
1261                          'U_FILE'            => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))
1262                      );
1263                  }
1264  
1265              break;
1266          }
1267  
1268          if (count($error))
1269          {
1270              $template->assign_vars(array(
1271                  'S_WARNING'        => true,
1272                  'WARNING_MSG'    => implode('<br />', $error))
1273              );
1274          }
1275  
1276          if (count($notify))
1277          {
1278              $template->assign_vars(array(
1279                  'S_NOTIFY'        => true,
1280                  'NOTIFY_MSG'    => implode('<br />', $notify))
1281              );
1282          }
1283      }
1284  
1285      /**
1286      * Get attachment file count and size of upload directory
1287      *
1288      * @param $limit string    Additional limit for WHERE clause to filter stats by.
1289      * @return array Returns array with stats: num_files and upload_dir_size
1290      */
1291  	public function get_attachment_stats($limit = '')
1292      {
1293          $sql = 'SELECT COUNT(a.attach_id) AS num_files, SUM(a.filesize) AS upload_dir_size
1294              FROM ' . ATTACHMENTS_TABLE . " a
1295              WHERE a.is_orphan = 0
1296                  $limit";
1297          $result = $this->db->sql_query($sql);
1298          $row = $this->db->sql_fetchrow($result);
1299          $this->db->sql_freeresult($result);
1300  
1301          return array(
1302              'num_files'            => (int) $row['num_files'],
1303              'upload_dir_size'    => (float) $row['upload_dir_size'],
1304          );
1305      }
1306  
1307      /**
1308      * Set config attachment stat values
1309      *
1310      * @param $stats array    Array of config key => value pairs to set.
1311      * @return null
1312      */
1313  	public function set_attachment_stats($stats)
1314      {
1315          foreach ($stats as $key => $value)
1316          {
1317              $this->config->set($key, $value, true);
1318          }
1319      }
1320  
1321      /**
1322      * Check accuracy of attachment statistics.
1323      *
1324      * @return bool|string    Returns false if stats are correct or error message
1325      *    otherwise.
1326      */
1327  	public function check_stats_accuracy()
1328      {
1329          // Get fresh stats.
1330          $stats = $this->get_attachment_stats();
1331  
1332          // Get current files stats
1333          $num_files = (int) $this->config['num_files'];
1334          $total_size = (float) $this->config['upload_dir_size'];
1335  
1336          if (($num_files != $stats['num_files']) || ($total_size != $stats['upload_dir_size']))
1337          {
1338              $u_resync = $this->u_action . '&amp;action=stats';
1339  
1340              return $this->user->lang(
1341                  'FILES_STATS_WRONG',
1342                  (int) $stats['num_files'],
1343                  get_formatted_filesize($stats['upload_dir_size']),
1344                  '<a href="' . $u_resync . '">',
1345                  '</a>'
1346              );
1347          }
1348          return false;
1349      }
1350  
1351      /**
1352      * Handle stats resync.
1353      *
1354      * @return null
1355      */
1356  	public function handle_stats_resync()
1357      {
1358          if (!confirm_box(true))
1359          {
1360              confirm_box(false, $this->user->lang['RESYNC_FILES_STATS_CONFIRM'], build_hidden_fields(array(
1361                  'i'            => $this->id,
1362                  'mode'        => 'manage',
1363                  'action'    => 'stats',
1364              )));
1365          }
1366          else
1367          {
1368              $this->set_attachment_stats($this->get_attachment_stats());
1369  
1370              /* @var $log \phpbb\log\log_interface */
1371              $log = $this->phpbb_container->get('log');
1372              $log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_RESYNC_FILES_STATS');
1373          }
1374  
1375      }
1376  
1377      /**
1378      * Build Select for category items
1379      */
1380  	function category_select($select_name, $group_id = false, $key = '')
1381      {
1382          global $db, $user;
1383  
1384          $types = array(
1385              ATTACHMENT_CATEGORY_NONE        => $user->lang['NO_FILE_CAT'],
1386              ATTACHMENT_CATEGORY_IMAGE        => $user->lang['CAT_IMAGES'],
1387          );
1388  
1389          if ($group_id)
1390          {
1391              $sql = 'SELECT cat_id
1392                  FROM ' . EXTENSION_GROUPS_TABLE . '
1393                  WHERE group_id = ' . (int) $group_id;
1394              $result = $db->sql_query($sql);
1395  
1396              $cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE : $row['cat_id'];
1397  
1398              $db->sql_freeresult($result);
1399          }
1400          else
1401          {
1402              $cat_type = ATTACHMENT_CATEGORY_NONE;
1403          }
1404  
1405          $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
1406  
1407          foreach ($types as $type => $mode)
1408          {
1409              $selected = ($type == $cat_type) ? ' selected="selected"' : '';
1410              $group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>';
1411          }
1412  
1413          $group_select .= '</select>';
1414  
1415          return $group_select;
1416      }
1417  
1418      /**
1419      * Extension group select
1420      */
1421  	function group_select($select_name, $default_group = false, $key = '')
1422      {
1423          global $db, $user;
1424  
1425          $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
1426  
1427          $sql = 'SELECT group_id, group_name
1428              FROM ' . EXTENSION_GROUPS_TABLE . '
1429              ORDER BY group_name';
1430          $result = $db->sql_query($sql);
1431  
1432          $group_name = array();
1433          while ($row = $db->sql_fetchrow($result))
1434          {
1435              $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'];
1436              $group_name[] = $row;
1437          }
1438          $db->sql_freeresult($result);
1439  
1440          $row['group_id'] = 0;
1441          $row['group_name'] = $user->lang['NOT_ASSIGNED'];
1442          $group_name[] = $row;
1443  
1444          for ($i = 0, $groups_size = count($group_name); $i < $groups_size; $i++)
1445          {
1446              if ($default_group === false)
1447              {
1448                  $selected = ($i == 0) ? ' selected="selected"' : '';
1449              }
1450              else
1451              {
1452                  $selected = ($group_name[$i]['group_id'] == $default_group) ? ' selected="selected"' : '';
1453              }
1454  
1455              $group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>';
1456          }
1457  
1458          $group_select .= '</select>';
1459  
1460          return $group_select;
1461      }
1462  
1463      /**
1464      * Test Settings
1465      */
1466  	function test_upload(&$error, $upload_dir, $create_directory = false)
1467      {
1468          global $user, $phpbb_root_path;
1469  
1470          // Does the target directory exist, is it a directory and writable.
1471          if ($create_directory)
1472          {
1473              if (!file_exists($phpbb_root_path . $upload_dir))
1474              {
1475                  @mkdir($phpbb_root_path . $upload_dir, 0777);
1476  
1477                  try
1478                  {
1479                      $this->filesystem->phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);
1480                  }
1481                  catch (\phpbb\filesystem\exception\filesystem_exception $e)
1482                  {
1483                      // Do nothing
1484                  }
1485              }
1486          }
1487  
1488          if (!file_exists($phpbb_root_path . $upload_dir))
1489          {
1490              $error[] = sprintf($user->lang['NO_UPLOAD_DIR'], $upload_dir);
1491              return;
1492          }
1493  
1494          if (!is_dir($phpbb_root_path . $upload_dir))
1495          {
1496              $error[] = sprintf($user->lang['UPLOAD_NOT_DIR'], $upload_dir);
1497              return;
1498          }
1499  
1500          if (!$this->filesystem->is_writable($phpbb_root_path . $upload_dir))
1501          {
1502              $error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
1503              return;
1504          }
1505      }
1506  
1507      /**
1508      * Perform operations on sites for external linking
1509      */
1510  	function perform_site_list()
1511      {
1512          global $db, $user, $request, $phpbb_log;
1513  
1514          if (isset($_REQUEST['securesubmit']))
1515          {
1516              // Grab the list of entries
1517              $ips = $request->variable('ips', '');
1518              $ip_list = array_unique(explode("\n", $ips));
1519              $ip_list_log = implode(', ', $ip_list);
1520  
1521              $ip_exclude = (int) $request->variable('ipexclude', false, false, \phpbb\request\request_interface::POST);
1522  
1523              $iplist = array();
1524              $hostlist = array();
1525  
1526              foreach ($ip_list as $item)
1527              {
1528                  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))
1529                  {
1530                      // Don't ask about all this, just don't ask ... !
1531                      $ip_1_counter = $ip_range_explode[1];
1532                      $ip_1_end = $ip_range_explode[5];
1533  
1534                      while ($ip_1_counter <= $ip_1_end)
1535                      {
1536                          $ip_2_counter = ($ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[2] : 0;
1537                          $ip_2_end = ($ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[6];
1538  
1539                          if ($ip_2_counter == 0 && $ip_2_end == 254)
1540                          {
1541                              $ip_2_counter = 256;
1542  
1543                              $iplist[] = "'$ip_1_counter.*'";
1544                          }
1545  
1546                          while ($ip_2_counter <= $ip_2_end)
1547                          {
1548                              $ip_3_counter = ($ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[3] : 0;
1549                              $ip_3_end = ($ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[7];
1550  
1551                              if ($ip_3_counter == 0 && $ip_3_end == 254)
1552                              {
1553                                  $ip_3_counter = 256;
1554  
1555                                  $iplist[] = "'$ip_1_counter.$ip_2_counter.*'";
1556                              }
1557  
1558                              while ($ip_3_counter <= $ip_3_end)
1559                              {
1560                                  $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;
1561                                  $ip_4_end = ($ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end) ? 254 : $ip_range_explode[8];
1562  
1563                                  if ($ip_4_counter == 0 && $ip_4_end == 254)
1564                                  {
1565                                      $ip_4_counter = 256;
1566  
1567                                      $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.*'";
1568                                  }
1569  
1570                                  while ($ip_4_counter <= $ip_4_end)
1571                                  {
1572                                      $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter'";
1573                                      $ip_4_counter++;
1574                                  }
1575                                  $ip_3_counter++;
1576                              }
1577                              $ip_2_counter++;
1578                          }
1579                          $ip_1_counter++;
1580                      }
1581                  }
1582                  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)))
1583                  {
1584                      $iplist[] = "'" . trim($item) . "'";
1585                  }
1586                  else if (preg_match('#^([\w\-_]\.?){2,}$#is', trim($item)))
1587                  {
1588                      $hostlist[] = "'" . trim($item) . "'";
1589                  }
1590                  else if (preg_match("#^([a-z0-9\-\*\._/]+?)$#is", trim($item)))
1591                  {
1592                      $hostlist[] = "'" . trim($item) . "'";
1593                  }
1594              }
1595  
1596              $sql = 'SELECT site_ip, site_hostname
1597                  FROM ' . SITELIST_TABLE . "
1598                  WHERE ip_exclude = $ip_exclude";
1599              $result = $db->sql_query($sql);
1600  
1601              if ($row = $db->sql_fetchrow($result))
1602              {
1603                  $iplist_tmp = array();
1604                  $hostlist_tmp = array();
1605                  do
1606                  {
1607                      if ($row['site_ip'])
1608                      {
1609                          if (strlen($row['site_ip']) > 40)
1610                          {
1611                              continue;
1612                          }
1613  
1614                          $iplist_tmp[] = "'" . $row['site_ip'] . "'";
1615                      }
1616                      else if ($row['site_hostname'])
1617                      {
1618                          if (strlen($row['site_hostname']) > 255)
1619                          {
1620                              continue;
1621                          }
1622  
1623                          $hostlist_tmp[] = "'" . $row['site_hostname'] . "'";
1624                      }
1625                      // break;
1626                  }
1627                  while ($row = $db->sql_fetchrow($result));
1628  
1629                  $iplist = array_unique(array_diff($iplist, $iplist_tmp));
1630                  $hostlist = array_unique(array_diff($hostlist, $hostlist_tmp));
1631                  unset($iplist_tmp);
1632                  unset($hostlist_tmp);
1633              }
1634              $db->sql_freeresult($result);
1635  
1636              if (count($iplist))
1637              {
1638                  foreach ($iplist as $ip_entry)
1639                  {
1640                      $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_ip, ip_exclude)
1641                          VALUES ($ip_entry, $ip_exclude)";
1642                      $db->sql_query($sql);
1643                  }
1644              }
1645  
1646              if (count($hostlist))
1647              {
1648                  foreach ($hostlist as $host_entry)
1649                  {
1650                      $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_hostname, ip_exclude)
1651                          VALUES ($host_entry, $ip_exclude)";
1652                      $db->sql_query($sql);
1653                  }
1654              }
1655  
1656              if (!empty($ip_list_log))
1657              {
1658                  // Update log
1659                  $log_entry = ($ip_exclude) ? 'LOG_DOWNLOAD_EXCLUDE_IP' : 'LOG_DOWNLOAD_IP';
1660                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log_entry, false, array($ip_list_log));
1661              }
1662  
1663              trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
1664          }
1665          else if (isset($_POST['unsecuresubmit']))
1666          {
1667              $unip_sql = $request->variable('unip', array(0));
1668  
1669              if (count($unip_sql))
1670              {
1671                  $l_unip_list = '';
1672  
1673                  // Grab details of ips for logging information later
1674                  $sql = 'SELECT site_ip, site_hostname
1675                      FROM ' . SITELIST_TABLE . '
1676                      WHERE ' . $db->sql_in_set('site_id', $unip_sql);
1677                  $result = $db->sql_query($sql);
1678  
1679                  while ($row = $db->sql_fetchrow($result))
1680                  {
1681                      $l_unip_list .= (($l_unip_list != '') ? ', ' : '') . (($row['site_ip']) ? $row['site_ip'] : $row['site_hostname']);
1682                  }
1683                  $db->sql_freeresult($result);
1684  
1685                  $sql = 'DELETE FROM ' . SITELIST_TABLE . '
1686                      WHERE ' . $db->sql_in_set('site_id', $unip_sql);
1687                  $db->sql_query($sql);
1688  
1689                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DOWNLOAD_REMOVE_IP', false, array($l_unip_list));
1690              }
1691  
1692              trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
1693          }
1694      }
1695  
1696      /**
1697      * Write display_order config field
1698      */
1699  	function display_order($value, $key = '')
1700      {
1701          $radio_ary = array(0 => 'DESCENDING', 1 => 'ASCENDING');
1702  
1703          return h_radio('config[display_order]', $radio_ary, $value, $key);
1704      }
1705  
1706      /**
1707      * Adjust all three max_filesize config vars for display
1708      */
1709  	function max_filesize($value, $key = '')
1710      {
1711          // Determine size var and adjust the value accordingly
1712          $filesize = get_formatted_filesize($value, false, array('mb', 'kb', 'b'));
1713          $size_var = $filesize['si_identifier'];
1714          $value = $filesize['value'];
1715  
1716          // size and maxlength must not be specified for input of type number
1717          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>';
1718      }
1719  
1720      /**
1721      * Write secure_allow_deny config field
1722      */
1723  	function select_allow_deny($value, $key = '')
1724      {
1725          $radio_ary = array(1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW');
1726  
1727          return h_radio('config[' . $key . ']', $radio_ary, $value, $key);
1728      }
1729  
1730  }


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