From 97864d69ee66134f04936137e2357caf99cd9f30 Mon Sep 17 00:00:00 2001
From: rxu
Date: Thu, 17 Feb 2011 23:31:05 +0700
Subject: [PATCH 1/5] [feature/attachment-management-no-reassignment]
Attachments management
This feature allows to manage attachments in posts and PMs via ACP.
PHPBB3-9721
---
phpBB/adm/style/acp_attachments.html | 68 +++++++++
phpBB/includes/acp/acp_attachments.php | 154 ++++++++++++++++++++
phpBB/includes/acp/info/acp_attachments.php | 1 +
phpBB/language/en/acp/common.php | 7 +
4 files changed, 230 insertions(+)
diff --git a/phpBB/adm/style/acp_attachments.html b/phpBB/adm/style/acp_attachments.html
index 22f271ea82..c11d3c7117 100644
--- a/phpBB/adm/style/acp_attachments.html
+++ b/phpBB/adm/style/acp_attachments.html
@@ -371,6 +371,74 @@
+
+
+
+
diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php
index 3179be7de7..7d796adf03 100644
--- a/phpBB/includes/acp/acp_attachments.php
+++ b/phpBB/includes/acp/acp_attachments.php
@@ -61,6 +61,10 @@ class acp_attachments
$l_title = 'ACP_ORPHAN_ATTACHMENTS';
break;
+ case 'attachments':
+ $l_title = 'ACP_MANAGE_ATTACHMENTS';
+ break;
+
default:
trigger_error('NO_MODE', E_USER_ERROR);
break;
@@ -1043,6 +1047,156 @@ class acp_attachments
$db->sql_freeresult($result);
break;
+
+ case 'attachments':
+
+ if ($submit)
+ {
+ $delete_files = (isset($_POST['delete'])) ? array_keys(request_var('delete', array('' => 0))) : array();
+
+ if (sizeof($delete_files))
+ {
+ // Select those attachments we want to delete...
+ $sql = 'SELECT real_filename
+ FROM ' . ATTACHMENTS_TABLE . '
+ WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
+ AND is_orphan = 0';
+ $result = $db->sql_query($sql);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $deleted_filenames[] = $row['real_filename'];
+ }
+ $db->sql_freeresult($result);
+ delete_attachments('attach', $delete_files);
+ add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $deleted_filenames));
+ $notify[] = sprintf($user->lang['LOG_ATTACHMENTS_DELETED'], implode(', ', $deleted_filenames));
+ }
+ }
+
+ $template->assign_vars(array(
+ 'S_ATTACHMENTS' => true)
+ );
+
+ // Sort keys
+ $sort_days = request_var('st', 0);
+ $sort_key = request_var('sk', 't');
+ $sort_dir = request_var('sd', 'd');
+
+ // Sorting
+ $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
+ $sort_by_text = array('f' => $user->lang['FILENAME'], 't' => $user->lang['FILEDATE'], 's' => $user->lang['FILESIZE'], 'x' => $user->lang['EXTENSION'], 'd' => $user->lang['DOWNLOADS'],'p' => $user->lang['ATTACH_POST_ID'], 'u' => $user->lang['AUTHOR']);
+ $sort_by_sql = array('f' => 'a.real_filename', 't' => 'a.filetime', 's' => 'a.filesize', 'x' => 'a.extension', 'd' => 'a.download_count', 'p' => 'a.post_msg_id', 'u' => 'u.username');
+
+ $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
+ gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
+
+ $min_filetime = ($sort_days) ? (time() - ($sort_days * 86400)) : '';
+ $limit_filetime = ($min_filetime) ? " AND a.filetime >= $min_filetime " : '';
+ $start = ($sort_days && isset($_POST['sort'])) ? 0 : $start;
+
+ $num_files = (int) $config['num_files'];
+ $total_size = get_formatted_filesize((int) $config['upload_dir_size']);
+
+ // Make sure $start is set to the last page if it exceeds the amount
+ if ($start < 0 || $start > $num_files)
+ {
+ $start = ($start < 0) ? 0 : floor(($num_files - 1) / $config['posts_per_page']) * $config['posts_per_page'];
+ }
+
+ // If the user is trying to reach the second half of the attachments list, fetch it starting from the end
+ $store_reverse = false;
+ $sql_limit = $config['posts_per_page'];
+
+ if ($start > $num_files / 2)
+ {
+ $store_reverse = true;
+
+ if ($start + $config['posts_per_page'] > $num_files)
+ {
+ $sql_limit = min($config['posts_per_page'], max(1, $num_files - $start));
+ }
+
+ // Select the sort order. Add time sort anchor for non-time sorting cases
+ $sql_sort_anchor = ($sort_key != 't') ? ', a.filetime ' . (($sort_dir == 'd') ? 'ASC' : 'DESC') : '';
+ $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC') . $sql_sort_anchor;
+ $sql_start = max(0, $num_files - $sql_limit - $start);
+ }
+ else
+ {
+ // Select the sort order. Add time sort anchor for non-time sorting cases
+ $sql_sort_anchor = ($sort_key != 't') ? ', a.filetime ' . (($sort_dir == 'd') ? 'DESC' : 'ASC') : '';
+ $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC') . $sql_sort_anchor;
+ $sql_start = $start;
+
+ }
+
+ $attachments_list = array();
+
+ // Just get the files
+ $sql = 'SELECT a.*, u.username, u.user_colour, t.topic_title
+ FROM ' . ATTACHMENTS_TABLE . ' a
+ LEFT JOIN ' . USERS_TABLE . ' u ON (u.user_id = a.poster_id)
+ LEFT JOIN ' . TOPICS_TABLE . " t ON (a.topic_id = t.topic_id)
+ WHERE a.is_orphan = 0
+ $limit_filetime
+ ORDER BY $sql_sort_order";
+ $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
+
+ $i = ($store_reverse) ? $sql_limit - 1 : 0;
+ while ($attachment_row = $db->sql_fetchrow($result))
+ {
+ $attachments_list[$i] = $attachment_row;
+ ($store_reverse) ? $i-- : $i++;
+ }
+ $db->sql_freeresult($result);
+
+ $template->assign_vars(array(
+ 'TOTAL_FILES' => $num_files,
+ 'TOTAL_SIZE' => $total_size,
+ 'PAGINATION' => generate_pagination($this->u_action . "&$u_sort_param", $num_files, $config['posts_per_page'], $start, true),
+
+ 'S_ON_PAGE' => on_page($num_files, $config['posts_per_page'], $start),
+ 'S_LIMIT_DAYS' => $s_limit_days,
+ 'S_SORT_KEY' => $s_sort_key,
+ 'S_SORT_DIR' => $s_sort_dir)
+ );
+
+ // Grab extensions
+ $extensions = array();
+ $extensions = $cache->obtain_attach_extensions(true);
+
+ for ($i = 0, $end = sizeof($attachments_list); $i < $end; ++$i)
+ {
+ $row =& $attachments_list[$i];
+
+ $row['extension'] = strtolower(trim((string) $row['extension']));
+ $display_cat = $extensions[$row['extension']]['display_cat'];
+ $l_downloaded_viewed = ($display_cat == ATTACHMENT_CATEGORY_NONE) ? 'DOWNLOAD_COUNT' : 'VIEWED_COUNT';
+ $l_download_count = (!isset($row['download_count']) || (int) $row['download_count'] == 0) ? $user->lang[$l_downloaded_viewed . '_NONE'] : (((int) $row['download_count'] == 1) ? sprintf($user->lang[$l_downloaded_viewed], $row['download_count']) : sprintf($user->lang[$l_downloaded_viewed . 'S'], $row['download_count']));
+
+ $template->assign_block_vars('attachments', array(
+ 'ATTACHMENT_POSTER' => get_username_string('full', (int) $row['poster_id'], (string) $row['username'], (string) $row['user_colour'], (string) $row['username']),
+ 'FILESIZE' => get_formatted_filesize((int) $row['filesize']),
+ 'FILETIME' => $user->format_date((int) $row['filetime']),
+ 'REAL_FILENAME' => utf8_wordwrap(utf8_basename((string) $row['real_filename']), 40, '
', true),
+ 'PHYSICAL_FILENAME' => utf8_basename((string) $row['physical_filename']),
+ 'TOPIC_TITLE' => (!$row['in_message']) ? (string) $row['topic_title'] : '',
+ 'DISABLED' => 'disabled="disabled"',
+ 'ATTACH_ID' => (int) $row['attach_id'],
+ 'POST_ID' => (int) $row['post_msg_id'],
+ 'TOPIC_ID' => (int) $row['topic_id'],
+ 'POST_IDS' => (!empty($post_ids[$row['attach_id']])) ? (int) $post_ids[$row['attach_id']] : '',
+
+ 'L_DOWNLOAD_COUNT' => $l_download_count,
+
+ 'S_IN_MESSAGE' => (bool) $row['in_message'],
+
+ 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}",
+ 'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&id=' . $row['attach_id']))
+ );
+ }
+
+ break;
}
if (sizeof($error))
diff --git a/phpBB/includes/acp/info/acp_attachments.php b/phpBB/includes/acp/info/acp_attachments.php
index d5f57ece4e..945392bc2a 100644
--- a/phpBB/includes/acp/info/acp_attachments.php
+++ b/phpBB/includes/acp/info/acp_attachments.php
@@ -24,6 +24,7 @@ class acp_attachments_info
'extensions' => array('title' => 'ACP_MANAGE_EXTENSIONS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
'ext_groups' => array('title' => 'ACP_EXTENSION_GROUPS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
'orphan' => array('title' => 'ACP_ORPHAN_ATTACHMENTS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS'))
+ 'attachments' => array('title' => 'ACP_MANAGE_ATTACHMENTS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
),
);
}
diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php
index 847e763ae8..9f89b6284c 100644
--- a/phpBB/language/en/acp/common.php
+++ b/phpBB/language/en/acp/common.php
@@ -116,6 +116,10 @@ $lang = array_merge($lang, array(
'ACP_LOGGING' => 'Logging',
'ACP_MAIN' => 'ACP index',
+
+ 'ACP_MANAGE_ATTACHMENTS' => 'Manage attachments',
+ 'ACP_MANAGE_ATTACHMENTS_EXPLAIN' => 'Here you can manage files attached to posts. You are able to delete the files or reassign them to existing posts. Reassigning to posts requires a valid post ID, you have to determine this ID by yourself. This will reassign the already assigned attachment to the post you entered.',
+
'ACP_MANAGE_EXTENSIONS' => 'Manage extensions',
'ACP_MANAGE_FORUMS' => 'Manage forums',
'ACP_MANAGE_RANKS' => 'Manage ranks',
@@ -227,6 +231,7 @@ $lang = array_merge($lang, array(
'DOWNLOAD_AS' => 'Download as',
'DOWNLOAD_STORE' => 'Download or store file',
'DOWNLOAD_STORE_EXPLAIN' => 'You may directly download the file or save it in your store/ folder.',
+ 'DOWNLOADS' => 'Downloads',
'EDIT' => 'Edit',
'ENABLE' => 'Enable',
@@ -284,6 +289,8 @@ $lang = array_merge($lang, array(
'SHOW_ALL_OPERATIONS' => 'Show all operations',
+ 'TOTAL_SIZE' => 'Total size',
+
'UCP' => 'User Control Panel',
'USERNAMES_EXPLAIN' => 'Place each username on a separate line.',
'USER_CONTROL_PANEL' => 'User Control Panel',
From 804a11074bfb6c8e1fef6f39d1b720468ff56a2f Mon Sep 17 00:00:00 2001
From: rxu
Date: Mon, 14 Mar 2011 00:03:31 +0700
Subject: [PATCH 2/5] [feature/attachment-management-no-reassignment] Fix minor
flaws in the code.
Thanks to Oleg for inspection.
PHPBB3-9721
---
phpBB/includes/acp/acp_attachments.php | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php
index 7d796adf03..b926f0c771 100644
--- a/phpBB/includes/acp/acp_attachments.php
+++ b/phpBB/includes/acp/acp_attachments.php
@@ -1137,9 +1137,9 @@ class acp_attachments
FROM ' . ATTACHMENTS_TABLE . ' a
LEFT JOIN ' . USERS_TABLE . ' u ON (u.user_id = a.poster_id)
LEFT JOIN ' . TOPICS_TABLE . " t ON (a.topic_id = t.topic_id)
- WHERE a.is_orphan = 0
- $limit_filetime
- ORDER BY $sql_sort_order";
+ WHERE a.is_orphan = 0
+ $limit_filetime
+ ORDER BY $sql_sort_order";
$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
$i = ($store_reverse) ? $sql_limit - 1 : 0;
@@ -1161,8 +1161,7 @@ class acp_attachments
'S_SORT_DIR' => $s_sort_dir)
);
- // Grab extensions
- $extensions = array();
+ // Grab extensions information
$extensions = $cache->obtain_attach_extensions(true);
for ($i = 0, $end = sizeof($attachments_list); $i < $end; ++$i)
From d3523f4f8718c98d5c5709e1c05c6ab7c28f04aa Mon Sep 17 00:00:00 2001
From: rxu
Date: Mon, 11 Apr 2011 12:32:31 +0800
Subject: [PATCH 3/5] [feature/attachment-management-no-reassignment] Fix some
more errors
Missing comma for orphan key in info module, define $start variable
PHPBB3-9721
---
phpBB/includes/acp/acp_attachments.php | 2 ++
phpBB/includes/acp/info/acp_attachments.php | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php
index b926f0c771..7cc84b5a8e 100644
--- a/phpBB/includes/acp/acp_attachments.php
+++ b/phpBB/includes/acp/acp_attachments.php
@@ -1076,6 +1076,8 @@ class acp_attachments
$template->assign_vars(array(
'S_ATTACHMENTS' => true)
);
+
+ $start = request_var('start', 0);
// Sort keys
$sort_days = request_var('st', 0);
diff --git a/phpBB/includes/acp/info/acp_attachments.php b/phpBB/includes/acp/info/acp_attachments.php
index 945392bc2a..d55003bbe5 100644
--- a/phpBB/includes/acp/info/acp_attachments.php
+++ b/phpBB/includes/acp/info/acp_attachments.php
@@ -23,7 +23,7 @@ class acp_attachments_info
'attach' => array('title' => 'ACP_ATTACHMENT_SETTINGS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_BOARD_CONFIGURATION', 'ACP_ATTACHMENTS')),
'extensions' => array('title' => 'ACP_MANAGE_EXTENSIONS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
'ext_groups' => array('title' => 'ACP_EXTENSION_GROUPS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
- 'orphan' => array('title' => 'ACP_ORPHAN_ATTACHMENTS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS'))
+ 'orphan' => array('title' => 'ACP_ORPHAN_ATTACHMENTS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
'attachments' => array('title' => 'ACP_MANAGE_ATTACHMENTS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
),
);
From d811820bc11bac61076d5a92d741d22df9944af8 Mon Sep 17 00:00:00 2001
From: rxu
Date: Mon, 11 Apr 2011 19:59:50 +0800
Subject: [PATCH 4/5] [feature/attachment-management-no-reassignment] Further
feature adjustments.
-add database update entry;
- add files statistics checks;
- improve files deletion procedure;
- improve reversed order for pagination;
- adjust template file;
- add missing comma for orphan key in info module;
- change module mode name;
- fix module explanation text;
- add files comments output;
- change attachments per page amount from posts to topics per page value.
PHPBB3-9721
---
phpBB/adm/style/acp_attachments.html | 19 ++----
phpBB/includes/acp/acp_attachments.php | 75 +++++++++++++++------
phpBB/includes/acp/info/acp_attachments.php | 2 +-
phpBB/install/database_update.php | 7 ++
phpBB/language/en/acp/common.php | 6 +-
5 files changed, 75 insertions(+), 34 deletions(-)
diff --git a/phpBB/adm/style/acp_attachments.html b/phpBB/adm/style/acp_attachments.html
index c11d3c7117..4a75a9b63b 100644
--- a/phpBB/adm/style/acp_attachments.html
+++ b/phpBB/adm/style/acp_attachments.html
@@ -371,7 +371,7 @@
-
+
-
+ {S_FORM_TOKEN}
diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php
index 7cc84b5a8e..1c3c43c8e9 100644
--- a/phpBB/includes/acp/acp_attachments.php
+++ b/phpBB/includes/acp/acp_attachments.php
@@ -61,7 +61,7 @@ class acp_attachments
$l_title = 'ACP_ORPHAN_ATTACHMENTS';
break;
- case 'attachments':
+ case 'manage':
$l_title = 'ACP_MANAGE_ATTACHMENTS';
break;
@@ -1048,7 +1048,7 @@ class acp_attachments
break;
- case 'attachments':
+ case 'manage':
if ($submit)
{
@@ -1067,16 +1067,27 @@ class acp_attachments
$deleted_filenames[] = $row['real_filename'];
}
$db->sql_freeresult($result);
- delete_attachments('attach', $delete_files);
- add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $deleted_filenames));
- $notify[] = sprintf($user->lang['LOG_ATTACHMENTS_DELETED'], implode(', ', $deleted_filenames));
+
+ if ($num_deleted = delete_attachments('attach', $delete_files))
+ {
+ if (sizeof($delete_files) != $num_deleted)
+ {
+ $error[] = $user->lang['FILES_GONE'];
+ }
+ add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $deleted_filenames));
+ $notify[] = sprintf($user->lang['LOG_ATTACHMENTS_DELETED'], implode(', ', $deleted_filenames));
+ }
+ else
+ {
+ $error[] = $user->lang['NO_FILES_TO_DELETE'];
+ }
}
}
$template->assign_vars(array(
- 'S_ATTACHMENTS' => true)
+ 'S_MANAGE' => true)
);
-
+
$start = request_var('start', 0);
// Sort keys
@@ -1096,26 +1107,48 @@ class acp_attachments
$limit_filetime = ($min_filetime) ? " AND a.filetime >= $min_filetime " : '';
$start = ($sort_days && isset($_POST['sort'])) ? 0 : $start;
+ $attachments_per_page = (int) $config['topics_per_page'];
+
$num_files = (int) $config['num_files'];
- $total_size = get_formatted_filesize((int) $config['upload_dir_size']);
+ $total_size = (int) $config['upload_dir_size'];
+
+ // Check if files statistics is accurate
+ $sql = 'SELECT COUNT(attach_id) as num_files
+ FROM ' . ATTACHMENTS_TABLE . '
+ WHERE is_orphan = 0';
+ $result = $db->sql_query($sql, 600);
+ $num_files_real = (int) $db->sql_fetchfield('num_files');
+ $db->sql_freeresult($result);
+
+ $sql = 'SELECT SUM(filesize) as upload_dir_size
+ FROM ' . ATTACHMENTS_TABLE . '
+ WHERE is_orphan = 0';
+ $result = $db->sql_query($sql, 600);
+ $total_size_real = (int) $db->sql_fetchfield('upload_dir_size');
+ $db->sql_freeresult($result);
+
+ if (($num_files != $num_files_real) || ($total_size != $total_size_real))
+ {
+ $error[] = sprintf($user->lang['FILES_STAT_WRONG'], $num_files_real, get_formatted_filesize($total_size_real));
+ }
// Make sure $start is set to the last page if it exceeds the amount
if ($start < 0 || $start > $num_files)
{
- $start = ($start < 0) ? 0 : floor(($num_files - 1) / $config['posts_per_page']) * $config['posts_per_page'];
+ $start = ($start < 0) ? 0 : floor(($num_files - 1) / $attachments_per_page) * $attachments_per_page;
}
// If the user is trying to reach the second half of the attachments list, fetch it starting from the end
$store_reverse = false;
- $sql_limit = $config['posts_per_page'];
+ $sql_limit = $attachments_per_page;
if ($start > $num_files / 2)
{
$store_reverse = true;
- if ($start + $config['posts_per_page'] > $num_files)
+ if ($start + $attachments_per_page > $num_files)
{
- $sql_limit = min($config['posts_per_page'], max(1, $num_files - $start));
+ $sql_limit = min($attachments_per_page, max(1, $num_files - $start));
}
// Select the sort order. Add time sort anchor for non-time sorting cases
@@ -1145,32 +1178,36 @@ class acp_attachments
$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
$i = ($store_reverse) ? $sql_limit - 1 : 0;
+
+ // Store increment value in a variable to save some conditional calls
+ $i_increment = ($store_reverse) ? -1 : 1;
while ($attachment_row = $db->sql_fetchrow($result))
{
$attachments_list[$i] = $attachment_row;
- ($store_reverse) ? $i-- : $i++;
+ $i = $i + $i_increment;
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'TOTAL_FILES' => $num_files,
- 'TOTAL_SIZE' => $total_size,
- 'PAGINATION' => generate_pagination($this->u_action . "&$u_sort_param", $num_files, $config['posts_per_page'], $start, true),
+ 'TOTAL_SIZE' => get_formatted_filesize($total_size),
+ 'PAGINATION' => generate_pagination($this->u_action . "&$u_sort_param", $num_files, $attachments_per_page, $start, true),
- 'S_ON_PAGE' => on_page($num_files, $config['posts_per_page'], $start),
+ 'S_ON_PAGE' => on_page($num_files, $attachments_per_page, $start),
'S_LIMIT_DAYS' => $s_limit_days,
'S_SORT_KEY' => $s_sort_key,
'S_SORT_DIR' => $s_sort_dir)
);
- // Grab extensions information
+ // Grab extensions
$extensions = $cache->obtain_attach_extensions(true);
for ($i = 0, $end = sizeof($attachments_list); $i < $end; ++$i)
{
- $row =& $attachments_list[$i];
+ $row = $attachments_list[$i];
$row['extension'] = strtolower(trim((string) $row['extension']));
+ $comment = ($row['attach_comment']) ? str_replace(array("\n", "\r"), array('
', "\n"), $row['attach_comment']) : '';
$display_cat = $extensions[$row['extension']]['display_cat'];
$l_downloaded_viewed = ($display_cat == ATTACHMENT_CATEGORY_NONE) ? 'DOWNLOAD_COUNT' : 'VIEWED_COUNT';
$l_download_count = (!isset($row['download_count']) || (int) $row['download_count'] == 0) ? $user->lang[$l_downloaded_viewed . '_NONE'] : (((int) $row['download_count'] == 1) ? sprintf($user->lang[$l_downloaded_viewed], $row['download_count']) : sprintf($user->lang[$l_downloaded_viewed . 'S'], $row['download_count']));
@@ -1181,8 +1218,8 @@ class acp_attachments
'FILETIME' => $user->format_date((int) $row['filetime']),
'REAL_FILENAME' => utf8_wordwrap(utf8_basename((string) $row['real_filename']), 40, '
', true),
'PHYSICAL_FILENAME' => utf8_basename((string) $row['physical_filename']),
+ 'COMMENT' => $comment,
'TOPIC_TITLE' => (!$row['in_message']) ? (string) $row['topic_title'] : '',
- 'DISABLED' => 'disabled="disabled"',
'ATTACH_ID' => (int) $row['attach_id'],
'POST_ID' => (int) $row['post_msg_id'],
'TOPIC_ID' => (int) $row['topic_id'],
diff --git a/phpBB/includes/acp/info/acp_attachments.php b/phpBB/includes/acp/info/acp_attachments.php
index d55003bbe5..4bcd7e2ea5 100644
--- a/phpBB/includes/acp/info/acp_attachments.php
+++ b/phpBB/includes/acp/info/acp_attachments.php
@@ -24,7 +24,7 @@ class acp_attachments_info
'extensions' => array('title' => 'ACP_MANAGE_EXTENSIONS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
'ext_groups' => array('title' => 'ACP_EXTENSION_GROUPS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
'orphan' => array('title' => 'ACP_ORPHAN_ATTACHMENTS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
- 'attachments' => array('title' => 'ACP_MANAGE_ATTACHMENTS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
+ 'manage' => array('title' => 'ACP_MANAGE_ATTACHMENTS', 'auth' => 'acl_a_attach', 'cat' => array('ACP_ATTACHMENTS')),
),
);
}
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index cf611ca951..4f2a5966ee 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -1958,6 +1958,13 @@ function change_database_data(&$no_updates, $version)
'auth' => 'acl_a_group',
'cat' => 'ACP_GROUPS',
),
+ 'manage' => array(
+ 'base' => 'attachments',
+ 'class' => 'acp',
+ 'title' => 'ACP_MANAGE_ATTACHMENTS',
+ 'auth' => 'acl_a_attach',
+ 'cat' => 'ACP_ATTACHMENTS',
+ ),
);
_add_modules($modules_to_install);
diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php
index 9f89b6284c..11e8e05a56 100644
--- a/phpBB/language/en/acp/common.php
+++ b/phpBB/language/en/acp/common.php
@@ -118,7 +118,7 @@ $lang = array_merge($lang, array(
'ACP_MAIN' => 'ACP index',
'ACP_MANAGE_ATTACHMENTS' => 'Manage attachments',
- 'ACP_MANAGE_ATTACHMENTS_EXPLAIN' => 'Here you can manage files attached to posts. You are able to delete the files or reassign them to existing posts. Reassigning to posts requires a valid post ID, you have to determine this ID by yourself. This will reassign the already assigned attachment to the post you entered.',
+ 'ACP_MANAGE_ATTACHMENTS_EXPLAIN' => 'Here you can list and delete files attached to posts and private messages.',
'ACP_MANAGE_EXTENSIONS' => 'Manage extensions',
'ACP_MANAGE_FORUMS' => 'Manage forums',
@@ -238,6 +238,9 @@ $lang = array_merge($lang, array(
'EXPORT_DOWNLOAD' => 'Download',
'EXPORT_STORE' => 'Store',
+ 'FILES_GONE' => 'Some of the attachments you selected for deletion do not exist. They may have been already deleted. Attachments that did exist were deleted.',
+ 'FILES_STAT_WRONG' => 'Your files statistics is probably inaccurate and might need to be resynchronised. Actual values: number of attachments » %1$d, total size of attachments » %2$s.',
+
'GENERAL_OPTIONS' => 'General options',
'GENERAL_SETTINGS' => 'General settings',
'GLOBAL_MASK' => 'Global permission mask',
@@ -263,6 +266,7 @@ $lang = array_merge($lang, array(
'NOTIFY' => 'Notification',
'NO_ADMIN' => 'You are not authorised to administer this board.',
'NO_EMAILS_DEFINED' => 'No valid e-mail addresses found.',
+ 'NO_FILES_TO_DELETE' => 'Attachments you selected for deletion do not exist.',
'NO_PASSWORD_SUPPLIED' => 'You need to enter your password to access the Administration Control Panel.',
'OFF' => 'Off',
From baba66a22991e93908a8b4e7f8bfa104b3588450 Mon Sep 17 00:00:00 2001
From: rxu
Date: Sun, 24 Apr 2011 23:33:51 +0800
Subject: [PATCH 5/5] [feature/attachment-management-no-reassignment] Handle
privacy and some more.
- restrict files info for PM attachments;
- add an option to resync files stats if wrong;
- replace post_id sorting with post type (PM/regular post) one;
- some language fixes.
PHPBB3-9721
---
phpBB/adm/style/acp_attachments.html | 20 ++++++++--
phpBB/includes/acp/acp_attachments.php | 54 +++++++++++++++++++++-----
phpBB/includes/cache/service.php | 1 +
phpBB/language/en/acp/attachments.php | 1 +
phpBB/language/en/acp/common.php | 6 ++-
5 files changed, 68 insertions(+), 14 deletions(-)
diff --git a/phpBB/adm/style/acp_attachments.html b/phpBB/adm/style/acp_attachments.html
index 4a75a9b63b..d938135440 100644
--- a/phpBB/adm/style/acp_attachments.html
+++ b/phpBB/adm/style/acp_attachments.html
@@ -396,7 +396,10 @@
|
- {attachments.REAL_FILENAME} {attachments.COMMENT} {attachments.L_DOWNLOAD_COUNT} {L_IN} {L_PRIVATE_MESSAGE}{L_TOPIC}: {attachments.TOPIC_TITLE} |
+
+ {L_EXTENSION_GROUP}: {attachments.EXT_GROUP_NAME}{L_NO_EXT_GROUP} {attachments.L_DOWNLOAD_COUNT} {L_IN} {L_PRIVATE_MESSAGE}
+ {attachments.REAL_FILENAME} {attachments.COMMENT} {attachments.L_DOWNLOAD_COUNT} {L_TOPIC}: {attachments.TOPIC_TITLE}
+ |
{attachments.FILETIME} {L_POST_BY_AUTHOR} {attachments.ATTACHMENT_POSTER} |
{attachments.FILESIZE} |
|
@@ -414,6 +417,7 @@
{L_DISPLAY_LOG}: {S_LIMIT_DAYS} {L_SORT_BY}: {S_SORT_KEY} {S_SORT_DIR}
+
-
-
{S_FORM_TOKEN}
-
+
+
+
diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php
index 1c3c43c8e9..c62fefae46 100644
--- a/phpBB/includes/acp/acp_attachments.php
+++ b/phpBB/includes/acp/acp_attachments.php
@@ -1097,8 +1097,8 @@ class acp_attachments
// Sorting
$limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
- $sort_by_text = array('f' => $user->lang['FILENAME'], 't' => $user->lang['FILEDATE'], 's' => $user->lang['FILESIZE'], 'x' => $user->lang['EXTENSION'], 'd' => $user->lang['DOWNLOADS'],'p' => $user->lang['ATTACH_POST_ID'], 'u' => $user->lang['AUTHOR']);
- $sort_by_sql = array('f' => 'a.real_filename', 't' => 'a.filetime', 's' => 'a.filesize', 'x' => 'a.extension', 'd' => 'a.download_count', 'p' => 'a.post_msg_id', 'u' => 'u.username');
+ $sort_by_text = array('f' => $user->lang['FILENAME'], 't' => $user->lang['FILEDATE'], 's' => $user->lang['FILESIZE'], 'x' => $user->lang['EXTENSION'], 'd' => $user->lang['DOWNLOADS'],'p' => $user->lang['ATTACH_POST_TYPE'], 'u' => $user->lang['AUTHOR']);
+ $sort_by_sql = array('f' => 'a.real_filename', 't' => 'a.filetime', 's' => 'a.filesize', 'x' => 'a.extension', 'd' => 'a.download_count', 'p' => 'a.in_message', 'u' => 'u.username');
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
@@ -1109,27 +1109,62 @@ class acp_attachments
$attachments_per_page = (int) $config['topics_per_page'];
- $num_files = (int) $config['num_files'];
- $total_size = (int) $config['upload_dir_size'];
+ // Handle files stats resync
+ $action = request_var('action', '');
+ $resync_files_stats = false;
+ if ($action && $action = 'stats')
+ {
+ if (!confirm_box(true))
+ {
+ confirm_box(false, $user->lang['RESYNC_FILES_STATS_CONFIRM'], build_hidden_fields(array(
+ 'i' => $id,
+ 'mode' => $mode,
+ 'action' => $action,
+ )));
+ }
+ else
+ {
+ $resync_files_stats = true;
+ add_log('admin', 'LOG_RESYNC_FILES_STATS');
+ }
+ }
- // Check if files statistics is accurate
+ // Check if files stats are accurate
$sql = 'SELECT COUNT(attach_id) as num_files
FROM ' . ATTACHMENTS_TABLE . '
WHERE is_orphan = 0';
$result = $db->sql_query($sql, 600);
$num_files_real = (int) $db->sql_fetchfield('num_files');
+ if ($resync_files_stats === true)
+ {
+ set_config('num_files', $num_files_real, true);
+ }
$db->sql_freeresult($result);
$sql = 'SELECT SUM(filesize) as upload_dir_size
FROM ' . ATTACHMENTS_TABLE . '
WHERE is_orphan = 0';
$result = $db->sql_query($sql, 600);
- $total_size_real = (int) $db->sql_fetchfield('upload_dir_size');
+ $total_size_real = (float) $db->sql_fetchfield('upload_dir_size');
+ if ($resync_files_stats === true)
+ {
+ set_config('upload_dir_size', $total_size_real, true);
+ }
$db->sql_freeresult($result);
+ // Get current files stats
+ $num_files = (int) $config['num_files'];
+ $total_size = (float) $config['upload_dir_size'];
+
+ // Issue warning message if files stats are inaccurate
if (($num_files != $num_files_real) || ($total_size != $total_size_real))
{
- $error[] = sprintf($user->lang['FILES_STAT_WRONG'], $num_files_real, get_formatted_filesize($total_size_real));
+ $error[] = sprintf($user->lang['FILES_STATS_WRONG'], $num_files_real, get_formatted_filesize($total_size_real));
+
+ $template->assign_vars(array(
+ 'S_ACTION_OPTIONS' => ($auth->acl_get('a_board')) ? true : false,
+ 'U_ACTION' => $this->u_action,)
+ );
}
// Make sure $start is set to the last page if it exceeds the amount
@@ -1207,7 +1242,7 @@ class acp_attachments
$row = $attachments_list[$i];
$row['extension'] = strtolower(trim((string) $row['extension']));
- $comment = ($row['attach_comment']) ? str_replace(array("\n", "\r"), array('
', "\n"), $row['attach_comment']) : '';
+ $comment = ($row['attach_comment'] && !$row['in_message']) ? str_replace(array("\n", "\r"), array('
', "\n"), $row['attach_comment']) : '';
$display_cat = $extensions[$row['extension']]['display_cat'];
$l_downloaded_viewed = ($display_cat == ATTACHMENT_CATEGORY_NONE) ? 'DOWNLOAD_COUNT' : 'VIEWED_COUNT';
$l_download_count = (!isset($row['download_count']) || (int) $row['download_count'] == 0) ? $user->lang[$l_downloaded_viewed . '_NONE'] : (((int) $row['download_count'] == 1) ? sprintf($user->lang[$l_downloaded_viewed], $row['download_count']) : sprintf($user->lang[$l_downloaded_viewed . 'S'], $row['download_count']));
@@ -1216,8 +1251,9 @@ class acp_attachments
'ATTACHMENT_POSTER' => get_username_string('full', (int) $row['poster_id'], (string) $row['username'], (string) $row['user_colour'], (string) $row['username']),
'FILESIZE' => get_formatted_filesize((int) $row['filesize']),
'FILETIME' => $user->format_date((int) $row['filetime']),
- 'REAL_FILENAME' => utf8_wordwrap(utf8_basename((string) $row['real_filename']), 40, '
', true),
+ 'REAL_FILENAME' => (!$row['in_message']) ? utf8_wordwrap(utf8_basename((string) $row['real_filename']), 40, '
', true) : '',
'PHYSICAL_FILENAME' => utf8_basename((string) $row['physical_filename']),
+ 'EXT_GROUP_NAME' => (!empty($extensions[$row['extension']]['group_name'])) ? $user->lang['EXT_GROUP_' . $extensions[$row['extension']]['group_name']] : '',
'COMMENT' => $comment,
'TOPIC_TITLE' => (!$row['in_message']) ? (string) $row['topic_title'] : '',
'ATTACH_ID' => (int) $row['attach_id'],
diff --git a/phpBB/includes/cache/service.php b/phpBB/includes/cache/service.php
index 68026c8647..0c01953d55 100644
--- a/phpBB/includes/cache/service.php
+++ b/phpBB/includes/cache/service.php
@@ -194,6 +194,7 @@ class phpbb_cache_service
'max_filesize' => (int) $row['max_filesize'],
'allow_group' => $row['allow_group'],
'allow_in_pm' => $row['allow_in_pm'],
+ 'group_name' => $row['group_name'],
);
$allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
diff --git a/phpBB/language/en/acp/attachments.php b/phpBB/language/en/acp/attachments.php
index 9ae250a95a..eede2c5d50 100644
--- a/phpBB/language/en/acp/attachments.php
+++ b/phpBB/language/en/acp/attachments.php
@@ -62,6 +62,7 @@ $lang = array_merge($lang, array(
'ATTACH_MAX_PM_FILESIZE_EXPLAIN' => 'Maximum size of each file, with 0 being unlimited, attached to a private message.',
'ATTACH_ORPHAN_URL' => 'Orphan attachments',
'ATTACH_POST_ID' => 'Post ID',
+ 'ATTACH_POST_TYPE' => 'Post type',
'ATTACH_QUOTA' => 'Total attachment quota',
'ATTACH_QUOTA_EXPLAIN' => 'Maximum drive space available for attachments for the whole board, with 0 being unlimited.',
'ATTACH_TO_POST' => 'Attach file to post',
diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php
index 11e8e05a56..2a8ed86175 100644
--- a/phpBB/language/en/acp/common.php
+++ b/phpBB/language/en/acp/common.php
@@ -239,7 +239,7 @@ $lang = array_merge($lang, array(
'EXPORT_STORE' => 'Store',
'FILES_GONE' => 'Some of the attachments you selected for deletion do not exist. They may have been already deleted. Attachments that did exist were deleted.',
- 'FILES_STAT_WRONG' => 'Your files statistics is probably inaccurate and might need to be resynchronised. Actual values: number of attachments » %1$d, total size of attachments » %2$s.',
+ 'FILES_STATS_WRONG' => 'Your files statistics are probably inaccurate and need to be resynchronised. Actual values: number of attachments = %1$d, total size of attachments = %2$s.',
'GENERAL_OPTIONS' => 'General options',
'GENERAL_SETTINGS' => 'General settings',
@@ -281,6 +281,8 @@ $lang = array_merge($lang, array(
'REMIND' => 'Remind',
'RESYNC' => 'Resynchronise',
+ 'RESYNC_FILES_STATS' => 'Resynchronise files statistics',
+ 'RESYNC_FILES_STATS_EXPLAIN' => 'Recalculates the total number and size of files attached to posts and private messages.',
'RETURN_TO' => 'Return to…',
'SELECT_ANONYMOUS' => 'Select anonymous user',
@@ -367,6 +369,7 @@ $lang = array_merge($lang, array(
'RESET_DATE_CONFIRM' => 'Are you sure you wish to reset the board’s start date?',
'RESET_ONLINE' => 'Reset most users ever online',
'RESET_ONLINE_CONFIRM' => 'Are you sure you wish to reset the most users ever online counter?',
+ 'RESYNC_FILES_STATS_CONFIRM' => 'Are you sure you wish to resynchronise files statistics?',
'RESYNC_POSTCOUNTS' => 'Resynchronise post counts',
'RESYNC_POSTCOUNTS_EXPLAIN' => 'Only existing posts will be taken into consideration. Pruned posts will not be counted.',
'RESYNC_POSTCOUNTS_CONFIRM' => 'Are you sure you wish to resynchronise post counts?',
@@ -671,6 +674,7 @@ $lang = array_merge($lang, array(
'LOG_REFERER_INVALID' => 'Referer validation failed
»Referer was “%1$s”. The request was rejected and the session killed.',
'LOG_RESET_DATE' => 'Board start date reset',
'LOG_RESET_ONLINE' => 'Most users online reset',
+ 'LOG_RESYNC_FILES_STATS' => 'Files statistics resynchronised',
'LOG_RESYNC_POSTCOUNTS' => 'User post counts resynchronised',
'LOG_RESYNC_POST_MARKING' => 'Dotted topics resynchronised',
'LOG_RESYNC_STATS' => 'Post, topic and user statistics resynchronised',