From bd2fde5c8c395f090f9c18e8c1976e58d4a7591a Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 13 Dec 2004 22:54:44 +0000 Subject: - refresh paginated navigation bar : displays First and Last, displays Previous and Next even if non applicable (but no link), displays only page umbers around the current page (if a category contains hundreds of elements, no more long list of pages) git-svn-id: http://piwigo.org/svn/trunk@643 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/config.inc.php | 4 ++ include/functions_html.inc.php | 114 ++++++++++++++++++++++++------ language/en_UK.iso-8859-1/common.lang.php | 2 + 3 files changed, 97 insertions(+), 23 deletions(-) diff --git a/include/config.inc.php b/include/config.inc.php index 9b6a552ee..e5926578d 100644 --- a/include/config.inc.php +++ b/include/config.inc.php @@ -189,4 +189,8 @@ $conf['newcat_default_status'] = 'public'; // level_separator : character string used for separating a category level // to the sub level $conf['level_separator'] = ' / '; + +// paginate_pages_around : on paginate navigation bar, on many pages display +// before and after the current page ? +$conf['paginate_pages_around'] = 2; ?> diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index 2ff918ae4..b175a8be1 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -54,22 +54,44 @@ function get_icon( $date ) return $output; } -function create_navigation_bar( $url, $nb_element, $start, - $nb_element_page, $link_class ) +function create_navigation_bar($url, $nb_element, $start, + $nb_element_page, $link_class) { - global $lang; - $navigation_bar = ""; - // 0. détection de la page en cours - if( !isset( $start ) - || !is_numeric( $start ) - || ( is_numeric( $start ) && $start < 0 ) ) + global $lang, $conf; + + $pages_around = $conf['paginate_pages_around']; + + $navigation_bar = ''; + + // current page detection + if (!isset($start) + or !is_numeric($start) + or (is_numeric($start) and $start < 0)) { $start = 0; } - // on n'affiche la bare de navigation que si on plus de 1 page - if ( $nb_element > $nb_element_page ) + + // navigation bar useful only if more than one page to display ! + if ($nb_element > $nb_element_page) { - // 1.une page précédente ? + // searching the current page + $cur_page = ceil($start / $nb_element_page) + 1; + $maximum = ceil($nb_element / $nb_element_page); + + // link to first page ? + if ($cur_page != 1) + { + $navigation_bar.= ''.$lang['first_page']; + $navigation_bar.= ''; + } + else + { + $navigation_bar.= $lang['first_page']; + } + $navigation_bar.= ' | '; + // link on previous page ? if ( $start != 0 ) { $previous = $start - $nb_element_page; @@ -77,33 +99,79 @@ function create_navigation_bar( $url, $nb_element, $start, $navigation_bar.= add_session_id( $url.'&start='.$previous ); $navigation_bar.= '" class="'.$link_class.'">'.$lang['previous_page']; $navigation_bar.= ''; - $navigation_bar.= ' | '; } - // 2.liste des numéros de page - $maximum = ceil ( $nb_element / $nb_element_page ); - for ( $i = 1; $i <= $maximum; $i++ ) + else + { + $navigation_bar.= $lang['previous_page']; + } + $navigation_bar.= ' | '; + + if ($cur_page > $pages_around + 1) + { + $navigation_bar.= ' 1 ...'; + } + + // inspired from punbb source code + for ($i = $cur_page - $pages_around, $stop = $cur_page + $pages_around + 1; + $i < $stop; + $i++) { - $temp_start = ( $i - 1 ) * $nb_element_page; - if ( $temp_start == $start ) + if ($i < 1 or $i > $maximum) + { + continue; + } + else if ($i != $cur_page) { - $navigation_bar.= ' '.$i.' '; + $temp_start = ($i - 1) * $nb_element_page; + $navigation_bar.= ' '.$i.''; } else { - $navigation_bar.= ' '.$i.' '; + $navigation_bar.= ' '; + $navigation_bar.= $i.''; } } - // 3.une page suivante ? + + if ($cur_page < ($maximum - $pages_around)) + { + $temp_start = ($maximum - 1) * $nb_element_page; + $navigation_bar.= ' ... '.$maximum.''; + } + + $navigation_bar.= ' | '; + // link on next page ? if ( $nb_element > $nb_element_page && $start + $nb_element_page < $nb_element ) { $next = $start + $nb_element_page; - $navigation_bar.= ' | '.$lang['next_page'].''; } + else + { + $navigation_bar.= $lang['next_page']; + } + // link to last page ? + if ($cur_page != $maximum) + { + $temp_start = ($maximum - 1) * $nb_element_page; + $navigation_bar.= ' | '; + $navigation_bar.= ''.$lang['last_page']; + $navigation_bar.= ''; + } + else + { + $navigation_bar.= $lang['last_page']; + } } return $navigation_bar; } diff --git a/language/en_UK.iso-8859-1/common.lang.php b/language/en_UK.iso-8859-1/common.lang.php index 606248234..a835f5099 100644 --- a/language/en_UK.iso-8859-1/common.lang.php +++ b/language/en_UK.iso-8859-1/common.lang.php @@ -204,6 +204,8 @@ $lang['no_category'] = 'Home'; $lang['page_number'] = 'page number'; $lang['previous_page'] = 'Previous'; $lang['next_page'] = 'Next'; +$lang['first_page'] = 'First'; +$lang['last_page'] = 'Last'; $lang['recent_image'] = 'Image within the'; $lang['days'] = 'days'; -- cgit v1.2.3