Esempio n. 1
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $data     Data submitted by the user to be passed for authentication.
  * @param int   $optin_id The optin ID being used.
  *
  * @return string The list dropdown HTML
  */
 public function authenticate($data = array(), $optin_id)
 {
     // Attempt to conenct to the Feedblitz API.
     libxml_use_internal_errors(true);
     $api = wp_remote_get('https://www.feedblitz.com/f.api/syndications?key=' . $data['om-api-key'] . '&summary=1', array('headers' => array('Content-Type' => 'application/xml', 'User-Agent' => 'OptinMonster API')));
     $body = wp_remote_retrieve_body($api);
     $body = str_replace('&', 'OMamp;', $body);
     $body = str_replace('&', '&', $body);
     $body = str_replace('OMamp;', '&', $body);
     $res = json_decode(json_encode(simplexml_load_string($body)));
     if (!empty($res->rsp->err->{'@attributes'}->msg)) {
         return $this->error('api-error', $res->rsp->err->{'@attributes'}->msg . '.');
     } else {
         if (!$res) {
             return $this->error('api-error', __('There was an error connecting to the Feedblitz API. Please try again.', 'optin-monster'));
         }
     }
     // Save the account data for future reference.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['api'] = trim($data['om-api-key']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($data['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     // The $lists variable will already have our list data, so just return the lists variable.
     return $this->build_list_html($res->syndications->syndication);
 }
Esempio n. 2
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  */
 public function authenticate($args = array(), $optin_id)
 {
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['label'] = 'MailPoet';
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists();
 }
Esempio n. 3
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  */
 public function authenticate($args = array(), $optin_id)
 {
     // Store the account reference in the optin data.
     $uniqid = uniqid();
     $meta = get_post_meta($optin_id, '_om_meta', true);
     $meta['email']['provider'] = $this->provider;
     $meta['email']['account'] = $uniqid;
     $meta['custom_html'] = $args['content'];
     update_post_meta($optin_id, '_om_meta', $meta);
     // Flush any optin caches.
     Optin_Monster_Common::get_instance()->flush_optin_caches($optin_id);
 }
Esempio n. 4
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  *
  * @return string The client & list dropdown HTML
  */
 public function authenticate($args = array(), $optin_id)
 {
     $this->api['access'] = $args['om-access-token'];
     $this->api['expires'] = time() + $args['om-expires-in'];
     // Save the account data for future reference.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['token'] = $this->api['access'];
     $providers[$this->provider][$uniqid]['expires'] = $this->api['expires'];
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists();
 }
Esempio n. 5
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $data     Data submitted by the user to be passed for authentication.
  * @param int   $optin_id The optin ID being used.
  *
  * @return string The list dropdown HTML
  */
 public function authenticate($data = array(), $optin_id)
 {
     // Call to ActiveCampaign.
     $this->api = new ActiveCampaign($data['om-api-url'], $data['om-api-key']);
     // Save the account data for future reference.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['url'] = trim($data['om-api-url']);
     $providers[$this->provider][$uniqid]['api'] = trim($data['om-api-key']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($data['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists(array('url' => $data['om-api-url'], 'api' => $data['om-api-key']));
 }
Esempio n. 6
0
 public function __construct()
 {
     // Get some useful class instances.
     $this->base = Optin_Monster::get_instance();
     $this->common = Optin_Monster_Common::get_instance();
     $this->admin = Optin_Monster_Menu_Admin::get_instance();
     // Make sure get_plugins() is available.
     if (!function_exists('get_plugins')) {
         require_once ABSPATH . 'wp-admin/includes/plugin.php';
     }
     // See if we've done this before and save the auth info.
     $this->auth = get_option('awesomemotive_auth');
     // Find out what kind of request we'll be making.
     $this->request_type = $this->get_request_type();
     // Gather the required data.
     $this->data = $this->gather_data();
 }
Esempio n. 7
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  *
  * @return  string|object   Output of the email lists or WP_Error
  */
 public function authenticate($args = array(), $optin_id)
 {
     // Instantiate the API
     $this->api = new GetResponse_OM($args['om-api-key']);
     // Make sure we can communicate with GetResponse
     $ping = $this->api->ping();
     if (!$ping) {
         return $this->error('api-error', __('There was an error connecting to the GetResponse API. Please check your credentials.', 'optin-monster'));
     }
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['api'] = trim($args['om-api-key']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists();
 }
Esempio n. 8
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array  $args     Args to be passed for authentication.
  * @param int    $optin_id The optin ID to target.
  * @param string $uniqid   The account ID to target.
  *
  * @return  string|object Output of the email lists or WP_Error
  */
 public function authenticate($args = array(), $optin_id)
 {
     // Instantiate the API.
     $this->api = new TotalSend($args['om-email-address'], $args['om-password']);
     // Make sure we can communicate with TotalSend.
     $test_connection = $this->api->getConnection();
     if (false == $test_connection['Success']) {
         return $this->error('api-error', sprintf(__('Cannot authenticate. TotalSend returned the following error: <em>%s</em>.', 'optin-monster'), $test_connection['ErrorText'][0]));
     }
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['email'] = trim($args['om-email-address']);
     $providers[$this->provider][$uniqid]['password'] = trim($args['om-password']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists();
 }
Esempio n. 9
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $data     Data submitted by the user to be passed for authentication.
  * @param int   $optin_id The optin ID being used.
  *
  * @return string The list dropdown HTML
  */
 public function authenticate($args = array(), $optin_id)
 {
     // Attempt to authenticate with Infusionsoft
     try {
         $this->api = new iSDK();
         $this->api->cfgCon($args['om-subdomain'], $args['om-api-key'], 'throw');
     } catch (iSDKException $e) {
         return $this->error('auth-error', sprintf(__('There was an error authenticating with Infusionsoft. %s', 'optin-monster'), $e->getMessage()));
     }
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['app'] = trim($args['om-subdomain']);
     $providers[$this->provider][$uniqid]['api'] = trim($args['om-api-key']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists();
 }
Esempio n. 10
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  *
  * @return  string|object   Output of the email lists or WP_Error
  */
 public function authenticate($args = array(), $optin_id)
 {
     // Instantiate and save the API
     $this->api = new MadMimi($args['om-email-address'], $args['om-api-key']);
     libxml_use_internal_errors(true);
     // Make sure we can communicate with Mad Mimi.
     $test_call = simplexml_load_string($this->api->Lists());
     if (!$test_call) {
         return $this->error('auth-error', __('Unable to authenticate with the Mad Mimi API. Please check your credentials.', 'optin-monster'));
     }
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['username'] = trim($args['om-email-address']);
     $providers[$this->provider][$uniqid]['api'] = trim($args['om-api-key']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists();
 }
Esempio n. 11
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  *
  * @return  string|object   Output of the email lists or WP_Error
  */
 public function authenticate($args = array(), $optin_id)
 {
     // Instantiate the API
     $this->api = new Mailin('https://api.sendinblue.com/v1.0', $args['om-api-key'], $args['om-secret-key']);
     // Make sure we can communicate with SendinBlue
     $test_call = $this->api->get_account();
     if (!$test_call) {
         return $this->error('auth-error', __('There was a problem with your credentials.', 'optin-monster'));
     }
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['access_key'] = trim($args['om-api-key']);
     $providers[$this->provider][$uniqid]['secret_key'] = trim($args['om-secret-key']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     // Return all of the list output from SendinBlue.
     return $this->get_lists();
 }
Esempio n. 12
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  *
  * @return string The client & list dropdown HTML
  */
 public function authenticate($args = array(), $optin_id)
 {
     $auth = array('site_id' => $args['om-site-id'], 'api_key' => $args['om-api-key']);
     // Make sure we can communicate with Customer.io
     try {
         $this->api = $this->customerio_api(null, $auth, 'auth');
     } catch (Exception $e) {
         $message = $e->getMessage();
         return $this->error('auth-error', __('There was a problem authenticating with Customer.io.', 'optin-monster'));
     }
     // Save the integration data.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['api'] = trim($args['om-api-key']);
     $providers[$this->provider][$uniqid]['site'] = trim($args['om-site-id']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists();
 }
Esempio n. 13
0
 /**
  * Authentication method for providers.
  *
  * @since 2.1.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  */
 public function authenticate($args = array(), $optin_id)
 {
     $this->list_api = new ML_Lists($args['om-api-key']);
     // Let's make sure we can successfully connect
     $response_body = json_decode($this->list_api->getAll());
     $response_info = $this->list_api->getResponseInfo();
     // Return an error if something went wrong
     if (200 != $response_info['http_code']) {
         return $this->error('api-error', __('There was an issue connecting to the MailerLite API. Please check your credentials', 'optin-monster'));
     }
     $this->lists = $response_body->Results;
     // Save the account data for future reference.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['api-key'] = trim($args['om-api-key']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     // Return the lists
     return $this->get_lists();
 }
Esempio n. 14
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  *
  * @return string The client & list dropdown HTML
  */
 public function authenticate($args = array(), $optin_id)
 {
     $this->api = new Emma($args['om-account-id'], $args['om-api-key'], $args['om-secret-key']);
     // Make sure we can communicate to Emma
     try {
         $test = $this->api->myAccountSummary();
     } catch (Exception $e) {
         return $this->error('auth-error', __('There was an error authenticating with Emma. Please verify your API credentials.', 'optin-monster'));
     }
     // Save the integration info
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['api'] = trim($args['om-api-key']);
     $providers[$this->provider][$uniqid]['secret'] = trim($args['om-secret-key']);
     $providers[$this->provider][$uniqid]['account'] = trim($args['om-account-id']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     // Return all of the list output from Emma.
     return $this->get_lists();
 }
Esempio n. 15
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param   array $args     Args to be passed for authentication.
  * @param   int   $optin_id The optin ID to target.
  *
  * @return  string|object       Output of email lists or WP_Error
  */
 public function authenticate($args = array(), $optin_id)
 {
     $api_data = array('email' => $args['om-email-address'], 'password' => $args['om-password'], 'user_key' => $args['om-user-key']);
     // Instantiate the API.
     $this->api = new Pardot_OM_API();
     // Authenticate with Pardot.
     $this->api_key = $this->api->authenticate($api_data);
     if ($this->api->error) {
         return $this->error('auth-error', sprintf(__('Sorry, but Pardot was unable to grant access to your account. Pardot gave this response: <em>%s</em>. Please check your login information.', 'optin-monster'), $this->api->error));
     }
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['email'] = trim($args['om-email-address']);
     $providers[$this->provider][$uniqid]['password'] = trim($args['om-password']);
     $providers[$this->provider][$uniqid]['user_key'] = trim($args['om-user-key']);
     $providers[$this->provider][$uniqid]['api_key'] = trim($this->api_key);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists();
 }
Esempio n. 16
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Args to be passed for authentication.
  * @param int   $optin_id The optin ID to target.
  */
 public function authenticate($args = array(), $optin_id)
 {
     $auth = array('appId' => $args['om-app-id'], 'apiPassword' => $args['om-app-password'], 'apiUsername' => $args['om-username']);
     // Instantiate and authenticate with iContact.
     try {
         iContactApi::getInstance()->setConfig($auth);
         $this->api = iContactApi::getInstance();
     } catch (Exception $e) {
         $errors = $this->api->getErrors();
         return $this->error('auth-error', sprintf(__('There was an error authenticating with iContact. The following error was returned: <em>%s</em>', $errors[0])));
     }
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['app_id'] = trim($args['om-app-id']);
     $providers[$this->provider][$uniqid]['app_pass'] = trim($args['om-app-password']);
     $providers[$this->provider][$uniqid]['username'] = trim($args['om-username']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     return $this->get_lists();
 }
Esempio n. 17
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $data     Data submitted by the user to be passed for authentication.
  * @param int   $optin_id The optin ID being used.
  *
  * @return string The list dropdown HTML
  */
 public function authenticate($data = array(), $optin_id)
 {
     // Attempt to connect to the MailChimp API.
     $this->api = new OM_Mailchimp($data['om-api-key']);
     try {
         $this->api->helper->ping();
     } catch (Mailchimp_Invalid_ApiKey $e) {
         return $this->error('api-error', $e->getMessage());
     } catch (Exception $e) {
         return $this->error('api-error', $e->getMessage());
     }
     // Save the account data for future reference.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['api'] = trim($data['om-api-key']);
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($data['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     // Return all of the list output from MailChimp.
     return $this->get_lists(array('api' => $data['om-api-key']));
 }
Esempio n. 18
0
 /**
  * Authentication method for providers.
  *
  * @since 2.0.0
  *
  * @param array $args     Data submitted by the user to be passed for authentication.
  * @param int   $optin_id The optin ID being used.
  *
  * @return  string|object Output of the email lists or WP_Error.
  */
 public function authenticate($args = array(), $optin_id)
 {
     list($auth_key, $auth_token, $req_key, $req_token, $oauth) = explode('|', $args['om-auth-code']);
     $this->api = new AWeberAPI($auth_key, $auth_token);
     $this->api->user->requestToken = $req_key;
     $this->api->user->tokenSecret = $req_token;
     $this->api->user->verifier = $oauth;
     // Retrieve an access token
     try {
         list($this->access_token, $this->access_token_secret) = $this->api->getAccessToken();
     } catch (AWeberException $e) {
         return $this->error('api-error', sprintf(__('Sorry, but AWeber was unable to verify your authorization token. AWeber gave the following response: <em>%s</em>', 'optin-monster'), $e->getMessage()));
     }
     // Verify we can connect to AWeber
     try {
         $account = $this->api->getAccount();
     } catch (AWeberException $e) {
         return $this->error('api-error', sprintf(__('Sorry, but AWeber was unable to grant access to your account. AWeber gave the following response: <em>%s</em>', 'optin-monster'), $e->getMessage()));
     }
     // Save the account data for future reference.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $uniqid = uniqid();
     $providers[$this->provider][$uniqid]['auth_key'] = $auth_key;
     $providers[$this->provider][$uniqid]['auth_token'] = $auth_token;
     $providers[$this->provider][$uniqid]['access_token'] = $this->access_token;
     $providers[$this->provider][$uniqid]['access_secret'] = $this->access_token_secret;
     $providers[$this->provider][$uniqid]['label'] = trim(strip_tags($args['om-account-label']));
     update_option('optin_monster_providers', $providers);
     // Store the account reference in the optin data.
     $this->save_account($optin_id, $this->provider, $uniqid);
     // Return all of the list output from AWeber.
     return $this->get_lists();
 }
Esempio n. 19
0
 /**
  * Processes any bulk optin actions.
  *
  * @since 2.0.0
  */
 public function process_bulk_actions()
 {
     // Prepare variables.
     $ids = isset($_GET['optin']) ? $_GET['optin'] : false;
     $action = $this->current_action();
     // If the $ids variable is not an array, cast it as such.
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     // If there are no ids or the action is empty, return early.
     if (empty($ids) || empty($action)) {
         return;
     }
     // Loop through the IDs and process the action.
     foreach ($ids as $id) {
         switch ($action) {
             case 'delete':
                 wp_delete_post($id, true);
                 // Delete any split tests if they exist.
                 $clones = $this->base->get_split_tests($id);
                 if ($clones) {
                     foreach ($clones as $clone) {
                         wp_delete_post($clone->ID, true);
                     }
                 }
                 break;
             case 'reset-stats':
                 update_post_meta($id, 'om_counter', (int) 0);
                 update_post_meta($id, 'om_conversions', (int) 0);
                 break;
         }
         // Provide a hook to do extra things in the bulk action.
         do_action('optin_monster_table_bulk_action', $action, $id);
         // Flush any optin caches.
         Optin_Monster_Common::get_instance()->flush_optin_caches($id);
     }
 }
Esempio n. 20
0
/**
 * Deletes an integration for an email provider.
 *
 * @since 2.0.0
 */
function optin_monster_ajax_delete_integration()
{
    $hash = stripslashes($_POST['hash']);
    $provider = stripslashes($_POST['provider']);
    $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
    $response = array();
    if (isset($providers[$provider][$hash])) {
        unset($providers[$provider][$hash]);
        if (0 == count($providers[$provider])) {
            unset($providers[$provider]);
            $response['provider_empty'] = true;
        }
    }
    $updated = update_option('optin_monster_providers', $providers);
    $response['updated'] = $updated;
    die(json_encode($response));
}
Esempio n. 21
0
 /**
  * Processes any bulk optin actions.
  *
  * @since 2.0.0
  */
 public function process_bulk_actions()
 {
     // Prepare variables.
     $ids = isset($_GET['optin']) ? (array) $_GET['optin'] : array();
     $action = $this->current_action();
     // If there are no ids or the action is empty, return early.
     if (empty($ids) || empty($action)) {
         return;
     }
     // Loop through the IDs and process the action.
     foreach ($ids as $id) {
         switch ($action) {
             case 'delete':
                 wp_delete_post($id, true);
                 // Remove clone association from main optin.
                 $clones = get_post_meta($this->optin_id, '_om_has_clone', true);
                 if (($key = array_search($id, (array) $clones)) !== false) {
                     unset($clones[$key]);
                     $clones = array_filter($clones);
                     update_post_meta($this->optin_id, '_om_has_clone', $clones);
                 }
                 break;
             case 'reset-stats':
                 update_post_meta($id, 'om_counter', (int) 0);
                 update_post_meta($id, 'om_conversions', (int) 0);
                 break;
         }
         // Provide a hook to do extra things in the bulk action.
         do_action('optin_monster_table_bulk_action', $action, $id);
         // Flush any optin caches.
         Optin_Monster_Common::get_instance()->flush_optin_caches($id);
         Optin_Monster_Common::get_instance()->flush_optin_caches($this->optin_id);
     }
 }
Esempio n. 22
0
 /**
  * Retrieves a new access token if needed
  *
  * @since 2.0.0
  *
  * @param string $uniqid        The integration ID
  * @param string $refresh_token The refresh token associated with the integration
  *
  * @return string|WP_Error
  */
 private function refresh_access_token($uniqid, $refresh_token)
 {
     // Setup the request.
     $base_url = 'https://api.createsend.com/oauth/token';
     $params = array('method' => 'POST', 'body' => array('grant_type' => 'refresh_token', 'refresh_token' => $refresh_token));
     // Perform the request.
     $result = wp_remote_post($base_url, $params);
     // Return an error if there was a problem with the request.
     if (is_wp_error($result) || $result && $result['response']['code'] == 401) {
         return $this->error('refresh-error', __('There was a problem accessing Campaign Monitor. Please contact the site owner.', 'optin-monster'));
     }
     $body = json_decode($result['body']);
     // Save the new account tokens.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $providers[$this->provider][$uniqid]['access'] = $body->access_token;
     $providers[$this->provider][$uniqid]['refresh'] = $body->refresh_token;
     $providers[$this->provider][$uniqid]['expires'] = time() + $body->expires_in;
     update_option('optin_monster_providers', $providers);
     // Return the new access token for immediate use.
     return $body->access_token;
 }
Esempio n. 23
0
 /**
  * Makes a split test the primary optin.
  *
  * @since 2.0.0
  */
 public function make_primary()
 {
     // Prepare variables.
     $new_primary = $this->optin->ID;
     $original_primary = $this->split;
     $original_clones = get_post_meta($original_primary, '_om_has_clone', true);
     // Remove the split that is about to be made primary from the clones array.
     if (($key = array_search($new_primary, (array) $original_clones)) !== false) {
         unset($original_clones[$key]);
         $original_clones = array_filter($original_clones);
     }
     // Add the original primary as a clone of the new primary, set it as a split test and deactivate.
     $original_clones[] = $original_primary;
     $original_meta = get_post_meta($original_primary, '_om_meta', true);
     $original_meta['display']['enabled'] = 0;
     update_post_meta($original_primary, '_om_meta', $original_meta);
     update_post_meta($original_primary, '_om_is_clone', $new_primary);
     delete_post_meta($original_primary, '_om_test_mode');
     // Remove the meta key for saying the current split is a split test, and add the clones to it.
     delete_post_meta($new_primary, '_om_is_clone');
     update_post_meta($new_primary, '_om_has_clone', $original_clones);
     // Update each clone so that it references the new parent optin.
     foreach ((array) $original_clones as $clone) {
         update_post_meta($clone, '_om_is_clone', $new_primary);
     }
     // Provide an API to modify data.
     do_action('optin_monster_primary_optin', $this->optin_id, $this->optin, $this->split);
     // Flush any optin caches now since we will have to do a redirect.
     Optin_Monster_Common::get_instance()->flush_optin_caches($this->optin_id, is_object($this->optin) ? $this->optin->post_name : '');
     if ($this->split) {
         Optin_Monster_Common::get_instance()->flush_optin_caches($this->split);
     }
     // Now we need to do a redirect because the old primary optin no longer exists.
     wp_redirect(add_query_arg(array('om_primary' => true, 'om_title' => urlencode($this->get_optin_title())), admin_url('admin.php?page=optin-monster-settings')));
     exit;
 }
Esempio n. 24
0
 /**
  * Method for saving API account info to an optin.
  *
  * @since 2.0.0
  *
  * @param int $optin_id    The ID of the optin to target.
  * @param string $provider The email provider slug.
  * @param string $account  The unique account ID for the optin.
  */
 public function save_account($optin_id, $provider, $account)
 {
     $meta = get_post_meta($optin_id, '_om_meta', true);
     $meta['email']['provider'] = $provider;
     $meta['email']['account'] = $account;
     update_post_meta($optin_id, '_om_meta', $meta);
     // Flush any optin caches.
     Optin_Monster_Common::get_instance()->flush_optin_caches($optin_id);
     // Now reset the meta property with our updated meta field.
     Optin_Monster_Output::get_instance()->meta = get_post_meta($optin_id, '_om_meta', true);
 }
Esempio n. 25
0
 private function get_access_token($uniqid, $args, $refresh = true)
 {
     // Build the request URL
     $url = "https://{$args['subdomain']}.mktorest.com/identity/oauth/token?grant_type=client_credentials&client_id={$args['client_id']}&client_secret={$args['client_secret']}";
     // Send the auth request
     $request = wp_remote_get($url);
     $body = json_decode(wp_remote_retrieve_body($request));
     if (array_key_exists('error', $body)) {
         throw new Exception('The API credentials you provided are not correct.');
     }
     // Save the new account info if this is a refresh
     if ($refresh) {
         $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
         $providers[$this->provider][$uniqid]['access'] = $body->access_token;
         $providers[$this->provider][$uniqid]['expires'] = time() + $body->expires_in;
         update_option('optin_monster_providers', $providers);
     }
     // Return the new access token for immediate use.
     return $body;
 }
Esempio n. 26
0
    /**
     * Displays the UI view.
     *
     * @since 2.0.0
     */
    public function display()
    {
        $registered = Optin_Monster_Common::get_instance()->get_email_providers(true);
        ?>
        <div id="optin-monster-settings-<?php 
        echo $this->tab;
        ?>
">
        <?php 
        if (empty($registered)) {
            ?>
            <div class="error below-h2"><p><?php 
            _e('You have not registered any email service provider integrations.', 'optin-monster');
            ?>
</p></div>
        <?php 
        } else {
            ?>
            <div class="optin-integrations om-clearfix">
                <?php 
            $i = 1;
            foreach ($registered as $provider => $array) {
                $class = 0 == $i % 3 ? ' last' : '';
                ?>
                    <?php 
                if (1 == $i || 1 == $i % 3) {
                    ?>
                        <div class="optin-integration-wrap om-clearfix">
                    <?php 
                }
                ?>
                    <div class="optin-integration <?php 
                echo $provider . $class;
                ?>
">
                        <div class="logo"></div>
                        <ul class="integration om-clearfix">
                            <?php 
                foreach ($array as $hash => $data) {
                    ?>
                                <li><span class="name"><?php 
                    echo $data['label'];
                    ?>
</span> <a class="button button-secondary button-small delete-integration" href="#" title="<?php 
                    esc_attr_e('Delete Integration', 'optin-monster');
                    ?>
" data-provider="<?php 
                    echo $provider;
                    ?>
" data-hash="<?php 
                    echo $hash;
                    ?>
"><?php 
                    _e('Delete', 'optin-monster');
                    ?>
</a></li>
                            <?php 
                }
                ?>
                        </ul>
                    </div>
                    <?php 
                if (0 == $i % 3 || $i == count($registered)) {
                    ?>
                        </div>
                    <?php 
                }
                $i++;
                ?>
                <?php 
            }
            ?>
            </div>
        <?php 
        }
        ?>
        </div>
        <?php 
    }
Esempio n. 27
0
 /**
  * Retrieves a new access token if needed.
  *
  * @since 2.0.0
  *
  * @param string $uniqid        The integration ID.
  * @param arrsy $args           The HubSpot account args.
  * @param string $refresh_token The refresh token associated with the integration.
  *
  * @return string|WP_Error
  */
 private function refresh_access_token($uniqid, $args, $refresh_token)
 {
     // Setup the request.
     $base_url = 'https://api.hubapi.com/auth/v1/refresh';
     $params = array('method' => 'POST', 'body' => array('refresh_token' => $refresh_token, 'client_id' => '4c4b2343-fd6a-11e3-aead-bddfb3c95bea', 'grant_type' => 'refresh_token'));
     // Perform the request.
     $result = wp_remote_post($base_url, $params);
     // Return an error if there was a problem with the request.
     if (is_wp_error($result) || $result && $result['response']['code'] == 401) {
         return $this->error('refresh-error', __('There was a problem accessing HubSpot. Please contact the site owner.', 'optin-monster'));
     }
     $body = json_decode($result['body']);
     // Save the new account tokens.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $providers[$this->provider][$uniqid]['portalid'] = $args['portalid'];
     $providers[$this->provider][$uniqid]['label'] = $args['label'];
     $providers[$this->provider][$uniqid]['access'] = $body->access_token;
     $providers[$this->provider][$uniqid]['refresh'] = $body->refresh_token;
     $providers[$this->provider][$uniqid]['expires'] = time() + $body->expires_in;
     update_option('optin_monster_providers', $providers);
     // Return the new access token for immediate use.
     return $body->access_token;
 }
Esempio n. 28
0
 /**
  * The class constructor.
  *
  * @since 2.0.0
  *
  * @param                               $data        The user data from the browser
  * @param Optin_Monster_Provider        $provider    The provider object
  * @param Optin_Monster_Lead_Datastore  $lead_store  The lead datastore object
  * @param Optin_Monster_Track_Datastore $track_store The tracking datastore object
  */
 public function __construct($data, Optin_Monster_Provider $provider, Optin_Monster_Lead_Datastore $lead_store, Optin_Monster_Track_Datastore $track_store)
 {
     // Set class properties.
     $this->provider = $provider;
     $this->lead_store = $lead_store;
     $this->track_store = $track_store;
     // Process the data from the browser.
     $lead['optin_id'] = isset($data['optin_id']) ? absint($data['optin_id']) : 0;
     $lead['referrer'] = isset($data['referrer']) ? stripslashes(esc_url($data['referrer'])) : '';
     $lead['user_agent'] = isset($data['user_agent']) ? stripslashes(strip_tags($data['user_agent'])) : '';
     $lead['lead_name'] = isset($data['name']) ? stripslashes($data['name']) : '';
     $lead['lead_email'] = isset($data['email']) ? stripslashes($data['email']) : '';
     $lead['referred_from'] = isset($data['previous']) ? stripslashes(esc_url($data['previous'])) : '';
     $lead['post_id'] = isset($data['post_id']) ? absint($data['post_id']) : 0;
     $lead['lead_type'] = 'conversion';
     // Get the optin meta data.
     $this->optin_meta = get_post_meta($lead['optin_id'], '_om_meta', true);
     // Provide a hook to save custom tracking data.
     do_action('optin_monster_track_optin', $lead['optin_id'], 'conversion');
     // Increase the conversion counter.
     if (apply_filters('optin_monster_tracking', true, $lead['optin_id'])) {
         try {
             $track = $this->track_store->save('conversion');
         } catch (Exception $e) {
             $this->response = $e->getMessage();
         }
     }
     // Save the lead in the database.
     $option = get_option('optin_monster');
     if (isset($option['leads']) && $option['leads']) {
         try {
             $save = $this->lead_store->save($lead);
         } catch (Exception $e) {
             $this->response = $e->getMessage();
         }
     }
     // Save the lead to the email provider.
     $providers = Optin_Monster_Common::get_instance()->get_email_providers(true);
     $provider = $this->optin_meta['email']['provider'];
     $account = $this->optin_meta['email']['account'];
     $list_id = $this->optin_meta['email']['list_id'];
     // Prepare the provider account.
     $provider_account = $providers[$provider][$account];
     $provider_account['account_id'] = $account;
     // Get segments if set.
     if (!empty($this->optin_meta['email']['segments'])) {
         $provider_account['segments'] = $this->optin_meta['email']['segments'];
     }
     // Get client if set.
     if (!empty($this->optin_meta['email']['client_id'])) {
         $provider_account['client'] = $this->optin_meta['email']['client_id'];
     }
     // Set the response.
     $this->response = $this->provider->optin($provider_account, $list_id, $lead);
     // Provide a hook to interact with the lead.
     do_action('optin_monster_after_lead_stored', $lead, $this);
     // Allow the response to be filtered (as long as it is not an error) so that lead data can be passed back to redirect URLs.
     if (!is_wp_error($this->response)) {
         $this->response = apply_filters('optin_monster_lead_response', $this->response, $lead, $this);
     }
 }
Esempio n. 29
0
 /**
  * Retrieves the panel content for the Integration panel.
  *
  * @since 2.0.0
  *
  * @param string HTML string of panel content.
  */
 public function get_integration_panel_content()
 {
     $html = $this->get_dropdown_field('provider', $this->get_email_setting('provider'), Optin_Monster_Common::get_instance()->get_email_providers(), __('Email provider', 'optin-monster'));
     return $html;
 }
Esempio n. 30
0
 /**
  * Returns the singleton instance of the class.
  *
  * @since 2.0.0
  *
  * @return object The Optin_Monster_Common object.
  */
 public static function get_instance()
 {
     if (!isset(self::$instance) && !self::$instance instanceof Optin_Monster_Common) {
         self::$instance = new Optin_Monster_Common();
     }
     return self::$instance;
 }