Browse Source

Auto create attachments directories.

Finally done.
Kays48 12 years ago
parent
commit
1d30939721

+ 42 - 82
Sources/Attachments.php

@@ -90,21 +90,17 @@ function automanage_attachments_check_directory()
 			$updir = '';
 	}
 
-	if (!is_array($modSettings['attachmentUploadDir']) && !empty($modSettings['currentAttachmentUploadDir']))
+	if (!is_array($modSettings['attachmentUploadDir']))
 		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-	if (!is_array($modSettings['attachmentUploadDir']) || (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)))
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
 		$outputCreation = automanage_attachments_create_directory($updir);
 	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
 		$outputCreation = true;
 
 	if ($outputCreation)
 	{
-		if (!is_array($modSettings['attachmentUploadDir']))
-			$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-
 		$modSettings['currentAttachmentUploadDir'] = array_search($updir, $modSettings['attachmentUploadDir']);
 		$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
-		$context['id_folder'] = $modSettings['currentAttachmentUploadDir'];
 
 		updateSettings(array(
 			'currentAttachmentUploadDir' => $modSettings['currentAttachmentUploadDir'],
@@ -116,14 +112,22 @@ function automanage_attachments_check_directory()
 
 function automanage_attachments_create_directory($updir)
 {
-	global $modSettings, $initial_error, $context;
+	global $modSettings, $initial_error, $context, $boarddir;
 
 	$tree = mama_get_directory_tree_elements($updir);
 	$count = count($tree);
 
 	$directory = mama_init_dir($tree, $count);
 	if ($directory === false)
-		return false;
+	{
+		// Maybe it's just the folder name
+		$tree = mama_get_directory_tree_elements($boarddir . DIRECTORY_SEPARATOR . $updir);
+		$count = count($tree);
+	
+		$directory = mama_init_dir($tree, $count);
+		if ($directory === false)
+			return false;
+	}
 
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
 
@@ -133,13 +137,8 @@ function automanage_attachments_create_directory($updir)
 		{
 			if (!@mkdir($directory,0755))
 			{
-				if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
-					fatal_lang_error('attachments_no_create', 'critical');
-				else
-				{
-					$context['dir_creation_error'] = 'attachments_no_create';
-					return false;
-				}
+				$context['dir_creation_error'] = 'attachments_no_create';
+				return false;
 			}
 		}
 
@@ -158,13 +157,8 @@ function automanage_attachments_create_directory($updir)
 				chmod($directory, 0777);
 				if (!is_writable($directory))
 				{
-					if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
-						fatal_lang_error('attachments_no_write', 'critical');
-					else
-					{
-						$context['dir_creation_error'] = 'attachments_no_write';
-						return false;
-					}
+					$context['dir_creation_error'] = 'attachments_no_write';
+					return false;
 				}
 			}
 		}
@@ -172,16 +166,13 @@ function automanage_attachments_create_directory($updir)
 
 	// Everything seems fine...let's create the .htaccess
 	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htacess'))
-		secureDirectory($directory, true);
+		secureDirectory($updir, true);
 
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
-	$directory = rtrim($directory, $sep);
-
-	if (!is_array($modSettings['attachmentUploadDir']))
-		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+	$updir = rtrim($updir, $sep);
 
 	// Only update if it's a new directory
-	if (!in_array($directory, $modSettings['attachmentUploadDir']))
+	if (!in_array($updir, $modSettings['attachmentUploadDir']))
 	{
 		$modSettings['currentAttachmentUploadDir'] = max(array_keys($modSettings['attachmentUploadDir'])) +1;
 		$modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']] = $updir;
@@ -194,8 +185,6 @@ function automanage_attachments_create_directory($updir)
 	}
 
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
-	$context['id_folder'] = $modSettings['currentAttachmentUploadDir'];
-
 	return true;
 }
 
@@ -214,8 +203,6 @@ function automanage_attachments_by_space()
 	// Get the current base directory
 	if (!empty($modSettings['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories']))
 	{
-		if (!is_array($modSettings['attachment_basedirectories']))
-			$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
 	}
@@ -223,8 +210,6 @@ function automanage_attachments_by_space()
 		$base_dir = 0;
 
 	// Get the last attachment directory for that base directory
-	if (!is_array($modSettings['last_attachments_directory']))
-		$modSettings['last_attachments_directory'] = unserialize($modSettings['last_attachments_directory']);
 	if (empty($modSettings['last_attachments_directory'][$base_dir]))
 		$modSettings['last_attachments_directory'][$base_dir] = 0;
 	// And increment it.
@@ -233,13 +218,7 @@ function automanage_attachments_by_space()
 	$updir = $basedirectory . DIRECTORY_SEPARATOR . 'attachments_' . $modSettings['last_attachments_directory'][$base_dir];
 	if (automanage_attachments_create_directory($updir))
 	{
-		if (!is_array($modSettings['attachmentUploadDir']) && !empty($modSettings['currentAttachmentUploadDir']))
-			$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-
 		$modSettings['currentAttachmentUploadDir'] = array_search($updir, $modSettings['attachmentUploadDir']);
-		$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
-		$context['id_folder'] = $modSettings['currentAttachmentUploadDir'];
-
 		updateSettings(array(
 			'last_attachments_directory' => serialize($modSettings['last_attachments_directory']),
 			'currentAttachmentUploadDir' => $modSettings['currentAttachmentUploadDir'],
@@ -300,18 +279,10 @@ function processAttachments()
 	if (!empty($modSettings['automanage_attachments']))
 		automanage_attachments_check_directory();
 
-	if (!empty($modSettings['currentAttachmentUploadDir']))
-	{
-		if (!is_array($modSettings['attachmentUploadDir']))
-			$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-		$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
-		$context['id_folder'] = $modSettings['currentAttachmentUploadDir'];
-	}
-	else
-	{
-		$context['attach_dir'] = $modSettings['attachmentUploadDir'];
-		$context['id_folder'] = 1;
-	}
+	if (!is_array($modSettings['attachmentUploadDir']))
+		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+
+	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
 
 	// Is the attachments folder actualy there?
 	if (!empty($context['dir_creation_error']))
@@ -322,22 +293,6 @@ function processAttachments()
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
 	}
 
-	// Check that the attachments folder is writable. No sense in proceeding if it isn't.
-	if (empty($initial_error) && !is_writable($context['attach_dir']))
-	{
-		chmod($context['attach_dir'], 0755);
-		if (!is_writable($context['attach_dir']))
-		{
-			chmod($context['attach_dir'], 0775);
-			if (!is_writable($context['attach_dir']))
-			{
-				chmod($context['attach_dir'], 0777);
-				if (!is_writable($context['attach_dir']))
-					$initial_error = 'attachments_no_write';
-			}
-		}
-	}
-
 	if (!isset($initial_error) && !isset($context['attachments']))
 	{
 		// If this isn't a new post, check the current attachments.
@@ -447,7 +402,7 @@ function processAttachments()
 				'tmp_name' => $destName,
 				'size' => $_FILES['attachment']['size'][$n],
 				'type' => $_FILES['attachment']['type'][$n],
-				'id_folder' => $context['id_folder'],
+				'id_folder' => $modSettings['currentAttachmentUploadDir'],
 				'errors' => array(),
 			);
 
@@ -483,7 +438,7 @@ function processAttachments()
 	//   tmp_name => Path to the temp file ($context['attach_dir'] . '/' . $attachID).
 	//   size => File size (required).
 	//   type => MIME type (optional if not available on upload).
-	//   id_folder =>
+	//   id_folder => $modSettings['currentAttachmentUploadDir']
 	//   errors => An array of errors (use the index of the $txt variable for that error).
 	// Template changes can be done using "integrate_upload_template".
 	call_integration_hook('integrate_attachment_upload', array());
@@ -599,16 +554,18 @@ function attachmentChecks($attachID)
 				{
 					rename($_SESSION['temp_attachments'][$attachID]['tmp_name'], $context['attach_dir'] . '/' . $attachID);
 					$_SESSION['temp_attachments'][$attachID]['tmp_name'] = $context['attach_dir'] . '/' . $attachID;
-					$_SESSION['temp_attachments'][$attachID]['id_folder'] = $context['id_folder'];
+					$_SESSION['temp_attachments'][$attachID]['id_folder'] = $modSettings['currentAttachmentUploadDir'];
 					$context['dir_size'] = $_SESSION['temp_attachments'][$attachID]['size'];
 					$context['dir_files'] = 1;
-
-					if (isset($context['dir_creation_error']))
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
 				}
 				// Or, let the user know that it ain't gonna happen.
 				else
-					$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
+				{
+					if (isset($context['dir_creation_error']))
+						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
+					else
+						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
+				}
 			}
 			else
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
@@ -651,8 +608,10 @@ function attachmentChecks($attachID)
 	// Undo the math if there's an error
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
 	{
-		$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
-		$context['dir_files']--;
+		if (isset($context['dir_size']))
+			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
+		if (isset($context['dir_files']))
+			$context['dir_files']--;
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
 		$context['attachments']['quantity']--;
 		return false;
@@ -781,8 +740,9 @@ function createAttachment(&$attachmentOptions)
 			// We should check the file size and count here since thumbs are added to the existing totals.
 			if (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] == 1 && !empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))
 			{
-				$context['dir_size'] += $thumb_size;
-				$context['dir_files']++;
+				$context['dir_size'] = isset($context['dir_size']) ? $context['dir_size'] += $thumb_size : $context['dir_size'] = 0;
+				$context['dir_files'] = isset($context['dir_files']) ? $context['dir_files']++ : $context['dir_files'] = 0;
+
 				// If the folder is full, try to create a new one and move the thumb to it.
 				if ($context['dir_size'] > $modSettings['attachmentDirSizeLimit'] * 1024 || $context['dir_files'] + 2 > $modSettings['attachmentDirFileLimit'])
 				{
@@ -796,7 +756,7 @@ function createAttachment(&$attachmentOptions)
 				}
 			}
 			// If a new folder has been already created. Gotta move this thumb there then.
-			if ($context['id_folder'] != $attachmentOptions['id_folder'])
+			if ($modSettings['currentAttachmentUploadDir'] != $attachmentOptions['id_folder'])
 			{
 				rename($thumb_path, $context['attach_dir'] . '/' . $thumb_filename);
 				$thumb_path = $context['attach_dir'] . '/' . $thumb_filename;
@@ -810,7 +770,7 @@ function createAttachment(&$attachmentOptions)
 					'size' => 'int', 'width' => 'int', 'height' => 'int', 'mime_type' => 'string-20', 'approved' => 'int',
 				),
 				array(
-					(int) $context['id_folder'], (int) $attachmentOptions['post'], 3, $thumb_filename, $thumb_file_hash, $attachmentOptions['fileext'],
+					$modSettings['currentAttachmentUploadDir'], (int) $attachmentOptions['post'], 3, $thumb_filename, $thumb_file_hash, $attachmentOptions['fileext'],
 					$thumb_size, $thumb_width, $thumb_height, $thumb_mime, (int) $attachmentOptions['approved'],
 				),
 				array('id_attach')
@@ -829,7 +789,7 @@ function createAttachment(&$attachmentOptions)
 					)
 				);
 
-				rename($thumb_path, getAttachmentFilename($thumb_filename, $attachmentOptions['thumb'], $context['id_folder'], false, $thumb_file_hash));
+				rename($thumb_path, getAttachmentFilename($thumb_filename, $attachmentOptions['thumb'], $modSettings['currentAttachmentUploadDir'], false, $thumb_file_hash));
 			}
 		}
 	}

+ 229 - 160
Sources/ManageAttachments.php

@@ -91,8 +91,7 @@ function ManageAttachmentSettings($return_config = false)
 	require_once($sourcedir . '/Attachments.php');
 
 	// Get the current attachment directory.
-	if (!is_array($modSettings['attachmentUploadDir']))
-		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+	$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
 	$context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
 
 	// If not set, show a default path for the base directory
@@ -112,7 +111,7 @@ function ManageAttachmentSettings($return_config = false)
 	// A bit of razzle dazzle with the $txt strings. :)
 	$txt['attachment_path'] = $context['attachmentUploadDir'];
 	$txt['basedirectory_for_attachments_path']= isset($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : '';
-	$txt['use_subdirectories_for_attachments_note'] = empty($modSettings['use_subdirectories_for_attachments']) ? $txt['use_subdirectories_for_attachments_note'] : '';
+	$txt['use_subdirectories_for_attachments_note'] = empty($modSettings['attachment_basedirectories']) || empty($modSettings['use_subdirectories_for_attachments']) ? $txt['use_subdirectories_for_attachments_note'] : '';
 	$txt['attachmentUploadDir_multiple_configure'] = '<a href="' . $scripturl . '?action=admin;area=manageattachments;sa=attachpaths">[' . $txt['attachmentUploadDir_multiple_configure'] . ']</a>';
 	$txt['attach_current_dir'] = empty($modSettings['automanage_attachments']) ? $txt['attach_current_dir'] : $txt['attach_last_dir'];
 	$txt['attach_current_dir_warning'] = $txt['attach_current_dir'] . $txt['attach_current_dir_warning'];
@@ -150,7 +149,7 @@ function ManageAttachmentSettings($return_config = false)
 			array('warning', empty($testUM) ? 'attachment_filesize_warning' : ''),
 			array('int', 'attachmentNumPerPostLimit', 'subtext' => $txt['zero_for_no_limit'], 6),
 			// Security Items
-			array('title', 'attachment_security_settings'),
+		array('title', 'attachment_security_settings'),
 			// Extension checks etc.
 			array('check', 'attachmentCheckExtensions'),
 			array('text', 'attachmentExtensions', 40),
@@ -216,17 +215,9 @@ function ManageAttachmentSettings($return_config = false)
 			{
 				$currentAttachmentUploadDir = $modSettings['currentAttachmentUploadDir'];
 
-				if (!is_array($modSettings['attachmentUploadDir']))
-					$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-
-				if (in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir']))
-					$modSettings['currentAttachmentUploadDir'] = array_search($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir']);
-
-				if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments']))
-				{
-					// @todo Some sort of an error here also maybe??
-					$_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments'];
-				}
+				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir']))
+					if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments']))
+						$_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments'];				}
 
 				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
 				{
@@ -1549,18 +1540,10 @@ function RepairAttachments()
 	// What about files who are not recorded in the database?
 	if ($_GET['step'] <= 5)
 	{
-		if (!empty($modSettings['currentAttachmentUploadDir']))
-		{
-			if (!is_array($modSettings['attachmentUploadDir']))
-				$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-
-			// Just use the current path for temp files.
-			$attach_dirs = $modSettings['attachmentUploadDir'];
-		}
-		else
-		{
-			$attach_dirs = array($modSettings['attachmentUploadDir']);
-		}
+		// Just use the current path for temp files.
+		if (!is_array($modSettings['attachmentUploadDir']))
+			$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+		$attach_dirs = $modSettings['attachmentUploadDir'];
 
 		$current_check = 0;
 		$max_checks = 500;
@@ -1861,7 +1844,7 @@ function ApproveAttachments($attachments)
  */
 function ManageAttachmentPaths()
 {
-	global $modSettings, $scripturl, $context, $txt, $sourcedir, $smcFunc;
+	global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc;
 
 	// Since this needs to be done eventually.
 	if (!is_array($modSettings['attachmentUploadDir']))
@@ -1878,6 +1861,7 @@ function ManageAttachmentPaths()
 	{
 		checkSession();
 
+		$_POST['current_dir'] = (int) $_POST['current_dir'];
 		$new_dirs = array();
 		foreach ($_POST['dirs'] as $id => $path)
 		{
@@ -1885,42 +1869,115 @@ function ManageAttachmentPaths()
 			if ($id < 1)
 				continue;
 
+			// Hmm, a new path maybe?
+			if (!array_key_exists($id, $modSettings['attachmentUploadDir']))
+			{
+				// or is it?
+				if (in_array($path, $modSettings['attachmentUploadDir']) || in_array($boarddir . DIRECTORY_SEPARATOR . $path, $modSettings['attachmentUploadDir']))
+				{
+						$errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg'];
+						continue;
+				}
+
+				// OK, so let's try to create it then.
+				require_once($sourcedir . '/Attachments.php');
+				if (automanage_attachments_create_directory($path))
+					$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
+				else
+					$errors[] =  $path . ': ' . $txt[$context['dir_creation_error']];
+			}
+
 			// Changing a directory name?
 			if (!empty($modSettings['attachmentUploadDir'][$id]) && !empty($path) && $path != $modSettings['attachmentUploadDir'][$id])
 			{
 				if ($path != $modSettings['attachmentUploadDir'][$id] && !is_dir($path))
-					if (!rename($modSettings['attachmentUploadDir'][$id], $path))
+				{
+					if (!@rename($modSettings['attachmentUploadDir'][$id], $path))
+					{
+						$errors[] = $path . ': ' . $txt['attach_dir_no_rename'];
 						$path = $modSettings['attachmentUploadDir'][$id];
-				// @todo else{return some sorta error}
+					}
+				}
+				else
+				{
+					$errors[] = $path . ': ' . $txt['attach_dir_exists_msg'];
+					$path = $modSettings['attachmentUploadDir'][$id];
+				}
+
+				// Update the base directory path
+				if (!empty($modSettings['attachment_basedirectories']) && array_key_exists($id, $modSettings['attachment_basedirectories']))
+				{
+					$modSettings['attachment_basedirectories'][$id] = $path;
+					$update = array('attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']));
+				}
 			}
 
 			if (empty($path))
 			{
-				// Let's not try to delete a path with files in it.
-				$request = $smcFunc['db_query']('', '
-					SELECT COUNT(id_attach) AS num_attach
-					FROM {db_prefix}attachments
-					WHERE id_folder = {int:id_folder}',
-					array(
-						'id_folder' => (int) $id,
-					)
-				);
+				$path = $modSettings['attachmentUploadDir'][$id];
+
+				// It's not a good idea to delete the current directory. 
+				if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir']))
+					$errors[] = $path . ': ' . $txt['attach_dir_is_current'];
+				// Or the current base directory
+				elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id])
+					$errors[] = $path . ': ' . $txt['attach_dir_is_current_bd'];
+				else
+				{
+					// Let's not try to delete a path with files in it.
+					$request = $smcFunc['db_query']('', '
+						SELECT COUNT(id_attach) AS num_attach
+						FROM {db_prefix}attachments
+						WHERE id_folder = {int:id_folder}',
+						array(
+							'id_folder' => (int) $id,
+						)
+					);
 
-				list ($num_attach) = $smcFunc['db_fetch_row']($request);
-				$smcFunc['db_free_result']($request);
+					list ($num_attach) = $smcFunc['db_fetch_row']($request);
+					$smcFunc['db_free_result']($request);
 
-				// A check to see if it's a used base dir.
-				if (!empty($modSettings['attachment_basedirectories']))
-				{
-					// Count any sub-folders.
-					foreach ($modSettings['attachmentUploadDir'] as $sub)
-						if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false)
-							$num_attach++;
-				}
+					// A check to see if it's a used base dir.
+					if (!empty($modSettings['attachment_basedirectories']))
+					{
+						// Count any sub-folders.
+						foreach ($modSettings['attachmentUploadDir'] as $sub)
+							if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false)
+								$num_attach++;
+					}
+
+					// It's safe to delete. So try to delete the folder also
+					if ($num_attach == 0)
+					{
+						if (is_dir($path))
+							$doit = true;
+						elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path))
+						{
+							$doit = true;
+							$path = $boarddir . DIRECTORY_SEPARATOR . $path;
+						}
+
+						if (isset($doit))
+						{
+							unlink($path . '/.htaccess');
+							unlink($path . '/index.php');
+							if (!@rmdir($path))
+								$errors[] = $path . ': ' . $txt['attach_dir_no_delete'];
+						}
+					}
+					else
+						$errors[] = $path . ': ' . $txt['attach_dir_no_remove'];
+
+					// Remove it from the base directory list.
+					if (empty($errors) && !empty($modSettings['attachment_basedirectories']))
+					{
+						unset($modSettings['attachment_basedirectories'][$id]);
+						updateSettings(array('attachment_basedirectories' => serialize($modSettings['attachment_basedirectories'])));
+					}
 
-				// It's safe to delete.
-				if ($num_attach == 0)
-					continue;
+					if (empty($errors))
+						continue;
+				}
 			}
 
 			$new_dirs[$id] = $path;
@@ -1929,10 +1986,15 @@ function ManageAttachmentPaths()
 		// We need to make sure the current directory is right.
 		if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir']))
 			$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
-		$_POST['current_dir'] = (int) $_POST['current_dir'];
 
+		// Find the current directory if there's no value carried,
 		if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']]))
-			fatal_lang_error('attach_path_current_bad', false);
+		{
+			if (in_array($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir']))
+				$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
+			else
+				$_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir']));
+		}
 
 		// Going back to just one path?
 		if (count($new_dirs) == 1)
@@ -1951,24 +2013,27 @@ function ManageAttachmentPaths()
 						)
 					);
 
-				updateSettings(array(
-					'currentAttachmentUploadDir' => 0,
-					'attachmentUploadDir' => $dir,
-				));
+				$update = array(
+					'currentAttachmentUploadDir' => 1,
+					'attachmentUploadDir' => serialize(array(1 => $dir)),
+				);
 			}
 		}
 		else
 		{
-			// A check to prevent a user from adding an existing folder twice.
-			if (count($modSettings['attachmentUploadDir']) == count(array_unique($modSettings['attachmentUploadDir'])))
-				$new_dirs = array_unique($new_dirs);
-
 			// Save it to the database.
-			updateSettings(array(
+			$update = array(
 				'currentAttachmentUploadDir' => $_POST['current_dir'],
 				'attachmentUploadDir' => serialize($new_dirs),
-			));
+			);
 		}
+
+		if (!empty($update))
+			updateSettings($update);
+
+		if (!empty($errors))
+			$_SESSION['errors']['dir'] = $errors;
+
 		redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']);
 	}
 
@@ -1977,15 +2042,12 @@ function ManageAttachmentPaths()
 	{
 		checkSession();
 
-		if (!is_array($modSettings['attachmentUploadDir']))
-			$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-
 		// Changing the current base directory?
 		$_POST['current_base_dir'] = (int) $_POST['current_base_dir'];
 		if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir']))
 		{
 			if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']])
-				updateSettings(array(
+				$update = (array(
 					'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']],
 				));
 
@@ -1999,25 +2061,41 @@ function ManageAttachmentPaths()
 			$_POST['new_base_dir'] = htmlspecialchars($_POST['new_base_dir'], ENT_QUOTES);
 
 			$current_dir = $modSettings['currentAttachmentUploadDir'];
+
 			if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir']))
-				automanage_attachments_create_directory($_POST['new_base_dir']);
-				// @todo Something if return is false.
+				if (!automanage_attachments_create_directory($_POST['new_base_dir']))
+					$errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create'];
+			else
+				$errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_dupe_msg'];
+
 
 			$modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']);
 			if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories']))
 				$modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir'];
+			ksort($modSettings['attachment_basedirectories']);
 
-			updateSettings(array(
+			$update = (array(
 				'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
 				'basedirectory_for_attachments' => $_POST['new_base_dir'],
 				'currentAttachmentUploadDir' => $current_dir,
 			));
-			$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
-
 		}
+
+		if (!empty($errors))
+			$_SESSION['base'] = $errors;
+
+		if (!empty($update))
+			updateSettings($update);
+
 		redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']);
 	}
 
+	if (isset($_SESSION['errors']))
+	{
+		$errors = $_SESSION['errors'];
+		unset($_SESSION['errors']);
+	}
+
 	$listOptions = array(
 		'id' => 'attach_paths',
 		'base_href' => $scripturl . '?action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id'],
@@ -2032,7 +2110,7 @@ function ManageAttachmentPaths()
 				),
 				'data' => array(
 					'function' => create_function('$rowData', '
-						return \'<input type="radio" name="current_dir" value="\' . $rowData[\'id\'] . \'" \' . ($rowData[\'current\'] ? \' checked="checked"\' : \'\') . (!empty($rowData[\'automanage_attachments\']) ? \' disabled="disabled"\' : \'\') . \' class="input_radio" />\';
+						return \'<input type="radio" name="current_dir" value="\' . $rowData[\'id\'] . \'" \' . ($rowData[\'current\'] ? \' checked="checked"\' : \'\') . (!empty($rowData[\'disable_current\']) ? \' disabled="disabled"\' : \'\') . \' class="input_radio" />\';
 					'),
 					'style' => 'text-align: center; width: 10%;',
 				),
@@ -2043,7 +2121,7 @@ function ManageAttachmentPaths()
 				),
 				'data' => array(
 					'function' => create_function('$rowData', '
-						return \'<input type="hidden" name="dirs[\' . $rowData[\'id\'] . \']" value="\' . $rowData[\'path\'] . \'" /><input type="text" size="40" name="dirs[\' . $rowData[\'id\'] . \']" value="\' . $rowData[\'path\'] . \'"\' . (!empty($rowData[\'is_base_dir\']) ? \' disabled="disabled"\' : \'\') . \' class="input_text" style="width: 100%" />\';
+						return \'<input type="hidden" name="dirs[\' . $rowData[\'id\'] . \']" value="\' . $rowData[\'path\'] . \'" /><input type="text" size="40" name="dirs[\' . $rowData[\'id\'] . \']" value="\' . $rowData[\'path\'] . \'"\' . (!empty($rowData[\'disable_base_dir\']) ? \' disabled="disabled"\' : \'\') . \' class="input_text" style="width: 100%" />\';
 					'),
 					'style' => 'text-align: center; width: 40%;',
 				),
@@ -2085,12 +2163,17 @@ function ManageAttachmentPaths()
 				'value' => '<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" /><input type="submit" name="new_path" value="' . $txt['attach_add_path'] . '" class="button_submit" />&nbsp;<input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />',
 				'style' => 'text-align: right;',
 			),
-			!empty($errors['folder']) ? array(
+			empty($errors['dir']) ? array(
+				'position' => 'top_of_list',
+				'value' => $txt['attach_dir_desc'],
+				'style' => 'text-align: left; padding: 5px 10px',
+				'class' => 'windowbg2 smalltext'
+			) : array(
 				'position' => 'top_of_list',
-				'value' => implode('<br />', $errors['folder']),
+				'value' => $txt['attach_dir_save_problem'] . '<br />' . implode('<br />', $errors['dir']),
 				'style' => 'text-align: left;',
 				'class' => 'noticebox',
-			) : '',
+			),
 		),
 	);
 	require_once($sourcedir . '/Subs-List.php');
@@ -2154,81 +2237,28 @@ function ManageAttachmentPaths()
 					'value' => '<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" /><input type="submit" name="new_base_path" value="' . $txt['attach_add_path'] . '" class="button_submit" />&nbsp;<input type="submit" name="save2" value="' . $txt['save'] . '" class="button_submit" />',
 					'style' => 'text-align: right;',
 				),
-				!empty($errors['base']) ? array(
+				empty($errors['base']) ? array(
 					'position' => 'top_of_list',
-					'value' => implode('<br />', $errors['base']),
+					'value' => $txt['attach_dir_base_desc'],
+					'style' => 'text-align: left; padding: 5px 10px',
+					'class' => 'windowbg2 smalltext'
+				) : array(
+					'position' => 'top_of_list',
+					'value' => $txt['attach_dir_save_problem'] . '<br />' . implode('<br />', $errors['base']),
 					'style' => 'text-align: left;',
 					'class' => 'noticebox',
-				) : '',
+				),
 			),
 		);
 		createList($listOptions2);
 	}
 
-
 	// Fix up our template.
 	$context[$context['admin_menu_name']]['current_subsection'] = 'attachpaths';
 	$context['page_title'] = $txt['attach_path_manage'];
 	$context['sub_template'] = 'attachment_paths';
 }
 
-/**
- * Prepare the actual attachment directories to be displayed in the list.
- */
-function list_getBaseDirs()
-{
-	global $modSettings, $context, $txt;
-
-	if (empty($modSettings['attachment_basedirectories']))
-		return;
-
-	// The dirs should already have been unserialized but just in case...
-	if (!is_array($modSettings['attachmentUploadDir']))
-		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-	if (!is_array($modSettings['attachment_basedirectories']))
-		$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
-
-	if (count($modSettings['attachment_basedirectories']) == 0)
-		return;
-
-	$basedirs = array();
-	// Get a list of the base directories.
-	foreach ($modSettings['attachment_basedirectories'] as $id => $dir)
-	{
-		// Loop through the attach directory array to count the sub-directories
-		$cnt = 0;
-		foreach ($modSettings['attachmentUploadDir'] as $sid => $sub)
-			if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
-				$cnt++;
-
-		if (!is_dir($dir))
-			$status = 'does_not_exist';
-		elseif (!is_writeable($dir))
-			$status = 'not_writable';
-		else
-			$status = 'ok';
-
-		$basedirs[] = array(
-			'id' => $id,
-			'current' => $dir == $modSettings['basedirectory_for_attachments'],
-			'path' => $dir,
-			'num_dirs' => $cnt,
-			'status' => $status == 'ok' ? $txt['attach_dir_ok'] : ('<span class="error">' . $txt['attach_dir_' . $status] . '</span>'),
-		);
-	}
-
-	if (isset($_REQUEST['new_base_path']))
-		$basedirs[] = array(
-			'id' => '',
-			'current' => false,
-			'path' => '<input type="text" name="new_base_dir" value="" size="40" />',
-			'num_dirs' => '',
-			'status' => '',
-		);
-
-	return $basedirs;
-}
-
 /**
  * Prepare the actual attachment directories to be displayed in the list.
  */
@@ -2236,9 +2266,11 @@ function list_getAttachDirs()
 {
 	global $smcFunc, $modSettings, $context, $txt;
 
-	// The dirs should already have been unserialized but just in case...
-	if (!is_array($modSettings['attachmentUploadDir']))
-		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+	if (isset($_SESSION['dir_errors']))
+	{
+		$context['dir_errors'] = $_SESSION['dir_errors'];
+		unset($_SESSION['dir_errors']);
+	}
 
 	$request = $smcFunc['db_query']('', '
 		SELECT id_folder, COUNT(id_attach) AS num_attach, SUM(size) AS size_attach
@@ -2272,9 +2304,6 @@ function list_getAttachDirs()
 		$is_base_dir = false;
 		if (!empty($modSettings['attachment_basedirectories']))
 		{
-			if (!is_array($modSettings['attachment_basedirectories']))
-				$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
-
 			$is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']);
 
 			// Count any sub-folders.
@@ -2289,12 +2318,12 @@ function list_getAttachDirs()
 		$attachdirs[] = array(
 			'id' => $id,
 			'current' => $id == $modSettings['currentAttachmentUploadDir'],
-			'automanage_attachments' => isset($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'],
-			'is_base_dir' => $is_base_dir,
+			'disable_current' => isset($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] > 0,
+			'disable_base_dir' =>  $is_base_dir && $sub_dirs > 0 && !empty($files) && empty($error) && empty($save_errors),
 			'path' => $dir,
-			'current_size' => !empty($expected_size[$id]) ? round($expected_size[$id] / 1024, 2) : 0,
-			'num_files' => $expected_files[$id] - $sub_dirs,
-			'status' => $is_base_dir ? $txt['attach_dir_basedir'] : ($error ? '<div class="error">' : '') . sprintf($txt['attach_dir_' . $status], $context['session_id'], $context['session_var']) . ($error ? '</div>' : ''),
+			'current_size' => !empty($expected_size[$id]) ? comma_format($expected_size[$id] / 1024, 0) : 0,
+			'num_files' => comma_format($expected_files[$id] - $sub_dirs, 0) . ($sub_dirs > 0 ? ' (' . $sub_dirs . ')' : ''),
+			'status' => ($is_base_dir ? $txt['attach_dir_basedir'] . '<br />' : '') . ($error ? '<div class="error">' : '') . sprintf($txt['attach_dir_' . $status], $context['session_id'], $context['session_var']) . ($error ? '</div>' : ''),
 		);
 	}
 
@@ -2312,24 +2341,65 @@ function list_getAttachDirs()
 	return $attachdirs;
 }
 
+/**
+ * Prepare the base directories to be displayed in a list.
+ */
+function list_getBaseDirs()
+{
+	global $modSettings, $context, $txt;
+
+	if (empty($modSettings['attachment_basedirectories']))
+		return;
+
+	$basedirs = array();
+	// Get a list of the base directories.
+	foreach ($modSettings['attachment_basedirectories'] as $id => $dir)
+	{
+		// Loop through the attach directory array to count any sub-directories
+		$expected_dirs = 0;
+		foreach ($modSettings['attachmentUploadDir'] as $sid => $sub)
+			if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
+				$expected_dirs++;
+
+		if (!is_dir($dir))
+			$status = 'does_not_exist';
+		elseif (!is_writeable($dir))
+			$status = 'not_writable';
+		else
+			$status = 'ok';
+
+		$basedirs[] = array(
+			'id' => $id,
+			'current' => $dir == $modSettings['basedirectory_for_attachments'],
+			'path' => $dir,
+			'num_dirs' => $expected_dirs,
+			'status' => $status == 'ok' ? $txt['attach_dir_ok'] : ('<span class="error">' . $txt['attach_dir_' . $status] . '</span>'),
+		);
+	}
+
+	if (isset($_REQUEST['new_base_path']))
+		$basedirs[] = array(
+			'id' => '',
+			'current' => false,
+			'path' => '<input type="text" name="new_base_dir" value="" size="40" />',
+			'num_dirs' => '',
+			'status' => '',
+		);
+
+	return $basedirs;
+}
+
 /**
  * Checks the status of an attachment directory and returns an array
  *  of the status key, if that status key signifies an error, and
- *  the folder size.
+ *  the file count.
  *
  * @param string $dir
  * @param int $expected_files
  */
 function attachDirStatus($dir, $expected_files)
 {
-	global $sourcedir;
-
-	// If there's a problem. Let's try to fix it first.
-	if (!is_dir($dir) || !is_writable($dir))
-	{
-		require_once($sourcedir . '/Attachments.php');
-		automanage_attachments_create_directory($dir);
-	}
+	global $sourcedir, $context;
 
 	if (!is_dir($dir))
 		return array('does_not_exist', true, '');
@@ -2337,7 +2407,6 @@ function attachDirStatus($dir, $expected_files)
 		return array('not_writable', true, '');
 
 	// Everything is okay so far, start to scan through the directory.
-	$dir_size = 0;
 	$num_files = 0;
 	$dir_handle = dir($dir);
 	while ($file = $dir_handle->read())

+ 3 - 16
Sources/Post.php

@@ -871,17 +871,6 @@ function Post()
 		// If there are attachments, calculate the total size and how many.
 		$context['attachments']['total_size'] = 0;
 		$context['attachments']['quantity'] = 0;
-		if (!empty($context['current_attachments']))
-		if (!empty($modSettings['currentAttachmentUploadDir']))
-		{
-			if (!is_array($modSettings['attachmentUploadDir']))
-				$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-
-			// Just use the current path for temp files.
-			$current_attach_dir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
-		}
-		else
-			$current_attach_dir = $modSettings['attachmentUploadDir'];
 
 		// If this isn't a new post, check the current attachments.
 		if (isset($_REQUEST['msg']))
@@ -1761,14 +1750,11 @@ function Post2()
 						$attachIDs[] = $attachmentOptions['thumb'];
 				}
 			}
+			else
+				$attach_errors[] = '<dt>&nbsp;</dt>';
 
 			if (!empty($attachmentOptions['errors']))
 			{
-				if (isset($br))
-					$attach_errors[] = '<dt>&nbsp;</dt>';
-				else
-					$br = '';
-
 				// Sort out the errors for display and delete any associated files.
 				$attach_errors[] = '<dt>' . vsprintf($txt['attach_warning'], $attachment['name']) . '</dt>';
 				$log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file');
@@ -2077,6 +2063,7 @@ function Post2()
 		$context['error_message'] = '<dl>';
 		$context['error_message'] .= implode("\n", $attach_errors);
 		$context['error_message'] .= '</dl>';
+		$context['error_title'] = $txt['attach_error_title'];
 
 		$context['linktree'][] = array(
 			'url' => $scripturl . '?topic=' . $topic . '.0',

+ 5 - 6
Themes/default/Errors.template.php

@@ -220,7 +220,7 @@ function template_attachment_errors()
 	<div>
 		<div class="cat_bar">
 			<h3 class="catbg">
-				', $txt['attach_error_title'], '
+				', $context['error_title'], '
 			</h3>
 		</div>
 		<div class="windowbg">
@@ -228,11 +228,10 @@ function template_attachment_errors()
 			<div class="padding">
 				<div class="noticebox" />', 
 					$context['error_message'], '
-				</div>
-				<hr class="hrcolor" />
-				<a class="button_link" href="', $scripturl, $context['back_link'], '">', $txt['back'], '</a>
-				<span style="float: right; margin:.5em;"></span>
-				<a class="button_link" href="', $scripturl, $context['redirect_link'], '">', $txt['attach_continue'], '</a>
+				</div>',
+				!empty($context['back_link']) ? ('<a class="button_link" href="' . $scripturl . $context['back_link'] . '">' . $txt['back'] . '</a>') : '',
+				'<span style="float: right; margin:.5em;"></span>
+				<a class="button_link" href="', $scripturl, $context['redirect_link'], '">', $txt['continue'], '</a>
 				<br class="clear_right" />
 			</div>
 			<span class="botslice"><span></span></span>

+ 1 - 1
Themes/default/Post.template.php

@@ -436,7 +436,7 @@ function template_main()
 						</dt>
 						<dd class="smalltext">
 							', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '" />'), '
-							<input type="file" size="60" name="attachment[]" id="attachment1" class="input_file" /> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)';
+							<input type="file" size="60" multiple="multiple" name="attachment[]" id="attachment1" class="input_file" /> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)';
 
 			// Show more boxes if they aren't approaching that limit.
 			if ($context['num_allowed_attachments'] > 1)

+ 17 - 2
Themes/default/languages/Admin.english.php

@@ -378,9 +378,24 @@ $txt['attach_dir_does_not_exist'] = 'Does Not Exist';
 $txt['attach_dir_not_writable'] = 'Not Writable';
 $txt['attach_dir_files_missing'] = 'Files Missing (<a href="' . $scripturl . '?action=admin;area=manageattachments;sa=repair;%2$s=%1$s">Repair</a>)';
 $txt['attach_dir_unused'] = 'Unused';
+$txt['attach_dir_empty'] = 'Empty';
 $txt['attach_dir_ok'] = 'OK';
 $txt['attach_dir_basedir'] = 'Base directory';
 
+$txt['attach_dir_desc'] = 'Create new directories or change the current directory below. Directories can be renamed as long as they do not contain a sub-directory. If the new directory is to be in the created within the forum directory structure. Just the directory name can be used. To remove a directory, blank the path input field. Directories can not be deleted if they contain either files or sub-directories (shown in brackets next to the file count).';
+$txt['attach_dir_base_desc'] = 'You may use below to change the current base directory or create a new one. New base directories are also added to the Attachment Directory list. You may also designate an existing directory to be a base directory.';
+$txt['attach_dir_save_problem'] = 'Oops, there seems to be a problem.';
+$txt['attachments_no_create'] = 'Unable to create a new attachment directory. Please do so using a FTP client or your site file manager.';
+$txt['attachments_no_write'] = 'This directory has been created but is not writable. Please attempt to do so using a FTP client or your site file manager.';
+$txt['attach_dir_duplicate_msg'] = 'Unable to add. This directory already exists.';
+$txt['attach_dir_exists_msg'] = 'Unable to move. A directory already exists at that path.';
+$txt['attach_dir_base_dupe_msg'] = 'Unable to add. This base directory has already been created.';
+$txt['attach_dir_base_no_create'] = 'Unable to create. Please verify the path input. Or create this directory using an FTP client or site file manager and re-try.';
+$txt['attach_dir_no_rename'] = 'Unable to move or rename. Please verify that the path is correct or that this directory does not contain any sub-directories.';
+$txt['attach_dir_no_delete'] = 'Is not empty and can not be deleted. Please do so using a FTP client or site file manager.';
+$txt['attach_dir_no_remove'] = 'Still contains files or is a base directory and can not be deleted.';
+$txt['attach_dir_is_current'] = 'Unable to remove while it is selected as the current directory.';
+$txt['attach_dir_is_current_bd'] = 'Unable to remove while it is selected as the current base directory.';
 $txt['attach_last_dir'] = 'Last active attachment directory';
 $txt['attach_current_dir'] = 'Current attachment directory';
 $txt['attach_current'] = 'Current';
@@ -414,8 +429,8 @@ $txt['use_subdirectories_for_attachments'] = 'Create new directories within a ba
 $txt['use_subdirectories_for_attachments_note'] = 'Otherwise any new directories will be created within the forum\'s main directory.';
 $txt['basedirectory_for_attachments'] = 'Set a base directory for attachments';
 $txt['basedirectory_for_attachments_current'] = 'Current base directory';
-$txt['basedirectory_for_attachments_warning'] = '<div class="smalltext">Please note that the directory is wrong. SMF will use the last directory used before this was introduced</div>';
-$txt['attach_current_dir_warning'] = '<div class="smalltext">There seems to be a problem with this directory. (<a href="' . $scripturl . '?action=admin;area=manageattachments;sa=attachpaths">Attempt to correct</a>)</div>';
+$txt['basedirectory_for_attachments_warning'] = '<div class="smalltext">Please note that the directory is wrong. <br />(<a href="' . $scripturl . '?action=admin;area=manageattachments;sa=attachpaths">Attempt to correct</a>)</div>';
+$txt['attach_current_dir_warning'] = '<div class="smalltext">There seems to be a problem with this directory. <br />(<a href="' . $scripturl . '?action=admin;area=manageattachments;sa=attachpaths">Attempt to correct</a>)</div>';
 
 $txt['mods_cat_avatars'] = 'Avatars';
 $txt['avatar_directory'] = 'Avatars directory';

+ 0 - 1
Themes/default/languages/Post.english.php

@@ -197,7 +197,6 @@ $txt['digest_mod_act_split'] = '"%1$s" was split';
 $txt['attach_error_title'] = 'Error uploading your attachments.';
 $txt['attach_warning'] = 'There was a problem during the uploading of <strong>%1$s</strong>.';
 $txt['attach_check_nag'] = 'Unable to continue due to incomplete data (%1$s).';
-$txt['attach_continue'] = 'Continue';
 $txt['attach_max_total_file_size'] = 'Sorry, you are out of attachment space. The total attachment size allowed per post is %1$s KB. Space remaining is %2$s kB.';
 $txt['attach_folder_warning'] = 'The attachments directory can not be located. Please notify an administrator of this problem.';
 $txt['attach_folder_admin_warning'] = 'The path to the attachments directory (%1$s) is incorrect. Please correct it in the attachment settings.';

+ 1 - 0
Themes/default/languages/index.english.php

@@ -161,6 +161,7 @@ $txt['search_thistopic'] = 'This topic';
 $txt['search_members'] = 'Members';
 
 $txt['back'] = 'Back';
+$txt['continue'] = 'Continue';
 $txt['password_reminder'] = 'Password reminder';
 $txt['topic_started'] = 'Topic started by';
 $txt['title'] = 'Title';

+ 1 - 0
other/install_2-1_mysql.sql

@@ -1666,6 +1666,7 @@ VALUES ('smfVersion', '{$smf_version}'),
 	('attachmentThumbnails', '1'),
 	('attachmentThumbWidth', '150'),
 	('attachmentThumbHeight', '150'),
+	('use_subdirectories_for_attachments', '1'),
 	('censorIgnoreCase', '1'),
 	('mostOnline', '1'),
 	('mostOnlineToday', '1'),

+ 1 - 0
other/install_2-1_postgresql.sql

@@ -2155,6 +2155,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentEncryptFil
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentThumbnails', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentThumbWidth', '150');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentThumbHeight', '150');
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('use_subdirectories_for_attachments', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('censorIgnoreCase', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('mostOnline', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('mostOnlineToday', '1');

+ 1 - 0
other/install_2-1_sqlite.sql

@@ -1808,6 +1808,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentEncryptFil
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentThumbnails', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentThumbWidth', '150');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentThumbHeight', '150');
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('use_subdirectories_for_attachments', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('censorIgnoreCase', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('mostOnline', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('mostOnlineToday', '1');