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