Пример #1
0
 /**
  * Parse the data into the template
  */
 private function parse()
 {
     // form was sent?
     if ($this->URL->getParameter('sent') == 'true') {
         // show message
         $this->tpl->assign('unsubscribeIsSuccess', true);
         // hide form
         $this->tpl->assign('unsubscribeHideForm', true);
     }
     // unsubscribe was issued for a specific group/address
     if (\SpoonFilter::isEmail($this->email) && FrontendMailmotorModel::existsGroup($this->group)) {
         // unsubscribe the address from this group
         if (FrontendMailmotorModel::unsubscribe($this->email, $this->group)) {
             // hide form
             $this->tpl->assign('unsubscribeHideForm', true);
             // show message
             $this->tpl->assign('unsubscribeIsSuccess', true);
         } else {
             // unsubscribe failed, show an error
             $this->tpl->assign('unsubscribeHasError', true);
         }
     }
     // parse the form
     $this->frm->parse($this->tpl);
 }
Пример #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;
 }