CC_GF_SuperClass

The Gravity Forms Constant Contact Add-On CC GF SuperClass class.

Defined (1)

The class is defined in the following location(s).

/api/class.cc_gf_superclass.php  
  1. class CC_GF_SuperClass extends CC_Utility { 
  2.  
  3. /** @var GF_Constant_Contact */ 
  4. private $loader = null; 
  5.  
  6. /** @var CC_List */ 
  7. private $CC_List = null; 
  8.  
  9. /** @var CC_Contact */ 
  10. private $CC_Contact = null; 
  11.  
  12. /** @var CC_Utility */ 
  13. private $CC_Utility = null; 
  14.  
  15. /** @var CC_Campaign */ 
  16. private $CC_Campaign = null; 
  17.  
  18. /** @var string API path for server calls */ 
  19. public $apiPath = 'https://api.constantcontact.com/ws/customers/'; 
  20.  
  21. static $instance = null; 
  22.  
  23. /** 
  24. * @param string $user 
  25. * @param string $password 
  26. * @param GF_Constant_Contact $loader 
  27. * @return CC_GF_SuperClass 
  28. */ 
  29. static public function get_instance( $user = '', $password = '', $loader = null ) { 
  30.  
  31. if ( ! self::$instance ) { 
  32. self::$instance = new self( $user, $password, $loader ); 
  33.  
  34. return self::$instance; 
  35.  
  36. /** 
  37. * CC_GF_SuperClass constructor. 
  38. * @param null $user 
  39. * @param null $password 
  40. * @param GF_Constant_Contact $loader 
  41. */ 
  42. public function __construct( $user = null, $password=null, $loader = null ) { 
  43.  
  44. $this->login = $user; 
  45. $this->password = $password; 
  46. $this->loader = $loader; 
  47.  
  48. /** 
  49. * @param string $actionBy Who is creating the entries? If the business and not the customer, "ACTION_BY_CONTACT". Otherwise, "ACTION_BY_CUSTOMER". 
  50. */ 
  51. $actionBy = apply_filters('gravity_forms_constant_contact_action_by', 'ACTION_BY_CONTACT'); 
  52.  
  53. if($actionBy === 'ACTION_BY_CONTACT' || $actionBy === 'ACTION_BY_CUSTOMER') { 
  54. $this->actionBy = $actionBy; 
  55. } else { 
  56. $this->actionBy = 'ACTION_BY_CUSTOMER'; 
  57.  
  58. $this->curl_debug = isset($_GET['debug']) && ( function_exists('current_user_can') && current_user_can( 'manage_options' ) ); 
  59.  
  60. $this->CC_List = $this->get_object( 'CC_List' ); 
  61. $this->CC_Contact = $this->get_object( 'CC_Contact' ); 
  62. $this->CC_Campaign = $this->get_object( 'CC_Campaign' ); 
  63. $this->CC_Utility = $this->get_object( 'CC_Utility' ); 
  64.  
  65. parent::__construct(); 
  66.  
  67. /** 
  68. * @return array|false 
  69. */ 
  70. public function lists() { 
  71.  
  72. $dont_cache = isset( $_GET['cache'] ) && GFCommon::current_user_can_any( 'manage_options' ); 
  73.  
  74. if( ! $dont_cache && $lists = get_transient( 'gf_ctct_lists_' . $this->login ) ) { 
  75. return $lists; 
  76.  
  77. unset( $_GET['cache'] ); 
  78.  
  79. $lists = $this->CC_List()->getLists(); 
  80.  
  81. if ( $lists ) { 
  82. set_transient( 'gf_ctct_lists_' . $this->login, $lists, HOUR_IN_SECONDS ); 
  83.  
  84. return $lists; 
  85.  
  86. /** 
  87. * Check whether a subscriber exists at $email 
  88. * @param string $email 
  89. * @return bool|string False if not found; string numeric ID if found 
  90. */ 
  91. public function subscriber_exists( $email = '' ) { 
  92.  
  93. if ( GFCommon::is_invalid_or_empty_email( $email ) ) { 
  94. return false; 
  95.  
  96. return $this->CC_Contact()->subscriberExists( $email ); 
  97.  
  98. /** 
  99. * @param string $email 
  100. * @return array|false False if invalid email or contact not found. Array of contact details if found. 
  101. */ 
  102. public function get_subscriber_details( $email = '' ) { 
  103.  
  104. if ( GFCommon::is_invalid_or_empty_email( $email ) ) { 
  105. return false; 
  106.  
  107. return $this->CC_Contact()->getSubscriberDetails( $email ); 
  108.  
  109. /** 
  110. * Search by email address 
  111. * @param string $email 
  112. * @return array|bool 
  113. */ 
  114. public function search( $email = '' ) { 
  115.  
  116. if ( GFCommon::is_invalid_or_empty_email( $email ) ) { 
  117. return false; 
  118.  
  119. return $this->CC_Contact()->getSubscribers( $email ); 
  120.  
  121. /** 
  122. * @param null $user 
  123. * @param null $password 
  124. * @return bool 
  125. */ 
  126. public function is_valid_login() { 
  127.  
  128. $api = $this->CC_List(); 
  129.  
  130. ob_start(); 
  131. $lists = $api->getAccountLists(); 
  132. $warnings = ob_get_clean(); 
  133.  
  134. update_option('gravity_forms_cc_valid_api', !empty($lists)); 
  135.  
  136. return empty($lists) ? false : true; 
  137.  
  138. /** 
  139. * Factory for fetching and populating CC_Utility objects 
  140. * The CC_Utility objects need to have login and password set. 
  141. * @param string $class_name The class name 
  142. * @return CC_Contact|CC_List|CC_Utility|CC_Campaign|false 
  143. */ 
  144. public function get_object( $class_name = 'CC_List' ) { 
  145.  
  146. // The object has already been created 
  147. if ( ! empty( $this->{$class_name} ) ) { 
  148. return $this->{$class_name}; 
  149.  
  150. // How the heck did this happen? 
  151. if ( ! class_exists( $class_name ) ) { 
  152. return false; 
  153.  
  154. $object = new $class_name(); 
  155.  
  156. $object->login = $this->login; 
  157. $object->password = $this->password; 
  158.  
  159. if ( isset( $object->apiPath ) ) { 
  160. // The API path has already been generated by the class; there's no overriding it, so we regenerate it instead 
  161. $object->apiPath = str_replace( 'USERNAME', '', (string) $this->apiPath ) . trim( $this->login ); 
  162.  
  163. $object->actionBy = $this->actionBy; 
  164. $object->curl_debug = $this->curl_debug; 
  165.  
  166. if ( isset( $object->apikey ) ) { 
  167. $object->requestLogin = $this->apikey . '%' . $this->login . ':' . $this->password; 
  168.  
  169. return $object; 
  170.  
  171. /** 
  172. * @return CC_List 
  173. */ 
  174. public function CC_List() { 
  175. return $this->get_object('CC_List'); 
  176.  
  177. /** 
  178. * @return CC_Campaign 
  179. */ 
  180. public function CC_Campaign() { 
  181. return $this->get_object('CC_Campaign'); 
  182.  
  183. /** 
  184. * @return CC_Utility 
  185. */ 
  186. public function CC_Utility() { 
  187. return $this->get_object('CC_Utility'); 
  188.  
  189. /** 
  190. * @return CC_Contact 
  191. */ 
  192. public function CC_Contact() { 
  193. return $this->get_object('CC_Contact'); 
  194.