PluginProbe
WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation / trunk
WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation vtrunk
1.4.48 1.4.47 1.4.46 1.4.45 1.4.44 1.4.43 1.4.42 1.4.41 1.4.40 1.4.39 1.4.38 1.4.37 1.4.36 1.1.2 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 All 64 releases
optin / includes / integrations / base / class-base-mail-integration.php

class-base-mail-integration.php in WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation trunk, at includes/integrations/base/class-base-mail-integration.php

165 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore
2
3 namespace OPTN\Includes\Integrations\Base;
4
5 use OPTN\Includes\Db;
6 use OPTN\Includes\Utils\Cache;
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Parent MailService class.
12 */
13 abstract class BaseMailIntegration implements MailIntegration {
14
15 /**
16 * Db instance
17 *
18 * @var Db $db Db variable
19 */
20 protected $db;
21
22
23 /**
24 * Account id
25 *
26 * @var int $account_id account id.
27 */
28 protected $account_id;
29
30 /**
31 * Settings for current account
32 *
33 * @var array $settings
34 */
35 protected $settings;
36
37 /**
38 * Constructor
39 *
40 * @param int|null $account_id account id.
41 */
42 public function __construct( $account_id ) {
43 $this->db = Db::get_instance();
44 $this->account_id = $account_id;
45 $this->settings = null;
46 }
47
48 /**
49 * Get name
50 *
51 * @return string
52 */
53 abstract public function get_name();
54
55 /**
56 * Adds subscriber
57 *
58 * @param array $data data.
59 * @return boolean
60 */
61 abstract public function add_subscriber( $data ): bool;
62
63 /**
64 * Add leads to lead table
65 *
66 * @param array $data user form input data.
67 * @return void
68 */
69 abstract public function add_lead( $data );
70
71 /**
72 * Gets all the fields
73 *
74 * @param array $args receive data as array.
75 * @return array
76 */
77 abstract public function get_fields( $args = array() ): array;
78
79
80 /**
81 * Gets all the lists
82 *
83 * @param array $args receive data as array.
84 * @return array
85 */
86 abstract public function get_lists( $args = array() ): array;
87
88 /**
89 * Gets user settings
90 *
91 * @return array
92 */
93 protected function get_settings() {
94
95 if ( is_null( $this->settings ) && $this->account_id ) {
96
97 $res = $this->db->get_integration( $this->account_id, false );
98 $this->settings = $res['data'];
99 }
100
101 return $this->settings;
102 }
103
104 /**
105 * Set lists cache
106 *
107 * @param array $value value.
108 * @return void
109 */
110 protected function set_lists_cache( $value ) {
111 $key = 'optn_int_' . $this->get_name() . '_lists_' . $this->account_id;
112 Cache::set( $key, wp_json_encode( $value ) );
113 }
114
115 /**
116 * Set fields cache
117 *
118 * @param array $value value.
119 * @return void
120 */
121 protected function set_fields_cache( $value ) {
122 $key = 'optn_int_' . $this->get_name() . '_fields_' . $this->account_id;
123 Cache::set( $key, wp_json_encode( $value ) );
124 }
125
126 /**
127 * Get lists cache
128 *
129 * @return mixed
130 */
131 protected function get_cached_lists() {
132 $key = 'optn_int_' . $this->get_name() . '_lists_' . $this->account_id;
133 $value = Cache::get( $key );
134 return $value ? json_decode( $value, true ) : null;
135 }
136
137 /**
138 * Get lists cache
139 *
140 * @return mixed
141 */
142 protected function get_cached_fields() {
143 $key = 'optn_int_' . $this->get_name() . '_fields_' . $this->account_id;
144 $value = Cache::get( $key );
145 return $value ? json_decode( $value, true ) : null;
146 }
147
148 /**
149 * Gets headers with authorization token
150 *
151 * @return array
152 */
153 protected function get_headers() {
154
155 $settings = $this->get_settings();
156
157 return array(
158 'User-Agent' => 'WowOptin/' . OPTN_VERSION,
159 'Content-Type' => 'application/json',
160 'Accept' => 'application/json',
161 'Authorization' => 'Bearer ' . $settings['apiKey'],
162 );
163 }
164 }
165