From c5c2f7f7d0f85c8a95271a5abeed0cc4a2bf2678 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 21 Feb 2016 14:10:45 +0100 Subject: [PATCH 1/4] [ticket/14437] Correctly assume index from attachment display order PHPBB3-14437 --- phpBB/includes/functions_content.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 6f861b8607..fe4e977ff2 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -975,7 +975,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, } // Sort correctly - if ($config['display_order']) + if (!$config['display_order']) { // Ascending sort krsort($attachments); @@ -1233,7 +1233,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, foreach ($matches[0] as $num => $capture) { // Flip index if we are displaying the reverse way - $index = ($config['display_order']) ? ($tpl_size-($matches[1][$num] + 1)) : $matches[1][$num]; + $index = (!$config['display_order']) ? ($tpl_size-($matches[1][$num] + 1)) : $matches[1][$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])]); From 1e10664739c2eb212c583ae2fbcdd62fc3d46984 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 6 Mar 2016 00:14:47 +0100 Subject: [PATCH 2/4] [ticket/14437] Sort attachments after assigning inline attachments This does not seem to cause any issues but prevents us from having to consider the currenty display order. PHPBB3-14437 --- phpBB/includes/functions_content.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index fe4e977ff2..725707f7dc 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -974,18 +974,6 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, unset($new_attachment_data); } - // Sort correctly - if (!$config['display_order']) - { - // Ascending sort - krsort($attachments); - } - else - { - // Descending sort - ksort($attachments); - } - foreach ($attachments as $attachment) { if (!sizeof($attachment)) @@ -1233,7 +1221,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, foreach ($matches[0] as $num => $capture) { // Flip index if we are displaying the reverse way - $index = (!$config['display_order']) ? ($tpl_size-($matches[1][$num] + 1)) : $matches[1][$num]; + $index = $tpl_size-($matches[1][$num] + 1); $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])]); @@ -1248,6 +1236,18 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, $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 foreach ($unset_tpl as $index) { From f1772ce7e5b2d75ced8379b5ed8a644af248532f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 6 Mar 2016 10:40:42 +0100 Subject: [PATCH 3/4] [ticket/14437] Preserve attachment ID order by ordering by attach_id PHPBB3-14437 --- phpBB/viewtopic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index fcc44abc33..c0041b0993 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1452,7 +1452,7 @@ if (sizeof($attach_list)) FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . ' 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); while ($row = $db->sql_fetchrow($result)) From 3d7d0c40b8e7f1897fc4a323d4edee6db2a7f452 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 6 Mar 2016 11:22:05 +0100 Subject: [PATCH 4/4] [ticket/14437] Make sure attachments array is properly ordered before processing PHPBB3-14437 --- phpBB/includes/functions_content.php | 8 ++++---- phpBB/posting.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 725707f7dc..ac3a35f8c9 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -974,6 +974,9 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, unset($new_attachment_data); } + // Make sure attachments are properly ordered + ksort($attachments); + foreach ($attachments as $attachment) { if (!sizeof($attachment)) @@ -1211,8 +1214,6 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, $attachments = $compiled_attachments; unset($compiled_attachments); - $tpl_size = sizeof($attachments); - $unset_tpl = array(); preg_match_all('#(.*?)#', $message, $matches, PREG_PATTERN_ORDER); @@ -1220,8 +1221,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, $replace = array(); foreach ($matches[0] as $num => $capture) { - // Flip index if we are displaying the reverse way - $index = $tpl_size-($matches[1][$num] + 1); + $index = $matches[1][$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])]); diff --git a/phpBB/posting.php b/phpBB/posting.php index a7df1a018e..263809e998 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -599,7 +599,7 @@ if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode WHERE post_msg_id = $post_id AND in_message = 0 AND is_orphan = 0 - ORDER BY filetime DESC"; + ORDER BY attach_id DESC"; $result = $db->sql_query($sql); $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result)); $db->sql_freeresult($result);