From e4244e53e336c654d6f4301ff4a4c6bc955a5e36 Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 4 Jan 2022 17:49:55 +0200 Subject: [PATCH] update post sending conditions --- src/application/controller/api/post/add.php | 15 +++++---------- src/system/helper/valid.php | 15 --------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/application/controller/api/post/add.php b/src/application/controller/api/post/add.php index 0a9609a..875d2ba 100644 --- a/src/application/controller/api/post/add.php +++ b/src/application/controller/api/post/add.php @@ -7,22 +7,17 @@ $response = [ if (isset($_SESSION['userName'])) { - if (!isset($_POST['message']) || (isset($_POST['message']) && !Valid::userPost($_POST['message']))) { + if (!$userPosts = $_twister->getPosts([$_SESSION['userName']], 1)) { $response = [ 'success' => false, - 'message' => _('Post message must contain from 1 to 140 chars') - ]; - - } else if (!$userPosts = $_twister->getPosts([$_SESSION['userName']], 1)) { - - $response = [ - 'success' => false, - 'message' => _('Could not receive user post') + 'message' => _('Could not receive last user post') ]; } else if (isset($userPosts[0]['userpost']['k']) && - $result = $_twister->newPostMessage($_SESSION['userName'], Filter::int($userPosts[0]['userpost']['k']) + 1, $_POST['message'])) { + $result = $_twister->newPostMessage($_SESSION['userName'], + Filter::int($userPosts[0]['userpost']['k']) + 1, + Filter::post($_POST['message']))) { $response = [ 'success' => true, diff --git a/src/system/helper/valid.php b/src/system/helper/valid.php index fa96b19..24fabc2 100644 --- a/src/system/helper/valid.php +++ b/src/system/helper/valid.php @@ -2,21 +2,6 @@ class Valid { - public static function userPost(string $userPost) { - - $length = mb_strlen($userPost); - - if ($length < 1 || $length > 140) { - - return false; - - } else { - - return true; - - } - } - public static function base64(string $string) { if (base64_encode(base64_decode($string, true)) === $string) {