forked from onassar/PHP-Pagination
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.inc.php
128 lines (117 loc) · 3.81 KB
/
render.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
// total page count calculation
$pages = ((int) ceil($total / $rpp));
// if it's an invalid page request
if ($current < 1) {
return;
} elseif ($current > $pages) {
return;
}
// if there are pages to be shown
if ($pages > 1 || $alwaysShowPagination === true) {
?>
<ul class="<?= implode(' ', $classes) ?>">
<?php
/**
* Previous Link
*/
// anchor classes and target
$classes = array('copy', 'previous');
$params = $get;
$params[$key] = ($current - 1);
$href = ($target) . '?' . http_build_query($params);
$href = preg_replace(
array('/=$/', '/=&/'),
array('', '&'),
$href
);
if ($current === 1) {
$href = '#';
array_push($classes, 'disabled');
}
?>
<li class="<?= implode(' ', $classes) ?>"><a href="<?= ($href) ?>"><?= ($previous) ?></a></li>
<?php
/**
* if this isn't a clean output for pagination (eg. show numerical
* links)
*/
if (!$clean) {
/**
* Calculates the number of leading page crumbs based on the minimum
* and maximum possible leading pages.
*/
$max = min($pages, $crumbs);
$limit = ((int) floor($max / 2));
$leading = $limit;
for ($x = 0; $x < $limit; ++$x) {
if ($current === ($x + 1)) {
$leading = $x;
break;
}
}
for ($x = $pages - $limit; $x < $pages; ++$x) {
if ($current === ($x + 1)) {
$leading = $max - ($pages - $x);
break;
}
}
// calculate trailing crumb count based on inverse of leading
$trailing = $max - $leading - 1;
// generate/render leading crumbs
for ($x = 0; $x < $leading; ++$x) {
// class/href setup
$params = $get;
$params[$key] = ($current + $x - $leading);
$href = ($target) . '?' . http_build_query($params);
$href = preg_replace(
array('/=$/', '/=&/'),
array('', '&'),
$href
);
?>
<li class="number"><a data-pagenumber="<?= ($current + $x - $leading) ?>" href="<?= ($href) ?>"><?= ($current + $x - $leading) ?></a></li>
<?php
}
// print current page
?>
<li class="number active"><a data-pagenumber="<?= ($current) ?>" href="#"><?= ($current) ?></a></li>
<?php
// generate/render trailing crumbs
for ($x = 0; $x < $trailing; ++$x) {
// class/href setup
$params = $get;
$params[$key] = ($current + $x + 1);
$href = ($target) . '?' . http_build_query($params);
$href = preg_replace(
array('/=$/', '/=&/'),
array('', '&'),
$href
);
?>
<li class="number"><a data-pagenumber="<?= ($current + $x + 1) ?>" href="<?= ($href) ?>"><?= ($current + $x + 1) ?></a></li>
<?php
}
}
/**
* Next Link
*/
// anchor classes and target
$classes = array('copy', 'next');
$params = $get;
$params[$key] = ($current + 1);
$href = ($target) . '?' . http_build_query($params);
$href = preg_replace(
array('/=$/', '/=&/'),
array('', '&'),
$href
);
if ($current === $pages) {
$href = '#';
array_push($classes, 'disabled');
}
?>
<li class="<?= implode(' ', $classes) ?>"><a href="<?= ($href) ?>"><?= ($next) ?></a></li>
</ul>
<?php
}