Merge pull request #1473 from dakur/master

Multipart e-mail messages
This commit is contained in:
Lucas Bartholemy 2016-02-12 12:27:54 +01:00
commit 5a8655e3e2
36 changed files with 339 additions and 22 deletions

View File

@ -26,7 +26,7 @@ class Module extends \humhub\components\Module
public function getMailUpdate(User $user, $interval)
{
$output = "";
$output = ['html' => '', 'plaintext' => ''];
$receive_email_activities = $user->getSetting("receive_email_activities", 'core', Setting::Get('receive_email_activities', 'mailing'));
@ -68,7 +68,8 @@ class Module extends \humhub\components\Module
foreach ($stream->getWallEntries() as $wallEntry) {
try {
$activity = $wallEntry->content->getPolymorphicRelation();
$output .= $activity->getActivityBaseClass()->render(BaseActivity::OUTPUT_MAIL);
$output['html'] .= $activity->getActivityBaseClass()->render(BaseActivity::OUTPUT_MAIL);
$output['plaintext'] .= $activity->getActivityBaseClass()->render(BaseActivity::OUTPUT_MAIL_PLAINTEXT);
} catch (\yii\base\Exception $ex) {
\Yii::error($ex->getMessage());
}

View File

@ -26,6 +26,7 @@ class BaseActivity extends \yii\base\Component
const OUTPUT_WEB = 'web';
const OUTPUT_MAIL = 'mail';
const OUTPUT_MAIL_PLAINTEXT = 'mail_plaintext';
/**
* The source object/record which created this activity
@ -74,6 +75,13 @@ class BaseActivity extends \yii\base\Component
*/
protected $layoutMail = "@humhub/modules/activity/views/layouts/mail.php";
/**
* Layout file for mail plaintext version
*
* @var string
*/
protected $layoutMailPlaintext = "@humhub/modules/notification/views/layouts/mail_plaintext.php";
/**
* The actvity record this belongs to
*
@ -120,8 +128,8 @@ class BaseActivity extends \yii\base\Component
$viewFile = $this->getViewPath() . '/' . $this->viewName . '.php';
// Switch to extra mail view file - if exists (otherwise use web view)
if ($mode == self::OUTPUT_MAIL) {
$viewMailFile = $this->getViewPath() . '/mail/' . $this->viewName . '.php';
if ($mode == self::OUTPUT_MAIL || $mode == self::OUTPUT_MAIL_PLAINTEXT) {
$viewMailFile = $this->getViewPath() . '/mail/' . ($mode == self::OUTPUT_MAIL_PLAINTEXT ? 'plaintext/' : '') . $this->viewName . '.php';
if (file_exists($viewMailFile)) {
$viewFile = $viewMailFile;
}
@ -129,7 +137,7 @@ class BaseActivity extends \yii\base\Component
$params['content'] = Yii::$app->getView()->renderFile($viewFile, $params, $this);
return Yii::$app->getView()->renderFile(($mode == self::OUTPUT_WEB) ? $this->layoutWeb : $this->layoutMail, $params, $this);
return Yii::$app->getView()->renderFile(($mode == self::OUTPUT_WEB) ? $this->layoutWeb : ($mode == self::OUTPUT_MAIL_PLAINTEXT ? $this->layoutMailPlaintext : $this->layoutMail), $params, $this);
}
/**

View File

@ -0,0 +1,12 @@
<?php
use yii\helpers\Html;
?>
<?php echo $content; ?>
<?php if (isset($record->content->space) && $record->content->space !== null): ?>(<?php echo strip_tags(Yii::t('ActivityModule.views_activityLayoutMail', 'via')); ?> <?php echo Html::encode($record->content->space->name); ?>)
<?php endif; ?><?php if ($url != "") : ?><?php echo strip_tags(Yii::t('ActivityModule.views_activityLayoutMail', 'see online')); ?>: <?php echo urldecode($url); ?><?php endif; ?>

View File

@ -82,7 +82,7 @@ class ApprovalController extends Controller
Kind Regards<br>
{AdminName}<br><br>', array(
'{displayName}' => Html::encode($user->displayName),
'{loginURL}' => Url::to(["/user/auth/login"], true),
'{loginURL}' => urldecode(Url::to(["/user/auth/login"], true)),
'{AdminName}' => Yii::$app->user->getIdentity()->displayName,
));

View File

@ -0,0 +1,11 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('CommentModule.views_activities_CommentCreated', "%displayName% wrote a new comment ", array(
'%displayName%' => Html::encode($originator->displayName)
)));
?>
"<?= strip_tags(\humhub\widgets\RichText::widget(['text' => $source->message, 'minimal' => true])); ?>"

View File

@ -0,0 +1,14 @@
<?php
use yii\helpers\Html;
$commentedObject = $source->content->getPolymorphicRelation();
?>
<?php
echo strip_tags(Yii::t('CommentModule.views_notifications_newCommented', "%displayName% commented %contentTitle%.", array(
'%displayName%' => Html::encode($source->user->displayName),
'%contentTitle%' => $this->context->getContentInfo($commentedObject)
)));
?>
"<?php echo strip_tags(humhub\widgets\RichText::widget(['text' => $source->message, 'minimal' => true, 'maxLength' => 400])); ?>"

View File

@ -10,6 +10,7 @@ namespace humhub\modules\content;
use Yii;
use humhub\modules\content\models\Content;
use humhub\modules\notification\components\BaseNotification;
use humhub\modules\user\models\User;
use humhub\commands\CronController;
use humhub\models\Setting;
@ -159,12 +160,17 @@ class Events extends \yii\base\Object
$notifications = Yii::$app->getModule('notification')->getMailUpdate($user, $interval);
$activities = Yii::$app->getModule('activity')->getMailUpdate($user, $interval);
if ($notifications != "" || $activities != "") {
if ((is_array($notifications) && isset($notifications['html']) && $notifications['html'] != "") || (is_array($activities) && isset($activities['html']) && $activities['html'] != "")) {
try {
$mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/content/views/mails/Update'], [
'activities' => $activities,
'notifications' => $notifications
$mail = Yii::$app->mailer->compose([
'html' => '@humhub/modules/content/views/mails/Update',
'text' => '@humhub/modules/content/views/mails/plaintext/Update'
], [
'activities' => (isset($activities['html']) ? $activities['html'] : ''),
'activities_plaintext' => (isset($activities['plaintext']) ? $activities['plaintext'] : ''),
'notifications' => (isset($notifications['html']) ? $notifications['html'] : ''),
'notifications_plaintext' => (isset($notifications['plaintext']) ? $notifications['plaintext'] : ''),
]);
$mail->setFrom([Setting::Get('systemEmailAddress', 'mailing') => Setting::Get('systemEmailName', 'mailing')]);
$mail->setTo($user->email);

View File

@ -8,4 +8,4 @@ echo Yii::t('ContentModule.activities_views_created', '{displayName} created a n
));
?>
<br />
<em>"<?php echo \humhub\widgets\RichText::widget(['text' => $source->getContentDescription(), 'minimal' => true]); ?>"</em>
<em>"<?php echo \humhub\widgets\RichText::widget(['text' => $source->getContentDescription(), 'minimal' => true]); ?>"</em>

View File

@ -0,0 +1,11 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('ContentModule.activities_views_created', '{displayName} created a new {contentTitle}.', array(
'{displayName}' => Html::encode($originator->displayName),
'{contentTitle}' => html_entity_decode(Html::encode($source->getContentName()))
)));
?>
"<?php echo strip_tags(\humhub\widgets\RichText::widget(['text' => $source->getContentDescription(), 'minimal' => true])); ?>"

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('ContentModule.notifications_views_ContentCreated', '{userName} created a new {contentTitle}.', array(
'{userName}' => Html::encode($originator->displayName),
'{contentTitle}' => $this->context->getContentInfo($source)
)));
?>

View File

@ -0,0 +1,12 @@
<?php echo strip_tags(Yii::t('base', '<strong>Latest</strong> updates')); ?>
<?php
if ($notifications_plaintext != '') {
echo $notifications_plaintext;
} else if ($activities_plaintext != '') {
echo $activities_plaintext;
}
?>

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('LikeModule.views_activities_Like', '{userDisplayName} likes {contentTitle}', array(
'{userDisplayName}' => Html::encode($originator->displayName),
'{contentTitle}' => $preview,
)));
?>

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('LikeModule.views_notifications_newLike', "%displayName% likes %contentTitle%.", array(
'%displayName%' => Html::encode($originator->displayName),
'%contentTitle%' => $this->context->getContentInfo($source->content->getPolymorphicRelation())
)));
?>

View File

@ -19,7 +19,7 @@ class Module extends \humhub\components\Module
public function getMailUpdate(User $user, $interval)
{
$output = "";
$output = ['html' => '', 'plaintext' => ''];
$receive_email_notifications = $user->getSetting("receive_email_notifications", 'core', Setting::Get('receive_email_notifications', 'mailing'));
@ -48,12 +48,13 @@ class Module extends \humhub\components\Module
}
}
$query = Notification::find()->where(['user_id' => $user->id])->andWhere(['!=', 'seen', 1])->andWhere(['!=', 'emailed', 1]);
foreach ($query->all() as $notification) {
$output .= $notification->getClass()->render(BaseNotification::OUTPUT_MAIL);
$output['html'] .= $notification->getClass()->render(BaseNotification::OUTPUT_MAIL);
$output['plaintext'] .= $notification->getClass()->render(BaseNotification::OUTPUT_MAIL_PLAINTEXT);
$notification->emailed = 1;
$notification->save();
}

View File

@ -28,6 +28,7 @@ class BaseNotification extends \yii\base\Component implements ViewContextInterfa
const OUTPUT_WEB = 'web';
const OUTPUT_MAIL = 'mail';
const OUTPUT_MAIL_PLAINTEXT = 'mail_plaintext';
const OUTPUT_TEXT = 'text';
/**
@ -73,6 +74,13 @@ class BaseNotification extends \yii\base\Component implements ViewContextInterfa
*/
protected $layoutMail = "@humhub/modules/notification/views/layouts/mail.php";
/**
* Layout file for mail plaintext version
*
* @var string
*/
protected $layoutMailPlaintext = "@humhub/modules/notification/views/layouts/mail_plaintext.php";
/**
* The notification record this notification belongs to
*
@ -107,8 +115,8 @@ class BaseNotification extends \yii\base\Component implements ViewContextInterfa
$viewFile = $this->getViewPath() . '/' . $this->viewName . '.php';
// Switch to extra mail view file - if exists (otherwise use web view)
if ($mode == self::OUTPUT_MAIL) {
$viewMailFile = $this->getViewPath() . '/mail/' . $this->viewName . '.php';
if ($mode == self::OUTPUT_MAIL || $mode == self::OUTPUT_MAIL_PLAINTEXT) {
$viewMailFile = $this->getViewPath() . '/mail/' . ($mode == self::OUTPUT_MAIL_PLAINTEXT ? 'plaintext/' : '') . $this->viewName . '.php';
if (file_exists($viewMailFile)) {
$viewFile = $viewMailFile;
}
@ -119,7 +127,7 @@ class BaseNotification extends \yii\base\Component implements ViewContextInterfa
$params['content'] = Yii::$app->getView()->renderFile($viewFile, $params, $this);
return Yii::$app->getView()->renderFile(($mode == self::OUTPUT_WEB) ? $this->layoutWeb : $this->layoutMail, $params, $this);
return Yii::$app->getView()->renderFile(($mode == self::OUTPUT_WEB) ? $this->layoutWeb : ($mode == self::OUTPUT_MAIL_PLAINTEXT ? $this->layoutMailPlaintext : $this->layoutMail), $params, $this);
}
/**

View File

@ -0,0 +1,13 @@
<?php
use yii\helpers\Html;
use humhub\models\Setting;
?>
<?php echo $content; ?>
<?php if (isset($space) && $space !== null): ?>(<?php echo strip_tags(Yii::t('NotificationModule.views_notificationLayoutMail', 'via')); ?> <?php echo Html::encode($space->name); ?>)
<?php endif; ?><?php echo strip_tags(Yii::t('NotificationModule.views_notificationLayoutMail', 'see online')); ?>: <?php echo urldecode($url); ?>

View File

@ -0,0 +1,10 @@
<?php
use yii\helpers\Html;
use humhub\libs\Helpers;
echo strip_tags(Yii::t('ActivityModule.views_activities_ActivitySpaceCreated', "%displayName% created the new space %spaceName%", array(
'%displayName%' => Html::encode($originator->displayName),
'%spaceName%' => '"' . Html::encode(Helpers::truncateText($source->name, 25)) . '"'
)));
?>

View File

@ -0,0 +1,10 @@
<?php
use yii\helpers\Html;
use humhub\libs\Helpers;
echo strip_tags(Yii::t('ActivityModule.views_activities_ActivitySpaceMemberAdded', "%displayName% joined the space %spaceName%", array(
'%displayName%' => Html::encode($originator->displayName),
'%spaceName%' => '"' . Html::encode(Helpers::truncateText($source->name, 40)) . '"'
)));
?>

View File

@ -0,0 +1,10 @@
<?php
use yii\helpers\Html;
use humhub\libs\Helpers;
echo strip_tags(Yii::t('ActivityModule.views_activities_ActivitySpaceMemberRemoved', "%displayName% left the space %spaceName%", array(
'%displayName%' => Html::encode($originator->displayName),
'%spaceName%' => '"' . Html::encode(Helpers::truncateText($source->name, 40)) . '"'
)));
?>

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('SpaceModule.views_notifications_approvalRequest', '{userName} requests membership for the space {spaceName}', array(
'{userName}' => Html::encode($originator->displayName),
'{spaceName}' => Html::encode($source->name)
)));
?>

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('SpaceModule.views_notifications_approvalRequestAccepted', '{userName} approved your membership for the space {spaceName}', array(
'{userName}' => Html::encode($originator->displayName),
'{spaceName}' => Html::encode($source->name)
)));
?>

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('SpaceModule.views_notifications_approvalRequestDeclined', '{userName} declined your membership request for the space {spaceName}', array(
'{userName}' => Html::encode($originator->displayName),
'{spaceName}' => Html::encode($source->name)
)));
?>

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('SpaceModule.views_notifications_invite', '{userName} invited you to the space {spaceName}', array(
'{userName}' => Html::encode($originator->displayName),
'{spaceName}' => Html::encode($source->name)
)));
?>

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('SpaceModule.views_notifications_inviteAccepted', '{userName} accepted your invite for the space {spaceName}', array(
'{userName}' => Html::encode($originator->displayName),
'{spaceName}' => Html::encode($source->name)
)));
?>

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('SpaceModule.views_notifications_inviteDeclined', '{userName} declined your invite for the space {spaceName}', array(
'{userName}' => Html::encode($originator->displayName),
'{spaceName}' => Html::encode($source->name)
)));
?>

View File

@ -0,0 +1,10 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('ActivityModule.views_activities_ActivityUserFollowsUser', '{user1} now follows {user2}.', array(
'{user1}' => Html::encode($originator->displayName),
'{user2}' => Html::encode($source->getTarget()->displayName),
)));
?>

View File

@ -99,7 +99,10 @@ class Invite extends \yii\db\ActiveRecord
// User requested registration link by its self
if ($this->source == self::SOURCE_SELF) {
$mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/UserInviteSelf'], ['token' => $this->token]);
$mail = Yii::$app->mailer->compose([
'html' => '@humhub/modules/user/views/mails/UserInviteSelf',
'text' => '@humhub/modules/user/views/mails/plaintext/UserInviteSelf'
], ['token' => $this->token]);
$mail->setFrom([\humhub\models\Setting::Get('systemEmailAddress', 'mailing') => \humhub\models\Setting::Get('systemEmailName', 'mailing')]);
$mail->setTo($this->email);
$mail->setSubject(Yii::t('UserModule.views_mails_UserInviteSelf', 'Registration Link'));
@ -109,7 +112,10 @@ class Invite extends \yii\db\ActiveRecord
// Switch to systems default language
Yii::$app->language = \humhub\models\Setting::Get('defaultLanguage');
$mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/UserInviteSpace'], [
$mail = Yii::$app->mailer->compose([
'html' => '@humhub/modules/user/views/mails/UserInviteSpace',
'text' => '@humhub/modules/user/views/mails/plaintext/UserInviteSpace'
], [
'token' => $this->token,
'originator' => $this->originator,
'originatorName' => $this->originator->displayName,

View File

@ -72,7 +72,10 @@ class AccountChangeEmail extends \yii\base\Model
$token = md5(Setting::Get('secret') . $user->guid . $this->newEmail);
$mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/ChangeEmail'], [
$mail = Yii::$app->mailer->compose([
'html' => '@humhub/modules/user/views/mails/ChangeEmail',
'text' => '@humhub/modules/user/views/mails/plaintext/ChangeEmail'
], [
'user' => $user,
'newEmail' => $this->newEmail,
'approveUrl' => Url::to(["/user/account/change-email-validate", 'email' => $this->newEmail, 'token' => $token], true)

View File

@ -75,7 +75,10 @@ class AccountRecoverPassword extends \yii\base\Model
$token = \humhub\libs\UUID::v4();
$user->setSetting('passwordRecoveryToken', $token . '.' . time(), 'user');
$mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/RecoverPassword'], [
$mail = Yii::$app->mailer->compose([
'html' => '@humhub/modules/user/views/mails/RecoverPassword',
'text' => '@humhub/modules/user/views/mails/plaintext/RecoverPassword'
], [
'user' => $user,
'linkPasswordReset' => Url::to(["/user/auth/reset-password", 'token' => $token, 'guid' => $user->guid], true)
]);

View File

@ -0,0 +1,8 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('UserModule.views_notifications_follow', '{userName} is now following you.', array(
'{userName}' => Html::encode($originator->displayName),
)));
?>

View File

@ -0,0 +1,9 @@
<?php
use yii\helpers\Html;
echo strip_tags(Yii::t('UserModule.views_notifications_Mentioned', '{userName} mentioned you in {contentTitle}.', array(
'{userName}' => Html::encode($originator->displayName),
'{contentTitle}' => $this->context->getContentInfo($source)
)));
?>

View File

@ -0,0 +1,14 @@
<?php
use yii\helpers\Html;
use humhub\models\Setting;
?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_ChangeEmail', '<strong>Confirm</strong></strong> your new email address')); ?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_ChangeEmail', 'Hello')); ?> <?php echo Html::encode($user->displayName); ?>,
<?php echo strip_tags(str_replace("<br>", "\n", Yii::t('UserModule.views_mails_ChangeEmail', 'You have requested to change your e-mail address.<br>Your new e-mail address is {newemail}.<br><br>To confirm your new e-mail address please click on the button below.', array('{newemail}' => Html::encode($newEmail))))); ?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_ChangeEmail', 'Confirm')); ?>: <?php echo urldecode($approveUrl); ?>

View File

@ -0,0 +1,17 @@
<?php
use yii\helpers\Html;
use humhub\models\Setting;
?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_RecoverPassword', '<strong>Password</strong> recovery')); ?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_RecoverPassword', 'Hello {displayName}', array('{displayName}' => Html::encode($user->displayName)))); ?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_RecoverPassword', 'Please use the following link within the next day to reset your password.')); ?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_RecoverPassword', "If you don't use this link within 24 hours, it will expire.")); ?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_RecoverPassword', 'Reset Password')); ?>: <?php echo urldecode($linkPasswordReset); ?>

View File

@ -0,0 +1,13 @@
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use humhub\models\Setting;
?>
<?php echo mb_strtoupper(Yii::t('UserModule.views_mails_UserInviteSelf', 'Welcome to %appName%', array('%appName%' => Html::encode(Yii::$app->name)))); ?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_UserInviteSelf', 'Welcome to %appName%. Please click on the button below to proceed with your registration.', array('%appName%' => Html::encode(Yii::$app->name)))); ?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_UserInviteSelf', 'Sign up')); ?>: <?php echo urldecode(Url::toRoute(["/user/auth/create-account", 'token' => $token], true)); ?>

View File

@ -0,0 +1,16 @@
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use humhub\models\Setting;
?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_UserInviteSpace', 'You got a <strong>space</strong> invite')); ?>
<?php echo Html::encode($originator->displayName); ?> <?php echo strip_tags(Yii::t('UserModule.views_mails_UserInviteSpace', 'invited you to the space:')); ?> <?php echo Html::encode($space->name); ?> at <?php echo Html::encode(Yii::$app->name); ?>
<?php echo strip_tags(str_replace(["\n","<br>"], [" ","\n"], Yii::t('UserModule.views_mails_UserInviteSpace', '<br>A social network to increase your communication and teamwork.<br>Register now
to join this space.'))); ?>
<?php echo strip_tags(Yii::t('UserModule.views_mails_UserInviteSpace', 'Sign up now')); ?>: <?php echo urldecode(Url::to(['/user/auth/create-account', 'token' => $token], true)); ?>

View File

@ -0,0 +1,10 @@
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use humhub\models\Setting;
?>
<?= $content; ?>
Powered by HumHub (http://www.humhub.org)