Follow-up to #2994
[kohana-pagination.git] / views / pagination / floating.php
blob4d34564c9df94145ac5c9c79ebbb112765b02c6a
1 <?php
2 /*
3 First Previous 1 2 3 ... 22 23 24 25 26 [27] 28 29 30 31 32 ... 48 49 50 Next Last
4 */
6 // Number of page links in the begin and end of whole range
7 $count_out = ( ! empty($config['count_out'])) ? (int) $config['count_out'] : 3;
8 // Number of page links on each side of current page
9 $count_in = ( ! empty($config['count_in'])) ? (int) $config['count_in'] : 5;
11 // Beginning group of pages: $n1...$n2
12 $n1 = 1;
13 $n2 = min($count_out, $total_pages);
15 // Ending group of pages: $n7...$n8
16 $n7 = max(1, $total_pages - $count_out + 1);
17 $n8 = $total_pages;
19 // Middle group of pages: $n4...$n5
20 $n4 = max($n2 + 1, $current_page - $count_in);
21 $n5 = min($n7 - 1, $current_page + $count_in);
22 $use_middle = ($n5 >= $n4);
24 // Point $n3 between $n2 and $n4
25 $n3 = (int) (($n2 + $n4) / 2);
26 $use_n3 = ($use_middle && (($n4 - $n2) > 1));
28 // Point $n6 between $n5 and $n7
29 $n6 = (int) (($n5 + $n7) / 2);
30 $use_n6 = ($use_middle && (($n7 - $n5) > 1));
32 // Links to display as array(page => content)
33 $links = array();
35 // Generate links data in accordance with calculated numbers
36 for ($i = $n1; $i <= $n2; $i++)
38 $links[$i] = $i;
40 if ($use_n3)
42 $links[$n3] = '&hellip;';
44 for ($i = $n4; $i <= $n5; $i++)
46 $links[$i] = $i;
48 if ($use_n6)
50 $links[$n6] = '&hellip;';
52 for ($i = $n7; $i <= $n8; $i++)
54 $links[$i] = $i;
58 <p class="pagination">
60 <?php if ($first_page !== FALSE): ?>
61 <a href="<?php echo $page->url($first_page) ?>" rel="first"><?php echo __('First') ?></a>
62 <?php else: ?>
63 <?php echo __('First') ?>
64 <?php endif ?>
66 <?php if ($previous_page !== FALSE): ?>
67 <a href="<?php echo $page->url($previous_page) ?>" rel="prev"><?php echo __('Previous') ?></a>
68 <?php else: ?>
69 <?php echo __('Previous') ?>
70 <?php endif ?>
72 <?php foreach ($links as $number => $content): ?>
74 <?php if ($number === $current_page): ?>
75 <strong><?php echo $content ?></strong>
76 <?php else: ?>
77 <a href="<?php echo $page->url($number) ?>"><?php echo $content ?></a>
78 <?php endif ?>
80 <?php endforeach ?>
82 <?php if ($next_page !== FALSE): ?>
83 <a href="<?php echo $page->url($next_page) ?>" rel="next"><?php echo __('Next') ?></a>
84 <?php else: ?>
85 <?php echo __('Next') ?>
86 <?php endif ?>
88 <?php if ($last_page !== FALSE): ?>
89 <a href="<?php echo $page->url($last_page) ?>" rel="last"><?php echo __('Last') ?></a>
90 <?php else: ?>
91 <?php echo __('Last') ?>
92 <?php endif ?>
94 </p><!-- .pagination -->