Browse Source

Major fixes and clean-up for edit form

pull/40/head
Michael Save 11 years ago
parent
commit
bceb314ce6
  1. 4
      inc/config.php
  2. 36
      inc/mod/pages.php
  3. 2
      mod.php
  4. 17
      templates/mod/edit_post_form.html

4
inc/config.php

@ -920,8 +920,8 @@
$config['mod']['bumplock'] = MOD; $config['mod']['bumplock'] = MOD;
// View whether a thread has been bumplocked ("-1" to allow non-mods to see too) // View whether a thread has been bumplocked ("-1" to allow non-mods to see too)
$config['mod']['view_bumplock'] = MOD; $config['mod']['view_bumplock'] = MOD;
// Edit posts (EXPERIMENTAL) // Edit posts
$config['mod']['editpost'] = MOD; $config['mod']['editpost'] = ADMIN;
// "Move" a thread to another board (EXPERIMENTAL; has some known bugs) // "Move" a thread to another board (EXPERIMENTAL; has some known bugs)
$config['mod']['move'] = DISABLED; $config['mod']['move'] = DISABLED;
// Bypass "field_disable_*" (forced anonymity, etc.) // Bypass "field_disable_*" (forced anonymity, etc.)

36
inc/mod/pages.php

@ -986,7 +986,7 @@ function mod_ban_post($board, $delete, $post, $token = false) {
mod_page(_('New ban'), 'mod/ban_form.html', $args); mod_page(_('New ban'), 'mod/ban_form.html', $args);
} }
function mod_edit_post($board, $post) { function mod_edit_post($board, $postID) {
global $config, $mod; global $config, $mod;
if (!openBoard($board)) if (!openBoard($board))
@ -995,37 +995,33 @@ function mod_edit_post($board, $post) {
if (!hasPermission($config['mod']['editpost'], $board)) if (!hasPermission($config['mod']['editpost'], $board))
error($config['error']['noaccess']); error($config['error']['noaccess']);
$security_token = make_secure_link_token($board . '/ban/' . $post); $security_token = make_secure_link_token($board . '/edit/' . $postID);
$query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `id` = :id', $board)); $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `id` = :id', $board));
$query->bindValue(':id', $post); $query->bindValue(':id', $postID);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if (!$_post = $query->fetch(PDO::FETCH_ASSOC)) if (!$post = $query->fetch(PDO::FETCH_ASSOC))
error($config['error']['404']); error($config['error']['404']);
if(isset($_POST['mode']) && $_POST['mode'] == "edit") if (isset($_POST['name'], $_POST['email'], $_POST['subject'], $_POST['body'])) {
{ $query = prepare(sprintf('UPDATE `posts_%s` SET `name` = :name, `email` = :email, `subject` = :subject, `body_nomarkup` = :body WHERE `id` = :id', $board));
$query = prepare(sprintf("UPDATE `posts_%s` SET `name` = :name,`email` = :email,`subject` = :subject,`body` = :body WHERE `id` = :id",$board)); $query->bindValue(':id', $postID);
$query->bindValue(':id', $post);
$query->bindValue('name', $_POST['name']); $query->bindValue('name', $_POST['name']);
$query->bindValue(':email', $_POST['email']); $query->bindValue(':email', $_POST['email']);
$query->bindValue(':subject', $_POST['subject']); $query->bindValue(':subject', $_POST['subject']);
$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: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); rebuildPost($postID);
buildIndex();
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $postID) . '#' . $postID, true, $config['redirect_http']);
} else { } else {
$args = array( if ($config['minify_html'])
'token' => $security_token, $post['body_nomarkup'] = str_replace("\n", '
', $post['body_nomarkup']);
'name' => $_post['name'],
'email' => $_post['email'], mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'post' => $post));
'subject' => $_post['subject'],
'body' => $_post['body'],
'mode' => "edit"
);
mod_page(_('Edit post'), 'mod/edit_post_form.html', $args);
} }
} }

2
mod.php

@ -61,11 +61,11 @@ $pages = array(
'/ban' => 'secure_POST ban', // new ban '/ban' => 'secure_POST ban', // new ban
'/(\w+)/ban(&delete)?/(\d+)' => 'secure_POST ban_post', // ban poster '/(\w+)/ban(&delete)?/(\d+)' => 'secure_POST ban_post', // ban poster
'/(\w+)/move/(\d+)' => 'secure_POST move', // move thread '/(\w+)/move/(\d+)' => 'secure_POST move', // move thread
'/(\w+)/edit/(\d+)' => 'secure_POST edit_post', // edit post
'/(\w+)/delete/(\d+)' => 'secure delete', // delete post '/(\w+)/delete/(\d+)' => 'secure delete', // delete post
'/(\w+)/deletefile/(\d+)' => 'secure deletefile', // delete file from post '/(\w+)/deletefile/(\d+)' => 'secure deletefile', // delete file from post
'/(\w+)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address '/(\w+)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address
'/(\w+)/(un)?lock/(\d+)' => 'secure lock', // lock thread '/(\w+)/(un)?lock/(\d+)' => 'secure lock', // lock thread
'/(\w+)/edit/(\d+)' => 'secure edit_post', // edit post
'/(\w+)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread '/(\w+)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread
'/(\w+)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread '/(\w+)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread

17
templates/mod/edit_post_form.html

@ -1,11 +1,13 @@
<form name="post" enctype="multipart/form-data" action="{{ action }}" method="post"> <form action="" method="post">
<input type="hidden" name="token" value="{{ token }}">
<table> <table>
<tr> <tr>
<th> <th>
{% trans %}Name{% endtrans %} {% trans %}Name{% endtrans %}
</th> </th>
<td> <td>
<input type="text" name="name" size="25" maxlength="35" autocomplete="off" value="{{ name }}"> <input type="text" name="name" size="25" maxlength="35" autocomplete="off" value="{{ post.name }}">
</td> </td>
</tr> </tr>
<tr> <tr>
@ -13,7 +15,7 @@
{% trans %}Email{% endtrans %} {% trans %}Email{% endtrans %}
</th> </th>
<td> <td>
<input type="text" name="email" size="25" maxlength="40" autocomplete="off" value="{{ email }}"> <input type="text" name="email" size="25" maxlength="40" autocomplete="off" value="{{ post.email }}">
</td> </td>
</tr> </tr>
<tr> <tr>
@ -21,7 +23,8 @@
{% trans %}Subject{% endtrans %} {% trans %}Subject{% endtrans %}
</th> </th>
<td> <td>
<input style="float:left;" type="text" name="subject" size="25" maxlength="100" autocomplete="off" value="{{ subject }}"> <input style="float:left;" type="text" name="subject" size="25" maxlength="100" autocomplete="off" value="{{ post.subject }}">
<input accesskey="s" style="margin-left:2px;" type="submit" name="post" value="{% trans %}Update{% endtrans %}">
</td> </td>
</tr> </tr>
<tr> <tr>
@ -29,12 +32,8 @@
{% trans %}Comment{% endtrans %} {% trans %}Comment{% endtrans %}
</th> </th>
<td> <td>
<textarea name="body" id="body" rows="5" cols="35">{{ body }}</textarea> <textarea name="body" id="body" rows="5" cols="35">{{ post.body_nomarkup }}</textarea>
</td> </td>
</tr> </tr>
<tr>
<th><input type="hidden" name="mode" value="{{ mode }}"></th>
<td><input name="sub" type="submit" value="{% trans 'Submit' %}"></td>
</tr>
</table> </table>
</form> </form>

Loading…
Cancel
Save