forked from torrentpier/torrentpier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodcp.php
753 lines (615 loc) · 26.3 KB
/
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
<?php
/**
* TorrentPier – Bull-powered BitTorrent tracker engine
*
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
define('BB_SCRIPT', 'modcp');
define('BB_ROOT', './');
require __DIR__ . '/common.php';
require INC_DIR . '/bbcode.php';
//
// Functions
//
function return_msg_mcp($status_msg)
{
global $topic_id, $req_topics, $forum_id, $lang, $mode;
if (count($req_topics) == 1) {
$topic_id = reset($req_topics);
}
$message = $status_msg;
$message .= '<br /><br />';
if ($topic_id && $mode != 'delete') {
$message .= sprintf($lang['CLICK_RETURN_TOPIC'], '<a href="' . TOPIC_URL . $topic_id . '">', '</a>');
$message .= '<br /><br />';
} elseif (count($req_topics) != 1) {
$message .= sprintf($lang['CLICK_RETURN_MODCP'], '<a href="' . FORUM_URL . "$forum_id&mod=1" . '">', '</a>');
$message .= '<br /><br />';
}
$message .= sprintf($lang['CLICK_RETURN_FORUM'], '<a href="' . FORUM_URL . $forum_id . '">', '</a>');
return $message;
}
function validate_topics($forum_id, &$req_topics, &$topic_titles)
{
$valid_topics = $valid_titles = array();
if ($topic_csv = get_id_csv($req_topics)) {
$sql = "SELECT topic_id, topic_title FROM " . BB_TOPICS . " WHERE topic_id IN($topic_csv) AND forum_id = $forum_id";
foreach (DB()->fetch_rowset($sql) as $row) {
$valid_topics[] = $row['topic_id'];
$valid_titles[] = $row['topic_title'];
}
}
$req_topics = $valid_topics;
$topic_titles = $valid_titles;
}
/**
* @param $request_index
* @param $mod_action
* @return bool
*/
function validate_mode_condition($request_index, $mod_action = '')
{
if (!$mod_action) {
$mod_action = $request_index;
}
return (isset($_REQUEST[$request_index]) || (isset($_POST['mod_action']) && $_POST['mod_action'] === $mod_action));
}
// Obtain initial vars
$forum_id = $_REQUEST['f'] ?? 0;
$topic_id = $_REQUEST['t'] ?? 0;
$post_id = $_REQUEST['p'] ?? 0;
$start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0;
$confirmed = isset($_POST['confirm']);
$mode = $topic_title = '';
if (isset($_REQUEST['mode'])) {
$mode = (string)$_REQUEST['mode'];
} else {
if (validate_mode_condition('delete', 'topic_delete')) {
$mode = 'delete';
} elseif (validate_mode_condition('move', 'topic_move')) {
$mode = 'move';
} elseif (validate_mode_condition('lock', 'topic_lock')) {
$mode = 'lock';
} elseif (validate_mode_condition('unlock', 'topic_unlock')) {
$mode = 'unlock';
} elseif (validate_mode_condition('post_pin')) {
$mode = 'post_pin';
} elseif (validate_mode_condition('post_unpin')) {
$mode = 'post_unpin';
}
}
// Obtain relevant data
if ($topic_id) {
$sql = "
SELECT
f.forum_id, f.forum_name, f.forum_topics, f.self_moderated,
t.topic_first_post_id, t.topic_poster
FROM " . BB_TOPICS . " t, " . BB_FORUMS . " f
WHERE t.topic_id = $topic_id
AND f.forum_id = t.forum_id
LIMIT 1
";
if (!$topic_row = DB()->fetch_row($sql)) {
bb_die('Topic post not exist');
}
$forum_id = $topic_row['forum_id'];
$forum_name = $topic_row['forum_name'];
$forum_topics = (!$topic_row['forum_topics']) ? 1 : $topic_row['forum_topics'];
} elseif ($forum_id) {
$sql = "SELECT forum_name, forum_topics FROM " . BB_FORUMS . " WHERE forum_id = $forum_id LIMIT 1";
if (!$topic_row = DB()->fetch_row($sql)) {
bb_die('Forum not exist');
}
$forum_name = $topic_row['forum_name'];
$forum_topics = (!$topic_row['forum_topics']) ? 1 : $topic_row['forum_topics'];
} else {
bb_die('Invalid request');
}
// Start session management
$user->session_start(array('req_login' => true));
// Check if user did or did not confirm. If they did not, forward them to the last page they were on
if (isset($_POST['cancel']) || IS_GUEST) {
$redirect = 'index.php';
if ($topic_id || $forum_id) {
$redirect = ($topic_id) ? TOPIC_URL . $topic_id : FORUM_URL . $forum_id;
}
redirect($redirect);
}
// Start auth check
$is_auth = auth(AUTH_ALL, $forum_id, $userdata);
$is_moderator = (IS_AM);
if ($mode == 'ip') {
// Moderator can view IP in all forums
$is_auth['auth_mod'] = $is_moderator;
} elseif ($mode == 'move' && !$is_auth['auth_mod']) {
// User can move his own topic if this forum is "self_moderated"
if ($topic_id && $topic_row['self_moderated'] && $topic_row['topic_poster'] == $userdata['user_id']) {
$is_auth['auth_mod'] = true;
$_POST['insert_bot_msg'] = 1;
unset($_POST['topic_id_list'], $_POST['move_leave_shadow']);
}
}
// Exit if user not authorized
if (!$is_auth['auth_mod']) {
bb_die($lang['NOT_MODERATOR']);
}
// Redirect to login page if not admin session
if ($is_moderator && !$userdata['session_admin']) {
$redirect = $_POST['redirect'] ?? $_SERVER['REQUEST_URI'];
redirect(LOGIN_URL . "?redirect=$redirect&admin=1");
}
//
// Get required vars
//
$req_topics = $topic_csv = $topic_titles = $hidden_fields = array();
switch ($mode) {
case 'delete':
case 'move':
case 'lock':
case 'unlock':
case 'set_download':
case 'unset_download':
case 'post_pin':
case 'post_unpin':
if (empty($_POST['topic_id_list']) && empty($topic_id)) {
bb_die($lang['NONE_SELECTED']);
}
$req_topics = $_POST['topic_id_list'] ?? $topic_id;
validate_topics($forum_id, $req_topics, $topic_titles);
if (!$req_topics || !($topic_csv = get_id_csv($req_topics))) {
bb_die($lang['NONE_SELECTED']);
}
$hidden_fields = array(
'sid' => $userdata['session_id'],
'mode' => $mode,
'f' => $forum_id,
't' => $topic_id,
);
foreach ($req_topics as $req_topic_id) {
$hidden_fields['topic_id_list'][] = $req_topic_id;
}
break;
}
//
// Perform action or show confirm message
//
switch ($mode) {
case 'delete':
if (!$is_auth['auth_delete']) {
bb_die(sprintf($lang['SORRY_AUTH_DELETE'], $is_auth['auth_delete_type']));
}
if ($confirmed) {
$result = \TorrentPier\Legacy\Admin\Common::topic_delete($req_topics, $forum_id);
//Обновление кеша новостей на главной
$news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id']));
if (isset($news_forums[$forum_id]) && $bb_cfg['show_latest_news'] && $result) {
$datastore->enqueue('latest_news');
$datastore->update('latest_news');
}
$net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id']));
if (isset($net_forums[$forum_id]) && $bb_cfg['show_network_news'] && $result) {
$datastore->enqueue('network_news');
$datastore->update('network_news');
}
$msg = ($result) ? $lang['TOPICS_REMOVED'] : $lang['NO_TOPICS_REMOVED'];
bb_die(return_msg_mcp($msg));
} else {
print_confirmation(array(
'QUESTION' => $lang['CONFIRM_DELETE_TOPIC'],
'ITEMS_LIST' => implode("\n</li>\n<li>\n", $topic_titles),
'FORM_ACTION' => "modcp.php",
'HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
));
}
break;
case 'move':
if ($confirmed) {
$new_forum_id = (int)$_POST['new_forum'];
$result = \TorrentPier\Legacy\Admin\Common::topic_move($req_topics, $new_forum_id, $forum_id, isset($_POST['move_leave_shadow']), isset($_POST['insert_bot_msg']));
//Обновление кеша новостей на главной
$news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id']));
if ((isset($news_forums[$forum_id]) || isset($news_forums[$new_forum_id])) && $bb_cfg['show_latest_news'] && $result) {
$datastore->enqueue('latest_news');
$datastore->update('latest_news');
}
$net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id']));
if ((isset($net_forums[$forum_id]) || isset($net_forums[$new_forum_id])) && $bb_cfg['show_network_news'] && $result) {
$datastore->enqueue('network_news');
$datastore->update('network_news');
}
$msg = ($result) ? $lang['TOPICS_MOVED'] : $lang['NO_TOPICS_MOVED'];
bb_die(return_msg_mcp($msg));
} else {
if (IS_ADMIN) {
$forum_select_mode = 'admin';
} else {
$not_auth_forums_csv = $user->get_not_auth_forums(AUTH_VIEW);
$forum_select_mode = explode(',', $not_auth_forums_csv);
}
$forum_select = get_forum_select($forum_select_mode, 'new_forum', $forum_id);
$template->assign_vars(array(
'TPL_MODCP_MOVE' => true,
'SHOW_LEAVESHADOW' => $is_moderator,
'SHOW_BOT_OPTIONS' => $is_moderator,
'MESSAGE_TITLE' => $lang['CONFIRM'],
'MESSAGE_TEXT' => $lang['CONFIRM_MOVE_TOPIC'],
'TOPIC_TITLES' => implode("\n</li>\n<li>\n", $topic_titles),
'S_FORUM_SELECT' => $forum_select,
'S_MODCP_ACTION' => "modcp.php",
'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
));
$template->set_filenames(array('body' => 'modcp.tpl'));
}
break;
case 'lock':
case 'unlock':
$lock = ($mode == 'lock');
$new_topic_status = ($lock) ? TOPIC_LOCKED : TOPIC_UNLOCKED;
$sql = "
SELECT topic_id, topic_title
FROM " . BB_TOPICS . "
WHERE topic_id IN($topic_csv)
AND forum_id = $forum_id
AND topic_status != " . TOPIC_MOVED . "
AND topic_status != $new_topic_status
";
$topic_csv = array();
foreach (DB()->fetch_rowset($sql) as $row) {
$topic_csv[] = $row['topic_id'];
$log_topics[$row['topic_id']] = $row['topic_title'];
}
if (!$topic_csv = get_id_csv($topic_csv)) {
bb_die($lang['NONE_SELECTED']);
}
DB()->query("
UPDATE " . BB_TOPICS . " SET
topic_status = $new_topic_status
WHERE topic_id IN($topic_csv)
");
// Log action
$type = ($lock) ? 'mod_topic_lock' : 'mod_topic_unlock';
foreach ($log_topics as $topic_id => $topic_title) {
$log_action->mod($type, array(
'forum_id' => $forum_id,
'topic_id' => $topic_id,
'topic_title' => $topic_title,
));
}
$msg = ($lock) ? $lang['TOPICS_LOCKED'] : $lang['TOPICS_UNLOCKED'];
bb_die(return_msg_mcp($msg));
break;
// Set or unset topics DL-type
case 'set_download':
case 'unset_download':
$set_download = ($mode == 'set_download');
$new_dl_type = ($set_download) ? TOPIC_DL_TYPE_DL : TOPIC_DL_TYPE_NORMAL;
DB()->query("
UPDATE " . BB_TOPICS . " SET
topic_dl_type = $new_dl_type
WHERE topic_id IN($topic_csv)
AND forum_id = $forum_id
AND topic_moved_id = 0
");
if ($mode == 'unset_download') {
clear_dl_list($topic_csv);
}
$msg = ($set_download) ? $lang['TOPICS_DOWN_SETS'] : $lang['TOPICS_DOWN_UNSETS'];
bb_die(return_msg_mcp($msg));
break;
case 'split':
//mpd
$delete_posts = isset($_POST['delete_posts']);
$split = (isset($_POST['split_type_all']) || isset($_POST['split_type_beyond']));
$posts = $_POST['post_id_list'] ?? array();
$start = /* (isset($_POST['start'])) ? intval($_POST['start']) : */
0;
$topic_first_post_id = $topic_row['topic_first_post_id'] ?? '';
$post_id_sql = $req_post_id_sql = array();
if (($split || $delete_posts) && ($posts && $topic_id && $forum_id && $topic_first_post_id) && $confirmed) {
foreach ($posts as $post_id) {
if ($pid = (int)$post_id) {
$req_post_id_sql[] = $pid;
}
}
if ($req_post_id_sql = implode(',', $req_post_id_sql)) {
$sql = "SELECT post_id
FROM " . BB_POSTS . "
WHERE post_id IN($req_post_id_sql)
AND post_id != $topic_first_post_id
AND topic_id = $topic_id
AND forum_id = $forum_id";
if (!$result = DB()->sql_query($sql)) {
bb_die('Could not get post id information');
}
if ($rowset = DB()->sql_fetchrowset($result)) {
foreach ($rowset as $rid => $row) {
$post_id_sql[] = $row['post_id'];
}
$post_id_sql = implode(',', $post_id_sql);
}
}
}
if ($post_id_sql && $split) {
//mpd end
$sql = "SELECT post_id, poster_id, topic_id, post_time
FROM " . BB_POSTS . "
WHERE post_id IN ($post_id_sql)
ORDER BY post_time ASC";
if (!($result = DB()->sql_query($sql))) {
bb_die('Could not get post information');
}
if ($row = DB()->sql_fetchrow($result)) {
$first_poster = $row['poster_id'];
$topic_id = $row['topic_id'];
$post_time = $row['post_time'];
$user_id_sql = '';
$post_id_sql = '';
do {
$user_id_sql .= (($user_id_sql != '') ? ', ' : '') . (int)$row['poster_id'];
$post_id_sql .= (($post_id_sql != '') ? ', ' : '') . (int)$row['post_id'];
} while ($row = DB()->sql_fetchrow($result));
$post_subject = clean_title($_POST['subject']);
if (empty($post_subject)) {
bb_die($lang['EMPTY_SUBJECT']);
}
$new_forum_id = (int)$_POST['new_forum_id'];
$topic_time = TIMENOW;
$sql = 'SELECT forum_id FROM ' . BB_FORUMS . ' WHERE forum_id = ' . $new_forum_id;
if (!($result = DB()->sql_query($sql))) {
bb_die('Could not select from forums table');
}
if (!DB()->sql_fetchrow($result)) {
bb_die('New forum does not exist');
}
DB()->sql_freeresult($result);
$first_post_id = min(explode(',', $post_id_sql));
$sql = "INSERT INTO " . BB_TOPICS . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_first_post_id)
VALUES ('" . DB()->escape($post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ", $first_post_id)";
if (!(DB()->sql_query($sql))) {
bb_die('Could not insert new topic');
}
$new_topic_id = DB()->sql_nextid();
// Update topic watch table, switch users whose posts
// have moved, over to watching the new topic
$sql = "UPDATE " . BB_TOPICS_WATCH . "
SET topic_id = $new_topic_id
WHERE topic_id = $topic_id
AND user_id IN ($user_id_sql)";
if (!DB()->sql_query($sql)) {
bb_die('Could not update topics watch table');
}
$sql_where = (!empty($_POST['split_type_beyond'])) ? " post_time >= $post_time AND topic_id = $topic_id" : "post_id IN ($post_id_sql)";
$sql = "UPDATE " . BB_POSTS . " SET topic_id = $new_topic_id, forum_id = $new_forum_id WHERE $sql_where";
if (!DB()->sql_query($sql)) {
bb_die('Could not update posts table');
}
//bot
if (isset($_POST['after_split_to_old'])) {
\TorrentPier\Legacy\Post::insert_post('after_split_to_old', $topic_id, $forum_id, '', $new_topic_id, trim($_POST['subject']));
}
if (isset($_POST['after_split_to_new'])) {
\TorrentPier\Legacy\Post::insert_post('after_split_to_new', $new_topic_id, $new_forum_id, $forum_id, $new_topic_id, '', $topic_id);
}
\TorrentPier\Legacy\Admin\Common::sync('topic', array($topic_id, $new_topic_id));
\TorrentPier\Legacy\Admin\Common::sync('forum', array($forum_id, $new_forum_id));
//bot
$message = $lang['TOPIC_SPLIT'] . '<br /><br /><a href="' . "viewtopic.php?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'] . '">' . $lang['TOPIC_SPLIT_OLD'] . '</a>';
$message .= ' :: <a href="' . "viewtopic.php?" . POST_TOPIC_URL . "=$new_topic_id&sid=" . $userdata['session_id'] . '">' . $lang['TOPIC_SPLIT_NEW'] . '</a>';
// Log action
$log_action->mod('mod_topic_split', array(
'forum_id' => $forum_id,
'forum_id_new' => $new_forum_id,
'topic_id' => $topic_id,
'topic_title' => get_topic_title($topic_id),
'topic_id_new' => $new_topic_id,
'topic_title_new' => htmlCHR($_POST['subject']),
));
bb_die($message);
}
} elseif ($post_id_sql && $delete_posts) {
if (!$is_auth['auth_delete']) {
bb_die(sprintf($lang['SORRY_AUTH_DELETE'], $is_auth['auth_delete_type']));
}
// Delete posts
$result = \TorrentPier\Legacy\Admin\Common::post_delete(explode(',', $post_id_sql));
$msg = ($result) ? $lang['DELETE_POSTS_SUCCESFULLY'] : 'No posts were removed';
bb_die(return_msg_mcp($msg));
} else {
$sql = "SELECT u.username, p.*, pt.post_text, p.post_username
FROM " . BB_POSTS . " p, " . BB_USERS . " u, " . BB_POSTS_TEXT . " pt
WHERE p.topic_id = $topic_id
AND p.poster_id = u.user_id
AND p.post_id = pt.post_id
ORDER BY p.post_time ASC";
if (!($result = DB()->sql_query($sql))) {
bb_die('Could not get topic / post information');
}
$s_hidden_fields = '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" /><input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" /><input type="hidden" name="mode" value="split" />';
if (($total_posts = DB()->num_rows($result)) > 0) {
$postrow = DB()->sql_fetchrowset($result);
$template->assign_vars(array(
'FORUM_NAME' => htmlCHR($forum_name),
'U_VIEW_FORUM' => FORUM_URL . $forum_id,
'S_SPLIT_ACTION' => 'modcp.php',
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'S_FORUM_SELECT' => get_forum_select('admin', 'new_forum_id', $forum_id),
));
for ($i = 0; $i < $total_posts; $i++) {
$post_id = $postrow[$i]['post_id'];
$poster_id = $postrow[$i]['poster_id'];
$poster = $postrow[$i]['username'];
$post_date = bb_date($postrow[$i]['post_time']);
$message = $postrow[$i]['post_text'];
//
// If the board has HTML off but the post has HTML
// on then we process it, else leave it alone
//
$message = bbcode2html($message);
$row_class = !($i % 2) ? 'row1' : 'row2';
$template->assign_block_vars('postrow', array(
'ROW_CLASS' => $row_class,
'POSTER_NAME' => wbr($poster),
'POST_DATE' => $post_date,
'MESSAGE' => $message,
'CHECKBOX' => (defined('BEGIN_CHECKBOX')) ? true : false,
'POST_ID' => $post_id,
'ROW_ID' => $i,
'CB_ID' => 'cb_' . $i,
));
if ($post_id == $topic_first_post_id) {
define('BEGIN_CHECKBOX', true);
}
}
}
}
$template->set_filenames(array('body' => 'modcp_split.tpl'));
break;
case 'ip':
$anon = GUEST_UID;
if (!$post_id) {
bb_die($lang['NO_SUCH_POST']);
}
// Look up relevant data for this post
$sql = "SELECT * FROM " . BB_POSTS . " WHERE post_id = $post_id AND forum_id = $forum_id";
if (!($result = DB()->sql_query($sql))) {
bb_die('Could not get poster IP information');
}
if (!($post_row = DB()->sql_fetchrow($result))) {
bb_die($lang['NO_SUCH_POST']);
}
if (!$ip_this_post = decode_ip($post_row['poster_ip'])) {
$ip_this_post = $lang['NOT_AVAILABLE'];
}
$poster_id = $post_row['poster_id'];
$template->assign_vars(array(
'TPL_MODCP_IP' => true,
'IP' => $ip_this_post,
'U_LOOKUP_IP' => "modcp.php?mode=ip&" . POST_POST_URL . "=$post_id&" . POST_TOPIC_URL . "=$topic_id&rdns=$ip_this_post&sid=" . $userdata['session_id'],
));
//
// Get other IP's this user has posted under
//
$where_sql = ($poster_id == $anon) ? "post_username = '{$post_row['post_username']}'" : "poster_id = $poster_id";
$sql = "SELECT poster_ip, COUNT(*) AS postings FROM " . BB_POSTS . " WHERE $where_sql GROUP BY poster_ip ORDER BY postings DESC LIMIT 100";
if (!($result = DB()->sql_query($sql))) {
bb_die('Could not get IP information for this user');
}
if ($row = DB()->sql_fetchrow($result)) {
$i = 0;
do {
if ($row['poster_ip'] == $post_row['poster_ip']) {
$template->assign_vars(array(
'POSTS' => $row['postings'],
));
continue;
}
if (!$ip = decode_ip($row['poster_ip'])) {
$ip = $lang['NOT_AVAILABLE'];
}
$template->assign_block_vars('iprow', array(
'ROW_CLASS' => !($i % 2) ? 'row4' : 'row5',
'IP' => $ip,
'POSTS' => $row['postings'],
'U_LOOKUP_IP' => "modcp.php?mode=ip&" . POST_POST_URL . "=$post_id&" . POST_TOPIC_URL . "=$topic_id&rdns=" . $row['poster_ip'] . "&sid=" . $userdata['session_id'],
));
$i++;
} while ($row = DB()->sql_fetchrow($result));
}
//
// Get other users who've posted under this IP
//
$sql = "SELECT
u.user_id,
IF(u.user_id = $anon, p.post_username, u.username) AS username,
COUNT(*) as postings
FROM " . BB_USERS . " u, " . BB_POSTS . " p
WHERE p.poster_id = u.user_id
AND p.poster_ip = '" . $post_row['poster_ip'] . "'
GROUP BY u.user_id, p.post_username
ORDER BY postings DESC
LIMIT 100";
if (!($result = DB()->sql_query($sql))) {
bb_die('Could not get posters information based on IP');
}
if ($row = DB()->sql_fetchrow($result)) {
$i = 0;
do {
$id = $row['user_id'];
$username = (!$row['username']) ? $lang['GUEST'] : $row['username'];
$template->assign_block_vars('userrow', array(
'ROW_CLASS' => !($i % 2) ? 'row4' : 'row5',
'USERNAME' => wbr($username),
'POSTS' => $row['postings'],
'U_PROFILE' => ($id == GUEST_UID) ? "modcp.php?mode=ip&p=$post_id&t=$topic_id" : PROFILE_URL . $id,
'U_SEARCHPOSTS' => "search.php?search_author=1&uid=$id",
));
$i++;
} while ($row = DB()->sql_fetchrow($result));
}
$template->set_filenames(array('body' => 'modcp.tpl'));
break;
case 'post_pin':
case 'post_unpin':
$pin = ($mode == 'post_pin');
$new_topic_status = ($pin) ? 1 : 0;
if (count($topic_csv)) {
$sql = "
SELECT topic_id, topic_title
FROM " . BB_TOPICS . "
WHERE topic_id IN($topic_csv)
AND forum_id = $forum_id
AND topic_show_first_post != " . TOPIC_MOVED . "
AND topic_show_first_post != $new_topic_status
";
$topic_csv = array();
foreach (DB()->fetch_rowset($sql) as $row) {
$topic_csv[] = $row['topic_id'];
$log_topics[$row['topic_id']] = $row['topic_title'];
}
if (!$topic_csv = get_id_csv($topic_csv)) {
bb_die($lang['NONE_SELECTED']);
}
DB()->query("
UPDATE " . BB_TOPICS . " SET
topic_show_first_post = $new_topic_status
WHERE topic_id IN($topic_csv)
");
$msg = ($pin) ? $lang['POST_PINNED'] : $lang['POST_UNPINNED'];
bb_die(return_msg_mcp($msg));
} elseif ($topic_id) {
$sql = "
SELECT topic_id, topic_title
FROM " . BB_TOPICS . "
WHERE topic_id = $topic_id
AND forum_id = $forum_id
AND topic_show_first_post != " . TOPIC_MOVED . "
AND topic_show_first_post != $new_topic_status
LIMIT 1
";
$topic_csv = array();
foreach (DB()->fetch_rowset($sql) as $row) {
$topic_csv[] = $row['topic_id'];
$log_topics[$row['topic_id']] = $row['topic_title'];
}
if (!$topic_csv = get_id_csv($topic_csv)) {
bb_die($lang['NONE_SELECTED']);
}
DB()->query("
UPDATE " . BB_TOPICS . " SET
topic_show_first_post = $new_topic_status
WHERE topic_id IN($topic_csv)
");
$msg = ($pin) ? $lang['POST_PINNED'] : $lang['POST_UNPINNED'];
bb_die(return_msg_mcp($msg));
}
break;
default:
bb_die('invalid action');
break;
}
$template->assign_vars(array('PAGE_TITLE' => $lang['MOD_CP']));
require(PAGE_HEADER);
$template->pparse('body');
require(PAGE_FOOTER);