Add posts to front page - move validation to inbox only

main
Terence Eden 2024-02-26 14:48:51 +00:00
rodzic 8a7544e5bb
commit 5e6a98dee3
1 zmienionych plików z 26 dodań i 4 usunięć

Wyświetl plik

@ -82,10 +82,6 @@
"Server Data: \n$serverData \n\n"
);
// Validate HTTP Message Signature
// This logs whether the signature was validated or not
if ( !verifyHTTPSignature() ) { die(); }
// Routing:
// The .htaccess changes /whatever to /?path=whatever
// This runs the function of the path requested.
@ -220,6 +216,10 @@
function inbox() {
global $body, $server, $username, $key_private;
// Validate HTTP Message Signature
// This logs whether the signature was validated or not
if ( !verifyHTTPSignature() ) { die(); }
// Get the message and type
$inbox_message = $body;
$inbox_type = $inbox_message["type"];
@ -420,6 +420,8 @@ echo <<< HTML
<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>
@ -431,6 +433,26 @@ echo <<< HTML
</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
$posts = array_reverse( glob("posts/*.json") );
foreach ($posts as $post) {
$postJSON = file_get_contents($post);
$postData = json_decode($postJSON, true);
$postTime = $postData["published"];
$postHTML = $postData["content"];
if ( isset($postData["attachment"]) ) {
$postImgUrl = $postData["attachment"]["url"];
$postImgAlt = $postData["attachment"]["name"];
$postImg = "<img src='{$postImgUrl}' alt='$postImgAlt'>";
} else {
$postImg = "";
}
echo "<li><a href='/{$post}'><time datetime='{$postTime}'>$postTime</time></a><br>{$postHTML}<br>{$postImg}</li>";
}
echo <<< HTML
</ul>
</body>
</html>
HTML;