forked from mybb/mybb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
showteam.php
307 lines (261 loc) · 7.8 KB
/
showteam.php
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
299
300
301
302
303
304
305
306
307
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
define("IN_MYBB", 1);
define('THIS_SCRIPT', 'showteam.php');
$templatelist = 'showteam,postbit_email,postbit_pm,showteam_usergroup_user,showteam_usergroup,showteam_moderators_mod,showteam_moderators,showteam_moderators_forum';
require_once "./global.php";
// Load global language phrases
$lang->load('showteam');
if($mybb->settings['enableshowteam'] == 0)
{
error($lang->showteam_disabled);
}
add_breadcrumb($lang->nav_showteam);
$plugins->run_hooks('showteam_start');
$timecut = TIME_NOW - $mybb->settings['wolcutoff'];
$usergroups = $moderators = $users = array();
// Fetch the list of groups which are to be shown on the page
$query = $db->simple_select("usergroups", "gid, title, usertitle", "showforumteam=1", array('order_by' => 'disporder'));
while($usergroup = $db->fetch_array($query))
{
$usergroups[$usergroup['gid']] = $usergroup;
}
if(empty($usergroups))
{
error($lang->error_noteamstoshow);
}
// Fetch specific forum moderator details
if($usergroups[6]['gid'])
{
$query = $db->query("
SELECT m.*, f.name
FROM ".TABLE_PREFIX."moderators m
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=m.id)
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=m.fid)
WHERE f.active = 1 AND m.isgroup = 0
ORDER BY u.username
");
while($moderator = $db->fetch_array($query))
{
$moderators[$moderator['id']][] = $moderator;
}
}
// Now query the users of those specific groups
$visible_groups = array_keys($usergroups);
$groups_in = implode(",", $visible_groups);
$users_in = implode(",", array_keys($moderators));
if(!$groups_in)
{
$groups_in = 0;
}
if(!$users_in)
{
$users_in = 0;
}
$forum_permissions = forum_permissions();
$query_part = '';
// Include additional groups if set to
if($mybb->settings['showaddlgroups'])
{
foreach($visible_groups as $visible_group)
{
if($db->type == "pgsql")
{
$query_part .= "'$visible_group' = ANY (string_to_array(additionalgroups, ',')) OR ";
}
else if($db->type == "sqlite")
{
$query_part .= "'$visible_group' IN (additionalgroups) OR ";
}
else
{
$query_part .= "FIND_IN_SET('$visible_group', additionalgroups) OR ";
}
}
}
// Include group leaders if set to
if($mybb->settings['showgroupleaders'])
{
$leaders = $leadlist = $leaderlist = array();
$query = $db->simple_select("groupleaders", "gid, uid");
while($leader = $db->fetch_array($query))
{
$leaders[$leader['uid']][] = $leader['gid'];
}
if(!empty($leaders))
{
foreach($leaders as $uid => $gid)
{
$leaderlist[$uid] = $gid;
$leadlist[] = implode(",", $gid);
}
$leadlist = implode(",", $leadlist);
$query = $db->simple_select("usergroups", "gid, title, namestyle", "gid IN ($leadlist)");
$leadlist = array();
while($leaded_group = $db->fetch_array($query))
{
$leaded_groups[$leaded_group['gid']] = str_replace("{username}",$leaded_group['title'], $leaded_group['namestyle']);
}
// Create virtual usergroup container for leaders
$usergroups[0] = array('gid' => 0, 'title' => $lang->group_leaders, 'usertitle' => $lang->group_leaders);
foreach($leaderlist as $uid => $leaded)
{
foreach($leaded as $gid){
$leadlist[] = $leaded_groups[$gid];
}
$usergroups[0]['user_list'][$uid]['leaded'] = implode(", ",$leadlist);
unset($leadlist);
}
$users_in = implode(",", array_keys(array_flip(explode(",", implode(",", array_keys($leaderlist)).",".$users_in))));
}
}
$query = $db->simple_select("users", "uid, username, displaygroup, usergroup, additionalgroups, ignorelist, hideemail, receivepms, lastactive, lastvisit, invisible, away", $query_part."displaygroup IN ($groups_in) OR (displaygroup='0' AND usergroup IN ($groups_in)) OR uid IN ($users_in)", array('order_by' => 'username'));
while($user = $db->fetch_array($query))
{
// If this user is a moderator
if(isset($moderators[$user['uid']]))
{
$forumlist = '';
foreach($moderators[$user['uid']] as $forum)
{
if($forum_permissions[$forum['fid']]['canview'] == 1)
{
$forum_url = get_forum_link($forum['fid']);
eval("\$forumlist .= \"".$templates->get("showteam_moderators_forum")."\";");
}
}
$user['forumlist'] = $forumlist;
$forumlist = '';
$usergroups[6]['user_list'][$user['uid']] = $user;
}
if($mybb->settings['showgroupleaders'] && isset($usergroups[0]['user_list']))
{
foreach($usergroups[0]['user_list'] as $uid => $userdetails)
{
if($user['uid'] == $uid)
{
$user['leaded'] = $usergroups[0]['user_list'][$uid]['leaded'];
$usergroups[0]['user_list'][$uid] = $user;
}
}
}
if($user['displaygroup'] == '6' || $user['usergroup'] == '6')
{
$usergroups[6]['user_list'][$user['uid']] = $user;
}
// Are they also in another group which is being shown on the list?
if($user['displaygroup'] != 0)
{
$group = $user['displaygroup'];
}
else
{
$group = $user['usergroup'];
}
if(isset($usergroups[$group]) && $group != 6)
{
$usergroups[$group]['user_list'][$user['uid']] = $user;
}
if($mybb->settings['showaddlgroups'] && $user['additionalgroups'] != '')
{
$adgroups = explode(',', $user['additionalgroups']);
foreach($adgroups as $adgroup)
{
if(in_array($adgroup, $visible_groups))
{
$usergroups[$adgroup]['user_list'][$user['uid']] = $user;
}
}
}
}
// Now we have all of our user details we can display them.
$grouplist = '';
foreach($usergroups as $usergroup)
{
$usergrouprows = $modrows = '';
// If we have no users - don't show this group
if(!isset($usergroup['user_list']))
{
continue;
}
$bgcolor = '';
foreach($usergroup['user_list'] as $user)
{
$user['username'] = format_name(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']);
$user['profilelink'] = get_profile_link($user['uid']);
// For the postbit templates
$post['uid'] = $user['uid'];
$emailcode = $pmcode = '';
if($user['hideemail'] != 1)
{
eval("\$emailcode = \"".$templates->get("postbit_email")."\";");
}
if($user['receivepms'] != 0 && $mybb->settings['enablepms'] != 0 && my_strpos(",".$user['ignorelist'].",", ",".$mybb->user['uid'].",") === false)
{
eval("\$pmcode = \"".$templates->get("postbit_pm")."\";");
}
// For the online image
if($user['lastactive'] > $timecut && ($user['invisible'] == 0 || $mybb->usergroup['canviewwolinvis'] == 1) && $user['lastvisit'] != $user['lastactive'])
{
$status = "online";
}
elseif($user['away'] == 1 && $mybb->settings['allowaway'] != 0)
{
$status = "away";
}
else
{
$status = "offline";
}
if($user['lastactive'])
{
if($user['invisible'] == 1 && $mybb->usergroup['canviewwolinvis'] != 1 && $user['uid'] != $mybb->user['uid'])
{
$user['lastvisit'] = $lang->lastvisit_hidden;
}
else
{
$user['lastvisit'] = my_date('relative', $user['lastactive']);
}
}
else
{
$user['lastvisit'] = $lang->lastvisit_never;
}
$bgcolor = alt_trow();
$plugins->run_hooks('showteam_user');
// If the current group is a moderator group
if(($usergroup['gid'] == 0 && !empty($user['leaded'])) || ($usergroup['gid'] == 6 && !empty($user['forumlist'])))
{
$scopelist = $usergroup['gid'] == 0 ? $user['leaded'] : $user['forumlist'];
eval("\$modrows .= \"".$templates->get("showteam_moderators_mod")."\";");
}
else
{
eval("\$usergrouprows .= \"".$templates->get("showteam_usergroup_user")."\";");
}
}
if($modrows && in_array($usergroup['gid'], array(0,6)))
{
$modscope = $usergroup['gid'] == 6 ? $lang->mod_forums : $lang->mod_groups;
eval("\$grouplist .= \"".$templates->get("showteam_moderators")."\";");
}
if($usergrouprows)
{
eval("\$grouplist .= \"".$templates->get("showteam_usergroup")."\";");
}
}
if(empty($grouplist))
{
error($lang->error_noteamstoshow);
}
$plugins->run_hooks("showteam_end");
eval("\$showteam = \"".$templates->get("showteam")."\";");
output_page($showteam);