Better handling of anonymous user names

This commit is contained in:
Marcin Kurczewski 2013-11-22 23:27:55 +01:00
parent ecc72e52e6
commit db602f08d3
5 changed files with 12 additions and 9 deletions

View file

@ -111,7 +111,7 @@ class AuthController
else else
{ {
$dummy = R::dispense('user'); $dummy = R::dispense('user');
$dummy->name = 'Anonymous'; $dummy->name = Model_User::getAnonymousName();
$dummy->access_rank = AccessRank::Anonymous; $dummy->access_rank = AccessRank::Anonymous;
$dummy->anonymous = true; $dummy->anonymous = true;
$_SESSION['user'] = serialize($dummy); $_SESSION['user'] = serialize($dummy);

View file

@ -211,7 +211,7 @@ class PostController
//log //log
LogHelper::bufferChanges(); LogHelper::bufferChanges();
$fmt = ($anonymous and !$this->config->misc->logAnonymousUploads) $fmt = ($anonymous and !$this->config->misc->logAnonymousUploads)
? 'someone' ? '{anon}'
: '{user}'; : '{user}';
$fmt .= ' added {post}'; $fmt .= ' added {post}';
LogHelper::logEvent('post-new', $fmt, ['post' => TextHelper::reprPost($post)]); LogHelper::logEvent('post-new', $fmt, ['post' => TextHelper::reprPost($post)]);

View file

@ -45,8 +45,11 @@ class LogHelper
public static function log($text, array $tokens = []) public static function log($text, array $tokens = [])
{ {
if (isset(self::$context->user)) $tokens['anon'] = Model_User::getAnonymousName();
if (self::$context->loggedIn and isset(self::$context->user))
$tokens['user'] = TextHelper::reprUser(self::$context->user->name); $tokens['user'] = TextHelper::reprUser(self::$context->user->name);
else
$tokens['user'] = $tokens['anon'];
$text = TextHelper::replaceTokens($text, $tokens); $text = TextHelper::replaceTokens($text, $tokens);

View file

@ -2,10 +2,10 @@
<div class="avatar"> <div class="avatar">
<?php if ($this->context->comment->commenter): ?> <?php if ($this->context->comment->commenter): ?>
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->comment->commenter->name]) ?>"> <a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->comment->commenter->name]) ?>">
<img src="<?php echo htmlspecialchars($this->context->comment->commenter->getAvatarUrl(40)) ?>" alt="<?php echo $this->context->comment->commenter->name ?: '[unknown user]' ?>"/> <img src="<?php echo htmlspecialchars($this->context->comment->commenter->getAvatarUrl(40)) ?>" alt="<?php echo $this->context->comment->commenter->name ?>"/>
</a> </a>
<?php else: ?> <?php else: ?>
<img src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="[unknown user]"> <img src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="<?php echo Model_User::getAnonymousName() ?>">
<?php endif ?> <?php endif ?>
</div> </div>
@ -17,7 +17,7 @@
<?php echo $this->context->comment->commenter->name ?> <?php echo $this->context->comment->commenter->name ?>
</a> </a>
<?php else: ?> <?php else: ?>
[unknown user] <?php echo Model_User::getAnonymousName() ?>
<?php endif ?> <?php endif ?>
</span> </span>

View file

@ -56,9 +56,9 @@
</a> </a>
</span> </span>
<?php else: ?> <?php else: ?>
<span class="value" title="[unknown user]"> <span class="value" title="<?php echo Model_User::getAnonymousName() ?>">
<img src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="[unknown user]"/> <img src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="<?php echo Model_User::getAnonymousName() ?>"/>
[unknown user] <?php echo Model_User::getAnonymousName() ?>
</span> </span>
<?php endif ?> <?php endif ?>
</div> </div>