-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsPagination.php
72 lines (71 loc) · 2.97 KB
/
sPagination.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
<?php
/**
* @author Savaş Can ALTUn <[email protected]>
* @link http://savascanaltun.com.tr
* @link http://github.com/saltun
* @since 20.11.2014
* @example example/example.php
* @version 1.0
*/
class sPagination {
public $getname, $totalpost, $maxpost, $url, $size, $lang;
public function pageList() {
if(empty($this->getname)) {
$this->getname = "page";
}
if(isset($_GET[$this->getname])) {
$page = $_GET[$this->getname];
} else {
$page = 1;
}
$total_pages3 = ceil($this->totalpost / $this->maxpost);
if($total_pages3 > 1) {
$part = '<ul class="pagination' . ' ' . 'pagination-' . $this->size . '"><li><a href="' . $this->url . '?' . $this->getname . '=';
$last = '">«</a></li> <li><a href="' . $this->url . '?' . $this->getname . '=' . (1) . '">' . $this->lang['first'] . '</a></li> ';
if(($page - 1) <= 1) {
echo $part . (1) . $last;
} else {
echo $part . ($page - 1) . $last;
}
if($page <= 4 and $page != 0) {
if($total_pages3 == 1 || $total_pages3 == 2 || $total_pages3 == 3 || $total_pages3 == 4 || $total_pages3 == 5) {
$total_pages = $total_pages3;
$i = 1;
} else {
$total_pages = 5;
$i = 1;
}
} else if($page >= 4 && $page < ($total_pages3 - 2)) {
$total_pages = $page + 2;
$i = $page - 2;
} else if($page >= ($total_pages3 - 2)) {
$total_pages = $total_pages3;
$i = $total_pages3 - 4;
}
for($i; $i <= $total_pages; $i++) {
$li = "<li";
if($page == $i) {
$ac = "class='active' ";
if($page == $total_pages3) {
$title = "title=' " . $this->totalpost . ' of ' . $this->totalpost . " " . $this->lang['totalrecord'] . "' ";
} else {
$title = "title=' " . $this->maxpost * $page . ' of ' . $this->totalpost . " " . $this->lang['totalrecord'] . " ' ";
}
} else {
$ac = "";
$title = "";
}
echo $li . ' ' . $ac . "><a " . $title . " href='" . $this->url . "?" . $this->getname . "=" . $i . "'>" . $i . "</a> </li> ";
}
if($page + 1 > $total_pages3) {
$pp = $page;
} else {
$pp = $page + 1;
}
$pag = '<li><a href="' . $this->url . '?' . $this->getname . '=' . $total_pages3 . '">' . $this->lang['last'] . '</a></li> <li><a href="' . $this->url . '?' . $this->getname . '=' . $pp . '">»</a></li></ul>';
echo $pag;
} else {
echo '';
}
}
}