1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-21 00:02:18 +02:00

Merge pull request #2852 from bantu/ticket/12938

[ticket/12938] Remove the 'Download all attachments' feature.

* bantu/ticket/12938:
  [ticket/12938] Remove functional tests for 'Download all attachments'.
  [ticket/12938] Remove the 'Download all attachments' feature.
This commit is contained in:
Joas Schilling 2014-08-10 12:22:22 +02:00
commit 1f6b9628e7
10 changed files with 8 additions and 364 deletions

View File

@ -139,11 +139,7 @@ if (isset($_GET['avatar']))
include($phpbb_root_path . 'common.' . $phpEx);
require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx);
$download_id = request_var('id', 0);
$topic_id = $request->variable('topic_id', 0);
$post_id = $request->variable('post_id', 0);
$msg_id = $request->variable('msg_id', 0);
$archive = $request->variable('archive', '.tar');
$attach_id = request_var('id', 0);
$mode = request_var('mode', '');
$thumbnail = request_var('t', false);
@ -158,27 +154,7 @@ if (!$config['allow_attachments'] && !$config['allow_pm_attach'])
trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
}
if ($download_id)
{
// Attachment id (only 1 attachment)
$sql_where = 'attach_id = ' . $download_id;
}
else if ($msg_id)
{
// Private message id (multiple attachments)
$sql_where = 'is_orphan = 0 AND in_message = 1 AND post_msg_id = ' . $msg_id;
}
else if ($post_id)
{
// Post id (multiple attachments)
$sql_where = 'is_orphan = 0 AND in_message = 0 AND post_msg_id = ' . $post_id;
}
else if ($topic_id)
{
// Topic id (multiple attachments)
$sql_where = 'is_orphan = 0 AND topic_id = ' . $topic_id;
}
else
if (!$attach_id)
{
send_status_line(404, 'Not Found');
trigger_error('NO_ATTACHMENT_SELECTED');
@ -186,25 +162,12 @@ else
$sql = 'SELECT attach_id, post_msg_id, topic_id, in_message, poster_id, is_orphan, physical_filename, real_filename, extension, mimetype, filesize, filetime
FROM ' . ATTACHMENTS_TABLE . "
WHERE $sql_where";
WHERE attach_id = $attach_id";
$result = $db->sql_query($sql);
$attachments = $attachment_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$attachment_id = (int) $row['attach_id'];
$row['physical_filename'] = utf8_basename($row['physical_filename']);
$attachment_ids[$attachment_id] = $attachment_id;
$attachments[$attachment_id] = $row;
}
$attachment = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// Make $attachment the first of the attachments we fetched.
$attachment = current($attachments);
if (empty($attachments))
if (!$attachment)
{
send_status_line(404, 'Not Found');
trigger_error('ERROR_NO_ATTACHMENT');
@ -214,9 +177,9 @@ else if (!download_allowed())
send_status_line(403, 'Forbidden');
trigger_error($user->lang['LINKAGE_FORBIDDEN']);
}
else if ($download_id)
else
{
// sizeof($attachments) == 1
$attachment['physical_filename'] = utf8_basename($attachment['physical_filename']);
if (!$attachment['in_message'] && !$config['allow_attachments'] || $attachment['in_message'] && !$config['allow_pm_attach'])
{
@ -323,142 +286,3 @@ else if ($download_id)
}
}
}
else
{
// sizeof($attachments) >= 1
if ($attachment['in_message'])
{
phpbb_download_handle_pm_auth($db, $auth, $user->data['user_id'], $attachment['post_msg_id']);
}
else
{
phpbb_download_handle_forum_auth($db, $auth, $attachment['topic_id']);
}
if (!class_exists('compress'))
{
require $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
}
if (!in_array($archive, compress::methods()))
{
$archive = '.tar';
}
$post_visibility = array();
if ($msg_id)
{
$sql = 'SELECT message_subject AS attach_subject
FROM ' . PRIVMSGS_TABLE . "
WHERE msg_id = $msg_id";
}
else if ($post_id)
{
$sql = 'SELECT post_subject AS attach_subject, forum_id, post_visibility
FROM ' . POSTS_TABLE . "
WHERE post_id = $post_id";
}
else
{
$sql = 'SELECT post_id, post_visibility
FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id
AND post_attachment = 1";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$post_visibility[(int) $row['post_id']] = (int) $row['post_visibility'];
}
$db->sql_freeresult($result);
$sql = 'SELECT topic_title AS attach_subject, forum_id
FROM ' . TOPICS_TABLE . "
WHERE topic_id = $topic_id";
}
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (empty($row))
{
send_status_line(404, 'Not Found');
trigger_error('ERROR_NO_ATTACHMENT');
}
$clean_name = phpbb_download_clean_filename($row['attach_subject']);
$suffix = '_' . (($msg_id) ? 'm' . $msg_id : (($post_id) ? 'p' . $post_id : 't' . $topic_id)) . '_' . $clean_name;
$archive_name = 'attachments' . $suffix;
$store_name = 'att_' . time() . '_' . unique_id();
$archive_path = "{$phpbb_root_path}store/{$store_name}{$archive}";
if ($archive === '.zip')
{
$compress = new compress_zip('w', $archive_path);
}
else
{
$compress = new compress_tar('w', $archive_path, $archive);
}
$extensions = array();
$files_added = 0;
$forum_id = ($attachment['in_message']) ? false : (int) $row['forum_id'];
$disallowed_extension = array();
foreach ($attachments as $attach)
{
if (!extension_allowed($forum_id, $attach['extension'], $extensions))
{
$disallowed_extension[$attach['extension']] = $attach['extension'];
continue;
}
if ($post_id && $row['post_visibility'] != ITEM_APPROVED && !$auth->acl_get('m_approve', $forum_id))
{
// Attachment of a soft deleted post and the user is not allowed to see the post
continue;
}
if ($topic_id && (!isset($post_visibility[$attach['post_msg_id']]) || $post_visibility[$attach['post_msg_id']] != ITEM_APPROVED) && !$auth->acl_get('m_approve', $forum_id))
{
// Attachment of a soft deleted post and the user is not allowed to see the post
continue;
}
$prefix = '';
if ($topic_id)
{
$prefix = $attach['post_msg_id'] . '_';
}
$compress->add_custom_file("{$phpbb_root_path}files/{$attach['physical_filename']}", "{$prefix}{$attach['real_filename']}");
$files_added++;
}
$compress->close();
if ($files_added)
{
phpbb_increment_downloads($db, $attachment_ids);
$compress->download($store_name, $archive_name);
}
unlink($archive_path);
if (!$files_added && !empty($disallowed_extension))
{
// None of the attachments had a valid extension
$disallowed_extension = implode($user->lang['COMMA_SEPARATOR'], $disallowed_extension);
send_status_line(403, 'Forbidden');
trigger_error($user->lang('EXTENSION_DISABLED_AFTER_POSTING', $disallowed_extension));
}
else if (!$files_added)
{
send_status_line(404, 'Not Found');
trigger_error('ERROR_NO_ATTACHMENT');
}
file_gc();
}

View File

@ -1420,44 +1420,6 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank
}
}
/**
* Generate a list of archive types available for compressing attachments
*
* @param string $param_key Either topic_id or post_id
* @param string $param_val The value of the topic or post id
* @param string $phpbb_root_path The root path of the phpBB installation
* @param string $phpEx The PHP file extension
*
* @return array Array containing the link and the type of compression
*/
function phpbb_gen_download_links($param_key, $param_val, $phpbb_root_path, $phpEx)
{
if (!class_exists('compress'))
{
require $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
}
$methods = compress::methods();
// Sort by preferred type.
$methods = array_intersect(array('.zip', '.tar.bz2', '.tar.gz', '.tar'), $methods);
$links = array();
foreach ($methods as $method)
{
$exploded = explode('.', $method);
$type = array_pop($exploded);
$params = array('archive' => $method);
$params[$param_key] = $param_val;
$links[] = array(
'LINK' => append_sid("{$phpbb_root_path}download/file.$phpEx", $params),
'TYPE' => $type,
);
}
return $links;
}
/**
* Prepare profile data
*/

View File

@ -717,27 +717,6 @@ function phpbb_download_check_pm_auth($db, $user_id, $msg_id)
return $allowed;
}
/**
* Cleans a filename of any characters that could potentially cause a problem on
* a user's filesystem.
*
* @param string $filename The filename to clean
*
* @return string The cleaned filename
*/
function phpbb_download_clean_filename($filename)
{
$bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
// rawurlencode to convert any potentially 'bad' characters that we missed
$filename = rawurlencode(str_replace($bad_chars, '_', $filename));
// Turn the %xx entities created by rawurlencode to _
$filename = preg_replace("/%(\w{2})/", '_', $filename);
return $filename;
}
/**
* Check if the browser is internet explorer version 7+
*

View File

@ -250,7 +250,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
'U_PM_ACTION' => $url . '&amp;mode=compose&amp;f=' . $folder_id . '&amp;p=' . $message_row['msg_id'],
'S_HAS_ATTACHMENTS' => (sizeof($attachments)) ? true : false,
'S_HAS_MULTIPLE_ATTACHMENTS' => (sizeof($attachments) > 1),
'S_DISPLAY_NOTICE' => $display_notice && $message_row['message_attachment'],
'S_AUTHOR_DELETED' => ($author_id == ANONYMOUS) ? true : false,
'S_SPECIAL_FOLDER' => in_array($folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)),
@ -339,12 +338,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
// Display not already displayed Attachments for this post, we already parsed them. ;)
if (isset($attachments) && sizeof($attachments))
{
$methods = phpbb_gen_download_links('msg_id', $msg_id, $phpbb_root_path, $phpEx);
foreach ($methods as $method)
{
$template->assign_block_vars('dl_method', $method);
}
foreach ($attachments as $attachment)
{
$template->assign_block_vars('attachment', array(

View File

@ -191,8 +191,6 @@ $lang = array_merge($lang, array(
'DISPLAY_MESSAGES' => 'Display messages from previous',
'DISPLAY_POSTS' => 'Display posts from previous',
'DISPLAY_TOPICS' => 'Display topics from previous',
'DOWNLOAD_ALL' => 'Download all',
'DOWNLOAD_ALL_ATTACHMENTS' => 'Download all attachments',
'DOWNLOADED' => 'Downloaded',
'DOWNLOADING_FILE' => 'Downloading file',
'DOWNLOAD_COUNTS' => array(

View File

@ -113,16 +113,6 @@
<dl class="attachbox">
<dt>
{L_ATTACHMENTS}
<!-- IF S_HAS_MULTIPLE_ATTACHMENTS -->
<div class="dl_links">
<strong>{L_DOWNLOAD_ALL}{L_COLON}</strong>
<ul>
<!-- BEGIN dl_method -->
<li>[ <a href="{dl_method.LINK}">{dl_method.TYPE}</a> ]</li>
<!-- END dl_method -->
</ul>
</div>
<!-- ENDIF -->
</dt>
<!-- BEGIN attachment -->
<dd>{attachment.DISPLAY_ATTACHMENT}</dd>

View File

@ -278,16 +278,6 @@
<dl class="attachbox">
<dt>
{L_ATTACHMENTS}
<!-- IF postrow.S_MULTIPLE_ATTACHMENTS -->
<div class="dl_links">
<strong>{L_DOWNLOAD_ALL}{L_COLON}</strong>
<ul>
<!-- BEGIN dl_method -->
<li>[ <a href="{postrow.dl_method.LINK}">{postrow.dl_method.TYPE}</a> ]</li>
<!-- END dl_method -->
</ul>
</div>
<!-- ENDIF -->
</dt>
<!-- BEGIN attachment -->
<dd>{postrow.attachment.DISPLAY_ATTACHMENT}</dd>

View File

@ -18,18 +18,6 @@
<!-- IF U_BUMP_TOPIC --><li class="small-icon icon-bump"><a href="{U_BUMP_TOPIC}" title="{L_BUMP_TOPIC}" data-ajax="true">{L_BUMP_TOPIC}</a></li><!-- ENDIF -->
<!-- IF U_EMAIL_TOPIC --><li class="small-icon icon-sendemail"><a href="{U_EMAIL_TOPIC}" title="{L_EMAIL_TOPIC}">{L_EMAIL_TOPIC}</a></li><!-- ENDIF -->
<!-- IF U_PRINT_TOPIC --><li class="small-icon icon-print"><a href="{U_PRINT_TOPIC}" title="{L_PRINT_TOPIC}" accesskey="p">{L_PRINT_TOPIC}</a></li><!-- ENDIF -->
<!-- IF S_HAS_ATTACHMENTS -->
<li class="small-icon icon-download">
<a class="dropdown-toggle-submenu" href="{U_DOWNLOAD_ALL_ATTACHMENTS}" title="{L_DOWNLOAD_ALL_ATTACHMENTS}">{L_DOWNLOAD_ALL_ATTACHMENTS}</a>
<ul class="dropdown-submenu hidden">
<li>
<!-- BEGIN dl_method -->
<a href="{dl_method.LINK}">{dl_method.TYPE}</a><!-- IF not dl_method.S_LAST_ROW --> &bull; <!-- ENDIF -->
<!-- END dl_method -->
</li>
</ul>
</li>
<!-- ENDIF -->
<!-- EVENT viewtopic_topic_tools_after -->
</ul>
</div>

View File

@ -1392,17 +1392,6 @@ if (sizeof($attach_list))
}
}
$methods = phpbb_gen_download_links('topic_id', $topic_id, $phpbb_root_path, $phpEx);
foreach ($methods as $method)
{
$template->assign_block_vars('dl_method', $method);
}
$template->assign_vars(array(
'S_HAS_ATTACHMENTS' => $topic_data['topic_attachment'],
'U_DOWNLOAD_ALL_ATTACHMENTS' => $methods[0]['LINK'],
));
// Instantiate BBCode if need be
if ($bbcode_bitfield !== '')
{
@ -1420,6 +1409,7 @@ $i_total = sizeof($rowset) - 1;
$prev_post_id = '';
$template->assign_vars(array(
'S_HAS_ATTACHMENTS' => $topic_data['topic_attachment'],
'S_NUM_POSTS' => sizeof($post_list))
);
@ -1918,12 +1908,6 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
'DISPLAY_ATTACHMENT' => $attachment)
);
}
$methods = phpbb_gen_download_links('post_id', $row['post_id'], $phpbb_root_path, $phpEx);
foreach ($methods as $method)
{
$template->assign_block_vars('postrow.dl_method', $method);
}
}
$current_row_number = $i;

View File

@ -80,20 +80,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case
'attachments' => true,
));
// Download topic archive as guest
$crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false);
self::assert_response_status_code(200);
$content = self::$client->getResponse()->getContent();
$finfo = new finfo(FILEINFO_MIME_TYPE);
self::assertEquals('application/zip', $finfo->buffer($content));
// Download post archive as guest
$crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false);
self::assert_response_status_code(200);
$content = self::$client->getResponse()->getContent();
$finfo = new finfo(FILEINFO_MIME_TYPE);
self::assertEquals('application/zip', $finfo->buffer($content));
// Download attachment as guest
$crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
self::assert_response_status_code(200);
@ -147,18 +133,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case
));
$this->add_lang('viewtopic');
// Download topic archive as guest: still works
$crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false);
self::assert_response_status_code(200);
$content = self::$client->getResponse()->getContent();
$finfo = new finfo(FILEINFO_MIME_TYPE);
self::assertEquals('application/zip', $finfo->buffer($content));
// No download post archive as guest
$crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false);
self::assert_response_html(404);
$this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text());
// No download attachment as guest
$crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
self::assert_response_html(404);
@ -167,20 +141,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case
// Login as admin and try again, should work now.
$this->login();
// Download topic archive as admin
$crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false);
self::assert_response_status_code(200);
$content = self::$client->getResponse()->getContent();
$finfo = new finfo(FILEINFO_MIME_TYPE);
self::assertEquals('application/zip', $finfo->buffer($content));
// Download post archive as admin
$crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false);
self::assert_response_status_code(200);
$content = self::$client->getResponse()->getContent();
$finfo = new finfo(FILEINFO_MIME_TYPE);
self::assertEquals('application/zip', $finfo->buffer($content));
// Download attachment as admin
$crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
self::assert_response_status_code(200);
@ -235,16 +195,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case
));
$this->add_lang('viewtopic');
// Download topic archive as guest: still works
$crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false);
self::assert_response_html(404);
$this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text());
// No download post archive as guest
$crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false);
self::assert_response_html(404);
$this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text());
// No download attachment as guest
$crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
self::assert_response_html(404);
@ -253,20 +203,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case
// Login as admin and try again, should work now.
$this->login();
// Download topic archive as admin
$crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false);
self::assert_response_status_code(200);
$content = self::$client->getResponse()->getContent();
$finfo = new finfo(FILEINFO_MIME_TYPE);
self::assertEquals('application/zip', $finfo->buffer($content));
// Download post archive as admin
$crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false);
self::assert_response_status_code(200);
$content = self::$client->getResponse()->getContent();
$finfo = new finfo(FILEINFO_MIME_TYPE);
self::assertEquals('application/zip', $finfo->buffer($content));
// Download attachment as admin
$crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
self::assert_response_status_code(200);