/**
  * Get  Lists from cache or renew
  *
  * @param bool $force_renewal
  *
  * @return mixed
  *
  */
 public function get_lists($force_renewal = false)
 {
     $lists = array();
     $cached_lists = get_transient('spu_infusionsoft_lists');
     // if empty try older one
     if (empty($cached_lists)) {
         $cached_lists = get_transient('spu_infusionsoft_lists_fallback');
     }
     if ((true === $force_renewal || false === $cached_lists || empty($cached_lists)) && isset($this->account)) {
         try {
             // Query Infusionsoft for available tags.
             $page = 0;
             while (true) {
                 $res = $this->api->dsQuery('ContactGroup', 1000, $page, array('Id' => '%'), array('Id', 'GroupName'));
                 $lists = array_merge($lists, $res);
                 if (count($res) < 1000) {
                     break;
                 }
                 $page++;
             }
         } catch (Exception $e) {
             SPU_Errors::display_error(sprintf(__('Sorry, but Infusionsoft  was unable to grant access to your account. Infusionsoft  gave the following response: <em>%s</em>', 'spup'), $e->getMessage()));
             return array();
         }
         set_transient('spu_infusionsoft_lists', $lists, 24 * 3600);
         // 1 day
         set_transient('spu_infusionsoft_lists_fallback', $lists, 24 * 3600 * 7);
         // 1 week
     } else {
         if (!empty($cached_lists)) {
             $lists = $cached_lists;
         }
     }
     return $lists;
 }
 /**
  * Get Mailchimp Lists from cache or renew
  *
  * @param bool $force_renewal
  *
  * @return mixed
  *
  */
 public function get_lists($force_renewal = false)
 {
     $lists = array();
     $cached_lists = get_transient('spu_ccontact_lists');
     // if empty try older one
     if (empty($cached_lists)) {
         $cached_lists = get_transient('spu_ccontact_lists_fallback');
     }
     if (true === $force_renewal || false === $cached_lists || empty($cached_lists)) {
         try {
             $lists = $this->api->get_lists();
         } catch (Exception $e) {
             SPU_Errors::display_error(sprintf(__('Sorry, but Constant Contact was unable to grant access to your account. Constant Contact gave the following response: <em>%s</em>', 'spup'), $e->getMessage()));
             return array();
         }
         set_transient('spu_ccontact_lists', $lists, 24 * 3600);
         // 1 day
         set_transient('spu_ccontact_lists_fallback', $lists, 24 * 3600 * 7);
         // 1 week
     } else {
         if (!empty($cached_lists)) {
             $lists = $cached_lists;
         }
     }
     return $lists;
 }
 /**
  * Save error to class and hook error box action
  * @param $string
  *
  * @return bool
  */
 public static function display_error($string)
 {
     if (!is_admin() || !current_user_can('manage_options')) {
         return false;
     }
     self::$error_message = $string;
     add_action('spu/integrations_page/before', array('SPU_Errors', 'error_box'));
     return true;
 }
 /**
  * Pings the MailChimp API to see if we're connected
  * @return boolean
  */
 public function is_connected()
 {
     if ($this->connected !== null) {
         return $this->connected;
     }
     $this->connected = false;
     $result = $this->api->call('helper/ping');
     if ($result !== false) {
         if (isset($result->msg) && $result->msg === "Everything's Chimpy!") {
             $this->connected = true;
         } else {
             SPU_Errors::display_error('MailChimp Error: ' . $result->error);
         }
     }
     return $this->connected;
 }
 /**
  * Pings the GetResponse API to see if we're connected
  * @return boolean
  */
 public function is_connected()
 {
     if ($this->connected !== null) {
         return $this->connected;
     }
     $this->connected = false;
     $result = $this->api->ping();
     if ($result !== false) {
         if (isset($result) && $result['ping'] === 'pong') {
             $this->connected = true;
         } else {
             SPU_Errors::display_error('GetResponse Error: ' . $result['message']);
         }
     }
     return $this->connected;
 }
 /**
  * Calls the MailChimp API
  *
  * @uses WP_HTTP
  *
  * @param string $method
  * @param array $data
  *
  * @return object
  */
 public function call($method, array $data = array())
 {
     // do not make request when no api key was provided.
     if (empty($this->api_key)) {
         SPU_Errors::display_error('Mailchimp Error: Empty api key');
         return false;
     }
     $data['apikey'] = $this->api_key;
     $url = $this->api_url . $method . '.json';
     $response = wp_remote_post($url, array('body' => $data, 'timeout' => 15, 'headers' => array('Accept-Encoding' => ''), 'sslverify' => false));
     if (is_wp_error($response)) {
         // show error message to admins
         SPU_Errors::display_error('Mailchimp Error: ' . $response->get_error_message());
         return false;
     }
     $body = wp_remote_retrieve_body($response);
     $response = json_decode($body);
     // store response
     $this->last_response = $response;
     return $response;
 }
Ejemplo n.º 7
0
 /**
  * Get Mailchimp Lists from cache or renew
  *
  * @param bool $force_renewal
  *
  * @return mixed
  *
  */
 public function get_lists($force_renewal = false)
 {
     $lists = array();
     $cached_lists = get_transient('spu_aweber_lists');
     // if empty try older one
     if (empty($cached_lists)) {
         $cached_lists = get_transient('spu_aweber_lists_fallback');
     }
     if ((true === $force_renewal || false === $cached_lists || empty($cached_lists)) && isset($this->account)) {
         try {
             $lists = $this->account->loadFromUrl('/accounts/' . $this->account->id . '/lists');
         } catch (AWeberException $e) {
             SPU_Errors::display_error(sprintf(__('Sorry, but AWeber was unable to grant access to your account. AWeber gave the following response: <em>%s</em>', 'spup'), $e->getMessage()));
             return array();
         }
         set_transient('spu_aweber_lists', $lists, 24 * 3600);
         // 1 day
         set_transient('spu_aweber_lists_fallback', $lists, 24 * 3600 * 7);
         // 1 week
     } else {
         if (!empty($cached_lists)) {
             $lists = $cached_lists;
         }
     }
     return $lists;
 }