diff options
Diffstat (limited to 'guestbook')
| -rw-r--r-- | guestbook/comments.css | 136 | ||||
| -rw-r--r-- | guestbook/comments.php | 46 | ||||
| -rw-r--r-- | guestbook/feed.php | 66 | ||||
| -rw-r--r-- | guestbook/index.php | 190 | ||||
| -rw-r--r-- | guestbook/submit.php | 81 |
5 files changed, 261 insertions, 258 deletions
diff --git a/guestbook/comments.css b/guestbook/comments.css new file mode 100644 index 0000000..031320f --- /dev/null +++ b/guestbook/comments.css @@ -0,0 +1,136 @@ +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; + 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; +} +.error { + color: red; + font-size: 0.85em; +} +.success { + color: lime; + font-size: 0.85em; +} +.warning { + color: yellow; + font-size: 0.85em; +} +.reply { + padding: calc(var(--stdpadding) * 1.5); + margin: 0; + margin-bottom: initial; + border-left: var(--stdaccentborder); + background-color: var(--blockbg); + margin-bottom: var(--stdpadding); +} +.reply > :last-child { + margin-bottom: 0; +} +.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) - (var(--stdpadding) * 2)) +} +@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; + } +}
\ No newline at end of file diff --git a/guestbook/comments.php b/guestbook/comments.php new file mode 100644 index 0000000..3f65fb9 --- /dev/null +++ b/guestbook/comments.php @@ -0,0 +1,46 @@ +<?php +function echo_comments($page, $Parsedown = null) { + include($_SERVER['DOCUMENT_ROOT'] . '/common.php'); + if(!$Parsedown) { + include($_SERVER['DOCUMENT_ROOT']."/Parsedown.php"); + $Parsedown = new Parsedown(); + $Parsedown->setSafeMode(true); + } + + $totaloutput = ""; + $postlist = json_decode(file_get_contents($datadir."posts.json")); + $index = 1; + foreach($postlist as $post) { + if($post->entry === $page and $post->modstatus > 0) { + $output = ""; + $date = date("Y-m-d h:iA", $post->date); + $name = htmlentities($post->name); + $message = $Parsedown->text($post->message); + $found = htmlentities($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>:$reply</div>"; + } + $output = $output."</article>"; + $index++; + $totaloutput = $output.$totaloutput; + } + } + echo $totaloutput; +} + diff --git a/guestbook/feed.php b/guestbook/feed.php index 7cdb62e..64d1b31 100644 --- a/guestbook/feed.php +++ b/guestbook/feed.php @@ -4,43 +4,51 @@ 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 '<description>The guestbook and blog comments 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")); + +include($_SERVER['DOCUMENT_ROOT']."/Parsedown.php"); +$Parsedown = new Parsedown(); +$Parsedown->setSafeMode(true); +include($_SERVER['DOCUMENT_ROOT'] . '/common.php'); +$postlist = json_decode(file_get_contents($datadir."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"; + if($post->modstatus == 1) { + $output = ""; + $entry = $post->entry; + $date = date("D, d M Y H:m:s", $post->date) . " GMT"; + $name = $post->name; + $message = $Parsedown->text($post->message); + $found = $post->found; + $website = $post->website; + $cool = $post->cool; + $reply = $Parsedown->text($post->reply); + + if($website) { $output = $output."<p><a href='$website'>$name</a>:</p>"; } + else { $output = $output."</p>$name:</p>"; } + + if($cool) { + $output = $output."<p><b>cool thing</b>: <a href='$cool'>$cool</a></p>"; + } + + if($found) { + $output = $output."<p><b>How did you find me?</b><br>$found</p>"; + } + + $output = $output.$message; + + if($reply) { + $output = $output."<hr><p><b>Reply</b>:</p>$reply"; + } + $output_sanitized = preg_replace("/&gt;/", ">", preg_replace("/&lt;/", "<", htmlspecialchars($output))); + $totaloutput = "<item><title>Entry #" . $index . " on " . $entry . " - " . $name . "</title><link>https://isopod.cool/guestbook/</link><pubDate>" . $date . "</pubDate><description>".$output_sanitized."</description><guid isPermaLink='false'>" . $index . $post->date . $name . "</guid></item>\n".$totaloutput; + $index++; } - $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; diff --git a/guestbook/index.php b/guestbook/index.php index 7d85fd1..77d211e 100644 --- a/guestbook/index.php +++ b/guestbook/index.php @@ -10,144 +10,17 @@ error_reporting(E_ALL); <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Guestbook</title> <link href="../style.css" rel="stylesheet" type="text/css" media="all"> + <link href="./comments.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(); ?> + <?php include($_SERVER['DOCUMENT_ROOT'] . '/nav.php'); bg(); + include($_SERVER['DOCUMENT_ROOT'] . '/common.php'); ?> <h1>guestbook</h1> <h2 id="caption">say hi!</h2> <nav> @@ -157,88 +30,41 @@ error_reporting(E_ALL); $return = $_GET["return"]; ?> <form action="submit.php" method="post" autocomplete="off"> + <textarea name="msg" placeholder="I know what you are." style="opacity: 0; position: absolute; left: -10000rem; height: 0; width: 0; overflow: clip;"></textarea> <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>"; } ?> + <?php if($return) { echo("<tr><td></td><td>".$gbform_messages[$return]."</td></tr>"); }?> <tr> - <td colspan="2" style="text-align: center;"><input type="reset"><input type="submit" value="Post"></td> + <td colspan="2" style="text-align: center;"><input type="reset"><input type="submit" value="Submit"></td> </tr> </table> + <input type='text' name='entry' value='guestbook' style='display: none;' readonly> </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; ?> - + <?php include('./comments.php'); echo_comments('guestbook'); ?> </body> </html> diff --git a/guestbook/submit.php b/guestbook/submit.php index 09d0404..7fab0d5 100644 --- a/guestbook/submit.php +++ b/guestbook/submit.php @@ -1,69 +1,56 @@ <?php + include($_SERVER['DOCUMENT_ROOT'] . '/common.php'); if ($_SERVER["REQUEST_METHOD"] == "POST") { - + $returnCode = "success"; - if($_POST["botcheck"] != "isopod") { + if($_POST["botcheck"] != "isopod" or $_POST['msg']) { $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"])) { + } else if( + $_POST["website"] and !preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $_POST["website"]) + or $_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"); + $modstatus = $defaultmodstatus; + $bannedwords = json_decode(file_get_contents($datadir."bannedwords.json")); + $bwspotted = false; + foreach($bannedwords as $word) { + if(preg_grep($word, $_POST)) { + $modstatus = 0; + } + } + if($modstatus < 1) { + $returnCode = "review"; + } + $currentPost = array( + "entry" => $_POST["entry"], + "sourceip" => $_SERVER['REMOTE_ADDR'], "date" => time(), - "name" => htmlentities($_POST["name"]), - "message" => htmlentities($_POST["message"]), - "found" => htmlentities($_POST["found"]), + "name" => $_POST["name"], + "message" => $_POST["message"], + + "found" => $_POST["found"], "website" => $_POST["website"], "cool" => $_POST["cool"], - "reply" => "" + "reply" => "", + "modstatus" => $modstatus ); - $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); - } + $filename = $datadir."posts.json"; + $extantPosts = json_decode(file_get_contents($filename)); + array_push($extantPosts, $currentPost); + file_put_contents($filename, json_encode($extantPosts, JSON_PRETTY_PRINT)); + } } - header("Location: ./?return=$returnCode"); + $referrer = preg_replace("/\?.*/", "", $_SERVER['HTTP_REFERER']); + header("Location: $referrer?return=$returnCode"); ?> <!DOCTYPE html> <html lang="en"> |
