Răsfoiți Sursa

'nuther commit.

Resolved some operational inconsistencies as well as multiple bug fixes
Kays48 12 ani în urmă
părinte
comite
9ad05a7005

+ 1 - 0
Sources/Admin.php

@@ -276,6 +276,7 @@ function AdminMain()
 						'browse' => array($txt['attachment_manager_browse']),
 						'attachments' => array($txt['attachment_manager_settings']),
 						'avatars' => array($txt['attachment_manager_avatar_settings']),
+						'attachpaths' => array($txt['attach_directories']),
 						'maintenance' => array($txt['attachment_manager_maintenance']),
 					),
 				),

+ 53 - 60
Sources/Attachments.php

@@ -18,14 +18,12 @@
 if (!defined('SMF'))
 	die('Hacking attempt...');
 
-function automanage_attachments_check_directory($return = false)
+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 (isset($_GET['action']) && $_GET['action'] == 'admin')
-		$doit = true;
-	elseif (empty($modSettings['automanage_attachments']))
+	if (empty($modSettings['automanage_attachments']))
 		return;
 	elseif (!isset($_FILES) && !isset($doit))
 		return;
@@ -48,12 +46,17 @@ function automanage_attachments_check_directory($return = false)
 	$rand1 = $rand[1];
 	$rand = $rand[0];
 
-	if (!empty($modSettings['attachment_basedirectories']))
+	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
 	{
-		if (!is_array($modSettings['attachment_basedirectories']))
-			$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
-		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $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']);
+	}
+	else
+		$base_dir = 0;
 
+	if ($modSettings['automanage_attachments'] == 1)
+	{
 		if (!isset($modSettings['last_attachments_directory']))
 			$modSettings['last_attachments_directory'] = array();
 		if (!is_array($modSettings['last_attachments_directory']))
@@ -78,10 +81,10 @@ function automanage_attachments_check_directory($return = false)
 			$updir = $basedirectory . DIRECTORY_SEPARATOR . $year . DIRECTORY_SEPARATOR . $month;
 			break;
 		case 4:
-			$updir = $basedirectory . DIRECTORY_SEPARATOR . (empty($modSettings['use_subdirectories_for_attachments']) ? 'attachments-' : '') . $rand;
+			$updir = $basedirectory . DIRECTORY_SEPARATOR . (empty($modSettings['use_subdirectories_for_attachments']) ? 'attachments-' : 'random_') . $rand;
 			break;
 		case 5:
-			$updir = $basedirectory . DIRECTORY_SEPARATOR . (empty($modSettings['use_subdirectories_for_attachments']) ? 'attachments-' : '') . $rand . DIRECTORY_SEPARATOR . $rand1;
+			$updir = $basedirectory . DIRECTORY_SEPARATOR . (empty($modSettings['use_subdirectories_for_attachments']) ? 'attachments-' : 'random_') . $rand . DIRECTORY_SEPARATOR . $rand1;
 			break;
 		default :
 			$updir = '';
@@ -89,15 +92,14 @@ function automanage_attachments_check_directory($return = false)
 
 	if (!is_array($modSettings['attachmentUploadDir']) && !empty($modSettings['currentAttachmentUploadDir']))
 		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-
 	if (!is_array($modSettings['attachmentUploadDir']) || (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)))
-		$outputCreation = automanage_attachments_create_directory($updir, $return);
+		$outputCreation = automanage_attachments_create_directory($updir);
 	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
 		$outputCreation = true;
 
 	if ($outputCreation)
 	{
-		if (!is_array($modSettings['attachmentUploadDir']) && !empty($modSettings['currentAttachmentUploadDir']))
+		if (!is_array($modSettings['attachmentUploadDir']))
 			$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
 
 		$modSettings['currentAttachmentUploadDir'] = array_search($updir, $modSettings['attachmentUploadDir']);
@@ -112,14 +114,14 @@ function automanage_attachments_check_directory($return = false)
 	return $outputCreation;
 }
 
-function automanage_attachments_create_directory($updir, $return = false)
+function automanage_attachments_create_directory($updir)
 {
 	global $modSettings, $initial_error, $context;
 
 	$tree = mama_get_directory_tree_elements($updir);
 	$count = count($tree);
 
-	$directory = mama_init_dir($tree, $count, $return);
+	$directory = mama_init_dir($tree, $count);
 	if ($directory === false)
 		return false;
 
@@ -136,11 +138,9 @@ function automanage_attachments_create_directory($updir, $return = false)
 				else
 				{
 					$context['dir_creation_error'] = 'attachments_no_create';
-					if ($return)
-						return false;
+					return false;
 				}
 			}
-			$success = true;
 		}
 
 		$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -163,8 +163,7 @@ function automanage_attachments_create_directory($updir, $return = false)
 					else
 					{
 						$context['dir_creation_error'] = 'attachments_no_write';
-						if ($return)
-							return false;
+						return false;
 					}
 				}
 			}
@@ -172,29 +171,27 @@ function automanage_attachments_create_directory($updir, $return = false)
 	}
 
 	// Everything seems fine...let's create the .htaccess
-	if (is_writable($directory) && !file_exists($directory . DIRECTORY_SEPARATOR . '.htacess'))
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htacess'))
 		secureDirectory($directory, true);
 
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
 	$directory = rtrim($directory, $sep);
-	if (!empty($modSettings['currentAttachmentUploadDir']))
-	{
-		if (!is_array($modSettings['attachmentUploadDir']) && unserialize($modSettings['attachmentUploadDir']))
-			$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-	}
-	else
+
+	if (!is_array($modSettings['attachmentUploadDir']))
+		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+
+	// Only update if it's a new directory
+	if (!in_array($directory, $modSettings['attachmentUploadDir']))
 	{
-		$modSettings['attachmentUploadDir'] = array(
-			1 => $modSettings['attachmentUploadDir']
-		);
-	}
+		$modSettings['currentAttachmentUploadDir'] = max(array_keys($modSettings['attachmentUploadDir'])) +1;
+		$modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']] = $updir;
 
-	$modSettings['attachmentUploadDir'][count($modSettings['attachmentUploadDir'])+1] = $updir;
-	updateSettings(array(
-		'attachmentUploadDir' => serialize($modSettings['attachmentUploadDir']),
-		'currentAttachmentUploadDir' => array_search($updir, $modSettings['attachmentUploadDir']),
-	));
-	$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+		updateSettings(array(
+			'attachmentUploadDir' => serialize($modSettings['attachmentUploadDir']),
+			'currentAttachmentUploadDir' => $modSettings['currentAttachmentUploadDir'],
+		), true);
+		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+	}
 
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
 	$context['id_folder'] = $modSettings['currentAttachmentUploadDir'];
@@ -206,19 +203,26 @@ function automanage_attachments_by_space()
 {
 	global $modSettings, $boarddir, $context;
 
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
+		return;
+
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
 	//Just to be sure: I don't want directory separators at the end
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
 	$basedirectory = rtrim($basedirectory, $sep);
 
 	// Get the current base directory
-	if (!is_array($modSettings['attachment_basedirectories']))
-		$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
-	$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
+	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;
+	}
+	else
+		$base_dir = 0;
 
 	// Get the last attachment directory for that base directory
-	if (!isset($modSettings['last_attachments_directory']))
-		$modSettings['last_attachments_directory'] = array();
 	if (!is_array($modSettings['last_attachments_directory']))
 		$modSettings['last_attachments_directory'] = unserialize($modSettings['last_attachments_directory']);
 	if (empty($modSettings['last_attachments_directory'][$base_dir]))
@@ -226,8 +230,8 @@ function automanage_attachments_by_space()
 	// And increment it.
 	$modSettings['last_attachments_directory'][$base_dir]++;
 
-	$updir = $basedirectory . '/attachments_' . $modSettings['last_attachments_directory'][$base_dir];
-	if (automanage_attachments_create_directory($updir, true))
+	$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']);
@@ -262,19 +266,14 @@ function mama_get_directory_tree_elements ($directory)
 	else
 	{
 		if (substr($directory, 0, 1)!=DIRECTORY_SEPARATOR)
-		{
-			if(!$return)
-				//TODO Future development maybe change to a personalized error message
-				fatal_lang_error('attachments_no_write', 'critical');
-			else
-				return false;
-		}
+			return false;
+
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory,DIRECTORY_SEPARATOR));
 	}
 	return $tree;
 }
 
-function mama_init_dir (&$tree, &$count, $return)
+function mama_init_dir (&$tree, &$count)
 {
 	$directory = '';
 	// If on Windows servers the first part of the path is the drive (e.g. "C:")
@@ -286,13 +285,7 @@ function mama_init_dir (&$tree, &$count, $return)
 		if (preg_match('/^[a-z]:$/i',$tree[0]))
 			$directory = array_shift($tree);
 		else
-		{
-			if (!$return)
-				//TODO Future development maybe change to a personalized error message
-				fatal_lang_error('attachments_no_write', 'critical');
-			else
-				return false;
-		}
+			return false;
 
 		$count--;
 	}
@@ -305,7 +298,7 @@ function processAttachments()
 
 	// Make sure we're uploading to the right place.
 	if (!empty($modSettings['automanage_attachments']))
-		automanage_attachments_check_directory(true);
+		automanage_attachments_check_directory();
 
 	if (!empty($modSettings['currentAttachmentUploadDir']))
 	{

+ 14 - 3
Sources/Load.php

@@ -175,6 +175,17 @@ function reloadSettings()
 	// Is post moderation alive and well?
 	$modSettings['postmod_active'] = isset($modSettings['admin_features']) ? in_array('pm', explode(',', $modSettings['admin_features'])) : true;
 
+	// Here to justify the name of this function. :P
+	// It should be added to the install and upgrade scripts.
+	// But since the convertors need to be updated also. This is easier.
+	if (empty($modSettings['currentAttachmentUploadDir']))
+	{
+		updateSettings(array(
+			'attachmentUploadDir' => serialize(array(1 => $modSettings['attachmentUploadDir'])),
+			'currentAttachmentUploadDir' => 1,
+		));
+	}
+
 	// Integration is cool.
 	if (defined('SMF_INTEGRATION_SETTINGS'))
 	{
@@ -940,7 +951,7 @@ function loadMemberData($users, $is_name = false, $set = 'normal')
 
 	// Allow mods to easily add to the selected member data
 	call_integration_hook('integrate_load_member_data', array(&$select_columns, &$select_tables));
-	
+
 	if (!empty($users))
 	{
 		// Load the member's data.
@@ -1644,7 +1655,7 @@ function loadTheme($id_theme = 0, $initialize = true)
 		// If not a user variant, select the default.
 		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
 			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
-	
+
 		// Do this to keep things easier in the templates.
 		$context['theme_variant'] = '_' . $context['theme_variant'];
 		$context['theme_variant_url'] = $context['theme_variant'] . '/';
@@ -2496,7 +2507,7 @@ function cache_quick_get($key, $file, $function, $params, $level = 1)
 /**
  * Puts value in the cache under key for ttl seconds.
  *
- * - It may "miss" so shouldn't be depended on 
+ * - It may "miss" so shouldn't be depended on
  * - Uses the cahce engine chosen in the ACP and saved in settings.php
  * - It supports:
  *     Turck MMCache: http://turck-mmcache.sourceforge.net/index_old.html#api

+ 302 - 114
Sources/ManageAttachments.php

@@ -86,19 +86,14 @@ function ManageAttachments()
 
 function ManageAttachmentSettings($return_config = false)
 {
-	global $txt, $modSettings, $scripturl, $context, $options, $sourcedir;
+	global $txt, $modSettings, $scripturl, $context, $options, $sourcedir, $boarddir;
 
 	require_once($sourcedir . '/Attachments.php');
 
 	// Get the current attachment directory.
-	if (!empty($modSettings['currentAttachmentUploadDir']))
-	{
-		if (!is_array($modSettings['attachmentUploadDir']))
-			$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-		$context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
-	}
-	else
-		$context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'];
+	if (!is_array($modSettings['attachmentUploadDir']))
+		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+	$context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
 
 	// If not set, show a default path for the base directory
 	if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments']))
@@ -107,9 +102,6 @@ function ManageAttachmentSettings($return_config = false)
 		else
 			$modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir'];
 
-	if (!empty($modSettings['automanage_attachments']))
-		automanage_attachments_check_directory();
-
 	$context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']);
 
 	if (!empty($modSettings['automanage_attachments']))
@@ -117,8 +109,14 @@ function ManageAttachmentSettings($return_config = false)
 	else
 		$context['valid_basedirectory'] = true;
 
+	// 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['attachmentUploadDir_multiple_configure'] = '<a href="' . $scripturl . '?action=admin;area=manageattachments;sa=attachpaths">[' . $txt['attachmentUploadDir_multiple_configure'] . ']</a>';
-	$txt['basedirectory_for_attachments_warning'] = $txt['basedirectory_for_attachments'] . $txt['basedirectory_for_attachments_warning'];
+	$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'];
+	$txt['basedirectory_for_attachments_warning'] = $txt['basedirectory_for_attachments_current'] . $txt['basedirectory_for_attachments_warning'];
 
 	// Perform a test to see if the GD module or ImageMagick are installed.
 	$testImg = get_extension_funcs('gd') || class_exists('Imagick');
@@ -138,10 +136,10 @@ function ManageAttachmentSettings($return_config = false)
 			array('check', 'attachmentRecodeLineEndings'),
 		'',
 			// Directory and size limits.
-			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'], 5 => $txt['attachments_auto_16x16'])),
-			array('text', 'basedirectory_for_attachments', 40, 'invalid' => empty($context['valid_basedirectory']),	'text_label' => (!empty($context['valid_basedirectory']) ? $txt['basedirectory_for_attachments'] : $txt['basedirectory_for_attachments_warning'])),
+			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['currentAttachmentUploadDir'])) ? array('text', 'attachmentUploadDir', 40, 'invalid' => !$context['valid_upload_dir']) : array('var_message', 'attachmentUploadDir_multiple', 'message' =>  'attachmentUploadDir_multiple_configure'),
+			(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'])),
 			array('int', 'attachmentDirFileLimit', 'subtext' => $txt['zero_for_no_limit'], 6),
 			array('int', 'attachmentDirSizeLimit', 'subtext' => $txt['zero_for_no_limit'], 6, 'postinput' => $txt['kilobyte']),
 		'',
@@ -172,41 +170,20 @@ function ManageAttachmentSettings($return_config = false)
 			array('warning', 'attachment_thumb_memory_note'),
 			array('text', 'attachmentThumbWidth', 6),
 			array('text', 'attachmentThumbHeight', 6),
+		'',
+			array('int', 'max_image_width', 'subtext' => $txt['zero_for_no_limit']),
+			array('int', 'max_image_height', 'subtext' => $txt['zero_for_no_limit']),
 	);
 
 	$context['settings_post_javascript'] = '
 	var storing_type = document.getElementById(\'automanage_attachments\');
 	var base_dir = document.getElementById(\'use_subdirectories_for_attachments\');
 
-	mod_addEvent(storing_type, \'change\', mod_toggleSubDir);
-	mod_addEvent(base_dir, \'change\', mod_toggleBaseDir);
-	mod_toggleSubDir();
-
-	function mod_addEvent(control, ev, fn){
-		if (control.addEventListener){
-			control.addEventListener(ev, fn, false);
-		} else if (control.attachEvent){
-			control.attachEvent(\'on\'+ev, fn);
-		}
-	}
-
-	function mod_toggleSubDir(){
-		var select_elem = document.getElementById(\'automanage_attachments\');
-		var use_sub_dir = document.getElementById(\'use_subdirectories_for_attachments\');
-
-		use_sub_dir.disabled = !Boolean(select_elem.selectedIndex);
-		mod_toggleBaseDir();
-	}
-	function mod_toggleBaseDir(){
-		var select_elem = document.getElementById(\'automanage_attachments\');
-		var sub_dir = document.getElementById(\'use_subdirectories_for_attachments\');
-		var dir_elem = document.getElementById(\'basedirectory_for_attachments\');
-		if(select_elem.selectedIndex==0){
-			dir_elem.disabled = 1;
-		} else {
-			dir_elem.disabled = !sub_dir.checked;
-		}
-	}';
+	createEventListener(storing_type)
+	storing_type.addEventListener("change", toggleSubDir, false);
+	createEventListener(base_dir)
+	base_dir.addEventListener("change", toggleSubDir, false);
+	toggleSubDir();';
 
 	call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars));
 
@@ -222,46 +199,43 @@ function ManageAttachmentSettings($return_config = false)
 	{
 		checkSession();
 
-		if(isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments']))
-			$_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
+		if (!empty($_POST['use_subdirectories_for_attachments']))
+		{
+			if(isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments']))
+				$_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
 
-		// @todo add "basedirectory_for_attachments" to install & upgrade scripts
-		if (empty($modSettings['basedirectory_for_attachments']))
-			$modSettings['basedirectory_for_attachments'] = '';
+			if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories']))
+			{
+				if (!is_array($modSettings['attachment_basedirectories']))
+					$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
+			}
+			else
+				$modSettings['attachment_basedirectories'] = array();
 
-		// Create a new base directory if that's being changed and not there.
-		if (!empty($_POST['basedirectory_for_attachments']) && !is_dir($_POST['basedirectory_for_attachments']))
-		{
-			// First time? Gotta setup the base directory array.
-			if (empty($modSettings['attachment_basedirectories']))
+			if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
 			{
-				if (empty($modSettings['currentAttachmentUploadDir']))
-					$modSettings['attachmentUploadDir'] = array(1 => $modSettings['attachmentUploadDir']);
-				elseif (!is_array($modSettings['attachmentUploadDir']))
-					$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+				$currentAttachmentUploadDir = $modSettings['currentAttachmentUploadDir'];
 
-				$modSettings['currentAttachmentUploadDir'] = 1;
-				$modSettings['attachment_basedirectories'] = array(1 => $modSettings['attachmentUploadDir'][1]);
-				$modSettings['attachmentUploadDir'] = serialize($modSettings['attachmentUploadDir']);
-			}
+				if (!is_array($modSettings['attachmentUploadDir']))
+					$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
 
-			if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'], true))
-				// @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']))
+					$modSettings['currentAttachmentUploadDir'] = array_search($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir']);
 
-			if (isset($_POST['attachmentUploadDir']))
-				$_POST['attachmentUploadDir'] = serialize($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'];
+				}
 
-			// Add to the array of known base directories.
-			if (!is_array($modSettings['attachment_basedirectories']))
-				$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
-			if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
-			{
-				$modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['basedirectory_for_attachments'];
-				updateSettings(array(
-					'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
-				));
-				$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
+				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
+				{
+					$modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['basedirectory_for_attachments'];
+					updateSettings(array(
+						'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
+						'currentAttachmentUploadDir' => $currentAttachmentUploadDir,
+					));
+				}
 			}
 		}
 
@@ -1889,6 +1863,16 @@ function ManageAttachmentPaths()
 {
 	global $modSettings, $scripturl, $context, $txt, $sourcedir, $smcFunc;
 
+	// Since this needs to be done eventually.
+	if (!is_array($modSettings['attachmentUploadDir']))
+		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+	if (!isset($modSettings['attachment_basedirectories']))
+		$modSettings['attachment_basedirectories'] = array();
+	elseif (!is_array($modSettings['attachment_basedirectories']))
+		$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
+
+	$errors = array();
+
 	// Saving?
 	if (isset($_REQUEST['save']))
 	{
@@ -1901,6 +1885,15 @@ function ManageAttachmentPaths()
 			if ($id < 1)
 				continue;
 
+			// 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))
+						$path = $modSettings['attachmentUploadDir'][$id];
+				// @todo else{return some sorta error}
+			}
+
 			if (empty($path))
 			{
 				// Let's not try to delete a path with files in it.
@@ -1916,6 +1909,15 @@ function ManageAttachmentPaths()
 				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++;
+				}
+
 				// It's safe to delete.
 				if ($num_attach == 0)
 					continue;
@@ -1925,7 +1927,10 @@ 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'];
+
 		if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']]))
 			fatal_lang_error('attach_path_current_bad', false);
 
@@ -1953,24 +1958,65 @@ function ManageAttachmentPaths()
 			}
 		}
 		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(
 				'currentAttachmentUploadDir' => $_POST['current_dir'],
 				'attachmentUploadDir' => serialize($new_dirs),
 			));
+		}
+		redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']);
 	}
 
-	// Are they here for the first time?
-	if (empty($modSettings['currentAttachmentUploadDir']))
+	// Saving a base directory?
+	if (isset($_REQUEST['save2']))
 	{
-		$modSettings['attachmentUploadDir'] = array(
-			1 => $modSettings['attachmentUploadDir']
-		);
-		$modSettings['currentAttachmentUploadDir'] = 1;
+		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(
+					'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']],
+				));
+
+			$modSettings['attachmentUploadDir'] = serialize($modSettings['attachmentUploadDir']);
+		}
+
+		// Or adding a new one?
+		if (!empty($_POST['new_base_dir']))
+		{
+			require_once($sourcedir . '/Attachments.php');
+			$_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.
+
+			$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'];
+
+			updateSettings(array(
+				'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
+				'basedirectory_for_attachments' => $_POST['new_base_dir'],
+				'currentAttachmentUploadDir' => $current_dir,
+			));
+			$modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
+
+		}
+		redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']);
 	}
-	// Otherwise just load up their attachment paths.
-	else
-		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
 
 	$listOptions = array(
 		'id' => 'attach_paths',
@@ -1982,13 +2028,13 @@ function ManageAttachmentPaths()
 		'columns' => array(
 			'current_dir' => array(
 				'header' => array(
-					'value' => $txt['attach_current_dir'],
+					'value' => $txt['attach_current'],
 				),
 				'data' => array(
 					'function' => create_function('$rowData', '
-						return \'<input type="radio" name="current_dir" value="\' . $rowData[\'id\'] . \'" \' . ($rowData[\'current\'] ? \' checked="checked"\' : \'\') . ($rowData[\'automanage_attachments\'] ? \' disabled="disabled""\' : \'\') . \' class="input_radio" />\';
+						return \'<input type="radio" name="current_dir" value="\' . $rowData[\'id\'] . \'" \' . ($rowData[\'current\'] ? \' checked="checked"\' : \'\') . (!empty($rowData[\'automanage_attachments\']) ? \' disabled="disabled"\' : \'\') . \' class="input_radio" />\';
 					'),
-					'style' => 'text-align: center; width: 15%;',
+					'style' => 'text-align: center; width: 10%;',
 				),
 			),
 			'path' => array(
@@ -1997,9 +2043,9 @@ function ManageAttachmentPaths()
 				),
 				'data' => array(
 					'function' => create_function('$rowData', '
-						return \'<input type="text" size="40" name="dirs[\' . $rowData[\'id\'] . \']" value="\' . $rowData[\'path\'] . \'" 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[\'is_base_dir\']) ? \' disabled="disabled"\' : \'\') . \' class="input_text" style="width: 100%" />\';
 					'),
-					'style' => 'text-align: center; width: 30%;',
+					'style' => 'text-align: center; width: 40%;',
 				),
 			),
 			'current_size' => array(
@@ -2039,18 +2085,150 @@ 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(
+				'position' => 'top_of_list',
+				'value' => implode('<br />', $errors['folder']),
+				'style' => 'text-align: left;',
+				'class' => 'noticebox',
+			) : '',
 		),
 	);
-
 	require_once($sourcedir . '/Subs-List.php');
 	createList($listOptions);
 
+	if (!empty($modSettings['attachment_basedirectories']))
+	{
+		$listOptions2 = array(
+			'id' => 'base_paths',
+			'base_href' => $scripturl . '?action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id'],
+			'title' => $txt['attach_base_paths'],
+			'get_items' => array(
+				'function' => 'list_getBaseDirs',
+			),
+			'columns' => array(
+				'current_dir' => array(
+					'header' => array(
+						'value' => $txt['attach_current'],
+					),
+					'data' => array(
+						'function' => create_function('$rowData', '
+							return \'<input type="radio" name="current_base_dir" value="\' . $rowData[\'id\'] . \'" \' . ($rowData[\'current\'] ? \' checked="checked"\' : \'\') . \' class="input_radio" />\';
+						'),
+						'style' => 'text-align: center; width: 10%;',
+					),
+				),
+				'path' => array(
+					'header' => array(
+						'value' => $txt['attach_path'],
+					),
+					'data' => array(
+						'db' => 'path',
+						'style' => 'width: 45%;',
+					),
+				),
+				'num_dirs' => array(
+					'header' => array(
+						'value' => $txt['attach_num_dirs'],
+					),
+					'data' => array(
+						'db' => 'num_dirs',
+						'style' => 'text-align: center; width: 15%;',
+					),
+				),
+				'status' => array(
+					'header' => array(
+						'value' => $txt['attach_dir_status'],
+					),
+					'data' => array(
+						'db' => 'status',
+						'style' => 'text-align: center; width: 15%;',
+					),
+				),
+			),
+			'form' => array(
+				'href' => $scripturl . '?action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id'],
+			),
+			'additional_rows' => array(
+				array(
+					'position' => 'below_table_data',
+					'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(
+					'position' => 'top_of_list',
+					'value' => implode('<br />', $errors['base']),
+					'style' => 'text-align: left;',
+					'class' => 'noticebox',
+				) : '',
+			),
+		);
+		createList($listOptions2);
+	}
+
+
 	// Fix up our template.
-	$context[$context['admin_menu_name']]['current_subsection'] = 'attachments';
+	$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.
  */
@@ -2063,18 +2241,20 @@ function list_getAttachDirs()
 		$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
 
 	$request = $smcFunc['db_query']('', '
-		SELECT id_folder, COUNT(id_attach) AS num_attach
-		FROM {db_prefix}attachments' . (empty($modSettings['custom_avatar_enabled']) ? '' : '
-		WHERE attachment_type != {int:type_avatar}') . '
+		SELECT id_folder, COUNT(id_attach) AS num_attach, SUM(size) AS size_attach
+		FROM {db_prefix}attachments
 		GROUP BY id_folder',
 		array(
-			'type_avatar' => 1,
 		)
 	);
 
 	$expected_files = array();
+	$expected_size = array();
 	while ($row = $smcFunc['db_fetch_assoc']($request))
+	{
 		$expected_files[$row['id_folder']] = $row['num_attach'];
+		$expected_size[$row['id_folder']] = $row['size_attach'];
+	}
 	$smcFunc['db_free_result']($request);
 
 	$attachdirs = array();
@@ -2085,27 +2265,36 @@ function list_getAttachDirs()
 			$expected_files[$id] = 0;
 
 		// Check if the directory is doing okay.
-		list ($status, $error, $size) = attachDirStatus($dir, $expected_files[$id]);
+		list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]);
 
-		// If it is, let's show that it's a base directory.
+		// If it is one, let's show that it's a base directory.
+		$sub_dirs = 0;
+		$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']) ? true : false;
+			$is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']);
+
+			// Count any sub-folders.
+			foreach ($modSettings['attachmentUploadDir'] as $sid => $sub)
+				if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
+				{
+					$expected_files[$id]++;
+					$sub_dirs++;
+				}
 		}
-		else
-			$is_base_dir = false;
 
 		$attachdirs[] = array(
 			'id' => $id,
 			'current' => $id == $modSettings['currentAttachmentUploadDir'],
-			'automanage_attachments' => isset($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] > 0 ? true : false,
+			'automanage_attachments' => isset($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'],
+			'is_base_dir' => $is_base_dir,
 			'path' => $dir,
-			'current_size' => $size,
-			'num_files' => $expected_files[$id],
-			'status' => ($is_base_dir ? $txt['attach_dir_basedir'] . '/' : '') . ($error ? '<span class="error">' : '') . sprintf($txt['attach_dir_' . $status], $context['session_id'], $context['session_var']) . ($error ? '</span>' : ''),
+			'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>' : ''),
 		);
 	}
 
@@ -2133,11 +2322,13 @@ function list_getAttachDirs()
  */
 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, true);
+		automanage_attachments_create_directory($dir);
 	}
 
 	if (!is_dir($dir))
@@ -2155,21 +2346,18 @@ function attachDirStatus($dir, $expected_files)
 		if (in_array($file, array('.', '..', '.htaccess', 'index.php')))
 			continue;
 
-		$dir_size += filesize($dir . '/' . $file);
 		$num_files++;
 	}
 	$dir_handle->close();
 
-	$dir_size = round($dir_size / 1024, 2);
-
 	if ($num_files < $expected_files)
-		return array('files_missing', true, $dir_size);
+		return array('files_missing', true, $num_files);
 	// Empty?
 	elseif ($expected_files == 0)
-		return array('unused', false, $dir_size);
+		return array('unused', false, $num_files);
 	// All good!
 	else
-		return array('ok', false, $dir_size);
+		return array('ok', false, $num_files);
 }
 
 ?>

+ 18 - 37
Sources/ManageServer.php

@@ -1,7 +1,7 @@
 <?php
 
 /**
- * Contains all the functionality required to be able to edit the core server 
+ * Contains all the functionality required to be able to edit the core server
  * settings. This includes anything from which an error may result in the forum
  * destroying itself in a firey fury.
  *
@@ -104,7 +104,7 @@ function ModifySettings()
 	// By default we're editing the core settings
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'general';
 	$context['sub_action'] = $_REQUEST['sa'];
-	
+
 	// Any messages to speak of?
 	$context['settings_message'] = (isset($_REQUEST['msg']) && isset($txt[$_REQUEST['msg']])) ? $txt[$_REQUEST['msg']] : '';
 
@@ -323,7 +323,7 @@ function ModifyCookieSettings($return_config = false)
 function ModifyCacheSettings($return_config = false)
 {
 	global $context, $scripturl, $txt, $helptxt, $cache_enable;
-	
+
 	// Detect all available optimizers
 	$detected = array();
 	if (function_exists('eaccelerator_put'))
@@ -338,13 +338,13 @@ function ModifyCacheSettings($return_config = false)
 		$detected['memcached'] = $txt['memcached_cache'];
 	if (function_exists('xcache_set'))
 		$detected['xcache'] = $txt['xcache_cache'];
-		
+
 	// set a message to show what, if anything, we found
 	if (empty($detected))
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
 	else
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
-	
+
 	// This is always an option
 	$detected['smf'] = $txt['default_cache'];
 
@@ -357,32 +357,13 @@ function ModifyCacheSettings($return_config = false)
 		array('cache_memcached', $txt['cache_memcached'], 'file', 'text', $txt['cache_memcached'], 'cache_memcached'),
 		array('cachedir', $txt['cachedir'], 'file', 'text', 36, 'cache_cachedir'),
 	);
-	
+
 	// some javascript to enable / disable certain settings if the option is not selected
 	$context['settings_post_javascript'] = '
 		var cache_type = document.getElementById(\'cache_accelerator\');
-		mod_addEvent(cache_type, \'change\', toggleCache);
-		toggleCache();
-
-		function mod_addEvent(control, ev, fn)
-		{
-			if (control.addEventListener)
-			{
-				control.addEventListener(ev, fn, false); 
-			} 
-			else if (control.attachEvent)
-			{
-				control.attachEvent(\'on\'+ev, fn);
-			}
-		}
-		function toggleCache()
-		{
-			var select_elem1 = document.getElementById(\'cache_memcached\');
-			var select_elem2 = document.getElementById(\'cachedir\');
-			select_elem1.disabled = cache_type.value != "memcached";
-			select_elem2.disabled = cache_type.value != "smf";
-		}
-	';
+		createEventListener(cache_type);
+		cache_type.addEventListener("change", toggleCache);
+		toggleCache();';
 
 	call_integration_hook('integrate_modify_cache_settings', array(&$config_vars));
 
@@ -395,14 +376,14 @@ function ModifyCacheSettings($return_config = false)
 		call_integration_hook('integrate_save_cache_settings');
 
 		saveSettings($config_vars);
-		
+
 		// we need to save the $cache_enable to $modSettings as well
 		updatesettings(array('cache_enable' => (int) $_POST['cache_enable']));
 
 		// exit so we reload our new settings on the page
 		redirectexit('action=admin;area=serversettings;sa=cache;' . $context['session_var'] . '=' . $context['session_id']);
 	}
-	
+
 	// if its off, allow them to clear it as well
 	// @todo why only when its off ?
 	if (empty($cache_enable))
@@ -507,7 +488,7 @@ function ModifyLoadBalancingSettings($return_config = false)
 		saveDBSettings($config_vars);
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
 	}
-	
+
 	createToken('admin-ssc');
 	createToken('admin-dbsc');
 	prepareDBSettingContext($config_vars);
@@ -570,7 +551,7 @@ function prepareServerSettingsContext(&$config_vars)
 				'preinput' => !empty($config_var['preinput']) ? $config_var['preinput'] : '',
 				'postinput' => !empty($config_var['postinput']) ? $config_var['postinput'] : '',
 			);
-			
+
 			// If this is a select box handle any data.
 			if (!empty($config_var[4]) && is_array($config_var[4]))
 			{
@@ -794,15 +775,15 @@ function saveSettings(&$config_vars)
 		'cookiename',
 		'webmaster_email',
 		'db_name', 'db_user', 'db_server', 'db_prefix', 'ssi_db_user',
-		'boarddir', 'sourcedir', 
+		'boarddir', 'sourcedir',
 		'cachedir', 'cache_accelerator', 'cache_memcached',
 	);
-	
+
 	// All the numeric variables.
 	$config_ints = array(
 		'cache_enable',
 	);
-	
+
 	// All the checkboxes.
 	$config_bools = array(
 		'db_persist', 'db_error_send',
@@ -944,7 +925,7 @@ function saveDBSettings(&$config_vars)
 function ShowPHPinfoSettings()
 {
 	global $context, $txt;
-	
+
 	$info_lines = array();
 	$category = $txt['phpinfo_settings'];
 
@@ -956,7 +937,7 @@ function ShowPHPinfoSettings()
 	$info_lines = preg_replace('~^.*<body>(.*)</body>.*$~', '$1', ob_get_contents());
 	$info_lines = explode("\n", strip_tags($info_lines, "<tr><td><h2>"));
 	ob_end_clean();
-	
+
 	// remove things that could be considered sensative
 	$remove = '_COOKIE|Cookie|_GET|_REQUEST|REQUEST_URI|QUERY_STRING|REQUEST_URL|HTTP_REFERER';
 

+ 4 - 4
Sources/ManageSettings.php

@@ -492,7 +492,7 @@ function ModifyBasicSettings($return_config = false)
 		'',
 			// Option-ish things... miscellaneous sorta.
 			array('check', 'allow_disableAnnounce'),
-			array('check', 'disallow_sendBody'),	
+			array('check', 'disallow_sendBody'),
 	);
 
 	// Get all the time zones.
@@ -612,8 +612,8 @@ function ModifyLayoutSettings($return_config = false)
 			array('check', 'enableVBStyleLogin'),
 		'',
 			// Automagic image resizing.
-			array('int', 'max_image_width'),
-			array('int', 'max_image_height'),
+			array('int', 'max_image_width', 'subtext' => $txt['zero_for_no_limit']),
+			array('int', 'max_image_height', 'subtext' => $txt['zero_for_no_limit']),
 		'',
 			// This is like debugging sorta.
 			array('check', 'timeLoadPageEnable'),
@@ -1737,7 +1737,7 @@ function EditCustomProfiles()
 		// Regex you say?  Do a very basic test to see if the pattern is valid
 		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
 			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
-			
+
 		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
 		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
 

+ 8 - 0
Themes/default/ManageAttachments.template.php

@@ -216,6 +216,14 @@ function template_attachment_repair()
 
 function template_attachment_paths()
 {
+	global $modSettings;
+
+	if (!empty($modSettings['attachment_basedirectories']))
+	{
+		template_show_list('base_paths');
+		echo '<br />';
+	}
+
 	template_show_list('attach_paths');
 }
 

+ 19 - 12
Themes/default/languages/Admin.english.php

@@ -351,9 +351,8 @@ $txt['attachmentCheckExtensions'] = 'Check attachment\'s extension';
 $txt['attachmentExtensions'] = 'Allowed attachment extensions';
 $txt['attachmentRecodeLineEndings'] = 'Recode line endings in textual attachments';
 $txt['attachmentShowImages'] = 'Display image attachments as pictures under post';
-$txt['attachmentUploadDir'] = 'Current attachments directory';
-$txt['attachmentUploadDir_multiple'] = 'Current attachments directory';
-$txt['attachmentUploadDir_multiple_configure'] = 'Configure multiple attachment directories';
+$txt['attachmentUploadDir'] = 'Attachments directory';
+$txt['attachmentUploadDir_multiple_configure'] = 'Manage attachment directories';
 $txt['attachmentDirSizeLimit'] = 'Max attachment folder space';
 $txt['attachmentPostLimit'] = 'Max attachment size per post';
 $txt['attachmentSizeLimit'] = 'Max size per attachment';
@@ -382,17 +381,26 @@ $txt['attach_dir_unused'] = 'Unused';
 $txt['attach_dir_ok'] = 'OK';
 $txt['attach_dir_basedir'] = 'Base directory';
 
+$txt['attach_last_dir'] = 'Last active attachment directory';
+$txt['attach_current_dir'] = 'Current attachment directory';
+$txt['attach_current'] = 'Current';
 $txt['attach_path_manage'] = 'Manage Attachment Paths';
-$txt['attach_paths'] = 'Attachment Paths';
-$txt['attach_current_dir'] = 'Current Directory';
+$txt['attach_directories'] = 'Attachment Directories';
+$txt['attach_paths'] = 'Attachment Directory Paths';
+$txt['attach_base_paths'] = 'Base Directory Paths';
 $txt['attach_path'] = 'Path';
-$txt['attach_current_size'] = 'Current Size (KB)';
+$txt['attach_current_size'] = 'Size (KB)';
 $txt['attach_num_files'] = 'Files';
 $txt['attach_dir_status'] = 'Status';
 $txt['attach_add_path'] = 'Add Path';
 $txt['attach_path_current_bad'] = 'Invalid current attachment path.';
 $txt['attachmentDirFileLimit'] = 'Maximum number of files per directory';
 
+$txt['attach_base_paths'] = 'Base Directory Paths';
+$txt['attach_num_dirs'] = 'Directories';
+$txt['max_image_width'] = 'Max display width of posted or attached images';
+$txt['max_image_height'] = 'Max display height of posted or attached images';
+
 $txt['automanage_attachments'] = 'Choose the method for the management of the attachment directories';
 $txt['attachments_normal'] = '(Manual) SMF default behaviour';
 $txt['attachments_auto_years'] = '(Auto) Subdivide by years';
@@ -401,14 +409,13 @@ $txt['attachments_auto_days'] = '(Auto) Subdivide by years, months and days';
 $txt['attachments_auto_16'] = '(Auto) 16 random folders';
 $txt['attachments_auto_16x16'] = '(Auto) 16 random folders with 16 random sub-folders';
 $txt['attachments_auto_space'] = '(Auto) When either directory space limit is reached';
-//$txt['attachments_auto_files'] = 'Change directory when file limit is reached';
 
-$txt['use_subdirectories_for_attachments'] = 'Create new directories within this directory';
+$txt['use_subdirectories_for_attachments'] = 'Create new directories within a base directory';
 $txt['use_subdirectories_for_attachments_note'] = 'Otherwise any new directories will be created within the forum\'s main directory.';
-//$txt['use_subdirectories_for_attachments_note'] = '<span class="smalltext">Otherwise any new directories will be created within the forum\'s main directory</span>';
-
-$txt['basedirectory_for_attachments'] = 'Base directory for attachments';
+$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['mods_cat_avatars'] = 'Avatars';
 $txt['avatar_directory'] = 'Avatars directory';
@@ -461,7 +468,7 @@ $txt['attach_repair_file_size_of_zero'] = '%1$d attachments/avatars have a size
 $txt['attach_repair_attachment_no_msg'] = '%1$d attachments no longer have a message associated with them';
 $txt['attach_repair_avatar_no_member'] = '%1$d avatars no longer have a member associated with them';
 $txt['attach_repair_wrong_folder'] = '%1$d attachments are in the wrong folder';
-$txt['attach_repair_files_without_attachment'] = '%1$d files doesn\'t have a corresponding entri into the database. (These will be deleted)';
+$txt['attach_repair_files_without_attachment'] = '%1$d files do not have a corresponding entry in the database. (These will be deleted)';
 
 $txt['news_title'] = 'News and Newsletters';
 $txt['news_settings_desc'] = 'Here you can change the settings and permissions related to news and newsletters.';

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

@@ -282,7 +282,7 @@ $helptxt['databaseSession_loose'] = 'Turning this on will decrease the bandwidth
 $helptxt['databaseSession_lifetime'] = 'This is the number of seconds for sessions to last after they haven\'t been accessed.  If a session is not accessed for too long, it is said to have &quot;timed out&quot;.  Anything higher than 2400 is recommended.';
 $helptxt['cache_enable'] = 'SMF performs caching at a variety of levels. The higher the level of caching enabled the more CPU time will be spent retrieving cached information. If caching is available on your machine it is recommended that you try caching at level 1 first.';
 $helptxt['cache_memcached'] = 'If you are using memcached you need to provide the server details. This should be entered as a comma separated list as shown in the example below:<br /><br/>	&quot;server1,server2,server3:port,server4&quot;<br /><br />Note that if no port is specified SMF will use port 11211. SMF will attempt to perform rough/random load balancing across the specified servers.';
-$helptxt['cache_cachedir'] = 'This setting This is only for the smf file based cache system. It specifies the path to the cache directory.  It is recommended that you place this in /tmp/ if you are going to use this, although it will work in any directory';  
+$helptxt['cache_cachedir'] = 'This setting This is only for the smf file based cache system. It specifies the path to the cache directory.  It is recommended that you place this in /tmp/ if you are going to use this, although it will work in any directory';
 $helptxt['enableErrorLogging'] = 'This will log any errors, like a failed login, so you can see what went wrong.';
 $helptxt['enableErrorQueryLogging'] = 'This will include the full query sent to the database in the error log.  Requires error logging to be turned on.<br /><br /><strong>Note:  This will affect the ability to filter the error log by the error message.</strong>';
 $helptxt['allow_disableAnnounce'] = 'This will allow users to opt out of notification of topics you announce by checking the &quot;announce topic&quot; checkbox when posting.';
@@ -295,7 +295,7 @@ $helptxt['timeLoadPageEnable'] = 'This will show the time in seconds SMF took to
 $helptxt['removeNestedQuotes'] = 'This will strip nested quotes from a post when citing the post in question via a quote link.';
 $helptxt['simpleSearch'] = 'This will show a simple search form and a link to a more advanced form.';
 $helptxt['search_dropdown'] = 'This will show a search selection dropdown next to the quick search box.  From this you can choose to search the current site, current board (if in a board_, current topic (if in a topic) or search for members.';
-$helptxt['max_image_width'] = 'This allows you to set a maximum size for posted pictures. Pictures smaller than the maximum will not be affected.';
+$helptxt['max_image_width'] = 'This allows you to set a maximum size for posted pictures. Pictures smaller than the maximum will not be affected. This also determines how attached images are displayed when a thumbnail is clicked on.';
 $helptxt['mail_type'] = 'This setting allows you to choose either PHP\'s default settings, or to override those settings with SMTP.  PHP doesn\'t support using authentication with SMTP (which many hosts require, now) so if you want that you should select SMTP.  Please note that SMTP can be slower, and some servers will not take usernames and passwords.<br /><br />You don\'t need to fill in the SMTP settings if this is set to PHP\'s default.';
 $helptxt['attachment_manager_settings'] = 'Attachments are files that members can upload, and attach to a post.<br /><br />
 		<strong>Check attachment extension</strong>:<br /> Do you want to check the extension of the files?<br />

+ 0 - 2
Themes/default/languages/ManageSettings.english.php

@@ -72,8 +72,6 @@ $txt['jquery_cdn'] = 'Google CDN';
 $txt['jquery_auto'] = 'Auto';
 $txt['queryless_urls'] = 'Search engine friendly URLs';
 $txt['queryless_urls_note'] = 'Apache/Lighttpd only!';
-$txt['max_image_width'] = 'Max width of posted pictures (0 = disable)';
-$txt['max_image_height'] = 'Max height of posted pictures (0 = disable)';
 $txt['enableReportPM'] = 'Enable reporting of personal messages';
 $txt['max_pm_recipients'] = 'Maximum number of recipients allowed in a personal message';
 $txt['max_pm_recipients_note'] = '(0 for no limit, admins are exempt)';

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

@@ -607,4 +607,59 @@ function select_in_category(cat_id, elem, brd_list)
 		document.getElementById(elem.value + '_brd' + brd_list[brd]).checked = true;
 
 	elem.selectedIndex = 0;
+}
+
+/*
+* Server Settings > Caching
+*/
+function toggleCache ()
+{
+	var memcache = document.getElementById('cache_memcached');
+	var cachedir = document.getElementById('cachedir');
+	memcache.disabled = cache_type.value != "memcached";
+	cachedir.disabled = cache_type.value != "smf";
+}
+
+/*
+* Attachments Settings
+*/
+function toggleSubDir ()
+{
+	var auto_attach = document.getElementById('automanage_attachments');
+	var use_sub_dir = document.getElementById('use_subdirectories_for_attachments');
+	var dir_elem = document.getElementById('basedirectory_for_attachments');
+
+	use_sub_dir.disabled = !Boolean(auto_attach.selectedIndex);
+	if (use_sub_dir.disabled)
+	{
+		use_sub_dir.style.display = "none";
+		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
+	{
+		use_sub_dir.style.display = "";
+		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();
+}
+function toggleBaseDir ()
+{
+	var auto_attach = document.getElementById('automanage_attachments');
+	var sub_dir = document.getElementById('use_subdirectories_for_attachments');
+	var dir_elem = document.getElementById('basedirectory_for_attachments');
+
+	if (auto_attach.selectedIndex == 0)
+	{
+		dir_elem.disabled = 1;
+	}
+	else
+		dir_elem.disabled = !sub_dir.checked;
 }