1 | <?php |
---|
2 | /*********************************************************************** |
---|
3 | |
---|
4 | Copyright (C) 2002-2005 Rickard Andersson (rickard@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 | define('PUN_ROOT', './'); |
---|
27 | require PUN_ROOT.'include/common.php'; |
---|
28 | |
---|
29 | |
---|
30 | if ($pun_user['g_read_board'] == '0') |
---|
31 | message($lang_common['No view']); |
---|
32 | |
---|
33 | |
---|
34 | $tid = isset($_GET['tid']) ? intval($_GET['tid']) : 0; |
---|
35 | $fid = isset($_GET['fid']) ? intval($_GET['fid']) : 0; |
---|
36 | if ($tid < 1 && $fid < 1 || $tid > 0 && $fid > 0) |
---|
37 | message($lang_common['Bad request']); |
---|
38 | |
---|
39 | // Fetch some info about the topic and/or the forum |
---|
40 | 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('Impossible de retrouver les informations forum', __FILE__, __LINE__, $db->error()); |
---|
42 | 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('Impossible de retrouver les informations forum', __FILE__, __LINE__, $db->error()); |
---|
44 | |
---|
45 | if (!$db->num_rows($result)) |
---|
46 | message($lang_common['Bad request']); |
---|
47 | |
---|
48 | $cur_posting = $db->fetch_assoc($result); |
---|
49 | |
---|
50 | // Is someone trying to post into a redirect forum? |
---|
51 | if ($cur_posting['redirect_url'] != '') |
---|
52 | message($lang_common['Bad request']); |
---|
53 | |
---|
54 | // Sort out who the moderators are and if we are currently a moderator (or an admin) |
---|
55 | $mods_array = ($cur_posting['moderators'] != '') ? unserialize($cur_posting['moderators']) : array(); |
---|
56 | $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && array_key_exists($pun_user['username'], $mods_array))) ? true : false; |
---|
57 | |
---|
58 | // Do we have permission to post? |
---|
59 | if ((($tid && (($cur_posting['post_replies'] == '' && $pun_user['g_post_replies'] == '0') || $cur_posting['post_replies'] == '0')) || |
---|
60 | ($fid && (($cur_posting['post_topics'] == '' && $pun_user['g_post_topics'] == '0') || $cur_posting['post_topics'] == '0')) || |
---|
61 | (isset($cur_posting['closed']) && $cur_posting['closed'] == '1')) && |
---|
62 | !$is_admmod) |
---|
63 | message($lang_common['No permission']); |
---|
64 | |
---|
65 | // Load the post.php language file |
---|
66 | require PUN_ROOT.'lang/'.$pun_user['language'].'/post.php'; |
---|
67 | |
---|
68 | // Start with a clean slate |
---|
69 | $errors = array(); |
---|
70 | |
---|
71 | |
---|
72 | // Did someone just hit "Submit" or "Preview"? |
---|
73 | if (isset($_POST['form_sent'])) |
---|
74 | { |
---|
75 | // Make sure form_user is correct |
---|
76 | if (($pun_user['is_guest'] && $_POST['form_user'] != 'Invité') || (!$pun_user['is_guest'] && $_POST['form_user'] != $pun_user['username'])) |
---|
77 | message($lang_common['Bad request']); |
---|
78 | |
---|
79 | // Flood protection |
---|
80 | if (!$pun_user['is_guest'] && !isset($_POST['preview']) && $pun_user['last_post'] != '' && (time() - $pun_user['last_post']) < $pun_user['g_post_flood']) |
---|
81 | $errors[] = $lang_post['Flood start'].' '.$pun_user['g_post_flood'].' '.$lang_post['flood end']; |
---|
82 | |
---|
83 | // If it's a new topic |
---|
84 | if ($fid) |
---|
85 | { |
---|
86 | $subject = pun_trim($_POST['req_subject']); |
---|
87 | |
---|
88 | if ($subject == '') |
---|
89 | $errors[] = $lang_post['No subject']; |
---|
90 | else if (pun_strlen($subject) > 70) |
---|
91 | $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) |
---|
93 | $subject = ucwords(strtolower($subject)); |
---|
94 | } |
---|
95 | |
---|
96 | // If the user is logged in we get the username and e-mail from $pun_user |
---|
97 | if (!$pun_user['is_guest']) |
---|
98 | { |
---|
99 | $username = $pun_user['username']; |
---|
100 | $email = $pun_user['email']; |
---|
101 | } |
---|
102 | // Otherwise it should be in $_POST |
---|
103 | else |
---|
104 | { |
---|
105 | $username = trim($_POST['req_username']); |
---|
106 | $email = strtolower(trim(($pun_config['p_force_guest_email'] == '1') ? $_POST['req_email'] : $_POST['email'])); |
---|
107 | |
---|
108 | // Load the register.php/profile.php language files |
---|
109 | require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php'; |
---|
110 | require PUN_ROOT.'lang/'.$pun_user['language'].'/register.php'; |
---|
111 | |
---|
112 | // It's a guest, so we have to validate the username |
---|
113 | if (strlen($username) < 2) |
---|
114 | $errors[] = $lang_prof_reg['Username too short']; |
---|
115 | else if (!strcasecmp($username, 'invité') || !strcasecmp($username, $lang_common['Guest'])) |
---|
116 | $errors[] = $lang_prof_reg['Username guest']; |
---|
117 | else if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $username)) |
---|
118 | $errors[] = $lang_prof_reg['Username IP']; |
---|
119 | |
---|
120 | if ((strpos($username, '[') !== false || strpos($username, ']') !== false) && strpos($username, '\'') !== false && strpos($username, '"') !== false) |
---|
121 | $errors[] = $lang_prof_reg['Username reserved chars']; |
---|
122 | if (preg_match('#\[b\]|\[/b\]|\[u\]|\[/u\]|\[i\]|\[/i\]|\[color|\[/color\]|\[quote\]|\[quote=|\[/quote\]|\[code\]|\[/code\]|\[img\]|\[/img\]|\[url|\[/url\]|\[email|\[/email\]#i', $username)) |
---|
123 | $errors[] = $lang_prof_reg['Username BBCode']; |
---|
124 | |
---|
125 | // Check username for any censored words |
---|
126 | $temp = censor_words($username); |
---|
127 | if ($temp != $username) |
---|
128 | $errors[] = $lang_register['Username censor']; |
---|
129 | |
---|
130 | // 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)).'\'') or error('Impossible de retrouver les informations utilisateur', __FILE__, __LINE__, $db->error()); |
---|
132 | if ($db->num_rows($result)) |
---|
133 | { |
---|
134 | $busy = $db->result($result); |
---|
135 | $errors[] = $lang_register['Username dupe 1'].' '.pun_htmlspecialchars($busy).'. '.$lang_register['Username dupe 2']; |
---|
136 | } |
---|
137 | |
---|
138 | if ($pun_config['p_force_guest_email'] == '1' || $email != '') |
---|
139 | { |
---|
140 | require PUN_ROOT.'include/email.php'; |
---|
141 | if (!is_valid_email($email)) |
---|
142 | $errors[] = $lang_common['Invalid e-mail']; |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | // Clean up message from POST |
---|
147 | $message = pun_linebreaks(pun_trim($_POST['req_message'])); |
---|
148 | |
---|
149 | if ($message == '') |
---|
150 | $errors[] = $lang_post['No message']; |
---|
151 | else if (strlen($message) > 65535) |
---|
152 | $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) |
---|
154 | $message = ucwords(strtolower($message)); |
---|
155 | |
---|
156 | // Validate BBCode syntax |
---|
157 | if ($pun_config['p_message_bbcode'] == '1' && strpos($message, '[') !== false && strpos($message, ']') !== false) |
---|
158 | { |
---|
159 | require PUN_ROOT.'include/parser.php'; |
---|
160 | $message = preparse_bbcode($message, $errors); |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | require PUN_ROOT.'include/search_idx.php'; |
---|
165 | |
---|
166 | $hide_smilies = isset($_POST['hide_smilies']) ? 1 : 0; |
---|
167 | $subscribe = isset($_POST['subscribe']) ? 1 : 0; |
---|
168 | |
---|
169 | $now = time(); |
---|
170 | |
---|
171 | // Did everything go according to plan? |
---|
172 | if (empty($errors) && !isset($_POST['preview'])) |
---|
173 | { |
---|
174 | // If it's a reply |
---|
175 | if ($tid) |
---|
176 | { |
---|
177 | if (!$pun_user['is_guest']) |
---|
178 | { |
---|
179 | // 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('Impossible de créer le message', __FILE__, __LINE__, $db->error()); |
---|
181 | $new_pid = $db->insert_id(); |
---|
182 | |
---|
183 | // To subscribe or not to subscribe, that ... |
---|
184 | if ($pun_config['o_subscriptions'] == '1' && $subscribe) |
---|
185 | { |
---|
186 | $result = $db->query('SELECT 1 FROM '.$db->prefix.'subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$tid) or error('Impossible de retrouver les informations d\'abonnement', __FILE__, __LINE__, $db->error()); |
---|
187 | if (!$db->num_rows($result)) |
---|
188 | $db->query('INSERT INTO '.$db->prefix.'subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$tid.')') or error('Impossible d\'ajouter l\'abonnement', __FILE__, __LINE__, $db->error()); |
---|
189 | } |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | // It's a guest. Insert the new post |
---|
194 | $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('Impossible de créer le message', __FILE__, __LINE__, $db->error()); |
---|
196 | $new_pid = $db->insert_id(); |
---|
197 | } |
---|
198 | |
---|
199 | // Count number of replies in the topic |
---|
200 | $result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'posts WHERE topic_id='.$tid) or error('Impossible de retrouver le total de messages de la discussion', __FILE__, __LINE__, $db->error()); |
---|
201 | $num_replies = $db->result($result, 0) - 1; |
---|
202 | |
---|
203 | // 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('Impossible de modifier la discussion', __FILE__, __LINE__, $db->error()); |
---|
205 | |
---|
206 | update_search_index('post', $new_pid, $message); |
---|
207 | |
---|
208 | update_forum($cur_posting['id']); |
---|
209 | |
---|
210 | // Should we send out notifications? |
---|
211 | if ($pun_config['o_subscriptions'] == '1') |
---|
212 | { |
---|
213 | // 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('Impossible de retrouver les information de message', __FILE__, __LINE__, $db->error()); |
---|
215 | $previous_post_time = $db->result($result); |
---|
216 | |
---|
217 | // Get any subscribed users that should be notified (banned users are excluded) |
---|
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('Impossible de retrouver les informations d\'abonnement', __FILE__, __LINE__, $db->error()); |
---|
219 | if ($db->num_rows($result)) |
---|
220 | { |
---|
221 | require_once PUN_ROOT.'include/email.php'; |
---|
222 | |
---|
223 | $notification_emails = array(); |
---|
224 | |
---|
225 | // Loop through subscribed users and send e-mails |
---|
226 | while ($cur_subscriber = $db->fetch_assoc($result)) |
---|
227 | { |
---|
228 | // Is the subscription e-mail for $cur_subscriber['language'] cached or not? |
---|
229 | if (!isset($notification_emails[$cur_subscriber['language']])) |
---|
230 | { |
---|
231 | if (file_exists(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl')) |
---|
232 | { |
---|
233 | // Load the "new reply" template |
---|
234 | $mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl')); |
---|
235 | |
---|
236 | // Load the "new reply full" template (with post included) |
---|
237 | $mail_tpl_full = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply_full.tpl')); |
---|
238 | |
---|
239 | // The first row contains the subject (it also starts with "Subject:") |
---|
240 | $first_crlf = strpos($mail_tpl, "\n"); |
---|
241 | $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8)); |
---|
242 | $mail_message = trim(substr($mail_tpl, $first_crlf)); |
---|
243 | |
---|
244 | $first_crlf = strpos($mail_tpl_full, "\n"); |
---|
245 | $mail_subject_full = trim(substr($mail_tpl_full, 8, $first_crlf-8)); |
---|
246 | $mail_message_full = trim(substr($mail_tpl_full, $first_crlf)); |
---|
247 | |
---|
248 | $mail_subject = str_replace('<topic_subject>', '\''.$cur_posting['subject'].'\'', $mail_subject); |
---|
249 | $mail_message = str_replace('<topic_subject>', '\''.$cur_posting['subject'].'\'', $mail_message); |
---|
250 | $mail_message = str_replace('<replier>', $username, $mail_message); |
---|
251 | $mail_message = str_replace('<post_url>', $pun_config['o_base_url'].'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $mail_message); |
---|
252 | $mail_message = str_replace('<unsubscribe_url>', $pun_config['o_base_url'].'/misc.php?unsubscribe='.$tid, $mail_message); |
---|
253 | $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message); |
---|
254 | |
---|
255 | $mail_subject_full = str_replace('<topic_subject>', '\''.$cur_posting['subject'].'\'', $mail_subject_full); |
---|
256 | $mail_message_full = str_replace('<topic_subject>', '\''.$cur_posting['subject'].'\'', $mail_message_full); |
---|
257 | $mail_message_full = str_replace('<replier>', $username, $mail_message_full); |
---|
258 | $mail_message_full = str_replace('<message>', $message, $mail_message_full); |
---|
259 | $mail_message_full = str_replace('<post_url>', $pun_config['o_base_url'].'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $mail_message_full); |
---|
260 | $mail_message_full = str_replace('<unsubscribe_url>', $pun_config['o_base_url'].'/misc.php?unsubscribe='.$tid, $mail_message_full); |
---|
261 | $mail_message_full = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message_full); |
---|
262 | |
---|
263 | $notification_emails[$cur_subscriber['language']][0] = $mail_subject; |
---|
264 | $notification_emails[$cur_subscriber['language']][1] = $mail_message; |
---|
265 | $notification_emails[$cur_subscriber['language']][2] = $mail_subject_full; |
---|
266 | $notification_emails[$cur_subscriber['language']][3] = $mail_message_full; |
---|
267 | |
---|
268 | $mail_subject = $mail_message = $mail_subject_full = $mail_message_full = null; |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | // We have to double check here because the templates could be missing |
---|
273 | if (isset($notification_emails[$cur_subscriber['language']])) |
---|
274 | { |
---|
275 | if ($cur_subscriber['notify_with_post'] == '0') |
---|
276 | pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][0], $notification_emails[$cur_subscriber['language']][1]); |
---|
277 | else |
---|
278 | pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][2], $notification_emails[$cur_subscriber['language']][3]); |
---|
279 | } |
---|
280 | } |
---|
281 | } |
---|
282 | } |
---|
283 | } |
---|
284 | // If it's a new topic |
---|
285 | else if ($fid) |
---|
286 | { |
---|
287 | // 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('Impossible de créer la discussion', __FILE__, __LINE__, $db->error()); |
---|
289 | $new_tid = $db->insert_id(); |
---|
290 | |
---|
291 | if (!$pun_user['is_guest']) |
---|
292 | { |
---|
293 | // To subscribe or not to subscribe, that ... |
---|
294 | 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('Impossible d\'ajouter l\'abonnement', __FILE__, __LINE__, $db->error()); |
---|
296 | |
---|
297 | // 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('Impossible de créer le message', __FILE__, __LINE__, $db->error()); |
---|
299 | } |
---|
300 | else |
---|
301 | { |
---|
302 | // Create the post ("topic post") |
---|
303 | $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('Impossible de créer le message', __FILE__, __LINE__, $db->error()); |
---|
305 | } |
---|
306 | $new_pid = $db->insert_id(); |
---|
307 | |
---|
308 | // 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('Impossible de modifier la discussion', __FILE__, __LINE__, $db->error()); |
---|
310 | |
---|
311 | update_search_index('post', $new_pid, $message, $subject); |
---|
312 | |
---|
313 | update_forum($fid); |
---|
314 | } |
---|
315 | |
---|
316 | // If the posting user is logged in, increment his/her post count |
---|
317 | if (!$pun_user['is_guest']) |
---|
318 | { |
---|
319 | $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('Impossible de modifier l\'utilisateur', __FILE__, __LINE__, $db->error()); |
---|
321 | } |
---|
322 | |
---|
323 | redirect('viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $lang_post['Post redirect']); |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | |
---|
328 | // If a topic id was specified in the url (it's a reply). |
---|
329 | if ($tid) |
---|
330 | { |
---|
331 | $action = $lang_post['Post a reply']; |
---|
332 | $form = '<form id="post" method="post" action="post.php?action=post&tid='.$tid.'" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">'; |
---|
333 | |
---|
334 | // If a quote-id was specified in the url. |
---|
335 | if (isset($_GET['qid'])) |
---|
336 | { |
---|
337 | $qid = intval($_GET['qid']); |
---|
338 | if ($qid < 1) |
---|
339 | message($lang_common['Bad request']); |
---|
340 | |
---|
341 | $result = $db->query('SELECT poster, message FROM '.$db->prefix.'posts WHERE id='.$qid.' AND topic_id='.$tid) or error('Impossible de retrouver les informations de citation', __FILE__, __LINE__, $db->error()); |
---|
342 | if (!$db->num_rows($result)) |
---|
343 | message($lang_common['Bad request']); |
---|
344 | |
---|
345 | list($q_poster, $q_message) = $db->fetch_row($result); |
---|
346 | |
---|
347 | // Mod: Flash MP3 Player (1 nouvelle ligne suit) |
---|
348 | $q_message = preg_replace("/\[mp3 url=([^ ]+)\]/", "[url]$1[/url]", $q_message); |
---|
349 | |
---|
350 | $q_message = str_replace('[img]', '[url]', $q_message); |
---|
351 | $q_message = str_replace('[/img]', '[/url]', $q_message); |
---|
352 | $q_message = pun_htmlspecialchars($q_message); |
---|
353 | |
---|
354 | if ($pun_config['p_message_bbcode'] == '1') |
---|
355 | { |
---|
356 | // If username contains a square bracket, we add "" or '' around it (so we know when it starts and ends) |
---|
357 | if (strpos($q_poster, '[') !== false || strpos($q_poster, ']') !== false) |
---|
358 | { |
---|
359 | if (strpos($q_poster, '\'') !== false) |
---|
360 | $q_poster = '"'.$q_poster.'"'; |
---|
361 | else |
---|
362 | $q_poster = '\''.$q_poster.'\''; |
---|
363 | } |
---|
364 | else |
---|
365 | { |
---|
366 | // Get the characters at the start and end of $q_poster |
---|
367 | $ends = substr($q_poster, 0, 1).substr($q_poster, -1, 1); |
---|
368 | |
---|
369 | // Deal with quoting "Username" or 'Username' (becomes '"Username"' or "'Username'") |
---|
370 | if ($ends == '\'\'') |
---|
371 | $q_poster = '"'.$q_poster.'"'; |
---|
372 | else if ($ends == '""') |
---|
373 | $q_poster = '\''.$q_poster.'\''; |
---|
374 | } |
---|
375 | |
---|
376 | $quote = '[quote='.$q_poster.']'.$q_message.'[/quote]'."\n"; |
---|
377 | } |
---|
378 | else |
---|
379 | $quote = '> '.$q_poster.' '.$lang_common['wrote'].':'."\n\n".'> '.$q_message."\n"; |
---|
380 | } |
---|
381 | |
---|
382 | $forum_name = '<a href="viewforum.php?id='.$cur_posting['id'].'">'.pun_htmlspecialchars($cur_posting['forum_name']).'</a>'; |
---|
383 | } |
---|
384 | // If a forum_id was specified in the url (new topic). |
---|
385 | else if ($fid) |
---|
386 | { |
---|
387 | $action = $lang_post['Post new topic']; |
---|
388 | $form = '<form id="post" method="post" action="post.php?action=post&fid='.$fid.'" onsubmit="return process_form(this)">'; |
---|
389 | |
---|
390 | $forum_name = pun_htmlspecialchars($cur_posting['forum_name']); |
---|
391 | } |
---|
392 | else |
---|
393 | message($lang_common['Bad request']); |
---|
394 | |
---|
395 | |
---|
396 | $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$action; |
---|
397 | $required_fields = array('req_email' => $lang_common['E-mail'], 'req_subject' => $lang_common['Subject'], 'req_message' => $lang_common['Message']); |
---|
398 | $focus_element = array('post'); |
---|
399 | |
---|
400 | if (!$pun_user['is_guest']) |
---|
401 | $focus_element[] = ($fid) ? 'req_subject' : 'req_message'; |
---|
402 | else |
---|
403 | { |
---|
404 | $required_fields['req_username'] = $lang_post['Guest name']; |
---|
405 | $focus_element[] = 'req_username'; |
---|
406 | } |
---|
407 | |
---|
408 | require PUN_ROOT.'header.php'; |
---|
409 | |
---|
410 | ?> |
---|
411 | <div class="linkst"> |
---|
412 | <div class="inbox"> |
---|
413 | <ul><li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li><li> » <?php echo $forum_name ?><?php if (isset($cur_posting['subject'])) echo '</li><li> » '.pun_htmlspecialchars($cur_posting['subject']) ?></li></ul> |
---|
414 | </div> |
---|
415 | </div> |
---|
416 | |
---|
417 | <?php |
---|
418 | |
---|
419 | // If there are errors, we display them |
---|
420 | if (!empty($errors)) |
---|
421 | { |
---|
422 | |
---|
423 | ?> |
---|
424 | <div id="posterror" class="block"> |
---|
425 | <h2><span><?php echo $lang_post['Post errors'] ?></span></h2> |
---|
426 | <div class="box"> |
---|
427 | <div class="inbox"> |
---|
428 | <p><?php echo $lang_post['Post errors info'] ?></p> |
---|
429 | <ul> |
---|
430 | <?php |
---|
431 | |
---|
432 | while (list(, $cur_error) = each($errors)) |
---|
433 | echo "\t\t\t\t".'<li><strong>'.$cur_error.'</strong></li>'."\n"; |
---|
434 | ?> |
---|
435 | </ul> |
---|
436 | </div> |
---|
437 | </div> |
---|
438 | </div> |
---|
439 | |
---|
440 | <?php |
---|
441 | |
---|
442 | } |
---|
443 | else if (isset($_POST['preview'])) |
---|
444 | { |
---|
445 | require_once PUN_ROOT.'include/parser.php'; |
---|
446 | $preview_message = parse_message($message, $hide_smilies); |
---|
447 | |
---|
448 | ?> |
---|
449 | <div id="postpreview" class="blockpost"> |
---|
450 | <h2><span><?php echo $lang_post['Post preview'] ?></span></h2> |
---|
451 | <div class="box"> |
---|
452 | <div class="inbox"> |
---|
453 | <div class="postright"> |
---|
454 | <div class="postmsg"> |
---|
455 | <?php echo $preview_message."\n" ?> |
---|
456 | </div> |
---|
457 | </div> |
---|
458 | </div> |
---|
459 | </div> |
---|
460 | </div> |
---|
461 | |
---|
462 | <?php |
---|
463 | |
---|
464 | } |
---|
465 | |
---|
466 | |
---|
467 | $cur_index = 1; |
---|
468 | |
---|
469 | ?> |
---|
470 | <div class="blockform"> |
---|
471 | <h2><span><?php echo $action ?></span></h2> |
---|
472 | <div class="box"> |
---|
473 | <?php echo $form."\n" ?> |
---|
474 | <div class="inform"> |
---|
475 | <fieldset> |
---|
476 | <legend><?php echo $lang_common['Write message legend'] ?></legend> |
---|
477 | <div class="infldset txtarea"> |
---|
478 | <input type="hidden" name="form_sent" value="1" /> |
---|
479 | <input type="hidden" name="form_user" value="<?php echo (!$pun_user['is_guest']) ? pun_htmlspecialchars($pun_user['username']) : 'Invité'; ?>" /> |
---|
480 | <?php |
---|
481 | |
---|
482 | if ($pun_user['is_guest']) |
---|
483 | { |
---|
484 | $email_label = ($pun_config['p_force_guest_email'] == '1') ? '<strong>'.$lang_common['E-mail'].'</strong>' : $lang_common['E-mail']; |
---|
485 | $email_form_name = ($pun_config['p_force_guest_email'] == '1') ? 'req_email' : 'email'; |
---|
486 | |
---|
487 | ?> <label class="conl"><strong><?php echo $lang_post['Guest name'] ?></strong><br /><input type="text" name="req_username" value="<?php if (isset($_POST['req_username'])) echo pun_htmlspecialchars($username); ?>" size="25" maxlength="25" tabindex="<?php echo $cur_index++ ?>" /><br /></label> |
---|
488 | <label class="conl"><?php echo $email_label ?><br /><input type="text" name="<?php echo $email_form_name ?>" value="<?php if (isset($_POST[$email_form_name])) echo pun_htmlspecialchars($email); ?>" size="50" maxlength="50" tabindex="<?php echo $cur_index++ ?>" /><br /></label> |
---|
489 | <div class="clearer"></div> |
---|
490 | <?php |
---|
491 | |
---|
492 | } |
---|
493 | |
---|
494 | if ($fid): ?> |
---|
495 | <label><strong><?php echo $lang_common['Subject'] ?></strong><br /><input class="longinput" type="text" name="req_subject" value="<?php if (isset($_POST['req_subject'])) echo pun_htmlspecialchars($subject); ?>" size="80" maxlength="70" tabindex="<?php echo $cur_index++ ?>" /><br /></label> |
---|
496 | <?php endif; require PUN_ROOT.'mod_easy_bbcode.php'; ?> <label><strong><?php echo $lang_common['Message'] ?></strong><br /> |
---|
497 | |
---|
498 | <textarea name="req_message" rows="20" cols="95" tabindex="<?php echo $cur_index++ ?>"><?php echo isset($_POST['req_message']) ? pun_htmlspecialchars($message) : (isset($quote) ? $quote : ''); ?></textarea><br /></label> |
---|
499 | <ul class="bblinks"> |
---|
500 | <li><a href="help.php#bbcode" onclick="window.open(this.href); return false;"><?php echo $lang_common['BBCode'] ?></a>: <?php echo ($pun_config['p_message_bbcode'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></li> |
---|
501 | <li><a href="help.php#img" onclick="window.open(this.href); return false;"><?php echo $lang_common['img tag'] ?></a>: <?php echo ($pun_config['p_message_img_tag'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></li> |
---|
502 | <li><a href="help.php#smilies" onclick="window.open(this.href); return false;"><?php echo $lang_common['Smilies'] ?></a>: <?php echo ($pun_config['o_smilies'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></li> |
---|
503 | </ul> |
---|
504 | </div> |
---|
505 | </fieldset> |
---|
506 | <?php |
---|
507 | |
---|
508 | $checkboxes = array(); |
---|
509 | if (!$pun_user['is_guest']) |
---|
510 | { |
---|
511 | if ($pun_config['o_smilies'] == '1') |
---|
512 | $checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" tabindex="'.($cur_index++).'"'.(isset($_POST['hide_smilies']) ? ' checked="checked"' : '').' />'.$lang_post['Hide smilies']; |
---|
513 | |
---|
514 | if ($pun_config['o_subscriptions'] == '1') |
---|
515 | $checkboxes[] = '<label><input type="checkbox" name="subscribe" value="1" tabindex="'.($cur_index++).'"'.(isset($_POST['subscribe']) ? ' checked="checked"' : '').' />'.$lang_post['Subscribe']; |
---|
516 | } |
---|
517 | else if ($pun_config['o_smilies'] == '1') |
---|
518 | $checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" tabindex="'.($cur_index++).'"'.(isset($_POST['hide_smilies']) ? ' checked="checked"' : '').' />'.$lang_post['Hide smilies']; |
---|
519 | |
---|
520 | if (!empty($checkboxes)) |
---|
521 | { |
---|
522 | |
---|
523 | ?> |
---|
524 | </div> |
---|
525 | <div class="inform"> |
---|
526 | <fieldset> |
---|
527 | <legend><?php echo $lang_common['Options'] ?></legend> |
---|
528 | <div class="infldset"> |
---|
529 | <div class="rbox"> |
---|
530 | <?php echo implode('<br /></label>'."\n\t\t\t\t", $checkboxes).'<br /></label>'."\n" ?> |
---|
531 | </div> |
---|
532 | </div> |
---|
533 | </fieldset> |
---|
534 | <?php |
---|
535 | |
---|
536 | } |
---|
537 | |
---|
538 | ?> |
---|
539 | </div> |
---|
540 | <p><input type="submit" name="submit" value="<?php echo $lang_common['Submit'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="s" /><input type="submit" name="preview" value="<?php echo $lang_post['Preview'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="p" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p> |
---|
541 | </form> |
---|
542 | </div> |
---|
543 | </div> |
---|
544 | |
---|
545 | <?php |
---|
546 | |
---|
547 | // Check to see if the topic review is to be displayed. |
---|
548 | if ($tid && $pun_config['o_topic_review'] != '0') |
---|
549 | { |
---|
550 | require_once PUN_ROOT.'include/parser.php'; |
---|
551 | |
---|
552 | $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('Impossible de retrouver le résumé de la discussion', __FILE__, __LINE__, $db->error()); |
---|
553 | |
---|
554 | ?> |
---|
555 | |
---|
556 | <div id="postreview" class="blockpost"> |
---|
557 | <h2><span><?php echo $lang_post['Topic review'] ?></span></h2> |
---|
558 | <?php |
---|
559 | |
---|
560 | //Set background switching on |
---|
561 | $bg_switch = true; |
---|
562 | $post_count = 0; |
---|
563 | |
---|
564 | while ($cur_post = $db->fetch_assoc($result)) |
---|
565 | { |
---|
566 | // Switch the background color for every message. |
---|
567 | $bg_switch = ($bg_switch) ? $bg_switch = false : $bg_switch = true; |
---|
568 | $vtbg = ($bg_switch) ? ' roweven' : ' rowodd'; |
---|
569 | $post_count++; |
---|
570 | |
---|
571 | $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']); |
---|
572 | |
---|
573 | ?> |
---|
574 | <div class="box<?php echo $vtbg ?>"> |
---|
575 | <div class="inbox"> |
---|
576 | <div class="postleft"> |
---|
577 | <dl> |
---|
578 | <dt><strong><?php echo pun_htmlspecialchars($cur_post['poster']) ?></strong></dt> |
---|
579 | <dd><?php echo format_time($cur_post['posted']) ?></dd> |
---|
580 | </dl> |
---|
581 | </div> |
---|
582 | <div class="postright"> |
---|
583 | <div class="postmsg"> |
---|
584 | <?php echo $cur_post['message'] ?> |
---|
585 | </div> |
---|
586 | </div> |
---|
587 | <div class="clearer"></div> |
---|
588 | </div> |
---|
589 | </div> |
---|
590 | <?php |
---|
591 | |
---|
592 | } |
---|
593 | |
---|
594 | ?> |
---|
595 | </div> |
---|
596 | <?php |
---|
597 | |
---|
598 | } |
---|
599 | |
---|
600 | require PUN_ROOT.'footer.php'; |
---|