diff --git a/app/Controllers/Forum/PostController.php b/app/Controllers/Forum/PostController.php index cdb103f..9698c7c 100644 --- a/app/Controllers/Forum/PostController.php +++ b/app/Controllers/Forum/PostController.php @@ -134,27 +134,25 @@ class PostController extends Controller || $titleTooLong || $textTooShort || $textTooLong) { - $message = ""; + $error = ""; if ($titleTooShort) { - $message = "This title is too short!"; + $error = "This title is too short!"; } elseif ($titleTooLong) { - $message = "This title is too long!"; + $error = "This title is too long!"; } elseif ($textTooShort) { - $message = "Please make your post a little bit longer!"; + $error = "Please make your post a little bit longer!"; } elseif ($textTooLong) { - $message = "Your post is too long, you're gonna have to cut a little!"; + $error = "Your post is too long, you're gonna have to cut a little!"; } - $redirect = route('forums.post', $post->id); - if (!isset($_SESSION['replyText'])) { $_SESSION['replyText'] = []; } $_SESSION['replyText']["t{$forum->id}"] = $text; - return view('global/information', compact('message', 'redirect')); + return $this->json(compact('error')); } unset($_SESSION['replyText']["t{$forum->id}"]); @@ -174,9 +172,11 @@ class PostController extends Controller $post->editUser = CurrentSession::$user; $post = $post->update(); - $postLink = route('forums.post', $post->id); - - return redirect($postLink); + return $this->json([ + 'id' => $post->id, + 'title' => $post->subject, + 'text' => $post->parsed, + ]); } /** diff --git a/app/Controllers/Forum/TopicController.php b/app/Controllers/Forum/TopicController.php index bf5b7f5..7a05645 100644 --- a/app/Controllers/Forum/TopicController.php +++ b/app/Controllers/Forum/TopicController.php @@ -201,65 +201,41 @@ class TopicController extends Controller { $text = $_POST['text'] ?? null; - // Attempt to get the forum $topic = new Topic($id); - - // And attempt to get the forum $forum = new Forum($topic->forum); - // Check if the topic exists - if ($topic->id === 0 + if (!session_check() + || $topic->id === 0 || $forum->type !== 0 || !$forum->perms->view) { - $message = "This post doesn't exist or you don't have access to it!"; - $redirect = route('forums.index'); - - return view('global/information', compact('message', 'redirect')); + return $this->json(['error' => "This post doesn't exist or you don't have access to it!"]); } - // Check if the topic exists if (!$forum->perms->reply || ( $topic->status === 1 && !$forum->perms->changeStatus )) { - $message = "You are not allowed to post in this topic!"; - $redirect = route('forums.topic', $topic->id); - - return view('global/information', compact('message', 'redirect')); + return $this->json(['error' => "You are not allowed to post in this topic!"]); } - // Length $length = strlen($text); $minLen = config('forum.min_post_length'); $maxLen = config('forum.max_post_length'); $tooShort = $length < $minLen; $tooLong = $length > $maxLen; - // Check requirments if ($tooShort || $tooLong) { - $route = route('forums.topic', $topic->id); - - $message = "Your post is " . ( - $tooShort - ? "too short, add some more text! Make it at least {$minLen}." - : "too long, you're gonna have to cut a little! Keep it under {$maxLen}." - ); - $redirect = "{$route}#reply"; - - if (!isset($_SESSION['replyText'])) { - $_SESSION['replyText'] = []; - } - - $_SESSION['replyText']["t{$topic->id}"] = $text; - - return view('global/information', compact('message', 'redirect')); + return $this->json([ + 'error' => "Your post is " . ( + $tooShort + ? "too short, add some more text! Make it at least {$minLen}." + : "too long, you're gonna have to cut a little! Keep it under {$maxLen}." + ) + ]); } - unset($_SESSION['replyText']["t{$topic->id}"]); - - // Create the post $post = Post::create( "Re: {$topic->title}", $text, @@ -268,16 +244,13 @@ class TopicController extends Controller $forum->id ); - // Go to the post - $postLink = route('forums.post', $post->id); - - // Head to the post - return redirect($postLink); + return $this->json(['error' => null, 'go' => route('forums.post', $post->id)]); } /** * Create a topic. * @param int $id + * @throws HttpMethodNotAllowedException * @return string */ public function create(int $id = 0): string @@ -294,14 +267,18 @@ class TopicController extends Controller || !$forum->perms->view || !$forum->perms->reply || !$forum->perms->topicCreate) { - $message = "This forum doesn't exist or you don't have access to it!"; - $redirect = route('forums.index'); - - return view('global/information', compact('message', 'redirect')); + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + return $this->json(['error' => "This forum doesn't exist or you don't have access to it!"]); + } else { + throw new HttpMethodNotAllowedException; + } } - if ($text && $title) { - // Length + if ($text !== null && $title !== null) { + if (!session_check()) { + return $this->json(['error' => 'Your session expired, please refresh!']); + } + $titleLength = strlen($title); $textLength = strlen($text); $titleMin = config('forum.min_title_length'); @@ -309,45 +286,33 @@ class TopicController extends Controller $textMin = config('forum.min_post_length'); $textMax = config('forum.max_post_length'); - // Checks $titleTooShort = $titleLength < $titleMin; $titleTooLong = $titleLength > $titleMax; $textTooShort = $textLength < $textMin; $textTooLong = $textLength > $textMax; - // Check requirments if ($titleTooShort || $titleTooLong || $textTooShort || $textTooLong) { - $message = ""; + $error = ""; if ($titleTooShort) { - $message = "This title is too short, it has to be longer than {$titleMin} characters!"; + $error = "This title is too short, it has to be longer than {$titleMin} characters!"; } elseif ($titleTooLong) { - $message = "This title is too long, keep it under {$titleMax} characters!"; + $error = "This title is too long, keep it under {$titleMax} characters!"; } elseif ($textTooShort) { - $message = "Please make your post a little bit longer, at least {$textMin} characters!"; + $error = "Please make your post a little bit longer, at least {$textMin} characters!"; } elseif ($textTooLong) { - $message = "Your post is too long, you're gonna have to cut a little!" + $error = "Your post is too long, you're gonna have to cut a little!" . " Can't be more than {$textMax} characters."; } - $redirect = route('forums.new', $forum->id); - - if (!isset($_SESSION['replyText'])) { - $_SESSION['replyText'] = []; - } - - $_SESSION['replyText']["f{$forum->id}"]["title"] = $title; - $_SESSION['replyText']["f{$forum->id}"]["text"] = $text; - - return view('global/information', compact('message', 'redirect')); + return $this->json(compact('error')); } unset($_SESSION['replyText']["f{$forum->id}"]); - // Create the post $post = Post::create( $title, $text, @@ -356,11 +321,7 @@ class TopicController extends Controller $forum->id ); - // Go to the post - $postLink = route('forums.post', $post->id); - - // Head to the post - return redirect($postLink); + return $this->json(['error' => null, 'go' => route('forums.post', $post->id)]); } return view('forum/topic', compact('forum')); diff --git a/resources/assets/less/yuuno/bem/post.less b/resources/assets/less/yuuno/bem/post.less index 0b8b3ed..1a111d9 100644 --- a/resources/assets/less/yuuno/bem/post.less +++ b/resources/assets/less/yuuno/bem/post.less @@ -30,10 +30,6 @@ height: 150px; margin: 5px auto; - &--online { - box-shadow: 0 3px 7px #484; - } - @media (max-width: 768px) { width: 100px; height: 100px; diff --git a/resources/views/yuuno/forum/elements/replyForm.twig b/resources/views/yuuno/forum/elements/replyForm.twig index 1aa278e..5a4690d 100644 --- a/resources/views/yuuno/forum/elements/replyForm.twig +++ b/resources/views/yuuno/forum/elements/replyForm.twig @@ -14,12 +14,13 @@ } %}
-
-