-
Notifications
You must be signed in to change notification settings - Fork 0
/
forums.php
219 lines (181 loc) · 5.03 KB
/
forums.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
<?php
/**
* forums
*
* @package Sngine
* @author Zamblek
*/
// fetch bootloader
require('bootloader.php');
// forums enabled
if(!$system['forums_enabled']) {
_error(404);
}
// user access
if(!$system['system_public']) {
user_access();
}
try {
// get view content
switch ($_GET['view']) {
case '':
// page header
page_header(__("Forums"));
// get forums
$forums = $user->get_forums();
/* assign variables */
$smarty->assign('forums', $forums);
// get online users
if($system['forums_online_enabled']) {
$online_users = $user->get_forum_online_users();
/* assign variables */
$smarty->assign('online_users', $online_users);
}
// get insights
if($system['forums_statistics_enabled']) {
/* total threads */
$get_threads = $db->query("SELECT COUNT(*) as count FROM forums_threads") or _error("SQL_ERROR_THROWEN");
$insights['threads'] = $get_threads->fetch_assoc()['count'];
/* total replies */
$get_replies = $db->query("SELECT COUNT(*) as count FROM forums_replies") or _error("SQL_ERROR_THROWEN");
$insights['replies'] = $get_replies->fetch_assoc()['count'];
/* total users */
$get_users = $db->query("SELECT COUNT(*) as count FROM users") or _error("SQL_ERROR_THROWEN");
$insights['users'] = $get_users->fetch_assoc()['count'];
/* assign variables */
$smarty->assign('insights', $insights);
}
break;
case 'forum':
// get forum
$forum = $user->get_forum($_GET['forum_id']);
if(!$forum) {
_error(404);
}
/* get threads */
if($forum['forum_threads'] > 0) {
$forum['threads'] = $user->get_forum_threads( array('forum' => $forum) );
}
/* assign variables */
$smarty->assign('forum', $forum);
// page header
page_header($forum['forum_name'], $forum['forum_description']);
break;
case 'thread':
// get thread
$thread = $user->get_forum_thread($_GET['thread_id'], true);
if(!$thread) {
_error(404);
}
/* get replies */
if($thread['replies'] > 0) {
$thread['thread_replies'] = $user->get_forum_replies( array('thread' => $thread) );
}
/* assign variables */
$smarty->assign('thread', $thread);
// page header
page_header($thread['title'], $thread['text_snippet']);
break;
case 'new-thread':
// user access
user_access();
// page header
page_header(__("Forums")." › ".__("Write New Thread"));
// get forum
$forum = $user->get_forum($_GET['forum_id'], false);
if(!$forum) {
_error(404);
}
/* assign variables */
$smarty->assign('forum', $forum);
break;
case 'edit-thread':
// user access
user_access();
// page header
page_header(__("Forums")." › ".__("Edit Thread"));
// get thread
$thread = $user->get_forum_thread($_GET['thread_id']);
if(!$thread) {
_error(404);
}
/* assign variables */
$smarty->assign('thread', $thread);
break;
case 'new-reply':
// user access
user_access();
// page header
page_header(__("Forums")." › ".__("Post Reply"));
// get thread
$thread = $user->get_forum_thread($_GET['thread_id']);
if(!$thread) {
_error(404);
}
/* assign variables */
$smarty->assign('thread', $thread);
break;
case 'edit-reply':
// user access
user_access();
// page header
page_header(__("Forums")." › ".__("Edit Reply"));
// get reply
$reply = $user->get_forum_reply($_GET['reply_id']);
if(!$reply) {
_error(404);
}
/* assign variables */
$smarty->assign('reply', $reply);
break;
case 'my-threads':
// user access
user_access();
// page header
page_header(__("Forums")." › ".__("My Threads"));
// get threads
$threads = $user->get_forum_threads( array('user_id' => $user->_data['user_id']) );
/* assign variables */
$smarty->assign('threads', $threads);
break;
case 'my-replies':
// user access
user_access();
// page header
page_header(__("Forums")." › ".__("My Replies"));
// get replies
$replies = $user->get_forum_replies( array('user_id' => $user->_data['user_id']) );
/* assign variables */
$smarty->assign('replies', $replies);
break;
case 'search':
// page header
page_header(__("Forums")." › ".__("Search"));
// get forums
$forums = $user->get_forums();
/* assign variables */
$smarty->assign('forums', $forums);
break;
case 'search-results':
// page header
page_header(__("Forums")." › ".__("Search Results"));
if(!isset($_GET['query']) || !isset($_GET['type']) || !isset($_GET['forum']) ) {
redirect('/forums/search');
}
$results = $user->search_forums($_GET['query'], $_GET['type'], $_GET['forum'], $_GET['recursive']);
$smarty->assign('query', $_GET['query']);
$smarty->assign('type', $_GET['type']);
$smarty->assign('results', $results);
break;
default:
_error(404);
break;
}
/* assign variables */
$smarty->assign('view', $_GET['view']);
} catch (Exception $e) {
_error(__("Error"), $e->getMessage());
}
// page footer
page_footer("forums");
?>