1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Copyright (C) 2008-2011 FluxBB |
---|
5 | * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB |
---|
6 | * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher |
---|
7 | */ |
---|
8 | |
---|
9 | define('PUN_ROOT', dirname(__FILE__).'/'); |
---|
10 | require PUN_ROOT.'include/common.php'; |
---|
11 | |
---|
12 | |
---|
13 | if ($pun_user['g_read_board'] == '0') |
---|
14 | message($lang_common['No view']); |
---|
15 | |
---|
16 | |
---|
17 | $id = isset($_GET['id']) ? intval($_GET['id']) : 0; |
---|
18 | if ($id < 1) |
---|
19 | message($lang_common['Bad request']); |
---|
20 | |
---|
21 | // Load the viewforum.php language file |
---|
22 | require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php'; |
---|
23 | |
---|
24 | // Fetch some info about the forum |
---|
25 | if (!$pun_user['is_guest']) |
---|
26 | $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='.$pun_user['id'].') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_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()); |
---|
27 | else |
---|
28 | $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='.$pun_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()); |
---|
29 | |
---|
30 | if (!$db->num_rows($result)) |
---|
31 | message($lang_common['Bad request']); |
---|
32 | |
---|
33 | $cur_forum = $db->fetch_assoc($result); |
---|
34 | |
---|
35 | // Is this a redirect forum? In that case, redirect! |
---|
36 | if ($cur_forum['redirect_url'] != '') |
---|
37 | { |
---|
38 | header('Location: '.$cur_forum['redirect_url']); |
---|
39 | exit; |
---|
40 | } |
---|
41 | |
---|
42 | // Sort out who the moderators are and if we are currently a moderator (or an admin) |
---|
43 | $mods_array = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array(); |
---|
44 | $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false; |
---|
45 | |
---|
46 | switch ($cur_forum['sort_by']) |
---|
47 | { |
---|
48 | case 0: |
---|
49 | $sort_by = 'last_post DESC'; |
---|
50 | break; |
---|
51 | case 1: |
---|
52 | $sort_by = 'posted DESC'; |
---|
53 | break; |
---|
54 | case 2: |
---|
55 | $sort_by = 'subject ASC'; |
---|
56 | break; |
---|
57 | default: |
---|
58 | $sort_by = 'last_post DESC'; |
---|
59 | break; |
---|
60 | } |
---|
61 | |
---|
62 | // Can we or can we not post new topics? |
---|
63 | if (($cur_forum['post_topics'] == '' && $pun_user['g_post_topics'] == '1') || $cur_forum['post_topics'] == '1' || $is_admmod) |
---|
64 | $post_link = "\t\t\t".'<p class="postlink conr"><a href="post.php?fid='.$id.'">'.$lang_forum['Post topic'].'</a></p>'."\n"; |
---|
65 | else |
---|
66 | $post_link = ''; |
---|
67 | |
---|
68 | // Get topic/forum tracking data |
---|
69 | if (!$pun_user['is_guest']) |
---|
70 | $tracked_topics = get_tracked_topics(); |
---|
71 | |
---|
72 | // Determine the topic offset (based on $_GET['p']) |
---|
73 | $num_pages = ceil($cur_forum['num_topics'] / $pun_user['disp_topics']); |
---|
74 | |
---|
75 | $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']); |
---|
76 | $start_from = $pun_user['disp_topics'] * ($p - 1); |
---|
77 | |
---|
78 | // Generate paging links |
---|
79 | $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'viewforum.php?id='.$id); |
---|
80 | |
---|
81 | if ($pun_config['o_feed_type'] == '1') |
---|
82 | $page_head = array('feed' => '<link rel="alternate" type="application/rss+xml" href="extern.php?action=feed&fid='.$id.'&type=rss" title="'.$lang_common['RSS forum feed'].'" />'); |
---|
83 | else if ($pun_config['o_feed_type'] == '2') |
---|
84 | $page_head = array('feed' => '<link rel="alternate" type="application/atom+xml" href="extern.php?action=feed&fid='.$id.'&type=atom" title="'.$lang_common['Atom forum feed'].'" />'); |
---|
85 | |
---|
86 | $forum_actions = array(); |
---|
87 | |
---|
88 | if (!$pun_user['is_guest']) |
---|
89 | { |
---|
90 | if ($pun_config['o_forum_subscriptions'] == '1') |
---|
91 | { |
---|
92 | if ($cur_forum['is_subscribed']) |
---|
93 | $forum_actions[] = '<span>'.$lang_forum['Is subscribed'].' - </span><a href="misc.php?action=unsubscribe&fid='.$id.'">'.$lang_forum['Unsubscribe'].'</a>'; |
---|
94 | else |
---|
95 | $forum_actions[] = '<a href="misc.php?action=subscribe&fid='.$id.'">'.$lang_forum['Subscribe'].'</a>'; |
---|
96 | } |
---|
97 | |
---|
98 | $forum_actions[] = '<a href="misc.php?action=markforumread&fid='.$id.'">'.$lang_common['Mark forum read'].'</a>'; |
---|
99 | } |
---|
100 | |
---|
101 | $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), pun_htmlspecialchars($cur_forum['forum_name'])); |
---|
102 | define('PUN_ALLOW_INDEX', 1); |
---|
103 | define('PUN_ACTIVE_PAGE', 'index'); |
---|
104 | require PUN_ROOT.'header.php'; |
---|
105 | |
---|
106 | ?> |
---|
107 | <div class="linkst"> |
---|
108 | <div class="inbox crumbsplus"> |
---|
109 | <ul class="crumbs"> |
---|
110 | <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li> |
---|
111 | <li><span>» </span><a href="viewforum.php?id=<?php echo $id ?>"><strong><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></strong></a></li> |
---|
112 | </ul> |
---|
113 | <div class="pagepost"> |
---|
114 | <p class="pagelink conl"><?php echo $paging_links ?></p> |
---|
115 | <?php echo $post_link ?> |
---|
116 | </div> |
---|
117 | <div class="clearer"></div> |
---|
118 | </div> |
---|
119 | </div> |
---|
120 | |
---|
121 | <div id="vf" class="blocktable"> |
---|
122 | <h2><span><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></span></h2> |
---|
123 | <div class="box"> |
---|
124 | <div class="inbox"> |
---|
125 | <table cellspacing="0"> |
---|
126 | <thead> |
---|
127 | <tr> |
---|
128 | <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th> |
---|
129 | <th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th> |
---|
130 | <?php if ($pun_config['o_topic_views'] == '1'): ?> <th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th> |
---|
131 | <?php endif; ?> <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th> |
---|
132 | </tr> |
---|
133 | </thead> |
---|
134 | <tbody> |
---|
135 | <?php |
---|
136 | |
---|
137 | // Retrieve a list of topic IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data |
---|
138 | $result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.$sort_by.', id DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']) or error('Unable to fetch topic IDs', __FILE__, __LINE__, $db->error()); |
---|
139 | |
---|
140 | // If there are topics in this forum |
---|
141 | if ($db->num_rows($result)) |
---|
142 | { |
---|
143 | $topic_ids = array(); |
---|
144 | for ($i = 0;$cur_topic_id = $db->result($result, $i);$i++) |
---|
145 | $topic_ids[] = $cur_topic_id; |
---|
146 | |
---|
147 | if (empty($topic_ids)) |
---|
148 | error('The topic table and forum table seem to be out of sync!', __FILE__, __LINE__); |
---|
149 | |
---|
150 | // Fetch list of topics to display on this page |
---|
151 | if ($pun_user['is_guest'] || $pun_config['o_show_dot'] == '0') |
---|
152 | { |
---|
153 | // Without "the dot" |
---|
154 | $sql = 'SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, 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'; |
---|
155 | } |
---|
156 | else |
---|
157 | { |
---|
158 | // With "the dot" |
---|
159 | $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='.$pun_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'; |
---|
160 | } |
---|
161 | |
---|
162 | $result = $db->query($sql) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error()); |
---|
163 | |
---|
164 | $topic_count = 0; |
---|
165 | while ($cur_topic = $db->fetch_assoc($result)) |
---|
166 | { |
---|
167 | ++$topic_count; |
---|
168 | $status_text = array(); |
---|
169 | $item_status = ($topic_count % 2 == 0) ? 'roweven' : 'rowodd'; |
---|
170 | $icon_type = 'icon'; |
---|
171 | |
---|
172 | if ($cur_topic['moved_to'] == null) |
---|
173 | $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_common['by'].' '.pun_htmlspecialchars($cur_topic['last_poster']).'</span>'; |
---|
174 | else |
---|
175 | $last_post = '- - -'; |
---|
176 | |
---|
177 | if ($pun_config['o_censoring'] == '1') |
---|
178 | $cur_topic['subject'] = censor_words($cur_topic['subject']); |
---|
179 | |
---|
180 | if ($cur_topic['sticky'] == '1') |
---|
181 | { |
---|
182 | $item_status .= ' isticky'; |
---|
183 | $status_text[] = '<span class="stickytext">'.$lang_forum['Sticky'].'</span>'; |
---|
184 | } |
---|
185 | |
---|
186 | if ($cur_topic['moved_to'] != 0) |
---|
187 | { |
---|
188 | $subject = '<a href="viewtopic.php?id='.$cur_topic['moved_to'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>'; |
---|
189 | $status_text[] = '<span class="movedtext">'.$lang_forum['Moved'].'</span>'; |
---|
190 | $item_status .= ' imoved'; |
---|
191 | } |
---|
192 | else if ($cur_topic['closed'] == '0') |
---|
193 | $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>'; |
---|
194 | else |
---|
195 | { |
---|
196 | $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>'; |
---|
197 | $status_text[] = '<span class="closedtext">'.$lang_forum['Closed'].'</span>'; |
---|
198 | $item_status .= ' iclosed'; |
---|
199 | } |
---|
200 | |
---|
201 | if (!$pun_user['is_guest'] && $cur_topic['last_post'] > $pun_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']) && $cur_topic['moved_to'] == null) |
---|
202 | { |
---|
203 | $item_status .= ' inew'; |
---|
204 | $icon_type = 'icon icon-new'; |
---|
205 | $subject = '<strong>'.$subject.'</strong>'; |
---|
206 | $subject_new_posts = '<span class="newtext">[ <a href="viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]</span>'; |
---|
207 | } |
---|
208 | else |
---|
209 | $subject_new_posts = null; |
---|
210 | |
---|
211 | // Insert the status text before the subject |
---|
212 | $subject = implode(' ', $status_text).' '.$subject; |
---|
213 | |
---|
214 | // Should we display the dot or not? :) |
---|
215 | if (!$pun_user['is_guest'] && $pun_config['o_show_dot'] == '1') |
---|
216 | { |
---|
217 | if ($cur_topic['has_posted'] == $pun_user['id']) |
---|
218 | { |
---|
219 | $subject = '<strong class="ipost">· </strong>'.$subject; |
---|
220 | $item_status .= ' iposted'; |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']); |
---|
225 | |
---|
226 | if ($num_pages_topic > 1) |
---|
227 | $subject_multipage = '<span class="pagestext">[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]</span>'; |
---|
228 | else |
---|
229 | $subject_multipage = null; |
---|
230 | |
---|
231 | // Should we show the "New posts" and/or the multipage links? |
---|
232 | if (!empty($subject_new_posts) || !empty($subject_multipage)) |
---|
233 | { |
---|
234 | $subject .= !empty($subject_new_posts) ? ' '.$subject_new_posts : ''; |
---|
235 | $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : ''; |
---|
236 | } |
---|
237 | |
---|
238 | ?> |
---|
239 | <tr class="<?php echo $item_status ?>"> |
---|
240 | <td class="tcl"> |
---|
241 | <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo forum_number_format($topic_count + $start_from) ?></div></div> |
---|
242 | <div class="tclcon"> |
---|
243 | <div> |
---|
244 | <?php echo $subject."\n" ?> |
---|
245 | </div> |
---|
246 | </div> |
---|
247 | </td> |
---|
248 | <td class="tc2"><?php echo ($cur_topic['moved_to'] == null) ? forum_number_format($cur_topic['num_replies']) : '-' ?></td> |
---|
249 | <?php if ($pun_config['o_topic_views'] == '1'): ?> <td class="tc3"><?php echo ($cur_topic['moved_to'] == null) ? forum_number_format($cur_topic['num_views']) : '-' ?></td> |
---|
250 | <?php endif; ?> <td class="tcr"><?php echo $last_post ?></td> |
---|
251 | </tr> |
---|
252 | <?php |
---|
253 | |
---|
254 | } |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | $colspan = ($pun_config['o_topic_views'] == '1') ? 4 : 3; |
---|
259 | |
---|
260 | ?> |
---|
261 | <tr class="rowodd inone"> |
---|
262 | <td class="tcl" colspan="<?php echo $colspan ?>"> |
---|
263 | <div class="icon inone"><div class="nosize"><!-- --></div></div> |
---|
264 | <div class="tclcon"> |
---|
265 | <div> |
---|
266 | <strong><?php echo $lang_forum['Empty forum'] ?></strong> |
---|
267 | </div> |
---|
268 | </div> |
---|
269 | </td> |
---|
270 | </tr> |
---|
271 | <?php |
---|
272 | |
---|
273 | } |
---|
274 | |
---|
275 | ?> |
---|
276 | </tbody> |
---|
277 | </table> |
---|
278 | </div> |
---|
279 | </div> |
---|
280 | </div> |
---|
281 | |
---|
282 | <div class="linksb"> |
---|
283 | <div class="inbox crumbsplus"> |
---|
284 | <div class="pagepost"> |
---|
285 | <p class="pagelink conl"><?php echo $paging_links ?></p> |
---|
286 | <?php echo $post_link ?> |
---|
287 | </div> |
---|
288 | <ul class="crumbs"> |
---|
289 | <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li> |
---|
290 | <li><span>» </span><a href="viewforum.php?id=<?php echo $id ?>"><strong><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></strong></a></li> |
---|
291 | </ul> |
---|
292 | <?php echo (!empty($forum_actions) ? "\t\t".'<p class="subscribelink clearb">'.implode(' - ', $forum_actions).'</p>'."\n" : '') ?> |
---|
293 | <div class="clearer"></div> |
---|
294 | </div> |
---|
295 | </div> |
---|
296 | <?php |
---|
297 | |
---|
298 | $forum_id = $id; |
---|
299 | $footer_style = 'viewforum'; |
---|
300 | require PUN_ROOT.'footer.php'; |
---|