PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.3.2
JetFormBuilder — Dynamic Blocks Form Builder v3.3.2
3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 All 130 releases
jetformbuilder / includes / integrations / getresponse-handler.php
getresponse-handler.php
99 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Jet_Form_Builder\Integrations;
4
5 // If this file is called directly, abort.
6 if ( ! defined( 'WPINC' ) ) {
7 die;
8 }
9
10 /**
11 * Define Getresponse_Handler class
12 */
13 class Getresponse_Handler extends Integration_Base {
14
15 protected $api_base_url = 'https://api.getresponse.com/v3/';
16
17 /**
18 * Constructor for the class
19 *
20 * @param $api_key
21 */
22 public function __construct( $api_key ) {
23 parent::__construct( $api_key );
24
25 if ( empty( $api_key ) ) {
26 // phpcs:ignore Universal.CodeAnalysis.ConstructorDestructorReturn.ReturnValueFound
27 return new \WP_Error( 'invalid_api_key' );
28 }
29
30 $this->api_key = $api_key;
31 $this->api_request_args = array(
32 'headers' => array(
33 'X-Auth-Token' => 'api-key ' . $api_key,
34 'Content-Type' => 'application/json',
35 ),
36 );
37 }
38
39
40 public function get_all_data() {
41 $lists = $this->get_lists();
42 $fields = $this->get_fields();
43
44 return ( empty( $lists ) && empty( $fields ) ) ? array() : array(
45 'lists' => $lists,
46 'fields' => $fields,
47 );
48 }
49
50 public function get_lists() {
51 $result = array();
52 $lists = $this->request( 'campaigns' );
53
54 if ( ! empty( $lists ) ) {
55 foreach ( $lists as $list ) {
56 if ( ! is_array( $list ) ) {
57 continue;
58 }
59 if ( ! isset( $list['campaignId'] ) ) {
60 return array();
61 }
62
63 $result[ $list['campaignId'] ] = $list['name'];
64 }
65 }
66
67 return $result;
68 }
69
70 public function get_fields() {
71 $result = array(
72 'email' => array(
73 'label' => esc_html__( 'Email', 'jet-form-builder' ),
74 'required' => true,
75 ),
76 'name' => array(
77 'label' => esc_html__( 'Name', 'jet-form-builder' ),
78 'required' => false,
79 ),
80 );
81
82 $custom_fields = $this->request( 'custom-fields' );
83
84 if ( ! empty( $custom_fields ) ) {
85 foreach ( $custom_fields as $field ) {
86 if ( ! isset( $field['customFieldId'] ) ) {
87 return array();
88 }
89 $result[ $field['customFieldId'] ] = array(
90 'label' => $field['name'],
91 'required' => false,
92 );
93 }
94 }
95
96 return $result;
97 }
98 }
99