Allow editing of the topic name when editing the original post.
This commit is contained in:
parent
28205006c5
commit
c025a2c88e
6 changed files with 68 additions and 23 deletions
|
@ -110,16 +110,15 @@ if (!empty($_POST)) {
|
|||
$notices[] = 'Could not verify request.';
|
||||
} else {
|
||||
$topicTitle = $_POST['post']['title'] ?? '';
|
||||
$topicTitleValidate = forum_validate_title($topicTitle);
|
||||
$setTopicTitle = empty($topic) || ($mode === 'edit' && $post['is_opening_post'] && $topicTitle !== $topic['topic_title']);
|
||||
$postText = $_POST['post']['text'] ?? '';
|
||||
$postTextValidate = forum_validate_post($postText);
|
||||
$postParser = (int)($_POST['post']['parser'] ?? MSZ_PARSER_BBCODE);
|
||||
|
||||
if (!parser_is_valid($postParser)) {
|
||||
$notices[] = 'Invalid parser selected.';
|
||||
}
|
||||
|
||||
switch ($postTextValidate) {
|
||||
switch (forum_validate_post($postText)) {
|
||||
case 'too-short':
|
||||
$notices[] = 'Post content was too short.';
|
||||
break;
|
||||
|
@ -129,8 +128,8 @@ if (!empty($_POST)) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (empty($topic)) {
|
||||
switch ($topicTitleValidate) {
|
||||
if ($setTopicTitle) {
|
||||
switch (forum_validate_title($topicTitle)) {
|
||||
case 'too-short':
|
||||
$notices[] = 'Topic title was too short.';
|
||||
break;
|
||||
|
@ -162,9 +161,15 @@ if (!empty($_POST)) {
|
|||
break;
|
||||
|
||||
case 'edit':
|
||||
if (!forum_post_edit($postId, ip_remote_address(), $postText, $postParser)) {
|
||||
if (!forum_post_update($postId, ip_remote_address(), $postText, $postParser)) {
|
||||
$notices[] = 'Post edit failed.';
|
||||
}
|
||||
|
||||
if ($setTopicTitle) {
|
||||
if (!forum_topic_update($topicId, $topicTitle)) {
|
||||
$notices[] = 'Topic update failed.';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ function forum_post_create(
|
|||
return $createPost->execute() ? db_last_insert_id() : 0;
|
||||
}
|
||||
|
||||
function forum_post_edit(
|
||||
function forum_post_update(
|
||||
int $postId,
|
||||
string $ipAddress,
|
||||
string $text,
|
||||
|
@ -78,22 +78,27 @@ function forum_post_get(int $postId, bool $allowDeleted = false): array
|
|||
SELECT
|
||||
p.`post_id`, p.`post_text`, p.`post_created`, p.`post_parse`,
|
||||
p.`topic_id`, p.`post_deleted`, p.`post_edited`,
|
||||
INET6_NTOA(p.`post_ip`) as `post_ip`,
|
||||
u.`user_id` as `poster_id`,
|
||||
u.`username` as `poster_name`,
|
||||
u.`user_created` as `poster_joined`,
|
||||
u.`user_country` as `poster_country`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `poster_colour`,
|
||||
INET6_NTOA(p.`post_ip`) AS `post_ip`,
|
||||
u.`user_id` AS `poster_id`,
|
||||
u.`username` AS `poster_name`,
|
||||
u.`user_created` AS `poster_joined`,
|
||||
u.`user_country` AS `poster_country`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) AS `poster_colour`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `user_id` = p.`user_id`
|
||||
AND `post_deleted` IS NULL
|
||||
) as `poster_post_count`
|
||||
FROM `msz_forum_posts` as p
|
||||
LEFT JOIN `msz_users` as u
|
||||
) AS `poster_post_count`,
|
||||
(
|
||||
SELECT MIN(`post_id`) = p.`post_id`
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = p.`topic_id`
|
||||
) AS `is_opening_post`
|
||||
FROM `msz_forum_posts` AS p
|
||||
LEFT JOIN `msz_users` AS u
|
||||
ON u.`user_id` = p.`user_id`
|
||||
LEFT JOIN `msz_roles` as r
|
||||
LEFT JOIN `msz_roles` AS r
|
||||
ON r.`role_id` = u.`display_role`
|
||||
WHERE `post_id` = :post_id
|
||||
%1$s
|
||||
|
@ -125,7 +130,12 @@ function forum_post_listing(int $topicId, int $offset = 0, int $take = 0, bool $
|
|||
FROM `msz_forum_posts`
|
||||
WHERE `user_id` = p.`user_id`
|
||||
AND `post_deleted` IS NULL
|
||||
) as `poster_post_count`
|
||||
) as `poster_post_count`,
|
||||
(
|
||||
SELECT MIN(`post_id`) = p.`post_id`
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = p.`topic_id`
|
||||
) AS `is_opening_post`
|
||||
FROM `msz_forum_posts` as p
|
||||
LEFT JOIN `msz_users` as u
|
||||
ON u.`user_id` = p.`user_id`
|
||||
|
|
|
@ -23,6 +23,22 @@ function forum_topic_create(int $forumId, int $userId, string $title): int
|
|||
return $createTopic->execute() ? (int)db_last_insert_id() : 0;
|
||||
}
|
||||
|
||||
function forum_topic_update(int $topicId, string $title): bool
|
||||
{
|
||||
if ($topicId < 1 || empty($title)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$updateTopic = db_prepare('
|
||||
UPDATE `msz_forum_topics`
|
||||
SET `topic_title` = :topic_title
|
||||
WHERE `topic_id` = :topic_id
|
||||
');
|
||||
$updateTopic->bindValue('topic_id', $topicId);
|
||||
$updateTopic->bindValue('topic_title', $title);
|
||||
return $updateTopic->execute();
|
||||
}
|
||||
|
||||
function forum_topic_fetch(int $topicId): array
|
||||
{
|
||||
$getTopic = db_prepare('
|
||||
|
|
|
@ -327,13 +327,12 @@
|
|||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro forum_post_listing(posts, opening_post_id, user_id, perms) %}
|
||||
{% macro forum_post_listing(posts, user_id, perms) %}
|
||||
{% from _self import forum_post_entry %}
|
||||
|
||||
{% for post in posts %}
|
||||
{{ forum_post_entry(
|
||||
post,
|
||||
post.post_id == opening_post_id,
|
||||
perms|perms_check(constant('MSZ_FORUM_PERM_CREATE_POST')),
|
||||
perms|perms_check(constant(user_id == post.poster_id ? 'MSZ_FORUM_PERM_EDIT_POST' : 'MSZ_FORUM_PERM_EDIT_ANY_POST')),
|
||||
perms|perms_check(constant(user_id == post.poster_id ? 'MSZ_FORUM_PERM_DELETE_POST' : 'MSZ_FORUM_PERM_DELETE_ANY_POST'))
|
||||
|
@ -341,7 +340,7 @@
|
|||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro forum_post_entry(post, is_original_post, can_post, can_edit, can_delete) %}
|
||||
{% macro forum_post_entry(post, can_post, can_edit, can_delete) %}
|
||||
{% set is_deleted = post.post_deleted is not null %}
|
||||
|
||||
<div class="container forum__post{% if is_deleted %} forum__post--deleted{% endif %}" id="p{{ post.post_id }}" style="{{ post.poster_colour|html_colour('--accent-colour') }}">
|
||||
|
|
|
@ -10,7 +10,22 @@
|
|||
{{ input_hidden('post[' ~ (is_reply ? 'topic' : 'forum') ~ ']', is_reply ? posting_topic.topic_id : posting_forum.forum_id) }}
|
||||
{{ input_hidden('post[mode]', posting_mode) }}
|
||||
{{ input_csrf('forum_post') }}
|
||||
{{ forum_header(is_reply ? posting_topic.topic_title : input_text('post[title]', 'forum__header__input', '', 'text', 'Enter your title here...'), posting_breadcrumbs, false, is_reply ? '/forum/topic.php?t=' ~ posting_topic.topic_id : '') }}
|
||||
{{ forum_header(
|
||||
is_reply and not posting_post.is_opening_post|default(false)
|
||||
? posting_topic.topic_title
|
||||
: input_text(
|
||||
'post[title]',
|
||||
'forum__header__input',
|
||||
posting_topic.topic_title|default(''),
|
||||
'text',
|
||||
'Enter your title here...'
|
||||
),
|
||||
posting_breadcrumbs,
|
||||
false,
|
||||
is_reply and not posting_post.is_opening_post|default(false)
|
||||
? '/forum/topic.php?t=' ~ posting_topic.topic_id
|
||||
: ''
|
||||
) }}
|
||||
|
||||
{% if posting_post is defined %}
|
||||
{{ input_hidden('post[id]', posting_post.post_id) }}
|
||||
|
|
|
@ -22,6 +22,6 @@
|
|||
{{ forum_header(topic_info.topic_title, topic_breadcrumbs) }}
|
||||
{{ forum_topic_locked(topic_info.topic_locked, topic_info.topic_archived) }}
|
||||
{{ topic_tools }}
|
||||
{{ forum_post_listing(topic_posts, topic_info.topic_first_post_id, current_user.user_id, topic_perms) }}
|
||||
{{ forum_post_listing(topic_posts, current_user.user_id, topic_perms) }}
|
||||
{{ topic_tools }}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Add table
Reference in a new issue