Added dropdown for selecting topic type in editor.
This commit is contained in:
parent
0d6b1be094
commit
8c7aad6d16
5 changed files with 74 additions and 30 deletions
|
@ -176,7 +176,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__parser {
|
&__dropdown {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,13 +47,7 @@ if (!empty($postId)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($topicId)) {
|
if (!empty($topicId)) {
|
||||||
$getTopic = db_prepare('
|
$topic = forum_topic_fetch($topicId);
|
||||||
SELECT `topic_id`, `forum_id`, `topic_title`, `topic_locked`
|
|
||||||
FROM `msz_forum_topics`
|
|
||||||
WHERE `topic_id` = :topic_id
|
|
||||||
');
|
|
||||||
$getTopic->bindValue('topic_id', $topicId);
|
|
||||||
$topic = $getTopic->execute() ? $getTopic->fetch(PDO::FETCH_ASSOC) : false;
|
|
||||||
|
|
||||||
if (isset($topic['forum_id'])) {
|
if (isset($topic['forum_id'])) {
|
||||||
$forumId = (int)$topic['forum_id'];
|
$forumId = (int)$topic['forum_id'];
|
||||||
|
@ -78,7 +72,7 @@ if (empty($forum)) {
|
||||||
$perms = forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $forum['forum_id'], user_session_current('user_id'));
|
$perms = forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $forum['forum_id'], user_session_current('user_id'));
|
||||||
|
|
||||||
if ($forum['forum_archived']
|
if ($forum['forum_archived']
|
||||||
|| !empty($topic['topic_locked'])
|
|| (!empty($topic['topic_locked']) && !perms_check($perms, MSZ_FORUM_PERM_LOCK_TOPIC))
|
||||||
|| !perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM | MSZ_FORUM_PERM_CREATE_POST)
|
|| !perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM | MSZ_FORUM_PERM_CREATE_POST)
|
||||||
|| (empty($topic) && !perms_check($perms, MSZ_FORUM_PERM_CREATE_TOPIC))) {
|
|| (empty($topic) && !perms_check($perms, MSZ_FORUM_PERM_CREATE_TOPIC))) {
|
||||||
echo render_error(403);
|
echo render_error(403);
|
||||||
|
@ -90,6 +84,22 @@ if (!forum_may_have_topics($forum['forum_type'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$topicTypes = [];
|
||||||
|
|
||||||
|
if ($mode === 'create' || $mode === 'edit') {
|
||||||
|
$topicTypes[MSZ_TOPIC_TYPE_DISCUSSION] = 'Normal discussion';
|
||||||
|
|
||||||
|
if (perms_check($perms, MSZ_FORUM_PERM_STICKY_TOPIC)) {
|
||||||
|
$topicTypes[MSZ_TOPIC_TYPE_STICKY] = 'Sticky topic';
|
||||||
|
}
|
||||||
|
if (perms_check($perms, MSZ_FORUM_PERM_ANNOUNCE_TOPIC)) {
|
||||||
|
$topicTypes[MSZ_TOPIC_TYPE_ANNOUNCEMENT] = 'Announcement';
|
||||||
|
}
|
||||||
|
if (perms_check($perms, MSZ_FORUM_PERM_GLOBAL_ANNOUNCE_TOPIC)) {
|
||||||
|
$topicTypes[MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT] = 'Global Announcement';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// edit mode stuff
|
// edit mode stuff
|
||||||
if ($mode === 'edit') {
|
if ($mode === 'edit') {
|
||||||
if (empty($post)) {
|
if (empty($post)) {
|
||||||
|
@ -109,8 +119,31 @@ if (!empty($_POST)) {
|
||||||
if (!csrf_verify('forum_post', $_POST['csrf'] ?? '')) {
|
if (!csrf_verify('forum_post', $_POST['csrf'] ?? '')) {
|
||||||
$notices[] = 'Could not verify request.';
|
$notices[] = 'Could not verify request.';
|
||||||
} else {
|
} else {
|
||||||
|
$isEditingTopic = empty($topic) || ($mode === 'edit' && $post['is_opening_post']);
|
||||||
|
|
||||||
|
if ($isEditingTopic) {
|
||||||
$topicTitle = $_POST['post']['title'] ?? '';
|
$topicTitle = $_POST['post']['title'] ?? '';
|
||||||
$setTopicTitle = empty($topic) || ($mode === 'edit' && $post['is_opening_post'] && $topicTitle !== $topic['topic_title']);
|
$originalTopicTitle = $topic['topic_title'] ?? null;
|
||||||
|
$topicTitleChanged = $topicTitle !== $originalTopicTitle;
|
||||||
|
$topicType = (int)($_POST['post']['type'] ?? array_key_first($topicTypes));
|
||||||
|
$originalTopicType = (int)($topic['topic_type'] ?? 0);
|
||||||
|
$topicTypeChanged = $topicType !== $originalTopicType;
|
||||||
|
|
||||||
|
switch (forum_validate_title($topicTitle)) {
|
||||||
|
case 'too-short':
|
||||||
|
$notices[] = 'Topic title was too short.';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'too-long':
|
||||||
|
$notices[] = 'Topic title was too long.';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists($topicType, $topicTypes) && $topicTypeChanged) {
|
||||||
|
$notices[] = 'You are not allowed to set this topic type.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$postText = $_POST['post']['text'] ?? '';
|
$postText = $_POST['post']['text'] ?? '';
|
||||||
$postParser = (int)($_POST['post']['parser'] ?? MSZ_PARSER_BBCODE);
|
$postParser = (int)($_POST['post']['parser'] ?? MSZ_PARSER_BBCODE);
|
||||||
|
|
||||||
|
@ -128,25 +161,18 @@ if (!empty($_POST)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($setTopicTitle) {
|
|
||||||
switch (forum_validate_title($topicTitle)) {
|
|
||||||
case 'too-short':
|
|
||||||
$notices[] = 'Topic title was too short.';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'too-long':
|
|
||||||
$notices[] = 'Topic title was too long.';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($notices)) {
|
if (empty($notices)) {
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
case 'create':
|
case 'create':
|
||||||
if (!empty($topic)) {
|
if (!empty($topic)) {
|
||||||
forum_topic_bump($topic['topic_id']);
|
forum_topic_bump($topic['topic_id']);
|
||||||
} else {
|
} else {
|
||||||
$topicId = forum_topic_create($forum['forum_id'], user_session_current('user_id', 0), $topicTitle);
|
$topicId = forum_topic_create(
|
||||||
|
$forum['forum_id'],
|
||||||
|
user_session_current('user_id', 0),
|
||||||
|
$topicTitle,
|
||||||
|
$topicType
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$postId = forum_post_create(
|
$postId = forum_post_create(
|
||||||
|
@ -165,8 +191,8 @@ if (!empty($_POST)) {
|
||||||
$notices[] = 'Post edit failed.';
|
$notices[] = 'Post edit failed.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($setTopicTitle) {
|
if ($isEditingTopic && ($topicTitleChanged || $topicTypeChanged)) {
|
||||||
if (!forum_topic_update($topicId, $topicTitle)) {
|
if (!forum_topic_update($topicId, $topicTitle, $topicType)) {
|
||||||
$notices[] = 'Topic update failed.';
|
$notices[] = 'Topic update failed.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,4 +235,5 @@ echo tpl_render('forum.posting', [
|
||||||
'posting_info' => $displayInfo,
|
'posting_info' => $displayInfo,
|
||||||
'posting_notices' => $notices,
|
'posting_notices' => $notices,
|
||||||
'posting_mode' => $mode,
|
'posting_mode' => $mode,
|
||||||
|
'posting_types' => $topicTypes,
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -58,7 +58,7 @@ function forum_topic_update(int $topicId, ?string $title, ?int $type = null): bo
|
||||||
|
|
||||||
$updateTopic = db_prepare('
|
$updateTopic = db_prepare('
|
||||||
UPDATE `msz_forum_topics`
|
UPDATE `msz_forum_topics`
|
||||||
SET `topic_title` = COALESCE(:topic_title, `topic_title`)
|
SET `topic_title` = COALESCE(:topic_title, `topic_title`),
|
||||||
`topic_type` = COALESCE(:topic_type, `topic_type`)
|
`topic_type` = COALESCE(:topic_type, `topic_type`)
|
||||||
WHERE `topic_id` = :topic_id
|
WHERE `topic_id` = :topic_id
|
||||||
');
|
');
|
||||||
|
|
|
@ -18,3 +18,16 @@ function array_apply(array $array, callable $func): array
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('array_key_first')) {
|
||||||
|
// https://secure.php.net/manual/en/function.array-key-first.php#123301
|
||||||
|
function array_key_first(array $array)
|
||||||
|
{
|
||||||
|
if (count($array)) {
|
||||||
|
reset($array);
|
||||||
|
return key($array);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
{% set title = 'Posting' %}
|
{% set title = 'Posting' %}
|
||||||
{% set is_reply = posting_topic is defined %}
|
{% set is_reply = posting_topic is defined %}
|
||||||
|
{% set is_opening = not is_reply or posting_post.is_opening_post|default(false) %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form method="post" action="/forum/posting.php">
|
<form method="post" action="/forum/posting.php">
|
||||||
|
@ -11,7 +12,7 @@
|
||||||
{{ input_hidden('post[mode]', posting_mode) }}
|
{{ input_hidden('post[mode]', posting_mode) }}
|
||||||
{{ input_csrf('forum_post') }}
|
{{ input_csrf('forum_post') }}
|
||||||
{{ forum_header(
|
{{ forum_header(
|
||||||
is_reply and not posting_post.is_opening_post|default(false)
|
is_reply and not is_opening
|
||||||
? posting_topic.topic_title
|
? posting_topic.topic_title
|
||||||
: input_text(
|
: input_text(
|
||||||
'post[title]',
|
'post[title]',
|
||||||
|
@ -22,7 +23,7 @@
|
||||||
),
|
),
|
||||||
posting_breadcrumbs,
|
posting_breadcrumbs,
|
||||||
false,
|
false,
|
||||||
is_reply and not posting_post.is_opening_post|default(false)
|
is_reply and not is_opening
|
||||||
? '/forum/topic.php?t=' ~ posting_topic.topic_id
|
? '/forum/topic.php?t=' ~ posting_topic.topic_id
|
||||||
: ''
|
: ''
|
||||||
) }}
|
) }}
|
||||||
|
@ -65,7 +66,10 @@
|
||||||
|
|
||||||
<div class="forum__post__options">
|
<div class="forum__post__options">
|
||||||
<div class="forum__post__settings">
|
<div class="forum__post__settings">
|
||||||
{{ input_select('post[parser]', constant('MSZ_PARSERS_NAMES'), posting_post.post_parse|default(constant('MSZ_PARSER_BBCODE')), null, null, null, 'forum__post__parser') }}
|
{{ input_select('post[parser]', constant('MSZ_PARSERS_NAMES'), posting_post.post_parse|default(constant('MSZ_PARSER_BBCODE')), null, null, null, 'forum__post__dropdown') }}
|
||||||
|
{% if is_opening and posting_types|length > 1 %}
|
||||||
|
{{ input_select('post[type]', posting_types, posting_topic.topic_type|default(posting_types|keys|first), null, null, null, 'forum__post__dropdown') }}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="forum__post__buttons">
|
<div class="forum__post__buttons">
|
||||||
|
|
Loading…
Add table
Reference in a new issue