punbb/viewforum.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 5 e3d7322305bf
equal deleted inserted replaced
1:8f6143115bf5 2:a8a21e1c7afa
    21   MA  02111-1307  USA
    21   MA  02111-1307  USA
    22 
    22 
    23 ************************************************************************/
    23 ************************************************************************/
    24 
    24 
    25 
    25 
    26 define('PUN_ROOT', './');
    26 //define('PUN_ROOT', './');
    27 require PUN_ROOT.'include/common.php';
    27 //require PUN_ROOT.'include/common.php';
       
    28 
       
    29 global $pun_db, $pun_user, $pun_config, $lang_common;
       
    30 
    28 
    31 
    29 
    32 
    30 if ($pun_user['g_read_board'] == '0')
    33 if ($pun_user['g_read_board'] == '0')
    31 	message($lang_common['No view']);
    34 	message($lang_common['No view']);
    32 
    35 
    37 
    40 
    38 // Load the viewforum.php language file
    41 // Load the viewforum.php language file
    39 require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
    42 require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
    40 
    43 
    41 // Fetch some info about the forum
    44 // Fetch some info about the forum
    42 $result = $db->query('SELECT f.forum_name, f.redirect_url, f.moderators, f.num_topics, f.sort_by, fp.post_topics 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());
    45 $result = $pun_db->query('SELECT f.forum_name, f.redirect_url, f.moderators, f.num_topics, f.sort_by, fp.post_topics FROM '.$pun_db->prefix.'forums AS f LEFT JOIN '.$pun_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__, $pun_db->error());
    43 if (!$db->num_rows($result))
    46 if (!$pun_db->num_rows($result))
    44 	message($lang_common['Bad request']);
    47 	message($lang_common['Bad request']);
    45 
    48 
    46 $cur_forum = $db->fetch_assoc($result);
    49 $cur_forum = $pun_db->fetch_assoc($result);
    47 
    50 
    48 // Is this a redirect forum? In that case, redirect!
    51 // Is this a redirect forum? In that case, redirect!
    49 if ($cur_forum['redirect_url'] != '')
    52 if ($cur_forum['redirect_url'] != '')
    50 {
    53 {
    51 	header('Location: '.$cur_forum['redirect_url']);
    54 	header('Location: '.$cur_forum['redirect_url']);
    71 
    74 
    72 $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
    75 $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
    73 $start_from = $pun_user['disp_topics'] * ($p - 1);
    76 $start_from = $pun_user['disp_topics'] * ($p - 1);
    74 
    77 
    75 // Generate paging links
    78 // Generate paging links
    76 $paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'viewforum.php?id='.$id);
    79 $paging_links = $lang_common['Pages'].': '.pun_paginate($num_pages, $p, 'viewforum.php?id='.$id);
    77 
    80 
    78 
    81 
    79 $page_title = pun_htmlspecialchars($pun_config['o_board_title'].' / '.$cur_forum['forum_name']);
    82 $page_title = pun_htmlspecialchars($pun_config['o_board_title'].' / '.$cur_forum['forum_name']);
    80 define('PUN_ALLOW_INDEX', 1);
    83 define('PUN_ALLOW_INDEX', 1);
    81 require PUN_ROOT.'header.php';
    84 require PUN_ROOT.'header.php';
   108 
   111 
   109 // Fetch list of topics to display on this page
   112 // Fetch list of topics to display on this page
   110 if ($pun_user['is_guest'] || $pun_config['o_show_dot'] == '0')
   113 if ($pun_user['is_guest'] || $pun_config['o_show_dot'] == '0')
   111 {
   114 {
   112 	// Without "the dot"
   115 	// Without "the dot"
   113 	$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 forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'];
   116 	$sql = 'SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM '.$pun_db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'];
   114 }
   117 }
   115 else
   118 else
   116 {
   119 {
   117 	// With "the dot"
   120 	// With "the dot"
   118 	switch ($db_type)
   121 	switch ($db_type)
   119 	{
   122 	{
   120 		case 'mysql':
   123 		case 'mysql':
   121 		case 'mysqli':
   124 		case 'mysqli':
   122 			$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.forum_id='.$id.' GROUP BY t.id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'];
   125 			$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 '.$pun_db->prefix.'topics AS t LEFT JOIN '.$pun_db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY t.id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'];
   123 			break;
   126 			break;
   124 
   127 
   125 		case 'sqlite':
   128 		case 'sqlite':
   126 			$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(SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'].') GROUP BY t.id ORDER BY t.sticky DESC, t.last_post DESC';
   129 			$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 '.$pun_db->prefix.'topics AS t LEFT JOIN '.$pun_db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' 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 '.$start_from.', '.$pun_user['disp_topics'].') GROUP BY t.id ORDER BY t.sticky DESC, t.last_post DESC';
   127 			break;
   130 			break;
   128 
   131 
   129 		default:
   132 		default:
   130 			$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.forum_id='.$id.' GROUP BY 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, p.poster_id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'];
   133 			$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 '.$pun_db->prefix.'topics AS t LEFT JOIN '.$pun_db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY 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, p.poster_id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'];
   131 			break;
   134 			break;
   132 
   135 
   133 	}
   136 	}
   134 }
   137 }
   135 
   138 
   136 $result = $db->query($sql) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
   139 $result = $pun_db->query($sql) or error('Unable to fetch topic list', __FILE__, __LINE__, $pun_db->error());
   137 
   140 
   138 // If there are topics in this forum.
   141 // If there are topics in this forum.
   139 if ($db->num_rows($result))
   142 if ($pun_db->num_rows($result))
   140 {
   143 {
   141 	while ($cur_topic = $db->fetch_assoc($result))
   144 	while ($cur_topic = $pun_db->fetch_assoc($result))
   142 	{
   145 	{
   143 		$icon_text = $lang_common['Normal icon'];
   146 		$icon_text = $lang_common['Normal icon'];
   144 		$item_status = '';
   147 		$item_status = '';
   145 		$icon_type = 'icon';
   148 		$icon_type = 'icon';
   146 
   149 
   191 		}
   194 		}
   192 
   195 
   193 		$num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
   196 		$num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
   194 
   197 
   195 		if ($num_pages_topic > 1)
   198 		if ($num_pages_topic > 1)
   196 			$subject_multipage = '[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]';
   199 			$subject_multipage = '[ '.pun_paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]';
   197 		else
   200 		else
   198 			$subject_multipage = null;
   201 			$subject_multipage = null;
   199 
   202 
   200 		// Should we show the "New posts" and/or the multipage links?
   203 		// Should we show the "New posts" and/or the multipage links?
   201 		if (!empty($subject_new_posts) || !empty($subject_multipage))
   204 		if (!empty($subject_new_posts) || !empty($subject_multipage))