split off post behavior

This commit is contained in:
awesomeuser 2023-08-02 21:59:10 +00:00
parent 7e8e96d029
commit 1fb9a966dd

View file

@ -77,7 +77,7 @@
<body> <body>
<!-- header and options for making posts --> <!-- header and options for making posts -->
<div class="post"> <div class="post" action="farp.php">
<h1 style="margin-bottom: 4px;"><span style="color: var(--accent);">furp</span>social</h1> <h1 style="margin-bottom: 4px;"><span style="color: var(--accent);">furp</span>social</h1>
<form method="post"> <form method="post">
@ -108,34 +108,14 @@
<div class="post" id="refresh" onclick="window.location.href = 'index.php'">refresh feed</div> <div class="post" id="refresh" onclick="window.location.href = 'index.php'">refresh feed</div>
<?php <?php
// make sure the file, well, exists // // make sure the file, well, exists
$myfile = fopen("posts.txt", "a"); // $myfile = fopen("posts.txt", "a");
fclose($myfile); // 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);
$_POST = array();
}
// show content // show content
echo $content; $myfile = fopen("posts.txt", "r") or die("Unable to open file!");
echo fread($myfile, filesize("posts.txt"));
fclose($myfile);
?> ?>
</body> </body>