[feature/attachment-management-no-reassignment] Attachments management

This feature allows to manage attachments in posts and PMs via ACP.

PHPBB3-9721
This commit is contained in:
rxu 2011-02-17 23:31:05 +07:00
parent 7074d19c40
commit 97864d69ee
4 changed files with 230 additions and 0 deletions

View file

@ -371,6 +371,74 @@
</fieldset> </fieldset>
</form> </form>
<!-- ELSEIF S_ATTACHMENTS -->
<form id="attachments" method="post" action="{U_ACTION}">
<fieldset class="tabulated">
<legend>{L_TITLE}</legend>
<!-- IF PAGINATION or TOTAL_FILES -->
<div class="pagination">
{L_NUMBER_FILES}: {TOTAL_FILES} &bull; {L_TOTAL_SIZE}: {TOTAL_SIZE}<!-- IF S_ON_PAGE --><!-- IF PAGINATION --> &bull; <a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{S_ON_PAGE}</a> &bull; <span>{PAGINATION}</span><!-- ELSE --> &bull; {S_ON_PAGE}<!-- ENDIF --><!-- ENDIF -->
</div>
<!-- ENDIF -->
<table cellspacing="1">
<thead>
<tr>
<th>{L_FILENAME}</th>
<th>{L_FILEDATE}</th>
<th>{L_FILESIZE}</th>
<th>{L_ATTACH_POST_ID}</th>
<th>{L_DELETE}</th>
</tr>
</thead>
<tbody>
<!-- BEGIN attachments -->
<!-- IF attachments.S_ROW_COUNT is even --><tr class="row1"><!-- ELSE --><tr class="row2"><!-- ENDIF -->
<td><a href="{attachments.U_FILE}" style="font-weight: bold;">{attachments.REAL_FILENAME}</a><br />{attachments.L_DOWNLOAD_COUNT}<br /><!-- IF attachments.S_IN_MESSAGE -->{L_IN} {L_PRIVATE_MESSAGE}<!-- ELSE -->{L_TOPIC}: <!-- ENDIF --><a href="{attachments.U_VIEW_TOPIC}">{attachments.TOPIC_TITLE}</a></td>
<td>{attachments.FILETIME}<br />{L_POST_BY_AUTHOR} {attachments.ATTACHMENT_POSTER}</td>
<td>{attachments.FILESIZE}</td>
<td>
<input type="text" name="post_id[{attachments.ATTACH_ID}]" size="7" maxlength="10" value="{attachments.POST_ID}" {attachments.DISABLED} />
<input type="hidden" name="current_post_id[{attachments.ATTACH_ID}]" value="{attachments.POST_ID}" />
<input type="hidden" name="current_topic_id[{attachments.ATTACH_ID}]" value="{attachments.TOPIC_ID}" />
</td>
<td><input type="checkbox" class="radio" name="delete[{attachments.ATTACH_ID}]" /></td>
</tr>
<!-- END attachments -->
<tr class="row4">
<td colspan="4">&nbsp;</td>
<td class="small"><a href="#" onclick="marklist('attachments', 'delete', true); return false;">{L_MARK_ALL}</a> :: <a href="#" onclick="marklist('attachments', 'delete', false); return false;">{L_UNMARK_ALL}</a></td>
</tr>
</tbody>
</table>
<fieldset class="display-options">
{L_DISPLAY_LOG}: &nbsp;{S_LIMIT_DAYS}&nbsp;{L_SORT_BY}: {S_SORT_KEY} {S_SORT_DIR}
<input class="button2" type="submit" value="{L_GO}" name="sort" />
{S_FORM_TOKEN}
</fieldset>
<hr />
<!-- IF PAGINATION or TOTAL_FILES -->
<div class="pagination">
{L_NUMBER_FILES}: {TOTAL_FILES} &bull; {L_TOTAL_SIZE}: {TOTAL_SIZE}<!-- IF S_ON_PAGE --><!-- IF PAGINATION --> &bull; <a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{S_ON_PAGE}</a> &bull; <span>{PAGINATION}</span><!-- ELSE --> &bull; {S_ON_PAGE}<!-- ENDIF --><!-- ENDIF -->
</div>
<!-- ENDIF -->
<br />
<p class="submit-buttons">
<input class="button1" type="submit" id="submit" name="submit" value="{L_SUBMIT}" />&nbsp;
<input class="button2" type="reset" id="reset" name="reset" value="{L_RESET}" />
</p>
</fieldset>
</form>
<!-- ENDIF --> <!-- ENDIF -->
<!-- INCLUDE overall_footer.html --> <!-- INCLUDE overall_footer.html -->

View file

@ -61,6 +61,10 @@ class acp_attachments
$l_title = 'ACP_ORPHAN_ATTACHMENTS'; $l_title = 'ACP_ORPHAN_ATTACHMENTS';
break; break;
case 'attachments':
$l_title = 'ACP_MANAGE_ATTACHMENTS';
break;
default: default:
trigger_error('NO_MODE', E_USER_ERROR); trigger_error('NO_MODE', E_USER_ERROR);
break; break;
@ -1043,6 +1047,156 @@ class acp_attachments
$db->sql_freeresult($result); $db->sql_freeresult($result);
break; 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 . "&amp;$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, '<br />', 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']}&amp;p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}",
'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))
);
}
break;
} }
if (sizeof($error)) if (sizeof($error))

View file

@ -24,6 +24,7 @@ class acp_attachments_info
'extensions' => array('title' => 'ACP_MANAGE_EXTENSIONS', 'auth' => 'acl_a_attach', 'cat' => array('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')), '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')),
), ),
); );
} }

View file

@ -116,6 +116,10 @@ $lang = array_merge($lang, array(
'ACP_LOGGING' => 'Logging', 'ACP_LOGGING' => 'Logging',
'ACP_MAIN' => 'ACP index', '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_EXTENSIONS' => 'Manage extensions',
'ACP_MANAGE_FORUMS' => 'Manage forums', 'ACP_MANAGE_FORUMS' => 'Manage forums',
'ACP_MANAGE_RANKS' => 'Manage ranks', 'ACP_MANAGE_RANKS' => 'Manage ranks',
@ -227,6 +231,7 @@ $lang = array_merge($lang, array(
'DOWNLOAD_AS' => 'Download as', 'DOWNLOAD_AS' => 'Download as',
'DOWNLOAD_STORE' => 'Download or store file', 'DOWNLOAD_STORE' => 'Download or store file',
'DOWNLOAD_STORE_EXPLAIN' => 'You may directly download the file or save it in your <samp>store/</samp> folder.', 'DOWNLOAD_STORE_EXPLAIN' => 'You may directly download the file or save it in your <samp>store/</samp> folder.',
'DOWNLOADS' => 'Downloads',
'EDIT' => 'Edit', 'EDIT' => 'Edit',
'ENABLE' => 'Enable', 'ENABLE' => 'Enable',
@ -284,6 +289,8 @@ $lang = array_merge($lang, array(
'SHOW_ALL_OPERATIONS' => 'Show all operations', 'SHOW_ALL_OPERATIONS' => 'Show all operations',
'TOTAL_SIZE' => 'Total size',
'UCP' => 'User Control Panel', 'UCP' => 'User Control Panel',
'USERNAMES_EXPLAIN' => 'Place each username on a separate line.', 'USERNAMES_EXPLAIN' => 'Place each username on a separate line.',
'USER_CONTROL_PANEL' => 'User Control Panel', 'USER_CONTROL_PANEL' => 'User Control Panel',