Ejemplo n.º 1
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     $this->logger->info('Subscribing user (arpReach): ' . print_r($data, true));
     if (isset($data['list']) && isset($data['email'])) {
         $fields = $this->prepareMergeVars();
         $status = $this->getClient()->subscribeContact($data['list'], $data['email'], $fields);
         $this->logger->notice('Subscription status (arpReach): ' . print_r($status, true));
         /*
          * Displays error
          */
         if (false === $status) {
             if (isset($_POST['already_subscribed_url']) && op_post('already_subscribed_url') !== '') {
                 $_POST['redirect_url'] = op_post('already_subscribed_url');
             } else {
                 if (isset($_POST['redirect_url'])) {
                     $action = sprintf(__('<a href="javascript:history.go(-1);">Return to previous page</a> or <a href="%s">continue</a>.', OP_SN), op_post('redirect_url'));
                 } else {
                     $action = __('<a href="javascript:history.go(-1);">Return to previous page.</a>', OP_SN);
                 }
                 op_warning_screen(__('This email is already subscribed...', OP_SN), __('Optin form - Warning', OP_SN), $action);
             }
             return false;
         }
         return true;
     } else {
         $this->logger->alert('Mandatory information not present [list and/or email address] (arpReach)');
         wp_die('Mandatory information not present [list and/or email address].');
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     $this->logger->info('Subscribing user (MailPoet): ' . print_r($data, true));
     if (isset($data['list']) && isset($data['email'])) {
         // Formating data
         $convertedData = $this->prepareMergeVars();
         $convertedData['user']['email'] = $data['email'];
         $convertedData['user_list']['list_ids'] = array($data['list']);
         $helperUser = WYSIJA::get('user', 'helper');
         $status = $helperUser->addSubscriber($convertedData);
         $this->logger->notice('Subscription status (MailPoet): ' . print_r($status, true));
         // Lets check if user is already subscribed
         $errorMessages = $helperUser->getMsgs();
         if (!empty($errorMessages) && isset($errorMessages['updated']) && false !== array_search("Oops! You're already subscribed.", $errorMessages['updated'])) {
             $this->logger->notice('User already subscribed (MailPoet).');
             if (isset($_POST['already_subscribed_url']) && op_post('already_subscribed_url') !== '') {
                 $_POST['redirect_url'] = op_post('already_subscribed_url');
             } else {
                 if (isset($_POST['redirect_url'])) {
                     $action = sprintf(__('<a href="javascript:history.go(-1);">Return to previous page</a> or <a href="%s">continue</a>.', 'optimizepress'), op_post('redirect_url'));
                 } else {
                     $action = __('<a href="javascript:history.go(-1);">Return to previous page.</a>', 'optimizepress');
                 }
                 op_warning_screen(__('This email is already subscribed...', 'optimizepress'), __('Optin form - Warning', 'optimizepress'), $action);
             }
             return false;
         }
         $this->logger->info('User added to list (MailPoet)');
         return true;
     } else {
         $this->logger->alert('Mandatory information not present [list and/or email address]');
         wp_die('Mandatory information not present [list and/or email address].');
         return false;
     }
 }
Ejemplo n.º 3
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     if (isset($data['list']) && isset($data['email'])) {
         $mergeVars = $this->prepareMergeVars($data['list']);
         $status = $this->getClient()->listSubscribe($data['list'], $data['email'], $mergeVars, 'html', op_post('double_optin') === 'Y' ? true : false);
         /*
          * Displays error
          */
         if (false === $status) {
             error_log('Error ' . $this->getClient()->errorCode . ': ' . $this->getClient()->errorMessage);
             if ($this->getClient()->errorCode == 214) {
                 if (isset($_POST['redirect_url'])) {
                     $action = sprintf(__('<a href="javascript:history.go(-1);">Return to previous page</a> or <a href="%s">continue</a>.', OP_SN), op_post('redirect_url'));
                 } else {
                     $action = __('<a href="javascript:history.go(-1);">Return to previous page.</a>', OP_SN);
                 }
                 op_warning_screen(__('This email is already subscribed...', OP_SN), __('Optin form - Warning', OP_SN), $action);
             }
         }
         return true;
     } else {
         wp_die('Mandatory information not present [list and/or email address].');
     }
 }
Ejemplo n.º 4
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     $this->logger->info('Subscribing user: '******'list']) && isset($data['email'])) {
         $status = op_post('double_optin') === 'Y' ? 0 : 1;
         $params = array('apikey' => $this->apiKey, 'plugin_key' => 'bb78ce44c9f6e99dd85ddd30fb782695', 'listID' => $data['list'], 'email' => $data['email'], 'status' => $status);
         $params = array_merge($params, $this->prepareMergeVars($data['list']));
         $this->logger->info('params: ' . print_r($params, true));
         $user = $this->getClient()->call('addSubscriber', $params);
         if (isset($user['ERROR'])) {
             if ($user['ERROR'] === 'EMAIL_ALREADY_EXISTS') {
                 if (isset($_POST['already_subscribed_url']) && op_post('already_subscribed_url') !== '') {
                     $_POST['redirect_url'] = op_post('already_subscribed_url');
                 } else {
                     if (isset($_POST['redirect_url'])) {
                         $action = sprintf(__('<a href="javascript:history.go(-1);">Return to previous page</a> or <a href="%s">continue</a>.', 'optimizepress'), op_post('redirect_url'));
                     } else {
                         $action = __('<a href="javascript:history.go(-1);">Return to previous page.</a>', 'optimizepress');
                     }
                     op_warning_screen(__('This email is already subscribed...', 'optimizepress'), __('Optin form - Warning', 'optimizepress'), $action);
                 }
             }
             return false;
         }
         return true;
     } else {
         $this->logger->alert('Mandatory information not present [list and/or email address]');
         wp_die('Mandatory information not present [list and/or email address].');
         return false;
     }
 }
Ejemplo n.º 5
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     $this->logger->info('Subscribing user: '******'list']) && isset($data['email'])) {
         $list = $this->getListById($data['list']);
         $params = array('email' => $data['email'], 'name' => false === op_post('name') ? '' : op_post('name'));
         if (null === $list) {
             $this->logger->error('Error: list ' . $data['list'] . ' not found');
             wp_die('Error when subscribing user: '******'List not found [' . $data['list'] . ']');
         }
         $mergeVars = $this->prepareMergeVars($list);
         if (null !== $mergeVars) {
             $params['custom_fields'] = $mergeVars;
         }
         try {
             $status = $list->subscribers->create($params);
             $this->logger->notice('Subscription status: ' . print_r($status, true));
         } catch (OP_AWeberAPIException $e) {
             $this->logger->error('Error ' . $e->type . ': ' . $e->message);
             if (trim($e->message) == 'email: Subscriber already subscribed.') {
                 if (isset($_POST['redirect_url'])) {
                     $action = sprintf(__('<a href="javascript:history.go(-1);">Return to previous page</a> or <a href="%s">continue</a>.', OP_SN), op_post('redirect_url'));
                 } else {
                     $action = __('<a href="javascript:history.go(-1);">Return to previous page.</a>', OP_SN);
                 }
                 op_warning_screen(__('This email is already subscribed...', OP_SN), __('Optin form - Warning', OP_SN), $action);
             }
         }
         return true;
     } else {
         $this->logger->alert('Mandatory information not present [list and/or email address]');
         wp_die('Mandatory information not present [list and/or email address].');
     }
 }
Ejemplo n.º 6
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     $this->logger->info('Subscribing user: '******'list']) && isset($data['email'])) {
         $fields = $this->prepareMergeVars($data['list'], $data['email']);
         $this->logger->info('Prepared Merge Vars: ' . print_r($fields, true));
         $status = $this->getClient()->api("contact/add", $fields);
         $this->logger->notice('Subscription status: ' . print_r($status, true));
         if ($status->success == 1) {
             $this->logger->notice('User Added to List');
             return true;
         } else {
             if (strpos($status->result_message, 'is in the system already')) {
                 if (isset($_POST['already_subscribed_url']) && op_post('already_subscribed_url') !== '') {
                     $_POST['redirect_url'] = op_post('already_subscribed_url');
                 } else {
                     if (isset($_POST['redirect_url'])) {
                         $action = sprintf(__('<a href="javascript:history.go(-1);">Return to previous page</a> or <a href="%s">continue</a>.', 'optimizepress'), op_post('redirect_url'));
                     } else {
                         $action = __('<a href="javascript:history.go(-1);">Return to previous page.</a>', 'optimizepress');
                     }
                     op_warning_screen(__('This email is already subscribed...', 'optimizepress'), __('Optin form - Warning', 'optimizepress'), $action);
                 }
             }
             return false;
         }
     } else {
         $this->logger->alert('Mandatory information not present [list and/or email address]');
         wp_die('Mandatory information not present [list and/or email address].');
         return false;
     }
 }
Ejemplo n.º 7
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     if (isset($data['list']) && isset($data['email'])) {
         $mergeVars = $this->prepareMergeVars();
         try {
             $contact = $this->getClient()->addContact($data['email'], 'normal', $mergeVars['prefix'], $mergeVars['name'], $mergeVars['last_name'], $mergeVars['sufix'], $mergeVars['street'], $mergeVars['street2'], $mergeVars['city'], $mergeVars['state'], $mergeVars['postal_code'], $mergeVars['phone'], $mergeVars['fax'], $mergeVars['business']);
             $this->logger->notice('Adding contact status: ' . print_r($contact, true));
             $status = $this->getClient()->subscribeContactToList($contact->contactId, $data['list']);
             $this->logger->notice('Subscription status: ' . print_r($status, true));
             /*
              * API returns empty status if user exists
              */
             if (empty($status)) {
                 if (isset($_POST['already_subscribed_url']) && op_post('already_subscribed_url') !== '') {
                     $_POST['redirect_url'] = op_post('already_subscribed_url');
                 } else {
                     if (isset($_POST['redirect_url'])) {
                         $action = sprintf(__('<a href="javascript:history.go(-1);">Return to previous page</a> or <a href="%s">continue</a>.', 'optimizepress'), op_post('redirect_url'));
                     } else {
                         $action = __('<a href="javascript:history.go(-1);">Return to previous page.</a>', 'optimizepress');
                     }
                     op_warning_screen(__('This email is already subscribed...', 'optimizepress'), __('Optin form - Warning', 'optimizepress'), $action);
                 }
             }
             return true;
         } catch (Exception $e) {
             $this->logger->error('Error ' . $e->getCode() . ': ' . $e->getMessage());
             return false;
         }
     } else {
         $this->logger->alert('Mandatory information not present [list and/or email address]');
         wp_die('Mandatory information not present [list and/or email address].');
         return false;
     }
 }
Ejemplo n.º 8
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     $this->logger->info('Subscribing user (Mailchimp): ' . print_r($data, true));
     if (isset($data['list']) && isset($data['email'])) {
         $mergeVars = $this->prepareMergeVars($data['list']);
         $doubleOptin = op_post('double_optin') === 'Y' ? true : false;
         $welcomeEmail = op_post('welcome_email') === 'Y' ? true : false;
         $updateExisting = apply_filters('op_mailchimp_update_existing_subscriber', false);
         if ($doubleOptin) {
             $welcomeEmail = false;
         }
         $status = $this->getClient()->listSubscribe($data['list'], $data['email'], $mergeVars, 'html', $doubleOptin, $updateExisting, true, $welcomeEmail);
         $this->logger->notice('Subscription status (Mailchimp): ' . print_r($status, true));
         /*
          * Displays error
          */
         if (false === $status) {
             $this->logger->error('Error ' . $this->getClient()->errorCode . ' (Mailchimp): ' . $this->getClient()->errorMessage);
             if ($this->getClient()->errorCode == 214) {
                 // Hijack redirect URL if user is already subscribed and already_subscribed_url param is defined
                 if (isset($_POST['already_subscribed_url']) && op_post('already_subscribed_url') !== '') {
                     $_POST['redirect_url'] = op_post('already_subscribed_url');
                 } else {
                     if (isset($_POST['redirect_url'])) {
                         $action = sprintf(__('<a href="javascript:history.go(-1);">Return to previous page</a> or <a href="%s">continue</a>.', 'optimizepress'), op_post('redirect_url'));
                     } else {
                         $action = __('<a href="javascript:history.go(-1);">Return to previous page.</a>', 'optimizepress');
                     }
                     op_warning_screen(__('This email is already subscribed...', 'optimizepress'), __('Optin form - Warning', 'optimizepress'), $action);
                 }
             }
             return false;
         }
         $this->logger->info('User added to list (Mailchimp)');
         return true;
     } else {
         $this->logger->alert('Mandatory information not present [list and/or email address]');
         wp_die('Mandatory information not present [list and/or email address].');
         return false;
     }
 }
Ejemplo n.º 9
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     $this->logger->info('Subscribing user: '******'list']) && isset($data['email'])) {
         $fields = $this->prepareMergeVars($data['list']);
         $status = $this->getClient()->import_single_member($data['email'], $fields, array($data['list']), $data['signup_form_id']);
         $this->logger->notice('Subscription status: ' . print_r($status, true));
         if (!isset($status->added) || (int) $status->added !== 1) {
             if (isset($_POST['already_subscribed_url']) && op_post('already_subscribed_url') !== '') {
                 $_POST['redirect_url'] = op_post('already_subscribed_url');
             } else {
                 if (isset($_POST['redirect_url'])) {
                     $action = sprintf(__('<a href="javascript:history.go(-1);">Return to previous page</a> or <a href="%s">continue</a>.', 'optimizepress'), op_post('redirect_url'));
                 } else {
                     $action = __('<a href="javascript:history.go(-1);">Return to previous page.</a>', 'optimizepress');
                 }
                 op_warning_screen(__('This email is already subscribed...', 'optimizepress'), __('Optin form - Warning', 'optimizepress'), $action);
             }
             return false;
         }
         return true;
     } else {
         $this->logger->alert('Mandatory information not present [list and/or email address]');
         wp_die('Mandatory information not present [list and/or email address].');
         return false;
     }
 }