aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/functions.inc.php')
-rw-r--r--include/functions.inc.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 83c9980de..3f43b943a 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -1493,4 +1493,73 @@ function get_comment_post_key($image_id)
)
);
}
+
+/**
+ * return an array which will be sent to template to display navigation bar
+ */
+function create_navigation_bar($url, $nb_element, $start, $nb_element_page, $clean_url = false)
+{
+ global $conf;
+
+ $pages_around = $conf['paginate_pages_around'];
+ $start_str = $clean_url ? '/start-' : (strpos($url, '?')===false ? '?':'&').'start=';
+
+ if (!isset($start) or !is_numeric($start) or (is_numeric($start) and $start < 0))
+ {
+ $start = 0;
+ }
+
+ $navbar = array();
+
+ // navigation bar useful only if more than one page to display !
+ if ($nb_element > $nb_element_page)
+ {
+ // current page and last page
+ $cur_page = ceil($start / $nb_element_page) + 1;
+ $maximum = ceil($nb_element / $nb_element_page);
+
+ $navbar['CURRENT_PAGE'] = $cur_page;
+
+ // link to first page ?
+ if ($cur_page != 1)
+ {
+ $navbar['URL_FIRST'] = $url;
+ }
+ // link on previous page ?
+ if ($start != 0)
+ {
+ $previous = $start - $nb_element_page;
+ $navbar['URL_PREV'] = $url.($previous > 0 ? $start_str.$previous : '');
+ }
+ // link on next page ?
+ if ($nb_element > $nb_element_page and $start + $nb_element_page < $nb_element)
+ {
+ $next = $start + $nb_element_page;
+ $navbar['URL_NEXT'] = $url.$start_str.$next;
+ }
+ // link to last page ?
+ if ($cur_page != $maximum)
+ {
+ $temp_start = ($maximum - 1) * $nb_element_page;
+ $navbar['URL_LAST'] = $url.$start_str.$temp_start;
+ }
+
+ // pages to display
+ $navbar['pages'] = array();
+
+ $navbar['pages'][1] = $url;
+ $navbar['pages'][$maximum] = $url.$start_str. ($maximum - 1) * $nb_element_page;
+
+ for ($i = $cur_page - $pages_around, $stop = $cur_page + $pages_around + 1; $i < $stop; $i++)
+ {
+ if ($i < 2 or $i > $maximum - 1)
+ {
+ continue;
+ }
+ $navbar['pages'][$i] = $url.$start_str. ($i - 1) * $nb_element_page;
+ }
+ ksort($navbar['pages']);
+ }
+ return $navbar;
+}
?> \ No newline at end of file