This repository has been archived on 2024-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
furpsocial/index.php
2023-08-02 21:26:35 +00:00

134 lines
No EOL
4.6 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
<title>furpsocial</title>
<meta charset="UTF-8">
<style>
:root {
--accent: #32a852;
}
body {
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
background: var(--accent);
margin: 0;
padding: 0;
}
#body-input {
width: 99%;
height: 150px;
resize: none;
}
.post {
width: 100%;
max-width: 600px;
margin: auto;
background: white;
padding: 10px;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-shadow: 0px 0px 10px gray;
border-radius: 8px;
overflow: hidden;
margin-bottom: 10px;
}
.post h1 {
margin: 0;
font-size: 20px;
}
.post h2 {
margin: 0;
font-size: 14px;
padding: 10px;
margin: -10px;
display: inline-block;
}
.post i {
float: right;
color: grey;
}
#refresh {
font-weight: 600;
text-align: center;
padding: 5px;
background: var(--accent);
}
#refresh:hover {
cursor: pointer;
}
</style>
</head>
<body>
<!-- header and options for making posts -->
<div class="post">
<h1><span style="color: var(--accent);">furp</span>social</h1>
<form method="post">
<textarea id="body-input" name="body"></textarea>
Signature (optional): <input id="signature-input" onchange="logSignature();" type="text" name="signature"><br>
<input type="submit" value="Farp it">
</form>
<span style="font-size: 12px; color: grey;">Privacy Policy: The only data collected by furpsocial server-side is the contents of your posts (signature and body text). This information is stored in our secure databases which are wiped of all post data every week. This data is only used to accomodate furpsocial as a social media platform. Client-side, furpsocial stores your most recently used signature as a cookie.</span>
</div>
<!-- save most recent signature as a cookie and autoload on page load -->
<script>
function logSignature() {
// save signature to cookie;
const d = new Date();
d.setTime(d.getTime() + (1 * 24 * 60 * 60 * 1000));
document.cookie = "signature=" + document.getElementById("signature-input").defaultValue + "; expires=" + d.toUTCString() + ";path=/";
alert(document.getElementById("signature-input").defaultValue);
}
// load caches signature
alert(document.cookie);
if (document.cookie.includes('=')) {
document.getElementById("signature-input").defaultValue = document.cookie.split('=')[1];
}
</script>
<!-- feed display -->
<div class="post" id="refresh" onclick="window.location.href = 'index.php'">refresh feed</div>
<?php
// make sure the file, well, exists
$myfile = fopen("posts.txt", "a");
fclose($myfile);
// read file into string
$myfile = fopen("posts.txt", "r") or die("Unable to open file!");
$content = fread($myfile, filesize("posts.txt"));
fclose($myfile);
// write new post to file if necessary
if (!is_null($_POST["body"]) && strlen($_POST["body"]) != 0) {
// concatenate new post to the beginning of the string
$signature = "anonymous";
if (!is_null($_POST["signature"]) && strlen($_POST["signature"]) != 0) {
$signature = htmlspecialchars($_POST["signature"]);
}
$content = "<div class='post'><h2>" . $signature . "</h2><i>UTC " . date("Y/m/d H:i") . "</i><div>" . htmlspecialchars($_POST["body"]) . "</div></div>" . $content;
// write string back into the file
$myfile = fopen("posts.txt", "w") or die("Unable to open file!");
fwrite($myfile, $content);
fclose($myfile);
}
// show content
echo $content;
?>
</body>
</html>