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
This commit is contained in:
Marcin Kurczewski 2013-11-17 20:30:04 +01:00
parent 3c41940142
commit fdee23af99
7 changed files with 70 additions and 22 deletions

View file

@ -484,13 +484,13 @@ class PostController
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
$key = '@' . $post->id; $key = TextHelper::reprPost($post);
if (!isset($_SESSION['flagged'])) $flagged = SessionHelper::get('flagged', []);
$_SESSION['flagged'] = []; if (in_array($key, $flagged))
if (in_array($key, $_SESSION['flagged']))
throw new SimpleException('You already flagged this post'); 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]); LogHelper::logEvent('post-flag', '**+{user} flagged @{post} for moderator attention**', ['post' => $post->id]);
StatusHelper::success(); StatusHelper::success();
@ -730,12 +730,15 @@ class PostController
$score = intval($s->score); $score = intval($s->score);
} }
$flagged = in_array(TextHelper::reprPost($post), SessionHelper::get('flagged', []));
$this->context->stylesheets []= 'post-view.css'; $this->context->stylesheets []= 'post-view.css';
$this->context->stylesheets []= 'comment-small.css'; $this->context->stylesheets []= 'comment-small.css';
$this->context->scripts []= 'post-view.js'; $this->context->scripts []= 'post-view.js';
$this->context->subTitle = 'showing @' . $post->id . ' – ' . join(', ', array_map(function($x) { return $x['name']; }, $post->sharedTag)); $this->context->subTitle = 'showing @' . $post->id . ' – ' . join(', ', array_map(function($x) { return $x['name']; }, $post->sharedTag));
$this->context->favorite = $favorite; $this->context->favorite = $favorite;
$this->context->score = $score; $this->context->score = $score;
$this->context->flagged = $flagged;
$this->context->transport->post = $post; $this->context->transport->post = $post;
$this->context->transport->prevPostId = $prevPost ? $prevPost['id'] : null; $this->context->transport->prevPostId = $prevPost ? $prevPost['id'] : null;
$this->context->transport->nextPostId = $nextPost ? $nextPost['id'] : null; $this->context->transport->nextPostId = $nextPost ? $nextPost['id'] : null;

View file

@ -47,8 +47,8 @@ class UserController
$headers []= sprintf('Content-Type: text/plain; charset=utf-8', $subject); $headers []= sprintf('Content-Type: text/plain; charset=utf-8', $subject);
$headers []= sprintf('X-Mailer: PHP/%s', phpversion()); $headers []= sprintf('X-Mailer: PHP/%s', phpversion());
$headers []= sprintf('X-Originating-IP: %s', $_SERVER['SERVER_ADDR']); $headers []= sprintf('X-Originating-IP: %s', $_SERVER['SERVER_ADDR']);
$subject = '=?UTF-8?B?' . base64_encode($subject) . '?='; $encodedSubject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
mail($recipientEmail, $subject, $body, implode("\r\n", $headers), '-f' . $senderEmail); mail($recipientEmail, $encodedSubject, $body, implode("\r\n", $headers), '-f' . $senderEmail);
LogHelper::logEvent('mail', 'Sending e-mail with subject "' . $subject . '" to ' . $recipientEmail); LogHelper::logEvent('mail', 'Sending e-mail with subject "' . $subject . '" to ' . $recipientEmail);
} }
@ -148,13 +148,13 @@ class UserController
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
$key = '+' . $user->name; $key = TextHelper::reprUser($user);
if (!isset($_SESSION['flagged'])) $flagged = SessionHelper::get('flagged', []);
$_SESSION['flagged'] = []; if (in_array($key, $flagged))
if (in_array($key, $_SESSION['flagged']))
throw new SimpleException('You already flagged this user'); 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]); LogHelper::logEvent('user-flag', '**+{user} flagged +{subject} for moderator attention**', ['subject' => $user->name]);
StatusHelper::success(); StatusHelper::success();
@ -459,6 +459,9 @@ class UserController
$page = max(1, min($pageCount, $page)); $page = max(1, min($pageCount, $page));
$posts = Model_Post::getEntities($query, $postsPerPage, $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->user = $user;
$this->context->transport->tab = $tab; $this->context->transport->tab = $tab;
$this->context->transport->paginator = new StdClass; $this->context->transport->paginator = new StdClass;
@ -637,7 +640,7 @@ class UserController
R::store($dbUser); R::store($dbUser);
LogHelper::logEvent('user-pass-reset', '+{subject} just reset password', ['subject' => $dbUser->name]); 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); StatusHelper::success($message);
$this->context->user = $dbUser; $this->context->user = $dbUser;

View file

@ -0,0 +1,15 @@
<?php
class SessionHelper
{
public static function get($key, $default = null)
{
if (!isset($_SESSION[$key]))
return $default;
return $_SESSION[$key];
}
public static function set($key, $value)
{
$_SESSION[$key] = $value;
}
}

View file

@ -180,6 +180,21 @@ class TextHelper
return $output; return $output;
} }
public static function reprPost($post)
{
return '@' . $post->id;
}
public static function reprUser($user)
{
return '+' . $user->name;
}
public static function reprTag($tag)
{
return '#' . $tag->name;
}
public static function encrypt($text) public static function encrypt($text)
{ {
$salt = \Chibi\Registry::getConfig()->main->salt; $salt = \Chibi\Registry::getConfig()->main->salt;

View file

@ -37,7 +37,7 @@
<ul> <ul>
<li><a href="<?php echo \Chibi\UrlHelper::route('user', 'password-reset-proxy') ?>">I don't remember my password</a></li> <li><a href="<?php echo \Chibi\UrlHelper::route('user', 'password-reset-proxy') ?>">I don't remember my password</a></li>
<li><a href="<?php echo \Chibi\UrlHelper::route('user', 'activation-proxy') ?>">I haven't received activation e-mail</a></li> <li><a href="<?php echo \Chibi\UrlHelper::route('user', 'activation-proxy') ?>">I haven't received activation e-mail</a></li>
<li><a href="<?php echo \Chibi\UrlHelper::route('user', 'registration') ?>">I don't have account</a></li> <li><a href="<?php echo \Chibi\UrlHelper::route('user', 'registration') ?>">I don't have an account</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View file

@ -84,10 +84,10 @@
<?php else: ?> <?php else: ?>
<a class="simple-action" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => 1]) ?>"> <a class="simple-action" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => 1]) ?>">
<?php endif ?> <?php endif ?>
up vote up
</a> </a>
&nbsp;|&nbsp; ,&nbsp;
<?php if ($this->context->score === -1): ?> <?php if ($this->context->score === -1): ?>
<a class="simple-action selected" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => 0]) ?>"> <a class="simple-action selected" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => 0]) ?>">
@ -249,9 +249,15 @@
<?php if (PrivilegesHelper::confirm(Privilege::FlagPost)): ?> <?php if (PrivilegesHelper::confirm(Privilege::FlagPost)): ?>
<li class="flag"> <li class="flag">
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'flag', ['id' => $this->context->transport->post->id]) ?>" data-confirm-text="Are you sure you want to flag this post?"> <?php if ($this->context->flagged): ?>
Flag for moderator attention <a class="simple-action inactive" href="#">
</a> Flagged
</a>
<?php else: ?>
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'flag', ['id' => $this->context->transport->post->id]) ?>" data-confirm-text="Are you sure you want to flag this post?">
Flag for moderator attention
</a>
<?php endif ?>
</li> </li>
<?php endif ?> <?php endif ?>

View file

@ -67,9 +67,15 @@
<?php if (PrivilegesHelper::confirm(Privilege::FlagUser)): ?> <?php if (PrivilegesHelper::confirm(Privilege::FlagUser)): ?>
<li class="flag"> <li class="flag">
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('user', 'flag', ['name' => $this->context->transport->user->name]) ?>" data-confirm-text="Are you sure you want to flag this user?"> <?php if ($this->context->flagged): ?>
Flag for moderator attention <a class="simple-action inactive" href="#">
</a> Flagged
</a>
<?php else: ?>
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('user', 'flag', ['name' => $this->context->transport->user->name]) ?>" data-confirm-text="Are you sure you want to flag this user?">
Flag for moderator attention
</a>
<?php endif ?>
</li> </li>
<?php endif ?> <?php endif ?>