pagination.php
6.18 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/**
* @package Joomla.Site
* @subpackage Templates.protostar
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* This is a file to add template specific chrome to pagination rendering.
*
* pagination_list_footer
* Input variable $list is an array with offsets:
* $list[limit] : int
* $list[limitstart] : int
* $list[total] : int
* $list[limitfield] : string
* $list[pagescounter] : string
* $list[pageslinks] : string
*
* pagination_list_render
* Input variable $list is an array with offsets:
* $list[all]
* [data] : string
* [active] : boolean
* $list[start]
* [data] : string
* [active] : boolean
* $list[previous]
* [data] : string
* [active] : boolean
* $list[next]
* [data] : string
* [active] : boolean
* $list[end]
* [data] : string
* [active] : boolean
* $list[pages]
* [{PAGE}][data] : string
* [{PAGE}][active] : boolean
*
* pagination_item_active
* Input variable $item is an object with fields:
* $item->base : integer
* $item->link : string
* $item->text : string
*
* pagination_item_inactive
* Input variable $item is an object with fields:
* $item->base : integer
* $item->link : string
* $item->text : string
*
* This gives template designers ultimate control over how pagination is rendered.
*
* NOTE: If you override pagination_item_active OR pagination_item_inactive you MUST override them both
*/
/**
* Renders the pagination footer
*
* @param array $list Array containing pagination footer
*
* @return string HTML markup for the full pagination footer
*
* @since 3.0
*/
function pagination_list_footer($list)
{
$html = "<div class=\"pagination\">\n";
$html .= $list['pageslinks'];
$html .= "\n<input type=\"hidden\" name=\"" . $list['prefix'] . "limitstart\" value=\"" . $list['limitstart'] . "\" />";
$html .= "\n</div>";
return $html;
}
/**
* Renders the pagination list
*
* @param array $list Array containing pagination information
*
* @return string HTML markup for the full pagination object
*
* @since 3.0
*/
function pagination_list_render($list)
{
// Calculate to display range of pages
$currentPage = 1;
$range = 1;
$step = 5;
foreach ($list['pages'] as $k => $page)
{
if (!$page['active'])
{
$currentPage = $k;
}
}
if ($currentPage >= $step)
{
if ($currentPage % $step === 0)
{
$range = ceil($currentPage / $step) + 1;
}
else
{
$range = ceil($currentPage / $step);
}
}
$html = '<nav role="navigation" aria-label="' . JText::_('JLIB_HTML_PAGINATION') . '">';
$html .= '<ul class="pagination-list">';
$html .= $list['start']['data'];
$html .= $list['previous']['data'];
foreach ($list['pages'] as $k => $page)
{
if ($k !== $currentPage && $k !== $range * $step - $step
&& ($k % $step === 0 || $k === $range * $step - ($step + 1))
&& in_array($k, range($range * $step - ($step + 1), $range * $step)))
{
$page['data'] = preg_replace('#(<a.*?>).*?(</a>)#', '$1...$2', $page['data']);
}
$html .= $page['data'];
}
$html .= $list['next']['data'];
$html .= $list['end']['data'];
$html .= '</ul>';
$html .= '</nav>';
return $html;
}
/**
* Renders an active item in the pagination block
*
* @param JPaginationObject $item The current pagination object
*
* @return string HTML markup for active item
*
* @since 3.0
*/
function pagination_item_active(&$item)
{
$class = '';
// Check for "Start" item
if ($item->text === JText::_('JLIB_HTML_START'))
{
$display = '<span class="icon-first" aria-hidden="true"></span>';
$aria = JText::sprintf('JLIB_HTML_GOTO_POSITION', strtolower($item->text));
}
// Check for "Prev" item
if ($item->text === JText::_('JPREV'))
{
$display = '<span class="icon-previous" aria-hidden="true"></span>';
$aria = JText::sprintf('JLIB_HTML_GOTO_POSITION', strtolower($item->text));
}
// Check for "Next" item
if ($item->text === JText::_('JNEXT'))
{
$display = '<span class="icon-next" aria-hidden="true"></span>';
$aria = JText::sprintf('JLIB_HTML_GOTO_POSITION', strtolower($item->text));
}
// Check for "End" item
if ($item->text === JText::_('JLIB_HTML_END'))
{
$display = '<span class="icon-last" aria-hidden="true"></span>';
$aria = JText::sprintf('JLIB_HTML_GOTO_POSITION', strtolower($item->text));
}
// If the display object isn't set already, just render the item with its text
if (!isset($display))
{
$display = $item->text;
$aria = JText::sprintf('JLIB_HTML_GOTO_PAGE', $item->text);
$class = ' class="hidden-phone"';
}
return '<li' . $class . '><a title="' . $item->text . '" href="' . $item->link . '" class="pagenav" aria-label="' . $aria . '">' . $display . '</a></li>';
}
/**
* Renders an inactive item in the pagination block
*
* @param JPaginationObject $item The current pagination object
*
* @return string HTML markup for inactive item
*
* @since 3.0
*/
function pagination_item_inactive(&$item)
{
// Check for "Start" item
if ($item->text === JText::_('JLIB_HTML_START'))
{
return '<li class="disabled"><a><span class="icon-first" aria-hidden="true"></span></a></li>';
}
// Check for "Prev" item
if ($item->text === JText::_('JPREV'))
{
return '<li class="disabled"><a><span class="icon-previous" aria-hidden="true"></span></a></li>';
}
// Check for "Next" item
if ($item->text === JText::_('JNEXT'))
{
return '<li class="disabled"><a><span class="icon-next" aria-hidden="true"></span></a></li>';
}
// Check for "End" item
if ($item->text === JText::_('JLIB_HTML_END'))
{
return '<li class="disabled"><a><span class="icon-last" aria-hidden="true"></span></a></li>';
}
// Check if the item is the active page
if (isset($item->active) && $item->active)
{
$aria = JText::sprintf('JLIB_HTML_PAGE_CURRENT', $item->text);
return '<li class="active hidden-phone"><a aria-current="true" aria-label="' . $aria . '">' . $item->text . '</a></li>';
}
// Doesn't match any other condition, render a normal item
return '<li class="disabled hidden-phone"><a>' . $item->text . '</a></li>';
}