|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class MylinksPageNav |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
var $total; |
|
|
|
|
|
|
6
|
|
|
var $perpage; |
|
|
|
|
|
|
7
|
|
|
var $current; |
|
|
|
|
|
|
8
|
|
|
var $url; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
function __construct($total_items, $items_perpage, $current_start, $start_name= 'start', $extra_arg= '') |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
$this->total = intval($total_items); |
|
13
|
|
|
$this->perpage = intval($items_perpage); |
|
14
|
|
|
$this->current = intval($current_start); |
|
15
|
|
|
if ( $extra_arg != '' && ( substr($extra_arg, -5) != '&' || substr($extra_arg, -1) != '&' ) ) { |
|
16
|
|
|
$extra_arg .= '&'; |
|
17
|
|
|
} |
|
18
|
|
|
$this->url = xoops_getenv('PHP_SELF') . '?' . $extra_arg . trim($start_name) . '='; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
function renderNav($offset = 5) |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
$ret = ''; |
|
24
|
|
|
if ( $this->total <= $this->perpage ) { |
|
25
|
|
|
return $ret; |
|
26
|
|
|
} |
|
27
|
|
|
$total_pages = ceil($this->total / $this->perpage); |
|
28
|
|
|
if ( $total_pages > 1 ) { |
|
29
|
|
|
$prev = $this->current - $this->perpage; |
|
30
|
|
|
if ( $prev >= 0 ) { |
|
31
|
|
|
$ret .= '<a href="' . $this->url . $prev . '"><u>«</u></a> '; |
|
32
|
|
|
} |
|
33
|
|
|
$counter = 1; |
|
34
|
|
|
$current_page = intval(floor(($this->current + $this->perpage) / $this->perpage)); |
|
35
|
|
View Code Duplication |
while ( $counter <= $total_pages ) { |
|
|
|
|
|
|
36
|
|
|
if ( $counter == $current_page ) { |
|
37
|
|
|
$ret .= '<strong>(' . $counter . ')</strong> '; |
|
38
|
|
|
} elseif ( ($counter > $current_page-$offset && $counter < $current_page + $offset ) || $counter == 1 || $counter == $total_pages ) { |
|
39
|
|
|
if ( $counter == $total_pages && $current_page < $total_pages - $offset ) { |
|
40
|
|
|
$ret .= '... '; |
|
41
|
|
|
} |
|
42
|
|
|
$ret .= '<a href="' . $this->url . (($counter - 1) * $this->perpage) . '">' . $counter . '</a> '; |
|
43
|
|
|
if ( $counter == 1 && $current_page > 1 + $offset ) { |
|
44
|
|
|
$ret .= '... '; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
$counter++; |
|
48
|
|
|
} |
|
49
|
|
|
$next = $this->current + $this->perpage; |
|
50
|
|
|
if ( $this->total > $next ) { |
|
51
|
|
|
$ret .= '<a href="' . $this->url . $next . '"><u>»</u></a> '; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $ret; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function renderSelect($showbutton = false) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
if ( $this->total < $this->perpage ) { |
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
$total_pages = ceil($this->total / $this->perpage); |
|
64
|
|
|
$ret = ''; |
|
65
|
|
|
if ( $total_pages > 1 ) { |
|
66
|
|
|
$ret = '<form name="pagenavform" action="' . xoops_getenv('PHP_SELF') . '">'; |
|
67
|
|
|
$ret .= '<select name="pagenavselect" onchange="location=this.options[this.options.selectedIndex].value;">'; |
|
68
|
|
|
$counter = 1; |
|
69
|
|
|
$current_page = intval(floor(($this->current + $this->perpage) / $this->perpage)); |
|
70
|
|
|
while ( $counter <= $total_pages ) { |
|
71
|
|
|
if ( $counter == $current_page ) { |
|
72
|
|
|
$ret .= '<option value="' . $this->url . (($counter - 1) * $this->perpage) . '" selected="selected">' . $counter.'</option>'; |
|
73
|
|
|
} else { |
|
74
|
|
|
$ret .= '<option value="' . $this->url . (($counter - 1) * $this->perpage) . '">'.$counter . '</option>'; |
|
75
|
|
|
} |
|
76
|
|
|
$counter++; |
|
77
|
|
|
} |
|
78
|
|
|
$ret .= '</select>'; |
|
79
|
|
|
if ($showbutton) { |
|
80
|
|
|
$ret .= ' <input type="submit" value="' . _GO . '">'; |
|
81
|
|
|
} |
|
82
|
|
|
$ret .= '</form>'; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $ret; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
function renderImageNav($offset = 5) |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
if ( $this->total < $this->perpage ) { |
|
91
|
|
|
return; |
|
92
|
|
|
} |
|
93
|
|
|
$total_pages = ceil($this->total / $this->perpage); |
|
94
|
|
|
$ret = ''; |
|
95
|
|
|
if ( $total_pages > 1 ) { |
|
96
|
|
|
$ret = '<table><tr>'; |
|
97
|
|
|
$prev = $this->current - $this->perpage; |
|
98
|
|
|
if ( $prev >= 0 ) { |
|
99
|
|
|
$ret .= '<td class="pagneutral"><a href="'.$this->url.$prev.'"><</a></td><td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt=""></td>'; |
|
100
|
|
|
} |
|
101
|
|
|
$counter = 1; |
|
102
|
|
|
$current_page = intval(floor(($this->current + $this->perpage) / $this->perpage)); |
|
103
|
|
View Code Duplication |
while ( $counter <= $total_pages ) { |
|
|
|
|
|
|
104
|
|
|
if ( $counter == $current_page ) { |
|
105
|
|
|
$ret .= '<td class="pagact"><b>'.$counter.'</b></td>'; |
|
106
|
|
|
} elseif ( ($counter > $current_page-$offset && $counter < $current_page + $offset ) || $counter == 1 || $counter == $total_pages ) { |
|
107
|
|
|
if ( $counter == $total_pages && $current_page < $total_pages - $offset ) { |
|
108
|
|
|
$ret .= '<td class="paginact">...</td>'; |
|
109
|
|
|
} |
|
110
|
|
|
$ret .= '<td class="paginact"><a href="'.$this->url.(($counter - 1) * $this->perpage).'">'.$counter.'</a></td>'; |
|
111
|
|
|
if ( $counter == 1 && $current_page > 1 + $offset ) { |
|
112
|
|
|
$ret .= '<td class="paginact">...</td>'; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
$counter++; |
|
116
|
|
|
} |
|
117
|
|
|
$next = $this->current + $this->perpage; |
|
118
|
|
|
if ( $this->total > $next ) { |
|
119
|
|
|
$ret .= '<td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt=""></td><td class="pagneutral"><a href="'.$this->url.$next.'">></a></td>'; |
|
120
|
|
|
} |
|
121
|
|
|
$ret .= '</tr></table>'; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return $ret; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.