Exemplo n.º 1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // validate required fields
         $email = $this->frm->getField('email');
         // validate required fields
         if ($email->isEmail(FL::err('EmailIsInvalid'))) {
             if (FrontendMailmotorModel::isSubscribed($email->getValue())) {
                 $email->addError(FL::err('AlreadySubscribed'));
             }
         }
         // no errors
         if ($this->frm->isCorrect()) {
             try {
                 // subscribe the user to our default group
                 if (!FrontendMailmotorCMHelper::subscribe($email->getValue())) {
                     throw new FrontendException('Could not subscribe');
                 }
                 // trigger event
                 FrontendModel::triggerEvent('Mailmotor', 'after_subscribe', array('email' => $email->getValue()));
                 // redirect
                 $this->redirect(FrontendNavigation::getURLForBlock('Mailmotor', 'Subscribe') . '?sent=true#subscribeForm');
             } catch (\Exception $e) {
                 // make sure RedirectExceptions get thrown
                 if ($e instanceof RedirectException) {
                     throw $e;
                 }
                 // when debugging we need to see the exceptions
                 if ($this->getContainer()->getParameter('kernel.debug')) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('subscribeHasError', true);
             }
         } else {
             $this->tpl->assign('subscribeHasFormError', true);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Unsubscribes an e-mail address from CampaignMonitor and our database
  *
  * @param string        $email   The e-mail address to unsubscribe.
  * @param string $groupId The id of the group to unsubscribe from.
  * @return bool
  */
 public static function unsubscribe($email, $groupId = null)
 {
     // get objects
     $db = FrontendModel::getContainer()->get('database');
     $cm = self::getCM();
     // set group ID
     $groupId = !empty($groupId) ? $groupId : FrontendMailmotorModel::getDefaultGroupID();
     // get group CM ID
     $groupCMId = self::getCampaignMonitorID('list', $groupId);
     // group exists
     if (FrontendMailmotorModel::existsGroup($groupId)) {
         try {
             // unsubscribe the email from this group
             $cm->unsubscribe($email, $groupCMId);
         } catch (\Exception $e) {
             // for the unsubscribe function we ignore any errors
             // stop here if something went wrong with CM
             return false;
         }
         // set variables
         $subscriber['status'] = 'unsubscribed';
         $subscriber['unsubscribed_on'] = FrontendModel::getUTCDate('Y-m-d H:i:s');
         // unsubscribe the user
         $db->update('mailmotor_addresses_groups', $subscriber, 'email = ? AND group_id = ?', array($email, $groupId));
         // user unsubscribed
         return true;
     }
     // user not unsubscribed
     return false;
 }
Exemplo n.º 3
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get values
         $email = $this->frm->getField('email');
         // validate required fields
         if ($email->isEmail(FL::err('EmailIsInvalid'))) {
             // email does not exist
             if (!FrontendMailmotorModel::exists($email->getValue())) {
                 $email->addError(FL::err('EmailNotInDatabase'));
             }
             // user is already unsubscribed
             if (!FrontendMailmotorModel::isSubscribed($email->getValue(), $this->group)) {
                 $email->addError(FL::err('AlreadyUnsubscribed'));
             }
         }
         // no errors and email address does not exist
         if ($this->frm->isCorrect()) {
             try {
                 // unsubscribe the user from our default group
                 if (!FrontendMailmotorCMHelper::unsubscribe($email->getValue(), $this->group)) {
                     throw new FrontendException('Could not unsubscribe');
                 }
                 // trigger event
                 FrontendModel::triggerEvent('Mailmotor', 'after_unsubscribe', array('email' => $email->getValue()));
                 // redirect
                 $this->redirect(FrontendNavigation::getURLForBlock('Mailmotor', 'Unsubscribe') . '?sent=true#unsubscribeForm');
             } catch (\Exception $e) {
                 // when debugging we need to see the exceptions
                 if ($this->getContainer()->getParameter('kernel.debug')) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('unsubscribeHasError', true);
             }
         } else {
             $this->tpl->assign('unsubscribeHasFormError', true);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 protected function loadData()
 {
     $this->id = $this->URL->getParameter(1);
     $this->mailing = FrontendMailmotorModel::get($this->id);
     $this->type = \SpoonFilter::getGetValue('type', array('html', 'plain'), 'html');
     $this->forCM = \SpoonFilter::getGetValue('cm', array(0, 1), 0, 'bool');
     // no point continuing if the mailing record is not set
     if (empty($this->mailing)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }