Exemplo n.º 1
0
 /**
  * Unsubscribe recipient from RecipientList by registering a bounce of level \Ecodev\Newsletter\BounceHandler::NEWSLETTER_UNSUBSCRIBE
  */
 public function unsubscribeAction()
 {
     $success = false;
     $newsletter = null;
     $email = null;
     $recipientAddress = null;
     // If we have an authentification code, look for the original email which was already sent
     if (@$_GET['c']) {
         $email = $this->emailRepository->findByAuthcode($_GET['c']);
         if ($email) {
             // Mark the email as requested to be unsubscribed
             $email->setUnsubscribed(true);
             $this->emailRepository->update($email);
             $recipientAddress = $email->getRecipientAddress();
             $newsletter = $email->getNewsletter();
             if ($newsletter) {
                 $recipientList = $newsletter->getRecipientList();
                 $recipientList->registerBounce($email->getRecipientAddress(), BounceHandler::NEWSLETTER_UNSUBSCRIBE);
                 $success = true;
                 $this->notifyUnsubscribe($newsletter, $recipientList, $email);
             }
         }
     }
     $this->view->assign('success', $success);
     $this->view->assign('recipientAddress', $recipientAddress);
 }
Exemplo n.º 2
0
 /**
  * Unsubscribe recipient from RecipientList by registering a bounce of level \Ecodev\Newsletter\BounceHandler::NEWSLETTER_UNSUBSCRIBE
  */
 public function unsubscribeAction()
 {
     $success = false;
     $newsletter = null;
     $email = null;
     $recipientAddress = null;
     $args = $this->request->getArguments();
     // For compatibility with old links
     if (!isset($args['c'])) {
         if (isset($_GET['c'])) {
             $args['c'] = $_GET['c'];
         }
     }
     // If we have an authentification code, look for the original email which was already sent
     if (@$args['c']) {
         $email = $this->emailRepository->findByAuthcode($args['c']);
         if ($email) {
             // Mark the email as requested to be unsubscribed
             $email->setUnsubscribed(true);
             $this->emailRepository->update($email);
             $recipientAddress = $email->getRecipientAddress();
             $newsletter = $email->getNewsletter();
             if ($newsletter) {
                 $recipientList = $newsletter->getRecipientList();
                 $recipientList->registerBounce($email->getRecipientAddress(), BounceHandler::NEWSLETTER_UNSUBSCRIBE);
                 $success = true;
                 $this->notifyUnsubscribe($newsletter, $recipientList, $email);
             }
         }
     }
     // Redirect unsubscribe via config.
     $redirect = Tools::confParam('unsubscribe_redirect');
     // If it is a PID, convert to a URL
     if (is_numeric($redirect)) {
         $uriBuilder = $this->controllerContext->getUriBuilder();
         $uriBuilder->reset();
         $uriBuilder->setUseCacheHash(false);
         $uriBuilder->setTargetPageUid((int) $redirect);
         // Append the recipient address just in case you want to do something with it at the destination
         $uriBuilder->setArguments(array('recipient' => $recipientAddress));
         $uri = $uriBuilder->build();
     }
     // If it is a valid URL, redirect to it
     if (GeneralUtility::isValidUrl($redirect)) {
         $this->redirectToUri($redirect);
     }
     // Else render the template.
     $this->view->assign('success', $success);
     $this->view->assign('recipientAddress', $recipientAddress);
 }