Changed internal parser selection value from integers to a string enum.
This commit is contained in:
parent
4d53565139
commit
d9f35594e7
32 changed files with 301 additions and 213 deletions
public-legacy
|
@ -4,7 +4,7 @@ namespace Misuzu;
|
|||
use stdClass;
|
||||
use RuntimeException;
|
||||
use Misuzu\Forum\{ForumCategoryInfo,ForumPostInfo,ForumTopicInfo};
|
||||
use Misuzu\Parsers\Parser;
|
||||
use Misuzu\Parsers\{Parsers,TextFormat};
|
||||
use Index\XDateTime;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
|
@ -19,8 +19,23 @@ $currentUserId = $currentUser->id;
|
|||
if($msz->usersCtx->hasActiveBan($currentUser))
|
||||
Template::throwError(403);
|
||||
|
||||
if(filter_has_var(INPUT_POST, 'preview')) {
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
||||
$text = (string)filter_input(INPUT_POST, 'text');
|
||||
$format = TextFormat::tryFrom((string)filter_input(INPUT_POST, 'format'));
|
||||
if($format === null) {
|
||||
http_response_code(400);
|
||||
return;
|
||||
}
|
||||
|
||||
http_response_code(200);
|
||||
echo Parsers::instance($format)->parseText(htmlspecialchars($text));
|
||||
return;
|
||||
}
|
||||
|
||||
$forumPostingModes = [
|
||||
'create', 'edit', 'quote', 'preview',
|
||||
'create', 'edit', 'quote',
|
||||
];
|
||||
|
||||
if(!empty($_POST)) {
|
||||
|
@ -38,22 +53,6 @@ if(!empty($_POST)) {
|
|||
if(!in_array($mode, $forumPostingModes, true))
|
||||
Template::throwError(400);
|
||||
|
||||
if($mode === 'preview') {
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
||||
$postText = (string)($_POST['post']['text']);
|
||||
$postParser = (int)($_POST['post']['parser']);
|
||||
|
||||
if(!Parser::isValid($postParser)) {
|
||||
http_response_code(400);
|
||||
return;
|
||||
}
|
||||
|
||||
http_response_code(200);
|
||||
echo Parser::instance($postParser)->parseText(htmlspecialchars($postText));
|
||||
return;
|
||||
}
|
||||
|
||||
if(empty($postId) && empty($topicId) && empty($forumId))
|
||||
Template::throwError(404);
|
||||
|
||||
|
@ -144,7 +143,7 @@ $notices = [];
|
|||
if(!empty($_POST)) {
|
||||
$topicTitle = $_POST['post']['title'] ?? '';
|
||||
$postText = $_POST['post']['text'] ?? '';
|
||||
$postParser = (int)($_POST['post']['parser'] ?? Parser::BBCODE);
|
||||
$postParser = TextFormat::tryFrom((string)($_POST['post']['parser'] ?? '')) ?? TextFormat::BBCode;
|
||||
$topicType = isset($_POST['post']['type']) ? $_POST['post']['type'] : null;
|
||||
$postSignature = isset($_POST['post']['signature']);
|
||||
|
||||
|
@ -192,9 +191,6 @@ if(!empty($_POST)) {
|
|||
}
|
||||
}
|
||||
|
||||
if(!Parser::isValid($postParser))
|
||||
$notices[] = 'Invalid parser selected.';
|
||||
|
||||
$postTextLengths = $cfg->getValues([
|
||||
['forum.post.minLength:i', 1],
|
||||
['forum.post.maxLength:i', 60000],
|
||||
|
@ -245,7 +241,7 @@ if(!empty($_POST)) {
|
|||
(string)$postId,
|
||||
remoteAddr: $_SERVER['REMOTE_ADDR'],
|
||||
body: $postText,
|
||||
bodyParser: $postParser,
|
||||
bodyFormat: $postParser,
|
||||
displaySignature: $postSignature,
|
||||
bumpEdited: $markUpdated
|
||||
);
|
||||
|
@ -294,9 +290,9 @@ if($mode === 'edit') { // $post is pretty much sure to be populated at this poin
|
|||
|
||||
try {
|
||||
$lastPostInfo = $msz->forumCtx->posts->getPost(userInfo: $currentUser, getLast: true, deleted: false);
|
||||
$selectedParser = $lastPostInfo->parser;
|
||||
$selectedParser = $lastPostInfo->bodyFormat;
|
||||
} catch(RuntimeException $ex) {
|
||||
$selectedParser = Parser::BBCODE;
|
||||
$selectedParser = TextFormat::BBCode;
|
||||
}
|
||||
|
||||
Template::render('forum.posting', [
|
||||
|
|
|
@ -5,7 +5,7 @@ use stdClass;
|
|||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Index\ByteFormat;
|
||||
use Misuzu\Parsers\Parser;
|
||||
use Misuzu\Parsers\TextFormat;
|
||||
use Misuzu\Users\{User,UsersContext};
|
||||
use Misuzu\Users\Assets\UserAvatarAsset;
|
||||
use Misuzu\Users\Assets\UserBackgroundAsset;
|
||||
|
@ -141,11 +141,11 @@ if($isEditing) {
|
|||
$notices[] = 'You\'re not allowed to edit your about page.';
|
||||
} else {
|
||||
$aboutText = (string)($_POST['about']['text'] ?? '');
|
||||
$aboutParse = (int)($_POST['about']['parser'] ?? Parser::PLAIN);
|
||||
$aboutParse = TextFormat::tryFrom((string)($_POST['about']['parser'] ?? '')) ?? TextFormat::Plain;
|
||||
$aboutValid = $msz->usersCtx->users->validateProfileAbout($aboutParse, $aboutText);
|
||||
|
||||
if($aboutValid === '')
|
||||
$msz->usersCtx->users->updateUser($userInfo, aboutBody: $aboutText, aboutBodyParser: $aboutParse);
|
||||
$msz->usersCtx->users->updateUser($userInfo, aboutBody: $aboutText, aboutBodyFormat: $aboutParse);
|
||||
else
|
||||
$notices[] = $msz->usersCtx->users->validateProfileAboutText($aboutValid);
|
||||
}
|
||||
|
@ -156,11 +156,11 @@ if($isEditing) {
|
|||
$notices[] = 'You\'re not allowed to edit your forum signature.';
|
||||
} else {
|
||||
$sigText = (string)($_POST['signature']['text'] ?? '');
|
||||
$sigParse = (int)($_POST['signature']['parser'] ?? Parser::PLAIN);
|
||||
$sigParse = TextFormat::tryFrom((string)($_POST['signature']['parser'] ?? '') ?? TextFormat::Plain;
|
||||
$sigValid = $msz->usersCtx->users->validateForumSignature($sigParse, $sigText);
|
||||
|
||||
if($sigValid === '')
|
||||
$msz->usersCtx->users->updateUser($userInfo, signatureBody: $sigText, signatureBodyParser: $sigParse);
|
||||
$msz->usersCtx->users->updateUser($userInfo, signatureBody: $sigText, signatureBodyFormat: $sigParse);
|
||||
else
|
||||
$notices[] = $msz->usersCtx->users->validateForumSignatureText($sigValid);
|
||||
}
|
||||
|
|
|
@ -133,12 +133,12 @@ if(isset($_POST['action']) && is_string($_POST['action'])) {
|
|||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'comments_categories', ['category_id:s', 'category_name:s', 'user_id:s:n', 'category_created:t', 'category_locked:t:n'], 'user_id');
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'comments_posts', ['comment_id:s', 'category_id:s', 'user_id:s:n', 'comment_reply_to:s:n', 'comment_text:s', 'comment_created:t', 'comment_pinned:t:n', 'comment_edited:t:n', 'comment_deleted:t:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'comments_votes', ['comment_id:s', 'user_id:s', 'comment_vote:i']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'forum_posts', ['post_id:s', 'topic_id:s', 'forum_id:s', 'user_id:s:n', 'post_remote_addr:a', 'post_text:s', 'post_parse:i', 'post_display_signature:b', 'post_created:t', 'post_edited:t:n', 'post_deleted:t:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'forum_posts', ['post_id:s', 'topic_id:s', 'forum_id:s', 'user_id:s:n', 'post_remote_addr:a', 'post_text:s', 'post_text_format:s', 'post_display_signature:b', 'post_created:t', 'post_edited:t:n', 'post_deleted:t:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'forum_topics', ['topic_id:s', 'forum_id:s', 'user_id:s:n', 'topic_type:i', 'topic_title:s', 'topic_count_views:i', 'topic_created:t', 'topic_bumped:t', 'topic_deleted:t:n', 'topic_locked:t:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'forum_topics_redirects', ['topic_id:s', 'user_id:s:n', 'redir_url:s', 'redir_created:t']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'forum_topics_track', ['user_id:s', 'topic_id:s', 'forum_id:s', 'track_last_read:t']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'login_attempts', ['attempt_id:s', 'user_id:s:n', 'attempt_success:b', 'attempt_remote_addr:a', 'attempt_country:s', 'attempt_created:t', 'attempt_user_agent:s']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'messages', ['msg_id:s', 'msg_owner_id:s', 'msg_author_id:s:n', 'msg_recipient_id:s:n', 'msg_reply_to:s:n', 'msg_title:s', 'msg_body:s', 'msg_parser:i', 'msg_created:t', 'msg_sent:t:n', 'msg_read:t:n', 'msg_deleted:t:n'], 'msg_owner_id');
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'messages', ['msg_id:s', 'msg_owner_id:s', 'msg_author_id:s:n', 'msg_recipient_id:s:n', 'msg_reply_to:s:n', 'msg_title:s', 'msg_body:s', 'msg_body_format:s', 'msg_created:t', 'msg_sent:t:n', 'msg_read:t:n', 'msg_deleted:t:n'], 'msg_owner_id');
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'news_posts', ['post_id:s', 'category_id:s', 'user_id:s:n', 'comment_section_id:s:n', 'post_featured:b', 'post_title:s', 'post_text:s', 'post_scheduled:t', 'post_created:t', 'post_updated:t', 'post_deleted:t:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'oauth2_access', ['acc_id:s', 'app_id:s', 'user_id:s:n', 'acc_token:n', 'acc_scope:s', 'acc_created:t', 'acc_expires:t']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'oauth2_authorise', ['auth_id:s', 'app_id:s', 'user_id:s', 'uri_id:s', 'auth_challenge_code:n', 'auth_challenge_method:s', 'auth_scope:s', 'auth_code:n', 'auth_created:t', 'auth_expires:t']);
|
||||
|
@ -148,7 +148,7 @@ if(isset($_POST['action']) && is_string($_POST['action'])) {
|
|||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'perms_calculated', ['user_id:s:n', 'forum_id:s:n', 'perms_category:s', 'perms_calculated:i']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'profile_fields_values', ['field_id:s', 'user_id:s', 'format_id:s', 'field_value:s']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'sessions', ['session_id:s', 'user_id:s', 'session_key:n', 'session_remote_addr_first:a', 'session_remote_addr_last:a:n', 'session_user_agent:s', 'session_country:s', 'session_expires:t', 'session_expires_bump:b', 'session_created:t', 'session_active:t:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users', ['user_id:s', 'user_name:s', 'user_password:n', 'user_email:s', 'user_remote_addr_first:a', 'user_remote_addr_last:a', 'user_super:b', 'user_country:s', 'user_colour:i:n', 'user_created:t', 'user_active:t:n', 'user_deleted:t:n', 'user_display_role_id:s:n', 'user_about_content:s:n', 'user_about_parser:i', 'user_signature_content:s:n', 'user_signature_parser:i', 'user_background_settings:i:n', 'user_title:s:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users', ['user_id:s', 'user_name:s', 'user_password:n', 'user_email:s', 'user_remote_addr_first:a', 'user_remote_addr_last:a', 'user_super:b', 'user_country:s', 'user_colour:i:n', 'user_created:t', 'user_active:t:n', 'user_deleted:t:n', 'user_display_role_id:s:n', 'user_about_content:s:n', 'user_about_content_format:s', 'user_signature_content:s:n', 'user_signature_content_format:s', 'user_background_settings:i:n', 'user_title:s:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users_bans', ['ban_id:s', 'user_id:s', 'mod_id:n', 'ban_severity:i', 'ban_reason_public:s', 'ban_reason_private:s', 'ban_created:t', 'ban_expires:t:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users_birthdates', ['user_id:s', 'birth_year:i:n', 'birth_month:i', 'birth_day:i']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users_password_resets', ['reset_id:s', 'user_id:s', 'reset_remote_addr:a', 'reset_requested:t', 'reset_code:n']);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue