Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

HTML subscription notifications and per user preview #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion classes/cjwnewsletteruser.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,14 @@ function sendSubcriptionMail( $mailTemplate )
$emailReceiverName = '';

$emailSubject = $subject;
$emailBody['text'] = $templateResult;
if( $tpl->hasVariable( 'content_type' ) && preg_match( '/^text\/html/', $tpl->variable( 'content_type' ) ) )
{
$emailBody['html'] = $templateResult;
}
else
{
$emailBody['text'] = $templateResult;
}

$cjwMail = new CjwNewsletterMail();
// x header set for current user
Expand Down
57 changes: 57 additions & 0 deletions classes/cjwnewsletterutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,63 @@ static function generateUniqueMd5Hash( $flexibleVar = '' )
$stringForHash = $flexibleVar. '-'. microtime( true ). '-' . mt_rand(). '-' . mt_rand();
return md5( $stringForHash );
}

/**
* Replaces markers in newsletter content
* @param string $content
* @param CjwNewsletterEditionSend $newsletterEditionSend
* @param CjwNewsletterUser $newsletterUser
* @return string
*/
static function replaceNewsletterMarkers( $content, CjwNewsletterEditionSend $newsletterEditionSend, CjwNewsletterUser $newsletterUser = null )
{
// TODO parse extra variables
$editionSendHash = $newsletterEditionSend->attribute( 'hash' );
$searchArray = array( '#_hash_editionsend_#' );
$replaceArray = array( $editionSendHash );

if( $newsletterUser )
{
$subscription = CjwNewsletterSubscription::fetchByListIdAndNewsletterUserId( $newsletterEditionSend->attribute('list_contentobject_id'), $newsletterUser->attribute( 'id' ) );

$newsletterUnsubscribeHash = $subscription->attribute( 'hash' );
$newsletterConfigureHash = $newsletterUser->attribute( 'hash' );

$personalizeContent = (int) $newsletterEditionSend->attribute( 'personalize_content' );

$searchArray = array_merge( $searchArray,
array(
'#_hash_unsubscribe_#',
'#_hash_configure_#'
));

$replaceArray = array_merge( $replaceArray,
array(
$newsletterUnsubscribeHash,
$newsletterConfigureHash
));

if( $personalizeContent === 1 )
{
$searchArray = array_merge( $searchArray,
array(
'[[name]]',
'[[salutation_name]]',
'[[first_name]]',
'[[last_name]]'
));
$replaceArray = array_merge( $replaceArray,
array(
$newsletterUser->attribute( 'name' ),
$newsletterUser->attribute( 'salutation_name' ),
$newsletterUser->attribute( 'first_name' ),
$newsletterUser->attribute( 'last_name' )
));
}
}

return str_replace( $searchArray, $replaceArray, $content );
}
}

?>
37 changes: 2 additions & 35 deletions cronjobs/cjw_newsletter_mailqueue_process.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

$emailSender = $sendObject->attribute( 'email_sender' );
$emailSenderName = $sendObject->attribute( 'email_sender_name' );
$personalizeContent = (int) $sendObject->attribute( 'personalize_content' );


$limit = 50;
$offset = 0;
Expand All @@ -89,54 +89,21 @@
$id = $sendItem->attribute('id');
$outputFormatId = $sendItem->attribute('output_format_id');

// ### subscription data
$newsletterSubscriptionObject = $sendItem->attribute('newsletter_subscription_object');
$newsletterUnsubscribeHash = $newsletterSubscriptionObject->attribute('hash');

// ### get newsletter user data through send_item_object
$newsletterUserObject = $sendItem->attribute('newsletter_user_object');
$emailReceiver = $newsletterUserObject->attribute('email');
$emailReceiverName = $newsletterUserObject->attribute('email_name');

// ### configure hash
$newsletterConfigureHash = $newsletterUserObject->attribute('hash');

// fetch html & text content of parsed outputxml from senmdobject
// data of outputformate
$outputStringArray = $outputFormatStringArray[ $outputFormatId ]['body'];
$emailSubject = $outputFormatStringArray[ $outputFormatId ]['subject'];

// parsed text and replace vars
// TODO parse extra variables

$searchArray = array( '#_hash_unsubscribe_#',
'#_hash_configure_#');

$replaceArray = array( $newsletterUnsubscribeHash,
$newsletterConfigureHash );

if( $personalizeContent === 1 )
{
$searchArray = array_merge( $searchArray,
array(
'[[name]]',
'[[salutation_name]]',
'[[first_name]]',
'[[last_name]]'
));
$replaceArray = array_merge( $replaceArray,
array(
$newsletterUserObject->attribute( 'name' ),
$newsletterUserObject->attribute( 'salutation_name' ),
$newsletterUserObject->attribute( 'first_name' ),
$newsletterUserObject->attribute( 'last_name' )
));
}

$outputStringArrayNew = array('html' => '', 'text' => '');
foreach ( $outputStringArray as $index => $string )
{
$outputStringArrayNew[ $index ] = str_replace( $searchArray, $replaceArray, $string );
$outputStringArrayNew[ $index ] = CjwNewsletterUtils::replaceNewsletterMarkers( $string, $sendObject, $newsletterUserObject);
}

// set x-cjwnl header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
{def $edition_data_map = $contentobject.data_map}
<td valign="top">
<table width="600" cellpadding="0" cellspacing="0" border="0" bgcolor="#ffffff">
<tr>
<td style="padding: 10px 30px 10px 10px;">
<p>
{'If you cannot properly view this newsletter please visit the following link'|i18n('cjw_newsletter/skin/default')}:
<a href="{'/newsletter/archive/#_hash_editionsend_#/0/#_hash_unsubscribe_#'|ezurl('no')}">{'read online'|i18n('cjw_newsletter/skin/default')}</a>
</p>
</td>
</tr>
<tr>
<td><a href="http://www.cjw-network.com" title="CJW Network - Developers united in eZ Publish"><img src={'images/newsletter/skin/default/cjw-newsletter_header.jpg'|ezdesign()} border="0" width="600" height="100" alt="CJW Network - Developers united in eZ Publish" /></a></td>
</tr>
Expand Down
11 changes: 10 additions & 1 deletion modules/newsletter/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@
$editionSendHash = $Params['EditionSendHash'];
$outputFormatId = 0;
$subscriptionHash = false;
$newsletterUser = null;

if( $Params['OutputFormatId'] )
$outputFormatId = (int) $Params['OutputFormatId'];

if( $Params['SubscriptionHash'] )
{
$subscriptionHash = $Params['SubscriptionHash'];
$subscription = CjwNewsletterSubscription::fetchByHash( $subscriptionHash );

if( $subscription )
{
$newsletterUser = CjwNewsletterUser::fetch( $subscription->attribute( 'newsletter_user_id' ) );
}
}

$editionSendObject = CjwNewsletterEditionSend::fetchByHash( $editionSendHash );

Expand All @@ -47,7 +56,7 @@
{
// html
case 0:
$newsletterContent = $newsletterContentArray['body']['html'];
$newsletterContent = CjwNewsletterUtils::replaceNewsletterMarkers( $newsletterContentArray['body']['html'], $editionSendObject, $newsletterUser );
break;
// text
case 1:
Expand Down
8 changes: 8 additions & 0 deletions translations/eng-US/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,14 @@ To edit your newsletter settings please visit the following link:
<source>To unsubscribe from this newsletter please visit the following link</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>read online</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>If you cannot properly view this newsletter please visit the following link</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>cjw_newsletter/subscribe</name>
Expand Down
8 changes: 8 additions & 0 deletions translations/fre-FR/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,14 @@ To edit your newsletter settings please visit the following link:
<source>To unsubscribe from this newsletter please visit the following link</source>
<translation>Pour se désabonner de cette newsletter, veuillez visiter le lien suivant</translation>
</message>
<message>
<source>read online</source>
<translation>lire en ligne</translation>
</message>
<message>
<source>If you cannot properly view this newsletter please visit the following link</source>
<translation>Si vous ne pouvez pas lire correctement cette newsletter, cliquez sur le lien suivant</translation>
</message>
</context>
<context>
<name>cjw_newsletter/subscribe</name>
Expand Down