Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

acp_attachments.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 43.54 KiB


 0001  <?php
 0002  /**
 0003  *
 0004  * @package acp
 0005  * @version $Id$
 0006  * @copyright (c) 2005 phpBB Group
 0007  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 0008  *
 0009  */
 0010   
 0011  /**
 0012  * @ignore
 0013  */
 0014  if (!defined('IN_PHPBB'))
 0015  {
 0016      exit;
 0017  }
 0018   
 0019  /**
 0020  * @package acp
 0021  */
 0022  class acp_attachments
 0023  {
 0024      var $u_action;
 0025      var $new_config;
 0026      
 0027      function main($id, $mode)
 0028      {
 0029          global $db, $user, $auth, $template, $cache;
 0030          global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
 0031   
 0032          $user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
 0033   
 0034          $error = $notify = array();
 0035          $submit = (isset($_POST['submit'])) ? true : false;
 0036          $action = request_var('action', '');
 0037   
 0038          $form_key = 'acp_attach';
 0039          add_form_key($form_key);
 0040   
 0041          if ($submit && !check_form_key($form_key))
 0042          {
 0043              trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 0044          }
 0045   
 0046          switch ($mode)
 0047          {
 0048              case 'attach':
 0049                  $l_title = 'ACP_ATTACHMENT_SETTINGS';
 0050              break;
 0051   
 0052              case 'extensions':
 0053                  $l_title = 'ACP_MANAGE_EXTENSIONS';
 0054              break;
 0055   
 0056              case 'ext_groups':
 0057                  $l_title = 'ACP_EXTENSION_GROUPS';
 0058              break;
 0059      
 0060              case 'orphan':
 0061                  $l_title = 'ACP_ORPHAN_ATTACHMENTS';
 0062              break;
 0063   
 0064              default:
 0065                  trigger_error('NO_MODE', E_USER_ERROR);
 0066              break;
 0067          }
 0068   
 0069          $this->tpl_name = 'acp_attachments';
 0070          $this->page_title = $l_title;
 0071   
 0072          $template->assign_vars(array(
 0073              'L_TITLE'            => $user->lang[$l_title],
 0074              'L_TITLE_EXPLAIN'    => $user->lang[$l_title . '_EXPLAIN'],
 0075              'U_ACTION'            => $this->u_action)
 0076          );
 0077   
 0078          switch ($mode)
 0079          {
 0080              case 'attach':
 0081   
 0082                  include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 0083   
 0084                  $sql = 'SELECT group_name, cat_id
 0085                      FROM ' . EXTENSION_GROUPS_TABLE . '
 0086                      WHERE cat_id > 0
 0087                      ORDER BY cat_id';
 0088                  $result = $db->sql_query($sql);
 0089   
 0090                  $s_assigned_groups = array();
 0091                  while ($row = $db->sql_fetchrow($result))
 0092                  {
 0093                      $s_assigned_groups[$row['cat_id']][] = $row['group_name'];
 0094                  }
 0095                  $db->sql_freeresult($result);
 0096   
 0097                  $l_legend_cat_images = $user->lang['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang['ASSIGNED_GROUP'] . ': ' . ((!empty($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE])) ? implode(', ', $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) : $user->lang['NO_EXT_GROUP']) . ']';
 0098   
 0099                  $display_vars = array(
 0100                      'title'    => 'ACP_ATTACHMENT_SETTINGS',
 0101                      'vars'    => array(
 0102                          'img_max_width' => false, 'img_max_height' => false, 'img_link_width' => false, 'img_link_height' => false,
 0103   
 0104                          'legend1'                => 'ACP_ATTACHMENT_SETTINGS',
 0105                          'allow_attachments'        => array('lang' => 'ALLOW_ATTACHMENTS',        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => false),
 0106                          'allow_pm_attach'        => array('lang' => 'ALLOW_PM_ATTACHMENTS',    'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => false),
 0107                          'upload_path'            => array('lang' => 'UPLOAD_DIR',            'validate' => 'wpath',    'type' => 'text:25:100', 'explain' => true),
 0108                          'display_order'            => array('lang' => 'DISPLAY_ORDER',            'validate' => 'bool',    'type' => 'custom', 'method' => 'display_order', 'explain' => true),
 0109                          'attachment_quota'        => array('lang' => 'ATTACH_QUOTA',            'validate' => 'string',    'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
 0110                          'max_filesize'            => array('lang' => 'ATTACH_MAX_FILESIZE',    'validate' => 'string',    'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
 0111                          'max_filesize_pm'        => array('lang' => 'ATTACH_MAX_PM_FILESIZE','validate' => 'string',    'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
 0112                          'max_attachments'        => array('lang' => 'MAX_ATTACHMENTS',        'validate' => 'int',    'type' => 'text:3:3', 'explain' => false),
 0113                          'max_attachments_pm'    => array('lang' => 'MAX_ATTACHMENTS_PM',    'validate' => 'int',    'type' => 'text:3:3', 'explain' => false),
 0114                          'secure_downloads'        => array('lang' => 'SECURE_DOWNLOADS',        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
 0115                          'secure_allow_deny'        => array('lang' => 'SECURE_ALLOW_DENY',        'validate' => 'int',    'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),
 0116                          'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
 0117   
 0118                          'legend2'                    => $l_legend_cat_images,
 0119                          'img_display_inlined'        => array('lang' => 'DISPLAY_INLINED',        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
 0120                          'img_create_thumbnail'        => array('lang' => 'CREATE_THUMBNAIL',        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
 0121                          'img_max_thumb_width'        => array('lang' => 'MAX_THUMB_WIDTH',        'validate' => 'int',    'type' => 'text:7:15', 'explain' => true, 'append' => ' px'),
 0122                          'img_min_thumb_filesize'    => array('lang' => 'MIN_THUMB_FILESIZE',    'validate' => 'int',    'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
 0123                          'img_imagick'                => array('lang' => 'IMAGICK_PATH',            'validate' => 'string',    'type' => 'text:20:200', 'explain' => true, 'append' => '&nbsp;&nbsp;<span>[ <a href="' . $this->u_action . '&amp;action=imgmagick">' . $user->lang['SEARCH_IMAGICK'] . '</a> ]</span>'),
 0124                          'img_max'                    => array('lang' => 'MAX_IMAGE_SIZE',        'validate' => 'int',    'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
 0125                          'img_link'                    => array('lang' => 'IMAGE_LINK_SIZE',        'validate' => 'int',    'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
 0126                      )
 0127                  );
 0128   
 0129                  $this->new_config = $config;
 0130                  $cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => '')) : $this->new_config;
 0131                  $error = array();
 0132   
 0133                  // We validate the complete config if whished
 0134                  validate_config_vars($display_vars['vars'], $cfg_array, $error);
 0135   
 0136                  // Do not write values if there is an error
 0137                  if (sizeof($error))
 0138                  {
 0139                      $submit = false;
 0140                  }
 0141   
 0142                  // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
 0143                  foreach ($display_vars['vars'] as $config_name => $null)
 0144                  {
 0145                      if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
 0146                      {
 0147                          continue;
 0148                      }
 0149   
 0150                      $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
 0151   
 0152                      if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm')))
 0153                      {
 0154                          $size_var = request_var($config_name, '');
 0155                          $this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
 0156                      }
 0157   
 0158                      if ($submit)
 0159                      {
 0160                          set_config($config_name, $config_value);
 0161                      }
 0162                  }
 0163   
 0164                  $this->perform_site_list();
 0165   
 0166                  if ($submit)
 0167                  {
 0168                      add_log('admin', 'LOG_CONFIG_ATTACH');
 0169   
 0170                      // Check Settings
 0171                      $this->test_upload($error, $this->new_config['upload_path'], false);
 0172   
 0173                      if (!sizeof($error))
 0174                      {
 0175                          trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
 0176                      }
 0177                  }
 0178   
 0179                  $template->assign_var('S_ATTACHMENT_SETTINGS', true);
 0180   
 0181                  if ($action == 'imgmagick')
 0182                  {
 0183                      $this->new_config['img_imagick'] = $this->search_imagemagick();
 0184                  }
 0185   
 0186                  // We strip eventually manual added convert program, we only want the patch
 0187                  $this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']);
 0188   
 0189                  $supported_types = get_supported_image_types();
 0190   
 0191                  // Check Thumbnail Support
 0192                  if (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format'])))
 0193                  {
 0194                      $this->new_config['img_create_thumbnail'] = 0;
 0195                  }
 0196   
 0197                  $template->assign_vars(array(
 0198                      'U_SEARCH_IMAGICK'        => $this->u_action . '&amp;action=imgmagick',
 0199                      'S_THUMBNAIL_SUPPORT'    => (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format']))) ? false : true)
 0200                  );
 0201   
 0202                  // Secure Download Options - Same procedure as with banning
 0203                  $allow_deny = ($this->new_config['secure_allow_deny']) ? 'ALLOWED' : 'DISALLOWED';
 0204          
 0205                  $sql = 'SELECT *
 0206                      FROM ' . SITELIST_TABLE;
 0207                  $result = $db->sql_query($sql);
 0208   
 0209                  $defined_ips = '';
 0210                  $ips = array();
 0211   
 0212                  while ($row = $db->sql_fetchrow($result))
 0213                  {
 0214                      $value = ($row['site_ip']) ? $row['site_ip'] : $row['site_hostname'];
 0215                      if ($value)
 0216                      {
 0217                          $defined_ips .= '<option' . (($row['ip_exclude']) ? ' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>';
 0218                          $ips[$row['site_id']] = $value;
 0219                      }
 0220                  }
 0221                  $db->sql_freeresult($result);
 0222   
 0223                  $template->assign_vars(array(
 0224                      'S_SECURE_DOWNLOADS'    => $this->new_config['secure_downloads'],
 0225                      'S_DEFINED_IPS'            => ($defined_ips != '') ? true : false,
 0226                      'S_WARNING'                => (sizeof($error)) ? true : false,
 0227   
 0228                      'WARNING_MSG'            => implode('<br />', $error),
 0229                      'DEFINED_IPS'            => $defined_ips,
 0230   
 0231                      'L_SECURE_TITLE'        => $user->lang['DEFINE_' . $allow_deny . '_IPS'],
 0232                      'L_IP_EXCLUDE'            => $user->lang['EXCLUDE_FROM_' . $allow_deny . '_IP'],
 0233                      'L_REMOVE_IPS'            => $user->lang['REMOVE_' . $allow_deny . '_IPS'])
 0234                  );
 0235   
 0236                  // Output relevant options
 0237                  foreach ($display_vars['vars'] as $config_key => $vars)
 0238                  {
 0239                      if (!is_array($vars) && strpos($config_key, 'legend') === false)
 0240                      {
 0241                          continue;
 0242                      }
 0243   
 0244                      if (strpos($config_key, 'legend') !== false)
 0245                      {
 0246                          $template->assign_block_vars('options', array(
 0247                              'S_LEGEND'        => true,
 0248                              'LEGEND'        => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
 0249                          );
 0250   
 0251                          continue;
 0252                      }
 0253   
 0254                      $type = explode(':', $vars['type']);
 0255   
 0256                      $l_explain = '';
 0257                      if ($vars['explain'] && isset($vars['lang_explain']))
 0258                      {
 0259                          $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
 0260                      }
 0261                      else if ($vars['explain'])
 0262                      {
 0263                          $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
 0264                      }
 0265   
 0266                      $template->assign_block_vars('options', array(
 0267                          'KEY'            => $config_key,
 0268                          'TITLE'            => $user->lang[$vars['lang']],
 0269                          'S_EXPLAIN'        => $vars['explain'],
 0270                          'TITLE_EXPLAIN'    => $l_explain,
 0271                          'CONTENT'        => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars),
 0272                          )
 0273                      );
 0274          
 0275                      unset($display_vars['vars'][$config_key]);
 0276                  }
 0277   
 0278              break;
 0279   
 0280              case 'extensions':
 0281   
 0282                  if ($submit || isset($_POST['add_extension_check']))
 0283                  {
 0284                      if ($submit)
 0285                      {
 0286                          // Change Extensions ?
 0287                          $extension_change_list    = request_var('extension_change_list', array(0));
 0288                          $group_select_list        = request_var('group_select', array(0));
 0289   
 0290                          // Generate correct Change List
 0291                          $extensions = array();
 0292   
 0293                          for ($i = 0, $size = sizeof($extension_change_list); $i < $size; $i++)
 0294                          {
 0295                              $extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i];
 0296                          }
 0297   
 0298                          $sql = 'SELECT *
 0299                              FROM ' . EXTENSIONS_TABLE . '
 0300                              ORDER BY extension_id';
 0301                          $result = $db->sql_query($sql);
 0302   
 0303                          while ($row = $db->sql_fetchrow($result))
 0304                          {
 0305                              if ($row['group_id'] != $extensions[$row['extension_id']]['group_id'])
 0306                              {
 0307                                  $sql = 'UPDATE ' . EXTENSIONS_TABLE . '
 0308                                      SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . '
 0309                                      WHERE extension_id = ' . $row['extension_id'];
 0310                                  $db->sql_query($sql);
 0311   
 0312                                  add_log('admin', 'LOG_ATTACH_EXT_UPDATE', $row['extension']);
 0313                              }
 0314                          }
 0315                          $db->sql_freeresult($result);
 0316   
 0317                          // Delete Extension?
 0318                          $extension_id_list = request_var('extension_id_list', array(0));
 0319   
 0320                          if (sizeof($extension_id_list))
 0321                          {
 0322                              $sql = 'SELECT extension
 0323                                  FROM ' . EXTENSIONS_TABLE . '
 0324                                  WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
 0325                              $result = $db->sql_query($sql);
 0326                              
 0327                              $extension_list = '';
 0328                              while ($row = $db->sql_fetchrow($result))
 0329                              {
 0330                                  $extension_list .= ($extension_list == '') ? $row['extension'] : ', ' . $row['extension'];
 0331                              }
 0332                              $db->sql_freeresult($result);
 0333   
 0334                              $sql = 'DELETE
 0335                                  FROM ' . EXTENSIONS_TABLE . '
 0336                                  WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
 0337                              $db->sql_query($sql);
 0338   
 0339                              add_log('admin', 'LOG_ATTACH_EXT_DEL', $extension_list);
 0340                          }
 0341                      }
 0342   
 0343                      // Add Extension?
 0344                      $add_extension            = strtolower(request_var('add_extension', ''));
 0345                      $add_extension_group    = request_var('add_group_select', 0);
 0346                      $add                    = (isset($_POST['add_extension_check'])) ? true : false;
 0347   
 0348                      if ($add_extension && $add)
 0349                      {
 0350                          if (!sizeof($error))
 0351                          {
 0352                              $sql = 'SELECT extension_id
 0353                                  FROM ' . EXTENSIONS_TABLE . "
 0354                                  WHERE extension = '" . $db->sql_escape($add_extension) . "'";
 0355                              $result = $db->sql_query($sql);
 0356                              
 0357                              if ($row = $db->sql_fetchrow($result))
 0358                              {
 0359                                  $error[] = sprintf($user->lang['EXTENSION_EXIST'], $add_extension);
 0360                              }
 0361                              $db->sql_freeresult($result);
 0362   
 0363                              if (!sizeof($error))
 0364                              {
 0365                                  $sql_ary = array(
 0366                                      'group_id'    =>    $add_extension_group,
 0367                                      'extension'    =>    $add_extension
 0368                                  );
 0369   
 0370                                  $db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
 0371                                  add_log('admin', 'LOG_ATTACH_EXT_ADD', $add_extension);
 0372                              }
 0373                          }
 0374                      }
 0375   
 0376                      if (!sizeof($error))
 0377                      {
 0378                          $notify[] = $user->lang['EXTENSIONS_UPDATED'];
 0379                      }
 0380   
 0381                      $cache->destroy('_extensions');
 0382                  }
 0383   
 0384                  $template->assign_vars(array(
 0385                      'S_EXTENSIONS'            => true,
 0386                      'ADD_EXTENSION'            => (isset($add_extension)) ? $add_extension : '',
 0387                      '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'))
 0388                  );
 0389   
 0390                  $sql = 'SELECT *
 0391                      FROM ' . EXTENSIONS_TABLE . '
 0392                      ORDER BY group_id, extension';
 0393                  $result = $db->sql_query($sql);
 0394   
 0395                  if ($row = $db->sql_fetchrow($result))
 0396                  {
 0397                      $old_group_id = $row['group_id'];
 0398                      do
 0399                      {
 0400                          $s_spacer = false;
 0401   
 0402                          $current_group_id = $row['group_id'];
 0403                          if ($old_group_id != $current_group_id)
 0404                          {
 0405                              $s_spacer = true;
 0406                              $old_group_id = $current_group_id;
 0407                          }
 0408   
 0409                          $template->assign_block_vars('extensions', array(
 0410                              'S_SPACER'        => $s_spacer,
 0411                              'EXTENSION_ID'    => $row['extension_id'],
 0412                              'EXTENSION'        => $row['extension'],
 0413                              'GROUP_OPTIONS'    => $this->group_select('group_select[]', $row['group_id']))
 0414                          );
 0415                      }
 0416                      while ($row = $db->sql_fetchrow($result));
 0417                  }
 0418                  $db->sql_freeresult($result);
 0419   
 0420              break;
 0421   
 0422              case 'ext_groups':
 0423   
 0424                  $template->assign_var('S_EXTENSION_GROUPS', true);
 0425   
 0426                  if ($submit)
 0427                  {
 0428                      $action = request_var('action', '');
 0429                      $group_id = request_var('g', 0);
 0430   
 0431                      if ($action != 'add' && $action != 'edit')
 0432                      {
 0433                          trigger_error('NO_MODE', E_USER_ERROR);
 0434                      }
 0435   
 0436                      if (!$group_id && $action == 'edit')
 0437                      {
 0438                          trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
 0439                      }
 0440   
 0441                      if ($group_id)
 0442                      {
 0443                          $sql = 'SELECT *
 0444                              FROM ' . EXTENSION_GROUPS_TABLE . "
 0445                              WHERE group_id = $group_id";
 0446                          $result = $db->sql_query($sql);
 0447                          $ext_row = $db->sql_fetchrow($result);
 0448                          $db->sql_freeresult($result);
 0449   
 0450                          if (!$ext_row)
 0451                          {
 0452                              trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
 0453                          }
 0454                      }
 0455                      else
 0456                      {
 0457                          $ext_row = array();
 0458                      }
 0459   
 0460                      $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
 0461                      $new_group_name = ($action == 'add') ? $group_name : (($ext_row['group_name'] != $group_name) ? $group_name : '');
 0462   
 0463                      if (!$group_name)
 0464                      {
 0465                          $error[] = $user->lang['NO_EXT_GROUP_NAME'];
 0466                      }
 0467   
 0468                      // Check New Group Name
 0469                      if ($new_group_name)
 0470                      {
 0471                          $sql = 'SELECT group_id
 0472                              FROM ' . EXTENSION_GROUPS_TABLE . "
 0473                              WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";
 0474                          $result = $db->sql_query($sql);
 0475   
 0476                          if ($db->sql_fetchrow($result))
 0477                          {
 0478                              $error[] = sprintf($user->lang['EXTENSION_GROUP_EXIST'], $new_group_name);
 0479                          }
 0480                          $db->sql_freeresult($result);
 0481                      }
 0482   
 0483                      if (!sizeof($error))
 0484                      {
 0485                          // Ok, build the update/insert array
 0486                          $upload_icon    = request_var('upload_icon', 'no_image');
 0487                          $size_select    = request_var('size_select', 'b');
 0488                          $forum_select    = request_var('forum_select', false);
 0489                          $allowed_forums    = request_var('allowed_forums', array(0));
 0490                          $allow_in_pm    = (isset($_POST['allow_in_pm'])) ? true : false;
 0491                          $max_filesize    = request_var('max_filesize', 0);
 0492                          $max_filesize    = ($size_select == 'kb') ? round($max_filesize * 1024) : (($size_select == 'mb') ? round($max_filesize * 1048576) : $max_filesize);
 0493                          $allow_group    = (isset($_POST['allow_group'])) ? true : false;
 0494   
 0495                          if ($max_filesize == $config['max_filesize'])
 0496                          {
 0497                              $max_filesize = 0;
 0498                          }
 0499   
 0500                          if (!sizeof($allowed_forums))
 0501                          {
 0502                              $forum_select = false;
 0503                          }
 0504   
 0505                          $group_ary = array(
 0506                              'group_name'    => $group_name,
 0507                              'cat_id'        => request_var('special_category', ATTACHMENT_CATEGORY_NONE),
 0508                              'allow_group'    => ($allow_group) ? 1 : 0,
 0509                              'upload_icon'    => ($upload_icon == 'no_image') ? '' : $upload_icon,
 0510                              'max_filesize'    => $max_filesize,
 0511                              'allowed_forums'=> ($forum_select) ? serialize($allowed_forums) : '',
 0512                              'allow_in_pm'    => ($allow_in_pm) ? 1 : 0,
 0513                          );
 0514   
 0515                          if ($action == 'add')
 0516                          {
 0517                              $group_ary['download_mode'] = INLINE_LINK;
 0518                          }
 0519   
 0520                          $sql = ($action == 'add') ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ';
 0521                          $sql .= $db->sql_build_array((($action == 'add') ? 'INSERT' : 'UPDATE'), $group_ary);
 0522                          $sql .= ($action == 'edit') ? " WHERE group_id = $group_id" : '';
 0523   
 0524                          $db->sql_query($sql);
 0525   
 0526                          if ($action == 'add')
 0527                          {
 0528                              $group_id = $db->sql_nextid();
 0529                          }
 0530   
 0531                          add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name);
 0532                      }
 0533   
 0534                      $extension_list = request_var('extensions', array(0));
 0535   
 0536                      if ($action == 'edit' && sizeof($extension_list))
 0537                      {
 0538                          $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
 0539                              SET group_id = 0
 0540                              WHERE group_id = $group_id";
 0541                          $db->sql_query($sql);
 0542                      }
 0543   
 0544                      if (sizeof($extension_list))
 0545                      {
 0546                          $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
 0547                              SET group_id = $group_id
 0548                              WHERE " . $db->sql_in_set('extension_id', $extension_list);
 0549                          $db->sql_query($sql);
 0550                      }
 0551   
 0552                      $cache->destroy('_extensions');
 0553   
 0554                      if (!sizeof($error))
 0555                      {
 0556                          $notify[] = $user->lang['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)];
 0557                      }
 0558                  }
 0559   
 0560                  $cat_lang = array(
 0561                      ATTACHMENT_CATEGORY_NONE        => $user->lang['NO_FILE_CAT'],
 0562                      ATTACHMENT_CATEGORY_IMAGE        => $user->lang['CAT_IMAGES'],
 0563                      ATTACHMENT_CATEGORY_WM            => $user->lang['CAT_WM_FILES'],
 0564                      ATTACHMENT_CATEGORY_RM            => $user->lang['CAT_RM_FILES'],
 0565                      ATTACHMENT_CATEGORY_FLASH        => $user->lang['CAT_FLASH_FILES'],
 0566                      ATTACHMENT_CATEGORY_QUICKTIME    => $user->lang['CAT_QUICKTIME_FILES'],
 0567                  );
 0568   
 0569                  $group_id = request_var('g', 0);
 0570                  $action = (isset($_POST['add'])) ? 'add' : $action;
 0571   
 0572                  switch ($action)
 0573                  {
 0574                      case 'delete':
 0575   
 0576                          if (confirm_box(true))
 0577                          {
 0578                              $sql = 'SELECT group_name
 0579                                  FROM ' . EXTENSION_GROUPS_TABLE . "
 0580                                  WHERE group_id = $group_id";
 0581                              $result = $db->sql_query($sql);
 0582                              $group_name = (string) $db->sql_fetchfield('group_name');
 0583                              $db->sql_freeresult($result);
 0584   
 0585                              $sql = 'DELETE
 0586                                  FROM ' . EXTENSION_GROUPS_TABLE . "
 0587                                  WHERE group_id = $group_id";
 0588                              $db->sql_query($sql);
 0589   
 0590                              // Set corresponding Extensions to a pending Group
 0591                              $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
 0592                                  SET group_id = 0
 0593                                  WHERE group_id = $group_id";
 0594                              $db->sql_query($sql);
 0595                      
 0596                              add_log('admin', 'LOG_ATTACH_EXTGROUP_DEL', $group_name);
 0597   
 0598                              $cache->destroy('_extensions');
 0599   
 0600                              trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action));
 0601                          }
 0602                          else
 0603                          {
 0604                              confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 0605                                  'i'            => $id,
 0606                                  'mode'        => $mode,
 0607                                  'group_id'    => $group_id,
 0608                                  'action'    => 'delete',
 0609                              )));
 0610                          }
 0611   
 0612                      break;
 0613   
 0614                      case 'edit':
 0615   
 0616                          if (!$group_id)
 0617                          {
 0618                              trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
 0619                          }
 0620   
 0621                          $sql = 'SELECT *
 0622                              FROM ' . EXTENSION_GROUPS_TABLE . "
 0623                              WHERE group_id = $group_id";
 0624                          $result = $db->sql_query($sql);
 0625                          $ext_group_row = $db->sql_fetchrow($result);
 0626                          $db->sql_freeresult($result);
 0627   
 0628                          $forum_ids = (!$ext_group_row['allowed_forums']) ? array() : unserialize(trim($ext_group_row['allowed_forums']));
 0629   
 0630                      // no break;
 0631   
 0632                      case 'add':
 0633   
 0634                          if ($action == 'add')
 0635                          {
 0636                              $ext_group_row = array(
 0637                                  'group_name'    => utf8_normalize_nfc(request_var('group_name', '', true)),
 0638                                  'cat_id'        => 0,
 0639                                  'allow_group'    => 1,
 0640                                  'allow_in_pm'    => 1,
 0641                                  'upload_icon'    => '',
 0642                                  'max_filesize'    => 0,
 0643                              );
 0644   
 0645                              $forum_ids = array();
 0646                          }
 0647   
 0648                          $extensions = array();
 0649   
 0650                          $sql = 'SELECT *
 0651                              FROM ' . EXTENSIONS_TABLE . "
 0652                              WHERE group_id = $group_id
 0653                                  OR group_id = 0
 0654                              ORDER BY extension";
 0655                          $result = $db->sql_query($sql);
 0656                          $extensions = $db->sql_fetchrowset($result);
 0657                          $db->sql_freeresult($result);
 0658   
 0659                          if ($ext_group_row['max_filesize'] == 0)
 0660                          {
 0661                              $ext_group_row['max_filesize'] = (int) $config['max_filesize'];
 0662                          }
 0663   
 0664                          $size_format = ($ext_group_row['max_filesize'] >= 1048576) ? 'mb' : (($ext_group_row['max_filesize'] >= 1024) ? 'kb' : 'b');
 0665   
 0666                          $ext_group_row['max_filesize'] = ($ext_group_row['max_filesize'] >= 1048576) ? round($ext_group_row['max_filesize'] / 1048576 * 100) / 100 : (($ext_group_row['max_filesize'] >= 1024) ? round($ext_group_row['max_filesize'] / 1024 * 100) / 100 : $ext_group_row['max_filesize']);
 0667   
 0668                          $img_path = $config['upload_icons_path'];
 0669   
 0670                          $filename_list = '';
 0671                          $no_image_select = false;
 0672   
 0673                          $imglist = filelist($phpbb_root_path . $img_path);
 0674   
 0675                          if (sizeof($imglist))
 0676                          {
 0677                              $imglist = array_values($imglist);
 0678                              $imglist = $imglist[0];
 0679   
 0680                              foreach ($imglist as $key => $img)
 0681                              {
 0682                                  if (!$ext_group_row['upload_icon'])
 0683                                  {
 0684                                      $no_image_select = true;
 0685                                      $selected = '';
 0686                                  }
 0687                                  else
 0688                                  {
 0689                                      $selected = ($ext_group_row['upload_icon'] == $img) ? ' selected="selected"' : '';
 0690                                  }
 0691   
 0692                                  if (strlen($img) > 255)
 0693                                  {
 0694                                      continue;
 0695                                  }
 0696   
 0697                                  $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
 0698                              }
 0699                          }
 0700   
 0701                          $i = 0;
 0702                          $assigned_extensions = '';
 0703                          foreach ($extensions as $num => $row)
 0704                          {
 0705                              if ($row['group_id'] == $group_id && $group_id)
 0706                              {
 0707                                  $assigned_extensions .= ($i) ? ', ' . $row['extension'] : $row['extension'];
 0708                                  $i++;
 0709                              }
 0710                          }
 0711   
 0712                          $s_extension_options = '';
 0713                          foreach ($extensions as $row)
 0714                          {
 0715                              $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>';
 0716                          }
 0717   
 0718                          $template->assign_vars(array(
 0719                              'PHPBB_ROOT_PATH'        => $phpbb_root_path,
 0720                              'IMG_PATH'                => $img_path,
 0721                              'ACTION'                => $action,
 0722                              'GROUP_ID'                => $group_id,
 0723                              'GROUP_NAME'            => $ext_group_row['group_name'],
 0724                              'ALLOW_GROUP'            => $ext_group_row['allow_group'],
 0725                              'ALLOW_IN_PM'            => $ext_group_row['allow_in_pm'],
 0726                              'UPLOAD_ICON_SRC'        => $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'],
 0727                              'EXTGROUP_FILESIZE'        => $ext_group_row['max_filesize'],
 0728                              'ASSIGNED_EXTENSIONS'    => $assigned_extensions,
 0729   
 0730                              'S_CATEGORY_SELECT'            => $this->category_select('special_category', $group_id, 'category'),
 0731                              'S_EXT_GROUP_SIZE_OPTIONS'    => size_select_options($size_format),
 0732                              'S_EXTENSION_OPTIONS'        => $s_extension_options,
 0733                              'S_FILENAME_LIST'            => $filename_list,
 0734                              'S_EDIT_GROUP'                => true,
 0735                              'S_NO_IMAGE'                => $no_image_select,
 0736                              'S_FORUM_IDS'                => (sizeof($forum_ids)) ? true : false,
 0737   
 0738                              'U_EXTENSIONS'        => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=extensions"),
 0739                              'U_BACK'            => $this->u_action,
 0740   
 0741                              'L_LEGEND'            => $user->lang[strtoupper($action) . '_EXTENSION_GROUP'])
 0742                          );
 0743   
 0744                          $s_forum_id_options = '';
 0745   
 0746                          $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
 0747                              FROM ' . FORUMS_TABLE . '
 0748                              ORDER BY left_id ASC';
 0749                          $result = $db->sql_query($sql, 600);
 0750   
 0751                          $right = $cat_right = $padding_inc = 0;
 0752                          $padding = $forum_list = $holding = '';
 0753                          $padding_store = array('0' => '');
 0754   
 0755                          while ($row = $db->sql_fetchrow($result))
 0756                          {
 0757                              if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
 0758                              {
 0759                                  // Non-postable forum with no subforums, don't display
 0760                                  continue;
 0761                              }
 0762   
 0763                              if (!$auth->acl_get('f_list', $row['forum_id']))
 0764                              {
 0765                                  // if the user does not have permissions to list this forum skip
 0766                                  continue;
 0767                              }
 0768   
 0769                              if ($row['left_id'] < $right)
 0770                              {
 0771                                  $padding .= '&nbsp; &nbsp;';
 0772                                  $padding_store[$row['parent_id']] = $padding;
 0773                              }
 0774                              else if ($row['left_id'] > $right + 1)
 0775                              {
 0776                                  $padding = $padding_store[$row['parent_id']];
 0777                              }
 0778   
 0779                              $right = $row['right_id'];
 0780   
 0781                              $selected = (in_array($row['forum_id'], $forum_ids)) ? ' selected="selected"' : '';
 0782   
 0783                              if ($row['left_id'] > $cat_right)
 0784                              {
 0785                                  // make sure we don't forget anything
 0786                                  $s_forum_id_options .= $holding;
 0787                                  $holding = '';
 0788                              }
 0789   
 0790                              if ($row['right_id'] - $row['left_id'] > 1)
 0791                              {
 0792                                  $cat_right = max($cat_right, $row['right_id']);
 0793   
 0794                                  $holding .= '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
 0795                              }
 0796                              else
 0797                              {
 0798                                  $s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
 0799                                  $holding = '';
 0800                              }
 0801                          }
 0802   
 0803                          if ($holding)
 0804                          {
 0805                              $s_forum_id_options .= $holding;
 0806                          }
 0807   
 0808                          $db->sql_freeresult($result);
 0809                          unset($padding_store);
 0810   
 0811                          $template->assign_vars(array(
 0812                              'S_FORUM_ID_OPTIONS'    => $s_forum_id_options)
 0813                          );
 0814   
 0815                      break;
 0816                  }
 0817   
 0818                  $sql = 'SELECT *
 0819                      FROM ' . EXTENSION_GROUPS_TABLE . '
 0820                      ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
 0821                  $result = $db->sql_query($sql);
 0822   
 0823                  $old_allow_group = $old_allow_pm = 1;
 0824                  while ($row = $db->sql_fetchrow($result))
 0825                  {
 0826                      $s_add_spacer = ($old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm']) ? true : false;
 0827   
 0828                      $template->assign_block_vars('groups', array(
 0829                          'S_ADD_SPACER'        => $s_add_spacer,
 0830                          'S_ALLOWED_IN_PM'    => ($row['allow_in_pm']) ? true : false,
 0831                          'S_GROUP_ALLOWED'    => ($row['allow_group']) ? true : false,
 0832   
 0833                          'U_EDIT'        => $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}",
 0834                          'U_DELETE'        => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}",
 0835   
 0836                          'GROUP_NAME'    => $row['group_name'],
 0837                          'CATEGORY'        => $cat_lang[$row['cat_id']],
 0838                          )
 0839                      );
 0840   
 0841                      $old_allow_group = $row['allow_group'];
 0842                      $old_allow_pm = $row['allow_in_pm'];
 0843                  }
 0844                  $db->sql_freeresult($result);
 0845   
 0846              break;
 0847   
 0848              case 'orphan':
 0849   
 0850                  if ($submit)
 0851                  {
 0852                      $delete_files = (isset($_POST['delete'])) ? array_keys(request_var('delete', array('' => 0))) : array();
 0853                      $add_files = (isset($_POST['add'])) ? array_keys(request_var('add', array('' => 0))) : array();
 0854                      $post_ids = request_var('post_id', array('' => 0));
 0855   
 0856                      if (sizeof($delete_files))
 0857                      {
 0858                          $sql = 'SELECT *
 0859                              FROM ' . ATTACHMENTS_TABLE . '
 0860                              WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
 0861                                  AND is_orphan = 1';
 0862                          $result = $db->sql_query($sql);
 0863   
 0864                          $delete_files = array();
 0865                          while ($row = $db->sql_fetchrow($result))
 0866                          {
 0867                              phpbb_unlink($row['physical_filename'], 'file');
 0868   
 0869                              if ($row['thumbnail'])
 0870                              {
 0871                                  phpbb_unlink($row['physical_filename'], 'thumbnail');
 0872                              }
 0873   
 0874                              $delete_files[$row['attach_id']] = $row['real_filename'];
 0875                          }
 0876                          $db->sql_freeresult($result);
 0877                      }
 0878   
 0879                      if (sizeof($delete_files))
 0880                      {
 0881                          $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
 0882                              WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
 0883                          $db->sql_query($sql);
 0884   
 0885                          add_log('admin', 'LOG_ATTACH_ORPHAN_DEL', implode(', ', $delete_files));
 0886                          $notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files));
 0887                      }
 0888   
 0889                      $upload_list = array();
 0890                      foreach ($add_files as $attach_id)
 0891                      {
 0892                          if (!in_array($attach_id, array_keys($delete_files)) && !empty($post_ids[$attach_id]))
 0893                          {
 0894                              $upload_list[$attach_id] = $post_ids[$attach_id];
 0895                          }
 0896                      }
 0897                      unset($add_files);
 0898   
 0899                      if (sizeof($upload_list))
 0900                      {
 0901                          $template->assign_var('S_UPLOADING_FILES', true);
 0902   
 0903                          $sql = 'SELECT forum_id, forum_name
 0904                              FROM ' . FORUMS_TABLE;
 0905                          $result = $db->sql_query($sql);
 0906   
 0907                          $forum_names = array();
 0908                          while ($row = $db->sql_fetchrow($result))
 0909                          {
 0910                              $forum_names[$row['forum_id']] = $row['forum_name'];
 0911                          }
 0912                          $db->sql_freeresult($result);
 0913   
 0914                          $sql = 'SELECT forum_id, topic_id, post_id, poster_id
 0915                              FROM ' . POSTS_TABLE . '
 0916                              WHERE ' . $db->sql_in_set('post_id', $upload_list);
 0917                          $result = $db->sql_query($sql);
 0918   
 0919                          $post_info = array();
 0920                          while ($row = $db->sql_fetchrow($result))
 0921                          {
 0922                              $post_info[$row['post_id']] = $row;
 0923                          }
 0924                          $db->sql_freeresult($result);
 0925   
 0926                          // Select those attachments we want to change...
 0927                          $sql = 'SELECT *
 0928                              FROM ' . ATTACHMENTS_TABLE . '
 0929                              WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
 0930                                  AND is_orphan = 1';
 0931                          $result = $db->sql_query($sql);
 0932   
 0933                          while ($row = $db->sql_fetchrow($result))
 0934                          {
 0935                              $post_row = $post_info[$upload_list[$row['attach_id']]];
 0936   
 0937                              $template->assign_block_vars('upload', array(
 0938                                  'FILE_INFO'        => sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']),
 0939                                  'S_DENIED'        => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? true : false,
 0940                                  'L_DENIED'        => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : '')
 0941                              );
 0942   
 0943                              if (!$auth->acl_get('f_attach', $post_row['forum_id']))
 0944                              {
 0945                                  continue;
 0946                              }
 0947   
 0948                              // Adjust attachment entry
 0949                              $sql_ary = array(
 0950                                  'in_message'    => 0,
 0951                                  'is_orphan'        => 0,
 0952                                  'poster_id'        => $post_row['poster_id'],
 0953                                  'post_msg_id'    => $post_row['post_id'],
 0954                                  'topic_id'        => $post_row['topic_id'],
 0955                              );
 0956   
 0957                              $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
 0958                                  SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 0959                                  WHERE attach_id = ' . $row['attach_id'];
 0960                              $db->sql_query($sql);
 0961   
 0962                              $sql = 'UPDATE ' . POSTS_TABLE . '
 0963                                  SET post_attachment = 1
 0964                                  WHERE post_id = ' . $post_row['post_id'];
 0965                              $db->sql_query($sql);
 0966   
 0967                              $sql = 'UPDATE ' . TOPICS_TABLE . '
 0968                                  SET topic_attachment = 1
 0969                                  WHERE topic_id = ' . $post_row['topic_id'];
 0970                              $db->sql_query($sql);
 0971   
 0972                              add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']);
 0973                          }
 0974                          $db->sql_freeresult($result);
 0975                      }
 0976                  }
 0977   
 0978                  $template->assign_vars(array(
 0979                      'S_ORPHAN'        => true)
 0980                  );
 0981   
 0982                  // Just get the files with is_orphan set and older than 3 hours
 0983                  $sql = 'SELECT *
 0984                      FROM ' . ATTACHMENTS_TABLE . '
 0985                      WHERE is_orphan = 1
 0986                          AND filetime < ' . (time() - 3*60*60) . '
 0987                      ORDER BY filetime DESC';
 0988                  $result = $db->sql_query($sql);
 0989   
 0990                  while ($row = $db->sql_fetchrow($result))
 0991                  {
 0992                      $size_lang = ($row['filesize'] >= 1048576) ? $user->lang['MB'] : (($row['filesize'] >= 1024) ? $user->lang['KB'] : $user->lang['BYTES']);
 0993                      $row['filesize'] = ($row['filesize'] >= 1048576) ? round((round($row['filesize'] / 1048576 * 100) / 100), 2) : (($row['filesize'] >= 1024) ? round((round($row['filesize'] / 1024 * 100) / 100), 2) : $row['filesize']);
 0994   
 0995                      $template->assign_block_vars('orphan', array(
 0996                          'FILESIZE'            => $row['filesize'] . ' ' . $size_lang,
 0997                          'FILETIME'            => $user->format_date($row['filetime']),
 0998                          'REAL_FILENAME'        => basename($row['real_filename']),
 0999                          'PHYSICAL_FILENAME'    => basename($row['physical_filename']),
 1000                          'ATTACH_ID'            => $row['attach_id'],
 1001                          'POST_IDS'            => (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
 1002                          'U_FILE'            => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))
 1003                      );
 1004                  }
 1005                  $db->sql_freeresult($result);
 1006   
 1007              break;
 1008          }
 1009   
 1010          if (sizeof($error))
 1011          {
 1012              $template->assign_vars(array(
 1013                  'S_WARNING'        => true,
 1014                  'WARNING_MSG'    => implode('<br />', $error))
 1015              );
 1016          }
 1017   
 1018          if (sizeof($notify))
 1019          {
 1020              $template->assign_vars(array(
 1021                  'S_NOTIFY'        => true,
 1022                  'NOTIFY_MSG'    => implode('<br />', $notify))
 1023              );
 1024          }
 1025      }
 1026   
 1027      /**
 1028      * Build Select for category items
 1029      */
 1030      function category_select($select_name, $group_id = false, $key = '')
 1031      {
 1032          global $db, $user;
 1033   
 1034          $types = array(
 1035              ATTACHMENT_CATEGORY_NONE        => $user->lang['NO_FILE_CAT'],
 1036              ATTACHMENT_CATEGORY_IMAGE        => $user->lang['CAT_IMAGES'],
 1037              ATTACHMENT_CATEGORY_WM            => $user->lang['CAT_WM_FILES'],
 1038              ATTACHMENT_CATEGORY_RM            => $user->lang['CAT_RM_FILES'],
 1039              ATTACHMENT_CATEGORY_FLASH        => $user->lang['CAT_FLASH_FILES'],
 1040              ATTACHMENT_CATEGORY_QUICKTIME    => $user->lang['CAT_QUICKTIME_FILES'],
 1041          );
 1042          
 1043          if ($group_id)
 1044          {
 1045              $sql = 'SELECT cat_id
 1046                  FROM ' . EXTENSION_GROUPS_TABLE . '
 1047                  WHERE group_id = ' . (int) $group_id;
 1048              $result = $db->sql_query($sql);
 1049   
 1050              $cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE : $row['cat_id'];
 1051   
 1052              $db->sql_freeresult($result);
 1053          }
 1054          else
 1055          {
 1056              $cat_type = ATTACHMENT_CATEGORY_NONE;
 1057          }
 1058          
 1059          $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
 1060   
 1061          foreach ($types as $type => $mode)
 1062          {
 1063              $selected = ($type == $cat_type) ? ' selected="selected"' : '';
 1064              $group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>';
 1065          }
 1066   
 1067          $group_select .= '</select>';
 1068   
 1069          return $group_select;
 1070      }
 1071   
 1072      /**
 1073      * Extension group select
 1074      */
 1075      function group_select($select_name, $default_group = false, $key = '')
 1076      {
 1077          global $db, $user;
 1078              
 1079          $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
 1080   
 1081          $sql = 'SELECT group_id, group_name
 1082              FROM ' . EXTENSION_GROUPS_TABLE . '
 1083              ORDER BY group_name';
 1084          $result = $db->sql_query($sql);
 1085   
 1086          $group_name = array();
 1087          while ($row = $db->sql_fetchrow($result))
 1088          {
 1089              $group_name[] = $row;
 1090          }
 1091          $db->sql_freeresult($result);
 1092   
 1093          $row['group_id'] = 0;
 1094          $row['group_name'] = $user->lang['NOT_ASSIGNED'];
 1095          $group_name[] = $row;
 1096          
 1097          for ($i = 0; $i < sizeof($group_name); $i++)
 1098          {
 1099              if ($default_group === false)
 1100              {
 1101                  $selected = ($i == 0) ? ' selected="selected"' : '';
 1102              }
 1103              else
 1104              {
 1105                  $selected = ($group_name[$i]['group_id'] == $default_group) ? ' selected="selected"' : '';
 1106              }
 1107   
 1108              $group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>';
 1109          }
 1110   
 1111          $group_select .= '</select>';
 1112   
 1113          return $group_select;
 1114      }
 1115   
 1116      /**
 1117      * Search Imagick
 1118      */
 1119      function search_imagemagick()
 1120      {
 1121          $imagick = '';
 1122   
 1123          $exe = ((defined('PHP_OS')) && (preg_match('#^win#i', PHP_OS))) ? '.exe' : '';
 1124   
 1125          $magic_home = getenv('MAGICK_HOME');
 1126   
 1127          if (empty($magic_home))
 1128          {
 1129              $locations = array('C:/WINDOWS/', 'C:/WINNT/', 'C:/WINDOWS/SYSTEM/', 'C:/WINNT/SYSTEM/', 'C:/WINDOWS/SYSTEM32/', 'C:/WINNT/SYSTEM32/', '/usr/bin/', '/usr/sbin/', '/usr/local/bin/', '/usr/local/sbin/', '/opt/', '/usr/imagemagick/', '/usr/bin/imagemagick/');
 1130              $path_locations = str_replace('\\', '/', (explode(($exe) ? ';' : ':', getenv('PATH'))));    
 1131   
 1132              $locations = array_merge($path_locations, $locations);
 1133   
 1134              foreach ($locations as $location)
 1135              {
 1136                  // The path might not end properly, fudge it
 1137                  if (substr($location, -1, 1) !== '/')
 1138                  {
 1139                      $location .= '/';
 1140                  }
 1141   
 1142                  if (@is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)
 1143                  {
 1144                      $imagick = str_replace('\\', '/', $location);
 1145                      continue;
 1146                  }
 1147              }
 1148          }
 1149          else
 1150          {
 1151              $imagick = str_replace('\\', '/', $magic_home);
 1152          }
 1153   
 1154          return $imagick;
 1155      }
 1156   
 1157      /**
 1158      * Test Settings
 1159      */
 1160      function test_upload(&$error, $upload_dir, $create_directory = false)
 1161      {
 1162          global $user, $phpbb_root_path;
 1163   
 1164          // Does the target directory exist, is it a directory and writable.
 1165          if ($create_directory)
 1166          {
 1167              if (!file_exists($phpbb_root_path . $upload_dir))
 1168              {
 1169                  @mkdir($phpbb_root_path . $upload_dir, 0777);
 1170                  @chmod($phpbb_root_path . $upload_dir, 0777);
 1171              }
 1172          }
 1173   
 1174          if (!file_exists($phpbb_root_path . $upload_dir))
 1175          {
 1176              $error[] = sprintf($user->lang['NO_UPLOAD_DIR'], $upload_dir);
 1177              return;
 1178          }
 1179   
 1180          if (!is_dir($phpbb_root_path . $upload_dir))
 1181          {
 1182              $error[] = sprintf($user->lang['UPLOAD_NOT_DIR'], $upload_dir);
 1183              return;
 1184          }
 1185   
 1186          if (!is_writable($phpbb_root_path . $upload_dir))
 1187          {
 1188              $error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
 1189              return;
 1190          }
 1191      }
 1192   
 1193      /**
 1194      * Perform operations on sites for external linking
 1195      */
 1196      function perform_site_list()
 1197      {
 1198          global $db, $user;
 1199   
 1200          if (isset($_REQUEST['securesubmit']))
 1201          {
 1202              // Grab the list of entries
 1203              $ips = request_var('ips', '');
 1204              $ip_list = array_unique(explode("\n", $ips));
 1205              $ip_list_log = implode(', ', $ip_list);
 1206   
 1207              $ip_exclude = (!empty($_POST['ipexclude'])) ? 1 : 0;
 1208   
 1209              $iplist = array();
 1210              $hostlist = array();
 1211   
 1212              foreach ($ip_list as $item)
 1213              {
 1214                  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))
 1215                  {
 1216                      // Don't ask about all this, just don't ask ... !
 1217                      $ip_1_counter = $ip_range_explode[1];
 1218                      $ip_1_end = $ip_range_explode[5];
 1219   
 1220                      while ($ip_1_counter <= $ip_1_end)
 1221                      {
 1222                          $ip_2_counter = ($ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[2] : 0;
 1223                          $ip_2_end = ($ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[6];
 1224   
 1225                          if ($ip_2_counter == 0 && $ip_2_end == 254)
 1226                          {
 1227                              $ip_2_counter = 256;
 1228                              $ip_2_fragment = 256;
 1229   
 1230                              $iplist[] = "'$ip_1_counter.*'";
 1231                          }
 1232   
 1233                          while ($ip_2_counter <= $ip_2_end)
 1234                          {
 1235                              $ip_3_counter = ($ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[3] : 0;
 1236                              $ip_3_end = ($ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[7];
 1237   
 1238                              if ($ip_3_counter == 0 && $ip_3_end == 254)
 1239                              {
 1240                                  $ip_3_counter = 256;
 1241                                  $ip_3_fragment = 256;
 1242   
 1243                                  $iplist[] = "'$ip_1_counter.$ip_2_counter.*'";
 1244                              }
 1245   
 1246                              while ($ip_3_counter <= $ip_3_end)
 1247                              {
 1248                                  $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;
 1249                                  $ip_4_end = ($ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end) ? 254 : $ip_range_explode[8];
 1250   
 1251                                  if ($ip_4_counter == 0 && $ip_4_end == 254)
 1252                                  {
 1253                                      $ip_4_counter = 256;
 1254                                      $ip_4_fragment = 256;
 1255   
 1256                                      $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.*'";
 1257                                  }
 1258   
 1259                                  while ($ip_4_counter <= $ip_4_end)
 1260                                  {
 1261                                      $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter'";
 1262                                      $ip_4_counter++;
 1263                                  }
 1264                                  $ip_3_counter++;
 1265                              }
 1266                              $ip_2_counter++;
 1267                          }
 1268                          $ip_1_counter++;
 1269                      }
 1270                  }
 1271                  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)))
 1272                  {
 1273                      $iplist[] = "'" . trim($item) . "'";
 1274                  }
 1275                  else if (preg_match('#^([\w\-_]\.?){2,}$#is', trim($item)))
 1276                  {
 1277                      $hostlist[] = "'" . trim($item) . "'";
 1278                  }
 1279                  else if (preg_match("#^([a-z0-9\-\*\._/]+?)$#is", trim($item)))
 1280                  {
 1281                      $hostlist[] = "'" . trim($item) . "'";
 1282                  }
 1283              }
 1284   
 1285              $sql = 'SELECT site_ip, site_hostname
 1286                  FROM ' . SITELIST_TABLE . "
 1287                  WHERE ip_exclude = $ip_exclude";
 1288              $result = $db->sql_query($sql);
 1289   
 1290              if ($row = $db->sql_fetchrow($result))
 1291              {
 1292                  $iplist_tmp = array();
 1293                  $hostlist_tmp = array();
 1294                  do
 1295                  {
 1296                      if ($row['site_ip'])
 1297                      {
 1298                          if (strlen($row['site_ip']) > 40)
 1299                          {
 1300                              continue;
 1301                          }
 1302   
 1303                          $iplist_tmp[] = "'" . $row['site_ip'] . "'";
 1304                      }
 1305                      else if ($row['site_hostname'])
 1306                      {
 1307                          if (strlen($row['site_hostname']) > 255)
 1308                          {
 1309                              continue;
 1310                          }
 1311   
 1312                          $hostlist_tmp[] = "'" . $row['site_hostname'] . "'";
 1313                      }
 1314                      // break;
 1315                  }
 1316                  while ($row = $db->sql_fetchrow($result));
 1317   
 1318                  $iplist = array_unique(array_diff($iplist, $iplist_tmp));
 1319                  $hostlist = array_unique(array_diff($hostlist, $hostlist_tmp));
 1320                  unset($iplist_tmp);
 1321                  unset($hostlist_tmp);
 1322              }
 1323              $db->sql_freeresult($result);
 1324   
 1325              if (sizeof($iplist))
 1326              {
 1327                  foreach ($iplist as $ip_entry)
 1328                  {
 1329                      $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_ip, ip_exclude)
 1330                          VALUES ($ip_entry, $ip_exclude)";
 1331                      $db->sql_query($sql);
 1332                  }
 1333              }
 1334   
 1335              if (sizeof($hostlist))
 1336              {
 1337                  foreach ($hostlist as $host_entry)
 1338                  {
 1339                      $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_hostname, ip_exclude)
 1340                          VALUES ($host_entry, $ip_exclude)";
 1341                      $db->sql_query($sql);
 1342                  }
 1343              }
 1344              
 1345              if (!empty($ip_list_log))
 1346              {
 1347                  // Update log
 1348                  $log_entry = ($ip_exclude) ? 'LOG_DOWNLOAD_EXCLUDE_IP' : 'LOG_DOWNLOAD_IP';
 1349                  add_log('admin', $log_entry, $ip_list_log);
 1350              }
 1351   
 1352              trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
 1353          }
 1354          else if (isset($_POST['unsecuresubmit']))
 1355          {
 1356              $unip_sql = request_var('unip', array(0));
 1357   
 1358              if (sizeof($unip_sql))
 1359              {
 1360                  $l_unip_list = '';
 1361   
 1362                  // Grab details of ips for logging information later
 1363                  $sql = 'SELECT site_ip, site_hostname
 1364                      FROM ' . SITELIST_TABLE . '
 1365                      WHERE ' . $db->sql_in_set('site_id', $unip_sql);
 1366                  $result = $db->sql_query($sql);
 1367   
 1368                  while ($row = $db->sql_fetchrow($result))
 1369                  {
 1370                      $l_unip_list .= (($l_unip_list != '') ? ', ' : '') . (($row['site_ip']) ? $row['site_ip'] : $row['site_hostname']);
 1371                  }
 1372                  $db->sql_freeresult($result);
 1373   
 1374                  $sql = 'DELETE FROM ' . SITELIST_TABLE . '
 1375                      WHERE ' . $db->sql_in_set('site_id', $unip_sql);
 1376                  $db->sql_query($sql);
 1377   
 1378                  add_log('admin', 'LOG_DOWNLOAD_REMOVE_IP', $l_unip_list);
 1379              }
 1380   
 1381              trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
 1382          }
 1383      }
 1384   
 1385      /**
 1386      * Write display_order config field
 1387      */
 1388      function display_order($value, $key = '')
 1389      {
 1390          $radio_ary = array(0 => 'DESCENDING', 1 => 'ASCENDING');
 1391   
 1392          return h_radio('config[display_order]', $radio_ary, $value, $key);
 1393      }
 1394   
 1395      /**
 1396      * Adjust all three max_filesize config vars for display
 1397      */
 1398      function max_filesize($value, $key = '')
 1399      {
 1400          // Determine size var and adjust the value accordingly
 1401          $size_var = ($value >= 1048576) ? 'mb' : (($value >= 1024) ? 'kb' : 'b');
 1402          $value = ($value >= 1048576) ? round($value / 1048576 * 100) / 100 : (($value >= 1024) ? round($value / 1024 * 100) / 100 : $value);
 1403   
 1404          return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
 1405      }
 1406   
 1407      /**
 1408      * Write secure_allow_deny config field
 1409      */
 1410      function select_allow_deny($value, $key = '')
 1411      {
 1412          $radio_ary = array(1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW');
 1413   
 1414          return h_radio('config[' . $key . ']', $radio_ary, $value, $key);
 1415      }
 1416   
 1417  }
 1418   
 1419  ?>