Show followers / following
rodzic
70404d1b12
commit
15f6602559
29
index.php
29
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 );
|
||||
|
|
Ładowanie…
Reference in New Issue