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.
|
// 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.
|
// The information here is self-attested. So you can lie and use any number you want.
|
||||||
function following() {
|
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(
|
$following = array(
|
||||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||||
"id" => "https://{$server}/following",
|
"id" => "https://{$server}/following",
|
||||||
"type" => "Collection",
|
"type" => "Collection",
|
||||||
"totalItems" => 0,
|
"totalItems" => $totalItems,
|
||||||
"items" => []
|
"items" => $items
|
||||||
);
|
);
|
||||||
header( "Content-Type: application/activity+json" );
|
header( "Content-Type: application/activity+json" );
|
||||||
echo json_encode( $following );
|
echo json_encode( $following );
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
function followers() {
|
function followers() {
|
||||||
global $server;
|
global $server, $directories;
|
||||||
// The number of followers is self-reported
|
// The number of followers is self-reported
|
||||||
// You can set this to any number you like
|
// You can set this to any number you like
|
||||||
|
|
||||||
// Get all the files
|
// Get all the files
|
||||||
$follower_files = glob("data/followers/*.json");
|
$follower_files = glob( $directories["followers"] . "/*.json");
|
||||||
// Number of posts
|
// Number of posts
|
||||||
$totalItems = count( $follower_files );
|
$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(
|
$followers = array(
|
||||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||||
"id" => "https://{$server}/followers",
|
"id" => "https://{$server}/followers",
|
||||||
"type" => "Collection",
|
"type" => "Collection",
|
||||||
"totalItems" => $totalItems,
|
"totalItems" => $totalItems,
|
||||||
"items" => []
|
"items" => $items
|
||||||
);
|
);
|
||||||
header( "Content-Type: application/activity+json" );
|
header( "Content-Type: application/activity+json" );
|
||||||
echo json_encode( $followers );
|
echo json_encode( $followers );
|
||||||
|
|
Ładowanie…
Reference in New Issue