From 57e70884743ceada2422345d16138d7b5aaedf77 Mon Sep 17 00:00:00 2001 From: Terence Eden Date: Sun, 18 Feb 2024 14:44:57 +0000 Subject: [PATCH] Add outbox --- index.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/index.php b/index.php index 87e9d0e..6133e66 100644 --- a/index.php +++ b/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();