aboutsummaryrefslogtreecommitdiff
path: root/guestbook
diff options
context:
space:
mode:
Diffstat (limited to 'guestbook')
-rw-r--r--guestbook/bg.jpgbin0 -> 1184070 bytes
-rw-r--r--guestbook/bg.jxlbin0 -> 664811 bytes
-rw-r--r--guestbook/feed.php47
-rw-r--r--guestbook/index.php244
-rw-r--r--guestbook/submit.php87
5 files changed, 378 insertions, 0 deletions
diff --git a/guestbook/bg.jpg b/guestbook/bg.jpg
new file mode 100644
index 0000000..cd3b3a0
--- /dev/null
+++ b/guestbook/bg.jpg
Binary files differ
diff --git a/guestbook/bg.jxl b/guestbook/bg.jxl
new file mode 100644
index 0000000..a386f5e
--- /dev/null
+++ b/guestbook/bg.jxl
Binary files differ
diff --git a/guestbook/feed.php b/guestbook/feed.php
new file mode 100644
index 0000000..7cdb62e
--- /dev/null
+++ b/guestbook/feed.php
@@ -0,0 +1,47 @@
+<?php
+
+header('Content-Type: text/xml');
+
+echo '<rss version="2.0"><channel>';
+echo '<title>isopod.cool guestbook</title>';
+echo '<description>The guestbook on isopod.cool</description>';
+echo '<language>en-us</language>';
+echo '<link>https://isopod.cool/guestbook/</link>';
+echo '<generator>My crappy PHP code</generator>';
+
+$postlist = json_decode(file_get_contents("posts.json"));
+$index = 1;
+$totaloutput = "";
+foreach($postlist as $post) {
+ $output = "";
+ $date = date("D, d M Y H:m:s", $post->date) . " GMT";
+ $name = $post->name;
+ $message = $post->message;
+ $found = $post->found;
+ $website = $post->website;
+ $cool = $post->cool;
+ $coolsanitized = htmlentities(preg_replace("/https?:\/\//i", "", $cool));
+ $reply = htmlentities($post->reply);
+
+ if($website) { $output = $output."<a href='$website'>$name</a>:<br><br>"; }
+ else { $output = $output.$name.":<br><br>"; }
+
+ if($cool) {
+ $output = $output."<b>cool thing</b>: <a href='$cool'>$coolsanitized</a><br><br>";
+ }
+
+ if($found) {
+ $output = $output."<b>How did you find me?</b><br>$found<br><br>";
+ }
+
+ $output = $output.$message."<br><br>";
+
+ if($reply) {
+ $output = $output."<hr><b>Reply:</b><br>$reply";
+ }
+ $totaloutput = "<item><title>Entry #" . $index . " - " . $name . "</title><link>https://isopod.cool/guestbook/</link><pubDate>" . $date . "</pubDate><description>".htmlentities($output)."</description><guid isPermaLink='false'>" . $index . $post->date . $name . "</guid></item>".$totaloutput;
+ $index++;
+}
+
+echo $totaloutput;
+echo "</channel></rss>"; \ No newline at end of file
diff --git a/guestbook/index.php b/guestbook/index.php
new file mode 100644
index 0000000..7d85fd1
--- /dev/null
+++ b/guestbook/index.php
@@ -0,0 +1,244 @@
+<!--?php
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+?-->
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>Guestbook</title>
+ <link href="../style.css" rel="stylesheet" type="text/css" media="all">
+ <style>
+ table {
+ border-collapse: collapse;
+ table-layout: fixed;
+ }
+ td {
+ padding: 0.3rem;
+ }
+
+ form > table {
+ width: 100%;
+ margin: auto;
+ margin-bottom: 1.5rem;
+ }
+ form td:first-child {
+ text-align: right;
+ }
+
+ article {
+ width: 100%;
+ margin: 2rem auto;
+ display: grid;
+ gap: 1rem;
+ grid-template-areas:
+ 'gb-name gb-date gb-index'
+ 'gb-cool gb-cool gb-cool'
+ 'gb-found gb-found gb-found'
+ 'gb-message gb-message gb-message'
+ 'gb-reply gb-reply gb-reply';
+ }
+ article :is(h1,h2,h3,h4,h5,h6) {
+ border: none;
+ padding-left: initial;
+ }
+
+ input, textarea {
+ border: none;
+ font-family: var(--stdfont);
+ }
+ input[type="text"], input[type="email"], textarea {
+ width: 100%;
+ background: none;
+ border-bottom: 2px solid #444444;
+ color: gainsboro;
+ padding: 0.35rem;
+ box-sizing: border-box;
+ font-size: .9em;
+ }
+ input[type="submit"], input[type="reset"] {
+ padding: 0.35rem 0.5rem;
+ box-shadow: 2px 2px 6px black;
+ margin: 0.3rem;
+ display: inline-block;
+ }
+ input[type="submit"]:active, input[type="reset"]:active {
+ transform: translate(1px, 1px); box-shadow: 0 0 2px black;
+ }
+ input[type="submit"]:hover, input[type="reset"]:hover {
+ cursor: pointer;
+ }
+
+ hr {
+ width: 30%;
+ }
+ .error {
+ color: red;
+ font-size: 0.85em;
+ }
+ .success {
+ color: #00ff00;
+ font-size: 0.85em;
+ }
+ .reply {
+ border-left: 3px solid gainsboro;
+ padding-left: 1rem;
+ }
+ .message {
+ padding-top: 1.5rem;
+ }
+ .gb-date {
+ text-align: center;
+ }
+ .gb-index {
+ text-align: right;
+ }
+ .gb-cool {
+ word-break: break-all;
+ }
+ .gb-name, .gb-date, .gb-index {
+ min-width: calc(var(--bodywidth) / 3);
+ }
+ @media only screen and (hover: none) {
+ form td:first-child {
+ text-align: left;
+ }
+ form td:nth-child(2) {
+ padding-left: 0;
+ padding-right: 0;
+ }
+ input[type="text"], input[type="email"], textarea {
+ background: none;
+ border: 2px solid #00000033;
+ border-bottom: 2px solid #888888;
+ }
+ article {
+ margin: 2rem auto;
+ }
+ @media (max-width: 43rem) {
+ article {
+ grid-template-areas:
+ 'gb-name gb-name gb-index'
+ 'gb-date gb-date gb-date'
+ 'gb-cool gb-cool gb-cool'
+ 'gb-found gb-found gb-found'
+ 'gb-message gb-message gb-message'
+ 'gb-reply gb-reply gb-reply';
+ }
+ }
+ }
+ @media (prefers-contrast: more) {
+ input[type="text"], input[type="email"], textarea {
+ outline: 1px solid white;
+ color: white;
+ }
+ input:focus, textarea:focus {
+ outline: 3px solid white;
+ }
+ input[type="submit"] {
+ background: none;
+ color: white;
+ outline: 1px solid white;
+ }
+ }
+ </style>
+ <?php include($_SERVER['DOCUMENT_ROOT'] . '/seasonal.php'); ?>
+ </head>
+ <body>
+ <?php include($_SERVER['DOCUMENT_ROOT'] . '/nav.php'); bg(); ?>
+ <h1>guestbook</h1>
+ <h2 id="caption">say hi!</h2>
+ <nav>
+ <a href="feed.php">RSS</a>
+ </nav>
+ <?php
+ $return = $_GET["return"];
+ ?>
+ <form action="submit.php" method="post" autocomplete="off">
+ <table>
+
+ <?php if($return == "noname") { echo "<td></td><td><span class='error'>Name required!</span></td>"; } ?>
+ <tr>
+ <td>Name<span style="color:red;">*</span></td>
+ <td><input type="text" name="name"></td>
+ </tr>
+
+ <?php if($return == "invalidwebsite") { echo "<td></td><td><span class='error'>Invalid URL!</span></td>"; } ?>
+ <tr>
+ <td>Website</td>
+ <td><input type="text" name="website" placeholder="https://"></td>
+ </tr>
+
+ <?php if($return == "invalidlink") { echo "<td></td><td><span class='error'>Invalid URL!</span></td>"; } ?>
+ <tr>
+ <td>Link something cool</td>
+ <td><input type="text" name="cool" placeholder="https://"></td>
+ </tr>
+
+ <tr>
+ <td>How did you find me?</td>
+ <td><textarea name="found"></textarea></td>
+ </tr>
+
+ <?php if($return == "nomessage") { echo "<td></td><td><span class='error'>Message required!</span></td>"; } ?>
+ <tr>
+ <td>Message<span style="color:red;">*</span></td>
+ <td><textarea name="message" placeholder="Now supports Markdown!"></textarea></td>
+ </tr>
+
+ <?php if($return == "botcheckfailed") { echo "<td></td><td><span class='error'>You failed the bot check!</span></td>"; } ?>
+ <tr>
+ <td>Bot test (six-letter scientific term for a roly-poly or woodlouse)<span style="color:red;">*</span></td>
+ <td><input type="text" name="botcheck" placeholder="*.cool"></td>
+ </tr>
+
+ <?php if($return == "success") { echo "<td></td><td><span class='success'>Successfully posted!</span></td>"; } ?>
+ <tr>
+ <td colspan="2" style="text-align: center;"><input type="reset"><input type="submit" value="Post"></td>
+ </tr>
+
+ </table>
+ </form>
+ <?php
+ include("../Parsedown.php");
+ $Parsedown = new Parsedown();
+ $Parsedown->setSafeMode(true);
+
+ $totaloutput = "";
+ $postlist = json_decode(file_get_contents("posts.json"));
+ $index = 1;
+ foreach($postlist as $post) {
+ $output = "";
+ $date = date("Y-m-d h:iA", $post->date);
+ $name = $post->name;
+ $message = $Parsedown->text(html_entity_decode($post->message));
+ $found = $post->found;
+ $website = $post->website;
+ $cool = $post->cool;
+ $coolsanitized = htmlentities(preg_replace("/https?:\/\//i", "", $cool));
+ $reply = $Parsedown->text($post->reply);
+
+ $output = $output."<hr><article><div style='grid-area:gb-name;' class='gb-name'>";
+ if($website) { $output = $output."<a href='$website'>$name</a>"; }
+ else { $output = $output.$name; }
+ $output = $output."</div><div style='grid-area:gb-date;' class='gb-date'>$date</div><div style='grid-area:gb-index;' class='gb-index'>Entry #$index</div>";
+ if($cool) {
+ $output = $output."<div style='grid-area:gb-cool;' class='gb-cool'><b>cool thing</b>: <a href='$cool'>$coolsanitized</a></div>";
+ }
+ if($found) {
+ $output = $output."<div style='grid-area:gb-found;'><b>How did you find me?</b><br>$found</div>";
+ }
+ $output = $output."<div style='grid-area:gb-message;'>$message</div>";
+ if($reply) {
+ $output = $output."<div style='grid-area:gb-reply;' class='reply'><b>Reply</b>:<br>$reply</div>";
+ }
+ $output = $output."</article>";
+ $index++;
+ $totaloutput = $output.$totaloutput;
+ }
+ echo $totaloutput; ?>
+
+ </body>
+</html>
diff --git a/guestbook/submit.php b/guestbook/submit.php
new file mode 100644
index 0000000..09d0404
--- /dev/null
+++ b/guestbook/submit.php
@@ -0,0 +1,87 @@
+<?php
+ if ($_SERVER["REQUEST_METHOD"] == "POST") {
+
+ $returnCode = "success";
+ if($_POST["botcheck"] != "isopod") {
+ $returnCode = "botcheckfailed";
+ } else if(!$_POST["name"]) {
+ $returnCode = "noname";
+ } else if(!$_POST["message"]) {
+ $returnCode = "nomessage";
+ } else if($_POST["website"] and !preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $_POST["website"])) {
+ $returnCode = "invalidwebsite";
+ } else if($_POST["cool"] and !preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $_POST["cool"])) {
+ $returnCode = "invalidlink";
+ } else {
+
+ date_default_timezone_set("America/Edmonton");
+ $currentPost = array(
+ "date" => time(),
+ "name" => htmlentities($_POST["name"]),
+ "message" => htmlentities($_POST["message"]),
+ "found" => htmlentities($_POST["found"]),
+ "website" => $_POST["website"],
+ "cool" => $_POST["cool"],
+ "reply" => ""
+ );
+
+ $filename = "posts.json";
+
+ $handle = @fopen($filename, 'r+');
+
+ // create the file if needed
+ if ($handle === null)
+ {
+ $handle = fopen($filename, 'w+');
+ }
+
+ if ($handle)
+ {
+ // seek to the end
+ fseek($handle, 0, SEEK_END);
+
+ // are we at the end of is the file empty
+ if (ftell($handle) > 0)
+ {
+ // move back a byte
+ fseek($handle, -2, SEEK_END);
+
+ // add the trailing comma
+ fwrite($handle, ",\n", 2);
+
+ // add the new json string
+ fwrite($handle, json_encode($currentPost) . "]\n");
+ }
+ else
+ {
+ // write the first event inside an array
+ fwrite($handle, json_encode(array($currentPost)));
+ }
+
+ // close the handle on the file
+ fclose($handle);
+ }
+ }
+ }
+ header("Location: ./?return=$returnCode");
+?>
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Guestbook</title>
+ <link href="../style.css" rel="stylesheet" type="text/css" media="all">
+ <style type="text/css">
+ body {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ }
+ </style>
+ <?php include($_SERVER['DOCUMENT_ROOT'] . '/seasonal.php'); ?>
+ </head>
+ <body>
+ <p>Your post has been submitted! It's weird that you're seeing this page though. Maybe your browser can't process location headers? At any rate, click <?php echo "<a href='./?return=$returnCode'>here</a>"; ?> to get where you're supposed to be right now.</p>
+ </body>
+</html> \ No newline at end of file