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