From f5f294bc9089e900ac44b4aa5714232a35de9e33 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 30 Dec 2021 20:38:16 +0200 Subject: [PATCH] init follow api --- src/application/controller/api/follow/add.php | 0 .../controller/api/follow/delete.php | 0 src/application/controller/api/follow/get.php | 0 .../controller/api/follow/total.php | 36 +++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 src/application/controller/api/follow/add.php create mode 100644 src/application/controller/api/follow/delete.php create mode 100644 src/application/controller/api/follow/get.php create mode 100644 src/application/controller/api/follow/total.php diff --git a/src/application/controller/api/follow/add.php b/src/application/controller/api/follow/add.php new file mode 100644 index 0000000..e69de29 diff --git a/src/application/controller/api/follow/delete.php b/src/application/controller/api/follow/delete.php new file mode 100644 index 0000000..e69de29 diff --git a/src/application/controller/api/follow/get.php b/src/application/controller/api/follow/get.php new file mode 100644 index 0000000..e69de29 diff --git a/src/application/controller/api/follow/total.php b/src/application/controller/api/follow/total.php new file mode 100644 index 0000000..bc2322f --- /dev/null +++ b/src/application/controller/api/follow/total.php @@ -0,0 +1,36 @@ + false, + 'message' => _('Internal server error'), + 'total' => 0 +]; + +if (isset($_SESSION['userName'])) { + + $userName = isset($_POST['userName']) ? $_POST['userName'] : $_SESSION['userName']; + + $followingUsersTotal = 0; + + foreach ((array) $_twister->getFollowing($_SESSION['userName']) as $followingUserName) { + $followingUsersTotal++; + } + + $response = [ + 'success' => true, + 'message' => _('Follow totals received'), + 'total' => $followingUsersTotal + ]; + +} else { + + $response = [ + 'success' => false, + 'message' => _('Session expired. Please, reload the page.'), + 'total' => 0 + ]; + +} + +header('Content-Type: application/json; charset=utf-8'); +echo json_encode($response); \ No newline at end of file