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 | $id = isset($_GET['id']) ? intval($_GET['id']) : 0; |
---|
35 | if ($id < 1) |
---|
36 | message($lang_common['Bad request']); |
---|
37 | |
---|
38 | // Fetch some info about the post, the topic and the forum |
---|
39 | $result = $db->query('SELECT f.id AS fid, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.id AS tid, t.subject, t.posted, t.closed, p.poster, p.poster_id, p.message, p.hide_smilies FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id 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 p.id='.$id) or error('Impossible de retrouver les informations des messages', __FILE__, __LINE__, $db->error()); |
---|
40 | if (!$db->num_rows($result)) |
---|
41 | message($lang_common['Bad request']); |
---|
42 | |
---|
43 | $cur_post = $db->fetch_assoc($result); |
---|
44 | |
---|
45 | // Sort out who the moderators are and if we are currently a moderator (or an admin) |
---|
46 | $mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array(); |
---|
47 | $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && array_key_exists($pun_user['username'], $mods_array))) ? true : false; |
---|
48 | |
---|
49 | // Determine whether this post is the "topic post" or not |
---|
50 | $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$cur_post['tid'].' ORDER BY posted LIMIT 1') or error('Impossible de retrouver les informations des messages', __FILE__, __LINE__, $db->error()); |
---|
51 | $topic_post_id = $db->result($result); |
---|
52 | |
---|
53 | $can_edit_subject = ($id == $topic_post_id && (($pun_user['g_edit_subjects_interval'] == '0' || (time() - $cur_post['posted']) < $pun_user['g_edit_subjects_interval']) || $is_admmod)) ? true : false; |
---|
54 | |
---|
55 | // Do we have permission to edit this post? |
---|
56 | if (($pun_user['g_edit_posts'] == '0' || |
---|
57 | $cur_post['poster_id'] != $pun_user['id'] || |
---|
58 | $cur_post['closed'] == '1') && |
---|
59 | !$is_admmod) |
---|
60 | message($lang_common['No permission']); |
---|
61 | |
---|
62 | // Load the post.php/edit.php language file |
---|
63 | require PUN_ROOT.'lang/'.$pun_user['language'].'/post.php'; |
---|
64 | |
---|
65 | // Start with a clean slate |
---|
66 | $errors = array(); |
---|
67 | |
---|
68 | |
---|
69 | if (isset($_POST['form_sent'])) |
---|
70 | { |
---|
71 | if ($is_admmod) |
---|
72 | confirm_referrer('edit.php'); |
---|
73 | |
---|
74 | // If it is a topic it must contain a subject |
---|
75 | if ($can_edit_subject) |
---|
76 | { |
---|
77 | $subject = pun_trim($_POST['req_subject']); |
---|
78 | |
---|
79 | if ($subject == '') |
---|
80 | $errors[] = $lang_post['No subject']; |
---|
81 | else if (pun_strlen($subject) > 70) |
---|
82 | $errors[] = $lang_post['Too long subject']; |
---|
83 | else if ($pun_config['p_subject_all_caps'] == '0' && strtoupper($subject) == $subject && $pun_user['g_id'] > PUN_MOD) |
---|
84 | $subject = ucwords(strtolower($subject)); |
---|
85 | } |
---|
86 | |
---|
87 | // Clean up message from POST |
---|
88 | $message = pun_linebreaks(pun_trim($_POST['req_message'])); |
---|
89 | |
---|
90 | if ($message == '') |
---|
91 | $errors[] = $lang_post['No message']; |
---|
92 | else if (strlen($message) > 65535) |
---|
93 | $errors[] = $lang_post['Too long message']; |
---|
94 | else if ($pun_config['p_message_all_caps'] == '0' && strtoupper($message) == $message && $pun_user['g_id'] > PUN_MOD) |
---|
95 | $message = ucwords(strtolower($message)); |
---|
96 | |
---|
97 | // Validate BBCode syntax |
---|
98 | if ($pun_config['p_message_bbcode'] == '1' && strpos($message, '[') !== false && strpos($message, ']') !== false) |
---|
99 | { |
---|
100 | require PUN_ROOT.'include/parser.php'; |
---|
101 | $message = preparse_bbcode($message, $errors); |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | $hide_smilies = isset($_POST['hide_smilies']) ? intval($_POST['hide_smilies']) : 0; |
---|
106 | if ($hide_smilies != '1') $hide_smilies = '0'; |
---|
107 | |
---|
108 | // Did everything go according to plan? |
---|
109 | if (empty($errors) && !isset($_POST['preview'])) |
---|
110 | { |
---|
111 | $edited_sql = (!isset($_POST['silent']) || !$is_admmod) ? $edited_sql = ', edited='.time().', edited_by=\''.$db->escape($pun_user['username']).'\'' : ''; |
---|
112 | |
---|
113 | require PUN_ROOT.'include/search_idx.php'; |
---|
114 | |
---|
115 | if ($can_edit_subject) |
---|
116 | { |
---|
117 | // Update the topic and any redirect topics |
---|
118 | $db->query('UPDATE '.$db->prefix.'topics SET subject=\''.$db->escape($subject).'\' WHERE id='.$cur_post['tid'].' OR moved_to='.$cur_post['tid']) or error('Impossible de modifier la discussion', __FILE__, __LINE__, $db->error()); |
---|
119 | |
---|
120 | // We changed the subject, so we need to take that into account when we update the search words |
---|
121 | update_search_index('edit', $id, $message, $subject); |
---|
122 | } |
---|
123 | else |
---|
124 | update_search_index('edit', $id, $message); |
---|
125 | |
---|
126 | // Update the post |
---|
127 | $db->query('UPDATE '.$db->prefix.'posts SET message=\''.$db->escape($message).'\', hide_smilies=\''.$hide_smilies.'\''.$edited_sql.' WHERE id='.$id) or error('Impossible de modifier le message', __FILE__, __LINE__, $db->error()); |
---|
128 | |
---|
129 | redirect('viewtopic.php?pid='.$id.'#p'.$id, $lang_post['Edit redirect']); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_post['Edit post']; |
---|
136 | $required_fields = array('req_subject' => $lang_common['Subject'], 'req_message' => $lang_common['Message']); |
---|
137 | $focus_element = array('edit', 'req_message'); |
---|
138 | require PUN_ROOT.'header.php'; |
---|
139 | |
---|
140 | $cur_index = 1; |
---|
141 | |
---|
142 | ?> |
---|
143 | <div class="linkst"> |
---|
144 | <div class="inbox"> |
---|
145 | <ul><li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li><li> » <a href="viewforum.php?id=<?php echo $cur_post['fid'] ?>"><?php echo pun_htmlspecialchars($cur_post['forum_name']) ?></a></li><li> » <?php echo pun_htmlspecialchars($cur_post['subject']) ?></li></ul> |
---|
146 | </div> |
---|
147 | </div> |
---|
148 | |
---|
149 | <?php |
---|
150 | |
---|
151 | // If there are errors, we display them |
---|
152 | if (!empty($errors)) |
---|
153 | { |
---|
154 | |
---|
155 | ?> |
---|
156 | <div id="posterror" class="block"> |
---|
157 | <h2><span><?php echo $lang_post['Post errors'] ?></span></h2> |
---|
158 | <div class="box"> |
---|
159 | <div class="inbox" |
---|
160 | <p><?php echo $lang_post['Post errors info'] ?></p> |
---|
161 | <ul> |
---|
162 | <?php |
---|
163 | |
---|
164 | while (list(, $cur_error) = each($errors)) |
---|
165 | echo "\t\t\t\t".'<li><strong>'.$cur_error.'</strong></li>'."\n"; |
---|
166 | ?> |
---|
167 | </ul> |
---|
168 | </div> |
---|
169 | </div> |
---|
170 | </div> |
---|
171 | |
---|
172 | <?php |
---|
173 | |
---|
174 | } |
---|
175 | else if (isset($_POST['preview'])) |
---|
176 | { |
---|
177 | require_once PUN_ROOT.'include/parser.php'; |
---|
178 | $preview_message = parse_message($message, $hide_smilies); |
---|
179 | |
---|
180 | ?> |
---|
181 | <div id="postpreview" class="blockpost"> |
---|
182 | <h2><span><?php echo $lang_post['Post preview'] ?></span></h2> |
---|
183 | <div class="box"> |
---|
184 | <div class="inbox"> |
---|
185 | <div class="postright"> |
---|
186 | <div class="postmsg"> |
---|
187 | <?php echo $preview_message."\n" ?> |
---|
188 | </div> |
---|
189 | </div> |
---|
190 | </div> |
---|
191 | </div> |
---|
192 | </div> |
---|
193 | |
---|
194 | <?php |
---|
195 | |
---|
196 | } |
---|
197 | |
---|
198 | ?> |
---|
199 | <div class="blockform"> |
---|
200 | <h2><?php echo $lang_post['Edit post'] ?></h2> |
---|
201 | <div class="box"> |
---|
202 | <form id="edit" method="post" action="edit.php?id=<?php echo $id ?>&action=edit" onsubmit="return process_form(this)"> |
---|
203 | <div class="inform"> |
---|
204 | <fieldset> |
---|
205 | <legend><?php echo $lang_post['Edit post legend'] ?></legend> |
---|
206 | <input type="hidden" name="form_sent" value="1" /> |
---|
207 | <div class="infldset txtarea"> |
---|
208 | <?php if ($can_edit_subject): ?> <label><?php echo $lang_common['Subject'] ?><br /> |
---|
209 | <input class="longinput" type="text" name="req_subject" size="80" maxlength="70" tabindex="<?php echo $cur_index++ ?>" value="<?php echo pun_htmlspecialchars(isset($_POST['req_subject']) ? $_POST['req_subject'] : $cur_post['subject']) ?>" /><br /></label> |
---|
210 | <?php endif; $bbcode_form = 'edit'; $bbcode_field = 'req_message'; require PUN_ROOT.'mod_easy_bbcode.php'; ?> <label><?php echo $lang_common['Message'] ?><br /> |
---|
211 | |
---|
212 | <textarea name="req_message" rows="20" cols="95" tabindex="<?php echo $cur_index++ ?>"><?php echo pun_htmlspecialchars(isset($_POST['req_message']) ? $message : $cur_post['message']) ?></textarea><br /></label> |
---|
213 | <ul class="bblinks"> |
---|
214 | <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> |
---|
215 | <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> |
---|
216 | <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> |
---|
217 | </ul> |
---|
218 | </div> |
---|
219 | </fieldset> |
---|
220 | <?php |
---|
221 | |
---|
222 | $checkboxes = array(); |
---|
223 | if ($pun_config['o_smilies'] == '1') |
---|
224 | { |
---|
225 | if (isset($_POST['hide_smilies']) || $cur_post['hide_smilies'] == '1') |
---|
226 | $checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" checked="checked" tabindex="'.($cur_index++).'" /> '.$lang_post['Hide smilies']; |
---|
227 | else |
---|
228 | $checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" tabindex="'.($cur_index++).'" /> '.$lang_post['Hide smilies']; |
---|
229 | } |
---|
230 | |
---|
231 | if ($is_admmod) |
---|
232 | { |
---|
233 | if ((isset($_POST['form_sent']) && isset($_POST['silent'])) || !isset($_POST['form_sent'])) |
---|
234 | $checkboxes[] = '<label><input type="checkbox" name="silent" value="1" tabindex="'.($cur_index++).'" checked="checked" /> '.$lang_post['Silent edit']; |
---|
235 | else |
---|
236 | $checkboxes[] = '<label><input type="checkbox" name="silent" value="1" tabindex="'.($cur_index++).'" /> '.$lang_post['Silent edit']; |
---|
237 | } |
---|
238 | |
---|
239 | if (!empty($checkboxes)) |
---|
240 | { |
---|
241 | |
---|
242 | ?> |
---|
243 | </div> |
---|
244 | <div class="inform"> |
---|
245 | <fieldset> |
---|
246 | <legend><?php echo $lang_common['Options'] ?></legend> |
---|
247 | <div class="infldset"> |
---|
248 | <div class="rbox"> |
---|
249 | <?php echo implode('</label>'."\n\t\t\t\t\t\t\t", $checkboxes).'</label>'."\n" ?> |
---|
250 | </div> |
---|
251 | </div> |
---|
252 | </fieldset> |
---|
253 | <?php |
---|
254 | |
---|
255 | } |
---|
256 | |
---|
257 | ?> |
---|
258 | </div> |
---|
259 | <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> |
---|
260 | </form> |
---|
261 | </div> |
---|
262 | </div> |
---|
263 | <?php |
---|
264 | |
---|
265 | require PUN_ROOT.'footer.php'; |
---|