|
|
|
@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
|
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
// Define default response |
|
|
|
|
$response = [ |
|
|
|
|
'success' => false, |
|
|
|
|
'message' => _('Internal server error'), |
|
|
|
@ -7,16 +8,20 @@ $response = [
@@ -7,16 +8,20 @@ $response = [
|
|
|
|
|
'page' => 0, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
// Authorization required |
|
|
|
|
if (isset($_SESSION['userName'])) { |
|
|
|
|
|
|
|
|
|
// Define page number |
|
|
|
|
$page = isset($_GET['page']) ? Filter::int($_GET['page']) : 1; |
|
|
|
|
|
|
|
|
|
$userNames = []; |
|
|
|
|
|
|
|
|
|
// Single user posts mode |
|
|
|
|
if (isset($_GET['userName']) && !empty($_GET['userName'])) { |
|
|
|
|
|
|
|
|
|
$userNames[] = Filter::userName($_GET['userName']); |
|
|
|
|
|
|
|
|
|
// Following feed by default (when userName attribute not provided) |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
foreach ((array) $_twister->getFollowing($_SESSION['userName']) as $followingUserName) { |
|
|
|
@ -25,6 +30,7 @@ if (isset($_SESSION['userName'])) {
@@ -25,6 +30,7 @@ if (isset($_SESSION['userName'])) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get posts from the node (pre-collected from DHT) |
|
|
|
|
if ($result = $_twister->getPosts($userNames, APPLICATION_MAX_POST_FEED * $page)) { |
|
|
|
|
|
|
|
|
|
$postsTotal = 0; |
|
|
|
@ -34,23 +40,26 @@ if (isset($_SESSION['userName'])) {
@@ -34,23 +40,26 @@ if (isset($_SESSION['userName'])) {
|
|
|
|
|
// Count posts |
|
|
|
|
$postsTotal++; |
|
|
|
|
|
|
|
|
|
// Process reTwists |
|
|
|
|
// Format reTwists |
|
|
|
|
$reTwist = []; |
|
|
|
|
if ($post['reTwist']) { |
|
|
|
|
if (isset($post['userpost']['rt'])) { |
|
|
|
|
|
|
|
|
|
$reTwist = [ |
|
|
|
|
'message' => Format::post($post['reTwist']['message']), |
|
|
|
|
'time' => Format::time($post['reTwist']['time']), |
|
|
|
|
'userName' => $post['reTwist']['userName'], |
|
|
|
|
'userName' => isset($post['userpost']['rt']['n']) ? $post['userpost']['rt']['n'] : false, |
|
|
|
|
'message' => Format::post((isset($post['userpost']['rt']['msg']) ? $post['userpost']['rt']['msg'] : false) . (isset($post['userpost']['rt']['msg2']) ? $post['userpost']['rt']['msg2'] : false)), |
|
|
|
|
'time' => Format::time((isset($post['userpost']['rt']['time']) ? $post['userpost']['rt']['time'] : false)), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Process posts |
|
|
|
|
// Format posts |
|
|
|
|
$posts[] = [ |
|
|
|
|
'message' => Format::post($post['message']), |
|
|
|
|
'time' => Format::time($post['time']), |
|
|
|
|
'userName' => $post['userName'], |
|
|
|
|
'userName' => isset($post['userpost']['n']) ? $post['userpost']['n'] : false, |
|
|
|
|
'message' => Format::post((isset($post['userpost']['msg']) ? $post['userpost']['msg'] : false) . (isset($post['userpost']['msg2']) ? $post['userpost']['msg2'] : false)), |
|
|
|
|
'time' => Format::time((isset($post['userpost']['time']) ? $post['userpost']['time'] : false)), |
|
|
|
|
|
|
|
|
|
'reTwist' => $reTwist, |
|
|
|
|
|
|
|
|
|
'meta' => base64_encode(json_encode($post)), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -58,6 +67,9 @@ if (isset($_SESSION['userName'])) {
@@ -58,6 +67,9 @@ if (isset($_SESSION['userName'])) {
|
|
|
|
|
'success' => true, |
|
|
|
|
'message' => _('Posts successfully loaded'), |
|
|
|
|
'posts' => $posts, |
|
|
|
|
|
|
|
|
|
// Increase page index for ajax pagination |
|
|
|
|
// (would be moved to JS, but next page button better to hide on empty results @TODO) |
|
|
|
|
'page' => $postsTotal == $page * APPLICATION_MAX_POST_FEED ? $page + 1 : 0 |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|