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