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