diff --git a/config.php b/config.php index 2d90bd5..46693c0 100644 --- a/config.php +++ b/config.php @@ -1,10 +1,13 @@ 'mysql:host=localhost;dbname=freepost;charset=utf8', 'username' => 'freepost', 'password' => 'freepost' ); + + public static $SEND_EMAILS = true; } \ No newline at end of file diff --git a/css/freepost.css b/css/freepost.css index 5695d0b..58ad06c 100644 --- a/css/freepost.css +++ b/css/freepost.css @@ -14,6 +14,12 @@ img max-width: 100%; } +label +{ + cursor: pointer; + font-weight: normal; +} + html, body { background-color: #fff; /* #f5f8fa; */ @@ -309,7 +315,7 @@ html, body width: 80%; } - .content table.user td:first-child + .content table.user tr > td:first-child { font-weight: bold; text-align: right; @@ -317,11 +323,16 @@ html, body width: 30%; } - .content table.user td:last-child + .content table.user tr > td:last-child { - text-align: left; + text-align: left; } - + + .content table.user tr > td:last-child label + { + padding: 1em 0; + } + /* User activity */ .content > .user_activity { diff --git a/database.php b/database.php index 3e99aa4..22911c2 100644 --- a/database.php +++ b/database.php @@ -250,6 +250,29 @@ class Database } /** + * Retrieve the user of a specific post + */ + function get_post_op ($post_hash_id) + { + $user = array(); + + if (is_null ($this->database)) + return $user; + + $query = $this->database->prepare( + 'SELECT U.* ' . + 'FROM `user` AS U ' . + 'JOIN `post` AS P ON P.`userId` = U.`id` ' . + 'WHERE P.`hashId` = ?'); + + $query->execute (array ($post_hash_id)); + + $user = $query->fetch (PDO::FETCH_ASSOC); + + return $user; + } + + /** * Retrieve all comments for a specific post */ function get_post_comments ($post_id) @@ -316,6 +339,29 @@ class Database } /** + * Retrieve the user of a specific comment + */ + function get_comment_op ($comment_hash_id) + { + $user = array(); + + if (is_null ($this->database)) + return $user; + + $query = $this->database->prepare( + 'SELECT U.* ' . + 'FROM `user` AS U ' . + 'JOIN `comment` AS C ON C.`userId` = U.`id` ' . + 'WHERE C.`hashId` = ?'); + + $query->execute (array ($comment_hash_id)); + + $user = $query->fetch (PDO::FETCH_ASSOC); + + return $user; + } + + /** * Return the number of unread messages */ function count_unread_messages ($user_id) @@ -820,15 +866,16 @@ class Database /** * Update user information */ - function edit_user ($about, $email, $user_id) + function edit_user ($about, $email, $email_notifications, $user_id) { $query = $this->database->prepare ( 'UPDATE `user`' . - 'SET `about` = :about, `email` = :email ' . + 'SET `about` = :about, `email` = :email, `email_notifications` = :email_notifications ' . 'WHERE `id` = :user_id'); $query->bindValue (':about', $about, PDO::PARAM_STR); $query->bindValue (':user_id', $user_id, PDO::PARAM_INT); + $query->bindValue (':email_notifications', $email_notifications, PDO::PARAM_INT); if (NULL == $email || '' == $email) $query->bindValue (':email', NULL, PDO::PARAM_NULL); diff --git a/login_reset.php b/login_reset.php index 549316b..652172f 100644 --- a/login_reset.php +++ b/login_reset.php @@ -45,7 +45,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') if (!is_null ($token)) { mail ($user['email'], - 'Freepost Password Reset', + 'freepost: password reset', $twig->render ('login_reset_email.twig', array ('token' => $token)), 'From: freepost ' . "\r\n" . 'Reply-To: freepost '); } diff --git a/post.php b/post.php index da262c9..2be025e 100644 --- a/post.php +++ b/post.php @@ -1,6 +1,7 @@ new_comment ($comment, $post_hash_id, Session::get_userid()); + /* Send email notification for the new comment + * $post_op is the post's original poster + */ + /* + if (Config::$SEND_EMAILS) + { + $post = $db->get_post ($post_hash_id); + $post_op = $db->get_post_op ($post_hash_id); + + if ($post_op['email_notifications']) + mail ($post_op['email'], + 'freepost: new comment to one of your posts', + $twig->render ('email/new_comment.twig', array ( + 'commenter' => Session::get_username (), + 'post' => $post['title'] + )), + 'From: freepost ' . "\r\n" . 'Reply-To: freepost '); + } + */ + header ('Location: ./' . $post_hash_id); - exit(); + + exit (); } diff --git a/session.php b/session.php index 5a3abe2..f1d25ea 100644 --- a/session.php +++ b/session.php @@ -45,12 +45,13 @@ class Session { // Set session variable $_SESSION = array ( 'user' => array ( - 'id' => $user['id'], - 'hash_id' => $user['hashId'], - 'email' => $user['email'], - 'registered' => $user['registered'], - 'name' => $user['username'], - 'about' => $user['about'])); + 'id' => $user['id'], + 'hash_id' => $user['hashId'], + 'email' => $user['email'], + 'email_notifications' => $user['email_notifications'], + 'registered' => $user['registered'], + 'name' => $user['username'], + 'about' => $user['about'])); } /** diff --git a/template/email/new_comment.twig b/template/email/new_comment.twig new file mode 100644 index 0000000..358a755 --- /dev/null +++ b/template/email/new_comment.twig @@ -0,0 +1,3 @@ +{{ commenter }} has posted a new comment to "{{ post }}". + +Check all new comments at https://freepo.st/user_activity/replies \ No newline at end of file diff --git a/template/user.twig b/template/user.twig index 22933d6..c318741 100644 --- a/template/user.twig +++ b/template/user.twig @@ -42,6 +42,12 @@ Required if you wish to change your password +

+ +

diff --git a/user.php b/user.php index 3feb93e..ed01610 100644 --- a/user.php +++ b/user.php @@ -24,13 +24,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') // Update database with new user information $data = array( 'about' => (isset ($_POST['about']) ? $_POST['about'] : ''), - 'email' => (isset ($_POST['email']) ? $_POST['email'] : '')); + 'email' => (isset ($_POST['email']) ? $_POST['email'] : ''), + 'email_notifications' => (isset ($_POST['email_notifications']) ? $_POST['email_notifications'] : '')); - $db->edit_user ($data['about'], $data['email'], Session::get_userid ()); + $db->edit_user ( + $data['about'], + $data['email'], + $data['email_notifications'], + Session::get_userid ()); // Update $_SESSION Session::set_property ('about', $data['about']); Session::set_property ('email', $data['email']); + Session::set_property ('email_notifications', $data['email_notifications']); header ('Location: ./user'); exit ();