Skip to content

Commit

Permalink
Merge branch 'hotfix/1.5.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Mar 11, 2019
2 parents d20dfdd + 59600f9 commit c046d5d
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 32 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"contao/newsletter-bundle": "Send notifications using the newsletter bundle of Contao"
},
"conflict": {
"contao/core-bundle": "4.5.0",
"contao/newsletter-bundle": "<3.5 || >= 5.0"
},
"extra":{
Expand Down
5 changes: 4 additions & 1 deletion dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
/**
* Palettes
*/
$GLOBALS['TL_DCA']['tl_module']['palettes']['registration'] = str_replace('reg_activate;', 'reg_activate,nc_notification,nc_activation_notification;', $GLOBALS['TL_DCA']['tl_module']['palettes']['registration']);
$GLOBALS['TL_DCA']['tl_module']['palettes']['registration'] = str_replace('reg_activate;', 'reg_activate,reg_jumpTo,nc_notification,nc_activation_notification;', $GLOBALS['TL_DCA']['tl_module']['palettes']['registration']);
// Move the "reg_jumpTo" field from the sub palette into the main palette. See #166
$GLOBALS['TL_DCA']['tl_module']['subpalettes']['reg_activate'] = str_replace('reg_jumpTo,', '', $GLOBALS['TL_DCA']['tl_module']['subpalettes']['reg_activate']);

$GLOBALS['TL_DCA']['tl_module']['palettes']['lostPasswordNotificationCenter'] = str_replace('reg_password', 'nc_notification', $GLOBALS['TL_DCA']['tl_module']['palettes']['lostPassword']);
$GLOBALS['TL_DCA']['tl_module']['palettes']['newsletterSubscribeNotificationCenter'] = '{title_legend},name,headline,type;{config_legend},nl_channels,nl_hideChannels,disableCaptcha;{text_legend},nl_text{notification_legend},nc_notification;{redirect_legend},jumpTo;{template_legend:hide},nl_template;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['newsletterActivateNotificationCenter'] = '{title_legend},name,headline,type;{config_legend},nl_channels,nl_hideChannels;{notification_legend},nc_notification;{redirect_legend},jumpTo;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
Expand Down
2 changes: 1 addition & 1 deletion library/NotificationCenter/Gateway/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ protected function saveToFTP($strFileName, $strContent, $strStorageMode)
$objFile->close();

// Copy the temporary file to the server
$blnResult = @ftp_put($resConnection, $this->objModel->file_path . '/' . $strFileName, $objFile->path, FTP_BINARY);
$blnResult = @ftp_put($resConnection, $this->objModel->file_path . '/' . $strFileName, TL_ROOT . '/' . $objFile->path, FTP_BINARY);

// Delete temporary file and close FTP connection
$objFile->delete();
Expand Down
77 changes: 57 additions & 20 deletions modules/ModuleNewsletterActivateNotificationCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,89 @@ public function generate()

protected function compile()
{
$this->activateRecipient();
$this->activateRecipient(\Input::get('token'));
}

/**
* Activate a recipient
*
* @param string $token
*/
protected function activateRecipient()
protected function activateRecipient($token)
{
// Check the token
$objRecipient = \NewsletterRecipientsModel::findByToken(\Input::get('token'));
if (version_compare(VERSION, '4.7', '>=')) {
/** @var \Contao\CoreBundle\OptIn\OptIn $optIn */
$optIn = \System::getContainer()->get('contao.opt-in');

if ($objRecipient === null) {
$this->Template->mclass = 'error';
$this->Template->message = $GLOBALS['TL_LANG']['ERR']['invalidToken'];
if (!($optInToken = $optIn->find($token)) || $optInToken->isConfirmed() || \count($arrRelated = $optInToken->getRelatedRecords()) < 1)
{
$this->Template->type = 'error';
$this->Template->message = $GLOBALS['TL_LANG']['MSC']['accountError'];

return;
return;
}

$strEmail = $optInToken->getEmail();
} else {
$objRecipient = \NewsletterRecipientsModel::findByToken($token);

if ($objRecipient === null) {
$this->Template->mclass = 'error';
$this->Template->message = $GLOBALS['TL_LANG']['ERR']['invalidToken'];

return;
}

$strEmail = $objRecipient->email;
}

$time = time();
$arrAdd = array();
$arrCids = array();

// Update the subscriptions
while ($objRecipient->next()) {
/** @var NewsletterChannelModel $objChannel */
$objChannel = $objRecipient->getRelated('pid');
if (version_compare(VERSION, '4.7', '>=')) {
foreach ($arrRelated as $strTable=>$intId)
{
if ($strTable == 'tl_newsletter_recipients' && ($objRecipient = \NewsletterRecipientsModel::findByPk($intId)))
{
$arrAdd[] = $objRecipient->id;
$arrCids[] = $objRecipient->pid;

$objRecipient->tstamp = $time;
$objRecipient->active = '1';
$objRecipient->save();
}
}

$optInToken->confirm();

} else {
// Update the subscriptions
while ($objRecipient->next()) {
/** @var NewsletterChannelModel $objChannel */
$objChannel = $objRecipient->getRelated('pid');

$arrAdd[] = $objRecipient->id;
$arrCids[] = $objChannel->id;
$arrAdd[] = $objRecipient->id;
$arrCids[] = $objChannel->id;

$objRecipient->active = 1;
$objRecipient->token = '';
$objRecipient->pid = $objChannel->id;
$objRecipient->confirmed = $time;
$objRecipient->save();
$objRecipient->active = 1;
$objRecipient->token = '';
$objRecipient->pid = $objChannel->id;
$objRecipient->confirmed = $time;
$objRecipient->save();
}
}

// HOOK: post activation callback
if (isset($GLOBALS['TL_HOOKS']['activateRecipient']) && \is_array($GLOBALS['TL_HOOKS']['activateRecipient'])) {
foreach ($GLOBALS['TL_HOOKS']['activateRecipient'] as $callback) {
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($objRecipient->email, $arrAdd, $arrCids);
$this->{$callback[0]}->{$callback[1]}($strEmail, $arrAdd, $arrCids);
}
}

$this->sendNotification($objRecipient->email, $arrCids);
$this->sendNotification($strEmail, $arrCids);
$this->redirectToJumpToPage();

// Confirm activation
Expand Down
17 changes: 14 additions & 3 deletions modules/ModuleNewsletterSubscribeNotificationCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ protected function addNewsletterRecipient($strEmail, $arrNew)

$time = time();
$strToken = md5(uniqid(mt_rand(), true));
$arrRelated = [];

// Add the new subscriptions
foreach ($arrNew as $id) {
Expand All @@ -139,11 +140,15 @@ protected function addNewsletterRecipient($strEmail, $arrNew)
$objRecipient->email = $strEmail;
$objRecipient->active = '';
$objRecipient->addedOn = $time;
$objRecipient->ip = \Environment::get('ip');
$objRecipient->token = $strToken;
$objRecipient->confirmed = '';
if (version_compare(VERSION, '4.7', '<')) {
$objRecipient->ip = \Environment::get('ip');
$objRecipient->token = $strToken;
$objRecipient->confirmed = '';
}
$objRecipient->save();

$arrRelated['tl_newsletter_recipients'][] = $objRecipient->id;

// Remove the blacklist entry (see #4999)
if (version_compare(VERSION, '4.1', '>=')
&& ($objBlacklist = \NewsletterBlacklistModel::findByHashAndPid(md5($strEmail), $id)) !== null
Expand All @@ -152,6 +157,12 @@ protected function addNewsletterRecipient($strEmail, $arrNew)
}
}

if (version_compare(VERSION, '4.7', '>=')) {
/** @var \Contao\CoreBundle\OptIn\OptIn $optIn */
$optIn = \System::getContainer()->get('contao.opt-in');
$strToken = $optIn->create('nl-', $strEmail, $arrRelated)->getIdentifier();
}

$this->sendNotification($strToken, $strEmail, $arrNew);
$this->redirectToJumpToPage();

Expand Down
20 changes: 13 additions & 7 deletions modules/ModulePasswordNotificationCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,21 @@ protected function sendPasswordLink($objMember)

$token = md5(uniqid(mt_rand(), true));
$contaoVersion = VERSION.'.'.BUILD;
if (version_compare($contaoVersion, '4.5.4', '>=')
|| (version_compare($contaoVersion, '4.5.0', '<') && version_compare($contaoVersion, '4.4.12', '>='))) {
$token = 'PW'.substr($token, 2);
if (version_compare($contaoVersion, '4.7.0', '>=')) {
/** @var \Contao\CoreBundle\OptIn\OptIn $optIn */
$optIn = System::getContainer()->get('contao.opt-in');
$optInToken = $optIn->create('pw-', $objMember->email, array('tl_member'=>array($objMember->id)));
$token = $optInToken->getIdentifier();
} elseif (version_compare($contaoVersion, '4.4.12', '>=')) {
$token = 'PW' . substr($token, 2);
}

// Store the token
$objMember = \MemberModel::findByPk($objMember->id);
$objMember->activation = $token;
$objMember->save();
if (!version_compare($contaoVersion, '4.7.0', '>=')) {
// Store the token
$objMember = \MemberModel::findByPk($objMember->id);
$objMember->activation = $token;
$objMember->save();
}

$arrTokens = array();

Expand Down

0 comments on commit c046d5d

Please sign in to comment.