Ignore:
Timestamp:
Mar 6, 2009, 2:06:18 AM (16 years ago)
Author:
patdenice
Message:

Code simplification of commit 3172

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions.inc.php

    r3172 r3173  
    15021502  global $conf;
    15031503
     1504  $navbar = array();
    15041505  $pages_around = $conf['paginate_pages_around'];
    15051506  $start_str = $clean_url ? '/start-' : (strpos($url, '?')===false ? '?':'&').'start=';
     
    15101511  }
    15111512
    1512   $navbar = array();
    1513 
    15141513  // navigation bar useful only if more than one page to display !
    15151514  if ($nb_element > $nb_element_page)
    15161515  {
    1517     // current page and last page
    15181516    $cur_page = ceil($start / $nb_element_page) + 1;
    15191517    $maximum = ceil($nb_element / $nb_element_page);
     1518    $previous = $start - $nb_element_page;
     1519    $next = $start + $nb_element_page;
     1520    $last = ($maximum - 1) * $nb_element_page;
    15201521
    15211522    $navbar['CURRENT_PAGE'] = $cur_page;
    15221523
    1523     // link to first page ?
     1524    // link to first page and previous page?
    15241525    if ($cur_page != 1)
    15251526    {
    15261527      $navbar['URL_FIRST'] = $url;
    1527     }
    1528     // link on previous page ?
    1529     if ($start != 0)
    1530     {
    1531       $previous = $start - $nb_element_page;
    15321528      $navbar['URL_PREV'] = $url.($previous > 0 ? $start_str.$previous : '');
    15331529    }
    1534     // link on next page ?
    1535     if ($nb_element > $nb_element_page and $start + $nb_element_page < $nb_element)
    1536     {
    1537       $next = $start + $nb_element_page;
     1530    // link on next page and last page?
     1531    if ($cur_page != $maximum)
     1532    {
    15381533      $navbar['URL_NEXT'] = $url.$start_str.$next;
    1539     }
    1540     // link to last page ?
    1541     if ($cur_page != $maximum)
    1542     {
    1543       $temp_start = ($maximum - 1) * $nb_element_page;
    1544       $navbar['URL_LAST'] = $url.$start_str.$temp_start;
     1534      $navbar['URL_LAST'] = $url.$start_str.$last;
    15451535    }
    15461536
    15471537    // pages to display
    15481538    $navbar['pages'] = array();
    1549 
    15501539    $navbar['pages'][1] = $url;
    1551     $navbar['pages'][$maximum] = $url.$start_str. ($maximum - 1) * $nb_element_page;
    1552 
    1553     for ($i = $cur_page - $pages_around, $stop = $cur_page + $pages_around + 1; $i < $stop; $i++)
    1554     {
    1555       if ($i < 2 or $i > $maximum - 1)
    1556       {
    1557         continue;
    1558       }
    1559       $navbar['pages'][$i] = $url.$start_str. ($i - 1) * $nb_element_page;
     1540    $navbar['pages'][$maximum] = $url.$start_str.$last;
     1541
     1542    for ($i = max($cur_page - $pages_around , 2), $stop = min($cur_page + $pages_around + 1, $maximum);
     1543         $i < $stop; $i++)
     1544    {
     1545      $navbar['pages'][$i] = $url.$start_str.(($i - 1) * $nb_element_page);
    15601546    }
    15611547    ksort($navbar['pages']);
Note: See TracChangeset for help on using the changeset viewer.