/
functions_modcp.php
341 lines (296 loc) · 9.47 KB
/
functions_modcp.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
/**
* Check if the current user has permission to perform a ModCP action on another user
*
* @param int $uid The user ID to perform the action on.
* @return boolean True if the user has necessary permissions
*/
function modcp_can_manage_user($uid)
{
global $mybb;
$user_permissions = user_permissions($uid);
// Current user is only a local moderator or use with ModCP permissions, cannot manage super mods or admins
if($mybb->usergroup['issupermod'] == 0 && ($user_permissions['issupermod'] == 1 || $user_permissions['cancp'] == 1))
{
return false;
}
// Current user is a super mod or is an administrator
else if($user_permissions['cancp'] == 1 && ($mybb->usergroup['cancp'] != 1 || (is_super_admin($uid) && !is_super_admin($mybb->user['uid']))))
{
return false;
}
return true;
}
/**
* Fetch forums the moderator can manage announcements to
*
* @param int $pid (Optional) The parent forum ID
* @param int $depth (Optional) The depth from parent forum the moderator can manage to
*/
function fetch_forum_announcements($pid=0, $depth=1)
{
global $mybb, $db, $lang, $theme, $announcements, $templates, $announcements_forum, $moderated_forums, $unviewableforums, $parser;
static $forums_by_parent, $forum_cache, $parent_forums;
if(!is_array($forum_cache))
{
$forum_cache = cache_forums();
}
if(!is_array($parent_forums) && $mybb->usergroup['issupermod'] != 1)
{
// Get a list of parentforums to show for normal moderators
$parent_forums = array();
foreach($moderated_forums as $mfid)
{
$parent_forums = array_merge($parent_forums, explode(',', $forum_cache[$mfid]['parentlist']));
}
}
if(!is_array($forums_by_parent))
{
foreach($forum_cache as $forum)
{
$forums_by_parent[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
}
}
if(!is_array($forums_by_parent[$pid]))
{
return;
}
foreach($forums_by_parent[$pid] as $children)
{
foreach($children as $forum)
{
if($forum['linkto'] || (is_array($unviewableforums) && in_array($forum['fid'], $unviewableforums)))
{
continue;
}
if($forum['active'] == 0 || !is_moderator($forum['fid'], "canmanageannouncements"))
{
// Check if this forum is a parent of a moderated forum
if(is_array($parent_forums) && in_array($forum['fid'], $parent_forums))
{
// A child is moderated, so print out this forum's title. RECURSE!
$trow = alt_trow();
eval("\$announcements_forum .= \"".$templates->get("modcp_announcements_forum_nomod")."\";");
}
else
{
// No subforum is moderated by this mod, so safely continue
continue;
}
}
else
{
// This forum is moderated by the user, so print out the forum's title, and its announcements
$trow = alt_trow();
$padding = 40*($depth-1);
eval("\$announcements_forum .= \"".$templates->get("modcp_announcements_forum")."\";");
if(isset($announcements[$forum['fid']]))
{
foreach($announcements[$forum['fid']] as $aid => $announcement)
{
$trow = alt_trow();
if($announcement['enddate'] < TIME_NOW && $announcement['enddate'] != 0)
{
eval("\$icon = \"".$templates->get("modcp_announcements_announcement_expired")."\";");
}
else
{
eval("\$icon = \"".$templates->get("modcp_announcements_announcement_active")."\";");
}
$subject = htmlspecialchars_uni($parser->parse_badwords($announcement['subject']));
eval("\$announcements_forum .= \"".$templates->get("modcp_announcements_announcement")."\";");
}
}
}
// Build the list for any sub forums of this forum
if(isset($forums_by_parent[$forum['fid']]))
{
fetch_forum_announcements($forum['fid'], $depth+1);
}
}
}
}
/**
* Send reported content to moderators
*
* @param array $report Array of reported content
* @param string $report_type Type of content being reported
* @return bool|array PM Information or false
*/
function send_report($report, $report_type='post')
{
global $db, $lang, $forum, $mybb, $post, $thread, $reputation, $user, $plugins;
$report_reason = '';
if($report['reasonid'])
{
$query = $db->simple_select("reportreasons", "title", "rid = '".(int)$report['reasonid']."'", array('limit' => 1));
$reason = $db->fetch_array($query);
$lang->load('report');
$report_reason = $lang->parse($reason['title']);
}
if($report['reason'])
{
$report_reason = $lang->sprintf($lang->email_report_comment_extra, $report_reason, $report['reason']);
}
$modsjoin = $modswhere = '';
if(!empty($forum['parentlist']))
{
$modswhere = "m.fid IN ({$forum['parentlist']}) OR ";
if($db->type == 'pgsql' || $db->type == 'sqlite')
{
$modsjoin = "LEFT JOIN {$db->table_prefix}moderators m ON (m.id = u.uid AND m.isgroup = 0) OR ((m.id = u.usergroup OR ',' || u.additionalgroups || ',' LIKE '%,' || m.id || ',%') AND m.isgroup = 1)";
}
else
{
$modsjoin = "LEFT JOIN {$db->table_prefix}moderators m ON (m.id = u.uid AND m.isgroup = 0) OR ((m.id = u.usergroup OR CONCAT(',', u.additionalgroups, ',') LIKE CONCAT('%,', m.id, ',%')) AND m.isgroup = 1)";
}
}
switch($db->type)
{
case "pgsql":
case "sqlite":
$query = $db->query("
SELECT DISTINCT u.username, u.email, u.receivepms, u.uid
FROM {$db->table_prefix}users u
{$modsjoin}
LEFT JOIN {$db->table_prefix}usergroups g ON (',' || u.additionalgroups || ',' LIKE '%,' || g.gid || ',%' OR g.gid = u.usergroup)
WHERE {$modswhere}g.cancp = 1 OR g.issupermod = 1
");
break;
default:
$query = $db->query("
SELECT DISTINCT u.username, u.email, u.receivepms, u.uid
FROM {$db->table_prefix}users u
{$modsjoin}
LEFT JOIN {$db->table_prefix}usergroups g ON (CONCAT(',', u.additionalgroups, ',') LIKE CONCAT('%,', g.gid, ',%') OR g.gid = u.usergroup)
WHERE {$modswhere}g.cancp = 1 OR g.issupermod = 1
");
}
$lang_string_subject = "emailsubject_report{$report_type}";
$lang_string_message = "email_report{$report_type}";
if(empty($lang->$lang_string_subject) || empty($lang->$lang_string_message))
{
return false;
}
global $send_report_subject, $send_report_url;
switch($report_type)
{
case 'post':
$send_report_subject = $post['subject'];
$send_report_url = str_replace('&', '&', get_post_link($post['pid'], $thread['tid'])."#pid".$post['pid']);
break;
case 'profile':
$send_report_subject = $user['username'];
$send_report_url = str_replace('&', '&', get_profile_link($user['uid']));
break;
case 'reputation':
$from_user = get_user($reputation['adduid']);
$send_report_subject = $from_user['username'];
$send_report_url = "reputation.php?uid={$reputation['uid']}#rid{$reputation['rid']}";
break;
}
$plugins->run_hooks("send_report_report_type");
$emailsubject = $lang->sprintf($lang->$lang_string_subject, $mybb->settings['bbname']);
$emailmessage = $lang->sprintf($lang->$lang_string_message, $mybb->user['username'], $mybb->settings['bbname'], $send_report_subject, $mybb->settings['bburl'], $send_report_url, $report_reason);
$pm_recipients = array();
while($mod = $db->fetch_array($query))
{
if($mybb->settings['reportmethod'] == "pms" && $mod['receivepms'] != 0 && $mybb->settings['enablepms'] != 0)
{
$pm_recipients[] = $mod['uid'];
}
else
{
my_mail($mod['email'], $emailsubject, $emailmessage);
}
}
if(count($pm_recipients) > 0)
{
require_once MYBB_ROOT."inc/datahandlers/pm.php";
$pmhandler = new PMDataHandler();
$pm = array(
"subject" => $emailsubject,
"message" => $emailmessage,
"icon" => 0,
"fromid" => $mybb->user['uid'],
"toid" => $pm_recipients,
"ipaddress" => $mybb->session->packedip
);
$pm['options'] = array(
"signature" => 0,
"disablesmilies" => 0,
"savecopy" => 0,
"readreceipt" => 0
);
$pm['saveasdraft'] = 0;
$pmhandler->admin_override = true;
$pmhandler->set_data($pm);
// Now let the pm handler do all the hard work.
if(!$pmhandler->validate_pm())
{
// Force it to valid to just get it out of here
$pmhandler->is_validated = true;
$pmhandler->errors = array();
}
$pminfo = $pmhandler->insert_pm();
return $pminfo;
}
return false;
}
/**
* Add a report
*
* @param array $report Array of reported content
* @param string $type Type of content being reported
* @return int Report ID
*/
function add_report($report, $type = 'post')
{
global $cache, $db, $mybb;
$insert_array = array(
'id' => (int)$report['id'],
'id2' => (int)$report['id2'],
'id3' => (int)$report['id3'],
'uid' => (int)$report['uid'],
'reportstatus' => 0,
'reasonid' => (int)$report['reasonid'],
'reason' => $db->escape_string($report['reason']),
'type' => $db->escape_string($type),
'reports' => 1,
'dateline' => TIME_NOW,
'lastreport' => TIME_NOW,
'reporters' => $db->escape_string(my_serialize(array($report['uid'])))
);
if($mybb->settings['reportmethod'] == "email" || $mybb->settings['reportmethod'] == "pms")
{
send_report($report, $type);
}
$rid = $db->insert_query("reportedcontent", $insert_array);
$cache->update_reportedcontent();
return $rid;
}
/**
* Update an existing report
*
* @param array $report Array of reported content
* @return bool true
*/
function update_report($report)
{
global $db;
$update_array = array(
'reports' => ++$report['reports'],
'lastreport' => TIME_NOW,
'reporters' => $db->escape_string(my_serialize($report['reporters']))
);
$db->update_query("reportedcontent", $update_array, "rid = '{$report['rid']}'");
return true;
}