redirect after posting in noticeboard to counter repost with F5

This commit is contained in:
Savetheinternet 2011-07-30 15:56:57 +10:00
parent 9076118d00
commit dcba7462d6

103
mod.php
View File

@ -488,8 +488,7 @@
$body = ''; $body = '';
if($mod['type'] >= $config['mod']['noticeboard_post']) { if(hasPermission($config['mod']['noticeboard_post']) && isset($_POST['subject']) && isset($_POST['body']) && !empty($_POST['body'])) {
if(isset($_POST['subject']) && isset($_POST['body']) && !empty($_POST['body'])) {
$query = prepare("INSERT INTO `noticeboard` VALUES (NULL, :mod, :time, :subject, :body)"); $query = prepare("INSERT INTO `noticeboard` VALUES (NULL, :mod, :time, :subject, :body)");
$query->bindValue(':mod', $mod['id'], PDO::PARAM_INT); $query->bindValue(':mod', $mod['id'], PDO::PARAM_INT);
$query->bindvalue(':time', time(), PDO::PARAM_INT); $query->bindvalue(':time', time(), PDO::PARAM_INT);
@ -498,60 +497,64 @@
markup($_POST['body']); markup($_POST['body']);
$query->bindValue(':body', $_POST['body']); $query->bindValue(':body', $_POST['body']);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
header('Location: ?/noticeboard', true, $config['redirect_http']);
} else {
if(hasPermission($config['mod']['noticeboard_post'])) {
$body .= '<fieldset><legend>New post</legend><form style="display:inline" action="" method="post"><table>' .
'<tr>' .
'<th><label for="subject">Name</label></th>' .
'<td>' . $mod['username'] . '</td>' .
'</tr><tr>' .
'<th>Subject</th>' .
'<td><input type="text" size="55" name="subject" id="subject" /></td>' .
'</tr><tr>' .
'<th>Body</th>' .
'<td><textarea name="body" style="width:100%;height:100px"></textarea></td>' .
'</tr><tr>' .
'<td></td><td><input type="submit" value="Post to noticeboard" /></td>' .
'</tr></table>' .
'</form></fieldset>';
} }
$body .= '<fieldset><legend>New post</legend><form style="display:inline" action="" method="post"><table>' . $query = prepare("SELECT * FROM `noticeboard` ORDER BY `id` DESC LIMIT :limit");
'<tr>' . $query->bindValue(':limit', $config['mod']['noticeboard_display'], PDO::PARAM_INT);
'<th><label for="subject">Name</label></th>' . $query->execute() or error(db_error($query));
'<td>' . $mod['username'] . '</td>' . while($notice = $query->fetch()) {
'</tr><tr>' . $m_query = prepare("SELECT `username` FROM `mods` WHERE `id` = :id");
'<th>Subject</th>' . $m_query->bindValue(':id', $notice['mod'], PDO::PARAM_INT);
'<td><input type="text" size="55" name="subject" id="subject" /></td>' . $m_query->execute() or error(db_error($m_query));
'</tr><tr>' . if(!$_mod = $m_query->fetch()) {
'<th>Body</th>' . $_mod = Array('username' => '<em>???</em>');
'<td><textarea name="body" style="width:100%;height:100px"></textarea></td>' . }
'</tr><tr>' .
'<td></td><td><input type="submit" value="Post to noticeboard" /></td>' .
'</tr></table>' .
'</form></fieldset>';
}
$query = prepare("SELECT * FROM `noticeboard` ORDER BY `id` DESC LIMIT :limit"); $body .= '<div class="ban">' .
$query->bindValue(':limit', $config['mod']['noticeboard_display'], PDO::PARAM_INT); ($mod['type'] >= $config['mod']['noticeboard_delete'] ?
$query->execute() or error(db_error($query)); '<span style="float:right;padding:2px"><a class="unimportant" href="?/noticeboard/delete/' . $notice['id'] . '">[delete]</a></span>'
while($notice = $query->fetch()) { : '') .
$m_query = prepare("SELECT `username` FROM `mods` WHERE `id` = :id"); '<h2 id="' . $notice['id'] . '">' .
$m_query->bindValue(':id', $notice['mod'], PDO::PARAM_INT); ($notice['subject'] ?
$m_query->execute() or error(db_error($m_query)); $notice['subject']
if(!$_mod = $m_query->fetch()) { :
$_mod = Array('username' => '<em>???</em>'); '<em>no subject</em>'
) .
'<span class="unimportant"> — by ' .
$_mod['username'] .
' at ' .
date($config['post_date'], $notice['time']) .
'</span></h2><p>' . $notice['body'] . '</p></div>';
} }
$body .= '<div class="ban">' .
($mod['type'] >= $config['mod']['noticeboard_delete'] ? echo Element('page.html', Array(
'<span style="float:right;padding:2px"><a class="unimportant" href="?/noticeboard/delete/' . $notice['id'] . '">[delete]</a></span>' 'config'=>$config,
: '') . 'title'=>'Noticeboard',
'<h2 id="' . $notice['id'] . '">' . 'body'=>$body,
($notice['subject'] ? 'mod'=>true
$notice['subject'] )
: );
'<em>no subject</em>'
) .
'<span class="unimportant"> — by ' .
$_mod['username'] .
' at ' .
date($config['post_date'], $notice['time']) .
'</span></h2><p>' . $notice['body'] . '</p></div>';
} }
echo Element('page.html', Array(
'config'=>$config,
'title'=>'Noticeboard',
'body'=>$body,
'mod'=>true
)
);
} elseif(preg_match('/^\/news\/delete\/(\d+)$/', $query, $match)) { } elseif(preg_match('/^\/news\/delete\/(\d+)$/', $query, $match)) {
if(!hasPermission($config['mod']['noticeboard_delete'])) error($config['error']['noaccess']); if(!hasPermission($config['mod']['noticeboard_delete'])) error($config['error']['noaccess']);