79 lines
2.5 KiB
PHP
79 lines
2.5 KiB
PHP
<?php
|
|
/*
|
|
First Previous 1 2 3 ... 22 23 24 25 26 [27] 28 29 30 31 32 ... 48 49 50 Next Last
|
|
*/
|
|
|
|
// Number of page links in the begin and end of whole range
|
|
$count_out = (! empty($config['count_out'])) ? (int)$config['count_out'] : 2;
|
|
// Number of page links on each side of current page
|
|
$count_in = (! empty($config['count_in'])) ? (int)$config['count_in'] : 2;
|
|
|
|
// Beginning group of pages: $n1...$n2
|
|
$n1 = 1;
|
|
$n2 = min($count_out,$page->total_pages());
|
|
|
|
// Ending group of pages: $n7...$n8
|
|
$n7 = max(1,$page->total_pages()-$count_out+1);
|
|
$n8 = $page->total_pages();
|
|
|
|
// Middle group of pages: $n4...$n5
|
|
$n4 = max($n2+1,$page->current_page()-$count_in);
|
|
$n5 = min($n7-1,$page->current_page()+$count_in);
|
|
$use_middle = ($n5 >= $n4);
|
|
|
|
// Point $n3 between $n2 and $n4
|
|
$n3 = (int)(($n2+$n4)/2);
|
|
$use_n3 = ($use_middle && (($n4-$n2)>1));
|
|
|
|
// Point $n6 between $n5 and $n7
|
|
$n6 = (int)(($n5+$n7)/2);
|
|
$use_n6 = ($use_middle && (($n7-$n5)>1));
|
|
|
|
// Links to display as array(page => content)
|
|
$links = array();
|
|
|
|
// Generate links data in accordance with calculated numbers
|
|
for ($i = $n1; $i <= $n2; $i++)
|
|
$links[$i] = $i;
|
|
|
|
if ($use_n3)
|
|
$links[$n3] = '…';
|
|
|
|
for ($i = $n4; $i <= $n5; $i++)
|
|
$links[$i] = $i;
|
|
|
|
if ($use_n6)
|
|
$links[$n6] = '…';
|
|
|
|
for ($i = $n7; $i <= $n8; $i++)
|
|
$links[$i] = $i;
|
|
?>
|
|
<nav>
|
|
<div class="text-center">
|
|
<ul class="pagination">
|
|
<li class="<?php echo $x=($page->first_page() !== FALSE) ? '' : 'disabled' ?>">
|
|
<a href="<?php echo $x ? '#' :HTML::chars($page->url($page->first_page())) ?>" rel="first"><?php echo __('First') ?></a>
|
|
</li>
|
|
|
|
<li class="<?php echo $x=($page->previous_page() !== FALSE) ? '' : 'disabled' ?>">
|
|
<a href="<?php echo $x ? '#' :HTML::chars($page->url($page->previous_page())) ?>" rel="prev"><?php echo __('Previous') ?></a>
|
|
</li>
|
|
|
|
<?php foreach ($links as $number => $content): ?>
|
|
<li class="<?php echo $x=($page->current_page() == $number) ? 'active disabled' : '' ?>">
|
|
<a href="<?php echo $x ? '#' : HTML::chars($page->url($number)) ?>"><?php echo $content ?></a>
|
|
</li>
|
|
<?php endforeach ?>
|
|
|
|
<li class="<?php echo $x=($page->next_page() !== FALSE) ? '' : 'disabled' ?>">
|
|
<a href="<?php echo $x ? '#' : HTML::chars($page->url($page->next_page())) ?>" rel="next"><?php echo __('Next') ?></a>
|
|
</li>
|
|
|
|
<li class="<?php echo $x=($page->last_page() !== FALSE) ? '' : 'disabled' ?>">
|
|
<a href="<?php echo $x ? '#' : HTML::chars($page->url($page->last_page())) ?>" rel="last"><?php echo __('Last') ?></a>
|
|
</li>
|
|
|
|
</ul>
|
|
</div>
|
|
</nav>
|