punbb/post.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 
    36 if ($tid < 1 && $fid < 1 || $tid > 0 && $fid > 0)
    39 if ($tid < 1 && $fid < 1 || $tid > 0 && $fid > 0)
    37 	message($lang_common['Bad request']);
    40 	message($lang_common['Bad request']);
    38 
    41 
    39 // Fetch some info about the topic and/or the forum
    42 // Fetch some info about the topic and/or the forum
    40 if ($tid)
    43 if ($tid)
    41 	$result = $db->query('SELECT f.id, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.subject, t.closed 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='.$tid) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
    44 	$result = $pun_db->query('SELECT f.id, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.subject, t.closed 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='.$tid) or error('Unable to fetch forum info', __FILE__, __LINE__, $pun_db->error());
    42 else
    45 else
    43 	$result = $db->query('SELECT f.id, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, 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='.$fid) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
    46 	$result = $pun_db->query('SELECT f.id, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, 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='.$fid) or error('Unable to fetch forum info', __FILE__, __LINE__, $pun_db->error());
    44 
    47 
    45 if (!$db->num_rows($result))
    48 if (!$pun_db->num_rows($result))
    46 	message($lang_common['Bad request']);
    49 	message($lang_common['Bad request']);
    47 
    50 
    48 $cur_posting = $db->fetch_assoc($result);
    51 $cur_posting = $pun_db->fetch_assoc($result);
    49 
    52 
    50 // Is someone trying to post into a redirect forum?
    53 // Is someone trying to post into a redirect forum?
    51 if ($cur_posting['redirect_url'] != '')
    54 if ($cur_posting['redirect_url'] != '')
    52 	message($lang_common['Bad request']);
    55 	message($lang_common['Bad request']);
    53 
    56 
    87 
    90 
    88 		if ($subject == '')
    91 		if ($subject == '')
    89 			$errors[] = $lang_post['No subject'];
    92 			$errors[] = $lang_post['No subject'];
    90 		else if (pun_strlen($subject) > 70)
    93 		else if (pun_strlen($subject) > 70)
    91 			$errors[] = $lang_post['Too long subject'];
    94 			$errors[] = $lang_post['Too long subject'];
    92 		else if ($pun_config['p_subject_all_caps'] == '0' && strtoupper($subject) == $subject && $pun_user['g_id'] > PUN_MOD)
    95 		else if ($pun_config['p_subject_all_caps'] == '0' && strtoupper($subject) == $subject && $pun_user['g_id'] < PUN_MOD)
    93 			$subject = ucwords(strtolower($subject));
    96 			$subject = ucwords(strtolower($subject));
    94 	}
    97 	}
    95 
    98 
    96 	// If the user is logged in we get the username and e-mail from $pun_user
    99 	// If the user is logged in we get the username and e-mail from $pun_user
    97 	if (!$pun_user['is_guest'])
   100 	if (!$pun_user['is_guest'])
   126 		$temp = censor_words($username);
   129 		$temp = censor_words($username);
   127 		if ($temp != $username)
   130 		if ($temp != $username)
   128 			$errors[] = $lang_register['Username censor'];
   131 			$errors[] = $lang_register['Username censor'];
   129 
   132 
   130 		// Check that the username (or a too similar username) is not already registered
   133 		// Check that the username (or a too similar username) is not already registered
   131 		$result = $db->query('SELECT username FROM '.$db->prefix.'users WHERE (username=\''.$db->escape($username).'\' OR username=\''.$db->escape(preg_replace('/[^\w]/', '', $username)).'\') AND id>1') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
   134 		$result = $pun_db->query('SELECT username FROM '.$pun_db->prefix.'users WHERE (username=\''.$pun_db->escape($username).'\' OR username=\''.$pun_db->escape(preg_replace('/[^\w]/', '', $username)).'\') AND id>1') or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
   132 		if ($db->num_rows($result))
   135 		if ($pun_db->num_rows($result))
   133 		{
   136 		{
   134 			$busy = $db->result($result);
   137 			$busy = $pun_db->result($result);
   135 			$errors[] = $lang_register['Username dupe 1'].' '.pun_htmlspecialchars($busy).'. '.$lang_register['Username dupe 2'];
   138 			$errors[] = $lang_register['Username dupe 1'].' '.pun_htmlspecialchars($busy).'. '.$lang_register['Username dupe 2'];
   136 		}
   139 		}
   137 
   140 
   138 		if ($pun_config['p_force_guest_email'] == '1' || $email != '')
   141 		if ($pun_config['p_force_guest_email'] == '1' || $email != '')
   139 		{
   142 		{
   148 
   151 
   149 	if ($message == '')
   152 	if ($message == '')
   150 		$errors[] = $lang_post['No message'];
   153 		$errors[] = $lang_post['No message'];
   151 	else if (strlen($message) > 65535)
   154 	else if (strlen($message) > 65535)
   152 		$errors[] = $lang_post['Too long message'];
   155 		$errors[] = $lang_post['Too long message'];
   153 	else if ($pun_config['p_message_all_caps'] == '0' && strtoupper($message) == $message && $pun_user['g_id'] > PUN_MOD)
   156 	else if ($pun_config['p_message_all_caps'] == '0' && strtoupper($message) == $message && $pun_user['g_id'] < PUN_MOD)
   154 		$message = ucwords(strtolower($message));
   157 		$message = ucwords(strtolower($message));
   155 
   158 
   156 	// Validate BBCode syntax
   159 	// Validate BBCode syntax
   157 	if ($pun_config['p_message_bbcode'] == '1' && strpos($message, '[') !== false && strpos($message, ']') !== false)
   160 	if ($pun_config['p_message_bbcode'] == '1' && strpos($message, '[') !== false && strpos($message, ']') !== false)
   158 	{
   161 	{
   160 		$message = preparse_bbcode($message, $errors);
   163 		$message = preparse_bbcode($message, $errors);
   161 	}
   164 	}
   162 
   165 
   163 
   166 
   164 	require PUN_ROOT.'include/search_idx.php';
   167 	require PUN_ROOT.'include/search_idx.php';
       
   168   global $db, $session, $paths, $template, $plugins; // Common objects
   165 
   169 
   166 	$hide_smilies = isset($_POST['hide_smilies']) ? 1 : 0;
   170 	$hide_smilies = isset($_POST['hide_smilies']) ? 1 : 0;
   167 	$subscribe = isset($_POST['subscribe']) ? 1 : 0;
   171 	$subscribe = isset($_POST['subscribe']) ? 1 : 0;
   168 
   172 
   169 	$now = time();
   173 	$now = time();
   172 	if (empty($errors) && !isset($_POST['preview']))
   176 	if (empty($errors) && !isset($_POST['preview']))
   173 	{
   177 	{
   174 		// If it's a reply
   178 		// If it's a reply
   175 		if ($tid)
   179 		if ($tid)
   176 		{
   180 		{
   177 			if (!$pun_user['is_guest'])
   181 			if ($session->user_logged_in)
   178 			{
   182 			{
   179 				// Insert the new post
   183 				// Insert the new post
   180 				$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', '.$pun_user['id'].', \''.get_remote_address().'\', \''.$db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
   184 				$pun_db->query('INSERT INTO '.$pun_db->prefix.'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\''.$pun_db->escape($username).'\', '.$pun_user['id'].', \''.get_remote_address().'\', \''.$pun_db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$tid.')') or error('Unable to create post', __FILE__, __LINE__, $pun_db->error());
   181 				$new_pid = $db->insert_id();
   185 				$new_pid = $pun_db->insert_id();
   182 
   186       
   183 				// To subscribe or not to subscribe, that ...
   187 				// To subscribe or not to subscribe, that ...
   184 				if ($pun_config['o_subscriptions'] == '1' && $subscribe)
   188 				if ($pun_config['o_subscriptions'] == '1' && $subscribe)
   185 				{
   189 				{
   186 					$result = $db->query('SELECT 1 FROM '.$db->prefix.'subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$tid) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
   190 					$result = $pun_db->query('SELECT 1 FROM '.$pun_db->prefix.'subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$tid) or error('Unable to fetch subscription info', __FILE__, __LINE__, $pun_db->error());
   187 					if (!$db->num_rows($result))
   191 					if (!$pun_db->num_rows($result))
   188 						$db->query('INSERT INTO '.$db->prefix.'subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$tid.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());
   192 						$pun_db->query('INSERT INTO '.$pun_db->prefix.'subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$tid.')') or error('Unable to add subscription', __FILE__, __LINE__, $pun_db->error());
   189 				}
   193 				}
   190 			}
   194 			}
   191 			else
   195 			else
   192 			{
   196 			{
   193 				// It's a guest. Insert the new post
   197 				// It's a guest. Insert the new post
   194 				$email_sql = ($pun_config['p_force_guest_email'] == '1' || $email != '') ? '\''.$email.'\'' : 'NULL';
   198 				$email_sql = ($pun_config['p_force_guest_email'] == '1' || $email != '') ? '\''.$email.'\'' : 'NULL';
   195 				$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_ip, poster_email, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', \''.get_remote_address().'\', '.$email_sql.', \''.$db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
   199 				$pun_db->query('INSERT INTO '.$pun_db->prefix.'posts (poster, poster_ip, poster_email, message, hide_smilies, posted, topic_id) VALUES(\''.$pun_db->escape($username).'\', \''.get_remote_address().'\', '.$email_sql.', \''.$pun_db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$tid.')') or error('Unable to create post', __FILE__, __LINE__, $pun_db->error());
   196 				$new_pid = $db->insert_id();
   200 				$new_pid = $pun_db->insert_id();
   197 			}
   201 			}
   198 
   202       
   199 			// Count number of replies in the topic
   203 			// Count number of replies in the topic
   200 			$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'posts WHERE topic_id='.$tid) or error('Unable to fetch post count for topic', __FILE__, __LINE__, $db->error());
   204 			$result = $pun_db->query('SELECT COUNT(id) FROM '.$pun_db->prefix.'posts WHERE topic_id='.$tid) or error('Unable to fetch post count for topic', __FILE__, __LINE__, $pun_db->error());
   201 			$num_replies = $db->result($result, 0) - 1;
   205 			$num_replies = $pun_db->result($result, 0) - 1;
   202 
   206       
   203 			// Update topic
   207 			// Update topic
   204 			$db->query('UPDATE '.$db->prefix.'topics SET num_replies='.$num_replies.', last_post='.$now.', last_post_id='.$new_pid.', last_poster=\''.$db->escape($username).'\' WHERE id='.$tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
   208 			$pun_db->query('UPDATE '.$pun_db->prefix.'topics SET num_replies='.$num_replies.', last_post='.$now.', last_post_id='.$new_pid.', last_poster=\''.$pun_db->escape($username).'\' WHERE id='.$tid) or error('Unable to update topic', __FILE__, __LINE__, $pun_db->error());
   205 
   209       
   206 			update_search_index('post', $new_pid, $message);
   210 			update_search_index('post', $new_pid, $message);
   207 
   211       
   208 			update_forum($cur_posting['id']);
   212 			update_forum($cur_posting['id']);
   209 
   213       
   210 			// Should we send out notifications?
   214 			// Should we send out notifications?
   211 			if ($pun_config['o_subscriptions'] == '1')
   215 			if ($pun_config['o_subscriptions'] == '1')
   212 			{
   216 			{
   213 				// Get the post time for the previous post in this topic
   217 				// Get the post time for the previous post in this topic
   214 				$result = $db->query('SELECT posted FROM '.$db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id DESC LIMIT 1, 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
   218 				$result = $pun_db->query('SELECT posted FROM '.$pun_db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id DESC LIMIT 1, 1') or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
   215 				$previous_post_time = $db->result($result);
   219 				$previous_post_time = $pun_db->result($result);
   216 
   220 
   217 				// Get any subscribed users that should be notified (banned users are excluded)
   221 				// Get any subscribed users that should be notified (banned users are NOT excluded in Enano)
   218 				$result = $db->query('SELECT u.id, u.email, u.notify_with_post, u.language FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'subscriptions AS s ON u.id=s.user_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id='.$cur_posting['id'].' AND fp.group_id=u.group_id) LEFT JOIN '.$db->prefix.'online AS o ON u.id=o.user_id LEFT JOIN '.$db->prefix.'bans AS b ON u.username=b.username WHERE b.username IS NULL AND COALESCE(o.logged, u.last_visit)>'.$previous_post_time.' AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.topic_id='.$tid.' AND u.id!='.intval($pun_user['id'])) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
   222 				$result = $pun_db->query('SELECT u.id, eu.email, u.notify_with_post, u.language FROM '.$pun_db->prefix.'users AS u LEFT JOIN '.table_prefix.'users AS eu ON eu.user_id=u.id INNER JOIN '.$pun_db->prefix.'subscriptions AS s ON u.id=s.user_id LEFT JOIN '.$pun_db->prefix.'forum_perms AS fp ON (fp.forum_id='.$cur_posting['id'].' AND fp.group_id=u.group_id) LEFT JOIN '.$pun_db->prefix.'online AS o ON u.id=o.user_id WHERE COALESCE(o.logged, u.last_visit)>'.$previous_post_time.' AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.topic_id='.$tid.' AND u.id!='.intval($pun_user['id'])) or error('Unable to fetch subscription info', __FILE__, __LINE__, $pun_db->error());
   219 				if ($db->num_rows($result))
   223 				if ($pun_db->num_rows($result))
   220 				{
   224 				{
   221 					require_once PUN_ROOT.'include/email.php';
   225 					require_once PUN_ROOT.'include/email.php';
   222 
   226 
   223 					$notification_emails = array();
   227 					$notification_emails = array();
   224 
   228 
   225 					// Loop through subscribed users and send e-mails
   229 					// Loop through subscribed users and send e-mails
   226 					while ($cur_subscriber = $db->fetch_assoc($result))
   230 					while ($cur_subscriber = $pun_db->fetch_assoc($result))
   227 					{
   231 					{
   228 						// Is the subscription e-mail for $cur_subscriber['language'] cached or not?
   232 						// Is the subscription e-mail for $cur_subscriber['language'] cached or not?
   229 						if (!isset($notification_emails[$cur_subscriber['language']]))
   233 						if (!isset($notification_emails[$cur_subscriber['language']]))
   230 						{
   234 						{
   231 							if (file_exists(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl'))
   235 							if (file_exists(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl'))
   283 		}
   287 		}
   284 		// If it's a new topic
   288 		// If it's a new topic
   285 		else if ($fid)
   289 		else if ($fid)
   286 		{
   290 		{
   287 			// Create the topic
   291 			// Create the topic
   288 			$db->query('INSERT INTO '.$db->prefix.'topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(\''.$db->escape($username).'\', \''.$db->escape($subject).'\', '.$now.', '.$now.', \''.$db->escape($username).'\', '.$fid.')') or error('Unable to create topic', __FILE__, __LINE__, $db->error());
   292 			$pun_db->query('INSERT INTO '.$pun_db->prefix.'topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(\''.$pun_db->escape($username).'\', \''.$pun_db->escape($subject).'\', '.$now.', '.$now.', \''.$pun_db->escape($username).'\', '.$fid.')') or error('Unable to create topic', __FILE__, __LINE__, $pun_db->error());
   289 			$new_tid = $db->insert_id();
   293 			$new_tid = $pun_db->insert_id();
   290 
   294 
   291 			if (!$pun_user['is_guest'])
   295 			if (!$pun_user['is_guest'])
   292 			{
   296 			{
   293 				// To subscribe or not to subscribe, that ...
   297 				// To subscribe or not to subscribe, that ...
   294 				if ($pun_config['o_subscriptions'] == '1' && (isset($_POST['subscribe']) && $_POST['subscribe'] == '1'))
   298 				if ($pun_config['o_subscriptions'] == '1' && (isset($_POST['subscribe']) && $_POST['subscribe'] == '1'))
   295 					$db->query('INSERT INTO '.$db->prefix.'subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$new_tid.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());
   299 					$pun_db->query('INSERT INTO '.$pun_db->prefix.'subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$new_tid.')') or error('Unable to add subscription', __FILE__, __LINE__, $pun_db->error());
   296 
   300 
   297 				// Create the post ("topic post")
   301 				// Create the post ("topic post")
   298 				$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', '.$pun_user['id'].', \''.get_remote_address().'\', \''.$db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
   302 				$pun_db->query('INSERT INTO '.$pun_db->prefix.'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\''.$pun_db->escape($username).'\', '.$pun_user['id'].', \''.get_remote_address().'\', \''.$pun_db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $pun_db->error());
   299 			}
   303 			}
   300 			else
   304 			else
   301 			{
   305 			{
   302 				// Create the post ("topic post")
   306 				// Create the post ("topic post")
   303 				$email_sql = ($pun_config['p_force_guest_email'] == '1' || $email != '') ? '\''.$email.'\'' : 'NULL';
   307 				$email_sql = ($pun_config['p_force_guest_email'] == '1' || $email != '') ? '\''.$email.'\'' : 'NULL';
   304 				$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_ip, poster_email, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', \''.get_remote_address().'\', '.$email_sql.', \''.$db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
   308 				$pun_db->query('INSERT INTO '.$pun_db->prefix.'posts (poster, poster_ip, poster_email, message, hide_smilies, posted, topic_id) VALUES(\''.$pun_db->escape($username).'\', \''.get_remote_address().'\', '.$email_sql.', \''.$pun_db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $pun_db->error());
   305 			}
   309 			}
   306 			$new_pid = $db->insert_id();
   310 			$new_pid = $pun_db->insert_id();
   307 
   311 
   308 			// Update the topic with last_post_id
   312 			// Update the topic with last_post_id
   309 			$db->query('UPDATE '.$db->prefix.'topics SET last_post_id='.$new_pid.' WHERE id='.$new_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
   313 			$pun_db->query('UPDATE '.$pun_db->prefix.'topics SET last_post_id='.$new_pid.' WHERE id='.$new_tid) or error('Unable to update topic', __FILE__, __LINE__, $pun_db->error());
   310 
   314 
   311 			update_search_index('post', $new_pid, $message, $subject);
   315 			update_search_index('post', $new_pid, $message, $subject);
   312 
   316 
   313 			update_forum($fid);
   317 			update_forum($fid);
   314 		}
   318 		}
   315 
   319 
   316 		// If the posting user is logged in, increment his/her post count
   320 		// If the posting user is logged in, increment his/her post count
   317 		if (!$pun_user['is_guest'])
   321 		if (!$pun_user['is_guest'])
   318 		{
   322 		{
   319 			$low_prio = ($db_type == 'mysql') ? 'LOW_PRIORITY ' : '';
   323 			$low_prio = ($db_type == 'mysql') ? 'LOW_PRIORITY ' : '';
   320 			$db->query('UPDATE '.$low_prio.$db->prefix.'users SET num_posts=num_posts+1, last_post='.$now.' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
   324 			$pun_db->query('UPDATE '.$low_prio.$pun_db->prefix.'users SET num_posts=num_posts+1, last_post='.$now.' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $pun_db->error());
   321 		}
   325 		}
   322 
   326 
   323 		redirect('viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $lang_post['Post redirect']);
   327 		pun_redirect('viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $lang_post['Post redirect']);
   324 	}
   328 	}
   325 }
   329 }
   326 
   330 
   327 
   331 
   328 // If a topic id was specified in the url (it's a reply).
   332 // If a topic id was specified in the url (it's a reply).
   336 	{
   340 	{
   337 		$qid = intval($_GET['qid']);
   341 		$qid = intval($_GET['qid']);
   338 		if ($qid < 1)
   342 		if ($qid < 1)
   339 			message($lang_common['Bad request']);
   343 			message($lang_common['Bad request']);
   340 
   344 
   341 		$result = $db->query('SELECT poster, message FROM '.$db->prefix.'posts WHERE id='.$qid.' AND topic_id='.$tid) or error('Unable to fetch quote info', __FILE__, __LINE__, $db->error());
   345 		$result = $pun_db->query('SELECT poster, message FROM '.$pun_db->prefix.'posts WHERE id='.$qid.' AND topic_id='.$tid) or error('Unable to fetch quote info', __FILE__, __LINE__, $pun_db->error());
   342 		if (!$db->num_rows($result))
   346 		if (!$pun_db->num_rows($result))
   343 			message($lang_common['Bad request']);
   347 			message($lang_common['Bad request']);
   344 
   348 
   345 		list($q_poster, $q_message) = $db->fetch_row($result);
   349 		list($q_poster, $q_message) = $pun_db->fetch_row($result);
   346 
   350 
   347 		$q_message = str_replace('[img]', '[url]', $q_message);
   351 		$q_message = str_replace('[img]', '[url]', $q_message);
   348 		$q_message = str_replace('[/img]', '[/url]', $q_message);
   352 		$q_message = str_replace('[/img]', '[/url]', $q_message);
   349 		$q_message = pun_htmlspecialchars($q_message);
   353 		$q_message = pun_htmlspecialchars($q_message);
   350 
   354 
   543 // Check to see if the topic review is to be displayed.
   547 // Check to see if the topic review is to be displayed.
   544 if ($tid && $pun_config['o_topic_review'] != '0')
   548 if ($tid && $pun_config['o_topic_review'] != '0')
   545 {
   549 {
   546 	require_once PUN_ROOT.'include/parser.php';
   550 	require_once PUN_ROOT.'include/parser.php';
   547 
   551 
   548 	$result = $db->query('SELECT poster, message, hide_smilies, posted FROM '.$db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id DESC LIMIT '.$pun_config['o_topic_review']) or error('Unable to fetch topic review', __FILE__, __LINE__, $db->error());
   552 	$result = $pun_db->query('SELECT poster, message, hide_smilies, posted FROM '.$pun_db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id DESC LIMIT '.$pun_config['o_topic_review']) or error('Unable to fetch topic review', __FILE__, __LINE__, $pun_db->error());
   549 
   553 
   550 ?>
   554 ?>
   551 
   555 
   552 <div id="postreview" class="blockpost">
   556 <div id="postreview" class="blockpost">
   553 	<h2><span><?php echo $lang_post['Topic review'] ?></span></h2>
   557 	<h2><span><?php echo $lang_post['Topic review'] ?></span></h2>
   555 
   559 
   556 	//Set background switching on
   560 	//Set background switching on
   557 	$bg_switch = true;
   561 	$bg_switch = true;
   558 	$post_count = 0;
   562 	$post_count = 0;
   559 
   563 
   560 	while ($cur_post = $db->fetch_assoc($result))
   564 	while ($cur_post = $pun_db->fetch_assoc($result))
   561 	{
   565 	{
   562 		// Switch the background color for every message.
   566 		// Switch the background color for every message.
   563 		$bg_switch = ($bg_switch) ? $bg_switch = false : $bg_switch = true;
   567 		$bg_switch = ($bg_switch) ? $bg_switch = false : $bg_switch = true;
   564 		$vtbg = ($bg_switch) ? ' roweven' : ' rowodd';
   568 		$vtbg = ($bg_switch) ? ' roweven' : ' rowodd';
   565 		$post_count++;
   569 		$post_count++;