punbb/viewtopic.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
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 
    42 
    45 
    43 
    46 
    44 // If a post ID is specified we determine topic ID and page number so we can redirect to the correct message
    47 // If a post ID is specified we determine topic ID and page number so we can redirect to the correct message
    45 if ($pid)
    48 if ($pid)
    46 {
    49 {
    47 	$result = $db->query('SELECT topic_id FROM '.$db->prefix.'posts WHERE id='.$pid) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
    50 	$result = $pun_db->query('SELECT topic_id FROM '.$pun_db->prefix.'posts WHERE id='.$pid) or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
    48 	if (!$db->num_rows($result))
    51 	if (!$pun_db->num_rows($result))
    49 		message($lang_common['Bad request']);
    52 		message($lang_common['Bad request']);
    50 
    53 
    51 	$id = $db->result($result);
    54 	$id = $pun_db->result($result);
    52 
    55 
    53 	// Determine on what page the post is located (depending on $pun_user['disp_posts'])
    56 	// Determine on what page the post is located (depending on $pun_user['disp_posts'])
    54 	$result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$id.' ORDER BY posted') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
    57 	$result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'posts WHERE topic_id='.$id.' ORDER BY posted') or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
    55 	$num_posts = $db->num_rows($result);
    58 	$num_posts = $pun_db->num_rows($result);
    56 
    59 
    57 	for ($i = 0; $i < $num_posts; ++$i)
    60 	for ($i = 0; $i < $num_posts; ++$i)
    58 	{
    61 	{
    59 		$cur_id = $db->result($result, $i);
    62 		$cur_id = $pun_db->result($result, $i);
    60 		if ($cur_id == $pid)
    63 		if ($cur_id == $pid)
    61 			break;
    64 			break;
    62 	}
    65 	}
    63 	++$i;	// we started at 0
    66 	++$i;	// we started at 0
    64 
    67 
    66 }
    69 }
    67 
    70 
    68 // If action=new, we redirect to the first new post (if any)
    71 // If action=new, we redirect to the first new post (if any)
    69 else if ($action == 'new' && !$pun_user['is_guest'])
    72 else if ($action == 'new' && !$pun_user['is_guest'])
    70 {
    73 {
    71 	$result = $db->query('SELECT MIN(id) FROM '.$db->prefix.'posts WHERE topic_id='.$id.' AND posted>'.$pun_user['last_visit']) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
    74 	$result = $pun_db->query('SELECT MIN(id) FROM '.$pun_db->prefix.'posts WHERE topic_id='.$id.' AND posted>'.$pun_user['last_visit']) or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
    72 	$first_new_post_id = $db->result($result);
    75 	$first_new_post_id = $pun_db->result($result);
    73 
    76 
    74 	if ($first_new_post_id)
    77 	if ($first_new_post_id)
    75 		header('Location: viewtopic.php?pid='.$first_new_post_id.'#p'.$first_new_post_id);
    78 		header('Location: viewtopic.php?pid='.$first_new_post_id.'#p'.$first_new_post_id);
    76 	else	// If there is no new post, we go to the last post
    79 	else	// If there is no new post, we go to the last post
    77 		header('Location: viewtopic.php?id='.$id.'&action=last');
    80 		header('Location: viewtopic.php?id='.$id.'&action=last');
    80 }
    83 }
    81 
    84 
    82 // If action=last, we redirect to the last post
    85 // If action=last, we redirect to the last post
    83 else if ($action == 'last')
    86 else if ($action == 'last')
    84 {
    87 {
    85 	$result = $db->query('SELECT MAX(id) FROM '.$db->prefix.'posts WHERE topic_id='.$id) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
    88 	$result = $pun_db->query('SELECT MAX(id) FROM '.$pun_db->prefix.'posts WHERE topic_id='.$id) or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
    86 	$last_post_id = $db->result($result);
    89 	$last_post_id = $pun_db->result($result);
    87 
    90 
    88 	if ($last_post_id)
    91 	if ($last_post_id)
    89 	{
    92 	{
    90 		header('Location: viewtopic.php?pid='.$last_post_id.'#p'.$last_post_id);
    93 		header('Location: viewtopic.php?pid='.$last_post_id.'#p'.$last_post_id);
    91 		exit;
    94 		exit;
    93 }
    96 }
    94 
    97 
    95 
    98 
    96 // Fetch some info about the topic
    99 // Fetch some info about the topic
    97 if (!$pun_user['is_guest'])
   100 if (!$pun_user['is_guest'])
    98 	$result = $db->query('SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, s.user_id AS is_subscribed FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'subscriptions AS s ON (t.id=s.topic_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 t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
   101 	$result = $pun_db->query('SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, s.user_id AS is_subscribed FROM '.$pun_db->prefix.'topics AS t INNER JOIN '.$pun_db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$pun_db->prefix.'subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$pun_user['id'].') 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 t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $pun_db->error());
    99 else
   102 else
   100 	$result = $db->query('SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, 0 FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_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 t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
   103 	$result = $pun_db->query('SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, 0 FROM '.$pun_db->prefix.'topics AS t INNER JOIN '.$pun_db->prefix.'forums AS f ON f.id=t.forum_id 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 t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $pun_db->error());
   101 
   104 
   102 if (!$db->num_rows($result))
   105 if (!$pun_db->num_rows($result))
   103 	message($lang_common['Bad request']);
   106 	message($lang_common['Bad request']);
   104 
   107 
   105 $cur_topic = $db->fetch_assoc($result);
   108 $cur_topic = $pun_db->fetch_assoc($result);
   106 
   109 
   107 // Sort out who the moderators are and if we are currently a moderator (or an admin)
   110 // Sort out who the moderators are and if we are currently a moderator (or an admin)
   108 $mods_array = ($cur_topic['moderators'] != '') ? unserialize($cur_topic['moderators']) : array();
   111 $mods_array = ($cur_topic['moderators'] != '') ? unserialize($cur_topic['moderators']) : array();
   109 $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
   112 $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
   110 
   113 
   130 
   133 
   131 $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
   134 $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
   132 $start_from = $pun_user['disp_posts'] * ($p - 1);
   135 $start_from = $pun_user['disp_posts'] * ($p - 1);
   133 
   136 
   134 // Generate paging links
   137 // Generate paging links
   135 $paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'viewtopic.php?id='.$id);
   138 $paging_links = $lang_common['Pages'].': '.pun_paginate($num_pages, $p, 'viewtopic.php?id='.$id);
   136 
   139 
   137 
   140 
   138 if ($pun_config['o_censoring'] == '1')
   141 if ($pun_config['o_censoring'] == '1')
   139 	$cur_topic['subject'] = censor_words($cur_topic['subject']);
   142 	$cur_topic['subject'] = censor_words($cur_topic['subject']);
   140 
   143 
   181 
   184 
   182 $bg_switch = true;	// Used for switching background color in posts
   185 $bg_switch = true;	// Used for switching background color in posts
   183 $post_count = 0;	// Keep track of post numbers
   186 $post_count = 0;	// Keep track of post numbers
   184 
   187 
   185 // Retrieve the posts (and their respective poster/online status)
   188 // Retrieve the posts (and their respective poster/online status)
   186 $result = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
   189 $result = $pun_db->query('SELECT eu.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$pun_db->prefix.'posts AS p INNER JOIN '.$pun_db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.table_prefix.'users AS eu ON eu.user_id=u.id INNER JOIN '.$pun_db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$pun_db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
   187 while ($cur_post = $db->fetch_assoc($result))
   190 while ($cur_post = $pun_db->fetch_assoc($result))
   188 {
   191 {
   189 	$post_count++;
   192 	$post_count++;
   190 	$user_avatar = '';
   193 	$user_avatar = '';
   191 	$user_info = array();
   194 	$user_info = array();
   192 	$user_contacts = array();
   195 	$user_contacts = array();
   229 				$user_info[] = '<dd>'.$lang_topic['From'].': '.pun_htmlspecialchars($cur_post['location']);
   232 				$user_info[] = '<dd>'.$lang_topic['From'].': '.pun_htmlspecialchars($cur_post['location']);
   230 			}
   233 			}
   231 
   234 
   232 			$user_info[] = '<dd>'.$lang_common['Registered'].': '.date($pun_config['o_date_format'], $cur_post['registered']);
   235 			$user_info[] = '<dd>'.$lang_common['Registered'].': '.date($pun_config['o_date_format'], $cur_post['registered']);
   233 
   236 
   234 			if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] < PUN_GUEST)
   237 			if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] >= USER_LEVEL_MEMBER)
   235 				$user_info[] = '<dd>'.$lang_common['Posts'].': '.$cur_post['num_posts'];
   238 				$user_info[] = '<dd>'.$lang_common['Posts'].': '.$cur_post['num_posts'];
   236 
   239 
   237 			// Now let's deal with the contact links (E-mail and URL)
   240 			// Now let's deal with the contact links (E-mail and URL)
   238 			if (($cur_post['email_setting'] == '0' && !$pun_user['is_guest']) || $pun_user['g_id'] < PUN_GUEST)
   241 			if (($cur_post['email_setting'] == '0' && !$pun_user['is_guest']) || $pun_user['g_id'] >= USER_LEVEL_MEMBER)
   239 				$user_contacts[] = '<a href="mailto:'.$cur_post['email'].'">'.$lang_common['E-mail'].'</a>';
   242 				$user_contacts[] = '<a href="mailto:'.$cur_post['email'].'">'.$lang_common['E-mail'].'</a>';
   240 			else if ($cur_post['email_setting'] == '1' && !$pun_user['is_guest'])
   243 			else if ($cur_post['email_setting'] == '1' && !$pun_user['is_guest'])
   241 				$user_contacts[] = '<a href="misc.php?email='.$cur_post['poster_id'].'">'.$lang_common['E-mail'].'</a>';
   244 				$user_contacts[] = '<a href="misc.php?email='.$cur_post['poster_id'].'">'.$lang_common['E-mail'].'</a>';
   242 
   245 
   243 			if ($cur_post['url'] != '')
   246 			if ($cur_post['url'] != '')
   244 				$user_contacts[] = '<a href="'.pun_htmlspecialchars($cur_post['url']).'">'.$lang_topic['Website'].'</a>';
   247 				$user_contacts[] = '<a href="'.pun_htmlspecialchars($cur_post['url']).'">'.$lang_topic['Website'].'</a>';
   245 		}
   248 		}
   246 
   249 
   247 		if ($pun_user['g_id'] < PUN_GUEST)
   250 		if ($pun_user['g_id'] >= USER_LEVEL_MEMBER)
   248 		{
   251 		{
   249 			$user_info[] = '<dd>IP: <a href="moderate.php?get_host='.$cur_post['id'].'">'.$cur_post['poster_ip'].'</a>';
   252 			$user_info[] = '<dd>IP: <a href="moderate.php?get_host='.$cur_post['id'].'">'.$cur_post['poster_ip'].'</a>';
   250 
   253 
   251 			if ($cur_post['admin_note'] != '')
   254 			if ($cur_post['admin_note'] != '')
   252 				$user_info[] = '<dd>'.$lang_topic['Note'].': <strong>'.pun_htmlspecialchars($cur_post['admin_note']).'</strong>';
   255 				$user_info[] = '<dd>'.$lang_topic['Note'].': <strong>'.pun_htmlspecialchars($cur_post['admin_note']).'</strong>';
   256 	else
   259 	else
   257 	{
   260 	{
   258 		$username = pun_htmlspecialchars($cur_post['username']);
   261 		$username = pun_htmlspecialchars($cur_post['username']);
   259 		$user_title = get_title($cur_post);
   262 		$user_title = get_title($cur_post);
   260 
   263 
   261 		if ($pun_user['g_id'] < PUN_GUEST)
   264 		if ($pun_user['g_id'] >= USER_LEVEL_MEMBER)
   262 			$user_info[] = '<dd>IP: <a href="moderate.php?get_host='.$cur_post['id'].'">'.$cur_post['poster_ip'].'</a>';
   265 			$user_info[] = '<dd>IP: <a href="moderate.php?get_host='.$cur_post['id'].'">'.$cur_post['poster_ip'].'</a>';
   263 
   266 
   264 		if ($pun_config['o_show_user_info'] == '1' && $cur_post['poster_email'] != '' && !$pun_user['is_guest'])
   267 		if ($pun_config['o_show_user_info'] == '1' && $cur_post['poster_email'] != '' && !$pun_user['is_guest'])
   265 			$user_contacts[] = '<a href="mailto:'.$cur_post['poster_email'].'">'.$lang_common['E-mail'].'</a>';
   268 			$user_contacts[] = '<a href="mailto:'.$cur_post['poster_email'].'">'.$lang_common['E-mail'].'</a>';
   266 	}
   269 	}
   386 
   389 
   387 }
   390 }
   388 
   391 
   389 // Increment "num_views" for topic
   392 // Increment "num_views" for topic
   390 $low_prio = ($db_type == 'mysql') ? 'LOW_PRIORITY ' : '';
   393 $low_prio = ($db_type == 'mysql') ? 'LOW_PRIORITY ' : '';
   391 $db->query('UPDATE '.$low_prio.$db->prefix.'topics SET num_views=num_views+1 WHERE id='.$id) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
   394 $pun_db->query('UPDATE '.$low_prio.$pun_db->prefix.'topics SET num_views=num_views+1 WHERE id='.$id) or error('Unable to update topic', __FILE__, __LINE__, $pun_db->error());
   392 
   395 
   393 $forum_id = $cur_topic['forum_id'];
   396 $forum_id = $cur_topic['forum_id'];
   394 $footer_style = 'viewtopic';
   397 $footer_style = 'viewtopic';
   395 require PUN_ROOT.'footer.php';
   398 require PUN_ROOT.'footer.php';