Merge remote-tracking branch 'bantu/ticket/11586' into develop

* bantu/ticket/11586:
  [ticket/11586] Move $filedata['thumbnail'] to where it might be returned.
  [ticket/11586] Combine $filedata['post_attach'] assign into a single statement.
  [ticket/11586] Use a variable for $cat_id == ATTACHMENT_CATEGORY_IMAGE.
  [ticket/11586] Combine administrator/moderator checks together.
This commit is contained in:
Joas Schilling 2013-06-03 20:06:00 +02:00
commit 74da9e32e5

View file

@ -403,14 +403,7 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage
$upload->set_disallowed_content(explode('|', $config['mime_triggers'])); $upload->set_disallowed_content(explode('|', $config['mime_triggers']));
} }
if (!$local) $filedata['post_attach'] = $local || $upload->is_valid($form_name);
{
$filedata['post_attach'] = ($upload->is_valid($form_name)) ? true : false;
}
else
{
$filedata['post_attach'] = true;
}
if (!$filedata['post_attach']) if (!$filedata['post_attach'])
{ {
@ -429,20 +422,18 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage
return $filedata; return $filedata;
} }
$cat_id = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE; // Whether the uploaded file is in the image category
$is_image = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE : false;
// Do we have to create a thumbnail?
$filedata['thumbnail'] = ($cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail']) ? 1 : 0;
// Check Image Size, if it is an image
if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id) && $cat_id == ATTACHMENT_CATEGORY_IMAGE)
{
$file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']);
}
// Admins and mods are allowed to exceed the allowed filesize
if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id)) if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id))
{ {
// Check Image Size, if it is an image
if ($is_image)
{
$file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']);
}
// Admins and mods are allowed to exceed the allowed filesize
if (!empty($extensions[$file->get('extension')]['max_filesize'])) if (!empty($extensions[$file->get('extension')]['max_filesize']))
{ {
$allowed_filesize = $extensions[$file->get('extension')]['max_filesize']; $allowed_filesize = $extensions[$file->get('extension')]['max_filesize'];
@ -457,10 +448,12 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage
$file->clean_filename('unique', $user->data['user_id'] . '_'); $file->clean_filename('unique', $user->data['user_id'] . '_');
// Are we uploading an image *and* this image being within the image category? Only then perform additional image checks. // Are we uploading an image *and* this image being within the image category?
$no_image = ($cat_id == ATTACHMENT_CATEGORY_IMAGE) ? false : true; // Only then perform additional image checks.
$file->move_file($config['upload_path'], false, !$is_image);
$file->move_file($config['upload_path'], false, $no_image); // Do we have to create a thumbnail?
$filedata['thumbnail'] = ($is_image && $config['img_create_thumbnail']) ? 1 : 0;
if (sizeof($file->error)) if (sizeof($file->error))
{ {
@ -472,7 +465,7 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage
} }
// Make sure the image category only holds valid images... // Make sure the image category only holds valid images...
if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image()) if ($is_image && !$file->is_image())
{ {
$file->remove(); $file->remove();