From 098e1a23e5a871be66ed2b309035a38f7cfe4674 Mon Sep 17 00:00:00 2001 From: Terence Eden Date: Sun, 3 Mar 2024 18:14:08 +0000 Subject: [PATCH] Add better interaction links --- index.php | 75 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/index.php b/index.php index 988d4aa..0ca1193 100644 --- a/index.php +++ b/index.php @@ -635,10 +635,21 @@ HTML; $actor = "https://example.com/anonymous"; } // Assume that what comes after the final `/` in the URl is the name - $actorName = end( explode( "/", $actor ) ); + $actorName = end( explode( "/", $actor ) ); + $actorServer = parse_url( $actor, PHP_URL_HOST ); + $actorUsername = "@{$actorName}@{$actorServer}"; + // Make i18n usernames readable and safe. $actorName = htmlspecialchars( rawurldecode( $actorName ) ); $actorHTML = "@{$actorName}"; + + // Buttons to interact with a message. + // By default, just shows a "Follow User" button. + if ( "read" == $style ) { + $interactHTML = "➕ "; + } else { + $interactHTML = ""; + } // What type of message is this? $type = $message["type"]; @@ -653,7 +664,7 @@ HTML; // Is this a reply to something? if ( isset( $object["inReplyTo"] ) ) { $replyToURl = $object["inReplyTo"]; - $replyTo = " in reply to $replyToURl"; + $replyTo = "in reply to $replyToURl"; } else { $replyTo = ""; } @@ -716,13 +727,6 @@ HTML; } } - // Buttons to repost or favourite a message - if ( "read" == $style ) { - $interactHTML = "🔁 ⚝"; - } else { - $interactHTML = ""; - } - // What sort of message is this? switch ( $type ) { case "Create": @@ -737,22 +741,29 @@ HTML; break; } + // Add some interaction buttons + $interactHTML .= "â†Šī¸ " . + "🔁 " . + "⚝ "; + if ( $reply ) { // Highlight that this is a reply - echo "
  • {$timeHTML} {$actorHTML} {$verb}{$replyTo}:
    {$content}
    {$interactHTML}
  • "; + $messageHTML = "{$timeHTML} {$actorHTML} {$verb} {$replyTo}:
    {$content}
    "; } else { - echo "
  • {$timeHTML} {$actorHTML} {$verb}{$replyTo}:
    {$content}
    {$interactHTML}
  • "; + $messageHTML = "{$timeHTML} {$actorHTML} {$verb} {$replyTo}:
    {$content}
    "; } } else if ( "Like" == $type ) { $objectHTML = "{$object}"; - echo "
  • {$timeHTML} {$actorHTML} liked {$objectHTML}
  • "; + $messageHTML = "{$timeHTML} {$actorHTML} liked {$objectHTML}"; } else if ( "Follow" == $type ) { - echo "
  • {$timeHTML} {$actorHTML} followed you
  • "; + $messageHTML = "{$timeHTML} {$actorHTML} followed you"; } else if ( "Announce" == $type ) { $objectHTML = "{$object}"; - echo "
  • {$timeHTML} {$actorHTML} boosted {$objectHTML}
  • "; + $messageHTML = "{$timeHTML} {$actorHTML} boosted {$objectHTML}"; } + + echo "
  • {$messageHTML}
    {$interactHTML}
  • "; } echo <<< HTML @@ -778,6 +789,12 @@ die(); } else { $likeURl = ""; } + + if ( isset( $_GET["reply"] ) && filter_var( $_GET["reply"], FILTER_VALIDATE_URL ) ) { + $replyURl = $_GET["reply"]; + } else { + $replyURl = ""; + } echo <<< HTML @@ -796,7 +813,7 @@ echo <<< HTML

    -
    +


    @@ -862,23 +879,28 @@ HTML; $guid = uuid(); // Construct the Message - // The audience is public and it is sent to all followers - // TODO: This will also need to be sent to the server of the user whose post it is $message = [ "@context" => "https://www.w3.org/ns/activitystreams", "id" => "https://{$server}/posts/{$guid}.json", "type" => $type, "actor" => "https://{$server}/{$username}", "published"=> date( "c" ), - "to" => [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc" => [ - "https://{$server}/followers" - ], "object" => $postURl ]; + // Annouces are sent to an audience + // The audience is public and it is sent to all followers + if ( $type == "Announce") { + $message = array_merge( $message, + array("to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://{$server}/followers" + ]) + ); + } + // Construct the Note // This is for saving in the logs $note = $message; @@ -1157,6 +1179,11 @@ HTML; // This creates a UI for the user to follow another user function follow() { + if ( isset( $_GET["account"] ) ) { + $accountURl = htmlspecialchars( $_GET["account"] ); + } else { + $announceURl = ""; + } echo <<< HTML @@ -1170,7 +1197,7 @@ HTML;
    -
    +