Add better interaction links

merge-requests/5/head
Terence Eden 2024-03-03 18:14:08 +00:00
rodzic 0f93c3fd71
commit 098e1a23e5
1 zmienionych plików z 51 dodań i 24 usunięć

Wyświetl plik

@ -636,10 +636,21 @@ HTML;
} }
// Assume that what comes after the final `/` in the URl is the name // 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. // Make i18n usernames readable and safe.
$actorName = htmlspecialchars( rawurldecode( $actorName ) ); $actorName = htmlspecialchars( rawurldecode( $actorName ) );
$actorHTML = "<a href=\"$actor\">@{$actorName}</a>"; $actorHTML = "<a href=\"$actor\">@{$actorName}</a>";
// Buttons to interact with a message.
// By default, just shows a "Follow User" button.
if ( "read" == $style ) {
$interactHTML = "<a href=\"/follow?account=$actorUsername\"></a> ";
} else {
$interactHTML = "";
}
// What type of message is this? // What type of message is this?
$type = $message["type"]; $type = $message["type"];
@ -716,13 +727,6 @@ HTML;
} }
} }
// Buttons to repost or favourite a message
if ( "read" == $style ) {
$interactHTML = "<a href=\"/write?announce=$id\">🔁</a> <a href=\"/write?like=$id\"></a>";
} else {
$interactHTML = "";
}
// What sort of message is this? // What sort of message is this?
switch ( $type ) { switch ( $type ) {
case "Create": case "Create":
@ -737,22 +741,29 @@ HTML;
break; break;
} }
// Add some interaction buttons
$interactHTML .= "<a href=\"/write?reply=$id\">↩️</a> " .
"<a href=\"/write?announce=$id\">🔁</a> " .
"<a href=\"/write?like=$id\"></a> ";
if ( $reply ) { if ( $reply ) {
// Highlight that this is a reply // Highlight that this is a reply
echo "<li><article class=\"h-entry\"><mark>{$timeHTML} {$actorHTML} {$verb}{$replyTo}:</mark> <blockquote class=\"e-content\">{$content}</blockquote>{$interactHTML}</article></li>"; $messageHTML = "<mark>{$timeHTML} {$actorHTML} {$verb} {$replyTo}:</mark> <blockquote class=\"e-content\">{$content}</blockquote>";
} else { } else {
echo "<li><article class=\"h-entry\">{$timeHTML} {$actorHTML} {$verb}{$replyTo}: <blockquote class=\"e-content\">{$content}</blockquote>{$interactHTML}</article></li>"; $messageHTML = "{$timeHTML} {$actorHTML} {$verb} {$replyTo}: <blockquote class=\"e-content\">{$content}</blockquote>";
} }
} else if ( "Like" == $type ) { } else if ( "Like" == $type ) {
$objectHTML = "<a href=\"$object\">{$object}</a>"; $objectHTML = "<a href=\"$object\">{$object}</a>";
echo "<li><article class=\"h-entry\">{$timeHTML} {$actorHTML} liked {$objectHTML}</article></li>"; $messageHTML = "{$timeHTML} {$actorHTML} liked {$objectHTML}";
} else if ( "Follow" == $type ) { } else if ( "Follow" == $type ) {
echo "<li><article class=\"h-entry\">{$timeHTML} {$actorHTML} followed you</article></li>"; $messageHTML = "<mark>{$timeHTML} {$actorHTML} followed you</mark>";
} else if ( "Announce" == $type ) { } else if ( "Announce" == $type ) {
$objectHTML = "<a href=\"$object\">{$object}</a>"; $objectHTML = "<a href=\"$object\">{$object}</a>";
echo "<li><article class=\"h-entry\">{$timeHTML} {$actorHTML} boosted {$objectHTML}</article></li>"; $messageHTML = "{$timeHTML} {$actorHTML} boosted {$objectHTML}";
} }
echo "<li><article class=\"h-entry\">{$messageHTML}<br>{$interactHTML}</article></li>";
} }
echo <<< HTML echo <<< HTML
</ul> </ul>
@ -778,6 +789,12 @@ die();
} else { } else {
$likeURl = ""; $likeURl = "";
} }
if ( isset( $_GET["reply"] ) && filter_var( $_GET["reply"], FILTER_VALIDATE_URL ) ) {
$replyURl = $_GET["reply"];
} else {
$replyURl = "";
}
echo <<< HTML echo <<< HTML
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en-GB"> <html lang="en-GB">
@ -796,7 +813,7 @@ echo <<< HTML
<label for="content">Your message:</label><br> <label for="content">Your message:</label><br>
<textarea id="content" name="content" rows="5" cols="32"></textarea><br> <textarea id="content" name="content" rows="5" cols="32"></textarea><br>
<label for="inReplyTo">Reply to URl:</label> <label for="inReplyTo">Reply to URl:</label>
<input type="url" name="inReplyTo" id="inReplyTo" size="32" /><br> <input type="url" name="inReplyTo" id="inReplyTo" size="32" value="{$replyURl}"><br>
<label for="image">Attach an image</label><br> <label for="image">Attach an image</label><br>
<input type="file" name="image" id="image" accept="image/*"><br> <input type="file" name="image" id="image" accept="image/*"><br>
<label for="alt">Alt Text</label> <label for="alt">Alt Text</label>
@ -862,22 +879,27 @@ HTML;
$guid = uuid(); $guid = uuid();
// Construct the Message // 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 = [ $message = [
"@context" => "https://www.w3.org/ns/activitystreams", "@context" => "https://www.w3.org/ns/activitystreams",
"id" => "https://{$server}/posts/{$guid}.json", "id" => "https://{$server}/posts/{$guid}.json",
"type" => $type, "type" => $type,
"actor" => "https://{$server}/{$username}", "actor" => "https://{$server}/{$username}",
"published"=> date( "c" ), "published"=> date( "c" ),
"to" => [ "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" "https://www.w3.org/ns/activitystreams#Public"
], ],
"cc" => [ "cc" => [
"https://{$server}/followers" "https://{$server}/followers"
], ])
"object" => $postURl );
]; }
// Construct the Note // Construct the Note
// This is for saving in the logs // This is for saving in the logs
@ -1157,6 +1179,11 @@ HTML;
// This creates a UI for the user to follow another user // This creates a UI for the user to follow another user
function follow() { function follow() {
if ( isset( $_GET["account"] ) ) {
$accountURl = htmlspecialchars( $_GET["account"] );
} else {
$announceURl = "";
}
echo <<< HTML echo <<< HTML
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en-GB"> <html lang="en-GB">
@ -1170,7 +1197,7 @@ HTML;
<body> <body>
<form action="/follow_user" method="post" enctype="multipart/form-data"> <form action="/follow_user" method="post" enctype="multipart/form-data">
<label for="user">User to follow</label> <label for="user">User to follow</label>
<input name="user" id="user" type="text" size="32" placeholder="@user@example.com" /><br> <input name="user" id="user" type="text" size="32" placeholder="@user@example.com" value="{$accountURl}"><br>
<label for="password">Password</label><br> <label for="password">Password</label><br>
<input name="password" id="password" type="password" size="32"><br> <input name="password" id="password" type="password" size="32"><br>
<input type="submit" value="Send Follow Request"> <input type="submit" value="Send Follow Request">