Fix sending and reading of own images

Fixes #12

Note, the homepage won't show older, incorrectly formatted sent images
main
Terence Eden 2024-03-04 15:43:21 +00:00
rodzic c8920dbde0
commit df7836d9fa
1 zmienionych plików z 24 dodań i 22 usunięć

Wyświetl plik

@ -567,14 +567,16 @@ HTML;
// Print the items in a list
foreach ( $messages_ordered as $published=>$message ) {
// Set up the common components
$object = $message["object"] ?? [];
// Received messages have an `object` which contains their data.
// Sent messages *are* their data
if ( isset( $message["object"] ) ) {
$object = $message["object"];
} else {
$object = $message;
}
if ( isset( $message["object"]["id"] ) ) {
$id = $message["object"]["id"];
$publishedHTML = "<a href=\"{$id}\">{$published}</a>";
} else if ( isset( $message["id"] ) ) {
$id = $message["id"];
if ( isset( $object["id"] ) ) {
$id = $object["id"];
$publishedHTML = "<a href=\"{$id}\">{$published}</a>";
} else {
$id = "";
@ -584,19 +586,18 @@ HTML;
$timeHTML = "<time datetime=\"{$published}\" class=\"u-url\" rel=\"bookmark\">{$publishedHTML}</time>";
// Get the actor who authored the message
if ( isset( $message["actor"] ) ) {
// Usually found in Inbox messages
if ( isset( $object["attributedTo"] ) ) {
$actor = $object["attributedTo"];
} else if ( isset( $message["actor"] ) ) {
// Usually found in Like and Announce 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
$actorArray = explode( "/", $actor );
$actorName = end( $actorArray );
$actorArray = explode( "/", $actor );
$actorName = end( $actorArray );
$actorServer = parse_url( $actor, PHP_URL_HOST );
$actorUsername = "@{$actorName}@{$actorServer}";
// Make i18n usernames readable and safe.
@ -669,8 +670,7 @@ HTML;
// Add any images
if ( isset( $object["attachment"] ) ) {
foreach ( $object["attachment"] as $attachment ) {
foreach ( $object["attachment"] as $attachment ) {
// Only use things which have a MIME Type set
if ( isset( $attachment["mediaType"] ) ) {
$mediaURl = $attachment["url"];
@ -718,12 +718,14 @@ HTML;
$messageHTML = "{$timeHTML} {$actorHTML} {$verb} {$replyTo}: <blockquote class=\"e-content\">{$content}</blockquote>";
}
} else if ( "Like" == $type ) {
$objectHTML = "<a href=\"$object\">{$object}</a>";
$messageHTML = "{$timeHTML} {$actorHTML} liked {$objectHTML}";
} else if ( "Follow" == $type ) {
$messageHTML = "<mark>{$timeHTML} {$actorHTML} followed you</mark>";
} else if ( "Like" == $type ) {
$object = $message["object"];
$objectHTML = "<a href=\"$object\">{$object}</a>";
$messageHTML = "{$timeHTML} {$actorHTML} liked {$objectHTML}";
} else if ( "Announce" == $type ) {
$object = $message["object"];
$objectHTML = "<a href=\"$object\">{$object}</a>";
$messageHTML = "{$timeHTML} {$actorHTML} boosted {$objectHTML}";
}
@ -910,12 +912,12 @@ HTML;
}
// Construct the attachment value for the post
$attachment = [
$attachment = array( [
"type" => "Image",
"mediaType" => "{$image_mime}",
"url" => "https://{$server}/{$image_full_path}",
"name" => $alt
];
] );
} else {
$attachment = [];
}
@ -1192,7 +1194,7 @@ HTML;
( filter_var( $url, FILTER_VALIDATE_URL) != true) ||
( parse_url( $url, PHP_URL_SCHEME ) != "https" )
) { die(); }
// Split the URL
$url_host = parse_url( $url, PHP_URL_HOST );
$url_path = parse_url( $url, PHP_URL_PATH );