aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/config.inc.php4
-rw-r--r--include/functions_html.inc.php114
-rw-r--r--language/en_UK.iso-8859-1/common.lang.php2
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.= '<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;
}
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';