forked from trhoppe/roadraceautox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowthread.php
2591 lines (2301 loc) · 85.5 KB
/
showthread.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('THIS_SCRIPT', 'showthread');
define('CSRF_PROTECTION', true);
define('FRIENDLY_URL_LINK', 'thread');
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
'posting',
'postbit',
'showthread',
'inlinemod',
'reputationlevel'
);
// get special data templates from the datastore
$specialtemplates = array(
'smiliecache',
'bbcodecache',
'mailqueue',
'bookmarksitecache',
);
// pre-cache templates used by all actions
$globaltemplates = array(
'ad_showthread_firstpost_start',
'ad_showthread_firstpost_sig',
'ad_thread_first_post_content',
'ad_thread_last_post_content',
'forumrules',
'im_aim',
'im_icq',
'im_msn',
'im_yahoo',
'im_skype',
'postbit',
'postbit_wrapper',
'postbit_attachment',
'postbit_attachmentimage',
'postbit_attachmentthumbnail',
'postbit_attachmentmoderated',
'postbit_deleted',
'postbit_ignore',
'postbit_ignore_global',
'postbit_ip',
'postbit_onlinestatus',
'bbcode_code',
'bbcode_html',
'bbcode_php',
'bbcode_quote',
'bbcode_video',
'SHOWTHREAD',
'showthread_list',
'showthread_similarthreadbit',
'showthread_similarthreads',
'showthread_bookmarksite',
'tagbit_wrapper',
'polloptions_table',
'polloption',
'polloption_multiple',
'pollresults_table',
'pollresult',
'threadadmin_imod_menu_post',
'editor_smilie_category',
'editor_smilie_row',
'newpost_disablesmiliesoption',
'editor_clientscript',
'editor_ckeditor',
'editor_jsoptions_font',
'editor_jsoptions_size',
'facebook_publishcheckbox',
'facebook_likebutton',
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ####################### PRE-BACK-END ACTIONS ##########################
function exec_postvar_call_back()
{
global $vbulletin;
$vbulletin->input->clean_gpc('r', 'goto', TYPE_STR);
if ($vbulletin->GPC['goto'] == 'newpost' OR $vbulletin->GPC['goto'] == 'postid')
{
$vbulletin->noheader = true;
}
}
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_bigthree.php');
require_once(DIR . '/includes/class_postbit.php');
require_once(DIR . '/includes/class_friendly_url.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
verify_forum_url();
($hook = vBulletinHook::fetch_hook('showthread_start')) ? eval($hook) : false;
$vbulletin->input->clean_array_gpc('r', array(
'perpage' => TYPE_UINT,
'pagenumber' => TYPE_UINT,
'highlight' => TYPE_STR,
'posted' => TYPE_BOOL,
'viewfull' => TYPE_BOOL,
'mode' => TYPE_STR,
));
// *********************************************************************************
// set $threadedmode (continued from global.php)
if ($vbulletin->options['allowthreadedmode'] AND !$show['search_engine'] AND !VB_API)
{
if (!empty($vbulletin->GPC['mode']))
{
// Look for command to switch types on the query string
switch ($vbulletin->GPC['mode'])
{
case 'threaded': $threadedCookieVal = 'threaded'; break;
case 'hybrid': $threadedCookieVal = 'hybrid'; break;
default: $threadedCookieVal = 'linear';
}
vbsetcookie('threadedmode', $threadedCookieVal);
$vbulletin->GPC[COOKIE_PREFIX . 'threadedmode'] = $threadedCookieVal;
unset($threadedCookieVal);
}
if (!empty($vbulletin->GPC[COOKIE_PREFIX . 'threadedmode']))
{
switch ($vbulletin->GPC[COOKIE_PREFIX . 'threadedmode'])
{
case 'threaded': $threadedmode = 1; break;
case 'hybrid': $threadedmode = 2; break;
default: $threadedmode = 0;
}
}
else
{
$threadedmode = ($vbulletin->userinfo['threadedmode'] == 3 ? 0 : $vbulletin->userinfo['threadedmode']);
}
switch ($threadedmode)
{
case 1:
$show['threadedmode'] = true;
$show['hybridmode'] = false;
$show['linearmode'] = false;
break;
case 2:
$show['threadedmode'] = false;
$show['hybridmode'] = true;
$show['linearmode'] = false;
break;
default:
$show['threadedmode'] = false;
$show['hybridmode'] = false;
$show['linearmode'] = true;
break;
}
}
else
{
DEVDEBUG('Threadedmode disabled by admin');
$threadedmode = 0;
$vbulletin->options['allowthreadedmode'] = false;
$show['threadedmode'] = false;
$show['linearmode'] = true;
$show['hybridmode'] = false;
}
// make an alternate class for the selected threadedmode
$modeclass = array();
for ($i = 0; $i < 3; $i++)
{
$modeclass["$i"] = iif($i == $threadedmode, 'alt2', 'alt1');
}
// prepare highlight words
if (!empty($vbulletin->GPC['highlight']))
{
$highlightwords = iif($vbulletin->GPC['goto'], '&', '&') . 'highlight=' . urlencode($vbulletin->GPC['highlight']);
}
else
{
$highlightwords = '';
}
// ##############################################################################
// ####################### HANDLE HEADER() CALLS ################################
// ##############################################################################
switch($vbulletin->GPC['goto'])
{
// *********************************************************************************
// go to next newest
case 'nextnewest':
$thread = goto_nextthread($threadid);
$threadid = $thread['threadid'];
unset($thread);
define('THREADNEXT', true);
break;
// *********************************************************************************
// go to next oldest
case 'nextoldest':
$thread = goto_prevthread($threadid);
$threadid = $thread['threadid'];
unset($thread);
define('THREADNEXT', true);
break;
// *********************************************************************************
// goto newest unread post
case 'newpost':
$threadinfo = verify_id('thread', $threadid, 1, 1);
if ($vbulletin->options['threadmarking'] AND $vbulletin->userinfo['userid'])
{
$vbulletin->userinfo['lastvisit'] = max($threadinfo['threadread'], $threadinfo['forumread'], TIMENOW - ($vbulletin->options['markinglimit'] * 86400));
}
else if (($tview = intval(fetch_bbarray_cookie('thread_lastview', $threadid))) > $vbulletin->userinfo['lastvisit'])
{
$vbulletin->userinfo['lastvisit'] = $tview;
}
if ($vbulletin->GPC['highlight'])
{
$pageinfo['highlight'] = urlencode($vbulletin->GPC['highlight']);
}
$coventry = fetch_coventry('string');
$posts = $db->query_first("
SELECT MIN(postid) AS postid
FROM " . TABLE_PREFIX . "post
WHERE threadid = $threadinfo[threadid]
AND visible = 1
AND dateline > " . intval($vbulletin->userinfo['lastvisit']) . "
". ($coventry ? "AND userid NOT IN ($coventry)" : "") . "
LIMIT 1
");
if ($posts['postid'])
{
unset($pageinfo['goto']);
$pageinfo['p'] = $posts['postid'];
exec_header_redirect(fetch_seo_url('thread|js', $threadinfo, $pageinfo, null, null, true) . "#post$posts[postid]");
}
else
{
unset($pageinfo['goto']);
$pageinfo['p'] = $threadinfo['lastpostid'];
exec_header_redirect(fetch_seo_url('thread|js', $threadinfo, $pageinfo, null, null, true) . "#post$threadinfo[lastpostid]");
}
break;
// *********************************************************************************
}
// end switch($vbulletin->GPC['goto'])
// *********************************************************************************
// workaround for header redirect issue from forms with enctype in IE
// (use a scrollIntoView javascript call in the <body> onload event)
$onload = '';
// *********************************************************************************
// set $perpage
$perpage = sanitize_maxposts($vbulletin->GPC['perpage']);
// *********************************************************************************
// set post order
if ($vbulletin->userinfo['postorder'] == 0)
{
$postorder = '';
}
else
{
$postorder = 'DESC';
}
// *********************************************************************************
// get thread info
$thread = verify_id('thread', $threadid, 1, 1);
$threadinfo =& $thread;
($hook = vBulletinHook::fetch_hook('showthread_getinfo')) ? eval($hook) : false;
// *********************************************************************************
// check for visible / deleted thread
if ((!$thread['visible'] AND !can_moderate($thread['forumid'], 'canmoderateposts'))
OR ($thread['isdeleted'] AND !can_moderate($thread['forumid'])))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['thread'], $vbulletin->options['contactuslink'])));
}
// *********************************************************************************
// Tachy goes to coventry
if (in_coventry($thread['postuserid']) AND !can_moderate($thread['forumid']))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['thread'], $vbulletin->options['contactuslink'])));
}
// *********************************************************************************
// do word wrapping for the thread title
if ($vbulletin->options['wordwrap'] != 0)
{
$thread['title'] = fetch_word_wrapped_string($thread['title']);
}
$thread['title'] = fetch_censored_text($thread['title']);
$thread['meta_description'] = strip_bbcode(strip_quotes($thread['description']), false, true);
$thread['meta_description'] = htmlspecialchars_uni(fetch_censored_text(fetch_trimmed_title($thread['meta_description'], 500, false)));
// *********************************************************************************
// words to highlight from the search engine
if (!empty($vbulletin->GPC['highlight']))
{
$highlight = preg_replace('#\*+#s', '*', $vbulletin->GPC['highlight']);
if ($highlight != '*')
{
$regexfind = array('\*', '\<', '\>');
$regexreplace = array('[\w.:@*/?=]*?', '<', '>');
$highlight = preg_quote(strtolower($highlight), '#');
$highlight = explode(' ', $highlight);
$highlight = str_replace($regexfind, $regexreplace, $highlight);
foreach ($highlight AS $val)
{
if ($val = trim($val))
{
$replacewords[] = htmlspecialchars_uni($val);
}
}
}
}
// *********************************************************************************
// make the forum jump in order to fill the forum caches
$navpopup = array(
'id' => 'showthread_navpopup',
'title' => $foruminfo['title_clean'],
'link' => fetch_seo_url('thread', $threadinfo)
);
construct_quick_nav($navpopup);
// *********************************************************************************
// get forum info
$forum = fetch_foruminfo($thread['forumid']);
$foruminfo =& $forum;
// *********************************************************************************
// check forum permissions
$forumperms = fetch_permissions($thread['forumid']);
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']))
{
print_no_permission();
}
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) AND ($thread['postuserid'] != $vbulletin->userinfo['userid'] OR $vbulletin->userinfo['userid'] == 0))
{
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']);
// *********************************************************************************
// jump page if thread is actually a redirect
if ($thread['open'] == 10)
{
$destthreadinfo = fetch_threadinfo($threadinfo['pollid']);
exec_header_redirect(fetch_seo_url('thread|js', $destthreadinfo, $pageinfo));
}
// *********************************************************************************
// get 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;
}
}
DEVDEBUG('ignored users: ' . implode(', ', array_keys($ignore)));
// *********************************************************************************
// filter out deletion notices if can't be seen
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canseedelnotice'] OR can_moderate($threadinfo['forumid']))
{
$deljoin = "LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON(post.postid = deletionlog.primaryid AND deletionlog.type = 'post')";
}
else
{
$deljoin = '';
}
$show['viewpost'] = (can_moderate($threadinfo['forumid'])) ? true : 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['approveattachment'] = (can_moderate($threadinfo['forumid'], 'canmoderateattachments')) ? true : false;
$show['inlinemod'] = (!$show['threadedmode'] AND ($show['managethread'] OR $show['managepost'] OR $show['approvepost'])) ? true : false;
$show['spamctrls'] = ($show['inlinemod'] AND $show['managepost']);
$url = $show['inlinemod'] ? SCRIPTPATH : '';
// build inline moderation popup
if ($show['popups'] AND $show['inlinemod'])
{
$threadadmin_imod_menu_post = vB_Template::create('threadadmin_imod_menu_post')->render();
}
else
{
$threadadmin_imod_menu_post = '';
}
// *********************************************************************************
// find the page that we should be on to display this post
if (!empty($postid) AND $threadedmode == 0)
{
$postinfo = verify_id('post', $postid, 1, 1);
$threadid = $postinfo['threadid'];
$coventry = fetch_coventry('string');
$getpagenum = $db->query_first("
SELECT COUNT(*) AS posts
FROM " . TABLE_PREFIX . "post AS post
WHERE threadid = $threadid AND visible = 1
" . ($coventry ? "AND post.userid NOT IN ($coventry)" : '') . "
AND dateline " . iif(!$postorder, '<=', '>=') . " $postinfo[dateline]
");
$vbulletin->GPC['pagenumber'] = ceil($getpagenum['posts'] / $perpage);
}
// *********************************************************************************
// display ratings if enabled
$show['rating'] = false;
if ($forum['allowratings'] == 1)
{
if ($thread['votenum'] > 0)
{
$thread['voteavg'] = vb_number_format($thread['votetotal'] / $thread['votenum'], 2);
$thread['rating'] = intval(round($thread['votetotal'] / $thread['votenum']));
if ($thread['votenum'] >= $vbulletin->options['showvotes'])
{
$show['rating'] = true;
}
}
devdebug("threadinfo[vote] = $threadinfo[vote]");
if ($threadinfo['vote'])
{
$voteselected["$threadinfo[vote]"] = 'selected="selected"';
$votechecked["$threadinfo[vote]"] = 'checked="checked"';
}
else
{
$voteselected[0] = 'selected="selected"';
$votechecked[0] = 'checked="checked"';
}
}
// *********************************************************************************
// set page number
if ($vbulletin->GPC['pagenumber'] < 1)
{
$vbulletin->GPC['pagenumber'] = 1;
}
else if ($vbulletin->GPC['pagenumber'] > ceil(($thread['replycount'] + 1) / $perpage))
{
$vbulletin->GPC['pagenumber'] = ceil(($thread['replycount'] + 1) / $perpage);
}
// verify that we are at the canonical SEO url and redirect to this if not
verify_seo_url('thread|js', $threadinfo, array('pagenumber' => $vbulletin->GPC['pagenumber']));
// *********************************************************************************
// update views counter, moved after seo re-direct.
if ($vbulletin->options['threadviewslive'])
{
// doing it as they happen; for optimization purposes, this cannot use a DM!
$db->shutdown_query("
UPDATE " . TABLE_PREFIX . "thread
SET views = views + 1
WHERE threadid = " . intval($threadinfo['threadid'])
);
}
else
{
// or doing it once an hour
$db->shutdown_query("
INSERT INTO " . TABLE_PREFIX . "threadviews (threadid)
VALUES (" . intval($threadinfo['threadid']) . ')'
);
}
// *********************************************************************************
// initialise some stuff...
$limitlower = ($vbulletin->GPC['pagenumber'] - 1) * $perpage;
$limitupper = ($vbulletin->GPC['pagenumber']) * $perpage;
$counter = 0;
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'];
}
}
$threadinfo['threadview'] = intval($threadview);
$displayed_dateline = 0;
################################################################################
############################### SHOW POLL ######################################
################################################################################
$poll = '';
if ($thread['pollid'])
{
$pollbits = '';
$counter = 1;
$pollid = $thread['pollid'];
$show['editpoll'] = iif(can_moderate($threadinfo['forumid'], 'caneditpoll'), true, false);
// get poll info
$pollinfo = $db->query_first_slave("
SELECT *
FROM " . TABLE_PREFIX . "poll
WHERE pollid = $pollid
");
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$pollinfo['question'] = $bbcode_parser->parse(unhtmlspecialchars($pollinfo['question']), $forum['forumid'], true);
$splitoptions = explode('|||', $pollinfo['options']);
$splitoptions = array_map('rtrim', $splitoptions);
$splitvotes = explode('|||', $pollinfo['votes']);
$showresults = 0;
$uservoted = 0;
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canvote']))
{
$nopermission = 1;
}
if (!$pollinfo['active'] OR !$thread['open'] OR ($pollinfo['dateline'] + ($pollinfo['timeout'] * 86400) < TIMENOW AND $pollinfo['timeout'] != 0) OR $nopermission)
{
//thread/poll is closed, ie show results no matter what
$showresults = 1;
}
else
{
//get userid, check if user already voted
$voted = intval(fetch_bbarray_cookie('poll_voted', $pollid));
if ($voted)
{
$uservoted = 1;
}
}
($hook = vBulletinHook::fetch_hook('showthread_poll_start')) ? eval($hook) : false;
if ($pollinfo['timeout'] AND !$showresults)
{
$pollendtime = vbdate($vbulletin->options['timeformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
$pollenddate = vbdate($vbulletin->options['dateformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
$show['pollenddate'] = true;
}
else
{
$show['pollenddate'] = false;
}
foreach ($splitvotes AS $index => $value)
{
$pollinfo['numbervotes'] += $value;
}
if ($vbulletin->userinfo['userid'] > 0)
{
$pollvotes = $db->query_read_slave("
SELECT voteoption
FROM " . TABLE_PREFIX . "pollvote
WHERE userid = " . $vbulletin->userinfo['userid'] . " AND pollid = $pollid
");
if ($db->num_rows($pollvotes) > 0)
{
$uservoted = 1;
}
}
if ($showresults OR $uservoted)
{
if ($uservoted)
{
$uservote = array();
while ($pollvote = $db->fetch_array($pollvotes))
{
$uservote["$pollvote[voteoption]"] = 1;
}
}
}
$left = vB_Template_Runtime::fetchStyleVar('left');
$right = vB_Template_Runtime::fetchStyleVar('right');
$option['open'] = $left[0];
$option['close'] = $right[0];
foreach ($splitvotes AS $index => $value)
{
$arrayindex = $index + 1;
$option['uservote'] = iif($uservote["$arrayindex"], true, false);
$option['question'] = $bbcode_parser->parse($splitoptions["$index"], $forum['forumid'], true);
// public link
if ($pollinfo['public'] AND $value)
{
$option['votes'] = '<a href="' . fetch_seo_url('poll', $pollinfo, array('do' => 'showresults')) .
'">' . vb_number_format($value) . '</a>';
}
else
{
$option['votes'] = vb_number_format($value); //get the vote count for the option
}
$option['number'] = $counter; //number of the option
//Now we check if the user has voted or not
if ($showresults OR $uservoted)
{ // user did vote or poll is closed
if ($value <= 0)
{
$option['percentraw'] = 0;
}
else if ($pollinfo['multiple'])
{
$option['percentraw'] = ($value < $pollinfo['voters']) ? $value / $pollinfo['voters'] * 100 : 100;
}
else
{
$option['percentraw'] = ($value < $pollinfo['numbervotes']) ? $value / $pollinfo['numbervotes'] * 100 : 100;
}
$option['percent'] = vb_number_format($option['percentraw'], 2);
$option['graphicnumber'] = $option['number'] % 6 + 1;
$option['barnumber'] = round($option['percent']) * 2;
$option['remainder'] = 201 - $option['barnumber'];
// Phrase parts below
if ($nopermission)
{
$pollstatus = $vbphrase['you_may_not_vote_on_this_poll'];
}
else if ($showresults)
{
$pollstatus = $vbphrase['this_poll_is_closed'];
}
else if ($uservoted)
{
$pollstatus = $vbphrase['you_have_already_voted_on_this_poll'];
}
($hook = vBulletinHook::fetch_hook('showthread_polloption')) ? eval($hook) : false;
$templater = vB_Template::create('pollresult');
$templater->register('names', $names);
$templater->register('option', $option);
$pollbits .= $templater->render();
}
else
{
($hook = vBulletinHook::fetch_hook('showthread_polloption')) ? eval($hook) : false;
if ($pollinfo['multiple'])
{
$templater = vB_Template::create('polloption_multiple');
$templater->register('option', $option);
$pollbits .= $templater->render();
}
else
{
$templater = vB_Template::create('polloption');
$templater->register('option', $option);
$pollbits .= $templater->render();
}
}
$counter++;
}
if ($pollinfo['multiple'])
{
$pollinfo['numbervotes'] = $pollinfo['voters'];
$show['multiple'] = true;
}
if ($pollinfo['public'])
{
$show['publicwarning'] = true;
}
else
{
$show['publicwarning'] = false;
}
$displayed_dateline = $threadinfo['lastpost'];
($hook = vBulletinHook::fetch_hook('showthread_poll_complete')) ? eval($hook) : false;
if ($showresults OR $uservoted)
{
$templater = vB_Template::create('pollresults_table');
$templater->register('pollbits', $pollbits);
$templater->register('pollenddate', $pollenddate);
$templater->register('pollendtime', $pollendtime);
$templater->register('pollinfo', $pollinfo);
$templater->register('pollstatus', $pollstatus);
$poll = $templater->render();
}
else
{
$templater = vB_Template::create('polloptions_table');
$templater->register('pollbits', $pollbits);
$templater->register('pollenddate', $pollenddate);
$templater->register('pollendtime', $pollendtime);
$templater->register('pollinfo', $pollinfo);
$poll = $templater->render();
}
}
// 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'))
AND (!fetch_require_hvcheck('post'))
)
{
$show['quickreply'] = true;
}
else
{
$show['quickreply'] = false;
$show['wysiwyg'] = 0;
$quickreply = '';
}
$show_reply_button = (($forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyown'] AND $vbulletin->userinfo['userid'] == $threadinfo['postuserid']) OR ($forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyothers'] AND $vbulletin->userinfo['userid'] != $threadinfo['postuserid']));
$show['largereplybutton'] = (!$thread['isdeleted'] AND !$show['threadedmode'] AND $forum['allowposting'] AND !$show['search_engine']);
$show['largereplybutton'] = ($show['largereplybutton'] AND $show_reply_button);
if (!$forum['allowposting'])
{
$show['quickreply'] = 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
));
$vbulletin->GPC['vbulletin_multiquote'] = explode(',', $vbulletin->GPC['vbulletin_multiquote']);
}
// post is cachable if option is enabled, last post is newer than max age, and this user
// isn't showing a sessionhash, and it's not an API call
$post_cachable = (
$vbulletin->options['cachemaxage'] > 0 AND
(TIMENOW - ($vbulletin->options['cachemaxage'] * 60 * 60 * 24)) <= $thread['lastpost'] AND
$vbulletin->session->vars['sessionurl'] == '' AND !VB_API
);
// sigs are cachable if this user isn't showing a sessionhash
$sigs_cachable = ($vbulletin->session->vars['sessionurl'] == '');
$saveparsed = '';
$save_parsed_sigs = '';
($hook = vBulletinHook::fetch_hook('showthread_post_start')) ? eval($hook) : false;
$fetch_api_info = false;
$vbulletin->options['apipostidmanage'] = @unserialize($vbulletin->options['apipostidmanage']);
if ($vbulletin->options['apipostidmanage']['enable'])
{
$contenttypeid = vB_Types::instance()->getContentTypeID('vBForum_Post');
$fetch_api_info = true;
}
################################################################################
####################### SHOW THREAD IN LINEAR MODE #############################
################################################################################
if ($threadedmode == 0)
{
// allow deleted posts to not be counted in number of posts displayed on the page;
// prevents issue with page count on forum display being incorrect
$ids = $attachids = array();
$lastpostid = 0;
$hook_query_joins = $hook_query_where = '';
($hook = vBulletinHook::fetch_hook('showthread_query_postids')) ? eval($hook) : false;
if (empty($deljoin) AND !$show['approvepost'])
{
$totalposts = $threadinfo['replycount'] + 1;
if (can_moderate($thread['forumid']))
{
$coventry = '';
}
else
{
$coventry = fetch_coventry('string');
}
//VBIV-6889 hack to calculate the correct value for the total posts
$calc_found_rows = '';
if(!empty($hook_query_where))
{
$calc_found_rows = 'SQL_CALC_FOUND_ROWS';
}
$getpostids = $db->query_read("
SELECT $calc_found_rows post.postid, post.attach
FROM " . TABLE_PREFIX . "post AS post
$hook_query_joins
WHERE post.threadid = $threadid
AND post.visible = 1
" . ($coventry ? "AND post.userid NOT IN ($coventry)" : '') . "
$hook_query_where
ORDER BY post.dateline $postorder
LIMIT $limitlower, $perpage
");
//VBIV-6889 hack to calculate the correct value for the total posts
if(!empty($hook_query_where))
{
$calc_found_rows_array = $db->query_first("SELECT FOUND_ROWS() AS found_rows");
$totalposts = $calc_found_rows_array['found_rows'];
}
while ($post = $db->fetch_array($getpostids))
{
if ($post['attach'])
{
$attachids[] = $post['postid'];
}
if (!isset($qrfirstpostid))
{
$qrfirstpostid = $post['postid'];
}
$qrlastpostid = $post['postid'];
$ids[] = $post['postid'];
}
$db->free_result($getpostids);
$lastpostid = $qrlastpostid;
}
else
{
$getpostids = $db->query_read("
SELECT post.postid, post.visible, post.userid, post.attach
FROM " . TABLE_PREFIX . "post AS post
$hook_query_joins
WHERE post.threadid = $threadid
AND post.visible IN (1
" . (!empty($deljoin) ? ",2" : "") . "
" . ($show['approvepost'] ? ",0" : "") . "
)
$hook_query_where
ORDER BY post.dateline $postorder
");
$totalposts = 0;
if ($limitlower != 0)
{
$limitlower++;
}
while ($post = $db->fetch_array($getpostids))
{
if (!isset($qrfirstpostid))
{
$qrfirstpostid = $post['postid'];
}
$qrlastpostid = $post['postid'];
if ($post['visible'] == 1 AND !in_coventry($post['userid']))
{
$totalposts++;
}
if ($post['attach'])
{
$attachids[] = $post['postid'];
}
if ($totalposts < $limitlower OR $totalposts > $limitupper)
{
continue;
}
// remember, these are only added if they're going to be displayed
$ids[] = $post['postid'];
$lastpostid = $post['postid'];
}
$db->free_result($getpostids);
}
// '0' inside parenthesis in unlikely case we have no ids for this page
// (this could happen if the replycount is wrong in the db)
$postids = "post.postid IN (0" . implode(',', $ids) . ")";
// load attachments
if ($thread['attach'])
{
require_once(DIR . '/packages/vbattach/attach.php');
$attach = new vB_Attach_Display_Content($vbulletin, 'vBForum_Post');
$postattach = $attach->fetch_postattach(0, $attachids, null, true);
}
$hook_query_fields = $hook_query_joins = '';
($hook = vBulletinHook::fetch_hook('showthread_query')) ? eval($hook) : false;
$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,') . "
" . ((can_moderate($thread['forumid'], 'canmoderateposts') OR can_moderate($thread['forumid'], 'candeleteposts')) ? 'spamlog.postid AS spamlog_postid,' : '') . "
" . iif($deljoin, 'deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason,') . "
" . ($fetch_api_info ? "apipost.platformname AS mobile_platformname," : "") . "
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(user.displaygroupid=0, user.usergroupid, user.displaygroupid) AS displaygroupid, infractiongroupid
" . iif(!($permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseehiddencustomfields']), $vbulletin->profilefield['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)") . "
" . ((can_moderate($thread['forumid'], 'canmoderateposts') OR can_moderate($thread['forumid'], 'candeleteposts')) ? "LEFT JOIN " . TABLE_PREFIX . "spamlog AS spamlog ON(spamlog.postid = post.postid)" : '') . "
$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)
" . ($fetch_api_info ? "LEFT JOIN " . TABLE_PREFIX . "apipost AS apipost ON (apipost.contenttypeid = $contenttypeid AND apipost.contentid = post.postid)" : "") . "
$hook_query_joins
WHERE $postids
ORDER BY post.dateline $postorder
");
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canseethumbnails']))
{
$vbulletin->options['attachthumbs'] = 0;
}
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['cangetattachment']))
{
$vbulletin->options['viewattachedimages'] = (($vbulletin->options['viewattachedimages'] AND $vbulletin->options['attachthumbs']) ? 1 : 0);
}
$postcount = ($vbulletin->GPC['pagenumber'] - 1) * $perpage;
if ($postorder)
{
// Newest first
$postcount = $totalposts - $postcount + 1;