diff --git a/src/application/controller/api/post/get.php b/src/application/controller/api/post/get.php index 543dfda..f1933d6 100644 --- a/src/application/controller/api/post/get.php +++ b/src/application/controller/api/post/get.php @@ -27,46 +27,22 @@ if (isset($_SESSION['userName'])) { $posts = []; foreach ($result as $post) { - // Split message parts - $messages = [Filter::post($post['userpost']['msg'])]; - - for ($i = 0; $i <= APPLICATION_MAX_POST_SPLIT; $i++) { - - $n = sprintf('msg%s', $i); - - if (isset($post['userpost'][$n])) { - $messages[] = Filter::post($post['userpost'][$n]); - } - } - // Process reTwists $reTwist = []; - if (isset($post['userpost']['rt'])) { - - // Split reTwists parts - $reTwists = [Filter::post($post['userpost']['rt']['msg'])]; - - for ($i = 0; $i <= APPLICATION_MAX_POST_SPLIT; $i++) { - - $n = sprintf('msg%s', $i); - - if (isset($post['userpost']['rt'][$n])) { - $reTwists[] = Filter::post($post['userpost']['rt'][$n]); - } - } + if ($post['reTwist']) { $reTwist = [ - 'message' => Format::post(implode('', $reTwists)), - 'time' => Format::time(Filter::int($post['userpost']['rt']['time'])), - 'userName' => Filter::userName($post['userpost']['rt']['n']), - 'reTwist' => $reTwist, + 'message' => Format::post($post['reTwist']['message']), + 'time' => Format::time($post['reTwist']['time']), + 'userName' => $post['reTwist']['userName'], ]; } + // Process posts $posts[] = [ - 'message' => Format::post(implode('', $messages)), - 'time' => Format::time(Filter::int($post['userpost']['time'])), - 'userName' => Filter::userName($post['userpost']['n']), + 'message' => Format::post($post['message']), + 'time' => Format::time($post['time']), + 'userName' => $post['userName'], 'reTwist' => $reTwist, ]; } diff --git a/src/system/twister.php b/src/system/twister.php index 8286458..353ff14 100644 --- a/src/system/twister.php +++ b/src/system/twister.php @@ -135,13 +135,84 @@ class Twister { if ($response = $this->_curl->execute()) { + $messages = []; + if ($response['error']) { $this->_error = _($response['error']['message']); } else { - return $response['result']; // Array + // Format response + if (isset($response['result'])) { + + foreach ($response['result'] as $message) { + + if (isset($message['userpost']['height']) && + isset($message['userpost']['k']) && + isset($message['userpost']['time']) && + isset($message['userpost']['n']) && + isset($message['userpost']['msg'])) { + + // Process reTwist if exist + $reTwist = []; + if (isset($message['userpost']['rt']) && + + isset($message['userpost']['rt']['height']) && + isset($message['userpost']['rt']['k']) && + isset($message['userpost']['rt']['time']) && + isset($message['userpost']['rt']['msg']) && + isset($message['userpost']['rt']['n'])) { + + // Split reTwist parts + $reTwists = [Filter::post($message['userpost']['rt']['msg'])]; + + for ($i = 0; $i <= APPLICATION_MAX_POST_SPLIT; $i++) { + + $n = sprintf('msg%s', $i); + + if (isset($message['userpost']['rt'][$n])) { + $reTwists[] = Filter::post($message['userpost']['rt'][$n]); + } + } + + $reTwist = [ + 'height' => Filter::int($message['userpost']['rt']['height']), + 'k' => Filter::int($message['userpost']['rt']['k']), + 'time' => Filter::int($message['userpost']['rt']['time']), + + 'userName' => Filter::userName($message['userpost']['rt']['n']), + 'message' => implode('', $reTwists), + ]; + } + + // Split message parts + $messageParts = [Filter::post($message['userpost']['msg'])]; + + for ($i = 0; $i <= APPLICATION_MAX_POST_SPLIT; $i++) { + + $n = sprintf('msg%s', $i); + + if (isset($message['userpost'][$n])) { + $messageParts[] = Filter::post($message['userpost'][$n]); + } + } + + $messages[] = [ + 'height' => Filter::int($message['userpost']['height']), + 'k' => Filter::int($message['userpost']['k']), + 'time' => Filter::int($message['userpost']['time']), + + 'userName' => Filter::userName($message['userpost']['n']), + 'message' => implode('', $messageParts), + + 'reTwist' => $reTwist + ]; + } + } + } + + return $messages; // Array } }