forked from mybb/mybb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlhttp.php
1161 lines (988 loc) · 32.4 KB
/
xmlhttp.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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
/**
* The deal with this file is that it handles all of the XML HTTP Requests for MyBB.
*
* It contains a stripped down version of the MyBB core which does not load things
* such as themes, who's online data, all of the language packs and more.
*
* This is done to make response times when using XML HTTP Requests faster and
* less intense on the server.
*/
define("IN_MYBB", 1);
// We don't want visits here showing up on the Who's Online
define("NO_ONLINE", 1);
define('THIS_SCRIPT', 'xmlhttp.php');
// Load MyBB core files
require_once dirname(__FILE__)."/inc/init.php";
$shutdown_queries = $shutdown_functions = array();
// Load some of the stock caches we'll be using.
$groupscache = $cache->read("usergroups");
if(!is_array($groupscache))
{
$cache->update_usergroups();
$groupscache = $cache->read("usergroups");
}
// Send no cache headers
header("Expires: Sat, 1 Jan 2000 01:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
// Create the session
require_once MYBB_ROOT."inc/class_session.php";
$session = new session;
$session->init();
// Load the language we'll be using
if(!isset($mybb->settings['bblanguage']))
{
$mybb->settings['bblanguage'] = "english";
}
if(isset($mybb->user['language']) && $lang->language_exists($mybb->user['language']))
{
$mybb->settings['bblanguage'] = $mybb->user['language'];
}
$lang->set_language($mybb->settings['bblanguage']);
if(function_exists('mb_internal_encoding') && !empty($lang->settings['charset']))
{
@mb_internal_encoding($lang->settings['charset']);
}
// Load the theme
// 1. Check cookies
if(!$mybb->user['uid'] && !empty($mybb->cookies['mybbtheme']))
{
$mybb->user['style'] = (int)$mybb->cookies['mybbtheme'];
}
// 2. Load style
if(isset($mybb->user['style']) && (int)$mybb->user['style'] != 0)
{
$loadstyle = "tid='".(int)$mybb->user['style']."'";
}
else
{
$loadstyle = "def='1'";
}
// Load basic theme information that we could be needing.
if($loadstyle != "def='1'")
{
$query = $db->simple_select('themes', 'name, tid, properties, allowedgroups', $loadstyle, array('limit' => 1));
$theme = $db->fetch_array($query);
if($theme && !is_member($theme['allowedgroups']) && $theme['allowedgroups'] != 'all')
{
if(isset($mybb->cookies['mybbtheme']))
{
my_unsetcookie('mybbtheme');
}
$loadstyle = "def='1'";
}
}
if($loadstyle == "def='1'")
{
if(!$cache->read('default_theme'))
{
$cache->update_default_theme();
}
$theme = $cache->read('default_theme');
}
// No theme was found - we attempt to load the master or any other theme
if(!isset($theme['tid']) || isset($theme['tid']) && !$theme['tid'])
{
// Missing theme was from a user, run a query to set any users using the theme to the default
$db->update_query('users', array('style' => 0), "style = '{$mybb->user['style']}'");
// Attempt to load the master or any other theme if the master is not available
$query = $db->simple_select('themes', 'name, tid, properties, stylesheets', '', array('order_by' => 'tid', 'limit' => 1));
$theme = $db->fetch_array($query);
}
$theme = @array_merge($theme, my_unserialize($theme['properties']));
// Set the appropriate image language directory for this theme.
// Are we linking to a remote theme server?
if(my_validate_url($theme['imgdir']))
{
// If a language directory for the current language exists within the theme - we use it
if(!empty($mybb->user['language']))
{
$theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->user['language'];
}
else
{
// Check if a custom language directory exists for this theme
if(!empty($mybb->settings['bblanguage']))
{
$theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->settings['bblanguage'];
}
// Otherwise, the image language directory is the same as the language directory for the theme
else
{
$theme['imglangdir'] = $theme['imgdir'];
}
}
}
else
{
$img_directory = $theme['imgdir'];
if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))
{
$img_directory = rtrim($mybb->settings['cdnpath'], '/') . '/' . ltrim($theme['imgdir'], '/');
}
if(!@is_dir($img_directory))
{
$theme['imgdir'] = 'images';
}
// If a language directory for the current language exists within the theme - we use it
if(!empty($mybb->user['language']) && is_dir($img_directory.'/'.$mybb->user['language']))
{
$theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->user['language'];
}
else
{
// Check if a custom language directory exists for this theme
if(is_dir($img_directory.'/'.$mybb->settings['bblanguage']))
{
$theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->settings['bblanguage'];
}
// Otherwise, the image language directory is the same as the language directory for the theme
else
{
$theme['imglangdir'] = $theme['imgdir'];
}
}
$theme['imgdir'] = $mybb->get_asset_url($theme['imgdir']);
$theme['imglangdir'] = $mybb->get_asset_url($theme['imglangdir']);
}
$templatelist = "postbit_editedby,xmlhttp_buddyselect_online,xmlhttp_buddyselect_offline,xmlhttp_buddyselect";
$templates->cache($db->escape_string($templatelist));
if($lang->settings['charset'])
{
$charset = $lang->settings['charset'];
}
// If not, revert to UTF-8
else
{
$charset = "UTF-8";
}
$lang->load("global");
$lang->load("xmlhttp");
$closed_bypass = array("refresh_captcha", "validate_captcha");
$mybb->input['action'] = $mybb->get_input('action');
$plugins->run_hooks("xmlhttp");
// If the board is closed, the user is not an administrator and they're not trying to login, show the board closed message
if($mybb->settings['boardclosed'] == 1 && $mybb->usergroup['canviewboardclosed'] != 1 && !in_array($mybb->input['action'], $closed_bypass))
{
// Show error
if(!$mybb->settings['boardclosed_reason'])
{
$mybb->settings['boardclosed_reason'] = $lang->boardclosed_reason;
}
$lang->error_boardclosed .= "<br /><em>{$mybb->settings['boardclosed_reason']}</em>";
xmlhttp_error($lang->error_boardclosed);
}
// Fetch a list of usernames beginning with a certain string (used for auto completion)
if($mybb->input['action'] == "get_users")
{
$mybb->input['query'] = ltrim($mybb->get_input('query'));
$search_type = $mybb->get_input('search_type', MyBB::INPUT_INT); // 0: starts with, 1: ends with, 2: contains
// If the string is less than 2 characters, quit.
if(my_strlen($mybb->input['query']) < 2)
{
exit;
}
if($mybb->get_input('getone', MyBB::INPUT_INT) == 1)
{
$limit = 1;
}
else
{
$limit = 15;
}
// Send our headers.
header("Content-type: application/json; charset={$charset}");
// Query for any matching users.
$query_options = array(
"order_by" => "username",
"order_dir" => "asc",
"limit_start" => 0,
"limit" => $limit
);
$plugins->run_hooks("xmlhttp_get_users_start");
$likestring = $db->escape_string_like($mybb->input['query']);
if($search_type == 1)
{
$likestring = '%'.$likestring;
}
elseif($search_type == 2)
{
$likestring = '%'.$likestring.'%';
}
else
{
$likestring .= '%';
}
$query = $db->simple_select("users", "uid, username", "username LIKE '{$likestring}'", $query_options);
if($limit == 1)
{
$user = $db->fetch_array($query);
$data = array('uid' => $user['uid'], 'id' => $user['username'], 'text' => $user['username']);
}
else
{
$data = array();
while($user = $db->fetch_array($query))
{
$data[] = array('uid' => $user['uid'], 'id' => $user['username'], 'text' => $user['username']);
}
}
$plugins->run_hooks("xmlhttp_get_users_end");
echo json_encode($data);
exit;
}
// This action provides editing of thread/post subjects from within their respective list pages.
else if($mybb->input['action'] == "edit_subject" && $mybb->request_method == "post")
{
// Verify POST request
if(!verify_post_check($mybb->get_input('my_post_key'), true))
{
xmlhttp_error($lang->invalid_post_code);
}
// We're editing a thread subject.
if($mybb->get_input('tid', MyBB::INPUT_INT))
{
// Fetch the thread.
$thread = get_thread($mybb->get_input('tid', MyBB::INPUT_INT));
if(!$thread)
{
xmlhttp_error($lang->thread_doesnt_exist);
}
// Fetch some of the information from the first post of this thread.
$query_options = array(
"order_by" => "dateline, pid",
);
$query = $db->simple_select("posts", "pid,uid,dateline", "tid='".$thread['tid']."'", $query_options);
$post = $db->fetch_array($query);
}
else
{
exit;
}
// Fetch the specific forum this thread/post is in.
$forum = get_forum($thread['fid']);
// Missing thread, invalid forum? Error.
if(!$forum || $forum['type'] != "f")
{
xmlhttp_error($lang->thread_doesnt_exist);
}
// Fetch forum permissions.
$forumpermissions = forum_permissions($forum['fid']);
$plugins->run_hooks("xmlhttp_edit_subject_start");
// If this user is not a moderator with "caneditposts" permissions.
if(!is_moderator($forum['fid'], "caneditposts"))
{
// Thread is closed - no editing allowed.
if($thread['closed'] == 1)
{
xmlhttp_error($lang->thread_closed_edit_subjects);
}
// Forum is not open, user doesn't have permission to edit, or author doesn't match this user - don't allow editing.
else if($forum['open'] == 0 || $forumpermissions['caneditposts'] == 0 || $mybb->user['uid'] != $post['uid'] || $mybb->user['uid'] == 0)
{
xmlhttp_error($lang->no_permission_edit_subject);
}
// If we're past the edit time limit - don't allow editing.
else if($mybb->usergroup['edittimelimit'] != 0 && $post['dateline'] < (TIME_NOW-($mybb->usergroup['edittimelimit']*60)))
{
$lang->edit_time_limit = $lang->sprintf($lang->edit_time_limit, $mybb->usergroup['edittimelimit']);
xmlhttp_error($lang->edit_time_limit);
}
$ismod = false;
}
else
{
$ismod = true;
}
$subject = $mybb->get_input('value');
if(my_strtolower($charset) != "utf-8")
{
if(function_exists("iconv"))
{
$subject = iconv($charset, "UTF-8//IGNORE", $subject);
}
else if(function_exists("mb_convert_encoding"))
{
$subject = @mb_convert_encoding($subject, $charset, "UTF-8");
}
else if(my_strtolower($charset) == "iso-8859-1")
{
$subject = utf8_decode($subject);
}
}
// Only edit subject if subject has actually been changed
if($thread['subject'] != $subject)
{
// Set up posthandler.
require_once MYBB_ROOT."inc/datahandlers/post.php";
$posthandler = new PostDataHandler("update");
$posthandler->action = "post";
// Set the post data that came from the input to the $post array.
$updatepost = array(
"pid" => $post['pid'],
"tid" => $thread['tid'],
"fid" => $forum['fid'],
"prefix" => $thread['prefix'],
"subject" => $subject,
"edit_uid" => $mybb->user['uid']
);
$posthandler->set_data($updatepost);
// Now let the post handler do all the hard work.
if(!$posthandler->validate_post())
{
$post_errors = $posthandler->get_friendly_errors();
xmlhttp_error($post_errors);
}
// No errors were found, we can call the update method.
else
{
$posthandler->update_post();
if($ismod == true)
{
$modlogdata = array(
"tid" => $thread['tid'],
"fid" => $forum['fid']
);
log_moderator_action($modlogdata, $lang->edited_post);
}
}
}
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
// Send our headers.
header("Content-type: application/json; charset={$charset}");
$plugins->run_hooks("xmlhttp_edit_subject_end");
$mybb->input['value'] = $parser->parse_badwords($mybb->get_input('value'));
// Spit the subject back to the browser.
$subject = substr($mybb->input['value'], 0, 120); // 120 is the varchar length for the subject column
echo json_encode(array("subject" => '<a href="'.get_thread_link($thread['tid']).'">'.htmlspecialchars_uni($subject).'</a>'));
// Close the connection.
exit;
}
else if($mybb->input['action'] == "edit_post")
{
// Fetch the post from the database.
$post = get_post($mybb->get_input('pid', MyBB::INPUT_INT));
// No result, die.
if(!$post || $post['visible'] == -1)
{
xmlhttp_error($lang->post_doesnt_exist);
}
// Fetch the thread associated with this post.
$thread = get_thread($post['tid']);
// Fetch the specific forum this thread/post is in.
$forum = get_forum($thread['fid']);
// Missing thread, invalid forum? Error.
if(!$thread || !$forum || $forum['type'] != "f")
{
xmlhttp_error($lang->thread_doesnt_exist);
}
// Check if this forum is password protected and we have a valid password
if(check_forum_password($forum['fid'], 0, true))
{
xmlhttp_error($lang->wrong_forum_password);
}
// Fetch forum permissions.
$forumpermissions = forum_permissions($forum['fid']);
$plugins->run_hooks("xmlhttp_edit_post_start");
// If this user is not a moderator with "caneditposts" permissions.
if(!is_moderator($forum['fid'], "caneditposts"))
{
// Thread is closed - no editing allowed.
if($thread['closed'] == 1)
{
xmlhttp_error($lang->thread_closed_edit_message);
}
// Forum is not open, user doesn't have permission to edit, or author doesn't match this user - don't allow editing.
else if($forum['open'] == 0 || $forumpermissions['caneditposts'] == 0 || $mybb->user['uid'] != $post['uid'] || $mybb->user['uid'] == 0 || $mybb->user['suspendposting'] == 1)
{
xmlhttp_error($lang->no_permission_edit_post);
}
// If we're past the edit time limit - don't allow editing.
else if($mybb->usergroup['edittimelimit'] != 0 && $post['dateline'] < (TIME_NOW-($mybb->usergroup['edittimelimit']*60)))
{
$lang->edit_time_limit = $lang->sprintf($lang->edit_time_limit, $mybb->usergroup['edittimelimit']);
xmlhttp_error($lang->edit_time_limit);
}
// User can't edit unapproved post unless permitted for own
if($post['visible'] == 0 && !($mybb->settings['showownunapproved'] && $post['uid'] == $mybb->user['uid']))
{
xmlhttp_error($lang->post_moderation);
}
}
$plugins->run_hooks("xmlhttp_edit_post_end");
if($mybb->get_input('do') == "get_post")
{
// Send our headers.
header("Content-type: application/json; charset={$charset}");
// Send the contents of the post.
echo json_encode($post['message']);
exit;
}
else if($mybb->get_input('do') == "update_post")
{
// Verify POST request
if(!verify_post_check($mybb->get_input('my_post_key'), true))
{
xmlhttp_error($lang->invalid_post_code);
}
$message = $mybb->get_input('value');
$editreason = $mybb->get_input('editreason');
if(my_strtolower($charset) != "utf-8")
{
if(function_exists("iconv"))
{
$message = iconv($charset, "UTF-8//IGNORE", $message);
$editreason = iconv($charset, "UTF-8//IGNORE", $editreason);
}
else if(function_exists("mb_convert_encoding"))
{
$message = @mb_convert_encoding($message, $charset, "UTF-8");
$editreason = @mb_convert_encoding($editreason, $charset, "UTF-8");
}
else if(my_strtolower($charset) == "iso-8859-1")
{
$message = utf8_decode($message);
$editreason = utf8_decode($editreason);
}
}
// Set up posthandler.
require_once MYBB_ROOT."inc/datahandlers/post.php";
$posthandler = new PostDataHandler("update");
$posthandler->action = "post";
// Set the post data that came from the input to the $post array.
$updatepost = array(
"pid" => $post['pid'],
"message" => $message,
"editreason" => $editreason,
"edit_uid" => $mybb->user['uid']
);
// If this is the first post set the prefix. If a forum requires a prefix the quick edit would throw an error otherwise
if($post['pid'] == $thread['firstpost'])
{
$updatepost['prefix'] = $thread['prefix'];
}
$posthandler->set_data($updatepost);
// Now let the post handler do all the hard work.
if(!$posthandler->validate_post())
{
$post_errors = $posthandler->get_friendly_errors();
xmlhttp_error($post_errors);
}
// No errors were found, we can call the update method.
else
{
$postinfo = $posthandler->update_post();
$visible = $postinfo['visible'];
if($visible == 0 && !is_moderator($post['fid'], "canviewunapprove"))
{
// Is it the first post?
if($thread['firstpost'] == $post['pid'])
{
echo json_encode(array("moderation_thread" => $lang->thread_moderation, 'url' => $mybb->settings['bburl'].'/'.get_forum_link($thread['fid']), "message" => $post['message']));
exit;
}
else
{
echo json_encode(array("moderation_post" => $lang->post_moderation, 'url' => $mybb->settings['bburl'].'/'.get_thread_link($thread['tid']), "message" => $post['message']));
exit;
}
}
}
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
$parser_options = array(
"allow_html" => $forum['allowhtml'],
"allow_mycode" => $forum['allowmycode'],
"allow_smilies" => $forum['allowsmilies'],
"allow_imgcode" => $forum['allowimgcode'],
"allow_videocode" => $forum['allowvideocode'],
"me_username" => $post['username'],
"filter_badwords" => 1
);
$post['username'] = htmlspecialchars_uni($post['username']);
if($post['smilieoff'] == 1)
{
$parser_options['allow_smilies'] = 0;
}
if($mybb->user['uid'] != 0 && $mybb->user['showimages'] != 1 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
{
$parser_options['allow_imgcode'] = 0;
}
if($mybb->user['uid'] != 0 && $mybb->user['showvideos'] != 1 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0)
{
$parser_options['allow_videocode'] = 0;
}
$post['message'] = $parser->parse_message($message, $parser_options);
// Now lets fetch all of the attachments for these posts.
if($mybb->settings['enableattachments'] != 0)
{
$query = $db->simple_select("attachments", "*", "pid='{$post['pid']}'");
while($attachment = $db->fetch_array($query))
{
$attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
}
require_once MYBB_ROOT."inc/functions_post.php";
get_post_attachments($post['pid'], $post);
}
// Figure out if we need to show an "edited by" message
// Only show if at least one of "showeditedby" or "showeditedbyadmin" is enabled
if($mybb->settings['showeditedby'] != 0 && $mybb->settings['showeditedbyadmin'] != 0)
{
$post['editdate'] = my_date('relative', TIME_NOW);
$post['editnote'] = $lang->sprintf($lang->postbit_edited, $post['editdate']);
$mybb->user['username'] = htmlspecialchars_uni($mybb->user['username']);
$post['editedprofilelink'] = build_profile_link($mybb->user['username'], $mybb->user['uid']);
$post['editreason'] = trim($editreason);
$editreason = "";
if($post['editreason'] != "")
{
$post['editreason'] = $parser->parse_badwords($post['editreason']);
$post['editreason'] = htmlspecialchars_uni($post['editreason']);
eval("\$editreason = \"".$templates->get("postbit_editedby_editreason")."\";");
}
eval("\$editedmsg = \"".$templates->get("postbit_editedby")."\";");
}
// Send our headers.
header("Content-type: application/json; charset={$charset}");
$editedmsg_response = null;
if(!empty($editedmsg))
{
$editedmsg_response = str_replace(array("\r", "\n"), "", $editedmsg);
}
$plugins->run_hooks("xmlhttp_update_post");
echo json_encode(array("message" => $post['message']."\n", "editedmsg" => $editedmsg_response));
exit;
}
}
// Fetch the list of multiquoted posts which are not in a specific thread
else if($mybb->input['action'] == "get_multiquoted")
{
// If the cookie does not exist, exit
if(!array_key_exists("multiquote", $mybb->cookies))
{
exit;
}
// Divide up the cookie using our delimeter
$multiquoted = explode("|", $mybb->cookies['multiquote']);
$plugins->run_hooks("xmlhttp_get_multiquoted_start");
// No values - exit
if(!is_array($multiquoted))
{
exit;
}
// Loop through each post ID and sanitize it before querying
foreach($multiquoted as $post)
{
$quoted_posts[$post] = (int)$post;
}
// Join the post IDs back together
$quoted_posts = implode(",", $quoted_posts);
// Fetch unviewable forums
$unviewable_forums = get_unviewable_forums();
$inactiveforums = get_inactive_forums();
if($unviewable_forums)
{
$unviewable_forums = "AND t.fid NOT IN ({$unviewable_forums})";
}
if($inactiveforums)
{
$inactiveforums = "AND t.fid NOT IN ({$inactiveforums})";
}
// Check group permissions if we can't view threads not started by us
$group_permissions = forum_permissions();
$onlyusfids = array();
foreach($group_permissions as $gpfid => $forum_permissions)
{
if(isset($forum_permissions['canonlyviewownthreads']) && $forum_permissions['canonlyviewownthreads'] == 1)
{
$onlyusfids[] = $gpfid;
}
}
$message = '';
// Are we loading all quoted posts or only those not in the current thread?
if(empty($mybb->input['load_all']))
{
$from_tid = "p.tid != '".$mybb->get_input('tid', MyBB::INPUT_INT)."' AND ";
}
else
{
$from_tid = '';
}
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
require_once MYBB_ROOT."inc/functions_posting.php";
$plugins->run_hooks("xmlhttp_get_multiquoted_intermediate");
// Query for any posts in the list which are not within the specified thread
$query = $db->query("
SELECT p.subject, p.message, p.pid, p.tid, p.username, p.dateline, t.fid, t.uid AS thread_uid, p.visible, u.username AS userusername
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
WHERE {$from_tid}p.pid IN ({$quoted_posts}) {$unviewable_forums} {$inactiveforums}
ORDER BY p.dateline, p.pid
");
while($quoted_post = $db->fetch_array($query))
{
if(
(!is_moderator($quoted_post['fid'], "canviewunapprove") && $quoted_post['visible'] == 0) ||
(!is_moderator($quoted_post['fid'], "canviewdeleted") && $quoted_post['visible'] == -1) ||
(in_array($quoted_post['fid'], $onlyusfids) && (!$mybb->user['uid'] || $quoted_post['thread_uid'] != $mybb->user['uid']))
)
{
// Allow quoting from own unapproved post
if($quoted_post['visible'] == 0 && !($mybb->settings['showownunapproved'] && $quoted_post['uid'] == $mybb->user['uid']))
{
continue;
}
}
$message .= parse_quoted_message($quoted_post, false);
}
if($mybb->settings['maxquotedepth'] != '0')
{
$message = remove_message_quotes($message);
}
// Send our headers.
header("Content-type: application/json; charset={$charset}");
$plugins->run_hooks("xmlhttp_get_multiquoted_end");
echo json_encode(array("message" => $message));
exit;
}
else if($mybb->input['action'] == "refresh_captcha")
{
$imagehash = $db->escape_string($mybb->get_input('imagehash'));
$query = $db->simple_select("captcha", "dateline", "imagehash='$imagehash'");
if($db->num_rows($query) == 0)
{
xmlhttp_error($lang->captcha_not_exists);
}
$db->delete_query("captcha", "imagehash='$imagehash'");
$randomstr = random_str(5);
$imagehash = md5(random_str(12));
$regimagearray = array(
"imagehash" => $imagehash,
"imagestring" => $randomstr,
"dateline" => TIME_NOW
);
$plugins->run_hooks("xmlhttp_refresh_captcha");
$db->insert_query("captcha", $regimagearray);
header("Content-type: application/json; charset={$charset}");
echo json_encode(array("imagehash" => $imagehash));
exit;
}
else if($mybb->input['action'] == "validate_captcha")
{
header("Content-type: application/json; charset={$charset}");
$imagehash = $db->escape_string($mybb->get_input('imagehash'));
$query = $db->simple_select("captcha", "imagestring", "imagehash='$imagehash'");
if($db->num_rows($query) == 0)
{
echo json_encode($lang->captcha_valid_not_exists);
exit;
}
$imagestring = $db->fetch_field($query, 'imagestring');
$plugins->run_hooks("xmlhttp_validate_captcha");
if(my_strtolower($imagestring) == my_strtolower($mybb->get_input('imagestring')))
{
//echo json_encode(array("success" => $lang->captcha_matches));
echo json_encode("true");
exit;
}
else
{
echo json_encode($lang->captcha_does_not_match);
exit;
}
}
else if($mybb->input['action'] == "refresh_question" && $mybb->settings['securityquestion'])
{
header("Content-type: application/json; charset={$charset}");
$sid = $db->escape_string($mybb->get_input('question_id'));
$query = $db->query("
SELECT q.qid, s.sid
FROM ".TABLE_PREFIX."questionsessions s
LEFT JOIN ".TABLE_PREFIX."questions q ON (q.qid=s.qid)
WHERE q.active='1' AND s.sid='{$sid}'
");
if($db->num_rows($query) == 0)
{
xmlhttp_error($lang->answer_valid_not_exists);
}
$qsession = $db->fetch_array($query);
// Delete previous question session
$db->delete_query("questionsessions", "sid='$sid'");
require_once MYBB_ROOT."inc/functions_user.php";
$sid = generate_question($qsession['qid']);
$query = $db->query("
SELECT q.question, s.sid
FROM ".TABLE_PREFIX."questionsessions s
LEFT JOIN ".TABLE_PREFIX."questions q ON (q.qid=s.qid)
WHERE q.active='1' AND s.sid='{$sid}' AND q.qid!='{$qsession['qid']}'
");
$plugins->run_hooks("xmlhttp_refresh_question");
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
$parser_options = array(
"allow_html" => 0,
"allow_mycode" => 1,
"allow_smilies" => 1,
"allow_imgcode" => 1,
"allow_videocode" => 1,
"filter_badwords" => 1,
"me_username" => 0,
"shorten_urls" => 0,
"highlight" => 0,
);
if($db->num_rows($query) > 0)
{
$question = $db->fetch_array($query);
echo json_encode(array("question" => $parser->parse_message($question['question'], $parser_options), 'sid' => htmlspecialchars_uni($question['sid'])));
exit;
}
else
{
xmlhttp_error($lang->answer_valid_not_exists);
}
}
elseif($mybb->input['action'] == "validate_question" && $mybb->settings['securityquestion'])
{
header("Content-type: application/json; charset={$charset}");
$sid = $db->escape_string($mybb->get_input('question'));
$answer = $db->escape_string($mybb->get_input('answer'));
$query = $db->query("
SELECT q.*, s.sid
FROM ".TABLE_PREFIX."questionsessions s
LEFT JOIN ".TABLE_PREFIX."questions q ON (q.qid=s.qid)
WHERE q.active='1' AND s.sid='{$sid}'
");
if($db->num_rows($query) == 0)
{
echo json_encode($lang->answer_valid_not_exists);
exit;
}
else
{
$question = $db->fetch_array($query);
$valid_answers = preg_split("/\r\n|\n|\r/", $question['answer']);
$validated = 0;
foreach($valid_answers as $answers)
{
if(my_strtolower($answers) == my_strtolower($answer))
{
$validated = 1;
}
}
$plugins->run_hooks("xmlhttp_validate_question");
if($validated != 1)
{
echo json_encode($lang->answer_does_not_match);
exit;
}
else
{
echo json_encode("true");
exit;
}
}
exit;
}
else if($mybb->input['action'] == "complex_password")
{
$password = trim($mybb->get_input('password'));
$password = str_replace(array(unichr(160), unichr(173), unichr(0xCA), dec_to_utf8(8238), dec_to_utf8(8237), dec_to_utf8(8203)), array(" ", "-", "", "", "", ""), $password);
header("Content-type: application/json; charset={$charset}");
$plugins->run_hooks("xmlhttp_complex_password");
if(!preg_match("/^.*(?=.{".$mybb->settings['minpasswordlength'].",})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password))
{
echo json_encode($lang->complex_password_fails);
}
else
{
// Return nothing but an OK password if passes regex
echo json_encode("true");
}
exit;
}
else if($mybb->input['action'] == "username_availability")
{
if(!verify_post_check($mybb->get_input('my_post_key'), true))
{
xmlhttp_error($lang->invalid_post_code);
}
require_once MYBB_ROOT."inc/functions_user.php";
$username = $mybb->get_input('username');
// Fix bad characters
$username = trim_blank_chrs($username);
$username = str_replace(array(unichr(160), unichr(173), unichr(0xCA), dec_to_utf8(8238), dec_to_utf8(8237), dec_to_utf8(8203)), array(" ", "-", "", "", "", ""), $username);
// Remove multiple spaces from the username
$username = preg_replace("#\s{2,}#", " ", $username);
header("Content-type: application/json; charset={$charset}");
if(empty($username))
{
echo json_encode($lang->banned_characters_username);
exit;
}
// Check if the username belongs to the list of banned usernames.
$banned_username = is_banned_username($username, true);
if($banned_username)
{
echo json_encode($lang->banned_username);
exit;
}
// Check for certain characters in username (<, >, &, and slashes)
if(strpos($username, "<") !== false || strpos($username, ">") !== false || strpos($username, "&") !== false || my_strpos($username, "\\") !== false || strpos($username, ";") !== false || strpos($username, ",") !== false || !validate_utf8_string($username, false, false))
{
echo json_encode($lang->banned_characters_username);
exit;
}
// Check if the username is actually already in use
$user = get_user_by_username($username);
$plugins->run_hooks("xmlhttp_username_availability");
if($user)
{
$lang->username_taken = $lang->sprintf($lang->username_taken, htmlspecialchars_uni($username));
echo json_encode($lang->username_taken);
exit;
}