예제 #1
0
 /**
  * Validate the form
  *
  * @return	void
  */
 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
                 FrontendMailmotorCMHelper::subscribe($email->getValue());
                 // trigger event
                 FrontendModel::triggerEvent('mailmotor', 'after_subscribe', array('email' => $email->getValue()));
                 // redirect
                 $this->redirect(FrontendNavigation::getURLForBlock('mailmotor', 'subscribe') . '?sent=true#subscribeForm');
             } catch (Exception $e) {
                 // when debugging we need to see the exceptions
                 if (SPOON_DEBUG) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('subscribeHasError', true);
             }
         } else {
             $this->tpl->assign('subscribeHasFormError', true);
         }
     }
 }
예제 #2
0
 /**
  * Unsubscribes an e-mail address from CampaignMonitor and our database
  *
  * @param string $email The e-mail address to unsubscribe.
  * @param string[optional] $groupId The id of the group to unsubscribe from.
  * @return bool
  */
 public static function unsubscribe($email, $groupId = null)
 {
     // get objects
     $db = FrontendModel::getDB(true);
     $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) {
             // 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;
 }
예제 #3
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 continueing if the mailing record is not set
     if (empty($this->mailing)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
예제 #4
0
 /**
  * Parse the data into the template
  *
  * @return	void
  */
 private function parse()
 {
     // add into breadcrumb
     $this->breadcrumb->addElement($this->record['name']);
     // set meta
     $this->header->setPageTitle($this->record['name']);
     // set the content to parse
     $content = $this->type == 'html' ? $this->record['data']['full_content_html'] : $this->record['content_plain'];
     // cm is asking the info
     if ($this->forCM) {
         // replace the unsubscribe
         if (preg_match_all('/<a id="unsubscribeURL".*?>.*?<\\/a>/is', $content, $matches)) {
             // loop the matches
             foreach ($matches[0] as $match) {
                 // get style attribute if one is provided
                 preg_match('/style=".*?"/is', $match, $styleAttribute);
                 // replace the match
                 $content = str_replace($match, '<unsubscribe' . (isset($styleAttribute[0]) ? ' ' . $styleAttribute[0] : '') . '>' . strip_tags($match) . '</unsubscribe>', $content);
             }
         }
         // online preview links
         if (preg_match_all('/<a id="onlineVersionURL".*?>.*?<\\/a>/is', $content, $matches)) {
             // loop the matches
             foreach ($matches[0] as $match) {
                 // replace the match
                 $content = str_replace('href="#', 'href="' . FrontendMailmotorModel::getMailingPreviewURL($this->id, $this->type), $content);
             }
         }
     }
     // assign article
     $this->tpl->assign('mailingContent', $content);
 }