PluginProbe
Datafeedr API / 1.2.12
Datafeedr API v1.2.12
1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 All 181 releases
datafeedr-api / classes / class-dfrapi-env.php

class-dfrapi-env.php in Datafeedr API 1.2.12, at classes/class-dfrapi-env.php

325 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 } // Exit if accessed directly
6
7 if ( ! class_exists( 'Dfrapi_Env' ) ) {
8
9 /**
10 * Check environment and print errors..
11 */
12 class Dfrapi_Env {
13
14 function __construct() {
15
16 // Cascading Errors
17 if ( ! self::api_keys_exist() ) {
18 dfrapi_admin_messages( 'missing_api_keys' );
19 } elseif ( ! self::network_is_selected() ) {
20 dfrapi_admin_messages( 'missing_network_ids' );
21 } elseif ( ! self::merchant_is_selected() ) {
22 dfrapi_admin_messages( 'missing_merchant_ids' );
23 }
24
25 // Non-cascading Errors
26 if ( self::usage_over_90_percent() ) {
27 dfrapi_admin_messages( 'usage_over_90_percent' );
28 }
29
30 if ( self::missing_affiliate_ids() ) {
31 dfrapi_admin_messages( 'missing_affiliate_ids' );
32 }
33
34 if ( $msg = self::unapproved_zanox_merchants_exist() ) {
35 dfrapi_admin_messages( 'unapproved_zanox_merchants', $msg );
36 }
37
38 if ( $msg = self::unapproved_ph_merchants_exist() ) {
39 dfrapi_admin_messages( 'unapproved_ph_merchants', $msg );
40 }
41
42 if ( $msg = self::unapproved_effiliation_merchants_exist() ) {
43 dfrapi_admin_messages( 'unapproved_effiliation_merchants', $msg );
44 }
45 }
46
47 static function api_keys_exist() {
48
49 $configuration = (array) get_option( 'dfrapi_configuration' );
50 $access_id = false;
51 $secret_key = false;
52
53 if ( isset( $configuration['access_id'] ) && ( $configuration['access_id'] != '' ) ) {
54 $access_id = $configuration['access_id'];
55 }
56
57 if ( isset( $configuration['secret_key'] ) && ( $configuration['secret_key'] != '' ) ) {
58 $secret_key = $configuration['secret_key'];
59 }
60
61 if ( $access_id && $secret_key ) {
62 return true;
63 }
64
65 return false;
66 }
67
68 static function network_is_selected() {
69 $networks = (array) get_option( 'dfrapi_networks' );
70 if ( ! empty( $networks['ids'] ) ) {
71 return true;
72 }
73
74 return false;
75 }
76
77 static function merchant_is_selected() {
78 $merchants = (array) get_option( 'dfrapi_merchants' );
79 if ( ! empty( $merchants['ids'] ) ) {
80 return true;
81 }
82
83 return false;
84 }
85
86 static function usage_over_90_percent() {
87 $percentage = dfrapi_get_api_usage_percentage();
88 if ( $percentage >= 90 ) {
89 return true;
90 }
91
92 return false;
93 }
94
95 static function missing_affiliate_ids() {
96 $networks = get_option( 'dfrapi_networks', array() );
97 if ( ! empty( $networks ) ) {
98 foreach ( $networks['ids'] as $network ) {
99
100 $network_id = absint( $network['nid'] );
101
102 $parternize_network_ids = [ 801, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820 ];
103 $effiliation_network_ids = [ 805, 806, 807 ];
104
105 // Partnerize does not have affiliate IDs.
106 if ( in_array( $network_id, $parternize_network_ids ) ) {
107 continue;
108 }
109
110 // Effiliation does not have affiliate IDs.
111 if ( in_array( $network_id, $effiliation_network_ids ) ) {
112 continue;
113 }
114
115 if ( empty( $network['aid'] ) ) {
116 return true;
117 }
118 }
119 }
120
121 return false;
122 }
123
124 static function unapproved_zanox_merchants_exist() {
125
126 return false;
127
128 global $wpdb;
129
130 // Get range of Zanox Network IDs
131 $zanox_network_ids = range( 401, 430 );
132
133 // Get user's currently selected networks and convert into simple array of IDs.
134 $selected_networks = get_option( 'dfrapi_networks', array( 'ids' => array() ) );
135 $selected_network_ids = array_keys( $selected_networks['ids'] );
136
137 // See if any Zanox Network IDs are found in the user's selected network IDs.
138 $selected_zanox_ids = array_intersect( $zanox_network_ids, $selected_network_ids );
139
140 // If there are no selected Zanox IDs, return.
141 if ( empty( $selected_zanox_ids ) ) {
142 return false;
143 }
144
145 $results = $wpdb->get_results(
146 "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '%_transient_zmid_%' ",
147 OBJECT
148 );
149
150 // No results so nothing to worry about. Return false.
151 if ( empty( $results ) ) {
152 return false;
153 }
154
155 $unapproved_merchants = array();
156
157 foreach ( $results as $row ) {
158
159 if ( 'dfrapi_unapproved_zanox_merchant' != $row->option_value ) {
160 continue;
161 }
162
163 $name = $row->option_name; // Example: _transient_zmid_46627_1264955
164 $name = str_replace( '_transient_zmid_', '', $name );
165 $name = explode( '_', $name );
166 $name = array_filter( $name );
167
168 $merchant_id = absint( $name[0] );
169 $adspace_id = ( isset( $name[1] ) ) ? absint( $name[1] ) : '_empty_';
170
171 $unapproved_merchants[ $merchant_id ] = $adspace_id;
172 }
173
174 if ( empty( $unapproved_merchants ) ) {
175 return false;
176 }
177
178 $unapproved_merchant_ids = array_keys( $unapproved_merchants );
179
180 $merchants = dfrapi_api_get_merchants_by_id( $unapproved_merchant_ids );
181
182 $msg = '';
183
184 foreach ( $merchants as $merchant ) {
185 $mid = absint( $merchant['_id'] );
186 $msg .= '<br>- <strong>' . $merchant['name'] . '</strong> has not approved the Adspace ID: <strong>' . $unapproved_merchants[ $mid ] . '</strong>';
187 }
188
189 return $msg;
190 }
191
192 static function unapproved_ph_merchants_exist() {
193
194 global $wpdb;
195
196 // Get range of Partnerize Network IDs
197 $ph_network_ids = range( 801, 802 );
198
199 // Get user's currently selected networks and convert into simple array of IDs.
200 $selected_networks = get_option( 'dfrapi_networks', array( 'ids' => array() ) );
201 $selected_network_ids = array_keys( $selected_networks['ids'] );
202
203 // See if any Partnerize Network IDs are found in the user's selected network IDs.
204 $selected_ph_ids = array_intersect( $ph_network_ids, $selected_network_ids );
205
206 // If there are no selected Partnerize IDs, return.
207 if ( empty( $selected_ph_ids ) ) {
208 return false;
209 }
210
211 $results = $wpdb->get_results(
212 "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '%_transient_camref_%' ",
213 OBJECT
214 );
215
216 // No results so nothing to worry about. Return false.
217 if ( empty( $results ) ) {
218 return false;
219 }
220
221 $unapproved_merchants = array();
222
223 foreach ( $results as $row ) {
224
225 if ( 'dfrapi_unapproved_ph_merchant' != $row->option_value ) {
226 continue;
227 }
228
229 $name = $row->option_name; // Example: _transient_camref_46627
230 $name = str_replace( '_transient_camref_', '', $name );
231 $name = explode( '_', $name );
232 $name = array_filter( $name );
233
234 $merchant_id = absint( $name[0] );
235
236 $unapproved_merchants[ $merchant_id ] = $merchant_id;
237 }
238
239 if ( empty( $unapproved_merchants ) ) {
240 return false;
241 }
242
243 $unapproved_merchant_ids = array_keys( $unapproved_merchants );
244
245 $merchants = dfrapi_api_get_merchants_by_id( $unapproved_merchant_ids );
246
247 $msg = '';
248
249 foreach ( $merchants as $merchant ) {
250 $mid = absint( $merchant['_id'] );
251 $msg .= '<br>- <strong>' . $merchant['name'] . '</strong>';
252 }
253
254 return $msg;
255 }
256
257 static function unapproved_effiliation_merchants_exist() {
258
259 global $wpdb;
260
261 // Get range of Effiliation Network IDs
262 $effiliation_network_ids = range( 805, 807 );
263
264 // Get user's currently selected networks and convert into simple array of IDs.
265 $selected_networks = get_option( 'dfrapi_networks', array( 'ids' => array() ) );
266 $selected_network_ids = array_keys( $selected_networks['ids'] );
267
268 // See if any Effiliation Network IDs are found in the user's selected network IDs.
269 $selected_effiliation_ids = array_intersect( $effiliation_network_ids, $selected_network_ids );
270
271 // If there are no selected Effiliation IDs, return.
272 if ( empty( $selected_effiliation_ids ) ) {
273 return false;
274 }
275
276 $results = $wpdb->get_results(
277 "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '%_transient_effiliation_%' AND option_name != '_transient_effiliation_affiliate_ids' ",
278 OBJECT
279 );
280
281 // No results so nothing to worry about. Return false.
282 if ( empty( $results ) ) {
283 return false;
284 }
285
286 $unapproved_merchants = array();
287
288 foreach ( $results as $row ) {
289
290 if ( 'dfrapi_unapproved_effiliation_merchant' != $row->option_value ) {
291 continue;
292 }
293
294 $name = $row->option_name; // Example: _transient_effiliation_46627
295 $name = str_replace( '_transient_effiliation_', '', $name );
296 $name = explode( '_', $name );
297 $name = array_filter( $name );
298
299 $merchant_id = absint( $name[0] );
300
301 $unapproved_merchants[ $merchant_id ] = $merchant_id;
302 }
303
304 if ( empty( $unapproved_merchants ) ) {
305 return false;
306 }
307
308 $unapproved_merchant_ids = array_keys( $unapproved_merchants );
309
310 $merchants = dfrapi_api_get_merchants_by_id( $unapproved_merchant_ids );
311
312 $msg = '';
313
314 foreach ( $merchants as $merchant ) {
315 $mid = absint( $merchant['_id'] );
316 $msg .= '<br>- <strong>' . $merchant['name'] . '</strong>';
317 }
318
319 return $msg;
320 }
321
322 } // class Dfrapi_Env
323
324 } // class_exists check
325