Add outbox
rodzic
a1953bc7ac
commit
57e7088474
38
index.php
38
index.php
|
@ -91,6 +91,8 @@
|
|||
write(); // User interface for writing posts
|
||||
case "send": // API for posting content to the Fediverse
|
||||
send();
|
||||
case "outbox": // Optional. Dynamic.
|
||||
outbox();
|
||||
default:
|
||||
die();
|
||||
}
|
||||
|
@ -131,6 +133,7 @@
|
|||
"following" => "https://{$server}/following",
|
||||
"followers" => "https://{$server}/followers",
|
||||
"inbox" => "https://{$server}/inbox",
|
||||
"outbox" => "https://{$server}/outbox",
|
||||
"preferredUsername" => rawurldecode($username),
|
||||
"name" => "{$realName}",
|
||||
"summary" => "{$summary}",
|
||||
|
@ -570,6 +573,41 @@ HTML;
|
|||
];
|
||||
}
|
||||
|
||||
// The Outbox contains a date-ordered list (newest first) of all the user's posts
|
||||
// This is optional.
|
||||
function outbox() {
|
||||
global $server, $username;
|
||||
|
||||
// Get all posts
|
||||
$posts = array_reverse( glob("posts/" . "*.json") );
|
||||
// Number of posts
|
||||
$totalItems = count( $posts );
|
||||
// Create an ordered list
|
||||
$orderedItems = [];
|
||||
foreach ($posts as $post) {
|
||||
$orderedItems[] = array(
|
||||
"type" => "Create",
|
||||
"actor" => "https://{$server}/{$username}",
|
||||
"object" => "https://{$server}/{$post}"
|
||||
);
|
||||
}
|
||||
|
||||
// Create User's outbox
|
||||
$outbox = array(
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "https://{$server}/outbox",
|
||||
"type" => "OrderedCollection",
|
||||
"totalItems" => $totalItems,
|
||||
"summary" => "All the user's posts",
|
||||
"orderedItems" => $orderedItems
|
||||
);
|
||||
|
||||
// Render the page
|
||||
header( "Content-Type: application/activity+json" );
|
||||
echo json_encode( $outbox );
|
||||
die();
|
||||
}
|
||||
|
||||
// "One to stun, two to kill, three to make sure"
|
||||
die();
|
||||
die();
|
||||
|
|
Ładowanie…
Reference in New Issue