forked from trhoppe/roadraceautox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewreply.php
1349 lines (1192 loc) · 46.7 KB
/
newreply.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
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.2.0 Patch Level 3 - Licence Number VBFBED0615
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2012 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('GET_EDIT_TEMPLATES', true);
define('THIS_SCRIPT', 'newreply');
define('CSRF_PROTECTION', true);
if ($_POST['do'] == 'postreply')
{
if (isset($_POST['ajax']))
{
define('NOPMPOPUP', 1);
define('NOSHUTDOWNFUNC', 1);
}
if (isset($_POST['fromquickreply']))
{ // Don't update Who's Online for Quick Replies since it will get stuck on that until the user goes somewhere else
define('LOCATION_BYPASS', 1);
}
}
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
'threadmanage',
'posting',
'postbit',
'reputationlevel',
);
// get special data templates from the datastore
$specialtemplates = array(
'smiliecache',
'bbcodecache',
'ranks',
);
// pre-cache templates used by all actions
$globaltemplates = array(
'newreply',
'newpost_attachment',
'newreply_reviewbit',
'newreply_reviewbit_ignore',
'newreply_reviewbit_ignore_global',
'newpost_attachmentbit',
'im_aim',
'im_icq',
'im_msn',
'im_yahoo',
'im_skype',
'postbit',
'postbit_wrapper',
'postbit_attachment',
'postbit_attachmentimage',
'postbit_attachmentthumbnail',
'postbit_attachmentmoderated',
'postbit_ip',
'postbit_onlinestatus',
'bbcode_code',
'bbcode_html',
'bbcode_php',
'bbcode_quote',
'bbcode_video',
'humanverify',
'facebook_publishcheckbox'
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_newpost.php');
require_once(DIR . '/includes/functions_editor.php');
require_once(DIR . '/includes/functions_bigthree.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
verify_forum_url();
// ### STANDARD INITIALIZATIONS ###
$checked = array();
$newpost = array();
$postattach = array();
$contenttype = 'vBForum_Post';
// sanity checks...
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'newreply';
}
$vbulletin->input->clean_array_gpc('r', array(
'noquote' => TYPE_BOOL,
'quoteall' => TYPE_BOOL
));
($hook = vBulletinHook::fetch_hook('newreply_start')) ? eval($hook) : false;
// ### CHECK IF ALLOWED TO POST ###
if ($threadinfo['isdeleted'] OR (!$threadinfo['visible'] AND !can_moderate($threadinfo['forumid'], 'canmoderateposts')))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['thread'], $vbulletin->options['contactuslink'])));
}
if (!$foruminfo['allowposting'] OR $foruminfo['link'] OR !$foruminfo['cancontainthreads'])
{
eval(standard_error(fetch_error('forumclosed')));
}
if (!$threadinfo['open'])
{
if (!can_moderate($threadinfo['forumid'], 'canopenclose'))
{
$vbulletin->url = fetch_seo_url('thread', $threadinfo);
eval(standard_error(fetch_error('threadclosed')));
}
}
$forumperms = fetch_permissions($foruminfo['forumid']);
if (($vbulletin->userinfo['userid'] != $threadinfo['postuserid'] OR !$vbulletin->userinfo['userid']) AND (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyothers'])))
{
print_no_permission();
}
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyown']) AND $vbulletin->userinfo['userid'] == $threadinfo['postuserid']))
{
print_no_permission();
}
// check if there is a forum password and if so, ensure the user has it set
verify_forum_password($foruminfo['forumid'], $foruminfo['password']);
// *********************************************************************************
// Tachy goes to coventry
if (in_coventry($threadinfo['postuserid']) AND !can_moderate($threadinfo['forumid']))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['thread'], $vbulletin->options['contactuslink'])));
}
// ### GET QUOTE FEATURES (WITH MQ SUPPORT) ###
// This section must exist before $_POST[do] == postreply because of the $newpost stuff
$newpost['message'] = '';
$unquoted_posts = 0;
$multiquote_empty = '';
$specifiedpost = 0;
if ($_REQUEST['do'] == 'newreply')
{
$vbulletin->input->clean_array_gpc('c', array(
'vbulletin_multiquote' => TYPE_STR
));
$vbulletin->input->clean_array_gpc('r', array(
'return_node' => TYPE_UINT
));
if ($vbulletin->options['multiquote'] AND !empty($vbulletin->GPC['vbulletin_multiquote']))
{
$quote_postids = explode(',', $vbulletin->GPC['vbulletin_multiquote']);
}
else
{
$quote_postids = array();
}
// quote the last post only if: don't want to skip it, specified a post,
// and post can be seen (visible or you're a mod)
if (!$vbulletin->GPC['noquote'] AND $postid AND
(
($postinfo['visible'] == 1 AND $threadinfo['visible'] == 1) OR
(
($threadinfo['visible'] == 0 OR $postinfo['visible'] == 0) AND
can_moderate($foruminfo['forumid'], 'canmoderateposts')
)
)
)
{
$quote_postids[] = $postinfo['postid'];
// fetch the quoted post title
$newpost['title'] = htmlspecialchars_uni(vbchop(fetch_quote_title($postinfo['title'], $threadinfo['title']), $vbulletin->options['titlemaxchars']));
$specifiedpost = 1; // the post we're replying to we explicitly picked
}
else
{
$newpost['title'] = htmlspecialchars_uni(vbchop(fetch_quote_title('', $threadinfo['title']), $vbulletin->options['titlemaxchars']));
}
if ($quote_postids)
{
$newpost['message'] = fetch_quotable_posts($quote_postids, $threadinfo['threadid'], $unquoted_post_count, $quoted_post_ids, 'only');
$quote_count = count($quoted_post_ids);
if ($quote_count > 1 OR ($quote_count == 1 AND $vbulletin->GPC['noquote']) OR ($quote_count == 1 AND $quoted_post_ids[0] != $postinfo['postid']))
{
// quoting more than one post, one post and noquote is set, or one post that isn't this post -- using MQ,
// so when we post, remove the posts from the MQ cookie that are in this thread
$multiquote_empty = 'only';
}
}
}
// ############################### start unquoted posts ###############################
if ($_POST['do'] == 'unquotedposts')
{
$vbulletin->input->clean_array_gpc('c', array(
'vbulletin_multiquote' => TYPE_STR
));
$vbulletin->input->clean_array_gpc('p', array(
'wysiwyg' => TYPE_BOOL,
'type' => TYPE_STR
));
$quote_postids = explode(',', $vbulletin->GPC['vbulletin_multiquote']);
require_once(DIR . '/includes/class_xml.php');
$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
$quote_text = fetch_quotable_posts($quote_postids, $threadinfo['threadid'], $unquoted_post_count, $quoted_post_ids, 'other', true);
if ($vbulletin->GPC['type'] == 'deselect')
{
$remaining = array_diff($quote_postids, $quoted_post_ids);
$xml->add_tag('mqpostids', implode(',', $remaining));
//setcookie('vbulletin_multiquote', implode(',', $remaining), 0, '/');
}
else
{
if ($vbulletin->GPC['wysiwyg'])
{
require_once(DIR . '/includes/class_wysiwygparser.php');
$html_parser = new vB_WysiwygHtmlParser($vbulletin);
$quote_text = $html_parser->parse_wysiwyg_html(htmlspecialchars_uni($quote_text), false, $threadinfo['forumid'], ($foruminfo['allowsmilies'] ? 1 : 0));
}
$xml->add_tag('quotes', process_replacement_vars($quote_text));
}
$xml->print_xml();
}
// ############################### start post reply ###############################
if ($_POST['do'] == 'postreply')
{
// Variables reused in templates
$posthash =& $vbulletin->input->clean_gpc('p', 'posthash', TYPE_NOHTML);
$poststarttime =& $vbulletin->input->clean_gpc('p', 'poststarttime', TYPE_UINT);
$vbulletin->input->clean_array_gpc('p', array(
'wysiwyg' => TYPE_BOOL,
'message' => TYPE_STR,
'quickreply' => TYPE_BOOL,
'fromquickreply' => TYPE_BOOL,
'ajaxqrfailed' => TYPE_BOOL,
'folderid' => TYPE_UINT,
'emailupdate' => TYPE_UINT,
'htmlstate' => TYPE_STR,
'subscribe' => TYPE_BOOL,
'title' => TYPE_STR,
'iconid' => TYPE_UINT,
'parseurl' => TYPE_BOOL,
'signature' => TYPE_BOOL,
'preview' => TYPE_STR,
'disablesmilies' => TYPE_BOOL,
'username' => TYPE_STR,
'rate' => TYPE_BOOL,
'rating' => TYPE_UINT,
'stickunstick' => TYPE_BOOL,
'openclose' => TYPE_BOOL,
'ajax' => TYPE_BOOL,
'ajax_lastpost' => TYPE_INT,
'loggedinuser' => TYPE_INT,
'humanverify' => TYPE_ARRAY,
'multiquoteempty'=> TYPE_NOHTML,
'specifiedpost' => TYPE_BOOL,
'return_node' => TYPE_UINT,
));
if ($vbulletin->GPC['loggedinuser'] != 0 AND $vbulletin->userinfo['userid'] == 0)
{
// User was logged in when writing post but isn't now. If we got this
// far, guest posts are allowed, but they didn't enter a username so
// they'll get an error. Force them to log back in.
standard_error(fetch_error('session_timed_out_login'), '', false, 'STANDARD_ERROR_LOGIN');
}
($hook = vBulletinHook::fetch_hook('newreply_post_start')) ? eval($hook) : false;
// ### PREP INPUT ###
if ($vbulletin->GPC['wysiwyg'])
{
require_once(DIR . '/includes/class_wysiwygparser.php');
$html_parser = new vB_WysiwygHtmlParser($vbulletin);
$newpost['message'] = $html_parser->parse_wysiwyg_html_to_bbcode($vbulletin->GPC['message'], $foruminfo['allowhtml']);
}
else
{
$newpost['message'] = $vbulletin->GPC['message'];
}
if ($vbulletin->GPC['ajax'])
{
// posting via ajax so we need to handle those %u0000 entries
$newpost['message'] = convert_urlencoded_unicode($newpost['message']);
}
if ($vbulletin->GPC['quickreply'])
{
$originalposter = fetch_quote_username($postinfo['username'] . ";$postinfo[postid]");
$pagetext = trim(strip_quotes($postinfo['pagetext']));
($hook = vBulletinHook::fetch_hook('newreply_post_quote')) ? eval($hook) : false;
$templater = vB_Template::create('newpost_quote');
$templater->register('originalposter', $originalposter);
$templater->register('pagetext', $pagetext);
$quotemessage = $templater->render(true);
$newpost['message'] = trim($quotemessage) . "\n$newpost[message]";
}
if ($vbulletin->GPC['fromquickreply'])
{
// We only add notifications to threads that don't have one if the user defaults to it, do nothing else!
if ($vbulletin->userinfo['autosubscribe'] != -1 AND !$threadinfo['issubscribed'])
{
$vbulletin->GPC['folderid'] = 0;
$vbulletin->GPC['emailupdate'] = $vbulletin->userinfo['autosubscribe'];
}
else if ($threadinfo['issubscribed'])
{ // Don't alter current settings
$vbulletin->GPC['folderid'] = $threadinfo['folderid'];
$vbulletin->GPC['emailupdate'] = $threadinfo['emailupdate'];
}
else
{ // Don't don't add!
$vbulletin->GPC['emailupdate'] = 9999;
}
// fetch the quoted post title
$vbulletin->GPC['title'] = fetch_quote_title($postinfo['title'], $threadinfo['title']);
}
$newpost['title'] =& $vbulletin->GPC['title'];
$newpost['iconid'] =& $vbulletin->GPC['iconid'];
$newpost['parseurl'] = (($vbulletin->options['allowedbbcodes'] & ALLOW_BBCODE_URL) AND $foruminfo['allowbbcode'] AND $vbulletin->GPC['parseurl']);
$newpost['signature'] =& $vbulletin->GPC['signature'];
$newpost['preview'] =& $vbulletin->GPC['preview'];
$newpost['disablesmilies'] =& $vbulletin->GPC['disablesmilies'];
$newpost['rating'] =& $vbulletin->GPC['rating'];
$newpost['rate'] =& $newpost['rating'];
$newpost['username'] =& $vbulletin->GPC['username'];
$newpost['folderid'] =& $vbulletin->GPC['folderid'];
$newpost['quickreply'] =& $vbulletin->GPC['quickreply'];
$newpost['poststarttime'] =& $poststarttime;
$newpost['posthash'] =& $posthash;
$newpost['humanverify'] =& $vbulletin->GPC['humanverify'];
// moderation options
$newpost['stickunstick'] =& $vbulletin->GPC['stickunstick'];
$newpost['openclose'] =& $vbulletin->GPC['openclose'];
$newpost['subscribe'] =& $vbulletin->GPC['subscribe'];
$newpost['ajaxqrfailed'] = $vbulletin->GPC['ajaxqrfailed'];
if ($vbulletin->GPC['ajax'] AND $newpost['username'])
{
if ($newpost['username'])
{
$newpost['username'] = convert_urlencoded_unicode($newpost['username']);
}
}
if ($foruminfo['allowhtml'])
{
$htmlchecked = fetch_htmlchecked($vbulletin->GPC['htmlstate']);
$newpost['htmlstate'] = array_pop($array = array_keys(fetch_htmlchecked($vbulletin->GPC['htmlstate'])));
}
else
{
$newpost['htmlstate'] = 'on_nl2br';
}
if ($vbulletin->GPC_exists['emailupdate'])
{
$newpost['emailupdate'] = $vbulletin->GPC['emailupdate'];
}
else
{
$newpost['emailupdate'] = array_pop($array = array_keys(fetch_emailchecked($threadinfo, $vbulletin->userinfo)));
}
if (!$vbulletin->GPC['subscribe'] AND !$vbulletin->GPC['fromquickreply'])
{
$newpost['emailupdate'] = 9999;
}
if ($vbulletin->GPC['specifiedpost'] AND $postinfo)
{
$postinfo['specifiedpost'] = true;
}
// Scan post for [attach] tags
$attachid = array();
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment'] AND $vbulletin->userinfo['userid'] AND !empty($vbulletin->userinfo['attachmentextensions']))
{
if (preg_match_all('#\[attach(?:=(right|left|config))?\](\d+)\[/attach\]#i', $newpost['message'], $matches) AND $matches[2])
{
foreach($matches[2] AS $key => $attachmentid)
{
$attachid[] = $attachmentid;
}
}
}
$cms_redirect = false;
$cms_comment_thread = false;
if ($vbulletin->GPC_exists['return_node'] AND $vbulletin->GPC['return_node'])
{
if (verify_threadNode($threadinfo['threadid'], $vbulletin->GPC['return_node']))
{
$cms_redirect = true;
$cms_comment_thread = true;
}
else // Something fishy - the threadid and nodeid dont match.
{
print_no_permission();
}
}
else if ($node = get_nodeFromThreadid($threadinfo['threadid']))
{
$cms_comment_thread = true;
$vbulletin->GPC['return_node'] = $node;
}
build_new_post('reply', $foruminfo, $threadinfo, $postinfo, $newpost, $errors);
$multiquote_empty = $vbulletin->GPC['multiquoteempty']; // cleaned to nohtml above
$specifiedpost = ($vbulletin->GPC['specifiedpost'] ? 1 : 0); // keep the sent value (for automoderation stuff)
if (sizeof($errors) > 0)
{
// ### POST HAS ERRORS ###
if ($vbulletin->GPC['ajax'])
{
require_once(DIR . '/includes/class_xml.php');
$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
$xml->add_group('errors');
foreach ($errors AS $error)
{
$xml->add_tag('error', $error);
}
$xml->close_group();
$xml->print_xml(true);
}
else
{
$postpreview = construct_errors($errors); // this will take the preview's place
construct_checkboxes($newpost);
$_REQUEST['do'] = 'newreply';
$newpost['message'] = htmlspecialchars_uni($newpost['message']);
}
}
else if ($newpost['preview'])
{
if ($vbulletin->options['multiquote'])
{
$vbulletin->input->clean_array_gpc('c', array(
'vbulletin_multiquote' => TYPE_STR
));
$quote_postids = explode(',', $vbulletin->GPC['vbulletin_multiquote']);
}
else
{
$quote_postids = array();
}
if ($quote_postids)
{
fetch_quotable_posts($quote_postids, $threadinfo['threadid'], $unquoted_post_count, $quoted_post_ids);
// handle MQ VBIV-388
$multiquote_empty = 'only';
}
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment'] AND $vbulletin->userinfo['userid'] AND !empty($vbulletin->userinfo['attachmentextensions']))
{
require_once(DIR . '/packages/vbattach/attach.php');
$attach = new vB_Attach_Display_Content($vbulletin, 'vBForum_Post');
$postattach = $attach->fetch_postattach($posthash, 0, $postinfo['userid'], true, $attachid);
}
// ### PREVIEW POST ###
$postpreview = process_post_preview($newpost, 0, $postattach['bycontent'][0], $postattach['byattachment']);
$_REQUEST['do'] = 'newreply';
$newpost['message'] = htmlspecialchars_uni($newpost['message']);
}
else
{
// ### NOT PREVIEW - ACTUAL POST ###
if ($vbulletin->options['threadmarking'] AND $vbulletin->userinfo['userid'])
{
$threadview = max($threadinfo['threadread'], $threadinfo['forumread'], TIMENOW - ($vbulletin->options['markinglimit'] * 86400));
}
else
{
$threadview = intval(fetch_bbarray_cookie('thread_lastview', $thread['threadid']));
if (!$threadview)
{
$threadview = $vbulletin->userinfo['lastvisit'];
}
}
$newpostid = $newpost['postid'];
if ($cms_comment_thread)
{
// Expire any CMS comments cache entries.
$expire_cache = array('cms_comments_change');
$expire_cache[] = 'cms_comments_change_' . $threadinfo['threadid'];
$expire_cache[] = 'cms_comments_add_' . $vbulletin->GPC['return_node'];
vB_Cache::instance()->eventPurge($expire_cache);
vB_Cache::instance()->cleanNow();
$cms_url = vBCms_Route_Content::getURL(array('node' => $vbulletin->GPC['return_node']));
$join = strpos($cms_url,'?') ? '&' : '?';
$cms_url .= "{$join}postid={$newpostid}#comments_{$newpostid}";
$cms_url = str_ireplace('&', '&', $cms_url);
}
if ($vbulletin->GPC['ajax'])
{
// #############################################################################
// #############################################################################
// #############################################################################
require_once(DIR . '/includes/class_postbit.php');
require_once(DIR . '/includes/class_xml.php');
$postcount = 0;
$thread =& $threadinfo;
$forum =& $foruminfo;
if ($cms_redirect)
{ /* This is a CMS comment. We got here by posting from an article etc. */
$postbit_factory = new vB_Postbit_Factory();
$postbit_factory->registry =& $vbulletin;
$postbit_factory->forum =& $foruminfo;
$postbit_factory->thread =& $thread;
$postbit_factory->cache = array();
$postbit_factory->bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$postbit_factory->bbcode_parser->set_quote_template('vbcms_bbcode_quote');
$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
$xml->add_group('postbits');
$postbit_obj = $postbit_factory->fetch_postbit('post');
$postbit_obj->set_template_prefix('vbcms_');
($hook = vBulletinHook::fetch_hook('newreply_post_ajax')) ? eval($hook) : false;
if ($newpost['doublepost'])
{
$vbulletin->GPC['ajax_lastpost'] = 0;
}
$posts = $db->query_read("
SELECT
post.*, post.username AS postusername, post.ipaddress AS ip, IF(post.visible = 2, 1, 0) AS isdeleted,
user.*, userfield.*, usertextfield.*,
" . iif($vbulletin->options['avatarenabled'], 'avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight,') . "
" . iif($deljoin, 'deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason,') . "
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
" . iif(!($permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseehiddencustomfields']), $vbulletin->profilefiled['hidden']) . "
FROM " . TABLE_PREFIX . "post AS post
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = post.userid)
LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON(userfield.userid = user.userid)
LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)
" . iif($vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)") . "
WHERE post.threadid = $threadinfo[threadid] AND post.parentid != 0 AND " . (
($lastviewed = $vbulletin->GPC['ajax_lastpost']) ?
"post.dateline > $lastviewed AND (post.visible = 1 OR post.postid = $newpost[postid])" :
"post.postid = $newpost[postid]"
) . "
ORDER BY dateline
");
$cms_template = vB_Template::create('vbcms_comments_detail');
while ($post = $db->fetch_array($posts))
{
if ($vbulletin->options['avatarenabled']
AND $vbulletin->userinfo['showavatars']
AND !$post['hascustomavatar'] AND !$post['avatarid'])
{
$post['hascustomavatar'] = 1;
$post['avatarid'] = true;
$post['avatarurl'] = $post['avatarpath'] = vB_Template_Runtime::fetchStyleVar('imgdir_misc') . '/unknown.gif';
$post['avwidth'] = 60;
$post['avheight'] = 60;
}
if ($tachyuser = in_coventry($post['userid'])
AND !can_moderate($threadinfo['forumid']))
{
continue;
}
($hook = vBulletinHook::fetch_hook('showthread_postbit_create')) ? eval($hook) : false;
if ($newpost['doublepost'])
{
$xml->add_tag('updatepost', $newpost['postid']);
}
$postcount++;
$this_postbit = process_replacement_vars($postbit_obj->construct_postbit($post));
$cms_template->register('postid', $post['postid'] );
$cms_template->register('postbit', $this_postbit);
$xml->add_tag('postbit', $cms_template->render(), array('postid' => $post['postid']));
}
}
else
{
// work out if quickreply should be shown or not
if (
$vbulletin->options['quickreply']
AND
!$thread['isdeleted'] AND !is_browser('netscape') AND $vbulletin->userinfo['userid']
AND (
($vbulletin->userinfo['userid'] == $threadinfo['postuserid'] AND $forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyown'])
OR
($vbulletin->userinfo['userid'] != $threadinfo['postuserid'] AND $forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyothers'])
) AND
($thread['open'] OR can_moderate($threadinfo['forumid'], 'canopenclose'))
)
{
$show['quickreply'] = true;
}
else
{
$show['quickreply'] = false;
$show['wysiwyg'] = 0;
$quickreply = '';
}
if (!$forum['allowposting'])
{
$show['quickreply'] = false;
}
$show['managepost'] = iif(can_moderate($threadinfo['forumid'], 'candeleteposts') OR can_moderate($threadinfo['forumid'], 'canremoveposts'), true, false);
$show['approvepost'] = (can_moderate($threadinfo['forumid'], 'canmoderateposts')) ? true : false;
$show['managethread'] = can_moderate($threadinfo['forumid'], 'canmanagethreads') ? true : false;
$show['inlinemod'] = ($show['managethread'] OR $show['managepost'] OR $show['approvepost']) ? true : false;
$show['multiquote_global'] = ($vbulletin->options['multiquote'] AND $vbulletin->userinfo['userid']);
if ($show['multiquote_global'])
{
$vbulletin->input->clean_array_gpc('c', array(
'vbulletin_multiquote' => TYPE_STR
));
// remove all posts from this thread from the cookie, but leave all the others
$quote_postids = explode(',', $vbulletin->GPC['vbulletin_multiquote']);
fetch_quotable_posts($quote_postids, $threadinfo['threadid'], $unquoted_post_count, $quoted_post_ids, 'only');
$remaining = array_diff($quote_postids, $quoted_post_ids);
setcookie('vbulletin_multiquote', implode(',', $remaining), 0, '/');
}
$hook_query_fields = $hook_query_joins = $hook_query_where = '';
($hook = vBulletinHook::fetch_hook('newreply_post_ajax')) ? eval($hook) : false;
if ($newpost['doublepost'])
{
$vbulletin->GPC['ajax_lastpost'] = 0;
}
$posts = $db->query_read("
SELECT
post.*, post.username AS postusername, post.ipaddress AS ip, IF(post.visible = 2, 1, 0) AS isdeleted,
user.*, userfield.*, usertextfield.*,
" . iif($forum['allowicons'], 'icon.title as icontitle, icon.iconpath,') . "
" . iif($vbulletin->options['avatarenabled'], 'avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight,') . "
" . iif($deljoin, 'deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason,') . "
editlog.userid AS edit_userid, editlog.username AS edit_username, editlog.dateline AS edit_dateline,
editlog.reason AS edit_reason, editlog.hashistory,
postparsed.pagetext_html, postparsed.hasimages,
sigparsed.signatureparsed, sigparsed.hasimages AS sighasimages,
sigpic.userid AS sigpic, sigpic.dateline AS sigpicdateline, sigpic.width AS sigpicwidth, sigpic.height AS sigpicheight,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
" . iif(!($permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseehiddencustomfields']), $vbulletin->profilefiled['hidden']) . "
$hook_query_fields
FROM " . TABLE_PREFIX . "post AS post
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = post.userid)
LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON(userfield.userid = user.userid)
LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)
" . iif($forum['allowicons'], "LEFT JOIN " . TABLE_PREFIX . "icon AS icon ON(icon.iconid = post.iconid)") . "
" . iif($vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)") . "
$deljoin
LEFT JOIN " . TABLE_PREFIX . "editlog AS editlog ON(editlog.postid = post.postid)
LEFT JOIN " . TABLE_PREFIX . "postparsed AS postparsed ON(postparsed.postid = post.postid AND postparsed.styleid = " . intval(STYLEID) . " AND postparsed.languageid = " . intval(LANGUAGEID) . ")
LEFT JOIN " . TABLE_PREFIX . "sigparsed AS sigparsed ON(sigparsed.userid = user.userid AND sigparsed.styleid = " . intval(STYLEID) . " AND sigparsed.languageid = " . intval(LANGUAGEID) . ")
LEFT JOIN " . TABLE_PREFIX . "sigpic AS sigpic ON(sigpic.userid = post.userid)
$hook_query_joins
WHERE post.threadid = $threadinfo[threadid] AND " . (
($lastviewed = $vbulletin->GPC['ajax_lastpost']) ?
"post.dateline > $lastviewed AND (post.visible = 1 OR post.postid = $newpost[postid])" :
"post.postid = $newpost[postid]"
) . "
$hook_query_where
ORDER BY dateline
");
$postcount_query = $db->query_first("
SELECT COUNT(*) AS count
FROM " . TABLE_PREFIX . "post AS post
WHERE threadid = $threadinfo[threadid]
AND visible = 1
AND dateline <= " . ($vbulletin->GPC['ajax_lastpost'] ? $vbulletin->GPC['ajax_lastpost'] : TIMENOW) . "
AND postid <> $newpost[postid]
");
$postcount = $postcount_query['count'];
// determine ignored users
$ignore = array();
if (trim($vbulletin->userinfo['ignorelist']))
{
$ignorelist = preg_split('/( )+/', trim($vbulletin->userinfo['ignorelist']), -1, PREG_SPLIT_NO_EMPTY);
foreach ($ignorelist AS $ignoreuserid)
{
$ignore["$ignoreuserid"] = 1;
}
}
$see_deleted = ($forumperms & $vbulletin->bf_ugp_forumpermissions['canseedelnotice'] OR can_moderate($threadinfo['forumid']));
$postbit_factory = new vB_Postbit_Factory();
$postbit_factory->registry =& $vbulletin;
$postbit_factory->forum =& $foruminfo;
$postbit_factory->thread =& $thread;
$postbit_factory->cache = array();
$postbit_factory->bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
$xml->add_group('postbits');
while ($post = $db->fetch_array($posts))
{
if ($tachyuser = in_coventry($post['userid']) AND !can_moderate($thread['forumid']))
{
continue;
}
if ($tachyuser)
{
$fetchtype = 'post_global_ignore';
}
else if ($ignore["$post[userid]"])
{
$fetchtype = 'post_ignore';
}
else if ($post['visible'] == 2)
{
if (!$see_deleted)
{
continue;
}
$fetchtype = 'post_deleted';
}
else if ($post['visible'] == 0 AND !can_moderate($thread['forumid'], 'canmoderateposts'))
{
$fetchtype = 'auto_moderated';
}
else
{
$fetchtype = 'post';
}
if ($postorder)
{
$post['postcount'] = --$postcount;
}
else
{
$post['postcount'] = ++$postcount;
}
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment'] AND $vbulletin->userinfo['userid'] AND !empty($vbulletin->userinfo['attachmentextensions']))
{
require_once(DIR . '/packages/vbattach/attach.php');
$attach = new vB_Attach_Display_Content($vbulletin, 'vBForum_Post');
$attachments = $attach->fetch_postattach(0, $post['postid'], $postinfo['userid'], true, $attachid);
$post['attachments'] = $attachments['byattachment'];
$post['allattachments'] = $attachments['bycontent'][$post['postid']];
}
($hook = vBulletinHook::fetch_hook('showthread_postbit_create')) ? eval($hook) : false;
if ($newpost['doublepost'])
{
$show['spacer'] = false; // Still needed ?
$xml->add_tag('updatepost', $newpost['postid']);
}
$postbit_obj =& $postbit_factory->fetch_postbit($fetchtype);
$xml->add_tag('postbit', process_replacement_vars($postbit_obj->construct_postbit($post)), array('postid' => $post['postid']));
}
}
// ajax posts always mark the thread as read because any missed posts are retrieved as well
mark_thread_read($threadinfo, $foruminfo, $vbulletin->userinfo['userid'], TIMENOW);
// if post is not moderated, attempt to publish this new reply to user's Facebook feed
if ($newpost['visible'] AND is_facebookenabled())
{
// If this is a cms comment post, and make the appropriate FB post if it is.
if ($cms_comment_thread)
{
$url = vBCms_Route_Content::getURL(array('node' => $vbulletin->GPC['return_node']));
$url = str_ireplace('&', '&', $url);
publishtofacebook_articlecomment($threadinfo['title'], $newpost['message'], create_full_url($url));
}
else // If not a cms comment, simply publish the new post to Facebook
{
if ($threadview < $threadinfo['lastpost'])
{
$fblink = fetch_seo_url('thread|js', $threadinfo, array('p' => $newpost['postid'], 'posted' => 1)) . "#post$newpost[postid]";
}
else
{
$fblink = fetch_seo_url('thread|js', $threadinfo, array('p' => $newpost['postid'])) . "#post$newpost[postid]";
}
publishtofacebook_newreply($threadinfo['title'], $newpost['message'], create_full_url($fblink));
}
}
$xml->add_tag('time', TIMENOW);
$xml->add_tag('newpostid', $newpostid);
if ($cms_redirect)
{
$xml->add_tag('newrows',$postcount);
$xml->add_tag('newposturl', $cms_url);
}
$xml->close_group();
$xml->print_xml(true);
// #############################################################################
// #############################################################################
// #############################################################################
}
else
{
// if this is a CMS article comment, perform the redirect back to the article
if ($cms_comment_thread)
{
if (is_facebookenabled())
{
publishtofacebook_articlecomment($threadinfo['title'], $newpost['message'], create_full_url($vbulletin->url));
}
if ($cms_redirect)
{
exec_header_redirect($cms_url);
}
}
if ($vbulletin->GPC['multiquoteempty'])
{
// setting cookies -- need to force a redirect on IIS because of
// some issues with location-based redirects and set-cookie headers
$forceredirect = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false);
if ($vbulletin->GPC['multiquoteempty'] == 'only')
{
// remove all posts from this thread from the cookie, but leave all the others
$vbulletin->input->clean_array_gpc('c', array(
'vbulletin_multiquote' => TYPE_STR
));
$quote_postids = explode(',', $vbulletin->GPC['vbulletin_multiquote']);
fetch_quotable_posts($quote_postids, $threadinfo['threadid'], $unquoted_post_count, $quoted_post_ids, 'only');
$remaining = array_diff($quote_postids, $quoted_post_ids);
setcookie('vbulletin_multiquote', implode(',', $remaining), 0, '/');
}
else if ($vbulletin->GPC['multiquoteempty'] == 'all')
{
// empty the cookie completely
setcookie('vbulletin_multiquote', '', 0, '/');
}
}
else
{
$forceredirect = false;
}
if ($newpost['visible'] OR can_moderate($foruminfo['forumid'], 'canmoderateposts'))
{
if ($threadview < $threadinfo['lastpost'])
{
$vbulletin->url = fetch_seo_url('thread', $threadinfo, array('p' => $newpost['postid'], 'posted' => 1)) . "#post$newpost[postid]";
}
else
{
$vbulletin->url = fetch_seo_url('thread', $threadinfo, array('p' => $newpost['postid'])) . "#post$newpost[postid]";
}
if (defined('VB_API') AND VB_API === true)
{
$show['threadid'] = $threadinfo['threadid'];
$show['postid'] = $newpost['postid'];
}
// if post is not moderated, attempt to publish this new reply to user's Facebook feed
if ($newpost['visible'] AND is_facebookenabled())
{
$fblink = str_ireplace('&', '&', $vbulletin->url);
publishtofacebook_newreply($threadinfo['title'], $newpost['message'], create_full_url($fblink));
}
($hook = vBulletinHook::fetch_hook('newreply_post_complete')) ? eval($hook) : false;
print_standard_redirect('redirect_postthanks', true, $forceredirect);
}
else
{
$vbulletin->url = fetch_seo_url('forum', $foruminfo);
($hook = vBulletinHook::fetch_hook('newreply_post_complete')) ? eval($hook) : false;
print_standard_redirect('redirect_postthanks_moderate', true, true);
}
}
} // end if
}
// ############################### start new reply ###############################
if ($_REQUEST['do'] == 'newreply')
{
// falls down from preview post and has already been sent through htmlspecialchars() in build_new_post()
$title = $newpost['title'];
($hook = vBulletinHook::fetch_hook('newreply_form_start')) ? eval($hook) : false;
// *********************************************************************
// get options checks
$posticons = construct_icons($newpost['iconid'], $foruminfo['allowicons']);
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment'] AND $vbulletin->userinfo['userid'] AND !empty($vbulletin->userinfo['attachmentextensions']))
{
$values = "values[t]=$threadinfo[threadid]";
require_once(DIR . '/packages/vbattach/attach.php');
$attach = new vB_Attach_Display_Content($vbulletin, 'vBForum_Post');
$attachmentoption = $attach->fetch_edit_attachments($posthash, $poststarttime, $postattach['bycontent'][0], 0, $values, $editorid, $attachcount);
$contenttypeid = $attach->fetch_contenttypeid();
}
else
{
$attachmentoption = '';
$contenttypeid = 0;
}
require_once(DIR . '/includes/functions_file.php');
$attachinfo = fetch_attachmentinfo($posthash, $poststarttime, $contenttypeid, array('t' => $threadinfo['threadid']));
$editorid = construct_edit_toolbar(
$newpost['message'],
0,
$foruminfo['forumid'],
iif($foruminfo['allowsmilies'], 1, 0),
1,
($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment'] AND $vbulletin->userinfo['userid'] AND !empty($vbulletin->userinfo['attachmentextensions'])),
'fe',
'',
$attachinfo,
'forum',
'vBForum_Post',
0,
$threadinfo['threadid'],
$postpreview,
true,
'title'
);
// get rating options
if ($foruminfo['allowratings'] AND ($forumperms & $vbulletin->bf_ugp_forumpermissions['canthreadrate']))