home » zplus/freepost.git
Author zPlus <--> 2016-10-08 12:51:52
Committer zPlus <--> 2016-10-08 12:51:52
Commit 158cdde (patch)
Tree b9d4ce2
Parent(s)

Add email notifications (not working yet, only the base structure)


commits diff: 9639111..158cdde
9 files changed, 115 insertions, 16 deletionsdownload


Diffstat
-rw-r--r-- config.php 3
-rw-r--r-- css/freepost.css 19
-rw-r--r-- database.php 51
-rw-r--r-- login_reset.php 2
-rw-r--r-- post.php 24
-rw-r--r-- session.php 13
-rw-r--r-- template/email/new_comment.twig 3
-rw-r--r-- template/user.twig 6
-rw-r--r-- user.php 10

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+3/-0 M   config.php
index 2d90bd5..46693c0
old size: 300B - new size: 349B
@@ -1,10 +1,13 @@
1 1 <?php
2 2
3 3 class Config {
4 +
4 5 public static $DATABASE = array (
5 6 // Data Source Name, contains the information required to connect to the database
6 7 'dsn' => 'mysql:host=localhost;dbname=freepost;charset=utf8',
7 8 'username' => 'freepost',
8 9 'password' => 'freepost'
9 10 );
11 +
12 + public static $SEND_EMAILS = true;
10 13 }
10 13 = \ No newline at end of file

+15/-4 M   css/freepost.css
index 5695d0b..58ad06c
old size: 11K - new size: 12K
@@ -14,6 +14,12 @@ img
14 14 max-width: 100%;
15 15 }
16 16
17 + label
18 + {
19 + cursor: pointer;
20 + font-weight: normal;
21 + }
22 +
17 23 html, body
18 24 {
19 25 background-color: #fff; /* #f5f8fa; */
@@ -309,7 +315,7 @@ html, body
309 315 width: 80%;
310 316 }
311 317
312 - .content table.user td:first-child
318 + .content table.user tr > td:first-child
313 319 {
314 320 font-weight: bold;
315 321 text-align: right;
@@ -317,11 +323,16 @@ html, body
317 323 width: 30%;
318 324 }
319 325
320 - .content table.user td:last-child
326 + .content table.user tr > td:last-child
321 327 {
322 - text-align: left;
328 + text-align: left;
323 329 }
324 -
330 +
331 + .content table.user tr > td:last-child label
332 + {
333 + padding: 1em 0;
334 + }
335 +
325 336 /* User activity */
326 337 .content > .user_activity
327 338 {

+49/-2 M   database.php
index 3e99aa4..22911c2
old size: 39K - new size: 40K
@@ -250,6 +250,29 @@ class Database
250 250 }
251 251
252 252 /**
253 + * Retrieve the user of a specific post
254 + */
255 + function get_post_op ($post_hash_id)
256 + {
257 + $user = array();
258 +
259 + if (is_null ($this->database))
260 + return $user;
261 +
262 + $query = $this->database->prepare(
263 + 'SELECT U.* ' .
264 + 'FROM `user` AS U ' .
265 + 'JOIN `post` AS P ON P.`userId` = U.`id` ' .
266 + 'WHERE P.`hashId` = ?');
267 +
268 + $query->execute (array ($post_hash_id));
269 +
270 + $user = $query->fetch (PDO::FETCH_ASSOC);
271 +
272 + return $user;
273 + }
274 +
275 + /**
253 276 * Retrieve all comments for a specific post
254 277 */
255 278 function get_post_comments ($post_id)
@@ -316,6 +339,29 @@ class Database
316 339 }
317 340
318 341 /**
342 + * Retrieve the user of a specific comment
343 + */
344 + function get_comment_op ($comment_hash_id)
345 + {
346 + $user = array();
347 +
348 + if (is_null ($this->database))
349 + return $user;
350 +
351 + $query = $this->database->prepare(
352 + 'SELECT U.* ' .
353 + 'FROM `user` AS U ' .
354 + 'JOIN `comment` AS C ON C.`userId` = U.`id` ' .
355 + 'WHERE C.`hashId` = ?');
356 +
357 + $query->execute (array ($comment_hash_id));
358 +
359 + $user = $query->fetch (PDO::FETCH_ASSOC);
360 +
361 + return $user;
362 + }
363 +
364 + /**
319 365 * Return the number of unread messages
320 366 */
321 367 function count_unread_messages ($user_id)
@@ -820,15 +866,16 @@ class Database
820 866 /**
821 867 * Update user information
822 868 */
823 - function edit_user ($about, $email, $user_id)
869 + function edit_user ($about, $email, $email_notifications, $user_id)
824 870 {
825 871 $query = $this->database->prepare (
826 872 'UPDATE `user`' .
827 - 'SET `about` = :about, `email` = :email ' .
873 + 'SET `about` = :about, `email` = :email, `email_notifications` = :email_notifications ' .
828 874 'WHERE `id` = :user_id');
829 875
830 876 $query->bindValue (':about', $about, PDO::PARAM_STR);
831 877 $query->bindValue (':user_id', $user_id, PDO::PARAM_INT);
878 + $query->bindValue (':email_notifications', $email_notifications, PDO::PARAM_INT);
832 879
833 880 if (NULL == $email || '' == $email)
834 881 $query->bindValue (':email', NULL, PDO::PARAM_NULL);

+1/-1 M   login_reset.php
index 549316b..652172f
old size: 3K - new size: 3K
@@ -45,7 +45,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST')
45 45 if (!is_null ($token))
46 46 {
47 47 mail ($user['email'],
48 - 'Freepost Password Reset',
48 + 'freepost: password reset',
49 49 $twig->render ('login_reset_email.twig', array ('token' => $token)),
50 50 'From: freepost <noreply@freepo.st>' . "\r\n" . 'Reply-To: freepost <noreply@freepo.st>');
51 51 }

+23/-1 M   post.php
index da262c9..2be025e
old size: 2K - new size: 3K
@@ -1,6 +1,7 @@
1 1 <?php
2 2
3 3 require_once 'session.php';
4 + require_once 'config.php';
4 5 require_once 'database.php';
5 6 require_once 'date.php';
6 7 require_once 'twig.php';
@@ -46,8 +47,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST')
46 47
47 48 $db->new_comment ($comment, $post_hash_id, Session::get_userid());
48 49
50 + /* Send email notification for the new comment
51 + * $post_op is the post's original poster
52 + */
53 + /*
54 + if (Config::$SEND_EMAILS)
55 + {
56 + $post = $db->get_post ($post_hash_id);
57 + $post_op = $db->get_post_op ($post_hash_id);
58 +
59 + if ($post_op['email_notifications'])
60 + mail ($post_op['email'],
61 + 'freepost: new comment to one of your posts',
62 + $twig->render ('email/new_comment.twig', array (
63 + 'commenter' => Session::get_username (),
64 + 'post' => $post['title']
65 + )),
66 + 'From: freepost <noreply@freepo.st>' . "\r\n" . 'Reply-To: freepost <noreply@freepo.st>');
67 + }
68 + */
69 +
49 70 header ('Location: ./' . $post_hash_id);
50 - exit();
71 +
72 + exit ();
51 73 }
52 74
53 75

+7/-6 M   session.php
index 5a3abe2..f1d25ea
old size: 3K - new size: 3K
@@ -45,12 +45,13 @@ class Session {
45 45 // Set session variable
46 46 $_SESSION = array (
47 47 'user' => array (
48 - 'id' => $user['id'],
49 - 'hash_id' => $user['hashId'],
50 - 'email' => $user['email'],
51 - 'registered' => $user['registered'],
52 - 'name' => $user['username'],
53 - 'about' => $user['about']));
48 + 'id' => $user['id'],
49 + 'hash_id' => $user['hashId'],
50 + 'email' => $user['email'],
51 + 'email_notifications' => $user['email_notifications'],
52 + 'registered' => $user['registered'],
53 + 'name' => $user['username'],
54 + 'about' => $user['about']));
54 55 }
55 56
56 57 /**

+3/-0 A   template/email/new_comment.twig
index 0000000..358a755
old size: 0B - new size: 124B
new file mode: -rw-r--r--
@@ -0,0 +1,3 @@
1 + {{ commenter }} has posted a new comment to "{{ post }}".
2 +
3 + Check all new comments at https://freepo.st/user_activity/replies
3 < \ No newline at end of file

+6/-0 M   template/user.twig
index 22933d6..c318741
old size: 2K - new size: 3K
@@ -42,6 +42,12 @@
42 42 <td>
43 43 <input type="text" name="email" class="form-control" value="{{ user.email }}" />
44 44 <em>Required if you wish to change your password</em>
45 + <p>
46 + <label>
47 + <input type="checkbox" name="email_notifications" {{ user.email_notifications ? 'checked="checked"' }} />
48 + Send notifications via email
49 + </label>
50 + </p>
45 51 </td>
46 52 </tr>
47 53

+8/-2 M   user.php
index 3feb93e..ed01610
old size: 1K - new size: 2K
@@ -24,13 +24,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST')
24 24 // Update database with new user information
25 25 $data = array(
26 26 'about' => (isset ($_POST['about']) ? $_POST['about'] : ''),
27 - 'email' => (isset ($_POST['email']) ? $_POST['email'] : ''));
27 + 'email' => (isset ($_POST['email']) ? $_POST['email'] : ''),
28 + 'email_notifications' => (isset ($_POST['email_notifications']) ? $_POST['email_notifications'] : ''));
28 29
29 - $db->edit_user ($data['about'], $data['email'], Session::get_userid ());
30 + $db->edit_user (
31 + $data['about'],
32 + $data['email'],
33 + $data['email_notifications'],
34 + Session::get_userid ());
30 35
31 36 // Update $_SESSION
32 37 Session::set_property ('about', $data['about']);
33 38 Session::set_property ('email', $data['email']);
39 + Session::set_property ('email_notifications', $data['email_notifications']);
34 40
35 41 header ('Location: ./user');
36 42 exit ();