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']);
    }
    $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}') . '
		GROUP BY id_folder', array('type_avatar' => 1));
    $expected_files = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $expected_files[$row['id_folder']] = $row['num_attach'];
    }
    $smcFunc['db_free_result']($request);
    $attachdirs = array();
    foreach ($modSettings['attachmentUploadDir'] as $id => $dir) {
        // If there aren't any attachments in this directory this won't exist.
        if (!isset($expected_files[$id])) {
            $expected_files[$id] = 0;
        }
        // Check if the directory is doing okay.
        list($status, $error, $size) = attachDirStatus($dir, $expected_files[$id]);
        $attachdirs[] = array('id' => $id, 'current' => $id == $modSettings['currentAttachmentUploadDir'], '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>' : ''));
    }
    // Just stick a new directory on at the bottom.
    if (isset($_REQUEST['new_path'])) {
        $attachdirs[] = array('id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1, 'current' => false, 'path' => '', 'current_size' => '', 'num_files' => '', 'status' => '');
    }
    return $attachdirs;
}
Esempio n. 2
0
/**
 * Prepare the actual attachment directories to be displayed in the list.
 */
function list_getAttachDirs()
{
    global $smcFunc, $modSettings, $context, $txt;
    if (isset($_SESSION['dir_errors'])) {
        $context['dir_errors'] = $_SESSION['dir_errors'];
        unset($_SESSION['dir_errors']);
    }
    $request = $smcFunc['db_query']('', '
		SELECT id_folder, COUNT(id_attach) AS num_attach, SUM(size) AS size_attach
		FROM {db_prefix}attachments
		GROUP BY id_folder', array());
    $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();
    foreach ($modSettings['attachmentUploadDir'] as $id => $dir) {
        // If there aren't any attachments in this directory this won't exist.
        if (!isset($expected_files[$id])) {
            $expected_files[$id] = 0;
        }
        // Check if the directory is doing okay.
        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('id' => $id, '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, '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>' : ''));
    }
    // Just stick a new directory on at the bottom.
    if (isset($_REQUEST['new_path'])) {
        $attachdirs[] = array('id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1, 'current' => false, 'path' => '', 'current_size' => '', 'num_files' => '', 'status' => '');
    }
    return $attachdirs;
}