Add better interaction links
rodzic
0f93c3fd71
commit
098e1a23e5
75
index.php
75
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 = "<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?
|
||||
$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 <a href=\"{$replyToURl}\">$replyToURl</a>";
|
||||
$replyTo = "in reply to <a href=\"{$replyToURl}\">$replyToURl</a>";
|
||||
} else {
|
||||
$replyTo = "";
|
||||
}
|
||||
|
@ -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?
|
||||
switch ( $type ) {
|
||||
case "Create":
|
||||
|
@ -737,22 +741,29 @@ HTML;
|
|||
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 ) {
|
||||
// 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 {
|
||||
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 ) {
|
||||
$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 ) {
|
||||
echo "<li><article class=\"h-entry\">{$timeHTML} {$actorHTML} followed you</article></li>";
|
||||
$messageHTML = "<mark>{$timeHTML} {$actorHTML} followed you</mark>";
|
||||
} else if ( "Announce" == $type ) {
|
||||
$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
|
||||
</ul>
|
||||
|
@ -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
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-GB">
|
||||
|
@ -796,7 +813,7 @@ echo <<< HTML
|
|||
<label for="content">Your message:</label><br>
|
||||
<textarea id="content" name="content" rows="5" cols="32"></textarea><br>
|
||||
<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>
|
||||
<input type="file" name="image" id="image" accept="image/*"><br>
|
||||
<label for="alt">Alt Text</label>
|
||||
|
@ -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
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-GB">
|
||||
|
@ -1170,7 +1197,7 @@ HTML;
|
|||
<body>
|
||||
<form action="/follow_user" method="post" enctype="multipart/form-data">
|
||||
<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>
|
||||
<input name="password" id="password" type="password" size="32"><br>
|
||||
<input type="submit" value="Send Follow Request">
|
||||
|
|
Ładowanie…
Reference in New Issue