Add text/plain part to confirmation and notifiocation mails.
This commit is contained in:
parent
a15b6a0edb
commit
63b0a9edf1
1 changed files with 41 additions and 21 deletions
|
|
@ -3,7 +3,7 @@ package WebGUI::AssetAspect::Subscriber;
|
|||
use strict;
|
||||
use warnings;
|
||||
use 5.010;
|
||||
use Class::C3;
|
||||
use Class::C3;
|
||||
use Carp;
|
||||
|
||||
use WebGUI::Asset::Template;
|
||||
|
|
@ -45,7 +45,7 @@ sub definition {
|
|||
alwaysConfirmSubscription => {
|
||||
fieldType => 'yesNo',
|
||||
defaultValue => 0,
|
||||
label => $i18n->get( 'require confirmation' ),
|
||||
label => $i18n->get( 'require confirmation' ),
|
||||
tab => 'subscription',
|
||||
},
|
||||
allowAnonymousSubscription => {
|
||||
|
|
@ -128,7 +128,7 @@ sub getListHeaders {
|
|||
my $site = $self->session->url->getSiteURL;
|
||||
|
||||
my $headers = {
|
||||
'List-Unsubscribe' =>
|
||||
'List-Unsubscribe' =>
|
||||
'<' . $site . $self->getUrl( "func=processSubscription&action=unsubscribe&email=$email" ) . '>',
|
||||
'List-Subscribe' =>
|
||||
'<' . $site . $self->getUrl( "func=processSubscription&action=subscribe&email=$email" ) . '>',
|
||||
|
|
@ -192,13 +192,13 @@ sub appendSubscriptionFormVars {
|
|||
my $i18n = WebGUI::International->new( $session, 'AssetAspect_Subscriber' );
|
||||
|
||||
# Setup form controls
|
||||
my $formHeader =
|
||||
my $formHeader =
|
||||
WebGUI::Form::formHeader( $session, { action => $self->getUrl } )
|
||||
. WebGUI::Form::hidden( $session, { name => 'func', value => 'processSubscription' } )
|
||||
;
|
||||
my $subscribeButton =
|
||||
my $subscribeButton =
|
||||
sprintf '<button type="submit" name="action" value="subscribe">%s</button>', $i18n->get('subscribe');
|
||||
my $unsubscribeButton =
|
||||
my $unsubscribeButton =
|
||||
sprintf '<button type="submit" name="action" value="unsubscribe">%s</button>', $i18n->get('unsubscribe');
|
||||
my $emailBox = WebGUI::Form::email( $session, { name => 'email', value => '' } );
|
||||
my $formFooter = WebGUI::Form::formFooter( $session );
|
||||
|
|
@ -231,8 +231,8 @@ sub appendSubscriptionFormVars {
|
|||
sub getSubscriptionGroup {
|
||||
my $self = shift;
|
||||
my $groupId = $self->get( "subscriptionGroupId" );
|
||||
my $group = $groupId
|
||||
? WebGUI::Group->new( $self->session, $groupId )
|
||||
my $group = $groupId
|
||||
? WebGUI::Group->new( $self->session, $groupId )
|
||||
: $self->createSubscriptionGroup
|
||||
;
|
||||
|
||||
|
|
@ -243,7 +243,7 @@ sub getSubscriptionGroup {
|
|||
sub getReturnUrl {
|
||||
my $self = shift;
|
||||
my $referer = $self->session->env->get('HTTP_REFERER');
|
||||
|
||||
|
||||
return unless $referer;
|
||||
|
||||
# Get path and strip leading and trailing slash if it exists.
|
||||
|
|
@ -331,14 +331,18 @@ sub sendSubscriptionConfirmation {
|
|||
$var->{ actionIsSubscribe } = $action eq 'subscribe';
|
||||
|
||||
my $mail = WebGUI::Mail::Send->create( $self->session, {
|
||||
to => $user->get('email'),
|
||||
subject => $self->get('confirmationEmailSubject'),
|
||||
to => $user->get('email'),
|
||||
subject => $self->get('confirmationEmailSubject'),
|
||||
contentType => 'multipart/alternative',
|
||||
} );
|
||||
|
||||
my $templateId = $self->get('confirmationEmailTemplateId');
|
||||
my $template = WebGUI::Asset::Template->new( $session, $templateId );
|
||||
if ( $template ) {
|
||||
$mail->addHtml( $template->process( $var ) );
|
||||
my $content = $template->process( $var );
|
||||
|
||||
$mail->addHtml( $content );
|
||||
$mail->addText( $self->transformToText( $content ) );
|
||||
}
|
||||
else {
|
||||
$session->log->error( "Cannot instanciate confirmation email template with id [$templateId]" );
|
||||
|
|
@ -362,14 +366,18 @@ sub sendNoMutationEmail {
|
|||
$var->{ actionIsSubscribe } = $action eq 'subscribe';
|
||||
|
||||
my $mail = WebGUI::Mail::Send->create( $self->session, {
|
||||
to => $user->get('email'),
|
||||
subject => $self->get('noMutationEmailSubject'),
|
||||
to => $user->get('email'),
|
||||
subject => $self->get('noMutationEmailSubject'),
|
||||
contentType => 'multipart/alternative',
|
||||
} );
|
||||
|
||||
my $templateId = $self->get('noMutationEmailTemplateId');
|
||||
my $template = WebGUI::Asset::Template->new( $session, $templateId );
|
||||
if ( $template ) {
|
||||
$mail->addHtml( $template->process( $var ) );
|
||||
my $content = $template->process( $var );
|
||||
|
||||
$mail->addHtml( $content );
|
||||
$mail->addText( $self->transformToText( $content ) );
|
||||
}
|
||||
else {
|
||||
$session->log->error( "Cannot instanciate no mutation email template with id [$templateId]" );
|
||||
|
|
@ -383,6 +391,18 @@ sub sendNoMutationEmail {
|
|||
return;
|
||||
}
|
||||
|
||||
sub transformToText {
|
||||
my $self = shift;
|
||||
my $html = shift;
|
||||
|
||||
my $text = $html;
|
||||
#HTML::Entities::decode($text);
|
||||
$text =~ s/<a.*?href=["'](.*?)['"].*?>(.+?)<\/a>/$2 ($1)/g;
|
||||
$text = WebGUI::HTML::html2text($text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub logConfirmation {
|
||||
my $self = shift;
|
||||
|
|
@ -390,7 +410,7 @@ sub logConfirmation {
|
|||
my $session = $self->session;
|
||||
my $db = $session->db;
|
||||
|
||||
$db->write(
|
||||
$db->write(
|
||||
' update assetAspectSubscriber_log set '
|
||||
.' confirmationIp=?, confirmationDate=?, confirmed=? where code=? and assetId=?',
|
||||
[
|
||||
|
|
@ -414,7 +434,7 @@ sub logRequest {
|
|||
my $session = $self->session;
|
||||
my $db = $session->db;
|
||||
|
||||
$db->write(
|
||||
$db->write(
|
||||
' insert into assetAspectSubscriber_log set '
|
||||
.' assetId=?, requestIp=?, requestDate=?, code=?, confirmed=?, anonymous=?, type=?, userId=?, email=?',
|
||||
[
|
||||
|
|
@ -440,7 +460,7 @@ sub subscribe {
|
|||
my $requireConfirm = shift // $self->get('alwaysConfirmSubscription');
|
||||
my $session = $self->session;
|
||||
|
||||
|
||||
|
||||
if ( $requireConfirm ) {
|
||||
if ( $user->isInGroup( $self->getSubscriptionGroup->getId ) ) {
|
||||
$self->sendNoMutationEmail( $user, 'subscribe' );
|
||||
|
|
@ -466,7 +486,7 @@ sub unsubscribe {
|
|||
my $self = shift;
|
||||
my $user = shift || $self->session->user;
|
||||
my $requireConfirm = shift // $self->get('alwaysConfirmSubscription');
|
||||
|
||||
|
||||
my $session = $self->session;
|
||||
|
||||
if ( $requireConfirm ) {
|
||||
|
|
@ -499,8 +519,8 @@ sub www_confirmMutation {
|
|||
my $code = $form->get('code');
|
||||
return unless $code;
|
||||
|
||||
my ($userId, $type) = $db->quickArray(
|
||||
'select userId, type from assetAspectSubscriber_log where confirmed=? and code=?',
|
||||
my ($userId, $type) = $db->quickArray(
|
||||
'select userId, type from assetAspectSubscriber_log where confirmed=? and code=?',
|
||||
[
|
||||
0,
|
||||
$code,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue