PluginProbe
Datafeedr API / 1.4.3
Datafeedr API v1.4.3
1.4.3 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 All 182 releases
datafeedr-api / classes / class-dfrapi-networks.php

class-dfrapi-networks.php in Datafeedr API 1.4.3, at classes/class-dfrapi-networks.php

403 lines 20.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 if ( ! class_exists( 'Dfrapi_Networks' ) ) {
9
10 /**
11 * Configuration page.
12 */
13 class Dfrapi_Networks {
14
15 private $page = 'dfrapi-networks';
16 private $key;
17 private $all_networks;
18 public $options;
19
20 public function __construct() {
21
22 $this->key = 'dfrapi_networks';
23 $this->all_networks = dfrapi_api_get_all_networks();
24 add_action( 'init', array( $this, 'load_settings' ) );
25 add_action( 'admin_init', array( $this, 'register_settings' ) );
26 add_action( 'admin_notices', array( $this, 'admin_notice' ) );
27 add_action( 'admin_notices', array( $this, 'api_errors' ) );
28 }
29
30 function api_errors() {
31 if ( array_key_exists( 'dfrapi_api_error', $this->all_networks ) ) {
32 echo '<div class="notice notice-error">';
33 dfrapi_output_api_error( $this->all_networks );
34 echo '</div>';
35 }
36 }
37
38 function admin_notice() {
39 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && $this->key == $_GET['page'] ) {
40 dfrapi_admin_notice( __( 'Networks successfully updated!', 'datafeedr-api' ), 'success' );
41 }
42 }
43
44 function load_settings() {
45 $this->options = (array) get_option( $this->key );
46 $this->options = array_merge( array(
47 'ids' => array(),
48 ), $this->options );
49 }
50
51 function register_settings() {
52 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
53 add_settings_section( 'networks', __( 'Select Networks', 'datafeedr-api' ), array(
54 &$this,
55 'section_networks_desc'
56 ), $this->page );
57 add_settings_field( 'ids', __( 'Networks', 'datafeedr-api' ), array(
58 &$this,
59 'field_network_ids'
60 ), $this->page, 'networks', array( 'label_for' => 'DFRAPI_HIDE_LABEL' ) );
61 }
62
63 function section_networks_desc() {
64 echo __( 'Select the affiliate networks you belong to, enter your affiliate ID for each then click <strong>[Save Changes]</strong>.', 'datafeedr-api' );
65 }
66
67 function field_network_ids() {
68 $groups = $this->get_network_group_names();
69 foreach ( $groups as $group ) {
70 $num_networks_checked_in_group = $this->num_networks_checked_in_group( $group );
71 $active = ( $num_networks_checked_in_group != '' ) ? 'active' : '';
72 $group_name = ( 'AffiliateWindow' == $group ) ? 'Awin' : $group;
73 echo '
74 <div class="group network_logo_30x30_' . esc_attr( dfrapi_group_name_to_css( $group ) ) . ' ' . $active . '" id="group_' . esc_attr( dfrapi_group_name_to_css( $group ) ) . '">
75 <div class="meta">
76 <span class="name">' . esc_html( $group_name ) . '</span>
77 <span class="status">
78 ' . $this->num_missing_affiliate_ids_in_group( $group ) . '
79 ' . $num_networks_checked_in_group . '
80 ' . $this->num_networks_in_group( $group ) . '
81 ' . $this->num_merchants_in_group( $group ) . '
82 ' . $this->num_products_in_group( $group ) . '
83 </span>
84 </div>
85 ' . $this->get_groups_networks( $group ) . '
86 </div>';
87 }
88 }
89
90 function get_groups_networks( $group_name ) {
91 $html = '
92 <div style="display:none;" class="networks">
93 <table class="wp-list-table widefat fixed networks_table" cellspacing="0">
94 <thead>
95 <tr>
96 <th class="checkbox_head"> &nbsp; </th>
97 <th class="networks_head">' . __( 'Network', 'datafeedr-api' ) . '</th>
98 <th class="type_head">' . __( 'Type', 'datafeedr-api' ) . '</th>
99 <th class="aid_head">' . __( 'Affiliate ID', 'datafeedr-api' ) . ' <a href="' . esc_url( $this->map_link( $group_name ) ) . '" target="_blank" title="' . esc_attr( __( 'Learn how to find your affiliate ID from ', 'datafeedr-api' ) . $group_name . __( ' (opens in new window).', 'datafeedr-api' ) ) . '"><img src="' . DFRAPI_URL . 'images/icons/help.png" alt="' . __( 'more info', 'datafeedr-api' ) . '" style="vertical-align: middle" /></a> <small style="font-weight:normal;color:#a00;">(' . __( 'required', 'datafeedr-api' ) . ')</small></th>
100 <th class="tid_head">' . __( 'Tracking ID', 'datafeedr-api' ) . ' <a href="https://datafeedrapi.helpscoutdocs.com/article/212-tracking-ids" target="_blank" title="' . __( 'Learn more about this field (opens in new window).', 'datafeedr-api' ) . '"><img src="' . DFRAPI_URL . 'images/icons/help.png" alt="' . __( 'more info', 'datafeedr-api' ) . '" style="vertical-align: middle" /></a> <small style="font-weight:normal;color:#999;">(' . __( 'optional', 'datafeedr-api' ) . ')</small></th>
101 </tr>
102 </thead>
103 <tbody>
104 ';
105
106 $i = 0;
107
108 foreach ( $this->all_networks as $network ) {
109
110 $i ++;
111 $checked = ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) ? ' checked="checked"' : '';
112 $type = ( $network['type'] === 'products' ) ? __( 'products', 'datafeedr-api' ) : __( 'coupons', 'datafeedr-api' );
113 $type_class = ( $network['type'] === 'products' ) ? ' dfrapi_label-info"' : ' dfrapi_label-success';
114 $no_products = ( $network['product_count'] < 1 ) ? 'no_products' : '';
115 $alternate = ( $i % 2 ) ? '' : ' alternate';
116
117 if ( $network['group'] == $group_name && (int) $network['group_id'] === dfrapi_get_partnerize_group_id() && ! dfrapi_get_ph_keys() ) {
118 $html .= sprintf(
119 __( '<tr><td colspan="4"><strong>%1$s</strong><br />Please go to <a href="%2$s">Datafeedr API > Configuration</a> and enter your Partnerize API keys before selecting this network.</td></tr>', 'datafeedr-api' ),
120 esc_html( $network['name'] ),
121 esc_url( dfrapi_configuration_page_url() )
122 );
123
124 continue;
125 }
126
127 if ( $network['group'] == $group_name && (int) $network['group_id'] === dfrapi_get_effiliation_group_id() && ! dfrapi_get_effiliation_keys() ) {
128 $html .= sprintf(
129 __( '<tr><td colspan="4"><strong>%1$s</strong><br />Please go to <a href="%2$s">Datafeedr API > Configuration</a> and enter your Effiliation Key before selecting this network.</td></tr>', 'datafeedr-api' ),
130 esc_html( $network['name'] ),
131 esc_url( dfrapi_configuration_page_url() )
132 );
133
134 continue;
135 }
136
137 if ( $network['group'] == $group_name && (int) $network['group_id'] === dfrapi_get_belboon_group_id() && is_wp_error( dfrapi_get_belboon_adspace_id() ) ) {
138 $html .= sprintf(
139 __( '<tr><td colspan="4"><strong>%1$s</strong><br />Please go to <a href="%2$s">Datafeedr API > Configuration</a> and enter your Belboon Adspace ID before selecting this network.</td></tr>', 'datafeedr-api' ),
140 esc_html( $network['name'] ),
141 esc_url( dfrapi_configuration_page_url() )
142 );
143
144 continue;
145 }
146
147 if ( $network['group'] == $group_name ) {
148
149 $aid = ( isset( $this->options['ids'][ $network['_id'] ]['aid'] ) ) ? esc_attr( $this->options['ids'][ $network['_id'] ]['aid'] ) : '';
150 $tid = ( isset( $this->options['ids'][ $network['_id'] ]['tid'] ) ) ? esc_attr( $this->options['ids'][ $network['_id'] ]['tid'] ) : '';
151 $nid = absint( $network['_id'] );
152
153 $html .= '
154 <tr
155 class="network ' . $no_products . $alternate . '"
156 id="network_id_' . $nid . '"
157 nid="' . $nid . '"
158 key="' . $this->key . '"
159 aid="' . $aid . '"
160 tid="' . $tid . '"
161 >
162 <td class="network_checkbox">
163 <input type="checkbox" id="nid_' . $nid . '" class="check_network" name="' . $this->key . '[ids][' . $nid . '][nid]" value="' . $nid . '"' . $checked . ' />
164 </td>
165 <td class="network_name">
166 <label for="nid_' . $nid . '">
167 ' . esc_html( $network['name'] ) . '
168 <div class="network_info">
169 <span class="num_merchants">' . number_format( $network['merchant_count'] ) . ' ' . __( 'merchants', 'datafeedr-api' ) . ' <span class="sep">/</span>
170 <span class="num_products">' . number_format( $network['product_count'] ) . ' ' . $type . '</span>
171 </div>
172 </label>
173 </td>
174 <td class="network_type">
175 <span class="dfrapi_label' . $type_class . '">' . ucfirst( $type ) . '</span>
176 </td>
177 ';
178
179 if ( $network['group_id'] == dfrapi_get_partnerize_group_id() ) {
180 $url = admin_url( 'admin.php?page=dfrapi' );
181 $html .= '<td class="aid_input"><a href="' . $url . '" target="_blank">Edit Partnerize Keys</a></td>';
182 } elseif ( $network['group_id'] == dfrapi_get_effiliation_group_id() ) {
183 $url = admin_url( 'admin.php?page=dfrapi' );
184 $html .= '<td class="aid_input"><a href="' . $url . '" target="_blank">Edit Effiliation Key</a></td>';
185 } elseif ( $network['group_id'] == dfrapi_get_belboon_group_id() && is_wp_error( dfrapi_get_belboon_adspace_id() ) ) {
186 $url = admin_url( 'admin.php?page=dfrapi' );
187 $html .= '<td class="aid_input"><a href="' . $url . '" target="_blank">Your Belboon Adspace ID is required before you can enter your affiliate ID. Enter Adspace ID.</a></td>';
188 } elseif ( $network['group_id'] == 10033 && is_wp_error( dfrapi_get_affiliate_gateway_sid() ) ) {
189 $url = admin_url( 'admin.php?page=dfrapi' );
190 $html .= '<td class="aid_input"><a href="' . $url . '" target="_blank">Your Affiliate Gateway SID is required before you can enter your affiliate ID. Enter SID.</a></td>';
191 } elseif ( $network['group_id'] == 10045 && is_wp_error( dfrapi_get_adservice_mid() ) ) {
192 $url = admin_url( 'admin.php?page=dfrapi' );
193 $html .= '<td class="aid_input"><a href="' . $url . '" target="_blank">Your Adservice Media ID is required before you can enter your affiliate ID. Enter Media ID.</a></td>';
194 } else {
195 $html .= '<td class="aid_input"><input type="text" name="dfrapi_networks[ids][' . $nid . '][aid]" value="' . $aid . '" class="aid_input_field" /></td>';
196 }
197
198 if ( apply_filters( 'dfrapi_network_supports_tracking_id', true, $network ) ) {
199 $html .= '<td class="tid_input"><input type="text" name="dfrapi_networks[ids][' . $nid . '][tid]" value="' . $tid . '" class="tid_input_field" /></td>';
200 } else {
201 $html .= '<td class="tid_input"><small>n/a</small></td>';
202 }
203
204 $html .= '</tr>';
205 }
206 }
207
208 $html .= '
209 </tbody>
210 </table>
211 </div>
212 ';
213
214 return $html;
215 }
216
217 function get_network_group_names() {
218 $networks = $this->all_networks;
219 $groups = array();
220 foreach ( $networks as $network ) {
221 $groups[] = $network['group'];
222 }
223
224 return array_unique( $groups );
225 }
226
227 function num_missing_affiliate_ids_in_group( $group_name ) {
228 $count = 0;
229 foreach ( $this->all_networks as $network ) {
230
231 if ( $network['group_id'] == dfrapi_get_partnerize_group_id() ) {
232 continue;
233 }
234
235 if ( $network['group_id'] == dfrapi_get_effiliation_group_id() ) {
236 continue;
237 }
238
239 if ( $network['group'] == $group_name ) {
240 if ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) {
241 if ( dfrapi_get_affiliate_id_by_network_id( (int) $network['_id'] ) === false ) {
242 $count ++;
243 }
244 }
245 }
246 }
247
248 if ( $count > 0 ) {
249 $messages = $this->messages();
250
251 return '<span class="num_missing">' . sprintf( translate_nooped_plural( $messages['num_missing'],
252 $count, 'datafeedr-api' ), number_format( $count ) ) . '</span> <span class="sep">/</span> ';
253 }
254
255 return '';
256 }
257
258 function num_networks_checked_in_group( $group_name ) {
259 $count = 0;
260 foreach ( $this->all_networks as $network ) {
261 if ( $network['group'] == $group_name ) {
262 if ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) {
263 $count ++;
264 }
265 }
266 }
267
268 if ( $count > 0 ) {
269 $messages = $this->messages();
270
271 return '<span class="num_checked">' . sprintf( translate_nooped_plural( $messages['num_checked'], $count, 'datafeedr-api' ), number_format( $count ) ) . '</span> <span class="sep">/</span> ';
272 }
273 }
274
275 function num_networks_in_group( $group_name ) {
276 $count = 0;
277 foreach ( $this->all_networks as $network ) {
278 if ( $network['group'] == $group_name ) {
279 $count ++;
280 }
281 }
282
283 if ( $count > 0 ) {
284 $messages = $this->messages();
285
286 return '<span class="num_networks">' . sprintf( translate_nooped_plural( $messages['num_networks'], $count, 'datafeedr-api' ), number_format( $count ) ) . '</span> <span class="sep">/</span> ';
287 }
288 }
289
290 function num_merchants_in_group( $group_name ) {
291 $count = 0;
292 foreach ( $this->all_networks as $network ) {
293 if ( $network['group'] == $group_name ) {
294 $count += $network['merchant_count'];
295 }
296 }
297
298 if ( $count > 0 ) {
299 $messages = $this->messages();
300
301 return '<span class="num_merchants">' . sprintf( translate_nooped_plural( $messages['num_merchants'], $count, 'datafeedr-api' ), number_format( $count ) ) . '</span> <span class="sep">/</span> ';
302 }
303 }
304
305 function num_products_in_group( $group_name ) {
306 $count = 0;
307 foreach ( $this->all_networks as $network ) {
308 if ( $network['group'] == $group_name ) {
309 $count += $network['product_count'];
310 }
311 }
312
313 if ( $count > 0 ) {
314 $messages = $this->messages();
315
316 return '<span class="num_products">' . sprintf( translate_nooped_plural( $messages['num_products'], $count, 'datafeedr-api' ), number_format( $count ) ) . '</span>';
317 }
318
319 }
320
321 function messages() {
322 return array(
323 'num_missing' => _n_noop( '%s missing affiliate ID', '%s missing affiliate IDs' ),
324 'num_checked' => _n_noop( '%s network selected', '%s networks selected' ),
325 'num_networks' => _n_noop( '%s network', '%s networks' ),
326 'num_merchants' => _n_noop( '%s merchant', '%s merchants' ),
327 'num_products' => _n_noop( '%s product', '%s products' ),
328 );
329 }
330
331 function map_link( $name ): string {
332 $links = [
333 '2Performant' => 'https://datafeedrapi.helpscoutdocs.com/article/240-how-to-find-your-2performant-affiliate-id',
334 'Admitad' => 'https://datafeedrapi.helpscoutdocs.com/article/241-how-to-find-your-admitad-affiliate-id',
335 'ADCELL' => 'https://datafeedrapi.helpscoutdocs.com/article/235-how-to-find-your-adcell-affiliate-id',
336 'Addrevenue' => 'https://datafeedrapi.helpscoutdocs.com/article/259-how-to-find-your-addrevenue-affiliate-id',
337 'Adrecord' => 'https://datafeedrapi.helpscoutdocs.com/article/115-how-to-find-your-adrecord-affiliate-id',
338 'Adservice' => 'https://datafeedrapi.helpscoutdocs.com/article/251-how-to-find-your-adservice-affiliate-id-and-media-id',
339 'Adtraction' => 'https://datafeedrapi.helpscoutdocs.com/article/116-how-to-find-your-adtraction-affiliate-id',
340 'Affiliate4You' => 'http://www.datafeedr.com/docs/item/265',
341 'Awin' => 'https://datafeedrapi.helpscoutdocs.com/article/120-how-to-find-your-affiliate-window-affiliate-id',
342 'Affiliator' => 'http://www.datafeedr.com/docs/item/270',
343 'Affilinet' => 'https://datafeedrapi.helpscoutdocs.com/article/121-how-to-find-your-affilinet-affiliate-id',
344 'Amazon Local' => 'http://www.datafeedr.com/docs/item/275',
345 'APD' => 'https://datafeedrapi.helpscoutdocs.com/article/133-how-to-find-your-apd-affiliate-id',
346 'Avangate' => 'https://datafeedrapi.helpscoutdocs.com/article/122-how-to-find-your-avangate-affiliate-id',
347 'AvantLink' => 'https://datafeedrapi.helpscoutdocs.com/article/123-how-to-find-your-avantlink-affiliate-id',
348 'Belboon' => 'https://datafeedrapi.helpscoutdocs.com/article/125-how-to-find-your-belboon-affiliate-id',
349 'BettyMills' => 'https://datafeedrapi.helpscoutdocs.com/article/129-how-to-find-your-betty-mills-affiliate-id',
350 'bol.com' => 'https://datafeedrapi.helpscoutdocs.com/article/186-how-to-find-your-bol-com-affiliate-id',
351 'ClickBank' => 'https://datafeedrapi.helpscoutdocs.com/article/130-how-to-find-your-clickbank-affiliate-id',
352 'ClixGalore' => 'https://datafeedrapi.helpscoutdocs.com/article/131-how-to-find-your-clixgalore-affiliate-id',
353 'Commission Factory' => 'https://datafeedrapi.helpscoutdocs.com/article/132-how-to-find-your-commission-factory-affiliate-id',
354 'Commission Junction' => 'https://datafeedrapi.helpscoutdocs.com/article/128-how-to-find-your-cj-affiliate-id',
355 'Commission Monster' => 'http://www.datafeedr.com/docs/item/109',
356 'Connexity' => 'https://datafeedrapi.helpscoutdocs.com/article/178-how-to-find-your-connexity-affiliate-id',
357 'Daisycon' => 'https://datafeedrapi.helpscoutdocs.com/article/135-how-to-find-your-daisycon-affiliate-id',
358 'DGM' => 'http://www.datafeedr.com/docs/item/263',
359 'Digital Advisor' => 'https://datafeedrapi.helpscoutdocs.com/article/250-how-to-find-your-digital-advisor-affiliate-id',
360 'Double.net' => 'https://datafeedrapi.helpscoutdocs.com/article/136-how-to-find-your-double-net-affiliate-id',
361 'Effiliation' => 'https://datafeedrapi.helpscoutdocs.com/article/211-how-to-find-your-effiliation-api-key',
362 'FamilyBlend' => 'https://datafeedrapi.helpscoutdocs.com/article/117-how-to-find-your-familyblend-affiliate-id',
363 'FlexOffers' => 'https://datafeedrapi.helpscoutdocs.com/article/209-how-to-find-your-flexoffers-affiliate-id',
364 'FlipKart' => 'https://datafeedrapi.helpscoutdocs.com/article/137-how-to-find-your-flipkart-affiliate-id',
365 'GoAffPro' => 'https://datafeedrapi.helpscoutdocs.com/article/249-how-to-find-your-goaffpro-affiliate-id',
366 'Impact' => 'https://datafeedrapi.helpscoutdocs.com/article/134-how-to-find-your-impact-radius-affiliate-id',
367 'LinkConnector' => 'https://datafeedrapi.helpscoutdocs.com/article/138-how-to-find-your-linkconnector-affiliate-id',
368 'Rakuten' => 'https://datafeedrapi.helpscoutdocs.com/article/139-how-to-find-your-rakuten-affiliate-id',
369 'M4N' => 'http://www.datafeedr.com/docs/item/198',
370 'MyCommerce' => 'http://www.datafeedr.com/docs/item/111',
371 'OneNetworkDirect' => 'https://datafeedrapi.helpscoutdocs.com/article/140-how-to-find-your-onenetworkdirect-affiliate-id',
372 'Optimise' => 'https://datafeedrapi.helpscoutdocs.com/article/141-how-to-find-your-optimise-affiliate-id',
373 'Paid on Results' => 'https://datafeedrapi.helpscoutdocs.com/article/142-how-to-find-your-paid-on-results-affiliate-id',
374 'Partner-ads' => 'https://datafeedrapi.helpscoutdocs.com/article/143-how-to-find-your-partner-ads-affiliate-id',
375 'Partnerize' => 'https://datafeedrapi.helpscoutdocs.com/article/195-how-to-find-your-partnerize-publisher-id-and-api-keys',
376 'PepperJam' => 'https://datafeedrapi.helpscoutdocs.com/article/127-how-to-find-your-ebay-enterprise-affiliate-network-affiliate-id',
377 'PerformanceHorizon' => 'https://datafeedrapi.helpscoutdocs.com/article/195-how-to-find-your-performance-horizon-publisher-id-and-api-keys',
378 'Profitshare' => 'https://datafeedrapi.helpscoutdocs.com/article/242-how-to-find-your-profitshare-affiliate-id',
379 'RegNow' => 'http://www.datafeedr.com/docs/item/111',
380 'RevResponse' => 'https://datafeedrapi.helpscoutdocs.com/article/144-how-to-find-your-revresponse-affiliate-id',
381 'ShareASale' => 'https://datafeedrapi.helpscoutdocs.com/article/126-how-to-find-your-shareasale-affiliate-id',
382 'Shopello' => 'https://datafeedrapi.helpscoutdocs.com/article/171-how-to-find-your-shopello-affiliate-id',
383 'Snapdeal' => 'https://datafeedrapi.helpscoutdocs.com/article/172-how-to-find-your-snapdeal-affiliate-id',
384 'SuperClix' => 'https://datafeedrapi.helpscoutdocs.com/article/145-how-to-find-your-superclix-affiliate-id',
385 'The Affiliate Gateway' => 'https://datafeedrapi.helpscoutdocs.com/article/225-how-to-find-your-affiliate-gateway-affiliate-id',
386 'TimeOne' => 'https://datafeedrapi.helpscoutdocs.com/article/262-how-to-find-your-timeone-affiliate-id',
387 'TradeDoubler' => 'https://datafeedrapi.helpscoutdocs.com/article/146-how-to-find-your-tradedoubler-affiliate-id',
388 'TradeTracker' => 'https://datafeedrapi.helpscoutdocs.com/article/148-how-to-find-your-tradetracker-affiliate-id',
389 'Webgains' => 'https://datafeedrapi.helpscoutdocs.com/article/147-how-to-find-your-webgains-affiliate-id',
390 'Zanox' => 'https://datafeedrapi.helpscoutdocs.com/article/149-how-to-find-your-zanox-api-keys',
391 ];
392
393 return $links[ $name ] ?? ( DFRAPI_DOCS_SEARCH_URL . sanitize_title( $name ) );
394 }
395
396 function validate( $input ) {
397 return dfrapi_sanitize_networks_option( $input );
398 }
399
400 } // class Dfrapi_Networks
401
402 } // class_exists check
403