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 |
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). |