diff options
Diffstat (limited to 'guestbook/submit.php')
| -rw-r--r-- | guestbook/submit.php | 81 |
1 files changed, 34 insertions, 47 deletions
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"> |
