phpBB

Code Changes

File: includes/acp/acp_attachments.php

  Unmodified   Added   Modified   Removed
Line 90Line 90
				$s_assigned_groups = array();
while ($row = $db->sql_fetchrow($result))
{

				$s_assigned_groups = array();
while ($row = $db->sql_fetchrow($result))
{

 
					$row['group_name'] = (isset($user->lang['EXT_GROUP_' . $row['group_name']])) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'];

					$s_assigned_groups[$row['cat_id']][] = $row['group_name'];
}
$db->sql_freeresult($result);

					$s_assigned_groups[$row['cat_id']][] = $row['group_name'];
}
$db->sql_freeresult($result);

Line 99Line 100
				$display_vars = array(
'title' => 'ACP_ATTACHMENT_SETTINGS',
'vars' => array(

				$display_vars = array(
'title' => 'ACP_ATTACHMENT_SETTINGS',
'vars' => array(

						'img_max_width' => false, 'img_max_height' => false, 'img_link_width' => false, 'img_link_height' => false,


 
						'legend1'				=> 'ACP_ATTACHMENT_SETTINGS',

						'legend1'				=> 'ACP_ATTACHMENT_SETTINGS',

 

'img_max_width' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
'img_max_height' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
'img_link_width' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
'img_link_height' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),


						'allow_attachments'		=> array('lang' => 'ALLOW_ATTACHMENTS',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => false),
'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
'upload_path' => array('lang' => 'UPLOAD_DIR', 'validate' => 'wpath', 'type' => 'text:25:100', 'explain' => true),

						'allow_attachments'		=> array('lang' => 'ALLOW_ATTACHMENTS',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => false),
'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
'upload_path' => array('lang' => 'UPLOAD_DIR', 'validate' => 'wpath', 'type' => 'text:25:100', 'explain' => true),

Line 113Line 118
						'max_attachments_pm'	=> array('lang' => 'MAX_ATTACHMENTS_PM',	'validate' => 'int',	'type' => 'text:3:3', 'explain' => false),
'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),

						'max_attachments_pm'	=> array('lang' => 'MAX_ATTACHMENTS_PM',	'validate' => 'int',	'type' => 'text:3:3', 'explain' => false),
'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),

						'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),



						'secure_allow_empty_referer'	=> array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),



'legend2' => $l_legend_cat_images,
'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'img_create_thumbnail' => array('lang' => 'CREATE_THUMBNAIL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),


'legend2' => $l_legend_cat_images,
'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'img_create_thumbnail' => array('lang' => 'CREATE_THUMBNAIL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),

						'img_max_thumb_width'		=> array('lang' => 'MAX_THUMB_WIDTH',		'validate' => 'int',	'type' => 'text:7:15', 'explain' => true, 'append' => ' px'),

						'img_max_thumb_width'		=> array('lang' => 'MAX_THUMB_WIDTH',		'validate' => 'int',	'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),

						'img_min_thumb_filesize'	=> array('lang' => 'MIN_THUMB_FILESIZE',	'validate' => 'int',	'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),

						'img_min_thumb_filesize'	=> array('lang' => 'MIN_THUMB_FILESIZE',	'validate' => 'int',	'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),

						'img_imagick'				=> array('lang' => 'IMAGICK_PATH',			'validate' => 'string',	'type' => 'text:20:200', 'explain' => true, 'append' => '&nbsp;&nbsp;<span>[ <a href="' . $this->u_action . '&amp;action=imgmagick">' . $user->lang['SEARCH_IMAGICK'] . '</a> ]</span>'),
'img_max' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
'img_link' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),

						'img_imagick'				=> array('lang' => 'IMAGICK_PATH',			'validate' => 'absolute_path',	'type' => 'text:20:200', 'explain' => true, 'append' => '&nbsp;&nbsp;<span>[ <a href="' . $this->u_action . '&amp;action=imgmagick">' . $user->lang['SEARCH_IMAGICK'] . '</a> ]</span>'),
'img_max' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
'img_link' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),

					)
);


					)
);


Line 184Line 191
				}

// We strip eventually manual added convert program, we only want the patch

				}

// We strip eventually manual added convert program, we only want the patch

 
				if ($this->new_config['img_imagick'])
{
// Change path separator
$this->new_config['img_imagick'] = str_replace('\\', '/', $this->new_config['img_imagick']);

				$this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']);

				$this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']);

 

// Check for trailing slash
if (substr($this->new_config['img_imagick'], -1) !== '/')
{
$this->new_config['img_imagick'] .= '/';
}
}


$supported_types = get_supported_image_types();



$supported_types = get_supported_image_types();


Line 261Line 279
					else if ($vars['explain'])
{
$l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';

					else if ($vars['explain'])
{
$l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';

 
					}

$content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
if (empty($content))
{
continue;

					}

$template->assign_block_vars('options', array(

					}

$template->assign_block_vars('options', array(

Line 268Line 292
						'TITLE'			=> $user->lang[$vars['lang']],
'S_EXPLAIN' => $vars['explain'],
'TITLE_EXPLAIN' => $l_explain,

						'TITLE'			=> $user->lang[$vars['lang']],
'S_EXPLAIN' => $vars['explain'],
'TITLE_EXPLAIN' => $l_explain,

						'CONTENT'		=> build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars),

						'CONTENT'		=> $content,

						)
);


						)
);


Line 471Line 495
						$sql = 'SELECT group_id
FROM ' . EXTENSION_GROUPS_TABLE . "
WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";

						$sql = 'SELECT group_id
FROM ' . EXTENSION_GROUPS_TABLE . "
WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";

 
						if ($group_id)
{
$sql .= ' AND group_id <> ' . $group_id;
}

						$result = $db->sql_query($sql);

if ($db->sql_fetchrow($result))

						$result = $db->sql_query($sql);

if ($db->sql_fetchrow($result))

Line 528Line 556
							$group_id = $db->sql_nextid();
}


							$group_id = $db->sql_nextid();
}


 
						$group_name = (isset($user->lang['EXT_GROUP_' . $group_name])) ? $user->lang['EXT_GROUP_' . $group_name] : $group_name;

						add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name);
}


						add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name);
}


Line 661Line 690
							$ext_group_row['max_filesize'] = (int) $config['max_filesize'];
}


							$ext_group_row['max_filesize'] = (int) $config['max_filesize'];
}


						$size_format = ($ext_group_row['max_filesize'] >= 1048576) ? 'mb' : (($ext_group_row['max_filesize'] >= 1024) ? 'kb' : 'b');

$ext_group_row['max_filesize'] = ($ext_group_row['max_filesize'] >= 1048576) ? round($ext_group_row['max_filesize'] / 1048576 * 100) / 100 : (($ext_group_row['max_filesize'] >= 1024) ? round($ext_group_row['max_filesize'] / 1024 * 100) / 100 : $ext_group_row['max_filesize']);

						$max_filesize = get_formatted_filesize($ext_group_row['max_filesize'], false, array('mb', 'kb', 'b'));
$size_format = $max_filesize['si_identifier'];
$ext_group_row['max_filesize'] = $max_filesize['value'];


$img_path = $config['upload_icons_path'];



$img_path = $config['upload_icons_path'];


Line 672Line 701

$imglist = filelist($phpbb_root_path . $img_path);



$imglist = filelist($phpbb_root_path . $img_path);


						if (sizeof($imglist))

						if (!empty($imglist['']))

						{
$imglist = array_values($imglist);
$imglist = $imglist[0];

						{
$imglist = array_values($imglist);
$imglist = $imglist[0];

Line 742Line 771
						);

$s_forum_id_options = '';

						);

$s_forum_id_options = '';

 

/** @todo use in-built function **/


$sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
FROM ' . FORUMS_TABLE . '


$sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
FROM ' . FORUMS_TABLE . '

Line 773Line 804
							}
else if ($row['left_id'] > $right + 1)
{

							}
else if ($row['left_id'] > $right + 1)
{

								$padding = $padding_store[$row['parent_id']];

								$padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']];

							}

$right = $row['right_id'];

							}

$right = $row['right_id'];

Line 833Line 864
						'U_EDIT'		=> $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}",
'U_DELETE' => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}",


						'U_EDIT'		=> $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}",
'U_DELETE' => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}",


						'GROUP_NAME'	=> $row['group_name'],

						'GROUP_NAME'	=> (isset($user->lang['EXT_GROUP_' . $row['group_name']])) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'],

						'CATEGORY'		=> $cat_lang[$row['cat_id']],
)
);

						'CATEGORY'		=> $cat_lang[$row['cat_id']],
)
);

Line 889Line 920
					$upload_list = array();
foreach ($add_files as $attach_id)
{

					$upload_list = array();
foreach ($add_files as $attach_id)
{

						if (!in_array($attach_id, array_keys($delete_files)) && !empty($post_ids[$attach_id]))

						if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id]))

						{
$upload_list[$attach_id] = $post_ids[$attach_id];
}

						{
$upload_list[$attach_id] = $post_ids[$attach_id];
}

Line 930Line 961
								AND is_orphan = 1';
$result = $db->sql_query($sql);


								AND is_orphan = 1';
$result = $db->sql_query($sql);


 
						$files_added = $space_taken = 0;

						while ($row = $db->sql_fetchrow($result))
{
$post_row = $post_info[$upload_list[$row['attach_id']]];

						while ($row = $db->sql_fetchrow($result))
{
$post_row = $post_info[$upload_list[$row['attach_id']]];

Line 968Line 1000
								SET topic_attachment = 1
WHERE topic_id = ' . $post_row['topic_id'];
$db->sql_query($sql);

								SET topic_attachment = 1
WHERE topic_id = ' . $post_row['topic_id'];
$db->sql_query($sql);

 

$space_taken += $row['filesize'];
$files_added++;


add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']);
}
$db->sql_freeresult($result);


add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']);
}
$db->sql_freeresult($result);

 

if ($files_added)
{
set_config_count('upload_dir_size', $space_taken, true);
set_config_count('num_files', $files_added, true);
}

					}
}


					}
}


Line 989Line 1030

while ($row = $db->sql_fetchrow($result))
{


while ($row = $db->sql_fetchrow($result))
{

					$size_lang = ($row['filesize'] >= 1048576) ? $user->lang['MB'] : (($row['filesize'] >= 1024) ? $user->lang['KB'] : $user->lang['BYTES']);
$row['filesize'] = ($row['filesize'] >= 1048576) ? round((round($row['filesize'] / 1048576 * 100) / 100), 2) : (($row['filesize'] >= 1024) ? round((round($row['filesize'] / 1024 * 100) / 100), 2) : $row['filesize']);


 
					$template->assign_block_vars('orphan', array(

					$template->assign_block_vars('orphan', array(

						'FILESIZE'			=> $row['filesize'] . ' ' . $size_lang,

						'FILESIZE'			=> get_formatted_filesize($row['filesize']),

						'FILETIME'			=> $user->format_date($row['filetime']),

						'FILETIME'			=> $user->format_date($row['filetime']),

						'REAL_FILENAME'		=> basename($row['real_filename']),
'PHYSICAL_FILENAME' => basename($row['physical_filename']),

						'REAL_FILENAME'		=> utf8_basename($row['real_filename']),
'PHYSICAL_FILENAME' => utf8_basename($row['physical_filename']),

						'ATTACH_ID'			=> $row['attach_id'],
'POST_IDS' => (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))

						'ATTACH_ID'			=> $row['attach_id'],
'POST_IDS' => (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))

Line 1086Line 1124
		$group_name = array();
while ($row = $db->sql_fetchrow($result))
{

		$group_name = array();
while ($row = $db->sql_fetchrow($result))
{

 
			$row['group_name'] = (isset($user->lang['EXT_GROUP_' . $row['group_name']])) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'];

			$group_name[] = $row;
}
$db->sql_freeresult($result);

			$group_name[] = $row;
}
$db->sql_freeresult($result);

Line 1134Line 1173
			foreach ($locations as $location)
{
// The path might not end properly, fudge it

			foreach ($locations as $location)
{
// The path might not end properly, fudge it

				if (substr($location, -1, 1) !== '/')

				if (substr($location, -1) !== '/')

				{
$location .= '/';
}


				{
$location .= '/';
}


				if (@is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)

				if (@file_exists($location) && @is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)

				{
$imagick = str_replace('\\', '/', $location);
continue;

				{
$imagick = str_replace('\\', '/', $location);
continue;

Line 1167Line 1206
			if (!file_exists($phpbb_root_path . $upload_dir))
{
@mkdir($phpbb_root_path . $upload_dir, 0777);

			if (!file_exists($phpbb_root_path . $upload_dir))
{
@mkdir($phpbb_root_path . $upload_dir, 0777);

				@chmod($phpbb_root_path . $upload_dir, 0777);

				phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);

			}
}


			}
}


Line 1183Line 1222
			return;
}


			return;
}


		if (!is_writable($phpbb_root_path . $upload_dir))

		if (!phpbb_is_writable($phpbb_root_path . $upload_dir))

		{
$error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
return;

		{
$error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
return;

Line 1398Line 1437
	function max_filesize($value, $key = '')
{
// Determine size var and adjust the value accordingly

	function max_filesize($value, $key = '')
{
// Determine size var and adjust the value accordingly

		$size_var = ($value >= 1048576) ? 'mb' : (($value >= 1024) ? 'kb' : 'b');
$value = ($value >= 1048576) ? round($value / 1048576 * 100) / 100 : (($value >= 1024) ? round($value / 1024 * 100) / 100 : $value);


		$filesize = get_formatted_filesize($value, false, array('mb', 'kb', 'b'));
$size_var = $filesize['si_identifier'];
$value = $filesize['value'];


return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
}


return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
}