From 9b1c494b03505928c17106d5c0b002ddd15b8e41 Mon Sep 17 00:00:00 2001 From: Terence Eden Date: Sun, 3 Mar 2024 14:39:12 +0000 Subject: [PATCH] Show follower/following count --- index.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 35c8036..a0ff7b2 100644 --- a/index.php +++ b/index.php @@ -484,6 +484,7 @@ global $username, $server, $realName, $summary, $directories; $rawUsername = rawurldecode( $username ); + // What sort of viewable page is this? switch ( $style ) { case "home": $h1 = "HomePage"; @@ -494,6 +495,13 @@ $directory = "inbox"; break; } + + // Counters for followers, following, and posts + $follower_files = glob( $directories["followers"] . "/*.json"); + $totalFollowers = count( $follower_files ); + $following_files = glob( $directories["following"] . "/*.json"); + $totalFollowing = count( $following_files ); + echo <<< HTML @@ -540,6 +548,7 @@ echo <<< HTML

{$summary}

+

Following: {$totalFollowing} | Followers: {$totalFollowers}

This software is licenced under AGPL 3.0.

This site is a basic ActivityPub server designed to be a lightweight educational tool.

@@ -587,12 +596,29 @@ HTML; if ( isset( $message["object"]["id"] ) ) { $id = $message["object"]["id"]; $timeHTML = ""; + } else if ( isset( $message["id"] ) ) { + $id = $message["id"]; + $timeHTML = ""; } else { $id = ""; $timeHTML = ""; } - $actor = $message["actor"]; - $actorName = end( explode("/", $actor ) ); + + // Get the actor who authored the message + if ( isset( $message["actor"] ) ) { + // Usually found in Inbox messages + $actor = $message["actor"]; + } else if ( isset( $message["attributedTo"] ) ) { + // Usually found in sent messages + $actor = $message["attributedTo"]; + } else { + // Should never happen! + $actor = "https://example.com/anonymous"; + } + // Assume that what comes after the final `/` in the URl is the name + $actorName = end( explode( "/", $actor ) ); + // Make i18n usernames readable and safe. + $actorName = htmlspecialchars( rawurldecode( $actorName ) ); $actorHTML = "@{$actorName}"; // What type of message is this?