|
@@ -86,14 +86,40 @@ function ManageAttachments()
|
|
|
|
|
|
function ManageAttachmentSettings($return_config = false)
|
|
function ManageAttachmentSettings($return_config = false)
|
|
{
|
|
{
|
|
- global $txt, $modSettings, $scripturl, $context, $options, $sourcedir;
|
|
|
|
|
|
+ global $txt, $modSettings, $scripturl, $context, $options, $sourcedir, $boarddir;
|
|
|
|
|
|
- $context['valid_upload_dir'] = is_dir($modSettings['attachmentUploadDir']) && is_writable($modSettings['attachmentUploadDir']);
|
|
|
|
|
|
+ require_once($sourcedir . '/Attachments.php');
|
|
|
|
+
|
|
|
|
+ // Get the current attachment directory.
|
|
|
|
+ $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']))
|
|
|
|
+ if (!empty($modSettings['currentAttachmentUploadDir']))
|
|
|
|
+ $modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1];
|
|
|
|
+ else
|
|
|
|
+ $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir'];
|
|
|
|
+
|
|
|
|
+ $context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']);
|
|
|
|
+
|
|
|
|
+ if (!empty($modSettings['automanage_attachments']))
|
|
|
|
+ $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']);
|
|
|
|
+ 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['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'];
|
|
|
|
+ $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.
|
|
// Perform a test to see if the GD module or ImageMagick are installed.
|
|
$testImg = get_extension_funcs('gd') || class_exists('Imagick');
|
|
$testImg = get_extension_funcs('gd') || class_exists('Imagick');
|
|
- $txt['attachmentUploadDir_multiple_configure'] = '<a href="' . $scripturl . '?action=admin;area=manageattachments;sa=attachpaths">[' . $txt['attachmentUploadDir_multiple_configure'] . ']</a>';
|
|
|
|
-
|
|
|
|
|
|
+
|
|
// See if we can find if the server is set up to support the attacment limits
|
|
// See if we can find if the server is set up to support the attacment limits
|
|
$post_max_size = ini_get('post_max_size');
|
|
$post_max_size = ini_get('post_max_size');
|
|
$upload_max_filesize = ini_get('upload_max_filesize');
|
|
$upload_max_filesize = ini_get('upload_max_filesize');
|
|
@@ -109,8 +135,14 @@ function ManageAttachmentSettings($return_config = false)
|
|
array('check', 'attachmentRecodeLineEndings'),
|
|
array('check', 'attachmentRecodeLineEndings'),
|
|
'',
|
|
'',
|
|
// Directory and size limits.
|
|
// Directory and size limits.
|
|
- empty($modSettings['currentAttachmentUploadDir']) ? array('text', 'attachmentUploadDir', 'subtext' => $txt['attachmentUploadDir_multiple_configure'], 40, 'invalid' => !$context['valid_upload_dir']) : array('var_message', 'attachmentUploadDir_multiple', 'message' => 'attachmentUploadDir_multiple_configure'),
|
|
|
|
|
|
+ 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'])),
|
|
|
|
+ array('int', 'attachmentDirFileLimit', 'subtext' => $txt['zero_for_no_limit'], 6),
|
|
array('int', 'attachmentDirSizeLimit', 'subtext' => $txt['zero_for_no_limit'], 6, 'postinput' => $txt['kilobyte']),
|
|
array('int', 'attachmentDirSizeLimit', 'subtext' => $txt['zero_for_no_limit'], 6, 'postinput' => $txt['kilobyte']),
|
|
|
|
+ '',
|
|
|
|
+ // Posting limits
|
|
array('int', 'attachmentPostLimit', 'subtext' => $txt['zero_for_no_limit'], 6, 'postinput' => $txt['kilobyte']),
|
|
array('int', 'attachmentPostLimit', 'subtext' => $txt['zero_for_no_limit'], 6, 'postinput' => $txt['kilobyte']),
|
|
array('warning', empty($testPM) ? 'attachment_postsize_warning' : ''),
|
|
array('warning', empty($testPM) ? 'attachment_postsize_warning' : ''),
|
|
array('int', 'attachmentSizeLimit', 'subtext' => $txt['zero_for_no_limit'], 6, 'postinput' => $txt['kilobyte']),
|
|
array('int', 'attachmentSizeLimit', 'subtext' => $txt['zero_for_no_limit'], 6, 'postinput' => $txt['kilobyte']),
|
|
@@ -137,8 +169,21 @@ function ManageAttachmentSettings($return_config = false)
|
|
array('warning', 'attachment_thumb_memory_note'),
|
|
array('warning', 'attachment_thumb_memory_note'),
|
|
array('text', 'attachmentThumbWidth', 6),
|
|
array('text', 'attachmentThumbWidth', 6),
|
|
array('text', 'attachmentThumbHeight', 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\');
|
|
|
|
+
|
|
|
|
+ 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));
|
|
call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars));
|
|
|
|
|
|
if ($return_config)
|
|
if ($return_config)
|
|
@@ -153,6 +198,38 @@ function ManageAttachmentSettings($return_config = false)
|
|
{
|
|
{
|
|
checkSession();
|
|
checkSession();
|
|
|
|
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ 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();
|
|
|
|
+
|
|
|
|
+ if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
|
|
|
|
+ {
|
|
|
|
+ $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']))
|
|
|
|
+ {
|
|
|
|
+ $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['basedirectory_for_attachments'];
|
|
|
|
+ updateSettings(array(
|
|
|
|
+ 'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
|
|
|
|
+ 'currentAttachmentUploadDir' => $currentAttachmentUploadDir,
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
call_integration_hook('integrate_save_attachment_settings');
|
|
call_integration_hook('integrate_save_attachment_settings');
|
|
|
|
|
|
saveDBSettings($config_vars);
|
|
saveDBSettings($config_vars);
|
|
@@ -1458,18 +1535,10 @@ function RepairAttachments()
|
|
// What about files who are not recorded in the database?
|
|
// What about files who are not recorded in the database?
|
|
if ($_GET['step'] <= 5)
|
|
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;
|
|
$current_check = 0;
|
|
$max_checks = 500;
|
|
$max_checks = 500;
|
|
@@ -1770,13 +1839,24 @@ function ApproveAttachments($attachments)
|
|
*/
|
|
*/
|
|
function ManageAttachmentPaths()
|
|
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']))
|
|
|
|
+ $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?
|
|
// Saving?
|
|
if (isset($_REQUEST['save']))
|
|
if (isset($_REQUEST['save']))
|
|
{
|
|
{
|
|
checkSession();
|
|
checkSession();
|
|
|
|
|
|
|
|
+ $_POST['current_dir'] = (int) $_POST['current_dir'];
|
|
$new_dirs = array();
|
|
$new_dirs = array();
|
|
foreach ($_POST['dirs'] as $id => $path)
|
|
foreach ($_POST['dirs'] as $id => $path)
|
|
{
|
|
{
|
|
@@ -1784,33 +1864,132 @@ function ManageAttachmentPaths()
|
|
if ($id < 1)
|
|
if ($id < 1)
|
|
continue;
|
|
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))
|
|
|
|
+ {
|
|
|
|
+ $errors[] = $path . ': ' . $txt['attach_dir_no_rename'];
|
|
|
|
+ $path = $modSettings['attachmentUploadDir'][$id];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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))
|
|
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);
|
|
|
|
|
|
- // It's safe to delete.
|
|
|
|
- if ($num_attach == 0)
|
|
|
|
- continue;
|
|
|
|
|
|
+ // 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'])));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (empty($errors))
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
$new_dirs[$id] = $path;
|
|
$new_dirs[$id] = $path;
|
|
}
|
|
}
|
|
|
|
|
|
// We need to make sure the current directory is right.
|
|
// We need to make sure the current directory is right.
|
|
- $_POST['current_dir'] = (int) $_POST['current_dir'];
|
|
|
|
|
|
+ if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir']))
|
|
|
|
+ $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
|
|
|
|
+
|
|
|
|
+ // Find the current directory if there's no value carried,
|
|
if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']]))
|
|
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?
|
|
// Going back to just one path?
|
|
if (count($new_dirs) == 1)
|
|
if (count($new_dirs) == 1)
|
|
@@ -1829,31 +2008,88 @@ function ManageAttachmentPaths()
|
|
)
|
|
)
|
|
);
|
|
);
|
|
|
|
|
|
- updateSettings(array(
|
|
|
|
- 'currentAttachmentUploadDir' => 0,
|
|
|
|
- 'attachmentUploadDir' => $dir,
|
|
|
|
- ));
|
|
|
|
|
|
+ $update = array(
|
|
|
|
+ 'currentAttachmentUploadDir' => 1,
|
|
|
|
+ 'attachmentUploadDir' => serialize(array(1 => $dir)),
|
|
|
|
+ );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
|
|
+ {
|
|
// Save it to the database.
|
|
// Save it to the database.
|
|
- updateSettings(array(
|
|
|
|
|
|
+ $update = array(
|
|
'currentAttachmentUploadDir' => $_POST['current_dir'],
|
|
'currentAttachmentUploadDir' => $_POST['current_dir'],
|
|
'attachmentUploadDir' => serialize($new_dirs),
|
|
'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']);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Saving a base directory?
|
|
|
|
+ if (isset($_REQUEST['save2']))
|
|
|
|
+ {
|
|
|
|
+ checkSession();
|
|
|
|
+
|
|
|
|
+ // 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']])
|
|
|
|
+ $update = (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']))
|
|
|
|
+ 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']);
|
|
|
|
+
|
|
|
|
+ $update = (array(
|
|
|
|
+ 'attachment_basedirectories' => serialize($modSettings['attachment_basedirectories']),
|
|
|
|
+ 'basedirectory_for_attachments' => $_POST['new_base_dir'],
|
|
|
|
+ 'currentAttachmentUploadDir' => $current_dir,
|
|
));
|
|
));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!empty($errors))
|
|
|
|
+ $_SESSION['base'] = $errors;
|
|
|
|
+
|
|
|
|
+ if (!empty($update))
|
|
|
|
+ updateSettings($update);
|
|
|
|
+
|
|
|
|
+ redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']);
|
|
}
|
|
}
|
|
|
|
|
|
- // Are they here for the first time?
|
|
|
|
- if (empty($modSettings['currentAttachmentUploadDir']))
|
|
|
|
|
|
+ if (isset($_SESSION['errors']))
|
|
{
|
|
{
|
|
- $modSettings['attachmentUploadDir'] = array(
|
|
|
|
- 1 => $modSettings['attachmentUploadDir']
|
|
|
|
- );
|
|
|
|
- $modSettings['currentAttachmentUploadDir'] = 1;
|
|
|
|
|
|
+ $errors = $_SESSION['errors'];
|
|
|
|
+ unset($_SESSION['errors']);
|
|
}
|
|
}
|
|
- // Otherwise just load up their attachment paths.
|
|
|
|
- else
|
|
|
|
- $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
|
|
|
|
|
|
|
|
$listOptions = array(
|
|
$listOptions = array(
|
|
'id' => 'attach_paths',
|
|
'id' => 'attach_paths',
|
|
@@ -1865,13 +2101,13 @@ function ManageAttachmentPaths()
|
|
'columns' => array(
|
|
'columns' => array(
|
|
'current_dir' => array(
|
|
'current_dir' => array(
|
|
'header' => array(
|
|
'header' => array(
|
|
- 'value' => $txt['attach_current_dir'],
|
|
|
|
|
|
+ 'value' => $txt['attach_current'],
|
|
),
|
|
),
|
|
'data' => array(
|
|
'data' => array(
|
|
'function' => create_function('$rowData', '
|
|
'function' => create_function('$rowData', '
|
|
- return \'<input type="radio" name="current_dir" value="\' . $rowData[\'id\'] . \'" \' . ($rowData[\'current\'] ? \'checked="checked"\' : \'\') . \' 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: 15%;',
|
|
|
|
|
|
+ 'style' => 'text-align: center; width: 10%;',
|
|
),
|
|
),
|
|
),
|
|
),
|
|
'path' => array(
|
|
'path' => array(
|
|
@@ -1880,9 +2116,9 @@ function ManageAttachmentPaths()
|
|
),
|
|
),
|
|
'data' => array(
|
|
'data' => array(
|
|
'function' => create_function('$rowData', '
|
|
'function' => create_function('$rowData', '
|
|
- return \'<input type="text" size="30" 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[\'disable_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(
|
|
'current_size' => array(
|
|
@@ -1922,14 +2158,98 @@ 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" />',
|
|
'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;',
|
|
'style' => 'text-align: right;',
|
|
),
|
|
),
|
|
|
|
+ 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' => $txt['attach_dir_save_problem'] . '<br />' . implode('<br />', $errors['dir']),
|
|
|
|
+ 'style' => 'text-align: left;',
|
|
|
|
+ 'class' => 'noticebox',
|
|
|
|
+ ),
|
|
),
|
|
),
|
|
);
|
|
);
|
|
-
|
|
|
|
require_once($sourcedir . '/Subs-List.php');
|
|
require_once($sourcedir . '/Subs-List.php');
|
|
createList($listOptions);
|
|
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" /> <input type="submit" name="save2" value="' . $txt['save'] . '" class="button_submit" />',
|
|
|
|
+ 'style' => 'text-align: right;',
|
|
|
|
+ ),
|
|
|
|
+ empty($errors['base']) ? array(
|
|
|
|
+ 'position' => 'top_of_list',
|
|
|
|
+ '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.
|
|
// 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['page_title'] = $txt['attach_path_manage'];
|
|
$context['sub_template'] = 'attachment_paths';
|
|
$context['sub_template'] = 'attachment_paths';
|
|
}
|
|
}
|
|
@@ -1941,23 +2261,27 @@ function list_getAttachDirs()
|
|
{
|
|
{
|
|
global $smcFunc, $modSettings, $context, $txt;
|
|
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']('', '
|
|
$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',
|
|
GROUP BY id_folder',
|
|
array(
|
|
array(
|
|
- 'type_avatar' => 1,
|
|
|
|
)
|
|
)
|
|
);
|
|
);
|
|
|
|
|
|
$expected_files = array();
|
|
$expected_files = array();
|
|
|
|
+ $expected_size = array();
|
|
while ($row = $smcFunc['db_fetch_assoc']($request))
|
|
while ($row = $smcFunc['db_fetch_assoc']($request))
|
|
|
|
+ {
|
|
$expected_files[$row['id_folder']] = $row['num_attach'];
|
|
$expected_files[$row['id_folder']] = $row['num_attach'];
|
|
|
|
+ $expected_size[$row['id_folder']] = $row['size_attach'];
|
|
|
|
+ }
|
|
$smcFunc['db_free_result']($request);
|
|
$smcFunc['db_free_result']($request);
|
|
|
|
|
|
$attachdirs = array();
|
|
$attachdirs = array();
|
|
@@ -1968,15 +2292,33 @@ function list_getAttachDirs()
|
|
$expected_files[$id] = 0;
|
|
$expected_files[$id] = 0;
|
|
|
|
|
|
// Check if the directory is doing okay.
|
|
// 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 one, let's show that it's a base directory.
|
|
|
|
+ $sub_dirs = 0;
|
|
|
|
+ $is_base_dir = false;
|
|
|
|
+ if (!empty($modSettings['attachment_basedirectories']))
|
|
|
|
+ {
|
|
|
|
+ $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++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
$attachdirs[] = array(
|
|
$attachdirs[] = array(
|
|
'id' => $id,
|
|
'id' => $id,
|
|
'current' => $id == $modSettings['currentAttachmentUploadDir'],
|
|
'current' => $id == $modSettings['currentAttachmentUploadDir'],
|
|
|
|
+ '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,
|
|
'path' => $dir,
|
|
- 'current_size' => $size,
|
|
|
|
- 'num_files' => $expected_files[$id],
|
|
|
|
- 'status' => ($error ? '<span class="error">' : '') . sprintf($txt['attach_dir_' . $status], $context['session_id'], $context['session_var']) . ($error ? '</span>' : ''),
|
|
|
|
|
|
+ '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>' : ''),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1994,23 +2336,72 @@ function list_getAttachDirs()
|
|
return $attachdirs;
|
|
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
|
|
* Checks the status of an attachment directory and returns an array
|
|
* of the status key, if that status key signifies an error, and
|
|
* of the status key, if that status key signifies an error, and
|
|
- * the folder size.
|
|
|
|
|
|
+ * the file count.
|
|
*
|
|
*
|
|
* @param string $dir
|
|
* @param string $dir
|
|
* @param int $expected_files
|
|
* @param int $expected_files
|
|
*/
|
|
*/
|
|
function attachDirStatus($dir, $expected_files)
|
|
function attachDirStatus($dir, $expected_files)
|
|
{
|
|
{
|
|
|
|
+ global $sourcedir, $context;
|
|
|
|
+
|
|
if (!is_dir($dir))
|
|
if (!is_dir($dir))
|
|
return array('does_not_exist', true, '');
|
|
return array('does_not_exist', true, '');
|
|
elseif (!is_writable($dir))
|
|
elseif (!is_writable($dir))
|
|
return array('not_writable', true, '');
|
|
return array('not_writable', true, '');
|
|
|
|
|
|
// Everything is okay so far, start to scan through the directory.
|
|
// Everything is okay so far, start to scan through the directory.
|
|
- $dir_size = 0;
|
|
|
|
$num_files = 0;
|
|
$num_files = 0;
|
|
$dir_handle = dir($dir);
|
|
$dir_handle = dir($dir);
|
|
while ($file = $dir_handle->read())
|
|
while ($file = $dir_handle->read())
|
|
@@ -2019,21 +2410,18 @@ function attachDirStatus($dir, $expected_files)
|
|
if (in_array($file, array('.', '..', '.htaccess', 'index.php')))
|
|
if (in_array($file, array('.', '..', '.htaccess', 'index.php')))
|
|
continue;
|
|
continue;
|
|
|
|
|
|
- $dir_size += filesize($dir . '/' . $file);
|
|
|
|
$num_files++;
|
|
$num_files++;
|
|
}
|
|
}
|
|
$dir_handle->close();
|
|
$dir_handle->close();
|
|
|
|
|
|
- $dir_size = round($dir_size / 1024, 2);
|
|
|
|
-
|
|
|
|
if ($num_files < $expected_files)
|
|
if ($num_files < $expected_files)
|
|
- return array('files_missing', true, $dir_size);
|
|
|
|
|
|
+ return array('files_missing', true, $num_files);
|
|
// Empty?
|
|
// Empty?
|
|
elseif ($expected_files == 0)
|
|
elseif ($expected_files == 0)
|
|
- return array('unused', false, $dir_size);
|
|
|
|
|
|
+ return array('unused', false, $num_files);
|
|
// All good!
|
|
// All good!
|
|
else
|
|
else
|
|
- return array('ok', false, $dir_size);
|
|
|
|
|
|
+ return array('ok', false, $num_files);
|
|
}
|
|
}
|
|
|
|
|
|
?>
|
|
?>
|