helper_page.php
5.54 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: helper_page.php 33588 2013-07-12 06:34:56Z hypowang $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class helper_page {
public static function multi($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE, $jsfunc = FALSE) {
global $_G;
$ajaxtarget = !empty($_GET['ajaxtarget']) ? " ajaxtarget=\"".dhtmlspecialchars($_GET['ajaxtarget'])."\" " : '';
$a_name = '';
$mpurl = str_replace(array("'", '"', "\\"), array('%27', '%22', '%5c'), $mpurl);
if(strpos($mpurl, '#') !== FALSE) {
$a_strs = explode('#', $mpurl);
$mpurl = $a_strs[0];
$a_name = '#'.$a_strs[1];
}
if($jsfunc !== FALSE) {
$mpurl = 'javascript:'.$mpurl;
$a_name = $jsfunc;
$pagevar = '';
} else {
$pagevar = 'page=';
}
if(defined('IN_ADMINCP')) {
$shownum = $showkbd = TRUE;
$showpagejump = FALSE;
$lang['prev'] = '‹‹';
$lang['next'] = '››';
} else {
$shownum = $showkbd = FALSE;
$showpagejump = TRUE;
if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
$lang['prev'] = lang('core', 'prevpage');
$lang['next'] = lang('core', 'nextpage');
} else {
$lang['prev'] = ' ';
$lang['next'] = lang('core', 'nextpage');
}
$lang['pageunit'] = lang('core', 'pageunit');
$lang['total'] = lang('core', 'total');
$lang['pagejumptip'] = lang('core', 'pagejumptip');
}
if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
$dot = '..';
$page = intval($page) < 10 && intval($page) > 0 ? $page : 4 ;
} else {
$dot = '...';
}
$multipage = '';
if($jsfunc === FALSE) {
$mpurl .= strpos($mpurl, '?') !== FALSE ? '&' : '?';
}
$realpages = 1;
$_G['page_next'] = 0;
$page -= strlen($curpage) - 1;
if($page <= 0) {
$page = 1;
}
if($num > $perpage) {
$offset = floor($page * 0.5);
$realpages = @ceil($num / $perpage);
$curpage = $curpage > $realpages ? $realpages : $curpage;
$pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
$from = $curpage - $offset;
$to = $from + $page - 1;
if($from < 1) {
$to = $curpage + 1 - $from;
$from = 1;
if($to - $from < $page) {
$to = $page;
}
} elseif($to > $pages) {
$from = $pages - $page + 1;
$to = $pages;
}
}
$_G['page_next'] = $to;
$multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.(self::mpurl($mpurl, $pagevar, 1)).$a_name.'" class="first"'.$ajaxtarget.'>1 '.$dot.'</a>' : '').
($curpage > 1 && !$simple ? '<a href="'.(self::mpurl($mpurl, $pagevar, $curpage - 1)).$a_name.'" class="prev"'.$ajaxtarget.'>'.$lang['prev'].'</a>' : '');
for($i = $from; $i <= $to; $i++) {
$multipage .= $i == $curpage ? '<strong>'.$i.'</strong>' :
'<a href="'.(self::mpurl($mpurl, $pagevar, $i)).($ajaxtarget && $i == $pages && $autogoto ? '#' : $a_name).'"'.$ajaxtarget.'>'.$i.'</a>';
}
$wml = defined('IN_MOBILE') && IN_MOBILE == 3;
$jsurl = '';
if(($showpagejump || $showkbd) && !$simple && !$ajaxtarget && !$wml) {
$jsurl = $mpurl.(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value;').'; doane(event);';
}
$multipage .= ($to < $pages ? '<a href="'.(self::mpurl($mpurl, $pagevar, $pages)).$a_name.'" class="last"'.$ajaxtarget.'>'.$dot.' '.$realpages.'</a>' : '').
($showpagejump && !$simple && !$ajaxtarget && !$wml ? '<label><input type="text" name="custompage" class="px" size="2" title="'.$lang['pagejumptip'].'" value="'.$curpage.'" onkeydown="if(event.keyCode==13) {window.location=\''.$jsurl.'}" /><span title="'.$lang['total'].' '.$pages.' '.$lang['pageunit'].'"> / '.$pages.' '.$lang['pageunit'].'</span></label>' : '').
($curpage < $pages && !$simple ? '<a href="'.(self::mpurl($mpurl, $pagevar, $curpage + 1)).$a_name.'" class="nxt"'.$ajaxtarget.'>'.$lang['next'].'</a>' : '').
($showkbd && !$simple && $pages > $page && !$ajaxtarget && !$wml ? '<kbd><input type="text" name="custompage" size="3" onkeydown="if(event.keyCode==13) {window.location=\''.$jsurl.'}" /></kbd>' : '');
$multipage = $multipage ? '<div class="pg">'.($shownum && !$simple ? '<em> '.$num.' </em>' : '').$multipage.'</div>' : '';
}
$maxpage = $realpages;
return $multipage;
}
public static function mpurl($mpurl, $pagevar, $page) {
if(strpos($mpurl, '{page}') !== false) {
return trim(str_replace('{page}', ($page == 1 ? '' : $page), $mpurl), '?');
} else {
$separator = '';
if($pagevar[0] !== '&' && $pagevar[0] !== '?') {
if(strpos($mpurl, '?') !== FALSE) {
$separator = '';
} else {
$separator = '?';
}
}
return $mpurl.$separator.$pagevar.$page;
}
}
public static function simplepage($num, $perpage, $curpage, $mpurl) {
$return = '';
$lang['next'] = lang('core', 'nextpage');
$lang['prev'] = lang('core', 'prevpage');
$next = $num == $perpage ? '<a href="'.(self::mpurl($mpurl, '&page=', $curpage + 1)).'" class="nxt">'.$lang['next'].'</a>' : '';
$prev = $curpage > 1 ? '<span class="pgb"><a href="'.(self::mpurl($mpurl, '&page=', $curpage - 1)).'">'.$lang['prev'].'</a></span>' : '';
if($next || $prev) {
$return = '<div class="pg">'.$prev.$next.'</div>';
}
return $return;
}
}
?>