aboutsummaryrefslogtreecommitdiff
path: root/app/model
diff options
context:
space:
mode:
authorThedro Neely <thedroneely@gmail.com>2018-08-30 04:30:53 -0400
committerThedro Neely <thedroneely@gmail.com>2018-08-30 04:30:53 -0400
commit2bdcd9d9283b44e7c35822aa1317013928006fd8 (patch)
treeca2bf097e4dfcfdabba36a5cb2643560ab03b926 /app/model
downloadthedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.tar.gz
thedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.tar.bz2
thedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.zip
Initialize Repo: First Commit
Diffstat (limited to 'app/model')
-rw-r--r--app/model/Form.php85
-rw-r--r--app/model/Navigation.php31
2 files changed, 116 insertions, 0 deletions
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 @@
+<?php
+
+// PHP mailer namespace
+use PHPMailer\PHPMailer\PHPMailer;
+use PHPMailer\PHPMailer\Exception;
+
+class Form
+{
+ public $name;
+ public $email;
+ public $message;
+
+ public function __construct($name, $email, $message)
+ {
+ $this->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 @@
+<?php
+
+class Navigation
+{
+ public function generateHomeButton()
+ {
+ if ($_SERVER['REQUEST_URI'] === '/') {
+ echo '<a class="navbar-active navbar-item" href="/">Home</a>';
+ return;
+ }
+ echo '<a class="navbar-item" href="/">Home</a>';
+ }
+
+ 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) . "<a class=\"navbar-item$append\"" . ' href="' . $route['uri'] . '">' . $title . '</a>' . "\n";
+ }
+ }
+}