Switch to using Hugo

This commit is contained in:
NeilBrommer 2018-05-12 16:50:36 -07:00
parent 03328460ae
commit 7caf09852c
29 changed files with 462 additions and 846 deletions

Binary file not shown.

116
static/contact.php Normal file
View file

@ -0,0 +1,116 @@
<?php
// on bluehost only
ini_set("include_path", '/home2/neilbrom/php:' . ini_get("include_path") );
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
include_once "info.php";
if ($_SERVER["REQUEST_METHOD"] == 'POST') {
if (isset($_POST["captcha"]) && !empty($_POST["captcha"])) {
$captcha = $_POST["captcha"];
$url = "https://www.google.com/recaptcha/api/siteverify";
$data = array(
"secret" => $recaptchaSecret,
"response" => $captcha,
"remoteip" => $_SERVER["REMOTE_ADDR"]
);
$options = array(
"http" => array(
"header" => "Content-Type: application/x-www-form-urlencoded\r\n",
"method" => "POST",
"content" => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === false) {
http_response_code(500);
die("Error verifying reCAPTCHA");
}
$result = json_decode($result, true);
if ($result["success"] == false) {
http_response_code(400);
die("Could not verify reCAPTCHA");
}
if (!isset($_POST["name"])) {
http_response_code(400);
die("A name is required");
}
$name = trim($_POST["name"]);
if ($name == '') {
http_response_code(400);
die("The name cannot be empty");
} else if (strtolower($name) == 'anon' || strToLower($name) == 'anonymous') {
http_response_code(400);
die("Enter a real name");
}
if (!isset($_POST["email"])) {
http_response_code(400);
die("An email address is required");
}
$email = trim($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
http_response_code(400);
die("Invalid email address");
}
$subject = "Message from contact form";
if (isset($_POST["subject"]) && trim($_POST["subject"]) != "") {
$subject = $subject . ": " . $_POST["subject"];
}
if (!isset($_POST["message"])) {
http_response_code(400);
die("A message is required");
}
$message = trim($_POST["message"]);
if ($message == '') {
http_response_code(400);
die("A message is required");
}
$message = $name . ' -- &lt;' . $email . '&gt;<hr>' . $message;
$mail = new PHPMailer(true); // true enables exceptions
try {
$mail->isSMTP();
//$mail->SMTPDebug = 3;
$mail->Host = $mailHost;
$mail->SMTPAuth = true;
$mail->Username = $mailUser;
$mail->Password = $mailPass;
$mail->SMTPSecure = 'ssl';
$mail->Port = $mailPort;
$mail->setFrom($mailFrom, 'Website Contact Form');
$mail->addAddress($mailDest);
$mail->addReplyTo($email);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->Send();
} catch (Exception $e) {
http_response_code(500);
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
} else { // no recaptcha
http_response_code(400);
echo "Bad reCAPTCHA";
}
} else {
http_response_code(404);
}
?>

88
static/css/main.css Normal file
View file

@ -0,0 +1,88 @@
:root {
--main-color: #3f51b5; /* R:63, G:82, B:181 */
--main-dark-color: #002984;
--main-light-color: #757de8;
}
body {
padding-top: 70px;
padding-bottom: 40px;
cursor: default;
}
.navbar, .fixed-top {
background-color: #3f51b5 !important;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
border-bottom: #002984 1px solid;
}
a:not(.nav-link):not(.navbar-brand) {
color: #3f51b5;
}
a:hover:not(.nav-link):not(.navbar-brand) {
color: #757de8;
}
li.col-md-6 {
padding-left: 0px;
}
.cover {
text-align: center;
}
.required {
color: red;
}
.invalid-captcha {
box-shadow: 0 0 1.5px 1px red;
}
.fa {
font-size: 0.85rem;
}
.full-height {
height: 100%;
}
.dark-mode {
color: white;
background-color: #343a40;
}
.dark-mode .jumbotron {
background-color: #2b3136;
}
.dark-mode a:not(.navbar-brand):not(.nav-link) {
color: #757de8 !important;
}
.dark-mode a:not(.navbar-brand):not(.nav-link):hover {
color: #3f51b5 !important;
}
.dark-mode .card {
background-color: #343a40;
border-color: rgba(255, 255, 255, 0.125);
}
.dark-mode .form-control {
background-color: rgb(81, 89, 107);
border-color: rgb(60, 66, 80);
}
.dark-mode .form-control:focus {
box-shadow: 0 0 0 .2rem rgba(255,255,255,.5);
}
/* for transitioning to/from dark mode */
.transition {
-webkit-transition: color 0.25s ease-in-out, background-color 0.25s ease-in-out, box-shadow 0.25s ease-in-out, border 0.25s ease-in-out;
-moz-transition: color 0.25s ease-in-out, background-color 0.25s ease-in-out, box-shadow 0.25s ease-in-out, border 0.25s ease-in-out;
-o-transition: color 0.25s ease-in-out, background-color 0.25s ease-in-out, box-shadow 0.25s ease-in-out, border 0.25s ease-in-out;
transition: color 0.25s ease-in-out, background-color 0.25s ease-in-out, box-shadow 0.25s ease-in-out, border 0.25s ease-in-out;
}

BIN
static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

65
static/js/contact.js Normal file
View file

@ -0,0 +1,65 @@
$(document).ready(function() {
$("#contactForm").on("submit", sendForm);
});
function sendForm(e) {
e.preventDefault(); // prevent the page from refreshing
$("#contactSubmit").prop("disabled", true);
if ($("#successAlert")[0].style.display != 'none') {
$("#successAlert").slideUp(250);
}
if ($("#errorAlert")[0].style.display != 'none') {
$("#errorAlert").slideUp(250);
}
var captcha = grecaptcha.getResponse();
if (captcha.length == 0) {
$(".captcha").addClass("invalid-captcha");
} else {
$(".captcha").removeClass("invalid-captcha");
var name = $("#nameField").val();
var email = $("#emailField").val();
var subject = $("#subjectField").val();
var message = $("#messageField").val();
$.ajax({
url: "../contact.php",
type: "POST",
data: {
"name": name,
"email": email,
"subject": subject,
"message": message,
"captcha": captcha
},
success: messageSuccess,
error: messageError,
complete: doneSending
});
}
}
function messageSuccess(result) {
$("#successAlert").slideDown(500);
}
function messageError(result) {
var alert = $("#errorAlert");
alert.empty();
$(document.createTextNode("Error: " + result.responseText)).appendTo(alert);
alert.slideDown(500);
}
function doneSending() {
var html = $("html");
var top = html.scrollTop() + $("body").scrollTop() // Get position of the body
if(top != 0) {
$("html,body").animate({scrollTop:0}, '500');
}
$("#contactSubmit").prop("disabled", false);
}

67
static/js/main.js Normal file
View file

@ -0,0 +1,67 @@
var theme = window.localStorage.getItem("theme");
if (theme != null && theme == "true")
$("body").addClass("dark-mode");
$(document).ready(function () {
$("#btnTheme").click(function () {
if ($("#btnTheme").hasClass("btn-light")) {
transitionLight();
} else {
transitionDark();
}
});
var theme = window.localStorage.getItem("theme");
if (theme != null && theme == "true")
setDark();
});
function checkTheme() {
if (theme != null && theme == "true")
setDark();
}
function transitionDark() {
$(".card").addClass("transition");
$(".jumbotron").addClass("transition");
$(".form-control").addClass("transition");
$("a:not(.navbar-brand):not(.nav-link)").addClass("transition");
$("body").addClass("transition dark-mode");
setTimeout(endTransition, 250);
$("#btnTheme").removeClass("btn-dark").addClass("transition btn-light");
$("#themeText").replaceWith($("<span>").attr("id", "themeText").addClass("fas fa-sun"));
window.localStorage.setItem("theme", "true");
}
function transitionLight() {
$(".card").addClass("transition");
$(".jumbotron").addClass("transition");
$(".form-control").addClass("transition");
$("a:not(.navbar-brand):not(.nav-link)").addClass("transition");
$("body").addClass("transition").removeClass("dark-mode");
setTimeout(endTransition, 250);
$("#btnTheme").removeClass("btn-light").addClass("transition btn-dark");
$("#themeText").replaceWith($("<span>").attr("id", "themeText").addClass("fas fa-moon"));
window.localStorage.setItem("theme", "false");
}
function endTransition() {
$("body").removeClass("transition");
$(".card").removeClass("transition");
$(".jumbotron").removeClass("transition");
$("a:not(.navbar-brand):not(.nav-link)").removeClass("transition");
$(".form-control").removeClass("transition");
}
function setDark() {
$("body").addClass("dark-mode");
$("#btnTheme").removeClass("btn-dark").addClass("btn-light");
$("#themeText").replaceWith($("<span>").attr("id", "themeText").addClass("fas fa-sun"));
}