Browse Source

upgrade getPosts request receiving

main
ghost 3 years ago
parent
commit
78bf342221
  1. 40
      src/application/controller/api/post/get.php
  2. 73
      src/system/twister.php

40
src/application/controller/api/post/get.php

@ -27,46 +27,22 @@ if (isset($_SESSION['userName'])) {
$posts = []; $posts = [];
foreach ($result as $post) { 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 // Process reTwists
$reTwist = []; $reTwist = [];
if (isset($post['userpost']['rt'])) { if ($post['reTwist']) {
// 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]);
}
}
$reTwist = [ $reTwist = [
'message' => Format::post(implode('', $reTwists)), 'message' => Format::post($post['reTwist']['message']),
'time' => Format::time(Filter::int($post['userpost']['rt']['time'])), 'time' => Format::time($post['reTwist']['time']),
'userName' => Filter::userName($post['userpost']['rt']['n']), 'userName' => $post['reTwist']['userName'],
'reTwist' => $reTwist,
]; ];
} }
// Process posts
$posts[] = [ $posts[] = [
'message' => Format::post(implode('', $messages)), 'message' => Format::post($post['message']),
'time' => Format::time(Filter::int($post['userpost']['time'])), 'time' => Format::time($post['time']),
'userName' => Filter::userName($post['userpost']['n']), 'userName' => $post['userName'],
'reTwist' => $reTwist, 'reTwist' => $reTwist,
]; ];
} }

73
src/system/twister.php

@ -135,13 +135,84 @@ class Twister {
if ($response = $this->_curl->execute()) { if ($response = $this->_curl->execute()) {
$messages = [];
if ($response['error']) { if ($response['error']) {
$this->_error = _($response['error']['message']); $this->_error = _($response['error']['message']);
} else { } 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
} }
} }

Loading…
Cancel
Save