-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewforum.php
231 lines (183 loc) · 10.2 KB
/
viewforum.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
<?php
/**
* Copyright (C) 2013-2014 ModernBB Group
* Based on code by FluxBB copyright (C) 2008-2012 FluxBB
* Based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
* Licensed under GPLv3 (http://modernbb.be/license.php)
*/
define('FORUM_ROOT', dirname(__FILE__).'/');
require FORUM_ROOT.'include/common.php';
if ($luna_user['g_read_board'] == '0')
message($lang['No view'], false, '403 Forbidden');
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 1)
message($lang['Bad request'], false, '404 Not Found');
// Fetch some info about the forum
if (!$luna_user['is_guest'])
$result = $db->query('SELECT f.forum_name, f.redirect_url, f.moderators, f.num_topics, f.sort_by, fp.post_topics, s.user_id AS is_subscribed FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_subscriptions AS s ON (f.id=s.forum_id AND s.user_id='.$luna_user['id'].') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
else
$result = $db->query('SELECT f.forum_name, f.redirect_url, f.moderators, f.num_topics, f.sort_by, fp.post_topics, 0 AS is_subscribed FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message($lang['Bad request'], false, '404 Not Found');
$cur_forum = $db->fetch_assoc($result);
// Is this a redirect forum? In that case, redirect!
if ($cur_forum['redirect_url'] != '')
{
header('Location: '.$cur_forum['redirect_url']);
exit;
}
// Sort out who the moderators are and if we are currently a moderator (or an admin)
$mods_array = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
$is_admmod = ($luna_user['g_id'] == FORUM_ADMIN || ($luna_user['g_moderator'] == '1' && array_key_exists($luna_user['username'], $mods_array))) ? true : false;
switch ($cur_forum['sort_by'])
{
case 0:
$sort_by = 'last_post DESC';
break;
case 1:
$sort_by = 'posted DESC';
break;
case 2:
$sort_by = 'subject ASC';
break;
default:
$sort_by = 'last_post DESC';
break;
}
// Can we or can we not post new topics?
if (($cur_forum['post_topics'] == '' && $luna_user['g_post_topics'] == '1') || $cur_forum['post_topics'] == '1' || $is_admmod)
$post_link = "\t\t\t".'<a class="btn btn-primary btn-post pull-right" href="post.php?fid='.$id.'">'.$lang['Post new topic'].'</a>'."\n";
else
$post_link = '';
// Get topic/forum tracking data
if (!$luna_user['is_guest'])
$tracked_topics = get_tracked_topics();
// Determine the topic offset (based on $_GET['p'])
$num_pages = ceil($cur_forum['num_topics'] / $luna_user['disp_topics']);
$p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
$start_from = $luna_user['disp_topics'] * ($p - 1);
// Generate paging links
$paging_links = paginate($num_pages, $p, 'viewforum.php?id='.$id);
if ($luna_config['o_feed_type'] == '1')
$page_head = array('feed' => '<link rel="alternate" type="application/rss+xml" href="extern.php?action=feed&fid='.$id.'&type=rss" title="'.$lang['RSS forum feed'].'" />');
else if ($luna_config['o_feed_type'] == '2')
$page_head = array('feed' => '<link rel="alternate" type="application/atom+xml" href="extern.php?action=feed&fid='.$id.'&type=atom" title="'.$lang['Atom forum feed'].'" />');
$forum_actions = array();
if (!$luna_user['is_guest'])
{
if ($luna_config['o_forum_subscriptions'] == '1')
{
if ($cur_forum['is_subscribed'])
$forum_actions[] = '<a href="misc.php?action=unsubscribe&fid='.$id.'">'.$lang['Unsubscribe'].'</a>';
else
$forum_actions[] = '<a href="misc.php?action=subscribe&fid='.$id.'">'.$lang['Subscribe'].'</a>';
}
$forum_actions[] = '<a href="misc.php?action=markforumread&fid='.$id.'">'.$lang['Mark as read'].'</a>';
}
$page_title = array(luna_htmlspecialchars($luna_config['o_board_title']), luna_htmlspecialchars($cur_forum['forum_name']));
define('FORUM_ALLOW_INDEX', 1);
define('FORUM_ACTIVE_PAGE', 'index');
require FORUM_ROOT.'header.php';
require get_view_path('viewforum-header.tpl.php');
// Retrieve a list of topic IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data
$result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.$sort_by.', id DESC LIMIT '.$start_from.', '.$luna_user['disp_topics']) or error('Unable to fetch topic IDs', __FILE__, __LINE__, $db->error());
// If there are topics in this forum
if ($db->num_rows($result))
{
$topic_ids = array();
for ($i = 0; $cur_topic_id = $db->result($result, $i); $i++)
$topic_ids[] = $cur_topic_id;
// Fetch list of topics to display on this page
if ($luna_user['is_guest'] || $luna_config['o_has_posted'] == '0')
{
// When not showing a posted label
$sql = 'SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, last_poster_id, num_views, num_replies, closed, sticky, moved_to FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $topic_ids).') ORDER BY sticky DESC, '.$sort_by.', id DESC';
}
else
{
// When showing a posted label
$sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$luna_user['id'].' WHERE t.id IN('.implode(',', $topic_ids).') GROUP BY t.id'.($db_type == 'pgsql' ? ', t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to, p.poster_id' : '').' ORDER BY t.sticky DESC, t.'.$sort_by.', t.id DESC';
}
$result = $db->query($sql) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
$topic_count = 0;
while ($cur_topic = $db->fetch_assoc($result)) {
++$topic_count;
$status_text = array();
$item_status = ($topic_count % 2 == 0) ? 'roweven' : 'rowodd';
$icon_type = 'icon';
if (is_null($cur_topic['moved_to']))
if ($luna_user['g_view_users'] == '1' && $cur_topic['last_poster_id'] > '1')
$last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> <span class="byuser">'.$lang['by'].' <a href="profile.php?id='.$cur_topic['last_poster_id'].'">'.luna_htmlspecialchars($cur_topic['last_poster']).'</a></span>';
else
$last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> <span class="byuser">'.$lang['by'].' '.luna_htmlspecialchars($cur_topic['last_poster']).'</span>';
else
$last_post = '';
if ($luna_config['o_censoring'] == '1')
$cur_topic['subject'] = censor_words($cur_topic['subject']);
if ($cur_topic['sticky'] == '1')
{
$item_status .= ' isticky';
$status_text[] = '<span class="label label-success">'.$lang['Sticky'].'</span>';
}
if ($cur_topic['moved_to'] != 0)
{
$subject = '<a href="viewtopic.php?id='.$cur_topic['moved_to'].'">'.luna_htmlspecialchars($cur_topic['subject']).'</a> <br /><span class="byuser">'.$lang['by'].' '.luna_htmlspecialchars($cur_topic['poster']).'</span>';
$status_text[] = '<span class="label label-info">'.$lang['Moved'].'</span>';
$item_status .= ' imoved';
}
else if ($cur_topic['closed'] == '0')
$subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.luna_htmlspecialchars($cur_topic['subject']).'</a> <br /><span class="byuser">'.$lang['by'].' '.luna_htmlspecialchars($cur_topic['poster']).'</span>';
else
{
$subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.luna_htmlspecialchars($cur_topic['subject']).'</a> <br /><span class="byuser">'.$lang['by'].' '.luna_htmlspecialchars($cur_topic['poster']).'</span>';
$status_text[] = '<span class="label label-danger">'.$lang['Closed'].'</span>';
$item_status .= ' iclosed';
}
if (!$luna_user['is_guest'] && $luna_config['o_has_posted'] == '1')
{
if ($cur_topic['has_posted'] == $luna_user['id'])
{
$status_text[] = '<span class="glyphicon glyphicon-asterisk"></span>';
$item_status .= ' iposted';
}
}
if (!$luna_user['is_guest'] && $cur_topic['last_post'] > $luna_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_topic['id']]) || $tracked_topics['topics'][$cur_topic['id']] < $cur_topic['last_post']) && (!isset($tracked_topics['forums'][$id]) || $tracked_topics['forums'][$id] < $cur_topic['last_post']) && is_null($cur_topic['moved_to']))
{
$item_status .= ' inew';
$icon_type = 'icon icon-new';
$subject = '<strong>'.$subject.'</strong>';
$subject_new_posts = '<span class="newtext">[ <a href="viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.$lang['New posts info'].'">'.$lang['New posts'].'</a> ]</span>';
}
else
$subject_new_posts = null;
// Insert the status text before the subject
$subject = implode(' ', $status_text).' '.$subject;
$num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $luna_user['disp_posts']);
if ($num_pages_topic > 1)
$subject_multipage = '<span class="inline-pagination"> '.simple_paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).'</span>';
else
$subject_multipage = null;
// Should we show the "New posts" and/or the multipage links?
if (!empty($subject_new_posts) || !empty($subject_multipage))
{
$subject .= !empty($subject_new_posts) ? ' '.$subject_new_posts : '';
$subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
}
if (forum_number_format($cur_topic['num_replies']) == '1') {
$replies_label = $lang['reply'];
} else {
$replies_label = $lang['replies'];
}
if (forum_number_format($cur_topic['num_views']) == '1') {
$views_label = $lang['view'];
} else {
$views_label = $lang['views'];
}
require get_view_path('viewforum-topics_list.tpl.php');
}
} else {
require get_view_path('viewforum-topics_list_empty.tpl.php');
}
$forum_id = $id;
$footer_style = 'viewforum';
require get_view_path('viewforum-footer.tpl.php');