diff --git a/composer.json b/composer.json index c3ecc527..d08ba336 100644 --- a/composer.json +++ b/composer.json @@ -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":{ diff --git a/dca/tl_module.php b/dca/tl_module.php index 0e6a3315..82d27b1e 100644 --- a/dca/tl_module.php +++ b/dca/tl_module.php @@ -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'; diff --git a/library/NotificationCenter/Gateway/File.php b/library/NotificationCenter/Gateway/File.php index 37f4dec6..97b50bfd 100644 --- a/library/NotificationCenter/Gateway/File.php +++ b/library/NotificationCenter/Gateway/File.php @@ -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(); diff --git a/modules/ModuleNewsletterActivateNotificationCenter.php b/modules/ModuleNewsletterActivateNotificationCenter.php index ea7c32a2..53dd7f4f 100644 --- a/modules/ModuleNewsletterActivateNotificationCenter.php +++ b/modules/ModuleNewsletterActivateNotificationCenter.php @@ -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 diff --git a/modules/ModuleNewsletterSubscribeNotificationCenter.php b/modules/ModuleNewsletterSubscribeNotificationCenter.php index 3d349e67..2e6263db 100644 --- a/modules/ModuleNewsletterSubscribeNotificationCenter.php +++ b/modules/ModuleNewsletterSubscribeNotificationCenter.php @@ -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) { @@ -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 @@ -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(); diff --git a/modules/ModulePasswordNotificationCenter.php b/modules/ModulePasswordNotificationCenter.php index 0843715c..be207a70 100644 --- a/modules/ModulePasswordNotificationCenter.php +++ b/modules/ModulePasswordNotificationCenter.php @@ -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();