diff options
Diffstat (limited to 'blog/comment')
| -rw-r--r-- | blog/comment/comments.css | 92 | ||||
| -rw-r--r-- | blog/comment/feed.php | 29 | ||||
| -rw-r--r-- | blog/comment/index.php | 40 | ||||
| -rw-r--r-- | blog/comment/submit.php | 81 |
4 files changed, 242 insertions, 0 deletions
diff --git a/blog/comment/comments.css b/blog/comment/comments.css new file mode 100644 index 0000000..7f97c4c --- /dev/null +++ b/blog/comment/comments.css @@ -0,0 +1,92 @@ +table { + border-collapse: collapse; + table-layout: fixed; +} +td { + padding: 0.3rem; +} + +form > table { + width: 100%; + margin: auto; + margin-bottom: 1.5rem; +} + +article { + width: 100%; + margin: 2rem auto; + display: grid; + gap: 1rem; +} + +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; +} +.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; +} +@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 (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; + } +}
\ No newline at end of file diff --git a/blog/comment/feed.php b/blog/comment/feed.php new file mode 100644 index 0000000..889514f --- /dev/null +++ b/blog/comment/feed.php @@ -0,0 +1,29 @@ +<?php +include("../../Parsedown.php"); +$Parsedown = new Parsedown(); +$Parsedown->setSafeMode(true); + +header('Content-Type: text/xml'); + +echo '<rss version="2.0"><channel>'; +echo '<title>isopod.cool blog comments</title>'; +echo '<description>Every comment posted on my blog in chronological order.</description>'; +echo '<language>en-us</language>'; +echo '<link>https://isopod.cool/blog/comment/</link>'; +echo '<generator>My crappy PHP code</generator>'; + +$postlist = json_decode(file_get_contents("posts.json")); +$totaloutput = ""; +foreach($postlist as $post) { + $output = ""; + $date = date("D, d M Y H:m:s", $post->date) . " GMT"; + $name = $post->name; + $message = $Parsedown->text(html_entity_decode($post->message)); + $entry = $post->entry; + + $output = $output."Comment from ".$name." on ".$entry.":<br><br>".$message."<br><br>"; + $totaloutput = "<item><title>Comment on " . $entry . " from " . $name . "</title><link>https://isopod.cool/blog/posts/" . $entry . "/</link><pubDate>" . $date . "</pubDate><description>".htmlentities($output)."</description><guid isPermaLink='false'>" . $entry . $post->date . $name . "</guid></item>".$totaloutput; +} + +echo $totaloutput; +echo "</channel></rss>";
\ No newline at end of file diff --git a/blog/comment/index.php b/blog/comment/index.php new file mode 100644 index 0000000..2d5f6a6 --- /dev/null +++ b/blog/comment/index.php @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>blog comments</title> + <link href="/style.css" rel="stylesheet" type="text/css" media="all"> + <link href="comments.css" rel="stylesheet" type="text/css" media="all"> + <style> + + </style> + <?php include($_SERVER['DOCUMENT_ROOT'] . '/seasonal.php'); ?> + </head> + <body> + <?php include($_SERVER['DOCUMENT_ROOT'] . '/nav.php'); ?> + <h1>blog</h1> + <h2 id="caption">every comment</h2> + <nav> + <a href="feed.php">RSS</a> + </nav> + <?php + include("../../Parsedown.php"); + $Parsedown = new Parsedown(); + $Parsedown->setSafeMode(true); + + $totaloutput = ""; + $postlist = json_decode(file_get_contents("posts.json")); + 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)); + $entry = $post->entry; + + $output = $output."<hr><article><table><tr><td style='text-align: left;'>".$name." <i>on</i> <a href='/blog/posts/".$entry."/'>".$entry."</a></td><td style='text-align: right;'>".$date."</td></tr><tr><td colspan='2'>".$message."</td></tr></table></article>"; + $totaloutput = $output.$totaloutput; + } + echo $totaloutput; ?> + </body> +</html> diff --git a/blog/comment/submit.php b/blog/comment/submit.php new file mode 100644 index 0000000..26e5647 --- /dev/null +++ b/blog/comment/submit.php @@ -0,0 +1,81 @@ +<?php + if ($_SERVER["REQUEST_METHOD"] == "POST") { + + $returnLocation = $_POST["entry"]; + $returnCode = "success"; + if($_POST["botcheck"] != "isopod") { + $returnCode = "botcheckfailed"; + } else if(!$_POST["name"]) { + $returnCode = "noname"; + } else if(!$_POST["message"]) { + $returnCode = "nomessage"; + } else { + + date_default_timezone_set("America/Edmonton"); + $currentPost = array( + "date" => time(), + "name" => htmlentities($_POST["name"]), + "message" => htmlentities($_POST["message"]), + "entry" => $_POST["entry"] + ); + + $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: ../posts/$returnLocation/?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 |
