Removed TextHelper hacks

This commit is contained in:
Marcin Kurczewski 2013-11-18 15:41:16 +01:00
parent 17bd7a7572
commit bf0e40683c
3 changed files with 13 additions and 16 deletions

View file

@ -20,7 +20,7 @@ class UserController
$senderName, $senderName,
$senderEmail, $senderEmail,
$recipientEmail, $recipientEmail,
$tokens) $linkActionName)
{ {
//prepare unique user token //prepare unique user token
do do
@ -36,8 +36,11 @@ class UserController
R::store($token); R::store($token);
\Chibi\Registry::getContext()->mailSent = true; \Chibi\Registry::getContext()->mailSent = true;
$tokens = [];
$tokens['host'] = $_SERVER['HTTP_HOST']; $tokens['host'] = $_SERVER['HTTP_HOST'];
$tokens['token'] = $tokenText; $tokens['token'] = $tokenText;
if ($linkActionName !== null)
$tokens['link'] = \Chibi\UrlHelper::route('user', $linkActionName, ['token' => $tokenText]);
$body = wordwrap(TextHelper::replaceTokens($body, $tokens), 70); $body = wordwrap(TextHelper::replaceTokens($body, $tokens), 70);
$subject = TextHelper::replaceTokens($subject, $tokens); $subject = TextHelper::replaceTokens($subject, $tokens);
@ -75,9 +78,6 @@ class UserController
return; return;
} }
$tokens = [];
$tokens['link'] = \Chibi\UrlHelper::route('user', 'activation', ['token' => '{token}']);
return self::sendTokenizedEmail( return self::sendTokenizedEmail(
$user, $user,
$regConfig->confirmationEmailBody, $regConfig->confirmationEmailBody,
@ -85,16 +85,13 @@ class UserController
$regConfig->confirmationEmailSenderName, $regConfig->confirmationEmailSenderName,
$regConfig->confirmationEmailSenderEmail, $regConfig->confirmationEmailSenderEmail,
$user->email_unconfirmed, $user->email_unconfirmed,
$tokens); 'activation');
} }
private static function sendPasswordResetConfirmation($user) private static function sendPasswordResetConfirmation($user)
{ {
$regConfig = \Chibi\Registry::getConfig()->registration; $regConfig = \Chibi\Registry::getConfig()->registration;
$tokens = [];
$tokens['link'] = \Chibi\UrlHelper::route('user', 'password-reset', ['token' => '{token}']);
return self::sendTokenizedEmail( return self::sendTokenizedEmail(
$user, $user,
$regConfig->passwordResetEmailBody, $regConfig->passwordResetEmailBody,
@ -102,7 +99,7 @@ class UserController
$regConfig->passwordResetEmailSenderName, $regConfig->passwordResetEmailSenderName,
$regConfig->passwordResetEmailSenderEmail, $regConfig->passwordResetEmailSenderEmail,
$user->email_confirmed, $user->email_confirmed,
$tokens); 'password-reset');
} }

View file

@ -77,12 +77,12 @@
<?php if (PrivilegesHelper::confirm(Privilege::ScorePost)): ?> <?php if (PrivilegesHelper::confirm(Privilege::ScorePost)): ?>
&nbsp;[ &nbsp;[
<?php $scoreLink = \Chibi\UrlHelper::route('post', 'score', ['id' => $this->context->transport->post->id, 'score' => '{score}']) ?> <?php $scoreLink = function($score) { return \Chibi\UrlHelper::route('post', 'score', ['id' => $this->context->transport->post->id, 'score' => $score]); } ?>
<?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 $scoreLink(0) ?>">
<?php else: ?> <?php else: ?>
<a class="simple-action" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => 1]) ?>"> <a class="simple-action" href="<?php echo $scoreLink(1) ?>">
<?php endif ?> <?php endif ?>
vote up vote up
</a> </a>
@ -90,9 +90,9 @@
,&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 $scoreLink(0) ?>">
<?php else: ?> <?php else: ?>
<a class="simple-action" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => -1]) ?>"> <a class="simple-action" href="<?php echo $scoreLink(-1) ?>">
<?php endif ?> <?php endif ?>
down down
</a>] </a>]

View file

@ -1,14 +1,14 @@
<?php $max = max([0]+array_map(function($x) { return $x['post_count']; }, $this->context->transport->tags)); ?> <?php $max = max([0]+array_map(function($x) { return $x['post_count']; }, $this->context->transport->tags)); ?>
<?php $add = 0.25 ?> <?php $add = 0.25 ?>
<?php $mul = 0.75 / max(1, log(max(1, $max))) ?> <?php $mul = 0.75 / max(1, log(max(1, $max))) ?>
<?php $url = \Chibi\UrlHelper::route('post', 'list', ['query' => '{query}']) ?> <?php $url = \Chibi\UrlHelper::route('post', 'list', ['query' => '_query_']) ?>
<div class="tags"> <div class="tags">
<ul> <ul>
<?php foreach ($this->context->transport->tags as $tag): ?> <?php foreach ($this->context->transport->tags as $tag): ?>
<?php $name = $tag['name'] ?> <?php $name = $tag['name'] ?>
<?php $count = $tag['post_count'] ?> <?php $count = $tag['post_count'] ?>
<li class="tag" title="<?php echo $name ?> (<?php echo $count ?>)"> <li class="tag" title="<?php echo $name ?> (<?php echo $count ?>)">
<a href="<?php echo TextHelper::replaceTokens($url, ['query' => $name]) ?>" style="opacity: <?php printf('%.02f', $add + $mul * log($count)) ?>"> <a href="<?php echo str_replace('_query_', $name, $url) ?>" style="opacity: <?php printf('%.02f', $add + $mul * log($count)) ?>">
<?php echo $name . ' (' . $count . ')' ?> <?php echo $name . ' (' . $count . ')' ?>
</a> </a>
</li> </li>