XCL Web Application Platform
2.5.0
The XoopsCube Legacy Project
📘
Loading...
Searching...
No Matches
pagenav.php
1
<?php
14
15
16
class
XoopsPageNav
17
{
21
public
$total
;
22
public
$perpage;
23
public
$current;
24
public
$url;
26
36
public
function
__construct
($total_items, $items_perpage, $current_start, $start_name=
'start'
, $extra_arg=
''
)
37
{
38
$this->total = (int)$total_items;
39
$this->perpage = (int)$items_perpage;
40
$this->current = (int)$current_start;
41
if
(
''
!== $extra_arg && (
'&'
!== substr($extra_arg, -5) ||
'&'
!== substr($extra_arg, -1))) {
42
$extra_arg .=
'&'
;
43
}
44
$this->url = xoops_getenv(
'PHP_SELF'
).
'?'
.$extra_arg.trim($start_name).
'='
;
45
}
46
53
public
function
renderNav
($offset = 4)
54
{
55
$ret =
''
;
56
if
($this->total <= $this->perpage) {
57
return
$ret;
58
}
59
$total_pages = ceil($this->total / $this->perpage);
60
if
($total_pages > 1) {
61
$ret .=
'<ul class="pagenavi">'
;
62
$prev = $this->current - $this->perpage;
63
if
($prev >= 0) {
64
$ret .=
'<li><a href="'
.$this->url.$prev.
'">«</a></li>'
;
65
}
66
$counter = 1;
67
$current_page = (int)floor(($this->current + $this->perpage) / $this->perpage);
68
while
($counter <= $total_pages) {
69
if
($counter == $current_page) {
70
$ret .=
'<li aria-label="page '
.$counter.
'" aria-current="page"><b>'
.$counter.
'</b></li>'
;
71
} elseif (($counter > $current_page-$offset && $counter < $current_page + $offset) || 1 == $counter || $counter == $total_pages) {
72
if
($counter == $total_pages && $current_page < $total_pages - $offset) {
73
$ret .=
'<li>...</li>'
;
74
}
75
$ret .=
'<li><a href="'
.$this->url.(($counter - 1) * $this->perpage).
'">'
.$counter.
'</a></li>'
;
76
if
(1 == $counter && $current_page > 1 + $offset) {
77
$ret .=
'<li>...</li>'
;
78
}
79
}
80
$counter++;
81
}
82
$next = $this->current + $this->perpage;
83
if
($this->total > $next) {
84
$ret .=
'<li><a href="'
.$this->url.$next.
'"><u>»</u></a></li>'
;
85
}
86
$ret .=
'</ul>'
;
87
}
88
return
$ret;
89
}
90
97
public
function
renderSelect
($showbutton =
false
)
98
{
99
if
($this->total < $this->perpage) {
100
return
;
101
}
102
$total_pages = ceil($this->total / $this->perpage);
103
$ret =
''
;
104
if
($total_pages > 1) {
105
$ret =
'<form name="pagenavform" action="'
.xoops_getenv(
'PHP_SELF'
).
'">'
;
106
$ret .=
'<select name="pagenavselect" onchange="location=this.options[this.options.selectedIndex].value;">'
;
107
$counter = 1;
108
$current_page = (int)floor(($this->current + $this->perpage) / $this->perpage);
109
while
($counter <= $total_pages) {
110
if
($counter == $current_page) {
111
$ret .=
'<option value="'
.$this->url.(($counter - 1) * $this->perpage).
'" selected="selected">'
.$counter.
'</option>'
;
112
}
else
{
113
$ret .=
'<option value="'
.$this->url.(($counter - 1) * $this->perpage).
'">'
.$counter.
'</option>'
;
114
}
115
$counter++;
116
}
117
$ret .=
'</select>'
;
118
if
($showbutton) {
119
$ret .=
' <input type="submit" value="'
._GO.
'" />'
;
120
}
121
$ret .=
'</form>'
;
122
}
123
return
$ret;
124
}
125
132
public
function
renderImageNav
($offset = 4)
133
{
134
if
($this->total < $this->perpage) {
135
return
;
136
}
137
$total_pages = ceil($this->total / $this->perpage);
138
$ret =
''
;
139
if
($total_pages > 1) {
140
$ret =
'<table><tr>'
;
141
$prev = $this->current - $this->perpage;
142
if
($prev >= 0) {
143
$ret .=
'<td class="pagneutral"><a href="'
.$this->url.$prev.
'"><</a></td><td><img src="'
.XOOPS_URL.
'/images/blank.gif" width="6" alt="" /></td>'
;
144
}
145
$counter = 1;
146
$current_page = (int)floor(($this->current + $this->perpage) / $this->perpage);
147
while
($counter <= $total_pages) {
148
if
($counter == $current_page) {
149
$ret .=
'<td class="pagact"><b>'
.$counter.
'</b></td>'
;
150
} elseif (($counter > $current_page-$offset && $counter < $current_page + $offset) || 1 == $counter || $counter == $total_pages) {
151
if
($counter == $total_pages && $current_page < $total_pages - $offset) {
152
$ret .=
'<td class="paginact">...</td>'
;
153
}
154
$ret .=
'<td class="paginact"><a href="'
.$this->url.(($counter - 1) * $this->perpage).
'">'
.$counter.
'</a></td>'
;
155
if
(1 == $counter && $current_page > 1 + $offset) {
156
$ret .=
'<td class="paginact">...</td>'
;
157
}
158
}
159
$counter++;
160
}
161
$next = $this->current + $this->perpage;
162
if
($this->total > $next) {
163
$ret .=
'<td><img src="'
.XOOPS_URL.
'/images/blank.gif" width="6" alt="" /></td><td class="pagneutral"><a href="'
.$this->url.$next.
'">></a></td>'
;
164
}
165
$ret .=
'</tr></table>'
;
166
}
167
return
$ret;
168
}
169
}
XoopsPageNav
Definition
pagenav.php:17
XoopsPageNav\renderSelect
renderSelect($showbutton=false)
Definition
pagenav.php:97
XoopsPageNav\$total
$total
Definition
pagenav.php:21
XoopsPageNav\__construct
__construct($total_items, $items_perpage, $current_start, $start_name='start', $extra_arg='')
Definition
pagenav.php:36
XoopsPageNav\renderNav
renderNav($offset=4)
Definition
pagenav.php:53
XoopsPageNav\renderImageNav
renderImageNav($offset=4)
Definition
pagenav.php:132
html
class
pagenav.php
Generated by
1.13.2