Fix encoding issue in mail subject

This commit is contained in:
Frédéric Guillot
2014-08-17 09:15:38 -07:00
parent 658123a232
commit 44e91721b0
4 changed files with 43 additions and 15 deletions

View File

@@ -46,6 +46,17 @@ class Translator
self::$enable_escaping = false; self::$enable_escaping = false;
} }
/**
* Enable HTML escaping for translations
*
* @static
* @access public
*/
public static function enableEscaping()
{
self::$enable_escaping = true;
}
/** /**
* Get a translation * Get a translation
* *

View File

@@ -2,6 +2,7 @@
namespace Model; namespace Model;
use Core\Translator;
use Core\Template; use Core\Template;
use Event\TaskNotificationListener; use Event\TaskNotificationListener;
use Event\CommentNotificationListener; use Event\CommentNotificationListener;
@@ -114,30 +115,46 @@ class Notification extends Base
*/ */
public function getMailSubject($template, array $data) public function getMailSubject($template, array $data)
{ {
Translator::disableEscaping();
switch ($template) { switch ($template) {
case 'notification_file_creation': case 'notification_file_creation':
return t('[%s][New attachment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); $subject = t('[%s][New attachment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_comment_creation': case 'notification_comment_creation':
return t('[%s][New comment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); $subject = t('[%s][New comment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_comment_update': case 'notification_comment_update':
return t('[%s][Comment updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); $subject = t('[%s][Comment updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_subtask_creation': case 'notification_subtask_creation':
return t('[%s][New subtask] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); $subject = t('[%s][New subtask] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_subtask_update': case 'notification_subtask_update':
return t('[%s][Subtask updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); $subject = t('[%s][Subtask updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_creation': case 'notification_task_creation':
return t('[%s][New task] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); $subject = t('[%s][New task] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_update': case 'notification_task_update':
return t('[%s][Task updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); $subject = t('[%s][Task updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_close': case 'notification_task_close':
return t('[%s][Task closed] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); $subject = t('[%s][Task closed] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_open': case 'notification_task_open':
return t('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); $subject = t('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_due': case 'notification_task_due':
return t('[%s][Due tasks]', $data['project']); $subject = t('[%s][Due tasks]', $data['project']);
break;
default:
$subject = t('[Kanboard] Notification');
} }
return t('[Kanboard] Notification'); Translator::enableEscaping();
return $subject;
} }
/** /**

View File

@@ -11,13 +11,13 @@
<?php endif ?> <?php endif ?>
<?php if ($task['creator_username']): ?> <?php if ($task['creator_username']): ?>
<li> <li>
<?= t('Created by %s', $task['creator_username']) ?> <?= t('Created by %s', $task['creator_name'] ?: $task['creator_username']) ?>
</li> </li>
<?php endif ?> <?php endif ?>
<li> <li>
<strong> <strong>
<?php if ($task['assignee_username']): ?> <?php if ($task['assignee_username']): ?>
<?= t('Assigned to %s', $task['assignee_username']) ?> <?= t('Assigned to %s', $task['assignee_name'] ?: $task['assignee_username']) ?>
<?php else: ?> <?php else: ?>
<?= t('There is nobody assigned') ?> <?= t('There is nobody assigned') ?>
<?php endif ?> <?php endif ?>

View File

@@ -11,13 +11,13 @@
<?php endif ?> <?php endif ?>
<?php if ($task['creator_username']): ?> <?php if ($task['creator_username']): ?>
<li> <li>
<?= t('Created by %s', $task['creator_username']) ?> <?= t('Created by %s', $task['creator_name'] ?: $task['creator_username']) ?>
</li> </li>
<?php endif ?> <?php endif ?>
<li> <li>
<strong> <strong>
<?php if ($task['assignee_username']): ?> <?php if ($task['assignee_username']): ?>
<?= t('Assigned to %s', $task['assignee_username']) ?> <?= t('Assigned to %s', $task['assignee_name'] ?: $task['assignee_username']) ?>
<?php else: ?> <?php else: ?>
<?= t('There is nobody assigned') ?> <?= t('There is nobody assigned') ?>
<?php endif ?> <?php endif ?>