From 15f66025592944829563dd55d537b641b189f308 Mon Sep 17 00:00:00 2001 From: Terence Eden Date: Thu, 29 Feb 2024 20:53:50 +0000 Subject: [PATCH] Show followers / following --- index.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 1a0cede..2543dce 100644 --- a/index.php +++ b/index.php @@ -191,35 +191,52 @@ // These JSON documents show how many users are following / followers-of this account. // The information here is self-attested. So you can lie and use any number you want. function following() { - global $server; + global $server, $directories; + + // Get all the files + $following_files = glob( $directories["following"] . "/*.json"); + // Number of posts + $totalItems = count( $following_files ); + + $items = array(); + foreach ( $following_files as $following_file ) { + $following = json_decode( file_get_contents( $following_file ),true ); + $items[] = $following["id"]; + } $following = array( "@context" => "https://www.w3.org/ns/activitystreams", "id" => "https://{$server}/following", "type" => "Collection", - "totalItems" => 0, - "items" => [] + "totalItems" => $totalItems, + "items" => $items ); header( "Content-Type: application/activity+json" ); echo json_encode( $following ); die(); } function followers() { - global $server; + global $server, $directories; // The number of followers is self-reported // You can set this to any number you like // Get all the files - $follower_files = glob("data/followers/*.json"); + $follower_files = glob( $directories["followers"] . "/*.json"); // Number of posts $totalItems = count( $follower_files ); + $items = array(); + foreach ( $follower_files as $follower_file ) { + $following = json_decode( file_get_contents( $follower_file ),true ); + $items[] = $following["id"]; + } + $followers = array( "@context" => "https://www.w3.org/ns/activitystreams", "id" => "https://{$server}/followers", "type" => "Collection", "totalItems" => $totalItems, - "items" => [] + "items" => $items ); header( "Content-Type: application/activity+json" ); echo json_encode( $followers );