Skip to content

Commit

Permalink
Merge pull request #751 from mmarcwabo/fix_search_term_is_lost_when_c…
Browse files Browse the repository at this point in the history
…hanging_pages

No more losing search term when changing page
  • Loading branch information
kroky authored Aug 29, 2023
2 parents 864929c + 277c7cf commit 06be076
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
18 changes: 12 additions & 6 deletions modules/core/message_list_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,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 = '';
Expand All @@ -569,6 +569,12 @@ function build_page_links($page_size, $current_page, $total, $path, $filter=fals
else {
$sort_str = '';
}
if ($keyword) {
$keyword_str = '&keyword='.$keyword;
}
else {
$keyword_str = '';
}

$max_pages = ceil($total/$page_size);
if ($max_pages == 1) {
Expand All @@ -586,16 +592,16 @@ function build_page_links($page_size, $current_page, $total, $path, $filter=fals
$next = '<a class="disabled_link"><img src="'.Hm_Image_Sources::$caret_right.'" alt="&rarr;" /></a>';

if ($floor > 1 ) {
$first = '<a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page=1'.$filter_str.$sort_str.'">1</a> ... ';
$first = '<a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page=1'.$keyword_str.$filter_str.$sort_str.'">1</a> ... ';
}
if ($ceil < $max_pages) {
$last = ' ... <a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.$max_pages.$filter_str.$sort_str.'">'.$max_pages.'</a>';
$last = ' ... <a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.$max_pages.$keyword_str.$filter_str.$sort_str.'">'.$max_pages.'</a>';
}
if ($current_page > 1) {
$prev = '<a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.($current_page - 1).$filter_str.$sort_str.'"><img src="'.Hm_Image_Sources::$caret_left.'" alt="&larr;" /></a>';
$prev = '<a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.($current_page - 1).$keyword_str.$filter_str.$sort_str.'"><img src="'.Hm_Image_Sources::$caret_left.'" alt="&larr;" /></a>';
}
if ($max_pages > 1 && $current_page < $max_pages) {
$next = '<a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.($current_page + 1).$filter_str.$sort_str.'"><img src="'.Hm_Image_Sources::$caret_right.'" alt="&rarr;" /></a>';
$next = '<a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.($current_page + 1).$keyword_str.$filter_str.$sort_str.'"><img src="'.Hm_Image_Sources::$caret_right.'" alt="&rarr;" /></a>';
}
for ($i=1;$i<=$max_pages;$i++) {
if ($i < $floor || $i > $ceil) {
Expand All @@ -605,7 +611,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&amp;list_path='.urlencode($path).'&amp;list_page='.$i.$filter_str.$sort_str.'">'.$i.'</a>';
$links .= 'href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.$i.$keyword_str.$filter_str.$sort_str.'">'.$i.'</a>';
}
return $prev.' '.$first.$links.$last.' '.$next;
}}
Expand Down
2 changes: 1 addition & 1 deletion modules/imap/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,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());
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/modules/core/message_list_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public function test_build_page_links() {
$this->assertEquals('<a href="?page=message_list&amp;list_path=%2F&amp;list_page=9"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%228%22%20height%3D%228%22%20viewBox%3D%220%200%208%208%22%3E%0A%20%20%3Cpath%20d%3D%22M6%200l-4%204%204%204v-8z%22%20%2F%3E%0A%3C%2Fsvg%3E" alt="&larr;" /></a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=1">1</a> ... <a href="?page=message_list&amp;list_path=%2F&amp;list_page=4">4</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=5">5</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=6">6</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=7">7</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=8">8</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=9">9</a> <a class="current_page" href="?page=message_list&amp;list_path=%2F&amp;list_page=10">10</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=11">11</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=12">12</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=13">13</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=14">14</a> ... <a href="?page=message_list&amp;list_path=%2F&amp;list_page=100">100</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=11"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%228%22%20height%3D%228%22%20viewBox%3D%220%200%208%208%22%3E%0A%20%20%3Cpath%20d%3D%22M2%200v8l4-4-4-4z%22%20%2F%3E%0A%3C%2Fsvg%3E" alt="&rarr;" /></a>', build_page_links(10, 10, 1000, '/'));
$this->assertEquals('', build_page_links(10, 1, 10, '/'));
$this->assertEquals('<a class="disabled_link"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%228%22%20height%3D%228%22%20viewBox%3D%220%200%208%208%22%3E%0A%20%20%3Cpath%20d%3D%22M6%200l-4%204%204%204v-8z%22%20%2F%3E%0A%3C%2Fsvg%3E" alt="&larr;" /></a> <a class="current_page" href="?page=message_list&amp;list_path=%2F&amp;list_page=1&amp;filter=1&amp;sort=1">1</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=2&amp;filter=1&amp;sort=1">2</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=3&amp;filter=1&amp;sort=1">3</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=4&amp;filter=1&amp;sort=1">4</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=5&amp;filter=1&amp;sort=1">5</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=6&amp;filter=1&amp;sort=1">6</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=7&amp;filter=1&amp;sort=1">7</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=8&amp;filter=1&amp;sort=1">8</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=9&amp;filter=1&amp;sort=1">9</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=10&amp;filter=1&amp;sort=1">10</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=2&amp;filter=1&amp;sort=1"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%228%22%20height%3D%228%22%20viewBox%3D%220%200%208%208%22%3E%0A%20%20%3Cpath%20d%3D%22M2%200v8l4-4-4-4z%22%20%2F%3E%0A%3C%2Fsvg%3E" alt="&rarr;" /></a>', build_page_links(10, 1, 100, '/', true, true));
$this->assertEquals('<a class="disabled_link"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%228%22%20height%3D%228%22%20viewBox%3D%220%200%208%208%22%3E%0A%20%20%3Cpath%20d%3D%22M6%200l-4%204%204%204v-8z%22%20%2F%3E%0A%3C%2Fsvg%3E" alt="&larr;" /></a> <a class="current_page" href="?page=message_list&amp;list_path=%2F&amp;list_page=1&amp;keyword=cypht&amp;filter=1&amp;sort=1">1</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=2&amp;keyword=cypht&amp;filter=1&amp;sort=1">2</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=3&amp;keyword=cypht&amp;filter=1&amp;sort=1">3</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=2&amp;keyword=cypht&amp;filter=1&amp;sort=1"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%228%22%20height%3D%228%22%20viewBox%3D%220%200%208%208%22%3E%0A%20%20%3Cpath%20d%3D%22M2%200v8l4-4-4-4z%22%20%2F%3E%0A%3C%2Fsvg%3E" alt="&rarr;" /></a>', build_page_links(10, 1, 30, '/', true, true, "cypht"));
}
}
?>

0 comments on commit 06be076

Please sign in to comment.