mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-12 06:18:52 +00:00
Merge pull request #4190 from marc1706/ticket/14437
[ticket/14437] Correctly assume index from attachment display order * marc1706/ticket/14437: [ticket/14437] Make sure attachments array is properly ordered before processing [ticket/14437] Preserve attachment ID order by ordering by attach_id [ticket/14437] Sort attachments after assigning inline attachments [ticket/14437] Correctly assume index from attachment display order
This commit is contained in:
commit
7f9ba9849b
3 changed files with 17 additions and 17 deletions
|
@ -1036,17 +1036,8 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count,
|
||||||
unset($new_attachment_data);
|
unset($new_attachment_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort correctly
|
// Make sure attachments are properly ordered
|
||||||
if ($config['display_order'])
|
|
||||||
{
|
|
||||||
// Ascending sort
|
|
||||||
krsort($attachments);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Descending sort
|
|
||||||
ksort($attachments);
|
ksort($attachments);
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($attachments as $attachment)
|
foreach ($attachments as $attachment)
|
||||||
{
|
{
|
||||||
|
@ -1285,8 +1276,6 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count,
|
||||||
$attachments = $compiled_attachments;
|
$attachments = $compiled_attachments;
|
||||||
unset($compiled_attachments);
|
unset($compiled_attachments);
|
||||||
|
|
||||||
$tpl_size = sizeof($attachments);
|
|
||||||
|
|
||||||
$unset_tpl = array();
|
$unset_tpl = array();
|
||||||
|
|
||||||
preg_match_all('#<!\-\- ia([0-9]+) \-\->(.*?)<!\-\- ia\1 \-\->#', $message, $matches, PREG_PATTERN_ORDER);
|
preg_match_all('#<!\-\- ia([0-9]+) \-\->(.*?)<!\-\- ia\1 \-\->#', $message, $matches, PREG_PATTERN_ORDER);
|
||||||
|
@ -1294,8 +1283,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count,
|
||||||
$replace = array();
|
$replace = array();
|
||||||
foreach ($matches[0] as $num => $capture)
|
foreach ($matches[0] as $num => $capture)
|
||||||
{
|
{
|
||||||
// Flip index if we are displaying the reverse way
|
$index = $matches[1][$num];
|
||||||
$index = ($config['display_order']) ? ($tpl_size-($matches[1][$num] + 1)) : $matches[1][$num];
|
|
||||||
|
|
||||||
$replace['from'][] = $matches[0][$num];
|
$replace['from'][] = $matches[0][$num];
|
||||||
$replace['to'][] = (isset($attachments[$index])) ? $attachments[$index] : sprintf($user->lang['MISSING_INLINE_ATTACHMENT'], $matches[2][array_search($index, $matches[1])]);
|
$replace['to'][] = (isset($attachments[$index])) ? $attachments[$index] : sprintf($user->lang['MISSING_INLINE_ATTACHMENT'], $matches[2][array_search($index, $matches[1])]);
|
||||||
|
@ -1310,6 +1298,18 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count,
|
||||||
|
|
||||||
$unset_tpl = array_unique($unset_tpl);
|
$unset_tpl = array_unique($unset_tpl);
|
||||||
|
|
||||||
|
// Sort correctly
|
||||||
|
if ($config['display_order'])
|
||||||
|
{
|
||||||
|
// Ascending sort
|
||||||
|
krsort($attachments);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Descending sort
|
||||||
|
ksort($attachments);
|
||||||
|
}
|
||||||
|
|
||||||
// Needed to let not display the inlined attachments at the end of the post again
|
// Needed to let not display the inlined attachments at the end of the post again
|
||||||
foreach ($unset_tpl as $index)
|
foreach ($unset_tpl as $index)
|
||||||
{
|
{
|
||||||
|
|
|
@ -599,7 +599,7 @@ if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode
|
||||||
WHERE post_msg_id = $post_id
|
WHERE post_msg_id = $post_id
|
||||||
AND in_message = 0
|
AND in_message = 0
|
||||||
AND is_orphan = 0
|
AND is_orphan = 0
|
||||||
ORDER BY filetime DESC";
|
ORDER BY attach_id DESC";
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
$message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
|
$message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
|
|
|
@ -1479,7 +1479,7 @@ if (sizeof($attach_list))
|
||||||
FROM ' . ATTACHMENTS_TABLE . '
|
FROM ' . ATTACHMENTS_TABLE . '
|
||||||
WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
|
WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
|
||||||
AND in_message = 0
|
AND in_message = 0
|
||||||
ORDER BY filetime DESC, post_msg_id ASC';
|
ORDER BY attach_id DESC, post_msg_id ASC';
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
|
Loading…
Add table
Reference in a new issue