Changeset 3 for branches/rsr.v5.1.dev/web/punbb/edit.php
- Timestamp:
- Nov 14, 2011, 11:17:15 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rsr.v5.1.dev/web/punbb/edit.php
r1 r3 1 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', './'); 2 3 /** 4 * Copyright (C) 2008-2011 FluxBB 5 * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB 6 * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher 7 */ 8 9 define('PUN_ROOT', dirname(__FILE__).'/'); 27 10 require PUN_ROOT.'include/common.php'; 28 11 … … 37 20 38 21 // 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());22 $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.first_post_id, t.sticky, 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('Unable to fetch post info', __FILE__, __LINE__, $db->error()); 40 23 if (!$db->num_rows($result)) 41 24 message($lang_common['Bad request']); … … 45 28 // Sort out who the moderators are and if we are currently a moderator (or an admin) 46 29 $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; 30 $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false; 31 32 $can_edit_subject = $id == $cur_post['first_post_id']; 33 34 if ($pun_config['o_censoring'] == '1') 35 { 36 $cur_post['subject'] = censor_words($cur_post['subject']); 37 $cur_post['message'] = censor_words($cur_post['message']); 38 } 54 39 55 40 // Do we have permission to edit this post? … … 72 57 confirm_referrer('edit.php'); 73 58 74 // If it is a topic it must contain a subject59 // If it's a topic it must contain a subject 75 60 if ($can_edit_subject) 76 61 { 77 62 $subject = pun_trim($_POST['req_subject']); 63 64 if ($pun_config['o_censoring'] == '1') 65 $censored_subject = pun_trim(censor_words($subject)); 78 66 79 67 if ($subject == '') 80 68 $errors[] = $lang_post['No subject']; 69 else if ($pun_config['o_censoring'] == '1' && $censored_subject == '') 70 $errors[] = $lang_post['No subject after censoring']; 81 71 else if (pun_strlen($subject) > 70) 82 72 $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));73 else if ($pun_config['p_subject_all_caps'] == '0' && is_all_uppercase($subject) && !$pun_user['is_admmod']) 74 $errors[] = $lang_post['All caps subject']; 85 75 } 86 76 … … 88 78 $message = pun_linebreaks(pun_trim($_POST['req_message'])); 89 79 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)); 80 // Here we use strlen() not pun_strlen() as we want to limit the post to PUN_MAX_POSTSIZE bytes, not characters 81 if (strlen($message) > PUN_MAX_POSTSIZE) 82 $errors[] = sprintf($lang_post['Too long message'], forum_number_format(PUN_MAX_POSTSIZE)); 83 else if ($pun_config['p_message_all_caps'] == '0' && is_all_uppercase($message) && !$pun_user['is_admmod']) 84 $errors[] = $lang_post['All caps message']; 96 85 97 86 // Validate BBCode syntax 98 if ($pun_config['p_message_bbcode'] == '1' && strpos($message, '[') !== false && strpos($message, ']') !== false)87 if ($pun_config['p_message_bbcode'] == '1') 99 88 { 100 89 require PUN_ROOT.'include/parser.php'; … … 102 91 } 103 92 104 105 $hide_smilies = isset($_POST['hide_smilies']) ? intval($_POST['hide_smilies']) : 0; 106 if ($hide_smilies != '1') $hide_smilies = '0'; 93 if (empty($errors)) 94 { 95 if ($message == '') 96 $errors[] = $lang_post['No message']; 97 else if ($pun_config['o_censoring'] == '1') 98 { 99 // Censor message to see if that causes problems 100 $censored_message = pun_trim(censor_words($message)); 101 102 if ($censored_message == '') 103 $errors[] = $lang_post['No message after censoring']; 104 } 105 } 106 107 $hide_smilies = isset($_POST['hide_smilies']) ? '1' : '0'; 108 $stick_topic = isset($_POST['stick_topic']) ? '1' : '0'; 109 if (!$is_admmod) 110 $stick_topic = $cur_post['sticky']; 107 111 108 112 // Did everything go according to plan? 109 113 if (empty($errors) && !isset($_POST['preview'])) 110 114 { 111 $edited_sql = (!isset($_POST['silent']) || !$is_admmod) ? $edited_sql =', edited='.time().', edited_by=\''.$db->escape($pun_user['username']).'\'' : '';115 $edited_sql = (!isset($_POST['silent']) || !$is_admmod) ? ', edited='.time().', edited_by=\''.$db->escape($pun_user['username']).'\'' : ''; 112 116 113 117 require PUN_ROOT.'include/search_idx.php'; … … 116 120 { 117 121 // 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());122 $db->query('UPDATE '.$db->prefix.'topics SET subject=\''.$db->escape($subject).'\', sticky='.$stick_topic.' WHERE id='.$cur_post['tid'].' OR moved_to='.$cur_post['tid']) or error('Unable to update topic', __FILE__, __LINE__, $db->error()); 119 123 120 124 // We changed the subject, so we need to take that into account when we update the search words … … 125 129 126 130 // 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());131 $db->query('UPDATE '.$db->prefix.'posts SET message=\''.$db->escape($message).'\', hide_smilies='.$hide_smilies.$edited_sql.' WHERE id='.$id) or error('Unable to update post', __FILE__, __LINE__, $db->error()); 128 132 129 133 redirect('viewtopic.php?pid='.$id.'#p'.$id, $lang_post['Edit redirect']); … … 133 137 134 138 135 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_post['Edit post'];139 $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_post['Edit post']); 136 140 $required_fields = array('req_subject' => $lang_common['Subject'], 'req_message' => $lang_common['Message']); 137 141 $focus_element = array('edit', 'req_message'); 142 define('PUN_ACTIVE_PAGE', 'index'); 138 143 require PUN_ROOT.'header.php'; 139 144 … … 143 148 <div class="linkst"> 144 149 <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> 150 <ul class="crumbs"> 151 <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li> 152 <li><span>» </span><a href="viewforum.php?id=<?php echo $cur_post['fid'] ?>"><?php echo pun_htmlspecialchars($cur_post['forum_name']) ?></a></li> 153 <li><span>» </span><a href="viewtopic.php?id=<?php echo $cur_post['tid'] ?>"><?php echo pun_htmlspecialchars($cur_post['subject']) ?></a></li> 154 <li><span>» </span><strong><?php echo $lang_post['Edit post'] ?></strong></li> 155 </ul> 146 156 </div> 147 157 </div> … … 157 167 <h2><span><?php echo $lang_post['Post errors'] ?></span></h2> 158 168 <div class="box"> 159 <div class="inbox "169 <div class="inbox error-info"> 160 170 <p><?php echo $lang_post['Post errors info'] ?></p> 161 <ul >162 <?php 163 164 while (list(, $cur_error) = each($errors))171 <ul class="error-list"> 172 <?php 173 174 foreach ($errors as $cur_error) 165 175 echo "\t\t\t\t".'<li><strong>'.$cur_error.'</strong></li>'."\n"; 166 176 ?> … … 183 193 <div class="box"> 184 194 <div class="inbox"> 185 <div class="postright"> 186 <div class="postmsg"> 187 <?php echo $preview_message."\n" ?> 195 <div class="postbody"> 196 <div class="postright"> 197 <div class="postmsg"> 198 <?php echo $preview_message."\n" ?> 199 </div> 188 200 </div> 189 201 </div> … … 197 209 198 210 ?> 199 <div class="blockform">200 <h2>< ?php echo $lang_post['Edit post'] ?></h2>211 <div id="editform" class="blockform"> 212 <h2><span><?php echo $lang_post['Edit post'] ?></span></h2> 201 213 <div class="box"> 202 214 <form id="edit" method="post" action="edit.php?id=<?php echo $id ?>&action=edit" onsubmit="return process_form(this)"> … … 206 218 <input type="hidden" name="form_sent" value="1" /> 207 219 <div class="infldset txtarea"> 208 <?php if ($can_edit_subject): ?> <label ><?php echo $lang_common['Subject'] ?><br />220 <?php if ($can_edit_subject): ?> <label class="required"><strong><?php echo $lang_common['Subject'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /> 209 221 <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 222 <?php endif; ?> <label class="required"><strong><?php echo $lang_common['Message'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /> 212 223 <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 224 <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>225 <li><span><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']; ?></span></li> 226 <li><span><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_bbcode'] == '1' && $pun_config['p_message_img_tag'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li> 227 <li><span><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']; ?></span></li> 217 228 </ul> 218 229 </div> … … 221 232 222 233 $checkboxes = array(); 234 if ($can_edit_subject && $is_admmod) 235 { 236 if (isset($_POST['stick_topic']) || $cur_post['sticky'] == '1') 237 $checkboxes[] = '<label><input type="checkbox" name="stick_topic" value="1" checked="checked" tabindex="'.($cur_index++).'" />'.$lang_common['Stick topic'].'<br /></label>'; 238 else 239 $checkboxes[] = '<label><input type="checkbox" name="stick_topic" value="1" tabindex="'.($cur_index++).'" />'.$lang_common['Stick topic'].'<br /></label>'; 240 } 241 223 242 if ($pun_config['o_smilies'] == '1') 224 243 { 225 244 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'];245 $checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" checked="checked" tabindex="'.($cur_index++).'" />'.$lang_post['Hide smilies'].'<br /></label>'; 227 246 else 228 $checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" tabindex="'.($cur_index++).'" />  '.$lang_post['Hide smilies'];247 $checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" tabindex="'.($cur_index++).'" />'.$lang_post['Hide smilies'].'<br /></label>'; 229 248 } 230 249 … … 232 251 { 233 252 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'];253 $checkboxes[] = '<label><input type="checkbox" name="silent" value="1" tabindex="'.($cur_index++).'" checked="checked" />'.$lang_post['Silent edit'].'<br /></label>'; 235 254 else 236 $checkboxes[] = '<label><input type="checkbox" name="silent" value="1" tabindex="'.($cur_index++).'" />  '.$lang_post['Silent edit'];255 $checkboxes[] = '<label><input type="checkbox" name="silent" value="1" tabindex="'.($cur_index++).'" />'.$lang_post['Silent edit'].'<br /></label>'; 237 256 } 238 257 … … 247 266 <div class="infldset"> 248 267 <div class="rbox"> 249 <?php echo implode( '</label>'."\n\t\t\t\t\t\t\t", $checkboxes).'</label>'."\n" ?>268 <?php echo implode("\n\t\t\t\t\t\t\t", $checkboxes)."\n" ?> 250 269 </div> 251 270 </div> … … 257 276 ?> 258 277 </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>278 <p class="buttons"><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 279 </form> 261 280 </div>
Note: See TracChangeset
for help on using the changeset viewer.