Blame Extras/phpBB/3.0.4/includes/acp/acp_attachments.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package acp
4c79b5
* @version $Id: acp_attachments.php 9041 2008-11-02 11:19:12Z acydburn $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* @package acp
4c79b5
*/
4c79b5
class acp_attachments
4c79b5
{
4c79b5
	var $u_action;
4c79b5
	var $new_config;
4c79b5
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $db, $user, $auth, $template, $cache;
4c79b5
		global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
4c79b5
4c79b5
		$user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
4c79b5
4c79b5
		$error = $notify = array();
4c79b5
		$submit = (isset($_POST['submit'])) ? true : false;
4c79b5
		$action = request_var('action', '');
4c79b5
4c79b5
		$form_key = 'acp_attach';
4c79b5
		add_form_key($form_key);
4c79b5
4c79b5
		if ($submit && !check_form_key($form_key))
4c79b5
		{
4c79b5
			trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
		}
4c79b5
4c79b5
		switch ($mode)
4c79b5
		{
4c79b5
			case 'attach':
4c79b5
				$l_title = 'ACP_ATTACHMENT_SETTINGS';
4c79b5
			break;
4c79b5
4c79b5
			case 'extensions':
4c79b5
				$l_title = 'ACP_MANAGE_EXTENSIONS';
4c79b5
			break;
4c79b5
4c79b5
			case 'ext_groups':
4c79b5
				$l_title = 'ACP_EXTENSION_GROUPS';
4c79b5
			break;
4c79b5
4c79b5
			case 'orphan':
4c79b5
				$l_title = 'ACP_ORPHAN_ATTACHMENTS';
4c79b5
			break;
4c79b5
4c79b5
			default:
4c79b5
				trigger_error('NO_MODE', E_USER_ERROR);
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		$this->tpl_name = 'acp_attachments';
4c79b5
		$this->page_title = $l_title;
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'L_TITLE'			=> $user->lang[$l_title],
4c79b5
			'L_TITLE_EXPLAIN'	=> $user->lang[$l_title . '_EXPLAIN'],
4c79b5
			'U_ACTION'			=> $this->u_action)
4c79b5
		);
4c79b5
4c79b5
		switch ($mode)
4c79b5
		{
4c79b5
			case 'attach':
4c79b5
4c79b5
				include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
4c79b5
4c79b5
				$sql = 'SELECT group_name, cat_id
4c79b5
					FROM ' . EXTENSION_GROUPS_TABLE . '
4c79b5
					WHERE cat_id > 0
4c79b5
					ORDER BY cat_id';
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				$s_assigned_groups = array();
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$s_assigned_groups[$row['cat_id']][] = $row['group_name'];
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$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']) . ']';
4c79b5
4c79b5
				$display_vars = array(
4c79b5
					'title'	=> 'ACP_ATTACHMENT_SETTINGS',
4c79b5
					'vars'	=> array(
4c79b5
						'legend1'				=> 'ACP_ATTACHMENT_SETTINGS',
4c79b5
4c79b5
						'img_max_width'			=> array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
4c79b5
						'img_max_height'		=> array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
4c79b5
						'img_link_width'		=> array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
4c79b5
						'img_link_height'		=> array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
4c79b5
4c79b5
						'allow_attachments'		=> array('lang' => 'ALLOW_ATTACHMENTS',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => false),
4c79b5
						'allow_pm_attach'		=> array('lang' => 'ALLOW_PM_ATTACHMENTS',	'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => false),
4c79b5
						'upload_path'			=> array('lang' => 'UPLOAD_DIR',			'validate' => 'wpath',	'type' => 'text:25:100', 'explain' => true),
4c79b5
						'display_order'			=> array('lang' => 'DISPLAY_ORDER',			'validate' => 'bool',	'type' => 'custom', 'method' => 'display_order', 'explain' => true),
4c79b5
						'attachment_quota'		=> array('lang' => 'ATTACH_QUOTA',			'validate' => 'string',	'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
4c79b5
						'max_filesize'			=> array('lang' => 'ATTACH_MAX_FILESIZE',	'validate' => 'string',	'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
4c79b5
						'max_filesize_pm'		=> array('lang' => 'ATTACH_MAX_PM_FILESIZE','validate' => 'string',	'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
4c79b5
						'max_attachments'		=> array('lang' => 'MAX_ATTACHMENTS',		'validate' => 'int',	'type' => 'text:3:3', 'explain' => false),
4c79b5
						'max_attachments_pm'	=> array('lang' => 'MAX_ATTACHMENTS_PM',	'validate' => 'int',	'type' => 'text:3:3', 'explain' => false),
4c79b5
						'secure_downloads'		=> array('lang' => 'SECURE_DOWNLOADS',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
4c79b5
						'secure_allow_deny'		=> array('lang' => 'SECURE_ALLOW_DENY',		'validate' => 'int',	'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),
4c79b5
						'secure_allow_empty_referer'	=> array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
4c79b5
						'check_attachment_content' 		=> array('lang' => 'CHECK_CONTENT', 'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
4c79b5
4c79b5
4c79b5
						'legend2'					=> $l_legend_cat_images,
4c79b5
						'img_display_inlined'		=> array('lang' => 'DISPLAY_INLINED',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
4c79b5
						'img_create_thumbnail'		=> array('lang' => 'CREATE_THUMBNAIL',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
4c79b5
						'img_max_thumb_width'		=> array('lang' => 'MAX_THUMB_WIDTH',		'validate' => 'int',	'type' => 'text:7:15', 'explain' => true, 'append' => ' px'),
4c79b5
						'img_min_thumb_filesize'	=> array('lang' => 'MIN_THUMB_FILESIZE',	'validate' => 'int',	'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
4c79b5
						'img_imagick'				=> array('lang' => 'IMAGICK_PATH',			'validate' => 'string',	'type' => 'text:20:200', 'explain' => true, 'append' => '  [ ' . $user->lang['SEARCH_IMAGICK'] . ' ]'),
4c79b5
						'img_max'					=> array('lang' => 'MAX_IMAGE_SIZE',		'validate' => 'int',	'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
4c79b5
						'img_link'					=> array('lang' => 'IMAGE_LINK_SIZE',		'validate' => 'int',	'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
4c79b5
					)
4c79b5
				);
4c79b5
4c79b5
				$this->new_config = $config;
4c79b5
				$cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => '')) : $this->new_config;
4c79b5
				$error = array();
4c79b5
4c79b5
				// We validate the complete config if whished
4c79b5
				validate_config_vars($display_vars['vars'], $cfg_array, $error);
4c79b5
4c79b5
				// Do not write values if there is an error
4c79b5
				if (sizeof($error))
4c79b5
				{
4c79b5
					$submit = false;
4c79b5
				}
4c79b5
4c79b5
				// We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
4c79b5
				foreach ($display_vars['vars'] as $config_name => $null)
4c79b5
				{
4c79b5
					if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
4c79b5
					{
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					$this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
4c79b5
4c79b5
					if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm')))
4c79b5
					{
4c79b5
						$size_var = request_var($config_name, '');
4c79b5
						$this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
4c79b5
					}
4c79b5
4c79b5
					if ($submit)
4c79b5
					{
4c79b5
						set_config($config_name, $config_value);
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$this->perform_site_list();
4c79b5
4c79b5
				if ($submit)
4c79b5
				{
4c79b5
					add_log('admin', 'LOG_CONFIG_ATTACH');
4c79b5
4c79b5
					// Check Settings
4c79b5
					$this->test_upload($error, $this->new_config['upload_path'], false);
4c79b5
4c79b5
					if (!sizeof($error))
4c79b5
					{
4c79b5
						trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$template->assign_var('S_ATTACHMENT_SETTINGS', true);
4c79b5
4c79b5
				if ($action == 'imgmagick')
4c79b5
				{
4c79b5
					$this->new_config['img_imagick'] = $this->search_imagemagick();
4c79b5
				}
4c79b5
4c79b5
				// We strip eventually manual added convert program, we only want the patch
4c79b5
				if ($this->new_config['img_imagick'])
4c79b5
				{
4c79b5
					// Change path separator
4c79b5
					$this->new_config['img_imagick'] = str_replace('\\', '/', $this->new_config['img_imagick']);
4c79b5
					$this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']);
4c79b5
4c79b5
					// Check for trailing slash
4c79b5
					if (substr($this->new_config['img_imagick'], -1) !== '/')
4c79b5
					{
4c79b5
						$this->new_config['img_imagick'] .= '/';
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$supported_types = get_supported_image_types();
4c79b5
4c79b5
				// Check Thumbnail Support
4c79b5
				if (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format'])))
4c79b5
				{
4c79b5
					$this->new_config['img_create_thumbnail'] = 0;
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'U_SEARCH_IMAGICK'		=> $this->u_action . '&action=imgmagick',
4c79b5
					'S_THUMBNAIL_SUPPORT'	=> (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format']))) ? false : true)
4c79b5
				);
4c79b5
4c79b5
				// Secure Download Options - Same procedure as with banning
4c79b5
				$allow_deny = ($this->new_config['secure_allow_deny']) ? 'ALLOWED' : 'DISALLOWED';
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . SITELIST_TABLE;
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				$defined_ips = '';
4c79b5
				$ips = array();
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$value = ($row['site_ip']) ? $row['site_ip'] : $row['site_hostname'];
4c79b5
					if ($value)
4c79b5
					{
4c79b5
						$defined_ips .= '<option' . (($row['ip_exclude']) ? ' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>';
4c79b5
						$ips[$row['site_id']] = $value;
4c79b5
					}
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_SECURE_DOWNLOADS'	=> $this->new_config['secure_downloads'],
4c79b5
					'S_DEFINED_IPS'			=> ($defined_ips != '') ? true : false,
4c79b5
					'S_WARNING'				=> (sizeof($error)) ? true : false,
4c79b5
4c79b5
					'WARNING_MSG'			=> implode('
', $error),
4c79b5
					'DEFINED_IPS'			=> $defined_ips,
4c79b5
4c79b5
					'L_SECURE_TITLE'		=> $user->lang['DEFINE_' . $allow_deny . '_IPS'],
4c79b5
					'L_IP_EXCLUDE'			=> $user->lang['EXCLUDE_FROM_' . $allow_deny . '_IP'],
4c79b5
					'L_REMOVE_IPS'			=> $user->lang['REMOVE_' . $allow_deny . '_IPS'])
4c79b5
				);
4c79b5
4c79b5
				// Output relevant options
4c79b5
				foreach ($display_vars['vars'] as $config_key => $vars)
4c79b5
				{
4c79b5
					if (!is_array($vars) && strpos($config_key, 'legend') === false)
4c79b5
					{
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					if (strpos($config_key, 'legend') !== false)
4c79b5
					{
4c79b5
						$template->assign_block_vars('options', array(
4c79b5
							'S_LEGEND'		=> true,
4c79b5
							'LEGEND'		=> (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
4c79b5
						);
4c79b5
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					$type = explode(':', $vars['type']);
4c79b5
4c79b5
					$l_explain = '';
4c79b5
					if ($vars['explain'] && isset($vars['lang_explain']))
4c79b5
					{
4c79b5
						$l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
4c79b5
					}
4c79b5
					else if ($vars['explain'])
4c79b5
					{
4c79b5
						$l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
4c79b5
					}
4c79b5
4c79b5
					$content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
4c79b5
					if (empty($content))
4c79b5
					{
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					$template->assign_block_vars('options', array(
4c79b5
						'KEY'			=> $config_key,
4c79b5
						'TITLE'			=> $user->lang[$vars['lang']],
4c79b5
						'S_EXPLAIN'		=> $vars['explain'],
4c79b5
						'TITLE_EXPLAIN'	=> $l_explain,
4c79b5
						'CONTENT'		=> $content,
4c79b5
						)
4c79b5
					);
4c79b5
4c79b5
					unset($display_vars['vars'][$config_key]);
4c79b5
				}
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'extensions':
4c79b5
4c79b5
				if ($submit || isset($_POST['add_extension_check']))
4c79b5
				{
4c79b5
					if ($submit)
4c79b5
					{
4c79b5
						// Change Extensions ?
4c79b5
						$extension_change_list	= request_var('extension_change_list', array(0));
4c79b5
						$group_select_list		= request_var('group_select', array(0));
4c79b5
4c79b5
						// Generate correct Change List
4c79b5
						$extensions = array();
4c79b5
4c79b5
						for ($i = 0, $size = sizeof($extension_change_list); $i < $size; $i++)
4c79b5
						{
4c79b5
							$extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i];
4c79b5
						}
4c79b5
4c79b5
						$sql = 'SELECT *
4c79b5
							FROM ' . EXTENSIONS_TABLE . '
4c79b5
							ORDER BY extension_id';
4c79b5
						$result = $db->sql_query($sql);
4c79b5
4c79b5
						while ($row = $db->sql_fetchrow($result))
4c79b5
						{
4c79b5
							if ($row['group_id'] != $extensions[$row['extension_id']]['group_id'])
4c79b5
							{
4c79b5
								$sql = 'UPDATE ' . EXTENSIONS_TABLE . '
4c79b5
									SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . '
4c79b5
									WHERE extension_id = ' . $row['extension_id'];
4c79b5
								$db->sql_query($sql);
4c79b5
4c79b5
								add_log('admin', 'LOG_ATTACH_EXT_UPDATE', $row['extension']);
4c79b5
							}
4c79b5
						}
4c79b5
						$db->sql_freeresult($result);
4c79b5
4c79b5
						// Delete Extension?
4c79b5
						$extension_id_list = request_var('extension_id_list', array(0));
4c79b5
4c79b5
						if (sizeof($extension_id_list))
4c79b5
						{
4c79b5
							$sql = 'SELECT extension
4c79b5
								FROM ' . EXTENSIONS_TABLE . '
4c79b5
								WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
4c79b5
							$result = $db->sql_query($sql);
4c79b5
4c79b5
							$extension_list = '';
4c79b5
							while ($row = $db->sql_fetchrow($result))
4c79b5
							{
4c79b5
								$extension_list .= ($extension_list == '') ? $row['extension'] : ', ' . $row['extension'];
4c79b5
							}
4c79b5
							$db->sql_freeresult($result);
4c79b5
4c79b5
							$sql = 'DELETE
4c79b5
								FROM ' . EXTENSIONS_TABLE . '
4c79b5
								WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							add_log('admin', 'LOG_ATTACH_EXT_DEL', $extension_list);
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					// Add Extension?
4c79b5
					$add_extension			= strtolower(request_var('add_extension', ''));
4c79b5
					$add_extension_group	= request_var('add_group_select', 0);
4c79b5
					$add					= (isset($_POST['add_extension_check'])) ? true : false;
4c79b5
4c79b5
					if ($add_extension && $add)
4c79b5
					{
4c79b5
						if (!sizeof($error))
4c79b5
						{
4c79b5
							$sql = 'SELECT extension_id
4c79b5
								FROM ' . EXTENSIONS_TABLE . "
4c79b5
								WHERE extension = '" . $db->sql_escape($add_extension) . "'";
4c79b5
							$result = $db->sql_query($sql);
4c79b5
4c79b5
							if ($row = $db->sql_fetchrow($result))
4c79b5
							{
4c79b5
								$error[] = sprintf($user->lang['EXTENSION_EXIST'], $add_extension);
4c79b5
							}
4c79b5
							$db->sql_freeresult($result);
4c79b5
4c79b5
							if (!sizeof($error))
4c79b5
							{
4c79b5
								$sql_ary = array(
4c79b5
									'group_id'	=>	$add_extension_group,
4c79b5
									'extension'	=>	$add_extension
4c79b5
								);
4c79b5
4c79b5
								$db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
4c79b5
								add_log('admin', 'LOG_ATTACH_EXT_ADD', $add_extension);
4c79b5
							}
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					if (!sizeof($error))
4c79b5
					{
4c79b5
						$notify[] = $user->lang['EXTENSIONS_UPDATED'];
4c79b5
					}
4c79b5
4c79b5
					$cache->destroy('_extensions');
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_EXTENSIONS'			=> true,
4c79b5
					'ADD_EXTENSION'			=> (isset($add_extension)) ? $add_extension : '',
4c79b5
					'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'))
4c79b5
				);
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . EXTENSIONS_TABLE . '
4c79b5
					ORDER BY group_id, extension';
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				if ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$old_group_id = $row['group_id'];
4c79b5
					do
4c79b5
					{
4c79b5
						$s_spacer = false;
4c79b5
4c79b5
						$current_group_id = $row['group_id'];
4c79b5
						if ($old_group_id != $current_group_id)
4c79b5
						{
4c79b5
							$s_spacer = true;
4c79b5
							$old_group_id = $current_group_id;
4c79b5
						}
4c79b5
4c79b5
						$template->assign_block_vars('extensions', array(
4c79b5
							'S_SPACER'		=> $s_spacer,
4c79b5
							'EXTENSION_ID'	=> $row['extension_id'],
4c79b5
							'EXTENSION'		=> $row['extension'],
4c79b5
							'GROUP_OPTIONS'	=> $this->group_select('group_select[]', $row['group_id']))
4c79b5
						);
4c79b5
					}
4c79b5
					while ($row = $db->sql_fetchrow($result));
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'ext_groups':
4c79b5
4c79b5
				$template->assign_var('S_EXTENSION_GROUPS', true);
4c79b5
4c79b5
				if ($submit)
4c79b5
				{
4c79b5
					$action = request_var('action', '');
4c79b5
					$group_id = request_var('g', 0);
4c79b5
4c79b5
					if ($action != 'add' && $action != 'edit')
4c79b5
					{
4c79b5
						trigger_error('NO_MODE', E_USER_ERROR);
4c79b5
					}
4c79b5
4c79b5
					if (!$group_id && $action == 'edit')
4c79b5
					{
4c79b5
						trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					if ($group_id)
4c79b5
					{
4c79b5
						$sql = 'SELECT *
4c79b5
							FROM ' . EXTENSION_GROUPS_TABLE . "
4c79b5
							WHERE group_id = $group_id";
4c79b5
						$result = $db->sql_query($sql);
4c79b5
						$ext_row = $db->sql_fetchrow($result);
4c79b5
						$db->sql_freeresult($result);
4c79b5
4c79b5
						if (!$ext_row)
4c79b5
						{
4c79b5
							trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
						}
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$ext_row = array();
4c79b5
					}
4c79b5
4c79b5
					$group_name = utf8_normalize_nfc(request_var('group_name', '', true));
4c79b5
					$new_group_name = ($action == 'add') ? $group_name : (($ext_row['group_name'] != $group_name) ? $group_name : '');
4c79b5
4c79b5
					if (!$group_name)
4c79b5
					{
4c79b5
						$error[] = $user->lang['NO_EXT_GROUP_NAME'];
4c79b5
					}
4c79b5
4c79b5
					// Check New Group Name
4c79b5
					if ($new_group_name)
4c79b5
					{
4c79b5
						$sql = 'SELECT group_id
4c79b5
							FROM ' . EXTENSION_GROUPS_TABLE . "
4c79b5
							WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";
4c79b5
						$result = $db->sql_query($sql);
4c79b5
4c79b5
						if ($db->sql_fetchrow($result))
4c79b5
						{
4c79b5
							$error[] = sprintf($user->lang['EXTENSION_GROUP_EXIST'], $new_group_name);
4c79b5
						}
4c79b5
						$db->sql_freeresult($result);
4c79b5
					}
4c79b5
4c79b5
					if (!sizeof($error))
4c79b5
					{
4c79b5
						// Ok, build the update/insert array
4c79b5
						$upload_icon	= request_var('upload_icon', 'no_image');
4c79b5
						$size_select	= request_var('size_select', 'b');
4c79b5
						$forum_select	= request_var('forum_select', false);
4c79b5
						$allowed_forums	= request_var('allowed_forums', array(0));
4c79b5
						$allow_in_pm	= (isset($_POST['allow_in_pm'])) ? true : false;
4c79b5
						$max_filesize	= request_var('max_filesize', 0);
4c79b5
						$max_filesize	= ($size_select == 'kb') ? round($max_filesize * 1024) : (($size_select == 'mb') ? round($max_filesize * 1048576) : $max_filesize);
4c79b5
						$allow_group	= (isset($_POST['allow_group'])) ? true : false;
4c79b5
4c79b5
						if ($max_filesize == $config['max_filesize'])
4c79b5
						{
4c79b5
							$max_filesize = 0;
4c79b5
						}
4c79b5
4c79b5
						if (!sizeof($allowed_forums))
4c79b5
						{
4c79b5
							$forum_select = false;
4c79b5
						}
4c79b5
4c79b5
						$group_ary = array(
4c79b5
							'group_name'	=> $group_name,
4c79b5
							'cat_id'		=> request_var('special_category', ATTACHMENT_CATEGORY_NONE),
4c79b5
							'allow_group'	=> ($allow_group) ? 1 : 0,
4c79b5
							'upload_icon'	=> ($upload_icon == 'no_image') ? '' : $upload_icon,
4c79b5
							'max_filesize'	=> $max_filesize,
4c79b5
							'allowed_forums'=> ($forum_select) ? serialize($allowed_forums) : '',
4c79b5
							'allow_in_pm'	=> ($allow_in_pm) ? 1 : 0,
4c79b5
						);
4c79b5
4c79b5
						if ($action == 'add')
4c79b5
						{
4c79b5
							$group_ary['download_mode'] = INLINE_LINK;
4c79b5
						}
4c79b5
4c79b5
						$sql = ($action == 'add') ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ';
4c79b5
						$sql .= $db->sql_build_array((($action == 'add') ? 'INSERT' : 'UPDATE'), $group_ary);
4c79b5
						$sql .= ($action == 'edit') ? " WHERE group_id = $group_id" : '';
4c79b5
4c79b5
						$db->sql_query($sql);
4c79b5
4c79b5
						if ($action == 'add')
4c79b5
						{
4c79b5
							$group_id = $db->sql_nextid();
4c79b5
						}
4c79b5
4c79b5
						add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name);
4c79b5
					}
4c79b5
4c79b5
					$extension_list = request_var('extensions', array(0));
4c79b5
4c79b5
					if ($action == 'edit' && sizeof($extension_list))
4c79b5
					{
4c79b5
						$sql = 'UPDATE ' . EXTENSIONS_TABLE . "
4c79b5
							SET group_id = 0
4c79b5
							WHERE group_id = $group_id";
4c79b5
						$db->sql_query($sql);
4c79b5
					}
4c79b5
4c79b5
					if (sizeof($extension_list))
4c79b5
					{
4c79b5
						$sql = 'UPDATE ' . EXTENSIONS_TABLE . "
4c79b5
							SET group_id = $group_id
4c79b5
							WHERE " . $db->sql_in_set('extension_id', $extension_list);
4c79b5
						$db->sql_query($sql);
4c79b5
					}
4c79b5
4c79b5
					$cache->destroy('_extensions');
4c79b5
4c79b5
					if (!sizeof($error))
4c79b5
					{
4c79b5
						$notify[] = $user->lang['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)];
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$cat_lang = array(
4c79b5
					ATTACHMENT_CATEGORY_NONE		=> $user->lang['NO_FILE_CAT'],
4c79b5
					ATTACHMENT_CATEGORY_IMAGE		=> $user->lang['CAT_IMAGES'],
4c79b5
					ATTACHMENT_CATEGORY_WM			=> $user->lang['CAT_WM_FILES'],
4c79b5
					ATTACHMENT_CATEGORY_RM			=> $user->lang['CAT_RM_FILES'],
4c79b5
					ATTACHMENT_CATEGORY_FLASH		=> $user->lang['CAT_FLASH_FILES'],
4c79b5
					ATTACHMENT_CATEGORY_QUICKTIME	=> $user->lang['CAT_QUICKTIME_FILES'],
4c79b5
				);
4c79b5
4c79b5
				$group_id = request_var('g', 0);
4c79b5
				$action = (isset($_POST['add'])) ? 'add' : $action;
4c79b5
4c79b5
				switch ($action)
4c79b5
				{
4c79b5
					case 'delete':
4c79b5
4c79b5
						if (confirm_box(true))
4c79b5
						{
4c79b5
							$sql = 'SELECT group_name
4c79b5
								FROM ' . EXTENSION_GROUPS_TABLE . "
4c79b5
								WHERE group_id = $group_id";
4c79b5
							$result = $db->sql_query($sql);
4c79b5
							$group_name = (string) $db->sql_fetchfield('group_name');
4c79b5
							$db->sql_freeresult($result);
4c79b5
4c79b5
							$sql = 'DELETE
4c79b5
								FROM ' . EXTENSION_GROUPS_TABLE . "
4c79b5
								WHERE group_id = $group_id";
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							// Set corresponding Extensions to a pending Group
4c79b5
							$sql = 'UPDATE ' . EXTENSIONS_TABLE . "
4c79b5
								SET group_id = 0
4c79b5
								WHERE group_id = $group_id";
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							add_log('admin', 'LOG_ATTACH_EXTGROUP_DEL', $group_name);
4c79b5
4c79b5
							$cache->destroy('_extensions');
4c79b5
4c79b5
							trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action));
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
								'i'			=> $id,
4c79b5
								'mode'		=> $mode,
4c79b5
								'group_id'	=> $group_id,
4c79b5
								'action'	=> 'delete',
4c79b5
							)));
4c79b5
						}
4c79b5
4c79b5
					break;
4c79b5
4c79b5
					case 'edit':
4c79b5
4c79b5
						if (!$group_id)
4c79b5
						{
4c79b5
							trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
						}
4c79b5
4c79b5
						$sql = 'SELECT *
4c79b5
							FROM ' . EXTENSION_GROUPS_TABLE . "
4c79b5
							WHERE group_id = $group_id";
4c79b5
						$result = $db->sql_query($sql);
4c79b5
						$ext_group_row = $db->sql_fetchrow($result);
4c79b5
						$db->sql_freeresult($result);
4c79b5
4c79b5
						$forum_ids = (!$ext_group_row['allowed_forums']) ? array() : unserialize(trim($ext_group_row['allowed_forums']));
4c79b5
4c79b5
					// no break;
4c79b5
4c79b5
					case 'add':
4c79b5
4c79b5
						if ($action == 'add')
4c79b5
						{
4c79b5
							$ext_group_row = array(
4c79b5
								'group_name'	=> utf8_normalize_nfc(request_var('group_name', '', true)),
4c79b5
								'cat_id'		=> 0,
4c79b5
								'allow_group'	=> 1,
4c79b5
								'allow_in_pm'	=> 1,
4c79b5
								'upload_icon'	=> '',
4c79b5
								'max_filesize'	=> 0,
4c79b5
							);
4c79b5
4c79b5
							$forum_ids = array();
4c79b5
						}
4c79b5
4c79b5
						$extensions = array();
4c79b5
4c79b5
						$sql = 'SELECT *
4c79b5
							FROM ' . EXTENSIONS_TABLE . "
4c79b5
							WHERE group_id = $group_id
4c79b5
								OR group_id = 0
4c79b5
							ORDER BY extension";
4c79b5
						$result = $db->sql_query($sql);
4c79b5
						$extensions = $db->sql_fetchrowset($result);
4c79b5
						$db->sql_freeresult($result);
4c79b5
4c79b5
						if ($ext_group_row['max_filesize'] == 0)
4c79b5
						{
4c79b5
							$ext_group_row['max_filesize'] = (int) $config['max_filesize'];
4c79b5
						}
4c79b5
4c79b5
						$size_format = ($ext_group_row['max_filesize'] >= 1048576) ? 'mb' : (($ext_group_row['max_filesize'] >= 1024) ? 'kb' : 'b');
4c79b5
						$ext_group_row['max_filesize'] = get_formatted_filesize($ext_group_row['max_filesize'], false);
4c79b5
4c79b5
						$img_path = $config['upload_icons_path'];
4c79b5
4c79b5
						$filename_list = '';
4c79b5
						$no_image_select = false;
4c79b5
4c79b5
						$imglist = filelist($phpbb_root_path . $img_path);
4c79b5
4c79b5
						if (sizeof($imglist))
4c79b5
						{
4c79b5
							$imglist = array_values($imglist);
4c79b5
							$imglist = $imglist[0];
4c79b5
4c79b5
							foreach ($imglist as $key => $img)
4c79b5
							{
4c79b5
								if (!$ext_group_row['upload_icon'])
4c79b5
								{
4c79b5
									$no_image_select = true;
4c79b5
									$selected = '';
4c79b5
								}
4c79b5
								else
4c79b5
								{
4c79b5
									$selected = ($ext_group_row['upload_icon'] == $img) ? ' selected="selected"' : '';
4c79b5
								}
4c79b5
4c79b5
								if (strlen($img) > 255)
4c79b5
								{
4c79b5
									continue;
4c79b5
								}
4c79b5
4c79b5
								$filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
4c79b5
							}
4c79b5
						}
4c79b5
4c79b5
						$i = 0;
4c79b5
						$assigned_extensions = '';
4c79b5
						foreach ($extensions as $num => $row)
4c79b5
						{
4c79b5
							if ($row['group_id'] == $group_id && $group_id)
4c79b5
							{
4c79b5
								$assigned_extensions .= ($i) ? ', ' . $row['extension'] : $row['extension'];
4c79b5
								$i++;
4c79b5
							}
4c79b5
						}
4c79b5
4c79b5
						$s_extension_options = '';
4c79b5
						foreach ($extensions as $row)
4c79b5
						{
4c79b5
							$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>';
4c79b5
						}
4c79b5
4c79b5
						$template->assign_vars(array(
4c79b5
							'PHPBB_ROOT_PATH'		=> $phpbb_root_path,
4c79b5
							'IMG_PATH'				=> $img_path,
4c79b5
							'ACTION'				=> $action,
4c79b5
							'GROUP_ID'				=> $group_id,
4c79b5
							'GROUP_NAME'			=> $ext_group_row['group_name'],
4c79b5
							'ALLOW_GROUP'			=> $ext_group_row['allow_group'],
4c79b5
							'ALLOW_IN_PM'			=> $ext_group_row['allow_in_pm'],
4c79b5
							'UPLOAD_ICON_SRC'		=> $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'],
4c79b5
							'EXTGROUP_FILESIZE'		=> $ext_group_row['max_filesize'],
4c79b5
							'ASSIGNED_EXTENSIONS'	=> $assigned_extensions,
4c79b5
4c79b5
							'S_CATEGORY_SELECT'			=> $this->category_select('special_category', $group_id, 'category'),
4c79b5
							'S_EXT_GROUP_SIZE_OPTIONS'	=> size_select_options($size_format),
4c79b5
							'S_EXTENSION_OPTIONS'		=> $s_extension_options,
4c79b5
							'S_FILENAME_LIST'			=> $filename_list,
4c79b5
							'S_EDIT_GROUP'				=> true,
4c79b5
							'S_NO_IMAGE'				=> $no_image_select,
4c79b5
							'S_FORUM_IDS'				=> (sizeof($forum_ids)) ? true : false,
4c79b5
4c79b5
							'U_EXTENSIONS'		=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=extensions"),
4c79b5
							'U_BACK'			=> $this->u_action,
4c79b5
4c79b5
							'L_LEGEND'			=> $user->lang[strtoupper($action) . '_EXTENSION_GROUP'])
4c79b5
						);
4c79b5
4c79b5
						$s_forum_id_options = '';
4c79b5
4c79b5
						/** @todo use in-built function **/
4c79b5
4c79b5
						$sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
4c79b5
							FROM ' . FORUMS_TABLE . '
4c79b5
							ORDER BY left_id ASC';
4c79b5
						$result = $db->sql_query($sql, 600);
4c79b5
4c79b5
						$right = $cat_right = $padding_inc = 0;
4c79b5
						$padding = $forum_list = $holding = '';
4c79b5
						$padding_store = array('0' => '');
4c79b5
4c79b5
						while ($row = $db->sql_fetchrow($result))
4c79b5
						{
4c79b5
							if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
4c79b5
							{
4c79b5
								// Non-postable forum with no subforums, don't display
4c79b5
								continue;
4c79b5
							}
4c79b5
4c79b5
							if (!$auth->acl_get('f_list', $row['forum_id']))
4c79b5
							{
4c79b5
								// if the user does not have permissions to list this forum skip
4c79b5
								continue;
4c79b5
							}
4c79b5
4c79b5
							if ($row['left_id'] < $right)
4c79b5
							{
4c79b5
								$padding .= '   ';
4c79b5
								$padding_store[$row['parent_id']] = $padding;
4c79b5
							}
4c79b5
							else if ($row['left_id'] > $right + 1)
4c79b5
							{
4c79b5
								$padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']];
4c79b5
							}
4c79b5
4c79b5
							$right = $row['right_id'];
4c79b5
4c79b5
							$selected = (in_array($row['forum_id'], $forum_ids)) ? ' selected="selected"' : '';
4c79b5
4c79b5
							if ($row['left_id'] > $cat_right)
4c79b5
							{
4c79b5
								// make sure we don't forget anything
4c79b5
								$s_forum_id_options .= $holding;
4c79b5
								$holding = '';
4c79b5
							}
4c79b5
4c79b5
							if ($row['right_id'] - $row['left_id'] > 1)
4c79b5
							{
4c79b5
								$cat_right = max($cat_right, $row['right_id']);
4c79b5
4c79b5
								$holding .= '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
4c79b5
							}
4c79b5
							else
4c79b5
							{
4c79b5
								$s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
4c79b5
								$holding = '';
4c79b5
							}
4c79b5
						}
4c79b5
4c79b5
						if ($holding)
4c79b5
						{
4c79b5
							$s_forum_id_options .= $holding;
4c79b5
						}
4c79b5
4c79b5
						$db->sql_freeresult($result);
4c79b5
						unset($padding_store);
4c79b5
4c79b5
						$template->assign_vars(array(
4c79b5
							'S_FORUM_ID_OPTIONS'	=> $s_forum_id_options)
4c79b5
						);
4c79b5
4c79b5
					break;
4c79b5
				}
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . EXTENSION_GROUPS_TABLE . '
4c79b5
					ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				$old_allow_group = $old_allow_pm = 1;
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$s_add_spacer = ($old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm']) ? true : false;
4c79b5
4c79b5
					$template->assign_block_vars('groups', array(
4c79b5
						'S_ADD_SPACER'		=> $s_add_spacer,
4c79b5
						'S_ALLOWED_IN_PM'	=> ($row['allow_in_pm']) ? true : false,
4c79b5
						'S_GROUP_ALLOWED'	=> ($row['allow_group']) ? true : false,
4c79b5
4c79b5
						'U_EDIT'		=> $this->u_action . "&action=edit&g={$row['group_id']}",
4c79b5
						'U_DELETE'		=> $this->u_action . "&action=delete&g={$row['group_id']}",
4c79b5
4c79b5
						'GROUP_NAME'	=> $row['group_name'],
4c79b5
						'CATEGORY'		=> $cat_lang[$row['cat_id']],
4c79b5
						)
4c79b5
					);
4c79b5
4c79b5
					$old_allow_group = $row['allow_group'];
4c79b5
					$old_allow_pm = $row['allow_in_pm'];
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'orphan':
4c79b5
4c79b5
				if ($submit)
4c79b5
				{
4c79b5
					$delete_files = (isset($_POST['delete'])) ? array_keys(request_var('delete', array('' => 0))) : array();
4c79b5
					$add_files = (isset($_POST['add'])) ? array_keys(request_var('add', array('' => 0))) : array();
4c79b5
					$post_ids = request_var('post_id', array('' => 0));
4c79b5
4c79b5
					if (sizeof($delete_files))
4c79b5
					{
4c79b5
						$sql = 'SELECT *
4c79b5
							FROM ' . ATTACHMENTS_TABLE . '
4c79b5
							WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
4c79b5
								AND is_orphan = 1';
4c79b5
						$result = $db->sql_query($sql);
4c79b5
4c79b5
						$delete_files = array();
4c79b5
						while ($row = $db->sql_fetchrow($result))
4c79b5
						{
4c79b5
							phpbb_unlink($row['physical_filename'], 'file');
4c79b5
4c79b5
							if ($row['thumbnail'])
4c79b5
							{
4c79b5
								phpbb_unlink($row['physical_filename'], 'thumbnail');
4c79b5
							}
4c79b5
4c79b5
							$delete_files[$row['attach_id']] = $row['real_filename'];
4c79b5
						}
4c79b5
						$db->sql_freeresult($result);
4c79b5
					}
4c79b5
4c79b5
					if (sizeof($delete_files))
4c79b5
					{
4c79b5
						$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
4c79b5
							WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
4c79b5
						$db->sql_query($sql);
4c79b5
4c79b5
						add_log('admin', 'LOG_ATTACH_ORPHAN_DEL', implode(', ', $delete_files));
4c79b5
						$notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files));
4c79b5
					}
4c79b5
4c79b5
					$upload_list = array();
4c79b5
					foreach ($add_files as $attach_id)
4c79b5
					{
4c79b5
						if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id]))
4c79b5
						{
4c79b5
							$upload_list[$attach_id] = $post_ids[$attach_id];
4c79b5
						}
4c79b5
					}
4c79b5
					unset($add_files);
4c79b5
4c79b5
					if (sizeof($upload_list))
4c79b5
					{
4c79b5
						$template->assign_var('S_UPLOADING_FILES', true);
4c79b5
4c79b5
						$sql = 'SELECT forum_id, forum_name
4c79b5
							FROM ' . FORUMS_TABLE;
4c79b5
						$result = $db->sql_query($sql);
4c79b5
4c79b5
						$forum_names = array();
4c79b5
						while ($row = $db->sql_fetchrow($result))
4c79b5
						{
4c79b5
							$forum_names[$row['forum_id']] = $row['forum_name'];
4c79b5
						}
4c79b5
						$db->sql_freeresult($result);
4c79b5
4c79b5
						$sql = 'SELECT forum_id, topic_id, post_id, poster_id
4c79b5
							FROM ' . POSTS_TABLE . '
4c79b5
							WHERE ' . $db->sql_in_set('post_id', $upload_list);
4c79b5
						$result = $db->sql_query($sql);
4c79b5
4c79b5
						$post_info = array();
4c79b5
						while ($row = $db->sql_fetchrow($result))
4c79b5
						{
4c79b5
							$post_info[$row['post_id']] = $row;
4c79b5
						}
4c79b5
						$db->sql_freeresult($result);
4c79b5
4c79b5
						// Select those attachments we want to change...
4c79b5
						$sql = 'SELECT *
4c79b5
							FROM ' . ATTACHMENTS_TABLE . '
4c79b5
							WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
4c79b5
								AND is_orphan = 1';
4c79b5
						$result = $db->sql_query($sql);
4c79b5
4c79b5
						$files_added = $space_taken = 0;
4c79b5
						while ($row = $db->sql_fetchrow($result))
4c79b5
						{
4c79b5
							$post_row = $post_info[$upload_list[$row['attach_id']]];
4c79b5
4c79b5
							$template->assign_block_vars('upload', array(
4c79b5
								'FILE_INFO'		=> sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']),
4c79b5
								'S_DENIED'		=> (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? true : false,
4c79b5
								'L_DENIED'		=> (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : '')
4c79b5
							);
4c79b5
4c79b5
							if (!$auth->acl_get('f_attach', $post_row['forum_id']))
4c79b5
							{
4c79b5
								continue;
4c79b5
							}
4c79b5
4c79b5
							// Adjust attachment entry
4c79b5
							$sql_ary = array(
4c79b5
								'in_message'	=> 0,
4c79b5
								'is_orphan'		=> 0,
4c79b5
								'poster_id'		=> $post_row['poster_id'],
4c79b5
								'post_msg_id'	=> $post_row['post_id'],
4c79b5
								'topic_id'		=> $post_row['topic_id'],
4c79b5
							);
4c79b5
4c79b5
							$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
4c79b5
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
4c79b5
								WHERE attach_id = ' . $row['attach_id'];
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							$sql = 'UPDATE ' . POSTS_TABLE . '
4c79b5
								SET post_attachment = 1
4c79b5
								WHERE post_id = ' . $post_row['post_id'];
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							$sql = 'UPDATE ' . TOPICS_TABLE . '
4c79b5
								SET topic_attachment = 1
4c79b5
								WHERE topic_id = ' . $post_row['topic_id'];
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							$space_taken += $row['filesize'];
4c79b5
							$files_added++;
4c79b5
4c79b5
							add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']);
4c79b5
						}
4c79b5
						$db->sql_freeresult($result);
4c79b5
4c79b5
						if ($files_added)
4c79b5
						{
4c79b5
							set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
4c79b5
							set_config('num_files', $config['num_files'] + $files_added, true);
4c79b5
						}
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_ORPHAN'		=> true)
4c79b5
				);
4c79b5
4c79b5
				// Just get the files with is_orphan set and older than 3 hours
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . ATTACHMENTS_TABLE . '
4c79b5
					WHERE is_orphan = 1
4c79b5
						AND filetime < ' . (time() - 3*60*60) . '
4c79b5
					ORDER BY filetime DESC';
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$template->assign_block_vars('orphan', array(
4c79b5
						'FILESIZE'			=> get_formatted_filesize($row['filesize']),
4c79b5
						'FILETIME'			=> $user->format_date($row['filetime']),
4c79b5
						'REAL_FILENAME'		=> basename($row['real_filename']),
4c79b5
						'PHYSICAL_FILENAME'	=> basename($row['physical_filename']),
4c79b5
						'ATTACH_ID'			=> $row['attach_id'],
4c79b5
						'POST_IDS'			=> (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
4c79b5
						'U_FILE'			=> append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&id=' . $row['attach_id']))
4c79b5
					);
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($error))
4c79b5
		{
4c79b5
			$template->assign_vars(array(
4c79b5
				'S_WARNING'		=> true,
4c79b5
				'WARNING_MSG'	=> implode('
', $error))
4c79b5
			);
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($notify))
4c79b5
		{
4c79b5
			$template->assign_vars(array(
4c79b5
				'S_NOTIFY'		=> true,
4c79b5
				'NOTIFY_MSG'	=> implode('
', $notify))
4c79b5
			);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Build Select for category items
4c79b5
	*/
4c79b5
	function category_select($select_name, $group_id = false, $key = '')
4c79b5
	{
4c79b5
		global $db, $user;
4c79b5
4c79b5
		$types = array(
4c79b5
			ATTACHMENT_CATEGORY_NONE		=> $user->lang['NO_FILE_CAT'],
4c79b5
			ATTACHMENT_CATEGORY_IMAGE		=> $user->lang['CAT_IMAGES'],
4c79b5
			ATTACHMENT_CATEGORY_WM			=> $user->lang['CAT_WM_FILES'],
4c79b5
			ATTACHMENT_CATEGORY_RM			=> $user->lang['CAT_RM_FILES'],
4c79b5
			ATTACHMENT_CATEGORY_FLASH		=> $user->lang['CAT_FLASH_FILES'],
4c79b5
			ATTACHMENT_CATEGORY_QUICKTIME	=> $user->lang['CAT_QUICKTIME_FILES'],
4c79b5
		);
4c79b5
4c79b5
		if ($group_id)
4c79b5
		{
4c79b5
			$sql = 'SELECT cat_id
4c79b5
				FROM ' . EXTENSION_GROUPS_TABLE . '
4c79b5
				WHERE group_id = ' . (int) $group_id;
4c79b5
			$result = $db->sql_query($sql);
4c79b5
4c79b5
			$cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE : $row['cat_id'];
4c79b5
4c79b5
			$db->sql_freeresult($result);
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$cat_type = ATTACHMENT_CATEGORY_NONE;
4c79b5
		}
4c79b5
4c79b5
		$group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
4c79b5
4c79b5
		foreach ($types as $type => $mode)
4c79b5
		{
4c79b5
			$selected = ($type == $cat_type) ? ' selected="selected"' : '';
4c79b5
			$group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>';
4c79b5
		}
4c79b5
4c79b5
		$group_select .= '</select>';
4c79b5
4c79b5
		return $group_select;
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Extension group select
4c79b5
	*/
4c79b5
	function group_select($select_name, $default_group = false, $key = '')
4c79b5
	{
4c79b5
		global $db, $user;
4c79b5
4c79b5
		$group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
4c79b5
4c79b5
		$sql = 'SELECT group_id, group_name
4c79b5
			FROM ' . EXTENSION_GROUPS_TABLE . '
4c79b5
			ORDER BY group_name';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		$group_name = array();
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$group_name[] = $row;
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$row['group_id'] = 0;
4c79b5
		$row['group_name'] = $user->lang['NOT_ASSIGNED'];
4c79b5
		$group_name[] = $row;
4c79b5
4c79b5
		for ($i = 0; $i < sizeof($group_name); $i++)
4c79b5
		{
4c79b5
			if ($default_group === false)
4c79b5
			{
4c79b5
				$selected = ($i == 0) ? ' selected="selected"' : '';
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$selected = ($group_name[$i]['group_id'] == $default_group) ? ' selected="selected"' : '';
4c79b5
			}
4c79b5
4c79b5
			$group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>';
4c79b5
		}
4c79b5
4c79b5
		$group_select .= '</select>';
4c79b5
4c79b5
		return $group_select;
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Search Imagick
4c79b5
	*/
4c79b5
	function search_imagemagick()
4c79b5
	{
4c79b5
		$imagick = '';
4c79b5
4c79b5
		$exe = ((defined('PHP_OS')) && (preg_match('#^win#i', PHP_OS))) ? '.exe' : '';
4c79b5
4c79b5
		$magic_home = getenv('MAGICK_HOME');
4c79b5
4c79b5
		if (empty($magic_home))
4c79b5
		{
4c79b5
			$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/');
4c79b5
			$path_locations = str_replace('\\', '/', (explode(($exe) ? ';' : ':', getenv('PATH'))));
4c79b5
4c79b5
			$locations = array_merge($path_locations, $locations);
4c79b5
4c79b5
			foreach ($locations as $location)
4c79b5
			{
4c79b5
				// The path might not end properly, fudge it
4c79b5
				if (substr($location, -1) !== '/')
4c79b5
				{
4c79b5
					$location .= '/';
4c79b5
				}
4c79b5
4c79b5
				if (@file_exists($location) && @is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)
4c79b5
				{
4c79b5
					$imagick = str_replace('\\', '/', $location);
4c79b5
					continue;
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$imagick = str_replace('\\', '/', $magic_home);
4c79b5
		}
4c79b5
4c79b5
		return $imagick;
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Test Settings
4c79b5
	*/
4c79b5
	function test_upload(&$error, $upload_dir, $create_directory = false)
4c79b5
	{
4c79b5
		global $user, $phpbb_root_path;
4c79b5
4c79b5
		// Does the target directory exist, is it a directory and writable.
4c79b5
		if ($create_directory)
4c79b5
		{
4c79b5
			if (!file_exists($phpbb_root_path . $upload_dir))
4c79b5
			{
4c79b5
				@mkdir($phpbb_root_path . $upload_dir, 0777);
4c79b5
				phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if (!file_exists($phpbb_root_path . $upload_dir))
4c79b5
		{
4c79b5
			$error[] = sprintf($user->lang['NO_UPLOAD_DIR'], $upload_dir);
4c79b5
			return;
4c79b5
		}
4c79b5
4c79b5
		if (!is_dir($phpbb_root_path . $upload_dir))
4c79b5
		{
4c79b5
			$error[] = sprintf($user->lang['UPLOAD_NOT_DIR'], $upload_dir);
4c79b5
			return;
4c79b5
		}
4c79b5
4c79b5
		if (!is_writable($phpbb_root_path . $upload_dir))
4c79b5
		{
4c79b5
			$error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
4c79b5
			return;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Perform operations on sites for external linking
4c79b5
	*/
4c79b5
	function perform_site_list()
4c79b5
	{
4c79b5
		global $db, $user;
4c79b5
4c79b5
		if (isset($_REQUEST['securesubmit']))
4c79b5
		{
4c79b5
			// Grab the list of entries
4c79b5
			$ips = request_var('ips', '');
4c79b5
			$ip_list = array_unique(explode("\n", $ips));
4c79b5
			$ip_list_log = implode(', ', $ip_list);
4c79b5
4c79b5
			$ip_exclude = (!empty($_POST['ipexclude'])) ? 1 : 0;
4c79b5
4c79b5
			$iplist = array();
4c79b5
			$hostlist = array();
4c79b5
4c79b5
			foreach ($ip_list as $item)
4c79b5
			{
4c79b5
				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))
4c79b5
				{
4c79b5
					// Don't ask about all this, just don't ask ... !
4c79b5
					$ip_1_counter = $ip_range_explode[1];
4c79b5
					$ip_1_end = $ip_range_explode[5];
4c79b5
4c79b5
					while ($ip_1_counter <= $ip_1_end)
4c79b5
					{
4c79b5
						$ip_2_counter = ($ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[2] : 0;
4c79b5
						$ip_2_end = ($ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[6];
4c79b5
4c79b5
						if ($ip_2_counter == 0 && $ip_2_end == 254)
4c79b5
						{
4c79b5
							$ip_2_counter = 256;
4c79b5
							$ip_2_fragment = 256;
4c79b5
4c79b5
							$iplist[] = "'$ip_1_counter.*'";
4c79b5
						}
4c79b5
4c79b5
						while ($ip_2_counter <= $ip_2_end)
4c79b5
						{
4c79b5
							$ip_3_counter = ($ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[3] : 0;
4c79b5
							$ip_3_end = ($ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[7];
4c79b5
4c79b5
							if ($ip_3_counter == 0 && $ip_3_end == 254)
4c79b5
							{
4c79b5
								$ip_3_counter = 256;
4c79b5
								$ip_3_fragment = 256;
4c79b5
4c79b5
								$iplist[] = "'$ip_1_counter.$ip_2_counter.*'";
4c79b5
							}
4c79b5
4c79b5
							while ($ip_3_counter <= $ip_3_end)
4c79b5
							{
4c79b5
								$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;
4c79b5
								$ip_4_end = ($ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end) ? 254 : $ip_range_explode[8];
4c79b5
4c79b5
								if ($ip_4_counter == 0 && $ip_4_end == 254)
4c79b5
								{
4c79b5
									$ip_4_counter = 256;
4c79b5
									$ip_4_fragment = 256;
4c79b5
4c79b5
									$iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.*'";
4c79b5
								}
4c79b5
4c79b5
								while ($ip_4_counter <= $ip_4_end)
4c79b5
								{
4c79b5
									$iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter'";
4c79b5
									$ip_4_counter++;
4c79b5
								}
4c79b5
								$ip_3_counter++;
4c79b5
							}
4c79b5
							$ip_2_counter++;
4c79b5
						}
4c79b5
						$ip_1_counter++;
4c79b5
					}
4c79b5
				}
4c79b5
				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)))
4c79b5
				{
4c79b5
					$iplist[] = "'" . trim($item) . "'";
4c79b5
				}
4c79b5
				else if (preg_match('#^([\w\-_]\.?){2,}$#is', trim($item)))
4c79b5
				{
4c79b5
					$hostlist[] = "'" . trim($item) . "'";
4c79b5
				}
4c79b5
				else if (preg_match("#^([a-z0-9\-\*\._/]+?)$#is", trim($item)))
4c79b5
				{
4c79b5
					$hostlist[] = "'" . trim($item) . "'";
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			$sql = 'SELECT site_ip, site_hostname
4c79b5
				FROM ' . SITELIST_TABLE . "
4c79b5
				WHERE ip_exclude = $ip_exclude";
4c79b5
			$result = $db->sql_query($sql);
4c79b5
4c79b5
			if ($row = $db->sql_fetchrow($result))
4c79b5
			{
4c79b5
				$iplist_tmp = array();
4c79b5
				$hostlist_tmp = array();
4c79b5
				do
4c79b5
				{
4c79b5
					if ($row['site_ip'])
4c79b5
					{
4c79b5
						if (strlen($row['site_ip']) > 40)
4c79b5
						{
4c79b5
							continue;
4c79b5
						}
4c79b5
4c79b5
						$iplist_tmp[] = "'" . $row['site_ip'] . "'";
4c79b5
					}
4c79b5
					else if ($row['site_hostname'])
4c79b5
					{
4c79b5
						if (strlen($row['site_hostname']) > 255)
4c79b5
						{
4c79b5
							continue;
4c79b5
						}
4c79b5
4c79b5
						$hostlist_tmp[] = "'" . $row['site_hostname'] . "'";
4c79b5
					}
4c79b5
					// break;
4c79b5
				}
4c79b5
				while ($row = $db->sql_fetchrow($result));
4c79b5
4c79b5
				$iplist = array_unique(array_diff($iplist, $iplist_tmp));
4c79b5
				$hostlist = array_unique(array_diff($hostlist, $hostlist_tmp));
4c79b5
				unset($iplist_tmp);
4c79b5
				unset($hostlist_tmp);
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			if (sizeof($iplist))
4c79b5
			{
4c79b5
				foreach ($iplist as $ip_entry)
4c79b5
				{
4c79b5
					$sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_ip, ip_exclude)
4c79b5
						VALUES ($ip_entry, $ip_exclude)";
4c79b5
					$db->sql_query($sql);
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if (sizeof($hostlist))
4c79b5
			{
4c79b5
				foreach ($hostlist as $host_entry)
4c79b5
				{
4c79b5
					$sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_hostname, ip_exclude)
4c79b5
						VALUES ($host_entry, $ip_exclude)";
4c79b5
					$db->sql_query($sql);
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if (!empty($ip_list_log))
4c79b5
			{
4c79b5
				// Update log
4c79b5
				$log_entry = ($ip_exclude) ? 'LOG_DOWNLOAD_EXCLUDE_IP' : 'LOG_DOWNLOAD_IP';
4c79b5
				add_log('admin', $log_entry, $ip_list_log);
4c79b5
			}
4c79b5
4c79b5
			trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
4c79b5
		}
4c79b5
		else if (isset($_POST['unsecuresubmit']))
4c79b5
		{
4c79b5
			$unip_sql = request_var('unip', array(0));
4c79b5
4c79b5
			if (sizeof($unip_sql))
4c79b5
			{
4c79b5
				$l_unip_list = '';
4c79b5
4c79b5
				// Grab details of ips for logging information later
4c79b5
				$sql = 'SELECT site_ip, site_hostname
4c79b5
					FROM ' . SITELIST_TABLE . '
4c79b5
					WHERE ' . $db->sql_in_set('site_id', $unip_sql);
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$l_unip_list .= (($l_unip_list != '') ? ', ' : '') . (($row['site_ip']) ? $row['site_ip'] : $row['site_hostname']);
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$sql = 'DELETE FROM ' . SITELIST_TABLE . '
4c79b5
					WHERE ' . $db->sql_in_set('site_id', $unip_sql);
4c79b5
				$db->sql_query($sql);
4c79b5
4c79b5
				add_log('admin', 'LOG_DOWNLOAD_REMOVE_IP', $l_unip_list);
4c79b5
			}
4c79b5
4c79b5
			trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Write display_order config field
4c79b5
	*/
4c79b5
	function display_order($value, $key = '')
4c79b5
	{
4c79b5
		$radio_ary = array(0 => 'DESCENDING', 1 => 'ASCENDING');
4c79b5
4c79b5
		return h_radio('config[display_order]', $radio_ary, $value, $key);
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Adjust all three max_filesize config vars for display
4c79b5
	*/
4c79b5
	function max_filesize($value, $key = '')
4c79b5
	{
4c79b5
		// Determine size var and adjust the value accordingly
4c79b5
		$size_var = ($value >= 1048576) ? 'mb' : (($value >= 1024) ? 'kb' : 'b');
4c79b5
		$value = get_formatted_filesize($value, false);
4c79b5
4c79b5
		return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Write secure_allow_deny config field
4c79b5
	*/
4c79b5
	function select_allow_deny($value, $key = '')
4c79b5
	{
4c79b5
		$radio_ary = array(1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW');
4c79b5
4c79b5
		return h_radio('config[' . $key . ']', $radio_ary, $value, $key);
4c79b5
	}
4c79b5
4c79b5
}
4c79b5
4c79b5
?>