aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2004-12-13 22:54:44 +0000
committerplegall <plg@piwigo.org>2004-12-13 22:54:44 +0000
commitbd2fde5c8c395f090f9c18e8c1976e58d4a7591a (patch)
treea5a671d32ac19f03d1c5602037039ff54c434b0d /include
parent391fac78a80c9317e764a13d742c88d8fe0866fc (diff)
- 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
Diffstat (limited to 'include')
-rw-r--r--include/config.inc.php4
-rw-r--r--include/functions_html.inc.php114
2 files changed, 95 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.= '<a href="';
+ $navigation_bar.= add_session_id($url.'&amp;start=0');
+ $navigation_bar.= '" class="'.$link_class.'">'.$lang['first_page'];
+ $navigation_bar.= '</a>';
+ }
+ 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.'&amp;start='.$previous );
$navigation_bar.= '" class="'.$link_class.'">'.$lang['previous_page'];
$navigation_bar.= '</a>';
- $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.= '&nbsp;<a href="';
+ $navigation_bar.= add_session_id($url.'&amp;start=0');
+ $navigation_bar.= '" class="'.$link_class.'">1</a>&nbsp;...';
+ }
+
+ // 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.= ' <span class="pageNumberSelected">'.$i.'</span> ';
+ $temp_start = ($i - 1) * $nb_element_page;
+ $navigation_bar.= '&nbsp;<a href="';
+ $navigation_bar.= add_session_id($url.'&amp;start='.$temp_start);
+ $navigation_bar.= '" class="'.$link_class.'">'.$i.'</a>';
}
else
{
- $navigation_bar.= ' <a href="';
- $navigation_bar.= add_session_id( $url.'&amp;start='.$temp_start );
- $navigation_bar.= '" class="'.$link_class.'">'.$i.'</a> ';
+ $navigation_bar.= '&nbsp;<span class="pageNumberSelected">';
+ $navigation_bar.= $i.'</span>';
}
}
- // 3.une page suivante ?
+
+ if ($cur_page < ($maximum - $pages_around))
+ {
+ $temp_start = ($maximum - 1) * $nb_element_page;
+ $navigation_bar.= '&nbsp;...&nbsp;<a href="';
+ $navigation_bar.= add_session_id($url.'&amp;start='.$temp_start);
+ $navigation_bar.= '" class="'.$link_class.'">'.$maximum.'</a>';
+ }
+
+ $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.= ' | <a href="';
+ $navigation_bar.= '<a href="';
$navigation_bar.= add_session_id( $url.'&amp;start='.$next );
$navigation_bar.= '" class="'.$link_class.'">'.$lang['next_page'].'</a>';
}
+ 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.= '<a href="';
+ $navigation_bar.= add_session_id($url.'&amp;start='.$temp_start);
+ $navigation_bar.= '" class="'.$link_class.'">'.$lang['last_page'];
+ $navigation_bar.= '</a>';
+ }
+ else
+ {
+ $navigation_bar.= $lang['last_page'];
+ }
}
return $navigation_bar;
}