source: extensions/Comments_on_Albums/include/functions.inc.php @ 15907

Last change on this file since 15907 was 9624, checked in by mistic100, 13 years ago

[plugins] Comments on Albums

File size: 1.7 KB
Line 
1<?php
2/* This is from include/functions.inc.php but adapted for Comments On Albums */
3
4/**
5 * return an array which will be sent to template to display navigation bar
6 */
7function create_comment_navigation_bar($url, $nb_element, $start, $nb_element_page)
8{
9  global $conf;
10
11  $navbar = array();
12  $pages_around = $conf['paginate_pages_around'];
13  $start_str = (strpos($url, '?')===false ? '?':'&amp;').'start_comments=';
14
15  if (!isset($start) or !is_numeric($start) or (is_numeric($start) and $start < 0))
16  {
17    $start = 0;
18  }
19
20  // navigation bar useful only if more than one page to display !
21  if ($nb_element > $nb_element_page)
22  {
23    $cur_page = ceil($start / $nb_element_page) + 1;
24    $maximum = ceil($nb_element / $nb_element_page);
25    $previous = $start - $nb_element_page;
26    $next = $start + $nb_element_page;
27    $last = ($maximum - 1) * $nb_element_page;
28
29    $navbar['CURRENT_PAGE'] = $cur_page;
30
31    // link to first page and previous page?
32    if ($cur_page != 1)
33    {
34      $navbar['URL_FIRST'] = $url;
35      $navbar['URL_PREV'] = $url.($previous > 0 ? $start_str.$previous : '');
36    }
37    // link on next page and last page?
38    if ($cur_page != $maximum)
39    {
40      $navbar['URL_NEXT'] = $url.$start_str.$next;
41      $navbar['URL_LAST'] = $url.$start_str.$last;
42    }
43
44    // pages to display
45    $navbar['pages'] = array();
46    $navbar['pages'][1] = $url;
47    $navbar['pages'][$maximum] = $url.$start_str.$last;
48
49    for ($i = max($cur_page - $pages_around , 2), $stop = min($cur_page + $pages_around + 1, $maximum);
50         $i < $stop; $i++)
51    {
52      $navbar['pages'][$i] = $url.$start_str.(($i - 1) * $nb_element_page);
53    }
54    ksort($navbar['pages']);
55  }
56  return $navbar;
57}
58
59?>
Note: See TracBrowser for help on using the repository browser.