6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
27 function main($id, $mode)
29 global $db, $user, $auth, $template, $cache, $config;
31 $user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
33 $error = $notify = array();
34 $submit = (isset($_POST['submit'])) ?
true : false;
35 $action = request_var('action', '');
37 $form_key = 'acp_attach';
38 add_form_key($form_key);
40 if ($submit && !check_form_key($form_key))
42 trigger_error($user->lang
['FORM_INVALID'] . adm_back_link($this->u_action
), E_USER_WARNING
);
48 $l_title = 'ACP_ATTACHMENT_SETTINGS';
52 $l_title = 'ACP_MANAGE_EXTENSIONS';
56 $l_title = 'ACP_EXTENSION_GROUPS';
60 $l_title = 'ACP_ORPHAN_ATTACHMENTS';
64 trigger_error('NO_MODE', E_USER_ERROR
);
68 $this->tpl_name
= 'acp_attachments';
69 $this->page_title
= $l_title;
71 $template->assign_vars(array(
72 'L_TITLE' => $user->lang
[$l_title],
73 'L_TITLE_EXPLAIN' => $user->lang
[$l_title . '_EXPLAIN'],
74 'U_ACTION' => $this->u_action
)
81 include_once(PHPBB_ROOT_PATH
. 'includes/functions_posting.' . PHP_EXT
);
83 $sql = 'SELECT group_name, cat_id
84 FROM ' . EXTENSION_GROUPS_TABLE
. '
87 $result = $db->sql_query($sql);
89 $s_assigned_groups = array();
90 while ($row = $db->sql_fetchrow($result))
92 $s_assigned_groups[$row['cat_id']][] = $row['group_name'];
94 $db->sql_freeresult($result);
96 $l_legend_cat_images = $user->lang
['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang
['ASSIGNED_GROUP'] . ': ' . ((!empty($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE
])) ?
implode(', ', $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE
]) : $user->lang
['NO_EXT_GROUP']) . ']';
98 $display_vars = array(
99 'title' => 'ACP_ATTACHMENT_SETTINGS',
101 'img_max_width' => false, 'img_max_height' => false, 'img_link_width' => false, 'img_link_height' => false,
103 'legend1' => 'ACP_ATTACHMENT_SETTINGS',
104 'allow_attachments' => array('lang' => 'ALLOW_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
105 'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
106 'upload_path' => array('lang' => 'UPLOAD_DIR', 'validate' => 'wpath', 'type' => 'text:25:100', 'explain' => true),
107 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'custom', 'method' => 'display_order', 'explain' => true),
108 'attachment_quota' => array('lang' => 'ATTACH_QUOTA', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
109 'max_filesize' => array('lang' => 'ATTACH_MAX_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
110 'max_filesize_pm' => array('lang' => 'ATTACH_MAX_PM_FILESIZE','validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
111 'max_attachments' => array('lang' => 'MAX_ATTACHMENTS', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false),
112 'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false),
113 'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
114 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),
115 'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
116 'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
119 'legend2' => $l_legend_cat_images,
120 'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
121 'img_create_thumbnail' => array('lang' => 'CREATE_THUMBNAIL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
122 'img_max_thumb_width' => array('lang' => 'MAX_THUMB_WIDTH', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' px'),
123 'img_min_thumb_filesize' => array('lang' => 'MIN_THUMB_FILESIZE', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang
['BYTES']),
124 'img_imagick' => array('lang' => 'IMAGICK_PATH', 'validate' => 'string', 'type' => 'text:20:200', 'explain' => true, 'append' => ' <span>[ <a href="' . $this->u_action
. '&action=imgmagick">' . $user->lang
['SEARCH_IMAGICK'] . '</a> ]</span>'),
125 'img_max' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
126 'img_link' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
130 $this->new_config
= $config;
131 $cfg_array = (isset($_REQUEST['config'])) ?
request_var('config', array('' => '')) : $this->new_config
;
134 // We validate the complete config if whished
135 validate_config_vars($display_vars['vars'], $cfg_array, $error);
137 // Do not write values if there is an error
143 // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
144 foreach ($display_vars['vars'] as $config_name => $null)
146 if (!isset($cfg_array[$config_name]) ||
strpos($config_name, 'legend') !== false)
151 $this->new_config
[$config_name] = $config_value = $cfg_array[$config_name];
153 if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm')))
155 $size_var = request_var($config_name, '');
156 $this->new_config
[$config_name] = $config_value = ($size_var == 'kb') ?
round($config_value * 1024) : (($size_var == 'mb') ?
round($config_value * 1048576) : $config_value);
161 set_config($config_name, $config_value);
165 $this->perform_site_list();
169 add_log('admin', 'LOG_CONFIG_ATTACH');
172 $this->test_upload($error, $this->new_config
['upload_path'], false);
176 trigger_error($user->lang
['CONFIG_UPDATED'] . adm_back_link($this->u_action
));
180 $template->assign_var('S_ATTACHMENT_SETTINGS', true);
182 if ($action == 'imgmagick')
184 $this->new_config
['img_imagick'] = $this->search_imagemagick();
187 // We strip eventually manual added convert program, we only want the patch
188 if ($this->new_config
['img_imagick'])
190 // Change path separator
191 $this->new_config
['img_imagick'] = str_replace('\\', '/', $this->new_config
['img_imagick']);
192 $this->new_config
['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config
['img_imagick']);
194 // Check for trailing slash
195 if (substr($this->new_config
['img_imagick'], -1) !== '/')
197 $this->new_config
['img_imagick'] .= '/';
201 $supported_types = get_supported_image_types();
203 // Check Thumbnail Support
204 if (!$this->new_config
['img_imagick'] && (!isset($supported_types['format']) ||
!sizeof($supported_types['format'])))
206 $this->new_config
['img_create_thumbnail'] = 0;
209 $template->assign_vars(array(
210 'U_SEARCH_IMAGICK' => $this->u_action
. '&action=imgmagick',
211 'S_THUMBNAIL_SUPPORT' => (!$this->new_config
['img_imagick'] && (!isset($supported_types['format']) ||
!sizeof($supported_types['format']))) ?
false : true)
214 // Secure Download Options - Same procedure as with banning
215 $allow_deny = ($this->new_config
['secure_allow_deny']) ?
'ALLOWED' : 'DISALLOWED';
218 FROM ' . SITELIST_TABLE
;
219 $result = $db->sql_query($sql);
224 while ($row = $db->sql_fetchrow($result))
226 $value = ($row['site_ip']) ?
$row['site_ip'] : $row['site_hostname'];
229 $defined_ips .= '<option' . (($row['ip_exclude']) ?
' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>';
230 $ips[$row['site_id']] = $value;
233 $db->sql_freeresult($result);
235 $template->assign_vars(array(
236 'S_SECURE_DOWNLOADS' => $this->new_config
['secure_downloads'],
237 'S_DEFINED_IPS' => ($defined_ips != '') ?
true : false,
238 'S_WARNING' => (sizeof($error)) ?
true : false,
240 'WARNING_MSG' => implode('<br />', $error),
241 'DEFINED_IPS' => $defined_ips,
243 'L_SECURE_TITLE' => $user->lang
['DEFINE_' . $allow_deny . '_IPS'],
244 'L_IP_EXCLUDE' => $user->lang
['EXCLUDE_FROM_' . $allow_deny . '_IP'],
245 'L_REMOVE_IPS' => $user->lang
['REMOVE_' . $allow_deny . '_IPS'])
248 // Output relevant options
249 foreach ($display_vars['vars'] as $config_key => $vars)
251 if (!is_array($vars) && strpos($config_key, 'legend') === false)
256 if (strpos($config_key, 'legend') !== false)
258 $template->assign_block_vars('options', array(
260 'LEGEND' => (isset($user->lang
[$vars])) ?
$user->lang
[$vars] : $vars)
266 $type = explode(':', $vars['type']);
269 if ($vars['explain'] && isset($vars['lang_explain']))
271 $l_explain = (isset($user->lang
[$vars['lang_explain']])) ?
$user->lang
[$vars['lang_explain']] : $vars['lang_explain'];
273 else if ($vars['explain'])
275 $l_explain = (isset($user->lang
[$vars['lang'] . '_EXPLAIN'])) ?
$user->lang
[$vars['lang'] . '_EXPLAIN'] : '';
278 $content = build_cfg_template($type, $config_key, $this->new_config
, $config_key, $vars);
284 $template->assign_block_vars('options', array(
285 'KEY' => $config_key,
286 'TITLE' => $user->lang
[$vars['lang']],
287 'S_EXPLAIN' => $vars['explain'],
288 'TITLE_EXPLAIN' => $l_explain,
289 'CONTENT' => $content,
293 unset($display_vars['vars'][$config_key]);
300 if ($submit ||
isset($_POST['add_extension_check']))
304 // Change Extensions ?
305 $extension_change_list = request_var('extension_change_list', array(0));
306 $group_select_list = request_var('group_select', array(0));
308 // Generate correct Change List
309 $extensions = array();
311 for ($i = 0, $size = sizeof($extension_change_list); $i < $size; $i++
)
313 $extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i];
317 FROM ' . EXTENSIONS_TABLE
. '
318 ORDER BY extension_id';
319 $result = $db->sql_query($sql);
321 while ($row = $db->sql_fetchrow($result))
323 if ($row['group_id'] != $extensions[$row['extension_id']]['group_id'])
325 $sql = 'UPDATE ' . EXTENSIONS_TABLE
. '
326 SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . '
327 WHERE extension_id = ' . $row['extension_id'];
328 $db->sql_query($sql);
330 add_log('admin', 'LOG_ATTACH_EXT_UPDATE', $row['extension']);
333 $db->sql_freeresult($result);
336 $extension_id_list = request_var('extension_id_list', array(0));
338 if (sizeof($extension_id_list))
340 $sql = 'SELECT extension
341 FROM ' . EXTENSIONS_TABLE
. '
342 WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
343 $result = $db->sql_query($sql);
345 $extension_list = '';
346 while ($row = $db->sql_fetchrow($result))
348 $extension_list .= ($extension_list == '') ?
$row['extension'] : ', ' . $row['extension'];
350 $db->sql_freeresult($result);
353 FROM ' . EXTENSIONS_TABLE
. '
354 WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
355 $db->sql_query($sql);
357 add_log('admin', 'LOG_ATTACH_EXT_DEL', $extension_list);
362 $add_extension = strtolower(request_var('add_extension', ''));
363 $add_extension_group = request_var('add_group_select', 0);
364 $add = (isset($_POST['add_extension_check'])) ?
true : false;
366 if ($add_extension && $add)
370 $sql = 'SELECT extension_id
371 FROM ' . EXTENSIONS_TABLE
. "
372 WHERE extension = '" . $db->sql_escape($add_extension) . "'";
373 $result = $db->sql_query($sql);
375 if ($row = $db->sql_fetchrow($result))
377 $error[] = sprintf($user->lang
['EXTENSION_EXIST'], $add_extension);
379 $db->sql_freeresult($result);
384 'group_id' => $add_extension_group,
385 'extension' => $add_extension
388 $db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE
. ' ' . $db->sql_build_array('INSERT', $sql_ary));
389 add_log('admin', 'LOG_ATTACH_EXT_ADD', $add_extension);
396 $notify[] = $user->lang
['EXTENSIONS_UPDATED'];
399 $cache->destroy('_extensions');
402 $template->assign_vars(array(
403 'S_EXTENSIONS' => true,
404 'ADD_EXTENSION' => (isset($add_extension)) ?
$add_extension : '',
405 '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'))
409 FROM ' . EXTENSIONS_TABLE
. '
410 ORDER BY group_id, extension';
411 $result = $db->sql_query($sql);
413 if ($row = $db->sql_fetchrow($result))
415 $old_group_id = $row['group_id'];
420 $current_group_id = $row['group_id'];
421 if ($old_group_id != $current_group_id)
424 $old_group_id = $current_group_id;
427 $template->assign_block_vars('extensions', array(
428 'S_SPACER' => $s_spacer,
429 'EXTENSION_ID' => $row['extension_id'],
430 'EXTENSION' => $row['extension'],
431 'GROUP_OPTIONS' => $this->group_select('group_select[]', $row['group_id']))
434 while ($row = $db->sql_fetchrow($result));
436 $db->sql_freeresult($result);
442 $template->assign_var('S_EXTENSION_GROUPS', true);
446 $action = request_var('action', '');
447 $group_id = request_var('g', 0);
449 if ($action != 'add' && $action != 'edit')
451 trigger_error('NO_MODE', E_USER_ERROR
);
454 if (!$group_id && $action == 'edit')
456 trigger_error($user->lang
['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action
), E_USER_WARNING
);
462 FROM ' . EXTENSION_GROUPS_TABLE
. "
463 WHERE group_id = $group_id";
464 $result = $db->sql_query($sql);
465 $ext_row = $db->sql_fetchrow($result);
466 $db->sql_freeresult($result);
470 trigger_error($user->lang
['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action
), E_USER_WARNING
);
478 $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
479 $new_group_name = ($action == 'add') ?
$group_name : (($ext_row['group_name'] != $group_name) ?
$group_name : '');
483 $error[] = $user->lang
['NO_EXT_GROUP_NAME'];
486 // Check New Group Name
489 $sql = 'SELECT group_name
490 FROM ' . EXTENSION_GROUPS_TABLE
;
491 $result = $db->sql_query($sql);
492 $ext_row = $db->sql_fetchrow($result);
493 $db->sql_freeresult($result);
495 $clean_group_name = utf8_clean_string($new_group_name);
497 while ($row = $db->sql_fetchrow($result))
499 if (utf8_clean_string($row['group_name']) === $clean_group_name)
501 $error[] = sprintf($user->lang
['EXTENSION_GROUP_EXIST'], $new_group_name);
505 $db->sql_freeresult($result);
510 // Ok, build the update/insert array
511 $upload_icon = request_var('upload_icon', 'no_image');
512 $size_select = request_var('size_select', 'b');
513 $forum_select = request_var('forum_select', false);
514 $allowed_forums = request_var('allowed_forums', array(0));
515 $allow_in_pm = (isset($_POST['allow_in_pm'])) ?
true : false;
516 $max_filesize = request_var('max_filesize', 0);
517 $max_filesize = ($size_select == 'kb') ?
round($max_filesize * 1024) : (($size_select == 'mb') ?
round($max_filesize * 1048576) : $max_filesize);
518 $allow_group = (isset($_POST['allow_group'])) ?
true : false;
520 if ($max_filesize == $config['max_filesize'])
525 if (!sizeof($allowed_forums))
527 $forum_select = false;
531 'group_name' => $group_name,
532 'cat_id' => request_var('special_category', ATTACHMENT_CATEGORY_NONE
),
533 'allow_group' => ($allow_group) ?
1 : 0,
534 'upload_icon' => ($upload_icon == 'no_image') ?
'' : $upload_icon,
535 'max_filesize' => $max_filesize,
536 'allowed_forums'=> ($forum_select) ?
serialize($allowed_forums) : '',
537 'allow_in_pm' => ($allow_in_pm) ?
1 : 0,
540 if ($action == 'add')
542 $group_ary['download_mode'] = INLINE_LINK
;
545 // @TODO: rewrite with the new param db functions
546 $sql = ($action == 'add') ?
'INSERT INTO ' . EXTENSION_GROUPS_TABLE
. ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE
. ' SET ';
547 $sql .= $db->sql_build_array((($action == 'add') ?
'INSERT' : 'UPDATE'), $group_ary);
548 $sql .= ($action == 'edit') ?
" WHERE group_id = $group_id" : '';
550 $db->sql_query($sql);
552 if ($action == 'add')
554 $group_id = $db->sql_nextid();
557 add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name);
560 $extension_list = request_var('extensions', array(0));
562 if ($action == 'edit' && sizeof($extension_list))
564 $sql = 'UPDATE ' . EXTENSIONS_TABLE
. "
566 WHERE group_id = $group_id";
567 $db->sql_query($sql);
570 if (sizeof($extension_list))
572 $sql = 'UPDATE ' . EXTENSIONS_TABLE
. "
573 SET group_id = $group_id
574 WHERE " . $db->sql_in_set('extension_id', $extension_list);
575 $db->sql_query($sql);
578 $cache->destroy('_extensions');
582 $notify[] = $user->lang
['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)];
587 ATTACHMENT_CATEGORY_NONE
=> $user->lang
['NO_FILE_CAT'],
588 ATTACHMENT_CATEGORY_IMAGE
=> $user->lang
['CAT_IMAGES'],
589 ATTACHMENT_CATEGORY_WM
=> $user->lang
['CAT_WM_FILES'],
590 ATTACHMENT_CATEGORY_RM
=> $user->lang
['CAT_RM_FILES'],
591 ATTACHMENT_CATEGORY_FLASH
=> $user->lang
['CAT_FLASH_FILES'],
592 ATTACHMENT_CATEGORY_QUICKTIME
=> $user->lang
['CAT_QUICKTIME_FILES'],
595 $group_id = request_var('g', 0);
596 $action = (isset($_POST['add'])) ?
'add' : $action;
602 if (confirm_box(true))
604 $sql = 'SELECT group_name
605 FROM ' . EXTENSION_GROUPS_TABLE
. "
606 WHERE group_id = $group_id";
607 $result = $db->sql_query($sql);
608 $group_name = (string) $db->sql_fetchfield('group_name');
609 $db->sql_freeresult($result);
612 FROM ' . EXTENSION_GROUPS_TABLE
. "
613 WHERE group_id = $group_id";
614 $db->sql_query($sql);
616 // Set corresponding Extensions to a pending Group
617 $sql = 'UPDATE ' . EXTENSIONS_TABLE
. "
619 WHERE group_id = $group_id";
620 $db->sql_query($sql);
622 add_log('admin', 'LOG_ATTACH_EXTGROUP_DEL', $group_name);
624 $cache->destroy('_extensions');
626 trigger_error($user->lang
['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action
));
630 confirm_box(false, $user->lang
['CONFIRM_OPERATION'], build_hidden_fields(array(
633 'group_id' => $group_id,
634 'action' => 'delete',
644 trigger_error($user->lang
['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action
), E_USER_WARNING
);
648 FROM ' . EXTENSION_GROUPS_TABLE
. "
649 WHERE group_id = $group_id";
650 $result = $db->sql_query($sql);
651 $ext_group_row = $db->sql_fetchrow($result);
652 $db->sql_freeresult($result);
654 $forum_ids = (!$ext_group_row['allowed_forums']) ?
array() : unserialize(trim($ext_group_row['allowed_forums']));
660 if ($action == 'add')
662 $ext_group_row = array(
663 'group_name' => utf8_normalize_nfc(request_var('group_name', '', true)),
671 $forum_ids = array();
674 $extensions = array();
677 FROM ' . EXTENSIONS_TABLE
. "
678 WHERE group_id = $group_id
681 $result = $db->sql_query($sql);
682 $extensions = $db->sql_fetchrowset($result);
683 $db->sql_freeresult($result);
685 if ($ext_group_row['max_filesize'] == 0)
687 $ext_group_row['max_filesize'] = (int) $config['max_filesize'];
690 $size_format = ($ext_group_row['max_filesize'] >= 1048576) ?
'mb' : (($ext_group_row['max_filesize'] >= 1024) ?
'kb' : 'b');
691 $ext_group_row['max_filesize'] = get_formatted_filesize($ext_group_row['max_filesize'], false);
693 $img_path = $config['upload_icons_path'];
696 $no_image_select = false;
698 $imglist = filelist(PHPBB_ROOT_PATH
. $img_path);
700 if (sizeof($imglist))
702 $imglist = array_values($imglist);
703 $imglist = $imglist[0];
705 foreach ($imglist as $key => $img)
707 if (!$ext_group_row['upload_icon'])
709 $no_image_select = true;
714 $selected = ($ext_group_row['upload_icon'] == $img) ?
' selected="selected"' : '';
717 if (strlen($img) > 255)
722 $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
727 $assigned_extensions = '';
728 foreach ($extensions as $num => $row)
730 if ($row['group_id'] == $group_id && $group_id)
732 $assigned_extensions .= ($i) ?
', ' . $row['extension'] : $row['extension'];
737 $s_extension_options = '';
738 foreach ($extensions as $row)
740 $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>';
743 $template->assign_vars(array(
744 'PHPBB_ROOT_PATH' => PHPBB_ROOT_PATH
,
745 'IMG_PATH' => $img_path,
747 'GROUP_ID' => $group_id,
748 'GROUP_NAME' => $ext_group_row['group_name'],
749 'ALLOW_GROUP' => $ext_group_row['allow_group'],
750 'ALLOW_IN_PM' => $ext_group_row['allow_in_pm'],
751 'UPLOAD_ICON_SRC' => PHPBB_ROOT_PATH
. $img_path . '/' . $ext_group_row['upload_icon'],
752 'EXTGROUP_FILESIZE' => $ext_group_row['max_filesize'],
753 'ASSIGNED_EXTENSIONS' => $assigned_extensions,
755 'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'),
756 'S_EXT_GROUP_SIZE_OPTIONS' => size_select_options($size_format),
757 'S_EXTENSION_OPTIONS' => $s_extension_options,
758 'S_FILENAME_LIST' => $filename_list,
759 'S_EDIT_GROUP' => true,
760 'S_NO_IMAGE' => $no_image_select,
761 'S_FORUM_IDS' => (sizeof($forum_ids)) ?
true : false,
763 'U_EXTENSIONS' => append_sid(PHPBB_ADMIN_PATH
. 'index.' . PHP_EXT
, "i=$id&mode=extensions"),
764 'U_BACK' => $this->u_action
,
766 'L_LEGEND' => $user->lang
[strtoupper($action) . '_EXTENSION_GROUP'])
769 $s_forum_id_options = '';
771 $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
772 FROM ' . FORUMS_TABLE
. '
773 ORDER BY left_id ASC';
774 $result = $db->sql_query($sql, 600);
776 $right = $cat_right = $padding_inc = 0;
777 $padding = $forum_list = $holding = '';
778 $padding_store = array('0' => '');
780 while ($row = $db->sql_fetchrow($result))
782 if ($row['forum_type'] == FORUM_CAT
&& ($row['left_id'] +
1 == $row['right_id']))
784 // Non-postable forum with no subforums, don't display
788 if (!$auth->acl_get('f_list', $row['forum_id']))
790 // if the user does not have permissions to list this forum skip
794 if ($row['left_id'] < $right)
796 $padding .= ' ';
797 $padding_store[$row['parent_id']] = $padding;
799 else if ($row['left_id'] > $right +
1)
801 $padding = $padding_store[$row['parent_id']];
804 $right = $row['right_id'];
806 $selected = (in_array($row['forum_id'], $forum_ids)) ?
' selected="selected"' : '';
808 if ($row['left_id'] > $cat_right)
810 // make sure we don't forget anything
811 $s_forum_id_options .= $holding;
815 if ($row['right_id'] - $row['left_id'] > 1)
817 $cat_right = max($cat_right, $row['right_id']);
819 $holding .= '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST
) ?
' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
823 $s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST
) ?
' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
830 $s_forum_id_options .= $holding;
833 $db->sql_freeresult($result);
834 unset($padding_store);
836 $template->assign_vars(array(
837 'S_FORUM_ID_OPTIONS' => $s_forum_id_options)
844 FROM ' . EXTENSION_GROUPS_TABLE
. '
845 ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
846 $result = $db->sql_query($sql);
848 $old_allow_group = $old_allow_pm = 1;
849 while ($row = $db->sql_fetchrow($result))
851 $s_add_spacer = ($old_allow_group != $row['allow_group'] ||
$old_allow_pm != $row['allow_in_pm']) ?
true : false;
853 $template->assign_block_vars('groups', array(
854 'S_ADD_SPACER' => $s_add_spacer,
855 'S_ALLOWED_IN_PM' => ($row['allow_in_pm']) ?
true : false,
856 'S_GROUP_ALLOWED' => ($row['allow_group']) ?
true : false,
858 'U_EDIT' => $this->u_action
. "&action=edit&g={$row['group_id']}",
859 'U_DELETE' => $this->u_action
. "&action=delete&g={$row['group_id']}",
861 'GROUP_NAME' => $row['group_name'],
862 'CATEGORY' => $cat_lang[$row['cat_id']],
866 $old_allow_group = $row['allow_group'];
867 $old_allow_pm = $row['allow_in_pm'];
869 $db->sql_freeresult($result);
877 $delete_files = (isset($_POST['delete'])) ?
array_keys(request_var('delete', array('' => 0))) : array();
878 $add_files = (isset($_POST['add'])) ?
array_keys(request_var('add', array('' => 0))) : array();
879 $post_ids = request_var('post_id', array('' => 0));
881 if (sizeof($delete_files))
884 FROM ' . ATTACHMENTS_TABLE
. '
885 WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
887 $result = $db->sql_query($sql);
889 $delete_files = array();
890 while ($row = $db->sql_fetchrow($result))
892 phpbb_unlink($row['physical_filename'], 'file');
894 if ($row['thumbnail'])
896 phpbb_unlink($row['physical_filename'], 'thumbnail');
899 $delete_files[$row['attach_id']] = $row['real_filename'];
901 $db->sql_freeresult($result);
904 if (sizeof($delete_files))
906 $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE
. '
907 WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
908 $db->sql_query($sql);
910 add_log('admin', 'LOG_ATTACH_ORPHAN_DEL', implode(', ', $delete_files));
911 $notify[] = sprintf($user->lang
['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files));
914 $upload_list = array();
915 foreach ($add_files as $attach_id)
917 if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id]))
919 $upload_list[$attach_id] = $post_ids[$attach_id];
924 if (sizeof($upload_list))
926 $template->assign_var('S_UPLOADING_FILES', true);
928 $sql = 'SELECT forum_id, forum_name
929 FROM ' . FORUMS_TABLE
;
930 $result = $db->sql_query($sql);
932 $forum_names = array();
933 while ($row = $db->sql_fetchrow($result))
935 $forum_names[$row['forum_id']] = $row['forum_name'];
937 $db->sql_freeresult($result);
939 $sql = 'SELECT forum_id, topic_id, post_id, poster_id
940 FROM ' . POSTS_TABLE
. '
941 WHERE ' . $db->sql_in_set('post_id', $upload_list);
942 $result = $db->sql_query($sql);
944 $post_info = array();
945 while ($row = $db->sql_fetchrow($result))
947 $post_info[$row['post_id']] = $row;
949 $db->sql_freeresult($result);
951 // Select those attachments we want to change...
953 FROM ' . ATTACHMENTS_TABLE
. '
954 WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
956 $result = $db->sql_query($sql);
958 $files_added = $space_taken = 0;
959 while ($row = $db->sql_fetchrow($result))
961 $post_row = $post_info[$upload_list[$row['attach_id']]];
963 $template->assign_block_vars('upload', array(
964 'FILE_INFO' => sprintf($user->lang
['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']),
965 'S_DENIED' => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ?
true : false,
966 'L_DENIED' => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ?
sprintf($user->lang
['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : '')
969 if (!$auth->acl_get('f_attach', $post_row['forum_id']))
974 // Adjust attachment entry
978 'poster_id' => $post_row['poster_id'],
979 'post_msg_id' => $post_row['post_id'],
980 'topic_id' => $post_row['topic_id'],
983 $sql = 'UPDATE ' . ATTACHMENTS_TABLE
. '
984 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
985 WHERE attach_id = ' . $row['attach_id'];
986 $db->sql_query($sql);
988 $sql = 'UPDATE ' . POSTS_TABLE
. '
989 SET post_attachment = 1
990 WHERE post_id = ' . $post_row['post_id'];
991 $db->sql_query($sql);
993 $sql = 'UPDATE ' . TOPICS_TABLE
. '
994 SET topic_attachment = 1
995 WHERE topic_id = ' . $post_row['topic_id'];
996 $db->sql_query($sql);
998 $space_taken +
= $row['filesize'];
1001 add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']);
1003 $db->sql_freeresult($result);
1007 set_config('upload_dir_size', $config['upload_dir_size'] +
$space_taken, true);
1008 set_config('num_files', $config['num_files'] +
$files_added, true);
1013 $template->assign_vars(array(
1017 // Just get the files with is_orphan set and older than 3 hours
1019 FROM ' . ATTACHMENTS_TABLE
. '
1021 AND filetime < ' . (time() - 3*60*60) . '
1022 ORDER BY filetime DESC';
1023 $result = $db->sql_query($sql);
1025 while ($row = $db->sql_fetchrow($result))
1027 $template->assign_block_vars('orphan', array(
1028 'FILESIZE' => get_formatted_filesize($row['filesize']),
1029 'FILETIME' => $user->format_date($row['filetime']),
1030 'REAL_FILENAME' => basename($row['real_filename']),
1031 'PHYSICAL_FILENAME' => basename($row['physical_filename']),
1032 'ATTACH_ID' => $row['attach_id'],
1033 'POST_IDS' => (!empty($post_ids[$row['attach_id']])) ?
$post_ids[$row['attach_id']] : '',
1034 'U_FILE' => append_sid('download/file', 'mode=view&id=' . $row['attach_id']))
1037 $db->sql_freeresult($result);
1044 $template->assign_vars(array(
1045 'S_WARNING' => true,
1046 'WARNING_MSG' => implode('<br />', $error))
1050 if (sizeof($notify))
1052 $template->assign_vars(array(
1054 'NOTIFY_MSG' => implode('<br />', $notify))
1060 * Build Select for category items
1062 function category_select($select_name, $group_id = false, $key = '')
1067 ATTACHMENT_CATEGORY_NONE
=> $user->lang
['NO_FILE_CAT'],
1068 ATTACHMENT_CATEGORY_IMAGE
=> $user->lang
['CAT_IMAGES'],
1069 ATTACHMENT_CATEGORY_WM
=> $user->lang
['CAT_WM_FILES'],
1070 ATTACHMENT_CATEGORY_RM
=> $user->lang
['CAT_RM_FILES'],
1071 ATTACHMENT_CATEGORY_FLASH
=> $user->lang
['CAT_FLASH_FILES'],
1072 ATTACHMENT_CATEGORY_QUICKTIME
=> $user->lang
['CAT_QUICKTIME_FILES'],
1077 $sql = 'SELECT cat_id
1078 FROM ' . EXTENSION_GROUPS_TABLE
. '
1079 WHERE group_id = ' . (int) $group_id;
1080 $result = $db->sql_query($sql);
1082 $cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE
: $row['cat_id'];
1084 $db->sql_freeresult($result);
1088 $cat_type = ATTACHMENT_CATEGORY_NONE
;
1091 $group_select = '<select name="' . $select_name . '"' . (($key) ?
' id="' . $key . '"' : '') . '>';
1093 foreach ($types as $type => $mode)
1095 $selected = ($type == $cat_type) ?
' selected="selected"' : '';
1096 $group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>';
1099 $group_select .= '</select>';
1101 return $group_select;
1105 * Extension group select
1107 function group_select($select_name, $default_group = false, $key = '')
1111 $group_select = '<select name="' . $select_name . '"' . (($key) ?
' id="' . $key . '"' : '') . '>';
1113 $sql = 'SELECT group_id, group_name
1114 FROM ' . EXTENSION_GROUPS_TABLE
. '
1115 ORDER BY group_name';
1116 $result = $db->sql_query($sql);
1118 $group_name = array();
1119 while ($row = $db->sql_fetchrow($result))
1121 $group_name[] = $row;
1123 $db->sql_freeresult($result);
1125 $row['group_id'] = 0;
1126 $row['group_name'] = $user->lang
['NOT_ASSIGNED'];
1127 $group_name[] = $row;
1129 for ($i = 0; $i < sizeof($group_name); $i++
)
1131 if ($default_group === false)
1133 $selected = ($i == 0) ?
' selected="selected"' : '';
1137 $selected = ($group_name[$i]['group_id'] == $default_group) ?
' selected="selected"' : '';
1140 $group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>';
1143 $group_select .= '</select>';
1145 return $group_select;
1151 function search_imagemagick()
1155 $exe = ((defined('PHP_OS')) && (preg_match('#^win#i', PHP_OS
))) ?
'.exe' : '';
1157 $magic_home = getenv('MAGICK_HOME');
1159 if (empty($magic_home))
1161 $locations = array('C:/WINDOWS/', 'C:/WINNT/', 'C:/WINDOWS/SYSTEM/', 'C:/WINNT/SYSTEM/', 'C:/WINDOWS/SYSTEM32/', 'C:/WINNT/SYSTEM32/', '/usr/bin/', '/usr/sbin/', '/usr/local/bin/', '/usr/local/sbin/', '/opt/', '/usr/imagemagick/', '/usr/bin/imagemagick/');
1162 $path_locations = str_replace('\\', '/', (explode(($exe) ?
';' : ':', getenv('PATH'))));
1164 $locations = array_merge($path_locations, $locations);
1166 foreach ($locations as $location)
1168 // The path might not end properly, fudge it
1169 if (substr($location, -1) !== '/')
1174 if (@is_readable
($location . 'mogrify' . $exe) && @filesize
($location . 'mogrify' . $exe) > 3000)
1176 $imagick = str_replace('\\', '/', $location);
1183 $imagick = str_replace('\\', '/', $magic_home);
1192 function test_upload(&$error, $upload_dir, $create_directory = false)
1196 // Does the target directory exist, is it a directory and writable.
1197 if ($create_directory)
1199 if (!file_exists(PHPBB_ROOT_PATH
. $upload_dir))
1201 @mkdir
(PHPBB_ROOT_PATH
. $upload_dir, 0777);
1202 phpbb_chmod(PHPBB_ROOT_PATH
. $upload_dir, CHMOD_READ | CHMOD_WRITE
);
1206 if (!file_exists(PHPBB_ROOT_PATH
. $upload_dir))
1208 $error[] = sprintf($user->lang
['NO_UPLOAD_DIR'], $upload_dir);
1212 if (!is_dir(PHPBB_ROOT_PATH
. $upload_dir))
1214 $error[] = sprintf($user->lang
['UPLOAD_NOT_DIR'], $upload_dir);
1218 if (!is_writable(PHPBB_ROOT_PATH
. $upload_dir))
1220 $error[] = sprintf($user->lang
['NO_WRITE_UPLOAD'], $upload_dir);
1226 * Perform operations on sites for external linking
1228 function perform_site_list()
1232 if (isset($_REQUEST['securesubmit']))
1234 // Grab the list of entries
1235 $ips = request_var('ips', '');
1236 $ip_list = array_unique(explode("\n", $ips));
1237 $ip_list_log = implode(', ', $ip_list);
1239 $ip_exclude = (!empty($_POST['ipexclude'])) ?
1 : 0;
1242 $hostlist = array();
1244 foreach ($ip_list as $item)
1246 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))
1248 // Don't ask about all this, just don't ask ... !
1249 $ip_1_counter = $ip_range_explode[1];
1250 $ip_1_end = $ip_range_explode[5];
1252 while ($ip_1_counter <= $ip_1_end)
1254 $ip_2_counter = ($ip_1_counter == $ip_range_explode[1]) ?
$ip_range_explode[2] : 0;
1255 $ip_2_end = ($ip_1_counter < $ip_1_end) ?
254 : $ip_range_explode[6];
1257 if ($ip_2_counter == 0 && $ip_2_end == 254)
1259 $ip_2_counter = 256;
1260 $ip_2_fragment = 256;
1262 $iplist[] = "'$ip_1_counter.*'";
1265 while ($ip_2_counter <= $ip_2_end)
1267 $ip_3_counter = ($ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ?
$ip_range_explode[3] : 0;
1268 $ip_3_end = ($ip_2_counter < $ip_2_end ||
$ip_1_counter < $ip_1_end) ?
254 : $ip_range_explode[7];
1270 if ($ip_3_counter == 0 && $ip_3_end == 254)
1272 $ip_3_counter = 256;
1273 $ip_3_fragment = 256;
1275 $iplist[] = "'$ip_1_counter.$ip_2_counter.*'";
1278 while ($ip_3_counter <= $ip_3_end)
1280 $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;
1281 $ip_4_end = ($ip_3_counter < $ip_3_end ||
$ip_2_counter < $ip_2_end) ?
254 : $ip_range_explode[8];
1283 if ($ip_4_counter == 0 && $ip_4_end == 254)
1285 $ip_4_counter = 256;
1286 $ip_4_fragment = 256;
1288 $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.*'";
1291 while ($ip_4_counter <= $ip_4_end)
1293 $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter'";
1303 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)))
1305 $iplist[] = "'" . trim($item) . "'";
1307 else if (preg_match('#^([\w\-_]\.?){2,}$#is', trim($item)))
1309 $hostlist[] = "'" . trim($item) . "'";
1311 else if (preg_match("#^([a-z0-9\-\*\._/]+?)$#is", trim($item)))
1313 $hostlist[] = "'" . trim($item) . "'";
1317 $sql = 'SELECT site_ip, site_hostname
1318 FROM ' . SITELIST_TABLE
. "
1319 WHERE ip_exclude = $ip_exclude";
1320 $result = $db->sql_query($sql);
1322 if ($row = $db->sql_fetchrow($result))
1324 $iplist_tmp = array();
1325 $hostlist_tmp = array();
1328 if ($row['site_ip'])
1330 if (strlen($row['site_ip']) > 40)
1335 $iplist_tmp[] = "'" . $row['site_ip'] . "'";
1337 else if ($row['site_hostname'])
1339 if (strlen($row['site_hostname']) > 255)
1344 $hostlist_tmp[] = "'" . $row['site_hostname'] . "'";
1348 while ($row = $db->sql_fetchrow($result));
1350 $iplist = array_unique(array_diff($iplist, $iplist_tmp));
1351 $hostlist = array_unique(array_diff($hostlist, $hostlist_tmp));
1353 unset($hostlist_tmp);
1355 $db->sql_freeresult($result);
1357 if (sizeof($iplist))
1359 foreach ($iplist as $ip_entry)
1361 $sql = 'INSERT INTO ' . SITELIST_TABLE
. " (site_ip, ip_exclude)
1362 VALUES ($ip_entry, $ip_exclude)";
1363 $db->sql_query($sql);
1367 if (sizeof($hostlist))
1369 foreach ($hostlist as $host_entry)
1371 $sql = 'INSERT INTO ' . SITELIST_TABLE
. " (site_hostname, ip_exclude)
1372 VALUES ($host_entry, $ip_exclude)";
1373 $db->sql_query($sql);
1377 if (!empty($ip_list_log))
1380 $log_entry = ($ip_exclude) ?
'LOG_DOWNLOAD_EXCLUDE_IP' : 'LOG_DOWNLOAD_IP';
1381 add_log('admin', $log_entry, $ip_list_log);
1384 trigger_error($user->lang
['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action
));
1386 else if (isset($_POST['unsecuresubmit']))
1388 $unip_sql = request_var('unip', array(0));
1390 if (sizeof($unip_sql))
1394 // Grab details of ips for logging information later
1395 $sql = 'SELECT site_ip, site_hostname
1396 FROM ' . SITELIST_TABLE
. '
1397 WHERE ' . $db->sql_in_set('site_id', $unip_sql);
1398 $result = $db->sql_query($sql);
1400 while ($row = $db->sql_fetchrow($result))
1402 $l_unip_list .= (($l_unip_list != '') ?
', ' : '') . (($row['site_ip']) ?
$row['site_ip'] : $row['site_hostname']);
1404 $db->sql_freeresult($result);
1406 $sql = 'DELETE FROM ' . SITELIST_TABLE
. '
1407 WHERE ' . $db->sql_in_set('site_id', $unip_sql);
1408 $db->sql_query($sql);
1410 add_log('admin', 'LOG_DOWNLOAD_REMOVE_IP', $l_unip_list);
1413 trigger_error($user->lang
['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action
));
1418 * Write display_order config field
1420 function display_order($value, $key = '')
1422 $radio_ary = array(0 => 'DESCENDING', 1 => 'ASCENDING');
1424 return h_radio('config[display_order]', $radio_ary, $value, $key);
1428 * Adjust all three max_filesize config vars for display
1430 function max_filesize($value, $key = '')
1432 // Determine size var and adjust the value accordingly
1433 $size_var = ($value >= 1048576) ?
'mb' : (($value >= 1024) ?
'kb' : 'b');
1434 $value = get_formatted_filesize($value, false);
1436 return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
1440 * Write secure_allow_deny config field
1442 function select_allow_deny($value, $key = '')
1444 $radio_ary = array(1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW');
1446 return h_radio('config[' . $key . ']', $radio_ary, $value, $key);