punbb/viewforum.php
changeset 7 98bbc533541c
equal deleted inserted replaced
6:5e1f1e916419 7:98bbc533541c
       
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2008  PunBB.org
       
     5 
       
     6   This file is part of PunBB.
       
     7 
       
     8   PunBB is free software; you can redistribute it and/or modify it
       
     9   under the terms of the GNU General Public License as published
       
    10   by the Free Software Foundation; either version 2 of the License,
       
    11   or (at your option) any later version.
       
    12 
       
    13   PunBB is distributed in the hope that it will be useful, but
       
    14   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16   GNU General Public License for more details.
       
    17 
       
    18   You should have received a copy of the GNU General Public License
       
    19   along with this program; if not, write to the Free Software
       
    20   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
       
    21   MA  02111-1307  USA
       
    22 
       
    23 ************************************************************************/
       
    24 
       
    25 
       
    26 // if (!defined('PUN_ROOT'))
       
    27 // 	define('PUN_ROOT', './');
       
    28 // require PUN_ROOT.'include/common.php';
       
    29 
       
    30 // import globals (I really hope this isn't dangerous)
       
    31 foreach ( $GLOBALS as $key => $_ )
       
    32 {
       
    33   $$key =& $GLOBALS[$key];
       
    34 }
       
    35 
       
    36 ($hook = get_hook('vf_start')) ? eval($hook) : null;
       
    37 
       
    38 if ($pun_user['g_read_board'] == '0')
       
    39 	message($lang_common['No view']);
       
    40 
       
    41 // Load the viewforum.php language file
       
    42 require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
       
    43 
       
    44 
       
    45 $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
       
    46 if ($id < 1)
       
    47 	message($lang_common['Bad request']);
       
    48 
       
    49 
       
    50 // Fetch some info about the forum
       
    51 $query = array(
       
    52 	'SELECT'	=> 'f.forum_name, f.redirect_url, f.moderators, f.num_topics, f.sort_by, fp.post_topics',
       
    53 	'FROM'		=> 'forums AS f',
       
    54 	'JOINS'		=> array(
       
    55 		array(
       
    56 			'LEFT JOIN'		=> 'forum_perms AS fp',
       
    57 			'ON'			=> '(fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].')'
       
    58 		)
       
    59 	),
       
    60 	'WHERE'		=> '(fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id
       
    61 );
       
    62 
       
    63 ($hook = get_hook('vf_qr_get_forum_info')) ? eval($hook) : null;
       
    64 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
    65 if (!$pun_db->num_rows($result))
       
    66 	message($lang_common['Bad request']);
       
    67 
       
    68 $cur_forum = $pun_db->fetch_assoc($result);
       
    69 
       
    70 // Is this a redirect forum? In that case, redirect!
       
    71 if ($cur_forum['redirect_url'] != '')
       
    72 {
       
    73 	($hook = get_hook('vf_redirect_forum_pre_redirect')) ? eval($hook) : null;
       
    74 
       
    75 	header('Location: '.$cur_forum['redirect_url']);
       
    76 	exit;
       
    77 }
       
    78 
       
    79 // Sort out who the moderators are and if we are currently a moderator (or an admin)
       
    80 $mods_array = array();
       
    81 if ($cur_forum['moderators'] != '')
       
    82 	$mods_array = unserialize($cur_forum['moderators']);
       
    83 
       
    84 $pun_user['is_admmod'] = ($session->user_level >= USER_LEVEL_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
       
    85 
       
    86 // Sort out whether or not this user can post
       
    87 $pun_user['may_post'] = (($cur_forum['post_topics'] == '' && $pun_user['g_post_topics'] == '1') || $cur_forum['post_topics'] == '1' || $pun_user['is_admmod']) ? true : false;
       
    88 
       
    89 // Get topic/forum tracking data
       
    90 if (!$pun_user['is_guest'])
       
    91 	$tracked_topics = get_tracked_topics();
       
    92 
       
    93 // Determine the topic offset (based on $_GET['p'])
       
    94 $pun_page['num_pages'] = ceil($cur_forum['num_topics'] / $pun_user['disp_topics']);
       
    95 $pun_page['page'] = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $pun_page['num_pages']) ? 1 : $_GET['p'];
       
    96 $pun_page['start_from'] = $pun_user['disp_topics'] * ($pun_page['page'] - 1);
       
    97 $pun_page['finish_at'] = min(($pun_page['start_from'] + $pun_user['disp_topics']), ($cur_forum['num_topics']));
       
    98 
       
    99 // Navigation links for header and page numbering for title/meta description
       
   100 if ($pun_page['page'] < $pun_page['num_pages'])
       
   101 {
       
   102 	$pun_page['nav'][] = '<link rel="last" href="'.pun_sublink($pun_url['forum'], $pun_url['page'], $pun_page['num_pages'], array($id, sef_friendly($cur_forum['forum_name']))).'" title="'.$lang_common['Page'].' '.$pun_page['num_pages'].'" />';
       
   103 	$pun_page['nav'][] = '<link rel="next" href="'.pun_sublink($pun_url['forum'], $pun_url['page'], ($pun_page['page'] + 1), array($id, sef_friendly($cur_forum['forum_name']))).'" title="'.$lang_common['Page'].' '.($pun_page['page'] + 1).'" />';
       
   104 }
       
   105 if ($pun_page['page'] > 1)
       
   106 {
       
   107 	$pun_page['nav'][] = '<link rel="prev" href="'.pun_sublink($pun_url['forum'], $pun_url['page'], ($pun_page['page'] - 1), array($id, sef_friendly($cur_forum['forum_name']))).'" title="'.$lang_common['Page'].' '.($pun_page['page'] - 1).'" />';
       
   108 	$pun_page['nav'][] = '<link rel="first" href="'.pun_link($pun_url['forum'], array($id, sef_friendly($cur_forum['forum_name']))).'" title="'.$lang_common['Page'].' 1" />';
       
   109 }
       
   110 
       
   111 
       
   112 // Fetch list of topics
       
   113 $query = array(
       
   114 	'SELECT'	=> 't.id, t.poster, t.subject, t.posted, t.first_post_id, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to',
       
   115 	'FROM'		=> 'topics AS t',
       
   116 	'WHERE'		=> 't.forum_id='.$id,
       
   117 	'ORDER BY'	=> 'sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC',
       
   118 	'LIMIT'		=> $pun_page['start_from'].', '.$pun_user['disp_topics']
       
   119 );
       
   120 
       
   121 // With "has posted" indication
       
   122 if (!$pun_user['is_guest'] && $pun_config['o_show_dot'] == '1')
       
   123 {
       
   124 	$query['SELECT'] .= ', p.poster_id AS has_posted';
       
   125 	$query['JOINS'][] = array(
       
   126 		'LEFT JOIN'	=> 'posts AS p',
       
   127 		'ON'		=> 't.id=p.topic_id AND p.poster_id='.$pun_user['id']
       
   128 	);
       
   129 
       
   130 	if ($db_type == 'sqlite')
       
   131 	{
       
   132 		$query['WHERE'] = 't.id IN(SELECT id FROM '.$pun_db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$pun_page['start_from'].', '.$pun_user['disp_topics'].')';
       
   133 		$query['ORDER BY'] = 't.sticky DESC, t.last_post DESC';
       
   134 	}
       
   135 
       
   136 	$query['GROUP BY'] = ($db_type != 'pgsql') ? 't.id' : 't.id, t.subject, t.poster, t.posted, t.first_post_id, 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';
       
   137 }
       
   138 
       
   139 ($hook = get_hook('vf_qr_get_topics')) ? eval($hook) : null;
       
   140 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   141 
       
   142 // Generate page information
       
   143 if ($pun_page['num_pages'] > 1)
       
   144 	$pun_page['main_info'] = '<span>'.sprintf($lang_common['Page number'], $pun_page['page'], $pun_page['num_pages']).' </span>'.sprintf($lang_common['Paged info'], $lang_common['Topics'], $pun_page['start_from'] + 1, $pun_page['finish_at'], $cur_forum['num_topics']);
       
   145 else
       
   146 	$pun_page['main_info'] = (($pun_db->num_rows($result)) ? sprintf($lang_common['Page info'], $lang_common['Topics'], $cur_forum['num_topics']) : $lang_forum['No topics']);
       
   147 
       
   148 // Generate paging/posting links
       
   149 $pun_page['page_post'][] = '<p class="paging"><strong>'.$lang_common['Pages'].'</strong> '.pun_paginate($pun_page['num_pages'], $pun_page['page'], $pun_url['forum'], array($id, sef_friendly($cur_forum['forum_name']))).'</p>';
       
   150 
       
   151 if ($pun_user['may_post'])
       
   152 	$pun_page['page_post'][] = '<p class="posting"><a class="newpost" href="'.pun_link($pun_url['new_topic'], $id).'"><span>'.$lang_forum['Post topic'].'</span></a></p>';
       
   153 
       
   154 // Setup main head/foot options
       
   155 $pun_page['main_head_options'] = array(
       
   156 	'<a class="feed-option" href="'.pun_link($pun_url['forum_atom'], $id).'"><span>'.$lang_common['ATOM Feed'].'</span></a>',
       
   157 	'<a class="feed-option" href="'.pun_link($pun_url['forum_rss'], $id).'"><span>'.$lang_common['RSS Feed'].'</span></a>'
       
   158 );
       
   159 
       
   160 $pun_page['main_foot_options'] = array();
       
   161 if ($pun_user['is_guest'] && !$pun_user['may_post'])
       
   162 	$pun_page['main_foot_options'][] = sprintf($lang_forum['Forum login nag'], '<a href="'.pun_link($pun_url['login']).'">'.strtolower($lang_common['Login']).'</a>', '<a href="'.pun_link($pun_url['register']).'">'.strtolower($lang_common['Register']).'</a>');
       
   163 
       
   164 if (!$pun_user['is_guest'] && $pun_db->num_rows($result))
       
   165 {
       
   166 	$pun_page['main_foot_options'][] = '<a class="user-option" href="'.pun_link($pun_url['mark_forum_read'], $id).'"><span>'.$lang_forum['Mark forum read'].'</span></a>';
       
   167 
       
   168 	if ($pun_user['is_admmod'])
       
   169 		$pun_page['main_foot_options'][] = '<a class="mod-option" href="'.pun_sublink($pun_url['moderate_forum'], $pun_url['page'], $pun_page['page'], $id).'"><span>'.$lang_forum['Moderate forum'].'</span></a>';
       
   170 }
       
   171 
       
   172 // Setup breadcrumbs
       
   173 $pun_page['crumbs'] = array(
       
   174 	array($pun_config['o_board_title'], pun_link($pun_url['index'])),
       
   175 	array($cur_forum['forum_name'], pun_link($pun_url['forum'], array($id, sef_friendly($cur_forum['forum_name']))))
       
   176 );
       
   177 
       
   178 ($hook = get_hook('vf_pre_header_load')) ? eval($hook) : null;
       
   179 
       
   180 define('PUN_ALLOW_INDEX', 1);
       
   181 define('PUN_PAGE', 'viewforum');
       
   182 require PUN_ROOT.'header.php';
       
   183 
       
   184 ?>
       
   185 <div id="pun-main" class="main paged">
       
   186 
       
   187 	<h1><span><a class="permalink" href="<?php echo pun_link($pun_url['forum'], array($id, sef_friendly($cur_forum['forum_name']))) ?>" rel="bookmark" title="<?php echo $lang_forum['Permalink forum'] ?>"><?php echo htmlspecialchars($cur_forum['forum_name']) ?></a></span></h1>
       
   188 
       
   189 	<div class="paged-head">
       
   190 		<?php echo implode("\n\t\t", $pun_page['page_post'])."\n" ?>
       
   191 	</div>
       
   192 
       
   193 	<div class="main-head">
       
   194 		<p class="main-options"><?php echo implode(' ', $pun_page['main_head_options']) ?></p>
       
   195 		<h2><span><?php echo $pun_page['main_info'] ?></span></h2>
       
   196 	</div>
       
   197 
       
   198 	<div id="forum<?php echo $id ?>" class="main-content forum">
       
   199 		<table cellspacing="0" summary="<?php printf($lang_forum['Table summary'], htmlspecialchars($cur_forum['forum_name'])) ?>">
       
   200 			<thead>
       
   201 				<tr>
       
   202 					<th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
       
   203 					<th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th>
       
   204 <?php if ($pun_config['o_topic_views'] == '1'): ?>					<th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th>
       
   205 <?php endif; ($hook = get_hook('vf_table_header_after_num_views')) ? eval($hook) : null; ?>					<th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
       
   206 <?php ($hook = get_hook('vf_table_header_after_last_post')) ? eval($hook) : null; ?>
       
   207 				</tr>
       
   208 			</thead>
       
   209 			<tbody class="statused">
       
   210 <?php
       
   211 
       
   212 // If there are topics in this forum
       
   213 if ($pun_db->num_rows($result))
       
   214 {
       
   215 	($hook = get_hook('vf_pre_topic_loop_start')) ? eval($hook) : null;
       
   216 
       
   217 	$pun_page['item_count'] = 0;
       
   218 
       
   219 	while ($cur_topic = $pun_db->fetch_assoc($result))
       
   220 	{
       
   221 		++$pun_page['item_count'];
       
   222 
       
   223 		// Start from scratch
       
   224 		$pun_page['item_subject'] = $pun_page['item_status'] = $pun_page['item_last_post'] = $pun_page['item_alt_message'] = $pun_page['item_nav'] = array();
       
   225 		$pun_page['item_indicator'] = '';
       
   226 		$pun_page['item_alt_message'][] = $lang_common['Topic'].' '.($pun_page['start_from'] + $pun_page['item_count']);
       
   227 
       
   228 		if ($pun_config['o_censoring'] == '1')
       
   229 			$cur_topic['subject'] = censor_words($cur_topic['subject']);
       
   230 
       
   231 		if ($cur_topic['moved_to'] != null)
       
   232 		{
       
   233 			$pun_page['item_status'][] = 'moved';
       
   234 			$pun_page['item_last_post'][] = $pun_page['item_alt_message'][] = $lang_forum['Moved'];
       
   235 			$pun_page['item_subject'][] = '<a href="'.pun_link($pun_url['topic'], array($cur_topic['moved_to'], sef_friendly($cur_topic['subject']))).'">'.htmlspecialchars($cur_topic['subject']).'</a>';
       
   236 			$pun_page['item_subject'][] = '<span class="byuser">'.sprintf($lang_common['By user'], htmlspecialchars($cur_topic['poster'])).'</span>';
       
   237 			$cur_topic['num_replies'] = $cur_topic['num_views'] = ' - ';
       
   238 		}
       
   239 		else
       
   240 		{
       
   241 			// Should we display the dot or not? :)
       
   242 			if (!$pun_user['is_guest'] && $pun_config['o_show_dot'] == '1' && $cur_topic['has_posted'] == $pun_user['id'])
       
   243 			{
       
   244 				$pun_page['item_indicator'] = $lang_forum['You posted indicator'];
       
   245 				$pun_page['item_status'][] = 'posted';
       
   246 				$pun_page['item_alt_message'][] = $lang_forum['You posted'];
       
   247 			}
       
   248 
       
   249 			if ($cur_topic['sticky'] == '1')
       
   250 			{
       
   251 				$pun_page['item_subject'][] = $lang_forum['Sticky'];
       
   252 				$pun_page['item_status'][] = 'sticky';
       
   253 			}
       
   254 
       
   255 			if ($cur_topic['closed'] == '1')
       
   256 			{
       
   257 				$pun_page['item_subject'][] = $lang_common['Closed'];
       
   258 				$pun_page['item_status'][] = 'closed';
       
   259 			}
       
   260 
       
   261 			$pun_page['item_subject'][] = '<a href="'.pun_link($pun_url['topic'], array($cur_topic['id'], sef_friendly($cur_topic['subject']))).'">'.htmlspecialchars($cur_topic['subject']).'</a>';
       
   262 
       
   263 			$pun_page['item_pages'] = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
       
   264 
       
   265 			if ($pun_page['item_pages'] > 1)
       
   266 				$pun_page['item_nav'][] = pun_paginate($pun_page['item_pages'], -1, $pun_url['topic'], array($cur_topic['id'], sef_friendly($cur_topic['subject'])));
       
   267 
       
   268 			// Does this topic contain posts we haven't read? If so, tag it accordingly.
       
   269 			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']))
       
   270 			{
       
   271 				$pun_page['item_nav'][] = '<a href="'.pun_link($pun_url['topic_new_posts'], array($cur_topic['id'], sef_friendly($cur_topic['subject']))).'" title="'.$lang_forum['New posts info'].'">'.$lang_common['New posts'].'</a>';
       
   272 				$pun_page['item_status'][] = 'new';
       
   273 			}
       
   274 
       
   275 			if (!empty($pun_page['item_nav']))
       
   276 				$pun_page['item_subject'][] = '<span class="topic-nav">[&#160;'.implode('&#160;&#160;', $pun_page['item_nav']).'&#160;]</span>';
       
   277 
       
   278 			$pun_page['item_subject'][] = '<span class="byuser">'.sprintf($lang_common['By user'], htmlspecialchars($cur_topic['poster'])).'</span>';
       
   279 			$pun_page['item_last_post'][] = '<a href="'.pun_link($pun_url['post'], $cur_topic['last_post_id']).'"><span>'.format_time($cur_topic['last_post']).'</span></a>';
       
   280 			$pun_page['item_last_post'][] = '<span class="byuser">'.sprintf($lang_common['By user'], htmlspecialchars($cur_topic['last_poster'])).'</span>';
       
   281 
       
   282 			if (empty($pun_page['item_status']))
       
   283 				$pun_page['item_status'][] = 'normal';
       
   284 		}
       
   285 
       
   286 		$pun_page['item_style'] = (($pun_page['item_count'] % 2 != 0) ? 'odd' : 'even').' '.implode(' ', $pun_page['item_status']);
       
   287 		$pun_page['item_indicator'] = '<span class="status '.implode(' ', $pun_page['item_status']).'" title="'.implode(' - ', $pun_page['item_alt_message']).'"><img src="'.$base_url.'/style/'.$pun_user['style'].'/status.png" alt="'.implode(' - ', $pun_page['item_alt_message']).'" />'.$pun_page['item_indicator'].'</span>';
       
   288 
       
   289 		($hook = get_hook('vf_row_pre_display')) ? eval($hook) : null;
       
   290 
       
   291 ?>
       
   292 				<tr class="<?php echo $pun_page['item_style'] ?>">
       
   293 					<td class="tcl"><?php echo $pun_page['item_indicator'].' '.implode(' ', $pun_page['item_subject']) ?></td>
       
   294 					<td class="tc2"><?php echo $cur_topic['num_replies'] ?></td>
       
   295 <?php if ($pun_config['o_topic_views'] == '1'): ?>					<td class="tc3"><?php echo $cur_topic['num_views'] ?></td>
       
   296 <?php endif; ($hook = get_hook('vf_table_contents_after_num_views')) ? eval($hook) : null; ?>					<td class="tcr"><?php echo implode(' ', $pun_page['item_last_post']) ?></td>
       
   297 <?php ($hook = get_hook('vf_table_contents_after_last_post')) ? eval($hook) : null; ?>
       
   298 				</tr>
       
   299 <?php
       
   300 
       
   301 	}
       
   302 }
       
   303 // Else there are no topics in this forum
       
   304 else
       
   305 {
       
   306 	$pun_page['item_indicator'] = '<span class="status empty" title="'.$lang_forum['No topics'].'"><img src="'.$base_url.'/style/'.$pun_user['style'].'/status.png" alt="'.$lang_forum['No topics'].'" /></span>';
       
   307 
       
   308 ?>
       
   309 				<tr class="odd empty">
       
   310 					<td class="tcl"><?php echo $pun_page['item_indicator'].' '.$lang_forum['First topic nag'] ?></td>
       
   311 					<td class="tc2">&#160;</td>
       
   312 <?php if ($pun_config['o_topic_views'] == '1'): ?>					<td class="tc3">&#160;</td>
       
   313 <?php endif; ?>					<td class="tcr"><?php echo $lang_forum['Never'] ?></td>
       
   314 				</tr>
       
   315 <?php
       
   316 
       
   317 }
       
   318 
       
   319 ?>
       
   320 			</tbody>
       
   321 		</table>
       
   322 	</div>
       
   323 
       
   324 	<div class="main-foot">
       
   325 		<p class="h2"><strong><?php echo $pun_page['main_info'] ?></strong></p>
       
   326 <?php if (!empty($pun_page['main_foot_options'])): ?>		<p class="main-options"><?php echo implode(' ', $pun_page['main_foot_options']) ?></p>
       
   327 <?php endif; ?>	</div>
       
   328 
       
   329 	<div class="paged-foot">
       
   330 		<?php echo implode("\n\t\t", array_reverse($pun_page['page_post']))."\n" ?>
       
   331 	</div>
       
   332 
       
   333 </div>
       
   334 
       
   335 <div id="pun-crumbs-foot">
       
   336 	<p class="crumbs"><?php echo generate_crumbs(false) ?></p>
       
   337 </div>
       
   338 <?php
       
   339 
       
   340 $forum_id = $id;
       
   341 
       
   342 ($hook = get_hook('vf_end')) ? eval($hook) : null;
       
   343 
       
   344 require PUN_ROOT.'footer.php';