From fdee23af99de3006d480edf04ce1ee17c71b4b71 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 17 Nov 2013 20:30:04 +0100 Subject: [PATCH] Small changes - Changed: rating posts - [up | down] --> [vote up, down] - Fixed: logging of e-mail subject - Improved: flagging posts/users provides visual feedback ("flagged") - Improved: grammar in login screen - Fixed: typo in password reset message - Added: SessionHelper for handy management of user session data --- src/Controllers/PostController.php | 13 ++++++++----- src/Controllers/UserController.php | 19 +++++++++++-------- src/Helpers/SessionHelper.php | 15 +++++++++++++++ src/Helpers/TextHelper.php | 15 +++++++++++++++ src/Views/auth-login.phtml | 2 +- src/Views/post-view.phtml | 16 +++++++++++----- src/Views/user-view.phtml | 12 +++++++++--- 7 files changed, 70 insertions(+), 22 deletions(-) create mode 100644 src/Helpers/SessionHelper.php diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index e75925d1..8e5b6bc7 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -484,13 +484,13 @@ class PostController if (InputHelper::get('submit')) { - $key = '@' . $post->id; + $key = TextHelper::reprPost($post); - if (!isset($_SESSION['flagged'])) - $_SESSION['flagged'] = []; - if (in_array($key, $_SESSION['flagged'])) + $flagged = SessionHelper::get('flagged', []); + if (in_array($key, $flagged)) throw new SimpleException('You already flagged this post'); - $_SESSION['flagged'] []= $key; + $flagged []= $key; + SessionHelper::set('flagged', $flagged); LogHelper::logEvent('post-flag', '**+{user} flagged @{post} for moderator attention**', ['post' => $post->id]); StatusHelper::success(); @@ -730,12 +730,15 @@ class PostController $score = intval($s->score); } + $flagged = in_array(TextHelper::reprPost($post), SessionHelper::get('flagged', [])); + $this->context->stylesheets []= 'post-view.css'; $this->context->stylesheets []= 'comment-small.css'; $this->context->scripts []= 'post-view.js'; $this->context->subTitle = 'showing @' . $post->id . ' – ' . join(', ', array_map(function($x) { return $x['name']; }, $post->sharedTag)); $this->context->favorite = $favorite; $this->context->score = $score; + $this->context->flagged = $flagged; $this->context->transport->post = $post; $this->context->transport->prevPostId = $prevPost ? $prevPost['id'] : null; $this->context->transport->nextPostId = $nextPost ? $nextPost['id'] : null; diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 4c97a35d..ec16c3fb 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -47,8 +47,8 @@ class UserController $headers []= sprintf('Content-Type: text/plain; charset=utf-8', $subject); $headers []= sprintf('X-Mailer: PHP/%s', phpversion()); $headers []= sprintf('X-Originating-IP: %s', $_SERVER['SERVER_ADDR']); - $subject = '=?UTF-8?B?' . base64_encode($subject) . '?='; - mail($recipientEmail, $subject, $body, implode("\r\n", $headers), '-f' . $senderEmail); + $encodedSubject = '=?UTF-8?B?' . base64_encode($subject) . '?='; + mail($recipientEmail, $encodedSubject, $body, implode("\r\n", $headers), '-f' . $senderEmail); LogHelper::logEvent('mail', 'Sending e-mail with subject "' . $subject . '" to ' . $recipientEmail); } @@ -148,13 +148,13 @@ class UserController if (InputHelper::get('submit')) { - $key = '+' . $user->name; + $key = TextHelper::reprUser($user); - if (!isset($_SESSION['flagged'])) - $_SESSION['flagged'] = []; - if (in_array($key, $_SESSION['flagged'])) + $flagged = SessionHelper::get('flagged', []); + if (in_array($key, $flagged)) throw new SimpleException('You already flagged this user'); - $_SESSION['flagged'] []= $key; + $flagged []= $key; + SessionHelper::set('flagged', $flagged); LogHelper::logEvent('user-flag', '**+{user} flagged +{subject} for moderator attention**', ['subject' => $user->name]); StatusHelper::success(); @@ -459,6 +459,9 @@ class UserController $page = max(1, min($pageCount, $page)); $posts = Model_Post::getEntities($query, $postsPerPage, $page); + $flagged = in_array(TextHelper::reprUser($user), SessionHelper::get('flagged', [])); + + $this->context->flagged = $flagged; $this->context->transport->user = $user; $this->context->transport->tab = $tab; $this->context->transport->paginator = new StdClass; @@ -637,7 +640,7 @@ class UserController R::store($dbUser); LogHelper::logEvent('user-pass-reset', '+{subject} just reset password', ['subject' => $dbUser->name]); - $message = 'Password reset successfuly. Your new password is **' . $randomPassword . '**.'; + $message = 'Password reset successful. Your new password is **' . $randomPassword . '**.'; StatusHelper::success($message); $this->context->user = $dbUser; diff --git a/src/Helpers/SessionHelper.php b/src/Helpers/SessionHelper.php new file mode 100644 index 00000000..3a2858cd --- /dev/null +++ b/src/Helpers/SessionHelper.php @@ -0,0 +1,15 @@ +id; + } + + public static function reprUser($user) + { + return '+' . $user->name; + } + + public static function reprTag($tag) + { + return '#' . $tag->name; + } + public static function encrypt($text) { $salt = \Chibi\Registry::getConfig()->main->salt; diff --git a/src/Views/auth-login.phtml b/src/Views/auth-login.phtml index 40819ec4..c48fc6c7 100644 --- a/src/Views/auth-login.phtml +++ b/src/Views/auth-login.phtml @@ -37,7 +37,7 @@ diff --git a/src/Views/post-view.phtml b/src/Views/post-view.phtml index 19246ad2..dd571b71 100644 --- a/src/Views/post-view.phtml +++ b/src/Views/post-view.phtml @@ -84,10 +84,10 @@ - up + vote up -  |  + ,  context->score === -1): ?> @@ -249,9 +249,15 @@
  • - - Flag for moderator attention - + context->flagged): ?> + + Flagged + + + + Flag for moderator attention + +
  • diff --git a/src/Views/user-view.phtml b/src/Views/user-view.phtml index 546541ae..a9de809d 100644 --- a/src/Views/user-view.phtml +++ b/src/Views/user-view.phtml @@ -67,9 +67,15 @@
  • - - Flag for moderator attention - + context->flagged): ?> + + Flagged + + + + Flag for moderator attention + +