-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericList.template.php
More file actions
298 lines (256 loc) · 10.2 KB
/
Copy pathGenericList.template.php
File metadata and controls
298 lines (256 loc) · 10.2 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2020 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1 RC3
*/
/**
* This template handles displaying a list
*
* @param string $list_id The list ID. If null, uses $context['default_list'].
*/
function template_show_list($list_id = null)
{
global $context;
// Get a shortcut to the current list.
$list_id = $list_id === null ? (!empty($context['default_list']) ? $context['default_list'] : '') : $list_id;
if (empty($list_id) || empty($context[$list_id]))
return;
$cur_list = &$context[$list_id];
// These are the main tabs that is used all around the template.
if (isset($cur_list['list_menu'], $cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] == 'both' || $cur_list['list_menu']['show_on'] == 'top'))
template_create_list_menu($cur_list['list_menu'], 'top');
if (isset($cur_list['form']))
echo '
<form action="', $cur_list['form']['href'], '" method="post"', empty($cur_list['form']['name']) ? '' : ' name="' . $cur_list['form']['name'] . '" id="' . $cur_list['form']['name'] . '"', ' accept-charset="', $context['character_set'], '">';
// Show the title of the table (if any).
if (!empty($cur_list['title']))
echo '
<h4 class="sub_bar">
', $cur_list['title'], '
</h4>';
if (isset($cur_list['additional_rows']['after_title']))
{
echo '
<div class="information flow_hidden">';
template_additional_rows('after_title', $cur_list);
echo '
</div>';
}
if (isset($cur_list['additional_rows']['top_of_list']))
template_additional_rows('top_of_list', $cur_list);
if ((!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) || isset($cur_list['additional_rows']['above_column_headers']))
{
// Show the page index (if this list doesn't intend to show all items).
if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index']))
echo '
<div class="floatleft">
<div class="pagesection">', $cur_list['page_index'], '</div>
</div>';
if (isset($cur_list['additional_rows']['above_column_headers']))
template_additional_rows('above_column_headers', $cur_list);
}
echo '
<table class="table_grid" ', !empty($list_id) ? 'id="' . $list_id . '"' : '', ' ', !empty($cur_list['width']) ? ' style="width:' . $cur_list['width'] . '"' : '', '>';
// Show the column headers.
$header_count = count($cur_list['headers']);
if (!($header_count < 2 && empty($cur_list['headers'][0]['label'])))
{
echo '
<thead>
<tr class="title_bar">';
// Loop through each column and add a table header.
foreach ($cur_list['headers'] as $col_header)
echo '
<th scope="col" id="header_', $list_id, '_', $col_header['id'], '" class="', $col_header['id'], empty($col_header['class']) ? '' : ' ' . $col_header['class'], '"', empty($col_header['style']) ? '' : ' style="' . $col_header['style'] . '"', empty($col_header['colspan']) ? '' : ' colspan="' . $col_header['colspan'] . '"', '>
', empty($col_header['href']) ? '' : '<a href="' . $col_header['href'] . '" rel="nofollow">', empty($col_header['label']) ? '' : $col_header['label'], empty($col_header['href']) ? '' : (empty($col_header['sort_image']) ? '</a>' : ' <span class="main_icons sort_' . $col_header['sort_image'] . '"></span></a>'), '
</th>';
echo '
</tr>
</thead>';
}
echo '
<tbody>';
// Show a nice message informing there are no items in this list.
if (empty($cur_list['rows']) && !empty($cur_list['no_items_label']))
echo '
<tr class="windowbg">
<td colspan="', $cur_list['num_columns'], '" class="', !empty($cur_list['no_items_align']) ? $cur_list['no_items_align'] : 'centertext', '">
', $cur_list['no_items_label'], '
</td>
</tr>';
// Show the list rows.
elseif (!empty($cur_list['rows']))
{
foreach ($cur_list['rows'] as $id => $row)
{
echo '
<tr class="windowbg', empty($row['class']) ? '' : ' ' . $row['class'], '"', empty($row['style']) ? '' : ' style="' . $row['style'] . '"', ' id="list_', $list_id, '_', $id, '">';
if (!empty($row['data']))
foreach ($row['data'] as $row_id => $row_data)
echo '
<td class="', $row_id, empty($row_data['class']) ? '' : ' ' . $row_data['class'] . '', '"', empty($row_data['style']) ? '' : ' style="' . $row_data['style'] . '"', '>
', $row_data['value'], '
</td>';
echo '
</tr>';
}
}
echo '
</tbody>
</table>';
if ((!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) || isset($cur_list['additional_rows']['below_table_data']))
{
echo '
<div class="flow_auto">';
// Show the page index (if this list doesn't intend to show all items).
if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index']))
echo '
<div class="floatleft">
<div class="pagesection">', $cur_list['page_index'], '</div>
</div>';
if (isset($cur_list['additional_rows']['below_table_data']))
template_additional_rows('below_table_data', $cur_list);
echo '
</div>';
}
if (isset($cur_list['additional_rows']['bottom_of_list']))
template_additional_rows('bottom_of_list', $cur_list);
if (isset($cur_list['form']))
{
foreach ($cur_list['form']['hidden_fields'] as $name => $value)
echo '
<input type="hidden" name="', $name, '" value="', $value, '">';
if (isset($cur_list['form']['token']))
echo '
<input type="hidden" name="', $context[$cur_list['form']['token'] . '_token_var'], '" value="', $context[$cur_list['form']['token'] . '_token'], '">';
echo '
</form>';
}
// Tabs at the bottom. Usually bottom aligned.
if (isset($cur_list['list_menu'], $cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] == 'both' || $cur_list['list_menu']['show_on'] == 'bottom'))
template_create_list_menu($cur_list['list_menu'], 'bottom');
if (isset($cur_list['javascript']))
echo '
<script>
', $cur_list['javascript'], '
</script>';
}
/**
* This template displays additional rows above or below the list.
*
* @param string $row_position The position ('top', 'bottom', etc.)
* @param array $cur_list An array with the data for the current list
*/
function template_additional_rows($row_position, $cur_list)
{
foreach ($cur_list['additional_rows'][$row_position] as $row)
echo '
<div class="additional_row', empty($row['class']) ? '' : ' ' . $row['class'], '"', empty($row['style']) ? '' : ' style="' . $row['style'] . '"', '>
', $row['value'], '
</div>';
}
/**
* This function creates a menu
*
* @param array $list_menu An array of menu data
* @param string $direction Which direction the items should go
*/
function template_create_list_menu($list_menu, $direction = 'top')
{
global $context;
/**
// This is used if you want your generic lists to have tabs.
$cur_list['list_menu'] = array(
// This is the style to use. Tabs or Buttons (Text 1 | Text 2).
// By default tabs are selected if not set.
// The main difference between tabs and buttons is that tabs get highlighted if selected.
// If style is set to buttons and use tabs is disabled then we change the style to old styled tabs.
'style' => 'tabs',
// The position of the tabs/buttons. Left or Right. By default is set to left.
'position' => 'left',
// This is used by the old styled menu. We *need* to know the total number of columns to span.
'columns' => 0,
// This gives you the option to show tabs only at the top, bottom or both.
// By default they are just shown at the top.
'show_on' => 'top',
// Links. This is the core of the array. It has all the info that we need.
'links' => array(
'name' => array(
// This will tell use were to go when they click it.
'href' => $scripturl . '?action=theaction',
// The name that you want to appear for the link.
'label' => $txt['name'],
// If we use tabs instead of buttons we highlight the current tab.
// Must use conditions to determine if its selected or not.
'is_selected' => isset($_REQUEST['name']),
),
),
);
*/
// Are we using right-to-left orientation?
$first = $context['right_to_left'] ? 'last' : 'first';
$last = $context['right_to_left'] ? 'first' : 'last';
if (!isset($list_menu['style']) || isset($list_menu['style']) && $list_menu['style'] == 'tabs')
{
echo '
<table style="margin-', $list_menu['position'], ': 10px; width: 100%;">
<tr>', $list_menu['position'] == 'right' ? '
<td></td>' : '', '
<td class="', $list_menu['position'], 'text">
<table>
<tr>
<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $first, '"></td>';
foreach ($list_menu['links'] as $link)
{
if ($link['is_selected'])
echo '
<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_active_', $first, '"></td>
<td class="', $direction == 'top' ? 'mirrortab' : 'maintab', '_active_back">
<a href="', $link['href'], '">', $link['label'], '</a>
</td>
<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_active_', $last, '"></td>';
else
echo '
<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_back">
<a href="', $link['href'], '">', $link['label'], '</a>
</td>';
}
echo '
<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $last, '"></td>
</tr>
</table>
</td>', $list_menu['position'] == 'left' ? '
<td></td>' : '', '
</tr>
</table>';
}
elseif (isset($list_menu['style']) && $list_menu['style'] == 'buttons')
{
$links = array();
foreach ($list_menu['links'] as $link)
$links[] = '<a href="' . $link['href'] . '">' . $link['label'] . '</a>';
echo '
<table style="margin-', $list_menu['position'], ': 10px; width: 100%;">
<tr>', $list_menu['position'] == 'right' ? '
<td></td>' : '', '
<td class="', $list_menu['position'], 'text">
<table>
<tr>
<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $first, '"></td>
<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_back">', implode(' | ', $links), '</td>
<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $last, '"></td>
</tr>
</table>
</td>', $list_menu['position'] == 'left' ? '
<td></td>' : '', '
</tr>
</table>';
}
}
?>