/** * Generate the content element */ protected function compile() { $objNewsletter = \NewsletterModel::findByIdOrAlias($this->pid); $objNewsletterChannel = \NewsletterChannelModel::findByIds(array($objNewsletter->pid), array('limit' => 1)); $objParent = $this->getPageDetails($objNewsletterChannel->jumpTo); $href = ampersand($this->generateFrontendUrl($objParent->row(), sprintf(\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/items/%s', $objNewsletter->alias))); //$href = ampersand($this->generateFrontendUrl($objParent->row(), ((\Config::get('useAutoItem') && !\Config::get('disableAlias')) ? '/%s' : '/items/%s'), $objParent->language)); $this->Template->setData($objNewsletter->row()); $this->Template->view_online = $href; return; }
private function addRecipient($email, $arrChannels, $strMailText, $intJumpTo) { $varInput = \Idna::encodeEmail($email); // Get the existing active subscriptions $arrSubscriptions = array(); if (($objSubscription = \NewsletterRecipientsModel::findBy(array("email=? AND active=1"), $varInput)) !== null) { $arrSubscriptions = $objSubscription->fetchEach('pid'); } $arrNew = array_diff($arrChannels, $arrSubscriptions); // Return if there are no new subscriptions if (!is_array($arrNew) || empty($arrNew)) { return; } // Remove old subscriptions that have not been activated yet if (($objOld = \NewsletterRecipientsModel::findBy(array("email=? AND active=''"), $varInput)) !== null) { while ($objOld->next()) { $objOld->delete(); } } $time = time(); $strToken = md5(uniqid(mt_rand(), true)); // Add the new subscriptions foreach ($arrNew as $id) { $objRecipient = new \NewsletterRecipientsModel(); $objRecipient->pid = $id; $objRecipient->tstamp = $time; $objRecipient->email = $varInput; $objRecipient->active = ''; $objRecipient->addedOn = $time; $objRecipient->ip = $this->anonymizeIp(\Environment::get('ip')); $objRecipient->token = $strToken; $objRecipient->confirmed = ''; $objRecipient->save(); } // Get the channels $objChannel = \NewsletterChannelModel::findByIds($arrChannels); // Prepare the e-mail text $strText = str_replace('##token##', $strToken, $strMailText); $strText = str_replace('##domain##', \Environment::get('host'), $strText); //$strText = str_replace('##link##', \Environment::get('base') . \Environment::get('request') . (($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false) ? '&' : '?') . 'token=' . $strToken, $strText); $objPageConfirm = \PageModel::findByPk($intJumpTo); if ($objPageConfirm === null) { $this->log('Newsletter confirmation page not found, id: ' . $intJumpTo, __CLASS__ . ":" . __METHOD__, TL_NEWSLETTER); } $strText = str_replace('##link##', rtrim(\Environment::get('base'), '/') . '/' . $this->generateFrontendUrl($objPageConfirm->row()) . '?token=' . $strToken, $strText); $strText = str_replace(array('##channel##', '##channels##'), implode("\n", $objChannel->fetchEach('title')), $strText); // Activation e-mail $objEmail = new \Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['nl_subject'], \Environment::get('host')); $objEmail->text = $strText; $objEmail->sendTo($varInput); }
/** * prepare */ public function prepare() { // check if the newsletter module is active if (in_array('newsletter', $this->Config->getActiveModules())) { // load backend user $this->import('BackendUser', 'User'); // check permission if ($this->User->isAdmin || $this->User->hasAccess('newsletter', 'modules') && isset($this->User->newsletters) && is_array($this->User->newsletters)) { // check if table exists if (!$this->Database->tableExists('tl_newsletter')) { return; } // get all newsletter channels $objNewsletter = \NewsletterChannelModel::findAll(array('order' => 'title')); // there are at minimum one newletter if (!is_null($objNewsletter) && $objNewsletter->count()) { // prepare directentry array $arrDirectEntry = array(); // set counter $intCounter = 1; // do this foreach page while ($objNewsletter->next()) { // check page permission if ($this->User->isAdmin || in_array($objNewsletter->id, $this->User->newsletters)) { // set the icon url and title $arrDirectEntry[$intCounter]['icons']['page']['url'] = 'contao/main.php?do=newsletter&table=tl_newsletter&id=' . $objNewsletter->id; $arrDirectEntry[$intCounter]['icons']['page']['title'] = 'newsletter'; $arrDirectEntry[$intCounter]['icons']['page']['icon'] = 'system/modules/newsletter/assets/icon.gif'; // set the page url and title $arrDirectEntry[$intCounter]['name']['url'] = 'contao/main.php?do=newsletter&table=tl_newsletter&id=' . $objNewsletter->id; $arrDirectEntry[$intCounter]['name']['title'] = $objNewsletter->title; $arrDirectEntry[$intCounter]['name']['link'] = strlen($objNewsletter->title) > 17 ? substr($objNewsletter->title, 0, 15) . '...' : $objNewsletter->title; // add one to counter $intCounter++; } } // add to direcentries service $this->import('DirectEntries'); $this->DirectEntries->addDirectEntry('content', 'newsletter', $arrDirectEntry); } } } }
/** * Add a new recipient */ protected function addRecipient() { if (!\Environment::get('isAjaxRequest')) { return parent::addRecipient(); } $arrChannels = \Input::post('channels'); if (!is_array($arrChannels)) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels']; return false; } $arrChannels = array_intersect($arrChannels, $this->nl_channels); // see #3240 // Check the selection if (!is_array($arrChannels) || empty($arrChannels)) { $_SESSION['SUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels']; return false; } $varInput = \Idna::encodeEmail(\Input::post('email', true)); // Validate the e-mail address if (!\Validator::isEmail($varInput)) { $_SESSION['SUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['email']; return false; } $arrSubscriptions = array(); // Get the existing active subscriptions if (($objSubscription = \NewsletterRecipientsModel::findBy(array("email=? AND active=1"), $varInput)) !== null) { $arrSubscriptions = $objSubscription->fetchEach('pid'); } $arrNew = array_diff($arrChannels, $arrSubscriptions); // Return if there are no new subscriptions if (!is_array($arrNew) || empty($arrNew)) { $_SESSION['SUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['subscribed']; return false; } // Remove old subscriptions that have not been activated yet if (($objOld = \NewsletterRecipientsModel::findBy(array("email=? AND active=''"), $varInput)) !== null) { while ($objOld->next()) { $objOld->delete(); } } $time = time(); $strToken = md5(uniqid(mt_rand(), true)); // Add the new subscriptions foreach ($arrNew as $id) { $objRecipient = new \NewsletterRecipientsModel(); $objRecipient->pid = $id; $objRecipient->tstamp = $time; $objRecipient->email = $varInput; $objRecipient->active = ''; $objRecipient->addedOn = $time; $objRecipient->ip = $this->anonymizeIp(\Environment::get('ip')); $objRecipient->token = $strToken; $objRecipient->confirmed = ''; $objRecipient->save(); } // Get the channels $objChannel = \NewsletterChannelModel::findByIds($arrChannels); // Prepare the e-mail text $strText = str_replace('##token##', $strToken, $this->nl_subscribe); $strText = str_replace('##domain##', \Idna::decode(\Environment::get('host')), $strText); $strText = str_replace('##link##', \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (\Config::get('disableAlias') || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $strToken, $strText); $strText = str_replace(array('##channel##', '##channels##'), implode("\n", $objChannel->fetchEach('title')), $strText); // Activation e-mail $objEmail = new \Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['nl_subject'], \Idna::decode(\Environment::get('host'))); $objEmail->text = $strText; $objEmail->sendTo($varInput); // Redirect to the jumpTo page if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) { $this->redirect($this->generateFrontendUrl($objTarget->row())); } $_SESSION['SUBSCRIBE_CONFIRM'] = $GLOBALS['TL_LANG']['MSC']['nl_confirm']; return true; }
/** * Create a new user and redirect * @param array */ protected function createNewUser($arrData) { $arrData['tstamp'] = time(); $arrData['login'] = $this->reg_allowLogin; $arrData['activation'] = md5(uniqid(mt_rand(), true)); $arrData['dateAdded'] = $arrData['tstamp']; // Set default groups if (!array_key_exists('groups', $arrData)) { $arrData['groups'] = $this->reg_groups; } // Disable account $arrData['disable'] = 1; // Send activation e-mail if ($this->reg_activate) { $arrChunks = array(); $strConfirmation = $this->reg_text; preg_match_all('/##[^#]+##/i', $strConfirmation, $arrChunks); foreach ($arrChunks[0] as $strChunk) { $strKey = substr($strChunk, 2, -2); switch ($strKey) { case 'domain': $strConfirmation = str_replace($strChunk, \Environment::get('host'), $strConfirmation); break; case 'link': $strConfirmation = str_replace($strChunk, \Environment::get('base') . \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $arrData['activation'], $strConfirmation); break; // HOOK: support newsletter subscriptions // HOOK: support newsletter subscriptions case 'channel': case 'channels': if (!in_array('newsletter', $this->Config->getActiveModules())) { break; } // Make sure newsletter is an array if (!is_array($arrData['newsletter'])) { if ($arrData['newsletter'] != '') { $arrData['newsletter'] = array($arrData['newsletter']); } else { $arrData['newsletter'] = array(); } } // Replace the wildcard if (!empty($arrData['newsletter'])) { $objChannels = \NewsletterChannelModel::findByIds($arrData['newsletter']); if ($objChannels !== null) { $strConfirmation = str_replace($strChunk, implode("\n", $objChannels->fetchEach('title')), $strConfirmation); } } else { $strConfirmation = str_replace($strChunk, '', $strConfirmation); } break; default: $strConfirmation = str_replace($strChunk, $arrData[$strKey], $strConfirmation); break; } } $objEmail = new \Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['emailSubject'], \Environment::get('host')); $objEmail->text = $strConfirmation; $objEmail->sendTo($arrData['email']); } // Make sure newsletter is an array if (isset($arrData['newsletter']) && !is_array($arrData['newsletter'])) { $arrData['newsletter'] = array($arrData['newsletter']); } // Create the user $objNewUser = new \MemberModel(); $objNewUser->setRow($arrData); $objNewUser->save(); $insertId = $objNewUser->id; // Assign home directory if ($this->reg_assignDir && is_dir(TL_ROOT . '/' . $this->reg_homeDir)) { $this->import('Files'); $strUserDir = $arrData['username'] ?: 'user_' . $insertId; // Add the user ID if the directory exists if (is_dir(TL_ROOT . '/' . $this->reg_homeDir . '/' . $strUserDir)) { $strUserDir .= '_' . $insertId; } new \Folder($this->reg_homeDir . '/' . $strUserDir); $objNewUser->assignDir = 1; $objNewUser->homeDir = $this->reg_homeDir . '/' . $strUserDir; $objNewUser->save(); } // HOOK: send insert ID and user data if (isset($GLOBALS['TL_HOOKS']['createNewUser']) && is_array($GLOBALS['TL_HOOKS']['createNewUser'])) { foreach ($GLOBALS['TL_HOOKS']['createNewUser'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($insertId, $arrData, $this); } } // Inform admin if no activation link is sent if (!$this->reg_activate) { $this->sendAdminNotification($insertId, $arrData); } $this->jumpToOrReload($this->objModel->getRelated('jumpTo')->row()); }
/** * Add newsletters to the indexer * * @param array $arrPages * @param integer $intRoot * @param boolean $blnIsSitemap * * @return array */ public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false) { $arrRoot = array(); if ($intRoot > 0) { $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page'); } $arrProcessed = array(); $time = \Date::floorToMinute(); // Get all channels $objNewsletter = \NewsletterChannelModel::findAll(); // Walk through each channel if ($objNewsletter !== null) { while ($objNewsletter->next()) { if (!$objNewsletter->jumpTo) { continue; } // Skip channels outside the root nodes if (!empty($arrRoot) && !in_array($objNewsletter->jumpTo, $arrRoot)) { continue; } // Get the URL of the jumpTo page if (!isset($arrProcessed[$objNewsletter->jumpTo])) { $objParent = \PageModel::findWithDetails($objNewsletter->jumpTo); // The target page does not exist if ($objParent === null) { continue; } // The target page has not been published (see #5520) if (!$objParent->published || $objParent->start != '' && $objParent->start > $time || $objParent->stop != '' && $objParent->stop <= $time + 60) { continue; } // The target page is exempt from the sitemap (see #6418) if ($blnIsSitemap && $objParent->sitemap == 'map_never') { continue; } // Set the domain (see #6421) $domain = ($objParent->rootUseSSL ? 'https://' : 'http://') . ($objParent->domain ?: \Environment::get('host')) . TL_PATH . '/'; // Generate the URL $arrProcessed[$objNewsletter->jumpTo] = $domain . $this->generateFrontendUrl($objParent->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/items/%s', $objParent->language); } $strUrl = $arrProcessed[$objNewsletter->jumpTo]; // Get the items $objItem = \NewsletterModel::findSentByPid($objNewsletter->id); if ($objItem !== null) { while ($objItem->next()) { $arrPages[] = sprintf($strUrl, $objItem->alias != '' && !\Config::get('disableAlias') ? $objItem->alias : $objItem->id); } } } } return $arrPages; }
/** * Add newsletters to the indexer * @param array * @param integer * @param boolean * @return array */ public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false) { $arrRoot = array(); if ($intRoot > 0) { $arrRoot = $this->getChildRecords($intRoot, 'tl_page'); } $arrProcessed = array(); // Get all channels $objNewsletter = \NewsletterChannelModel::findAll(); // Walk through each channel if ($objNewsletter !== null) { while ($objNewsletter->next()) { // Skip channels without target page if (!$objNewsletter->jumpTo) { continue; } // Skip channels outside the root nodes if (!empty($arrRoot) && !in_array($objNewsletter->jumpTo, $arrRoot)) { continue; } // Get the URL of the jumpTo page if (!isset($arrProcessed[$objNewsletter->jumpTo])) { $domain = \Environment::get('base'); $objParent = $this->getPageDetails($objNewsletter->jumpTo); if ($objParent->domain != '') { $domain = (\Environment::get('ssl') ? 'https://' : 'http://') . $objParent->domain . TL_PATH . '/'; } $arrProcessed[$objNewsletter->jumpTo] = $domain . $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/items/%s', $objParent->language); } $strUrl = $arrProcessed[$objNewsletter->jumpTo]; // Get the items $objItem = \NewsletterModel::findSentByPid($objNewsletter->id); if ($objItem !== null) { while ($objItem->next()) { $arrPages[] = sprintf($strUrl, $objItem->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objItem->alias : $objItem->id); } } } } return $arrPages; }
/** * Remove the recipient */ protected function removeRecipient() { $arrChannels = \Input::post('channels'); $arrChannels = array_intersect($arrChannels, $this->nl_channels); // see #3240 // Check the selection if (!is_array($arrChannels) || empty($arrChannels)) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels']; $this->reload(); } $varInput = \Idna::encodeEmail(\Input::post('email', true)); // Validate e-mail address if (!\Validator::isEmail($varInput)) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['email']; $this->reload(); } $arrSubscriptions = array(); // Get the existing active subscriptions if (($objSubscription = \NewsletterRecipientsModel::findBy(array("email=? AND active=1"), $varInput)) !== null) { $arrSubscriptions = $objSubscription->fetchEach('pid'); } $arrRemove = array_intersect($arrChannels, $arrSubscriptions); // Return if there are no subscriptions to remove if (!is_array($arrRemove) || empty($arrRemove)) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['unsubscribed']; $this->reload(); } // Remove the subscriptions if (($objRemove = \NewsletterRecipientsModel::findByEmailAndPids($varInput, $arrRemove)) !== null) { while ($objRemove->next()) { $objRemove->delete(); } } // Get the channels $objChannels = \NewsletterChannelModel::findByIds($arrRemove); $arrChannels = $objChannels->fetchEach('title'); // Log activity $this->log($varInput . ' unsubscribed from ' . implode(', ', $arrChannels), 'ModuleUnsubscribe removeRecipient()', TL_NEWSLETTER); // HOOK: post unsubscribe callback if (isset($GLOBALS['TL_HOOKS']['removeRecipient']) && is_array($GLOBALS['TL_HOOKS']['removeRecipient'])) { foreach ($GLOBALS['TL_HOOKS']['removeRecipient'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($varInput, $arrRemove); } } // Prepare the e-mail text $strText = str_replace('##domain##', \Environment::get('host'), $this->nl_unsubscribe); $strText = str_replace(array('##channel##', '##channels##'), implode("\n", $arrChannels), $strText); // Confirmation e-mail $objEmail = new \Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['nl_subject'], \Environment::get('host')); $objEmail->text = $strText; $objEmail->sendTo($varInput); // Redirect to the jumpTo page if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) { $this->redirect($this->generateFrontendUrl($objTarget->row())); } $_SESSION['UNSUBSCRIBE_CONFIRM'] = $GLOBALS['TL_LANG']['MSC']['nl_removed']; $this->reload(); }
protected function prepareSubmissionData() { $arrSubmissionData = parent::prepareSubmissionData(); $arrSubmissionData['domain'] = \Idna::decode(\Environment::get('host')); $arrSubmissionData['activation'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (\Config::get('disableAlias') || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $this->activeRecord->activation; if (in_array('newsletter', \ModuleLoader::getActive())) { // Replace the wildcard if (!empty($this->objModel->newsletter)) { $objChannels = \NewsletterChannelModel::findByIds($this->activeRecord->newsletter); if ($objChannels !== null) { $arrSubmissionData['channels'] = implode("\n", $objChannels->fetchEach('title')); } } } // Backwards compatibility $arrSubmissionData['channel'] = $arrSubmissionData['channels']; return $arrSubmissionData; }
/** * Create a new user and redirect * * @param array $arrData */ protected function createNewUser($arrData) { $arrData['tstamp'] = time(); $arrData['login'] = $this->reg_allowLogin; $arrData['activation'] = md5(uniqid(mt_rand(), true)); $arrData['dateAdded'] = $arrData['tstamp']; // Set default groups if (!array_key_exists('groups', $arrData)) { $arrData['groups'] = $this->reg_groups; } // Disable account $arrData['disable'] = 1; // Send activation e-mail if ($this->reg_activate) { // Prepare the simple token data $arrTokenData = $arrData; $arrTokenData['domain'] = \Idna::decode(\Environment::get('host')); $arrTokenData['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (\Config::get('disableAlias') || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $arrData['activation']; $arrTokenData['channels'] = ''; if (in_array('newsletter', \ModuleLoader::getActive())) { // Make sure newsletter is an array if (!is_array($arrData['newsletter'])) { if ($arrData['newsletter'] != '') { $arrData['newsletter'] = array($arrData['newsletter']); } else { $arrData['newsletter'] = array(); } } // Replace the wildcard if (!empty($arrData['newsletter'])) { $objChannels = \NewsletterChannelModel::findByIds($arrData['newsletter']); if ($objChannels !== null) { $arrTokenData['channels'] = implode("\n", $objChannels->fetchEach('title')); } } } // Backwards compatibility $arrTokenData['channel'] = $arrTokenData['channels']; $objEmail = new \Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['emailSubject'], \Idna::decode(\Environment::get('host'))); $objEmail->text = \String::parseSimpleTokens($this->reg_text, $arrTokenData); $objEmail->sendTo($arrData['email']); } // Make sure newsletter is an array if (isset($arrData['newsletter']) && !is_array($arrData['newsletter'])) { $arrData['newsletter'] = array($arrData['newsletter']); } // Create the user $objNewUser = new \MemberModel(); $objNewUser->setRow($arrData); $objNewUser->save(); // Assign home directory if ($this->reg_assignDir) { $objHomeDir = \FilesModel::findByUuid($this->reg_homeDir); if ($objHomeDir !== null) { $this->import('Files'); $strUserDir = standardize($arrData['username']) ?: 'user_' . $objNewUser->id; // Add the user ID if the directory exists while (is_dir(TL_ROOT . '/' . $objHomeDir->path . '/' . $strUserDir)) { $strUserDir .= '_' . $objNewUser->id; } // Create the user folder new \Folder($objHomeDir->path . '/' . $strUserDir); $objUserDir = \FilesModel::findByPath($objHomeDir->path . '/' . $strUserDir); // Save the folder ID $objNewUser->assignDir = 1; $objNewUser->homeDir = $objUserDir->uuid; $objNewUser->save(); } } // HOOK: send insert ID and user data if (isset($GLOBALS['TL_HOOKS']['createNewUser']) && is_array($GLOBALS['TL_HOOKS']['createNewUser'])) { foreach ($GLOBALS['TL_HOOKS']['createNewUser'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($objNewUser->id, $arrData, $this); } } // Create the initial version (see #7816) $objVersions = new \Versions('tl_member', $objNewUser->id); $objVersions->setUsername($objNewUser->username); $objVersions->setUserId(0); $objVersions->setEditUrl('contao/main.php?do=member&act=edit&id=%s&rt=1'); $objVersions->initialize(); // Inform admin if no activation link is sent if (!$this->reg_activate) { $this->sendAdminNotification($objNewUser->id, $arrData); } // Check whether there is a jumpTo page if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) { $this->jumpToOrReload($objJumpTo->row()); } $this->reload(); }
/** * Remove the recipient */ protected function removeRecipient() { $arrChannels = \Input::post('channels'); if (!is_array($arrChannels)) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels']; $this->reload(); } $arrChannels = array_intersect($arrChannels, $this->nl_channels); // see #3240 // Check the selection if (!is_array($arrChannels) || empty($arrChannels)) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels']; $this->reload(); } $varInput = \Idna::encodeEmail(\Input::post('email', true)); // Validate e-mail address if (!\Validator::isEmail($varInput)) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['email']; $this->reload(); } $arrSubscriptions = array(); // Get the existing active subscriptions if (($objSubscription = \NewsletterRecipientsModel::findBy(array("email=? AND active=1"), $varInput)) !== null) { $arrSubscriptions = $objSubscription->fetchEach('pid'); } $arrRemove = array_intersect($arrChannels, $arrSubscriptions); // Return if there are no subscriptions to remove if (!is_array($arrRemove) || empty($arrRemove)) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['unsubscribed']; $this->reload(); } // Remove the subscriptions if (($objRemove = \NewsletterRecipientsModel::findByEmailAndPids($varInput, $arrRemove)) !== null) { while ($objRemove->next()) { $objRemove->delete(); } } // Get the channels $objChannels = \NewsletterChannelModel::findByIds($arrRemove); $arrChannels = $objChannels->fetchEach('title'); // HOOK: post unsubscribe callback if (isset($GLOBALS['TL_HOOKS']['removeRecipient']) && is_array($GLOBALS['TL_HOOKS']['removeRecipient'])) { foreach ($GLOBALS['TL_HOOKS']['removeRecipient'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($varInput, $arrRemove); } } // Prepare the simple token data $arrData = array(); $arrData['domain'] = \Idna::decode(\Environment::get('host')); $arrData['channel'] = $arrData['channels'] = implode("\n", $arrChannels); // Confirmation e-mail $objEmail = new \Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['nl_subject'], \Idna::decode(\Environment::get('host'))); $objEmail->text = \StringUtil::parseSimpleTokens($this->nl_unsubscribe, $arrData); $objEmail->sendTo($varInput); // Redirect to the jumpTo page if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) { /** @var \PageModel $objTarget */ $this->redirect($objTarget->getFrontendUrl()); } $_SESSION['UNSUBSCRIBE_CONFIRM'] = $GLOBALS['TL_LANG']['MSC']['nl_removed']; $this->reload(); }