From f32f25c3d48d71c6b7499770b634ec3d1c0ac982 Mon Sep 17 00:00:00 2001 From: Marcellin Wabo Date: Fri, 25 Aug 2023 14:51:44 +0100 Subject: [PATCH 1/2] No more losing search term when changing page --- modules/core/message_list_functions.php | 18 ++++++++++++------ modules/imap/output_modules.php | 2 +- .../modules/core/message_list_functions.php | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/core/message_list_functions.php b/modules/core/message_list_functions.php index 24bf28df7c..2d4753c481 100644 --- a/modules/core/message_list_functions.php +++ b/modules/core/message_list_functions.php @@ -551,7 +551,7 @@ function search_field_selection($current, $output_mod) { * @return string */ if (!hm_exists('build_page_links')) { -function build_page_links($page_size, $current_page, $total, $path, $filter=false, $sort=false) { +function build_page_links($page_size, $current_page, $total, $path, $filter=false, $sort=false, $keyword=false) { $links = ''; $first = ''; $last = ''; @@ -568,6 +568,12 @@ function build_page_links($page_size, $current_page, $total, $path, $filter=fals else { $sort_str = ''; } + if ($keyword) { + $keyword_str = '&sort='.$keyword; + } + else { + $keyword_str = ''; + } $max_pages = ceil($total/$page_size); if ($max_pages == 1) { @@ -585,16 +591,16 @@ function build_page_links($page_size, $current_page, $total, $path, $filter=fals $next = '→'; if ($floor > 1 ) { - $first = '1 ... '; + $first = '1 ... '; } if ($ceil < $max_pages) { - $last = ' ... '.$max_pages.''; + $last = ' ... '.$max_pages.''; } if ($current_page > 1) { - $prev = '←'; + $prev = '←'; } if ($max_pages > 1 && $current_page < $max_pages) { - $next = '→'; + $next = '→'; } for ($i=1;$i<=$max_pages;$i++) { if ($i < $floor || $i > $ceil) { @@ -604,7 +610,7 @@ function build_page_links($page_size, $current_page, $total, $path, $filter=fals if ($i == $current_page) { $links .= 'class="current_page" '; } - $links .= 'href="?page=message_list&list_path='.urlencode($path).'&list_page='.$i.$filter_str.$sort_str.'">'.$i.''; + $links .= 'href="?page=message_list&list_path='.urlencode($path).'&list_page='.$i.$keyword_str.$filter_str.$sort_str.'">'.$i.''; } return $prev.' '.$first.$links.$last.' '.$next; }} diff --git a/modules/imap/output_modules.php b/modules/imap/output_modules.php index c679f16142..69a5225ef5 100644 --- a/modules/imap/output_modules.php +++ b/modules/imap/output_modules.php @@ -826,7 +826,7 @@ protected function output() { $page_num = ($details['offset']/$details['limit']) + 1; } $this->out('page_links', build_page_links($details['limit'], $page_num, $details['detail']['exists'], - $this->get('imap_mailbox_page_path'), $this->html_safe($this->get('list_filter')), $this->html_safe($this->get('list_sort')))); + $this->get('imap_mailbox_page_path'), $this->html_safe($this->get('list_filter')), $this->html_safe($this->get('list_sort')), $this->html_safe($this->get('list_keyword')))); } elseif (!$this->get('formatted_message_list')) { $this->out('formatted_message_list', array()); diff --git a/tests/phpunit/modules/core/message_list_functions.php b/tests/phpunit/modules/core/message_list_functions.php index 6d0b1e0e55..140d522ff2 100644 --- a/tests/phpunit/modules/core/message_list_functions.php +++ b/tests/phpunit/modules/core/message_list_functions.php @@ -174,6 +174,7 @@ public function test_build_page_links() { $this->assertEquals('← 1 ... 4 5 6 7 8 9 10 11 12 13 14 ... 100 →', build_page_links(10, 10, 1000, '/')); $this->assertEquals('', build_page_links(10, 1, 10, '/')); $this->assertEquals('← 1 2 3 4 5 6 7 8 9 10 →', build_page_links(10, 1, 100, '/', true, true)); + $this->assertEquals('← 1 2 3 →', build_page_links(10, 1, 30, '/', true, true, "cypht")); } } ?> From 277c7cfeb91f9210e4b43723a72c3eaaf563af0e Mon Sep 17 00:00:00 2001 From: Marcellin Wabo Date: Fri, 25 Aug 2023 20:29:47 +0100 Subject: [PATCH 2/2] Fix variable name: keyword instead of sort --- modules/core/message_list_functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/message_list_functions.php b/modules/core/message_list_functions.php index 2d4753c481..b748dca752 100644 --- a/modules/core/message_list_functions.php +++ b/modules/core/message_list_functions.php @@ -569,7 +569,7 @@ function build_page_links($page_size, $current_page, $total, $path, $filter=fals $sort_str = ''; } if ($keyword) { - $keyword_str = '&sort='.$keyword; + $keyword_str = '&keyword='.$keyword; } else { $keyword_str = '';