Add banner and additional formatting to home timeline

main
Jeff Sikes 2024-03-02 22:49:10 +00:00 zatwierdzone przez Terence Eden
rodzic ce30c1d378
commit 2878959e3d
2 zmienionych plików z 80 dodań i 45 usunięć

BIN
banner.png 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 126 KiB

125
index.php
Wyświetl plik

@ -191,6 +191,11 @@
"mediaType" => "image/png",
"url" => "https://{$server}/icon.png"
],
"image" => [
"type" => "Image",
"mediaType" => "image/png",
"url" => "https://{$server}/banner.png"
],
"publicKey" => [
"id" => "https://{$server}/{$username}#main-key",
"owner" => "https://{$server}/{$username}",
@ -477,55 +482,85 @@
function home() {
global $username, $server, $realName, $summary, $directories;
echo <<< HTML
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="UTF-8">
<title>{$realName}</title>
<style>
body { text-align: center; font-family:sans-serif; font-size:1.1em; }
ul { text-align: left; }
img { max-width: 50%; }
</style>
</head>
<body>
<span class="h-card">
<img src="icon.png" alt="icon" class="u-photo " width="140px" />
<h1><span class="p-name">{$realName}</span></h1>
<h2><a class="p-nickname u-url" href="https://{$server}/{$username}">@{$username}@{$server}</a></h2>
<p class="note">{$summary}</p>
</span>
<p><a href="https://gitlab.com/edent/activitypub-single-php-file/">This software is licenced under AGPL 3.0</a>.</p>
<p>This site is a basic <a href="https://www.w3.org/TR/activitypub/">ActivityPub</a> server designed to be <a href="https://shkspr.mobi/blog/2024/02/activitypub-server-in-a-single-file/">a lightweight educational tool</a>.</p>
<ul>
HTML;
// Get all posts, most recent first
$posts = array_reverse( glob( $directories["posts"] . "/*.json") );
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:url" content="https://{$server}">
<meta property="og:type" content="website">
<meta property="og:title" content="{$realName}">
<meta property="og:description" content="{$summary}">
<meta property="og:image" content="https://{$server}/banner.png">
<title>{$realName}</title>
<style>
body { margin:0; padding: 0; font-family:sans-serif; }
@media screen and (max-width: 800px) { body { width: 100%; }}
@media screen and (min-width: 799px) { body { width: 800px; margin: 0 auto; }}
img { max-width: 50%; }
.h-feed { margin:auto; width: 100%; }
.h-feed > .header { text-align: center; margin: 0 auto; }
.h-feed .banner { text-align: center; margin:0 auto; max-width: 650px; }
.h-feed > h1, .h-feed > h2 { margin-top: 10px; margin-bottom: 0; }
.h-feed > .header > h1:has(span.p-author), h2:has(a.p-nickname) { word-break: break-all; max-width: 90%; padding-left:20px; }
.h-feed .u-feature:first-child { margin-top: 10px; margin-bottom: -150px; max-width: 100%;}
.h-feed .u-photo { max-height: 8vw; max-width:100%; min-height: 120px; }
.h-feed .about { font-size: smaller; background-color: #F5F5F5; padding: 10px; border-top: dotted 1px #808080; border-bottom: dotted 1px #808080; }
.h-feed > ul { padding-left: 0; list-style-type: none; }
.h-feed > ul > li { padding: 10px; border-bottom: dotted 1px #808080; }
.h-entry { padding-right: 10px; }
.h-entry time.dt-published { font-weight: bold; }
.h-entry .e-content a { word-break: break-all; }
</style>
</head>
<body>
<div class="h-feed">
<div class="header">
<div class="banner">
<img src="banner.png" alt="banner" class="u-feature " /><br/>
<img src="icon.png" alt="icon" class="u-photo " />
</div>
<address>
<h1><span class="p-name p-author">{$realName}</span></h1>
<h2><a class="p-nickname u-url" rel="author" href="https://{$server}/{$username}">@{$username}@{$server}</a></h2>
</address>
<p class="p-summary">{$summary}</p>
<div class="about">
<p><a href="https://gitlab.com/edent/activitypub-single-php-file/">This software is licenced under AGPL 3.0</a>.</p>
<p>This site is a basic <a href="https://www.w3.org/TR/activitypub/">ActivityPub</a> server designed to be <a href="https://shkspr.mobi/blog/2024/02/activitypub-server-in-a-single-file/">a lightweight educational tool</a>.</p>
</div>
</div>
<ul>
HTML;
// Get all posts, most recent first
$posts = array_reverse( glob( $directories["posts"] . "/*.json") );
// Loop through the posts
foreach ($posts as $post) {
// Get the contents of the file
$postJSON = file_get_contents($post);
$postData = json_decode($postJSON, true);
// Loop through the posts
foreach ($posts as $post) {
// Get the contents of the file
$postJSON = file_get_contents($post);
$postData = json_decode($postJSON, true);
// Set up some common variables
$postTime = $postData["published"];
$postHTML = $postData["content"];
// Set up some common variables
$postTime = $postData["published"];
$postHTML = $postData["content"];
// If the message has an image attached, display it.
if ( isset($postData["attachment"]) ) {
$postImgUrl = $postData["attachment"]["url"];
$postImgAlt = $postData["attachment"]["name"];
$postImg = "<img src='{$postImgUrl}' alt='$postImgAlt'>";
} else {
$postImg = "";
// If the message has an image attached, display it.
if ( isset($postData["attachment"]["url"]) ) {
$postImgUrl = $postData["attachment"]["url"];
$postImgAlt = $postData["attachment"]["name"];
$postImg = "<br/><img class='u-photo' src='{$postImgUrl}' alt='$postImgAlt'>";
} else {
$postImg = "";
}
// Display the post
echo "<li><article class='h-entry'><a class='u-url' rel='bookmark' href='/{$post}'><time class='dt-published' datetime='{$postTime}'>$postTime</time></a><br><span class='e-content'>{$postHTML}{$postImg}</span></article></li>";
}
// Display the post
echo "<li><a href='/{$post}'><time datetime='{$postTime}'>$postTime</time></a><br>{$postHTML}<br>{$postImg}</li>";
}
echo <<< HTML
</ul>
</ul>
</div>
</div>
</body>
</html>
HTML;
@ -561,7 +596,7 @@ echo <<< HTML
</html>
HTML;
die();
}
}
// Send Endpoint:
// This takes the submitted message and checks the password is correct.