1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-24 15:40:12 +01:00

Make it so you can edit/remove embed, post preview

This commit is contained in:
Fredrick Brennan 2015-04-03 15:37:55 +08:00
parent c8a733d04a
commit 31d160d25b
2 changed files with 43 additions and 4 deletions

View File

@ -1615,10 +1615,17 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
$_POST['body'] .= "<tinyboard $key>$value</tinyboard>";
}
// Handle embed edits...
foreach ($config['embedding'] as &$embed) {
if (preg_match($embed[0], $_POST['embed'])) {
$embed_link = $_POST['embed'];
}
}
if ($edit_raw_html)
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name,'. $trip .' `email` = :email, `subject` = :subject, `body` = :body, `body_nomarkup` = :body_nomarkup, `edited_at` = UNIX_TIMESTAMP(NOW()) WHERE `id` = :id', $board));
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name,'. $trip .' `email` = :email, `subject` = :subject, `body` = :body, `body_nomarkup` = :body_nomarkup, `embed` = :embed `edited_at` = UNIX_TIMESTAMP(NOW()) WHERE `id` = :id', $board));
else
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name,'. $trip .' `email` = :email, `subject` = :subject, `body_nomarkup` = :body, `edited_at` = UNIX_TIMESTAMP(NOW()) WHERE `id` = :id', $board));
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name,'. $trip .' `email` = :email, `subject` = :subject, `body_nomarkup` = :body, `embed` = :embed, `edited_at` = UNIX_TIMESTAMP(NOW()) WHERE `id` = :id', $board));
$query->bindValue(':id', $postID);
$query->bindValue(':name', $_POST['name'] ? $_POST['name'] : $config['anonymous']);
$query->bindValue(':email', $_POST['email']);
@ -1628,6 +1635,11 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
$body_nomarkup = $_POST['body'] . "\n<tinyboard raw html>1</tinyboard>";
$query->bindValue(':body_nomarkup', $body_nomarkup);
}
if (isset($embed_link)) {
$query->bindValue(':embed', $embed_link);
} else {
$query->bindValue(':embed', NULL, PDO::PARAM_NULL);
}
$query->execute() or error(db_error($query));
if( $config['clean']['edits_remove_local'] || $config['clean']['edits_remove_global'] ) {
@ -1686,7 +1698,10 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
$post['body'] = str_replace("\t", '&#09;', $post['body']);
}
mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post));
$preview = new Post($post);
$html = $preview->build(true);
mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post, 'preview' => $html));
}
}

View File

@ -1,3 +1,5 @@
<div style="text-align: center">
<style>.post {text-align:left}</style>
<form action="" method="post">
<input type="hidden" name="token" value="{{ token }}">
@ -15,7 +17,7 @@
{% trans %}Tripcode{% endtrans %}
</th>
<td>
Remove? <input type="checkbox" name="remove_trip" value="{{ post.trip }}">
{% trans %}Remove tripcode?{% endtrans %} <input type="checkbox" name="remove_trip" value="{{ post.trip }}">
</td>
</tr>
<tr>
@ -43,7 +45,28 @@
<textarea name="body" id="body" rows="8" cols="35">{% if raw %}{{ post.body }}{% else %}{{ post.body_nomarkup }}{% endif %}</textarea>
</td>
</tr>
{# <tr> <!-- The file handling code is quite complicated and I'm not about to start maintaining it in two places. It needs to be made into a set of reusable functions or something. If you want to do so uncomment this. Pull requests that copy the code from post.php to inc/mod/pages.php without creating functions to be used in both won't be accepted. -->
<th>
{% trans %}Files{% endtrans %}<br/>
<p class="unimportant">{% trans %}Note: Changing files<br/>deletes all previous ones.{% endtrans %}</p>
</th>
<td>
{% for i in range(0, config.max_images - 1) %}
<input type="file" name="file" id="upload_file"><br/>
{% endfor %}
</td>
</tr> #}
<tr id="upload_embed">
<th>
{% trans %}Embed{% endtrans %}
</th>
<td>
<input type="text" name="embed" value="{{ post.embed|e }}" size="30" maxlength="120" autocomplete="off">
</td>
</tr>
</table>
<h2>{% trans %}Existing post{% endtrans %}</h2>
{{ preview }}
<p style="text-align:center">
{% if mod|hasPermission(config.mod.rawhtml) %}
{% if raw %}
@ -55,3 +78,4 @@
{% endif %}
</p>
</form>
</div>