From 2bdcd9d9283b44e7c35822aa1317013928006fd8 Mon Sep 17 00:00:00 2001 From: Thedro Neely Date: Thu, 30 Aug 2018 04:30:53 -0400 Subject: Initialize Repo: First Commit --- app/model/Form.php | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ app/model/Navigation.php | 31 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 app/model/Form.php create mode 100644 app/model/Navigation.php (limited to 'app/model') diff --git a/app/model/Form.php b/app/model/Form.php new file mode 100644 index 0000000..4e6d3f3 --- /dev/null +++ b/app/model/Form.php @@ -0,0 +1,85 @@ +name = $name; + $this->email = $email; + $this->message = $message; + + $this->isSpam(); + $this->isEmpty(); + } + + public function isSpam() + { + $spam = false; + + if (isset($_POST['contact'])) { + $spam = $_POST['contact']; + } + + if ((bool) $spam == true) { + http_response_code(403); + error_log('Contact Form Spam: Error 403'); + exit; + } + } + + public function isEmpty() + { + if ((bool) empty($this->name) == true + || (bool) empty($this->email) == true + || (bool) empty($this->message) == true + ) { + header('Location: /contact'); + exit; + } + } + + public function isSubmit() + { + // Include mail config + $config = include '../AppConfig.php'; + + $mail = new PHPMailer(true); + + try { + //Server settings + //$mail->SMTPDebug = 2; // Enable verbose debug output + $mail->isSMTP(); // Set mailer to use SMTP + $mail->Host = $config['mail']['host']; // Specify main and backup SMTP servers + $mail->SMTPAuth = true; // Enable SMTP authentication + $mail->Username = $config['mail']['username']; // SMTP username + $mail->Password = $config['mail']['password']; // SMTP password + $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted + $mail->Port = $config['mail']['port']; // TCP port to connect to + + //Recipients + $mail->setFrom('thedroneely@gmail.com', 'Thedro Neely'); + $mail->addAddress('thedroneely@gmail.com', 'Thedro Neely'); + $mail->addReplyTo($this->email, $this->name); + + //Content + $mail->isHTML(true); + $mail->Subject = 'New message from ' . $this->name; + $mail->Body = $this->message; + $mail->AltBody = $this->message; + + //Send Mail + $mail->send(); + + } catch (Exception $e) { + include '../app/views/mail-error.view.php'; + } + } +} diff --git a/app/model/Navigation.php b/app/model/Navigation.php new file mode 100644 index 0000000..4db89b5 --- /dev/null +++ b/app/model/Navigation.php @@ -0,0 +1,31 @@ +Home'; + return; + } + echo 'Home'; + } + + public function generateNavBar() + { + $navbar = [ + 'Posts' => ['uri' => '/post/'], + 'Projects' => ['uri' => '/project/'], + 'Profile' => ['uri' => '/about/'], + 'Contact' => ['uri' => '/contact/'], + ]; + + foreach ($navbar as $title => $route) { + $append =''; + if ($route['uri'] === $_SERVER['REQUEST_URI'] || strpos($_SERVER['REQUEST_URI'], $route['uri']) !== false) { + $append = ' navbar-active'; + } + echo str_repeat("\t", 4) . "' . $title . '' . "\n"; + } + } +} -- cgit v1.2.3