Browse Source

Merge pull request #200 from Kays48/attachment_folder_update

Signed-off-by: emanuele <[email protected]>
emanuele 11 years ago
parent
commit
2591618c7f

+ 18 - 14
Sources/Attachments.php

@@ -23,11 +23,13 @@ function automanage_attachments_check_directory()
 	global $boarddir, $modSettings, $context;
 
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
-	if (empty($modSettings['automanage_attachments']))
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
+		$doit = true;
+	elseif (empty($modSettings['automanage_attachments']))
 		return;
-	elseif (!isset($_FILES) && !isset($doit))
+	elseif (!isset($_FILES))
 		return;
-	elseif (isset($_FILES))
+	elseif (isset($_FILES['attachment']))
 		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
 			if (!empty($dummy))
 			{
@@ -132,9 +134,9 @@ function automanage_attachments_create_directory($updir)
 
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
 
-	while (!is_dir($directory) || $count != -1)
+	while (!@is_dir($directory) || $count != -1)
 	{
-		if (!is_dir($directory))
+		if (!@is_dir($directory))
 		{
 			if (!@mkdir($directory,0755))
 			{
@@ -524,9 +526,11 @@ function attachmentChecks($attachID)
 			$request = $smcFunc['db_query']('', '
 				SELECT COUNT(*), SUM(size)
 				FROM {db_prefix}attachments
-				WHERE id_folder = {int:folder_id}',
+				WHERE id_folder = {int:folder_id}
+					AND attachment_type != {int:type}',
 				array(
-					'folder_id' => (empty($modSettings['currentAttachmentUploadDir']) ? 1 : $modSettings['currentAttachmentUploadDir']),
+					'folder_id' => $modSettings['currentAttachmentUploadDir'],
+					'type' => 1,
 				)
 			);
 			list ($context['dir_files'], $context['dir_size']) = $smcFunc['db_fetch_row']($request);
@@ -536,8 +540,8 @@ function attachmentChecks($attachID)
 		$context['dir_files']++;
 
 		// Are we about to run out of room? Let's notify the admin then.
-		if (empty($modSettings['attachment_full_notified']) && empty($modSettings['attachmentDirSizeLimit']) && $modSettings['attachmentDirSizeLimit'] > 4000 && $context['dir_size'] > ($modSettings['attachmentDirSizeLimit'] - 2000) * 1024
-			|| (empty($modSettings['attachmentDirFileLimit']) && $modSettings['attachmentDirFileLimit'] * .95 < $context['dir_files'] && $modSettings['attachmentDirFileLimit'] > 500))
+		if (empty($modSettings['attachment_full_notified']) && !empty($modSettings['attachmentDirSizeLimit']) && $modSettings['attachmentDirSizeLimit'] > 4000 && $context['dir_size'] > ($modSettings['attachmentDirSizeLimit'] - 2000) * 1024
+			|| (!empty($modSettings['attachmentDirFileLimit']) && $modSettings['attachmentDirFileLimit'] * .95 < $context['dir_files'] && $modSettings['attachmentDirFileLimit'] > 500))
 		{
 			require_once($sourcedir . '/Subs-Admin.php');
 			emailAdmins('admin_attachments_full');
@@ -546,7 +550,7 @@ function attachmentChecks($attachID)
 
 		// // No room left.... What to do now???
 		if (!empty($modSettings['attachmentDirFileLimit']) && $context['dir_files'] + 2 > $modSettings['attachmentDirFileLimit']
-			|| (!empty($modSettings['attachmentDirFileLimit']) && $context['dir_size'] > $modSettings['attachmentDirSizeLimit'] * 1024))
+			|| (!empty($modSettings['attachmentDirSizeLimit']) && $context['dir_size'] > $modSettings['attachmentDirSizeLimit'] * 1024))
 		{
 			if (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] == 1)
 			{
@@ -556,8 +560,8 @@ 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'] = $modSettings['currentAttachmentUploadDir'];
-					$context['dir_size'] = $_SESSION['temp_attachments'][$attachID]['size'];
-					$context['dir_files'] = 1;
+					$context['dir_size'] = 0;
+					$context['dir_files'] = 0;
 				}
 				// Or, let the user know that it ain't gonna happen.
 				else
@@ -751,8 +755,8 @@ function createAttachment(&$attachmentOptions)
 					{
 						rename($thumb_path, $context['attach_dir'] . '/' . $thumb_filename);
 						$thumb_path = $context['attach_dir'] . '/' . $thumb_filename;
-						$context['dir_size'] = $thumb_size;
-						$context['dir_files'] = 1;
+						$context['dir_size'] = 0;
+						$context['dir_files'] = 0;
 					}
 				}
 			}

+ 389 - 39
Sources/ManageAttachments.php

@@ -50,7 +50,8 @@ function ManageAttachments()
 		'moveAvatars' => 'MoveAvatars',
 		'repair' => 'RepairAttachments',
 		'remove' => 'RemoveAttachment',
-		'removeall' => 'RemoveAllAttachments'
+		'removeall' => 'RemoveAllAttachments',
+		'transfer' => 'TransferAttachments',
 	);
 
 	call_integration_hook('integrate_manage_attachments', array(&$subActions));
@@ -94,10 +95,14 @@ function ManageAttachmentSettings($return_config = false)
 	$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
 	$context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
 
+	// First time here?
+	if (empty($modSettings['attachment_basedirectories']) && $modSettings['currentAttachmentUploadDir'] == 1 && count($modSettings['attachmentUploadDir']) == 1)
+		$modSettings['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][1];
+
 	// If not set, show a default path for the base directory
 	if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments']))
-		if (!empty($modSettings['currentAttachmentUploadDir']))
-			$modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1];
+		if (is_dir($modSettings['attachmentUploadDir'][1]))
+			$modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1];		
 		else
 			$modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir'];
 
@@ -138,7 +143,7 @@ function ManageAttachmentSettings($return_config = false)
 			array('select', 'automanage_attachments', array(0 => $txt['attachments_normal'], 1 => $txt['attachments_auto_space'], 2 => $txt['attachments_auto_years'], 3 => $txt['attachments_auto_months'], 4 => $txt['attachments_auto_16'])),
 			array('check', 'use_subdirectories_for_attachments', 'subtext' => $txt['use_subdirectories_for_attachments_note']),
 			(empty($modSettings['attachment_basedirectories']) ? array('text', 'basedirectory_for_attachments', 40,) : array('var_message', 'basedirectory_for_attachments', 'message' => 'basedirectory_for_attachments_path', 'invalid' => empty($context['valid_basedirectory']), 'text_label' => (!empty($context['valid_basedirectory']) ? $txt['basedirectory_for_attachments_current'] : $txt['basedirectory_for_attachments_warning']))),
-			array('var_message', 'attach_current_directory', 'subtext' => $txt['attachmentUploadDir_multiple_configure'], 'message' => 'attachment_path', 'invalid' => empty($context['valid_upload_dir']), 'text_label' => (!empty($context['valid_upload_dir']) ? $txt['attach_current_dir'] : $txt['attach_current_dir_warning'])),
+			empty($modSettings['attachment_basedirectories']) && $modSettings['currentAttachmentUploadDir'] == 1 && count($modSettings['attachmentUploadDir']) == 1	? array('text', 'attachmentUploadDir', 'subtext' => $txt['attachmentUploadDir_multiple_configure'], 40, 'invalid' => !$context['valid_upload_dir']) : array('var_message', 'attach_current_directory', 'subtext' => $txt['attachmentUploadDir_multiple_configure'], 'message' => 'attachment_path', 'invalid' => empty($context['valid_upload_dir']), 'text_label' => (!empty($context['valid_upload_dir']) ? $txt['attach_current_dir'] : $txt['attach_current_dir_warning'])),
 			array('int', 'attachmentDirFileLimit', 'subtext' => $txt['zero_for_no_limit'], 6),
 			array('int', 'attachmentDirSizeLimit', 'subtext' => $txt['zero_for_no_limit'], 6, 'postinput' => $txt['kilobyte']),
 		'',
@@ -198,6 +203,15 @@ function ManageAttachmentSettings($return_config = false)
 	{
 		checkSession();
 
+		if (isset($_POST['attachmentUploadDir']))
+		{
+			if (!empty($_POST['attachmentUploadDir']) && $modSettings['attachmentUploadDir'] != $_POST['attachmentUploadDir'])
+				rename($modSettings['attachmentUploadDir'], $_POST['attachmentUploadDir']);
+
+			$modSettings['attachmentUploadDir'] = array(1 => $_POST['attachmentUploadDir']);
+			$_POST['attachmentUploadDir'] = serialize($modSettings['attachmentUploadDir']);
+		}
+
 		if (!empty($_POST['use_subdirectories_for_attachments']))
 		{
 			if(isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments']))
@@ -216,8 +230,10 @@ function ManageAttachmentSettings($return_config = false)
 				$currentAttachmentUploadDir = $modSettings['currentAttachmentUploadDir'];
 
 				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']))
 				{
@@ -226,6 +242,10 @@ function ManageAttachmentSettings($return_config = false)
 						'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
 						'currentAttachmentUploadDir' => $currentAttachmentUploadDir,
 					));
+
+					$_POST['use_subdirectories_for_attachments'] = 1;
+					$_POST['attachmentUploadDir'] = serialize($modSettings['attachmentUploadDir']);	
+
 				}
 			}
 		}
@@ -666,6 +686,7 @@ function MaintainFiles()
 	);
 	list ($context['num_attachments']) = $smcFunc['db_fetch_row']($request);
 	$smcFunc['db_free_result']($request);
+	$context['num_attachments'] = comma_format($context['num_attachments'], 0);
 
 	// Also get the avatar amount....
 	$request = $smcFunc['db_query']('', '
@@ -678,26 +699,53 @@ function MaintainFiles()
 	);
 	list ($context['num_avatars']) = $smcFunc['db_fetch_row']($request);
 	$smcFunc['db_free_result']($request);
+	$context['num_avatars'] = comma_format($context['num_avatars'], 0);
 
 	// Check the size of all the directories.
 	$request = $smcFunc['db_query']('', '
 		SELECT SUM(size)
-		FROM {db_prefix}attachments',
+		FROM {db_prefix}attachments
+		WHERE attachment_type != {int:type}',
 		array(
+			'type' => 1,
 		)
 	);
 	list ($attachmentDirSize) = $smcFunc['db_fetch_row']($request);
 	$smcFunc['db_free_result']($request);
-
-	// Divide it into kilobytes.
 	$attachmentDirSize /= 1024;
+	$context['attachment_total_size'] = comma_format($attachmentDirSize, 2);
 
-	// If they specified a limit only....
-	if (!empty($modSettings['attachmentDirSizeLimit']))
-		$context['attachment_space'] = max(round($modSettings['attachmentDirSizeLimit'] - $attachmentDirSize, 2), 0);
-	$context['attachment_total_size'] = round($attachmentDirSize, 2);
+	$request = $smcFunc['db_query']('', '
+		SELECT COUNT(*), SUM(size)
+		FROM {db_prefix}attachments
+		WHERE id_folder = {int:folder_id}
+			AND attachment_type != {int:type}',
+		array(
+			'folder_id' => $modSettings['currentAttachmentUploadDir'],
+			'type' => 1,
+		)
+	);
+	list ($current_dir_files, $current_dir_size) = $smcFunc['db_fetch_row']($request);
+	$smcFunc['db_free_result']($request);
+	$current_dir_size /= 1024;
 
-	$context['attach_multiple_dirs'] = !empty($modSettings['currentAttachmentUploadDir']);
+	if (!empty($modSettings['attachmentDirSizeLimit']))
+		$context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2);
+	$context['attachment_current_size'] = comma_format($current_dir_size, 2);
+
+	if (!empty($modSettings['attachmentDirFileLimit']))
+		$context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0);
+	$context['attachment_current_files'] = comma_format($current_dir_files, 0);
+	
+	$context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false;
+	$context['attach_dirs'] = $attach_dirs;
+	$context['base_dirs'] = !empty($modSettings['attachment_basedirectories']) ? unserialize($modSettings['attachment_basedirectories']) : array();
+	$context['checked'] = isset($_SESSION['checked']) ? $_SESSION['checked'] : true;
+	if (!empty($_SESSION['results']))
+	{
+		$context['results'] = implode('<br />', $_SESSION['results']);
+		unset($_SESSION['results']);
+	}
 }
 
 /**
@@ -1873,6 +1921,7 @@ function ManageAttachmentPaths()
 		$new_dirs = array();
 		foreach ($_POST['dirs'] as $id => $path)
 		{
+			$error = '';
 			$id = (int) $id;
 			if ($id < 1)
 				continue;
@@ -1915,8 +1964,14 @@ function ManageAttachmentPaths()
 				// Update the base directory path
 				if (!empty($modSettings['attachment_basedirectories']) && array_key_exists($id, $modSettings['attachment_basedirectories']))
 				{
+					$base = $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id] ? $path : $modSettings['basedirectory_for_attachments'];
+
 					$modSettings['attachment_basedirectories'][$id] = $path;
-					$update = array('attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']));
+					updateSettings(array(
+						'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
+						'basedirectory_for_attachments' => $base,
+					));
+					$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
 				}
 			}
 
@@ -1970,21 +2025,24 @@ function ManageAttachmentPaths()
 							unlink($path . '/.htaccess');
 							unlink($path . '/index.php');
 							if (!@rmdir($path))
-								$errors[] = $path . ': ' . $txt['attach_dir_no_delete'];
+								$error = $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'])));
+						// Remove it from the base directory list.
+						if (empty($error) && !empty($modSettings['attachment_basedirectories']))
+						{
+							unset($modSettings['attachment_basedirectories'][$id]);
+							updateSettings(array('attachment_basedirectories' => serialize($modSettings['attachment_basedirectories'])));
+							$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
+						}
 					}
+					else
+						$error = $path . ': ' . $txt['attach_dir_no_remove'];
 
-					if (empty($errors))
+					if (empty($error))
 						continue;
+					else
+						$errors[] = $error;
 				}
 			}
 
@@ -1998,12 +2056,46 @@ function ManageAttachmentPaths()
 		// Find the current directory if there's no value carried,
 		if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']]))
 		{
-			if (in_array($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir']))
+			if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir']))
 				$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
 			else
 				$_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir']));
 		}
 
+		// If the user wishes to go back, update the last_dir array
+		if ($_POST['current_dir'] !=  $modSettings['currentAttachmentUploadDir']&& !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0])))
+		{
+			if (!is_array($modSettings['last_attachments_directory']))
+				$modSettings['last_attachments_directory'] = unserialize($modSettings['last_attachments_directory']);
+			$num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1);
+			
+			if (is_numeric($num))
+			{
+				// Need to find the base folder.
+				$bid = -1;
+				$use_subdirectories_for_attachments = 0;
+				if (!empty($modSettings['attachment_basedirectories']))
+					foreach($modSettings['attachment_basedirectories'] as $bid => $base)
+						if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !==false)
+						{
+							$use_subdirectories_for_attachments = 1;
+							break;
+						}
+
+				if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false)
+					$bid = 0;
+
+				$modSettings['last_attachments_directory'][$bid] = (int) $num;
+				$modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : '';
+				$modSettings['use_subdirectories_for_attachments'] = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['use_subdirectories_for_attachments'] : 0;
+				updateSettings(array(
+					'last_attachments_directory' => serialize($modSettings['last_attachments_directory']),
+					'basedirectory_for_attachments' => $bid == 0 ? $modSettings['basedirectory_for_attachments'] : $modSettings['attachment_basedirectories'][$bid],
+					'use_subdirectories_for_attachments' => $use_subdirectories_for_attachments,
+				));
+			}
+		}
+
 		// Going back to just one path?
 		if (count($new_dirs) == 1)
 		{
@@ -2059,7 +2151,42 @@ function ManageAttachmentPaths()
 					'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']],
 				));
 
-			$modSettings['attachmentUploadDir'] = serialize($modSettings['attachmentUploadDir']);
+			//$modSettings['attachmentUploadDir'] = serialize($modSettings['attachmentUploadDir']);
+		}
+
+		If (isset($_POST['base_dir']))
+		{
+			foreach($_POST['base_dir'] as $id => $dir)
+			{
+				if (!empty($dir) && $dir != $modSettings['attachmentUploadDir'][$id])
+				{
+					if (@rename($modSettings['attachmentUploadDir'][$id], $dir))
+					{
+						$modSettings['attachmentUploadDir'][$id] = $dir;
+						$modSettings['attachment_basedirectories'][$id] = $dir;
+						$update = (array(
+							'attachmentUploadDir' => serialize($modSettings['attachmentUploadDir']),
+							'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
+							'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']],
+						));
+					}
+				}
+
+				if (empty($dir))
+				{
+					if ($id == $_POST['current_base_dir'])
+					{
+						$errors[] = $modSettings['attachmentUploadDir'][$id] . ': ' . $txt['attach_dir_is_current'];
+						continue;
+					}
+
+					unset($modSettings['attachment_basedirectories'][$id]);
+					$update = (array(
+						'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
+						'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']],
+					));
+				}
+			}
 		}
 
 		// Or adding a new one?
@@ -2071,11 +2198,10 @@ function ManageAttachmentPaths()
 			$current_dir = $modSettings['currentAttachmentUploadDir'];
 
 			if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir']))
+			{
 				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']))
@@ -2090,7 +2216,7 @@ function ManageAttachmentPaths()
 		}
 
 		if (!empty($errors))
-			$_SESSION['base'] = $errors;
+			$_SESSION['errors']['base'] = $errors;
 
 		if (!empty($update))
 			updateSettings($update);
@@ -2100,7 +2226,17 @@ function ManageAttachmentPaths()
 
 	if (isset($_SESSION['errors']))
 	{
-		$errors = $_SESSION['errors'];
+		if (is_array($_SESSION['errors']))
+		{
+			$errors = array();
+			if (!empty($_SESSION['errors']['dir']))
+				foreach($_SESSION['errors']['dir'] as $error)
+					$errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES);
+			
+			if (!empty($_SESSION['errors']['base']))
+				foreach($_SESSION['errors']['base'] as $error)
+					$errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES);
+		}
 		unset($_SESSION['errors']);
 	}
 
@@ -2283,17 +2419,13 @@ function list_getAttachDirs()
 {
 	global $smcFunc, $modSettings, $context, $txt;
 
-	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
 		FROM {db_prefix}attachments
+		WHERE attachment_type != {int:type}
 		GROUP BY id_folder',
 		array(
+			'type' => 1,
 		)
 	);
 
@@ -2335,7 +2467,7 @@ function list_getAttachDirs()
 		$attachdirs[] = array(
 			'id' => $id,
 			'current' => $id == $modSettings['currentAttachmentUploadDir'],
-			'disable_current' => isset($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] > 0,
+			'disable_current' => isset($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] > 1,
 			'disable_base_dir' =>  $is_base_dir && $sub_dirs > 0 && !empty($files) && empty($error) && empty($save_errors),
 			'path' => $dir,
 			'current_size' => !empty($expected_size[$id]) ? comma_format($expected_size[$id] / 1024, 0) : 0,
@@ -2388,7 +2520,7 @@ function list_getBaseDirs()
 		$basedirs[] = array(
 			'id' => $id,
 			'current' => $dir == $modSettings['basedirectory_for_attachments'],
-			'path' => $dir,
+			'path' => $expected_dirs > 0 ? $dir : ('<input type="text" name="base_dir[' . $id . ']" value="' . $dir . '" size="40" />'),
 			'num_dirs' => $expected_dirs,
 			'status' => $status == 'ok' ? $txt['attach_dir_ok'] : ('<span class="error">' . $txt['attach_dir_' . $status] . '</span>'),
 		);
@@ -2446,4 +2578,222 @@ function attachDirStatus($dir, $expected_files)
 		return array('ok', false, $num_files);
 }
 
-?>
+function TransferAttachments()
+{
+	global $modSettings, $context, $smcFunc, $sourcedir, $txt, $boarddir;
+	
+	checkSession();
+	
+	$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+	if (!empty($modSettings['attachment_basedirectories']))
+		$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
+	else
+		$modSettings['basedirectory_for_attachments'] = array();
+
+	$_POST['from'] = (int) $_POST['from'];
+	$_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0;
+	$_POST['to'] = (int) $_POST['to'];
+	$start = !empty($_POST['empty_it']) ? 0 : $modSettings['attachmentDirFileLimit'];
+	$_SESSION['checked'] = !empty($_POST['empty_it']) ? true : false;
+	$limit = 501;
+	$results = array();
+	$dir_files = 0;
+	$current_progress = 0;
+	$total_moved = 0;
+	$total_not_moved = 0;
+	
+	if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to'])))
+		$results[] = $txt['attachment_transfer_no_dir'];
+
+	if ($_POST['from'] == $_POST['to'])
+		$results[] = $txt['attachment_transfer_same_dir'];
+
+	if (empty($results))
+	{
+		// Get the total file count for the progess bar.
+		$request = $smcFunc['db_query']('', '
+			SELECT COUNT(*)
+			FROM {db_prefix}attachments
+			WHERE id_folder = {int:folder_id}
+				AND attachment_type != {int:attachment_type}',
+			array(
+				'folder_id' => $_POST['from'],
+				'attachment_type' => 1,
+			)
+		);
+		list ($total_progress) = $smcFunc['db_fetch_row']($request);
+		$smcFunc['db_free_result']($request);
+		$total_progress -= $start;
+
+		if ($total_progress < 1)
+			$results[] = $txt['attachment_transfer_no_find'];
+	}
+
+	if (empty($results))
+	{
+		// Where are they going?
+		if (!empty($_POST['auto']))
+		{
+			require_once($sourcedir . '/Attachments.php');
+
+			$modSettings['automanage_attachments'] = 1;
+			$modSettings['use_subdirectories_for_attachments'] = $_POST['auto'] == -1 ? 0 : 1;
+			$modSettings['basedirectory_for_attachments'] = $_POST['auto'] > 0 ? $modSettings['attachmentUploadDir'][$_POST['auto']] : $modSettings['basedirectory_for_attachments'];
+
+			automanage_attachments_check_directory();
+			$new_dir = $modSettings['currentAttachmentUploadDir'];
+		}
+		else
+			$new_dir = $_POST['to'];
+
+		$modSettings['currentAttachmentUploadDir'] = $new_dir;
+
+		$break = false;
+		while ($break == false)
+		{
+			@set_time_limit(300);
+			if (function_exists('apache_reset_timeout'))
+				@apache_reset_timeout();
+
+			// If limts are set, get the file count and size for the destination folder
+			if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit'])))
+			{
+				$request = $smcFunc['db_query']('', '
+					SELECT COUNT(*), SUM(size)
+					FROM {db_prefix}attachments
+					WHERE id_folder = {int:folder_id}
+						AND attachment_type != {int:attachment_type}',
+					array(
+						'folder_id' => $new_dir,
+						'attachment_type' => 1,
+					)
+				);
+				list ($dir_files, $dir_size) = $smcFunc['db_fetch_row']($request);
+				$smcFunc['db_free_result']($request);
+			}
+
+			// Find some attachments to move
+			$request = $smcFunc['db_query']('', '
+				SELECT id_attach, filename, id_folder, file_hash, size
+				FROM {db_prefix}attachments
+				WHERE id_folder = {int:folder}
+					AND attachment_type != {int:attachment_type}
+				LIMIT {int:start}, {int:limit}',
+				array(
+					'folder' => $_POST['from'],
+					'attachment_type' => 1,
+					'start' => $start,
+					'limit' => $limit,
+				)
+			);
+
+			if ($smcFunc['db_num_rows']($request) === 0)
+			{
+				if (empty($current_progress))
+					$results[] = $txt['attachment_transfer_no_find'];
+				break;
+			}
+
+			if ($smcFunc['db_num_rows']($request) < $limit)
+				$break = true;
+
+			// Move them
+			$moved = array();
+			while ($row = $smcFunc['db_fetch_assoc']($request))
+			{
+				// Size and file count check
+				if (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))
+				{
+					$dir_files++;
+					$dir_size += !empty($row['size']) ? $row['size'] : filesize($source);
+
+					// If we've reached a limit. Do something.
+					if (!empty($modSettings['attachmentDirSizeLimit']) && $dir_size > $modSettings['attachmentDirSizeLimit'] * 1024 || (!empty($modSettings['attachmentDirFileLimit']) && $dir_files >  $modSettings['attachmentDirFileLimit']))
+					{
+						if (!empty($_POST['auto']))
+						{
+							// Since we're in auto mode. Create a new folder and reset the counters.
+							automanage_attachments_by_space();
+
+							$results[] = sprintf($txt['attachments_transfered'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]);
+							if (!empty($total_not_moved))
+								$results[] = sprintf($txt['attachments_not_transfered'], $total_not_moved);
+
+							$dir_files = 0;
+							$total_moved = 0;
+							$total_not_moved = 0;
+
+							$break = false;
+							break;
+						}
+						else
+						{
+							// Hmm, not in auto. Time to bail out then...
+							$results[] = $txt['attachment_transfer_no_room'];
+							$break = true;
+							break;
+						}
+					}
+				}
+
+				$source = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
+				$dest = $modSettings['attachmentUploadDir'][$new_dir] . '/' . basename($source);
+
+				if (@rename($source, $dest))
+				{
+					$total_moved++;
+					$current_progress++;
+					$moved[] = $row['id_attach'];
+				}
+				else
+					$total_not_moved++;
+			}
+			$smcFunc['db_free_result']($request);
+
+			if (!empty($moved))
+			{
+				// Update the database
+				$smcFunc['db_query']('', '
+					UPDATE {db_prefix}attachments
+					SET id_folder = {int:new}
+					WHERE id_attach IN ({array_int:attachments})',
+					array(
+						'attachments' => $moved,
+						'new' => $new_dir,
+					)
+				);
+			}
+
+			$moved = array();
+			$new_dir = $modSettings['currentAttachmentUploadDir'];
+
+			// Create the progress bar.
+			if (!$break)
+			{
+				$percent_done = min(round($current_progress / $total_progress * 100, 0), 100);
+				$prog_bar = '
+					<div class="progress_bar">
+						<div class="full_bar">' . $percent_done . '%</div>
+						<div class="green_percent" style="width: ' . $percent_done . '%;">&nbsp;</div>
+					</div>';
+				// Write it to a file so it can be displayed
+				$fp = fopen($boarddir . '/progress.php', "w");        
+				fwrite($fp, $prog_bar);  
+				fclose($fp);  
+				usleep(500000);
+			}
+		}
+
+		$results[] = sprintf($txt['attachments_transfered'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]);
+		if (!empty($total_not_moved))
+			$results[] = sprintf($txt['attachments_not_transfered'], $total_not_moved);
+	}
+
+	$_SESSION['results'] = $results;
+	if (file_exists($boarddir . '/progress.php'))
+		unlink($boarddir . '/progress.php');
+
+	redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer');
+}
+
+?>

+ 3 - 1
Sources/Packages.php

@@ -226,7 +226,9 @@ function PackageInstallTest()
 	$smcFunc['db_free_result']($request);
 
 	$context['database_changes'] = array();
-	if (!empty($db_changes))
+	if (isset($packageInfo['uninstall']['database']))
+		$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
+	elseif (!empty($db_changes))
 	{
 		foreach ($db_changes as $change)
 		{

+ 1 - 1
Sources/Post.php

@@ -1241,7 +1241,7 @@ function Post2()
 
 	// Then try to upload any attachments.
 	$context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
-	if ($context['can_post_attachment'] && !empty($_FILES['attachment']) && empty($_POST['from_qr']))
+	if ($context['can_post_attachment'] && empty($_POST['from_qr']))
 	{
 		 require_once($sourcedir . '/Attachments.php');
 		 processAttachments();

+ 90 - 3
Themes/default/ManageAttachments.template.php

@@ -57,7 +57,7 @@ function template_browse()
 
 function template_maintenance()
 {
-	global $context, $settings, $options, $scripturl, $txt;
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
 
 	echo '
 	<div id="manage_attachments">
@@ -69,8 +69,12 @@ function template_maintenance()
 				<dl class="settings">
 					<dt><strong>', $txt['attachment_total'], ':</strong></dt><dd>', $context['num_attachments'], '</dd>
 					<dt><strong>', $txt['attachment_manager_total_avatars'], ':</strong></dt><dd>', $context['num_avatars'], '</dd>
-					<dt><strong>', $txt['attachmentdir_size' . ($context['attach_multiple_dirs'] ? '_current' : '')], ':</strong></dt><dd>', $context['attachment_total_size'], ' ', $txt['kilobyte'], '</dd>
-					<dt><strong>', $txt['attachment_space' . ($context['attach_multiple_dirs'] ? '_current' : '')], ':</strong></dt><dd>', isset($context['attachment_space']) ? $context['attachment_space'] . ' ' . $txt['kilobyte'] : $txt['attachmentdir_size_not_set'], '</dd>
+					<dt><strong>', $txt['attachmentdir_size'], ':</strong></dt><dd>', $context['attachment_total_size'], ' ', $txt['kilobyte'], '</dd>
+					<dt><strong>', $txt['attach_current_dir'], ':</strong></dt><dd>', $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']], '</dd>
+					<dt><strong>', $txt['attachmentdir_size_current'], ':</strong></dt><dd>', $context['attachment_current_size'], ' ', $txt['kilobyte'], '</dd>
+					<dt><strong>', $txt['attachment_space'], ':</strong></dt><dd>', isset($context['attachment_space']) ? $context['attachment_space'] . ' ' . $txt['kilobyte'] : $txt['attachmentdir_size_not_set'], '</dd>
+					<dt><strong>', $txt['attachmentdir_files_current'], ':</strong></dt><dd>', $context['attachment_current_files'], '</dd>
+					<dt><strong>', $txt['attachment_files'], ':</strong></dt><dd>', isset($context['attachment_files']) ? $context['attachment_files'] : $txt['attachmentdir_files_not_set'], '</dd>
 				</dl>
 			</div>
 		</div>
@@ -124,6 +128,89 @@ function template_maintenance()
 			</div>
 		</div>
 	</div>';
+	
+	echo '
+			<div id="transfer" class="cat_bar">
+				<h3 class="catbg">', $txt['attachment_transfer'], '</h3>
+			</div>';
+
+	if (!empty($context['results']))
+		echo '
+			<div class="noticebox">', $context['results'], '</div>';
+
+	echo '
+			<div class="windowbg">
+				<div class="content">
+					<form action="', $scripturl, '?action=admin;area=manageattachments;sa=transfer" method="post" accept-charset="', $context['character_set'], '">
+						<p>', $txt['attachment_transfer_desc'], '</p>
+						<hr class="hrcolor" />
+						<dl class="settings">
+							<dt>', $txt['attachment_transfer_from'], '</dt>
+							<dd><select name="from">
+								<option value="0">', $txt['attachment_transfer_select'], '</option>';
+
+	foreach ($context['attach_dirs'] as $id => $dir)
+		echo '
+								<option value="', $id, '">', $dir, '</option>';
+	echo '
+							</select></dd>
+							<dt>', $txt['attachment_transfer_auto'], '</dt>
+							<dd><select name="auto">
+								<option value="0">', $txt['attachment_transfer_auto_select'], '</option>
+								<option value="-1">', $txt['attachment_transfer_forum_root'], '</option>';
+
+	if (!empty($context['base_dirs']))
+		foreach ($context['base_dirs'] as $id => $dir)
+			echo '
+								<option value="', $id, '">', $dir, '</option>';
+	else
+			echo '
+								<option value="0" disabled="disabled">', $txt['attachment_transfer_no_base'], '</option>';
+
+	echo '
+							</select></dd>
+							<dt>', $txt['attachment_transfer_to'], '</dt>
+							<dd><select name="to">
+								<option value="0">', $txt['attachment_transfer_select'], '</option>';
+
+	foreach($context['attach_dirs'] as $id => $dir)
+		echo '
+								<option value="', $id, '">', $dir, '</option>';
+	echo '
+							</select></dd>';
+
+	if (!empty($modSettings['attachmentDirFileLimit']))
+		echo '
+							<dt>', $txt['attachment_transfer_empty'], '</dt>
+							<dd><input type="checkbox" name="empty_it"', $context['checked'] ? ' checked="checked"' : '', ' /></dd>';
+	echo '
+						</dl>
+						<hr class="hrcolor"/>
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+						<input type="submit" onclick="start_progress()" name="transfer" value="', $txt['attachment_transfer_now'], '" class="button_submit" />
+						<div id="progress_msg"></div>
+						<div id="show_progress" class="padding"></div>
+						<br class="clear_right" />
+					</form>
+					<script type="text/javascript"><!-- // --><![CDATA[
+						function start_progress() {
+							setTimeout(\'show_msg()\', 1000);
+						}
+
+						function show_msg() {
+							$(\'#progress_msg\').html(\'<div><img src="', $settings['actual_images_url'], '/loading.gif" alt="loading.gif" width="35" height="35" />&nbsp; ', $txt['attachment_transfer_progress'] , '<\/div>\');
+							show_progress();
+						}
+
+						function show_progress() {
+							$(\'#show_progress\').load("progress.php");
+							setTimeout(\'show_progress()\', 1500);
+						}
+
+					// ]]></script>
+				</div>
+			</div>
+			<br class="clear" />';
 }
 
 function template_attachment_repair()

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

@@ -395,7 +395,7 @@ function template_main()
 						<dt>
 							', $txt['attached'], ':
 						</dt>
-						<dd class="smalltext">
+						<dd class="smalltext" style="width: 100%;">
 							<input type="hidden" name="attach_del[]" value="0" />
 							', $txt['uncheck_unwatchd_attach'], ':
 						</dd>';
@@ -406,12 +406,12 @@ function template_main()
 							!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label>
 						</dd>';
 
-		if (!empty($context['files_in_session_warning']))
-			echo '
-						<dd class="smalltext">', $context['files_in_session_warning'], '</dd>';
-
 		echo '
 					</dl>';
+
+		if (!empty($context['files_in_session_warning']))
+			echo '
+					<div class="smalltext">', $context['files_in_session_warning'], '</div>';
 	}
 
 	// Is the user allowed to post any additional ones? If so give them the boxes to do it!

+ 30 - 7
Themes/default/languages/Admin.english.php

@@ -88,18 +88,22 @@ $txt['attachment_check_now'] = 'Run check now';
 $txt['attachment_pruning'] = 'Attachment Pruning';
 $txt['attachment_pruning_message'] = 'Message to add to post';
 $txt['attachment_pruning_warning'] = 'Are you sure you want to delete these attachments?\\nThis cannot be undone!';
-$txt['attachment_total'] = 'Total Attachments';
-$txt['attachmentdir_size'] = 'Total size of attachment directory';
+
+$txt['attachment_total'] = 'Total attachments';
+$txt['attachmentdir_size'] = 'Total size of all attachment directories';
 $txt['attachmentdir_size_current'] = 'Total size of current attachment directory';
-$txt['attachment_space'] = 'Total space available in attachment directory';
-$txt['attachment_space_current'] = 'Total space available in current attachment directory';
-$txt['attachment_options'] = 'File attachment options';
-$txt['attachment_log'] = 'Attachment log';
+$txt['attachmentdir_files_current'] = 'Total files in current attachment directory';
+$txt['attachment_space'] = 'Total space available';
+$txt['attachment_files'] = 'Total files remaining';
+
+$txt['attachment_options'] = 'File Attachment Options';
+$txt['attachment_log'] = 'Attachment Log';
 $txt['attachment_remove_old'] = 'Remove attachments older than';
 $txt['attachment_remove_size'] = 'Remove attachments larger than';
 $txt['attachment_name'] = 'Attachment name';
 $txt['attachment_file_size'] = 'File Size';
 $txt['attachmentdir_size_not_set'] = 'No maximum directory size is currently set';
+$txt['attachmentdir_files_not_set'] = 'No directory file limit is currently set';
 $txt['attachment_delete_admin'] = '[attachment deleted by admin]';
 $txt['live'] = 'Live from Simple Machines...';
 $txt['remove_all'] = 'Clear Log';
@@ -331,7 +335,7 @@ $txt['attachment_manager_thumbs'] = 'Thumbnails';
 $txt['attachment_manager_last_active'] = 'Last Active';
 $txt['attachment_manager_member'] = 'Member';
 $txt['attachment_manager_avatars_older'] = 'Remove avatars from members not active for more than';
-$txt['attachment_manager_total_avatars'] = 'Total Avatars';
+$txt['attachment_manager_total_avatars'] = 'Total avatars';
 
 $txt['attachment_manager_avatars_no_entries'] = 'There are currently no avatars.';
 $txt['attachment_manager_attachments_no_entries'] = 'There are currently no attachments.';
@@ -432,6 +436,25 @@ $txt['basedirectory_for_attachments_current'] = 'Current base directory';
 $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['attachment_transfer'] = 'Transfer Attachments';
+$txt['attachment_transfer_desc'] = 'Transfer files betwen directories.';
+$txt['attachment_transfer_select'] = 'Select directory';
+$txt['attachment_transfer_now'] = 'Transfer';
+$txt['attachment_transfer_from'] = 'Transfer files from';
+$txt['attachment_transfer_auto'] = 'Automatically by space or file count';
+$txt['attachment_transfer_auto_select'] = 'Select base directory';
+$txt['attachment_transfer_to'] = 'Or to a specific directory.';
+$txt['attachment_transfer_empty'] = 'Empty the source directory';
+$txt['attachment_transfer_no_base'] = 'No base directories available.';
+$txt['attachment_transfer_forum_root'] = 'Forum root directory.';
+$txt['attachment_transfer_no_room'] = 'Directory size or file count limit reached.';
+$txt['attachment_transfer_no_find'] = 'No files were found to transfer.';
+$txt['attachments_transfered'] = '%1$d files were transfered to %2$s';
+$txt['attachments_not_transfered'] = '%1$d files were not transfered.';
+$txt['attachment_transfer_no_dir'] = 'Either the source directory or one of the target options were not selected.';
+$txt['attachment_transfer_same_dir'] = 'You cannot select the same directory as both the source and target.';
+$txt['attachment_transfer_progress'] = 'Please wait. Transfer in progess.';
+
 $txt['mods_cat_avatars'] = 'Avatars';
 $txt['avatar_directory'] = 'Avatars directory';
 $txt['avatar_url'] = 'Avatars URL';

+ 2 - 2
Themes/default/languages/Packages.english.php

@@ -96,7 +96,7 @@ $txt['package_file'] = 'File';
 $txt['package_tree'] = 'Tree';
 $txt['execute_modification'] = 'Execute Modification';
 $txt['execute_code'] = 'Execute Code';
-$txt['execute_database_changes'] = 'Adapt Database';
+$txt['execute_database_changes'] = 'Execute file';
 $txt['execute_hook_add'] = 'Add Hook';
 $txt['execute_hook_remove'] = 'Remove Hook';
 $txt['execute_hook_action'] = 'Adapting hook %1$s';
@@ -188,7 +188,7 @@ $txt['package_download_filename_info'] = 'Optional value.  Should be used when t
 
 $txt['package_db_uninstall'] = 'Remove all data associated with this modification.';
 $txt['package_db_uninstall_details'] = 'Details';
-$txt['package_db_uninstall_actions'] = 'Checking this option will result in the following database changes';
+$txt['package_db_uninstall_actions'] = 'Checking this option will result in the following actions';
 $txt['package_db_remove_table'] = 'Drop table &quot;%1$s&quot;';
 $txt['package_db_remove_column'] = 'Remove column &quot;%2$s&quot; from &quot;%1$s&quot;';
 $txt['package_db_remove_index'] = 'Remove index &quot;%1$s&quot; from &quot;%2$s&quot;';

+ 0 - 4
Themes/default/scripts/admin.js

@@ -652,8 +652,6 @@ function toggleSubDir ()
 		document.getElementById('setting_use_subdirectories_for_attachments').parentNode.style.display = "none";
 		dir_elem.style.display = "none";
 		document.getElementById('setting_basedirectory_for_attachments').parentNode.style.display = "none";
-		document.getElementById('attachmentUploadDir').parentNode.style.display = "";
-		document.getElementById('setting_attachmentUploadDir').parentNode.style.display = "";
 	}
 	else
 	{
@@ -661,8 +659,6 @@ function toggleSubDir ()
 		document.getElementById('setting_use_subdirectories_for_attachments').parentNode.style.display = "";
 		dir_elem.style.display = "";
 		document.getElementById('setting_basedirectory_for_attachments').parentNode.style.display = "";
-		document.getElementById('attachmentUploadDir').parentNode.style.display = "none";
-		document.getElementById('setting_attachmentUploadDir').parentNode.style.display = "none";
 	}
 		toggleBaseDir();
 }

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

@@ -1682,6 +1682,7 @@ VALUES ('smfVersion', '{$smf_version}'),
 	('attachmentPostLimit', '192'),
 	('attachmentNumPerPostLimit', '4'),
 	('attachmentDirSizeLimit', '10240'),
+	('attachmentDirFileLimit', '1000'),
 	('attachmentUploadDir', '{$boarddir}/attachments'),
 	('attachmentExtensions', 'doc,gif,jpg,mpg,pdf,png,txt,zip'),
 	('attachmentCheckExtensions', '0'),

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

@@ -2171,6 +2171,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentSizeLimit'
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentPostLimit', '192');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentNumPerPostLimit', '4');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentDirSizeLimit', '10240');
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentDirFileLimit', '1000');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentUploadDir', '{$boarddir}/attachments');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentExtensions', 'doc,gif,jpg,mpg,pdf,png,txt,zip');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentCheckExtensions', '0');

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

@@ -1824,6 +1824,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentSizeLimit'
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentPostLimit', '192');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentNumPerPostLimit', '4');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentDirSizeLimit', '10240');
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentDirFileLimit', '1000');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentUploadDir', '{$boarddir}/attachments');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentExtensions', 'doc,gif,jpg,mpg,pdf,png,txt,zip');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachmentCheckExtensions', '0');