-
Notifications
You must be signed in to change notification settings - Fork 0
/
forum.php
507 lines (350 loc) · 17.4 KB
/
forum.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
<?php
/*******************************************************************\
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #
# @ ArBB V 1.0.0 Beta 1 @ #
# @ All Copyrights are saved Arabian bulletin board team @ #
# @ Copyright © 2009 ArBB Team @ #
# @ ArBB Is Free Bulletin Board and not for sale @ #
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #
\*******************************************************************/
#
# forum File started
#
/*
File name -> forum.php
File Version -> 1.0.0 Beta 1
File Programmer -> Thaer
File type -> file
*/
$templatelist = 'forum,forum_subforumbit,forum_threadbit,forum_announcementbit,forum_password';
$phrasearray=array('forum');
require('global.php');
$plugins->cache('forum_start,forum_complete,forum_onlineuser,forum_moderator,forum_announcement');
require_once('./includes/functions_forum.php');
($evalp = $plugins->load('forum_start'))?eval($evalp):'';
if(empty($arbb->input['do']))
{
//# if the forumid is invalid
$show['invalid_forum']=1;
//# Securing _GET vriables which are going to be used
$fid = checkval($arbb->input['fid']);
$perpage = checkval($arbb->input['pp']);
$page = checkval($arbb->input['page']);
//# Some variables for sql orders
$limit = '';
$modsqladd = '';
$navarray = '';
//# page and perpage for sql orders
($page)?$page=$page:$page=1;
($perpage)?$perpage=$perpage:$perpage=$options['forumperpage'];
//# the forum's main query
$mainforumquery=$DB->query("select * from "._PREFIX_."forum where forumid='$fid' and active='1'");
//# forum content bits (subforums, threads, sticky threads and announcements)
$subforumsbit='';
$threadsbit='';
$stickythreadsbit='';
$announcementsbit='';
//# fetching forum query
while($mainforum=$DB->fetch_array($mainforumquery))
{
($evalp = $plugins->load('forum_query'))?eval($evalp):'';
$show['invalid_forum']=0;
//# if forum is link
if(strlen($mainforum['link'])>0)
{
header('location:'.$mainforum['link'].'');
exit;
}
//# Online updating variables location by title and url
$local['whereurl']='forum.php?fid='.$fid;
$local['wheretitle']=$mainforum['title'];
update_online();
$wheretitle='';
//# forum permission query for special permissions
$localgroup=get_forum_permissions($mainforum);
//# main forums for the navigation bar
build_nav_tree($mainforum);
// $local['wheretitle']=$local['wheretitle'].$mainforum['title'];
$wheretitle=$mainforum['title'];
//# if the administrator added password for this forum , ,
if(($mainforum['canusepassword']==1)&&(strlen($mainforum['password'])>0))
{
//# cookie Value ,, if it was set
$forumpass=$arbb->input[''. _CPREFIX_ .$mainforum[forumid].'_password'];
if($forumpass==$mainforum['password'])
{
$show['require_forum_password']=0;
}
else
{
if(($localgroup['canuseadmincp']==1)||($localgroup['canusemodcp']==1)||($localgroup['ismoderator']==1))
{
$show['require_forum_password']=0;
}
else
{
$show['require_forum_password']=1;
}
}
}
//# making sure the visitor or user group have permission for viewing this forum
if($localgroup['canviewforum']==0)
{
error_permission();
}
else
{
$canmoderate=is_moderator($mainforum);
if(!$show['require_forum_password'])
{
//# sub forums query
$subforumsquery=$DB->query("select f.*,i.title as icontitle,i.iconpath,p.iconid from "._PREFIX_."forum f
LEFT JOIN "._PREFIX_."post p on(p.postid=f.lastpostid)
LEFT JOIN "._PREFIX_."icon i on(i.iconid=p.iconid)
where mainid='$fid' and active='1' order by displayorder ASC");
if($DB->num_rows($subforumsquery)>0)
{
$show['subforums']=1;
while($forum=$DB->fetch_array($subforumsquery))
{
$forum['statusimg'] = forumstatusimg($forum);
if($forum['iconid']>0)
{
$show['posticon']=1;
}
$forum = $bbcode->clearhtml($forum);
$forum['lastposttime']=mydate($forum['lastpost'],'last');
$forum['lastthread']=$bbcode->clearhtml($forum[lastthread]);
($evalp = $plugins->load('forum_subforum'))?eval($evalp):'';
$subforumsbit.=$TP->GetTemp('forum_subforumbit');
}
}
//# default values for sort field and sort order for threads query
$sortfield = $mainforum['sortfield'];
$sortorder = $mainforum['sortorder'];
$order = array();
$sort = array();
//# getting the values from the browser if they were setted
if(isset($arbb->input['sort']))
{
$sortfield=$arbb->input['sort'];
}
if(isset($arbb->input['order']))
{
$sortorder=$arbb->input['order'];
}
/*/
/
/ making an array for allowed values for query sort and order
/ that protect query against wrong type of values
/
/*/
$sortorderfields=array('asc','desc','ASC','DESC');
$sortfields=array('lastpost','title','dateline','replycount','views','postusername');
if(!in_array($sortorder,$sortorderfields))
{
$sortorder=$mainforum['sortorder'];
}
if(!in_array($sortfield,$sortfields))
{
$sortfield=$mainforum['sortfield'];
}
$order[$sortorder] = 'selected';
$sort[$sortfield] = 'selected';
$sortfield='t.'.$sortfield;
$end=$page*$perpage;
$start=$end-$perpage;
$limit=$start.','.$perpage;
if($mainforum['isforum']>0)
{
if($localgroup['canviewthreads']==0)
{
$mainforum['isforum']=0;
}
else
{
$threadsquery = $DB->query("select t.*,p.post,i.title as icontitle,i.iconpath,i.iconid from "._PREFIX_."thread t
LEFT JOIN ". _PREFIX_ ."post p on(p.postid = t.firstpostid)
LEFT JOIN ". _PREFIX_ ."icon i on(i.iconid=t.iconid)
where t.forumid='$mainforum[forumid]' and sticky<>'1'
order by $sortfield $sortorder limit $limit");
$stickythreadsquery = $DB->query("select t.*,p.post,i.title as icontitle,i.iconpath,i.iconid from "._PREFIX_."thread t
LEFT JOIN ". _PREFIX_ ."post p on(p.postid = t.firstpostid)
LEFT JOIN ". _PREFIX_ ."icon i on(i.iconid=t.iconid)
where t.forumid='$mainforum[forumid]' and sticky='1'
order by $sortfield $sortorder");
$thread_contain_attachment=$lang['thread_contain_attachment'];
$threadsnum=$DB->num_rows($threadsquery)+$DB->num_rows($stickythreadsquery);
$posticon=' ';
while($thread=$DB->fetch_array($stickythreadsquery))
{
$thread['post']=str_replace('<br>','',substr($bbcode->clearhtml($thread['post']),0,350));
$thread=$bbcode->clearhtml($thread);
$thread['lastposttime']=mydate($thread['lastpost'],'last');
$thread['statusimg'] = threadstatusimg($thread);
if($thread['iconid']>0)
{
$posticon="<img src=\"$thread[iconpath]\" alt=\"$thread[icontitle]\">";
}
eval("\$lang['thread_attachments']=\"".$thread_contain_attachment."\";");
($evalp = $plugins->load('forum_thread'))?eval($evalp):'';
$stickythreadsbit.=$TP->GetTemp("forum_threadbit");
$posticon=' ';
}
while($thread=$DB->fetch_array($threadsquery))
{
$thread['post']=str_replace('<br>','',substr($bbcode->clearhtml($thread['post']),0,350));
$thread=$bbcode->clearhtml($thread);
$thread['lastposttime']=mydate($thread['lastpost'],'last');
$thread['statusimg'] = threadstatusimg($thread);
if($thread['iconid']>0)
{
$posticon="<img src=\"$thread[iconpath]\" alt=\"$thread[icontitle]\">";
}
eval("\$lang['thread_attachments']=\"".$thread_contain_attachment."\";");
($evalp = $plugins->load('forum_thread'))?eval($evalp):'';
$threadsbit.=$TP->GetTemp('forum_threadbit');
$posticon=' ';
}
}
}
$announcement_query=$DB->query("select a.*,u.username,u.customtitle,u.usertitle,u.usergroupid,ug.usertitle as ugusertitle,ug.opentag,ug.closetag
From ". _PREFIX_ ."announcement a
LEFT JOIN ". _PREFIX_ ."users u on(u.userid=a.userid)
LEFT JOIN ". _PREFIX_ ."usergroup ug on (ug.usergroupid=u.usergroupid)
where a.enddate > '".TIMENOW."' and a.startdate < '".TIMENOW."' and a.forumid='-1' or a.forumid in ($mainforum[parentlist])");
while($an=$DB->fetch_array($announcement_query))
{
$an['username']=$an['opentag'].$an['username'].$an['closetag'];
if($an['customtitle']==1)
{
$an['usertitle']=$an['usertitle'];
}
else
{
$an['usertitle']=$an['ugusertitle'];
}
$an['startdate']=mydate($an['startdate'],'last');
($evalp = $plugins->load('forum_announcement'))?eval($evalp):'';
$announcementsbit.=$TP->GetTemp('forum_announcementbit');
}
$modquery=$DB->query("select m.userid,m.forumid,u.username,u.usergroupid,ug.opentag,ug.closetag from "._PREFIX_."moderator m
LEFT JOIN "._PREFIX_."users u on (u.userid=m.userid)
LEFT JOIN "._PREFIX_."usergroup ug on (ug.usergroupid=u.usergroupid)
where m.forumid in(".$mainforum['parentlist'].")");
if($DB->num_rows($modquery)>0)
{
$show['moderators'] = 1;
$comma = '';
$moderatorslist = '';
$totalmods = $DB->num_rows($modquery);
$mods = array();
while($mod=$DB->fetch_array($modquery))
{
$mods[$mod[userid]]=$mod;
$mods[$mod[userid]]['username']=$mod['opentag'].$mod['username'].$mod['closetag'];
}
while(list($userid,$mod) = each($mods))
{
($evalp = $plugins->load('forum_moderator'))?eval($evalp):'';
$comma=($moderatorslist)?',':'';
$moderatorslist.=$comma."<a href=\"member.php?action=profile&userid=$mod[userid]\">".$mod['opentag'].$mod['username'].$mod['closetag']."</a>";
}
}
if($localgroup['canviewonline']==1)
{
$timer = 60*15;
$activenow = TIMENOW-$timer;
$act = array();
$activeusers = "";
$comma = "";
$online_users=$DB->query("select o.username,o.userid,u.usergroupid,ug.opentag,ug.closetag
from "._PREFIX_."online o
LEFT JOIN "._PREFIX_."users u on (u.userid=o.userid)
LEFT JOIN "._PREFIX_."usergroup ug on (ug.usergroupid=u.usergroupid)
where dateline > $activenow and o.whereurl like 'forum.php?fid=$fid%'");
$act['num'] = $DB->num_rows($online_users);
$act['guests'] = 0;
$act['users'] = 0;
if($act['num']>0)
{
$show['activeusers']=1;
while($online=$DB->fetch_array($online_users))
{
($evalp = $plugins->load('forum_onlineuser'))?eval($evalp):'';
if($online[userid]>0)
{
$act['users']++;
$comma=($activeusers)?',':'';
$activeusers.=$comma."<a href=\"member.php?action=profile&userid=$online[userid]\">".$online['opentag'].$online['username'].$online['closetag']."</a>";
}
else
{
$act['guests']++;
}
}
}
}
$end = ($perpage*$page);
$start = ($end-$perpage)+1;
$total=$DB->num_rows($DB->query("select threadid from "._PREFIX_."thread where forumid='$mainforum[forumid]'"));
$pages_table = next_page($fid,$total,$perpage);
if($end > $total)
{
$end=$total;
}
eval("\$lang[currently_active_users]=\"".$lang['currently_active_users']."\";");
eval("\$lang[x_members_y_guests]=\"".$lang['x_members_y_guests']."\";");
eval("\$lang[showing_threads_x_to_y_of_z]=\"".$lang['showing_threads_x_to_y_of_z']."\";");
$TP->webtemp('forum');
}
else
{
$message=$TP->GetTemp('forum_password');
error_message($message);
}
}
}
if($show['invalid_forum'])
{
$local['whereurl']="forum.php?fid=".$fid;
error_message($lang['invalid_forum']);
}
}
elseif($arbb->input['do']=='markread')
{
//# if the requested was to mark the forum(s) read
$local['whereurl']='forum.php?do=markread';
$wheretitle=$lang['do_mark_read'];
$fid=checkval($arbb->input['fid']);
($fid)?$fid=$fid:$fid=-1;
$mark_read = mark_forums_read($fid);
$url = $mark_read['url'];
$redirect_message = $mark_read['phrase'];
$local['whereurl'].= "&fid=$fid";
redirect($redirect_message,$url);
}
elseif($arbb->input['do']=='password')
{
$fid=checkval($arbb->input['fid']);
$query=$DB->query("select password,forumid,title from "._PREFIX_."forum where forumid='$fid'");
while($f=$DB->fetch_array($query))
{
if($bbcode->clearhtml($arbb->input['forum_password'])==$f['password'])
{
$cname = $fid .'_password';
newcookie($cname,$f['password'],900);
$redirect_message=$lang['forum_password_accepted'];
$url=$bbcode->clearhtml(urldecode($arbb->input['url']));
redirect($redirect_message,$url);
}
else
{
error_message($lang['forum_password_error']);
}
}
}
$titleetc=$wheretitle.' - ';
($evalp = $plugins->load('forum_complete'))?eval($evalp):'';
print_page();
?>