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
← All changes | classes/class-dfrapi-networks.php +239 -220 1.0.24 → 1.4.3 View file →
@@ -1,7 +1,10 @@
1 1 <?php
2 2
3 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 +// Exit if accessed directly
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
4 7
5 8 if ( ! class_exists( 'Dfrapi_Networks' ) ) {
6 9
7 10 /**
@@ -11,88 +14,67 @@
11 14
12 15 private $page = 'dfrapi-networks';
13 16 private $key;
14 17 private $all_networks;
18 + public $options;
15 19
16 20 public function __construct() {
17 -
18 - $this->key = 'dfrapi_networks';
21 +
22 + $this->key = 'dfrapi_networks';
19 23 $this->all_networks = dfrapi_api_get_all_networks();
20 - add_action( 'init', array( &$this, 'load_settings' ) );
21 - add_action( 'admin_init', array( &$this, 'register_settings' ) );
22 - add_action( 'admin_menu', array( $this, 'admin_menu' ) );
23 - add_action( 'admin_notices', array( $this, 'admin_notice' ) );
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' ) );
24 28 }
25 -
29 +
26 30 function api_errors() {
27 31 if ( array_key_exists( 'dfrapi_api_error', $this->all_networks ) ) {
28 - return $this->all_networks;
32 + echo '<div class="notice notice-error">';
33 + dfrapi_output_api_error( $this->all_networks );
34 + echo '</div>';
29 35 }
30 - return false;
31 36 }
32 -
33 - function admin_menu() {
34 - add_submenu_page(
35 - 'dfrapi',
36 - __( 'Networks &#8212; Datafeedr API', DFRAPI_DOMAIN ),
37 - __( 'Networks', DFRAPI_DOMAIN ),
38 - 'manage_options',
39 - $this->key,
40 - array( $this, 'output' )
41 - );
42 - }
43 -
37 +
44 38 function admin_notice() {
45 39 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && $this->key == $_GET['page'] ) {
46 - echo '<div class="updated"><p>';
47 - _e( 'Networks successfully updated!', DFRAPI_DOMAIN );
48 - echo '</p></div>';
40 + dfrapi_admin_notice( __( 'Networks successfully updated!', 'datafeedr-api' ), 'success' );
49 41 }
50 42 }
51 43
52 - function output() {
53 - echo '<div class="wrap" id="' . $this->key . '">';
54 - echo '<h2>' . dfrapi_setting_pages( $this->page ) . ' &#8212; Datafeedr API</h2>';
55 - if ( $errors = $this->api_errors() ) {
56 - echo dfrapi_html_output_api_error( $errors );
57 - } else {
58 - echo '<form method="post" action="options.php">';
59 - wp_nonce_field( 'update-options' );
60 - settings_fields( $this->page );
61 - do_settings_sections( $this->page);
62 - submit_button();
63 - echo '</form>';
64 - }
65 - echo '<div id="dfr_unload_message" style="display:none">' . __( 'You have unsaved changes', DFRAPI_DOMAIN ) . '</div>';
66 - echo '</div>';
67 - }
68 -
69 - function load_settings() {
44 + function load_settings() {
70 45 $this->options = (array) get_option( $this->key );
71 46 $this->options = array_merge( array(
72 47 'ids' => array(),
73 48 ), $this->options );
74 49 }
75 -
50 +
76 51 function register_settings() {
77 52 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
78 - add_settings_section( 'networks', __( 'Select Networks', DFRAPI_DOMAIN ), array( &$this, 'section_networks_desc' ), $this->page );
79 - add_settings_field( 'ids', __( 'Networks', DFRAPI_DOMAIN ), array( &$this, 'field_network_ids' ), $this->page, 'networks', array( 'label_for' => 'DFRAPI_HIDE_LABEL' ) );
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' ) );
80 61 }
81 -
82 - function section_networks_desc() {
83 - echo __( 'Select the affiliate networks you belong to, enter your affiliate ID for each then click <strong>[Save Changes]</strong>.', DFRAPI_DOMAIN );
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' );
84 65 }
85 -
66 +
86 67 function field_network_ids() {
87 68 $groups = $this->get_network_group_names();
88 69 foreach ( $groups as $group ) {
89 70 $num_networks_checked_in_group = $this->num_networks_checked_in_group( $group );
90 - $active = ( $num_networks_checked_in_group != '' ) ? 'active' : '';
71 + $active = ( $num_networks_checked_in_group != '' ) ? 'active' : '';
72 + $group_name = ( 'AffiliateWindow' == $group ) ? 'Awin' : $group;
91 73 echo '
92 - <div class="group network_logo_30x30_' . dfrapi_group_name_to_css( $group ) . ' ' . $active . '" id="group_' . dfrapi_group_name_to_css( $group ) . '">
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 ) ) . '">
93 75 <div class="meta">
94 - <span class="name">' . $group . '</span>
76 + <span class="name">' . esc_html( $group_name ) . '</span>
95 77 <span class="status">
96 78 ' . $this->num_missing_affiliate_ids_in_group( $group ) . '
97 79 ' . $num_networks_checked_in_group . '
98 80 ' . $this->num_networks_in_group( $group ) . '
@@ -111,44 +93,81 @@
111 93 <table class="wp-list-table widefat fixed networks_table" cellspacing="0">
112 94 <thead>
113 95 <tr>
114 96 <th class="checkbox_head"> &nbsp; </th>
115 - <th class="networks_head">' . __( 'Network', DFRAPI_DOMAIN ) . '</th>
116 - <th class="type_head">' . __( 'Type', DFRAPI_DOMAIN ) . '</th>
117 - <th class="aid_head">' . __( 'Affiliate ID', DFRAPI_DOMAIN ) . ' <a href="' .$this->map_link( $group_name ) .'" target="_blank" title="' . __( 'Learn how to find your affiliate ID from ', DFRAPI_DOMAIN ) . $group_name . __( ' (opens in new window).', DFRAPI_DOMAIN ) . '"><img src="' . DFRAPI_URL . 'images/icons/help.png" alt="' . __( 'more info', DFRAPI_DOMAIN ) . '" style="vertical-align: middle" /></a> <small style="font-weight:normal;color:#a00;">(' . __( 'required', DFRAPI_DOMAIN ) . ')</small></th>
118 - <th class="tid_head">' . __( 'Tracking ID', DFRAPI_DOMAIN ) . ' <a href="' . DFRAPI_HOME_URL . '/node/1113" target="_blank" title="' . __( 'Learn more about this field (opens in new window).', DFRAPI_DOMAIN ) . '"><img src="' . DFRAPI_URL . 'images/icons/help.png" alt="' . __( 'more info', DFRAPI_DOMAIN ) . '" style="vertical-align: middle" /></a> <small style="font-weight:normal;color:#999;">(' . __( 'optional', DFRAPI_DOMAIN ) . ')</small></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>
119 101 </tr>
120 102 </thead>
121 103 <tbody>
122 104 ';
123 -
124 - $i=0;
105 +
106 + $i = 0;
107 +
125 108 foreach ( $this->all_networks as $network ) {
126 - $i++;
127 - $checked = ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) ? ' checked="checked"' : '';
128 - $type = ( $network['type'] == 'products' ) ? __( 'products', DFRAPI_DOMAIN ) : __( 'coupons', DFRAPI_DOMAIN );
129 - $type_class = ( $network['type'] == 'products' ) ? ' dfrapi_label-info"' : ' dfrapi_label-success';
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';
130 114 $no_products = ( $network['product_count'] < 1 ) ? 'no_products' : '';
131 - $alternate = ( $i % 2 ) ? '' : ' alternate';
132 -
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 +
133 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 +
134 153 $html .= '
135 - <tr
136 - class="network ' . $no_products . $alternate . '"
137 - id="network_id_' . $network['_id'] . '"
138 - nid="' . $network['_id'] . '"
139 - key="' . $this->key . '"
140 - aid="' . @$this->options['ids'][$network['_id']]['aid'] . '"
141 - tid="' . @$this->options['ids'][$network['_id']]['tid'] . '"
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 . '"
142 161 >
143 162 <td class="network_checkbox">
144 - <input type="checkbox" id="nid_' . $network['_id'] . '" class="check_network" name="' . $this->key . '[ids][' . $network['_id'] . '][nid]" value="' . $network['_id'] . '"' . $checked . ' />
163 + <input type="checkbox" id="nid_' . $nid . '" class="check_network" name="' . $this->key . '[ids][' . $nid . '][nid]" value="' . $nid . '"' . $checked . ' />
145 164 </td>
146 165 <td class="network_name">
147 - <label for="nid_' . $network['_id'] . '">
148 - ' . $network['name'] . '
166 + <label for="nid_' . $nid . '">
167 + ' . esc_html( $network['name'] ) . '
149 168 <div class="network_info">
150 - <span class="num_merchants">' . number_format( $network['merchant_count'] ) . ' ' . __( 'merchants', DFRAPI_DOMAIN ) . ' <span class="sep">/</span>
169 + <span class="num_merchants">' . number_format( $network['merchant_count'] ) . ' ' . __( 'merchants', 'datafeedr-api' ) . ' <span class="sep">/</span>
151 170 <span class="num_products">' . number_format( $network['product_count'] ) . ' ' . $type . '</span>
152 171 </div>
153 172 </label>
154 173 </td>
@@ -154,230 +173,230 @@
154 173 </td>
155 174 <td class="network_type">
156 175 <span class="dfrapi_label' . $type_class . '">' . ucfirst( $type ) . '</span>
157 176 </td>
158 - ';
159 -
160 - if ( $group_name == 'Zanox' ) {
161 - $html .= '<td class="aid_input">' . $this->zanox_adspace( $network['_id'], @$this->options['ids'][$network['_id']]['aid'] ) . '</td>';
162 - } else {
163 - $html .= '<td class="aid_input"><input type="text" name="dfrapi_networks[ids][' . $network['_id'] . '][aid]" value="' . @$this->options['ids'][$network['_id']]['aid'] . '" class="aid_input_field" /></td>';
164 - }
165 -
166 - $html .= '
167 - <td class="tid_input"><input type="text" name="dfrapi_networks[ids][' . $network['_id'] . '][tid]" value="' . @$this->options['ids'][$network['_id']]['tid'] . '" class="tid_input_field" /></td>
168 - </tr>
169 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>';
170 205 }
171 206 }
172 -
207 +
173 208 $html .= '
174 209 </tbody>
175 210 </table>
176 211 </div>
177 212 ';
213 +
178 214 return $html;
179 215 }
180 -
216 +
181 217 function get_network_group_names() {
182 218 $networks = $this->all_networks;
183 - $groups = array();
219 + $groups = array();
184 220 foreach ( $networks as $network ) {
185 221 $groups[] = $network['group'];
186 222 }
187 - return array_unique( $groups );
223 +
224 + return array_unique( $groups );
188 225 }
189 -
190 - /**
191 - * This returns <select> menu for adspaces.
192 - */
193 - function zanox_adspace( $nid, $selected_adspace ) {
194 - $html = '';
195 - $adspaces = $this->get_zanox_adspaces();
196 - if ( isset( $adspaces['zanox_error'] ) ) {
197 - if ( $adspaces['zanox_error'] == 'missing_keys' ) {
198 - $html .= '<span><a href="' . admin_url( 'admin.php?page=dfrapi' ) . '" class="dfrapi_warning">' . __( 'Please add your Zanox Connection &amp; Secret Key', DFRAPI_DOMAIN ) . '</a>.</span>';
199 - } else {
200 - $html .= '<pre>' . print_r( $adspaces['zanox_error'], TRUE ) . '</pre>';
201 - }
202 - } else {
203 - $html .= '<select name="dfrapi_networks[ids][' . $nid . '][aid]">';
204 - $html .= '<option value="">' . __( 'Select an adspace', DFRAPI_DOMAIN ) . '</option>';
205 - foreach( $adspaces as $adspace ) {
206 - $selected = selected( $selected_adspace, $adspace['id'], false );
207 - $html .= '<option value="' . $adspace['id'] . '" ' . $selected . '>' . $adspace['name'] . '</option>';
208 - }
209 - $html .= '</select>';
210 - }
211 - return $html;
212 - }
213 -
214 - /**
215 - * This returns adspaces for a Zanox user.
216 - */
217 - function get_zanox_adspaces() {
218 - $option_name = 'dfrapi_zanox_adspaces';
219 - $adspaces = get_transient( $option_name );
220 - if ( false === $adspaces || empty ( $adspaces ) ) {
221 - $zanox_keys = dfrapi_get_zanox_keys();
222 - if ( !$zanox_keys ) {
223 - return array( 'zanox_error' => 'missing_keys' );
224 - } else {
225 - $client = new Dfr_ZanoxAPIClient( $zanox_keys['connection_key'], $zanox_keys['secret_key'] );
226 - $adspaces = $client->adspaces();
227 - if ( $client->error() ) {
228 - return array( 'zanox_error' => $client->error() );
229 - } else {
230 - set_transient( $option_name, $adspaces, HOUR_IN_SECONDS );
231 - }
232 - }
233 - }
234 - dfrapi_update_transient_whitelist( $option_name );
235 - return $adspaces;
236 - }
237 -
226 +
238 227 function num_missing_affiliate_ids_in_group( $group_name ) {
239 228 $count = 0;
240 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 +
241 239 if ( $network['group'] == $group_name ) {
242 240 if ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) {
243 - if ( trim( $this->options['ids'][$network['_id']]['aid'] ) == '' ) {
244 - $count++;
241 + if ( dfrapi_get_affiliate_id_by_network_id( (int) $network['_id'] ) === false ) {
242 + $count ++;
245 243 }
246 244 }
247 245 }
248 246 }
249 -
247 +
250 248 if ( $count > 0 ) {
251 249 $messages = $this->messages();
252 - return '<span class="num_missing">' . sprintf( translate_nooped_plural( $messages['num_missing'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . '</span> <span class="sep">/</span> ';
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 253 }
254 +
255 + return '';
254 256 }
255 -
257 +
256 258 function num_networks_checked_in_group( $group_name ) {
257 259 $count = 0;
258 260 foreach ( $this->all_networks as $network ) {
259 261 if ( $network['group'] == $group_name ) {
260 262 if ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) {
261 - $count++;
263 + $count ++;
262 264 }
263 265 }
264 266 }
265 -
267 +
266 268 if ( $count > 0 ) {
267 269 $messages = $this->messages();
268 - return '<span class="num_checked">' . sprintf( translate_nooped_plural( $messages['num_checked'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . '</span> <span class="sep">/</span> ';
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> ';
269 272 }
270 273 }
271 -
274 +
272 275 function num_networks_in_group( $group_name ) {
273 276 $count = 0;
274 277 foreach ( $this->all_networks as $network ) {
275 278 if ( $network['group'] == $group_name ) {
276 - $count++;
277 - }
279 + $count ++;
280 + }
278 281 }
279 -
282 +
280 283 if ( $count > 0 ) {
281 284 $messages = $this->messages();
282 - return '<span class="num_networks">' . sprintf( translate_nooped_plural( $messages['num_networks'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . '</span> <span class="sep">/</span> ';
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> ';
283 287 }
284 288 }
285 -
289 +
286 290 function num_merchants_in_group( $group_name ) {
287 291 $count = 0;
288 292 foreach ( $this->all_networks as $network ) {
289 293 if ( $network['group'] == $group_name ) {
290 294 $count += $network['merchant_count'];
291 - }
295 + }
292 296 }
293 -
297 +
294 298 if ( $count > 0 ) {
295 299 $messages = $this->messages();
296 - return '<span class="num_merchants">' . sprintf( translate_nooped_plural( $messages['num_merchants'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . '</span> <span class="sep">/</span> ';
297 - }
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 + }
298 303 }
299 -
304 +
300 305 function num_products_in_group( $group_name ) {
301 306 $count = 0;
302 307 foreach ( $this->all_networks as $network ) {
303 308 if ( $network['group'] == $group_name ) {
304 309 $count += $network['product_count'];
305 - }
310 + }
306 311 }
307 -
312 +
308 313 if ( $count > 0 ) {
309 314 $messages = $this->messages();
310 - return '<span class="num_products">' . sprintf( translate_nooped_plural( $messages['num_products'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . '</span>';
315 +
316 + return '<span class="num_products">' . sprintf( translate_nooped_plural( $messages['num_products'], $count, 'datafeedr-api' ), number_format( $count ) ) . '</span>';
311 317 }
312 -
318 +
313 319 }
314 -
320 +
315 321 function messages() {
316 322 return array(
317 - 'num_missing' => _n_noop( '%s missing affiliate ID', '%s missing affiliate IDs' ),
318 - 'num_checked' => _n_noop( '%s network selected', '%s networks selected' ),
323 + 'num_missing' => _n_noop( '%s missing affiliate ID', '%s missing affiliate IDs' ),
324 + 'num_checked' => _n_noop( '%s network selected', '%s networks selected' ),
319 325 'num_networks' => _n_noop( '%s network', '%s networks' ),
320 326 'num_merchants' => _n_noop( '%s merchant', '%s merchants' ),
321 327 'num_products' => _n_noop( '%s product', '%s products' ),
322 328 );
323 329 }
324 -
325 - function map_link( $name ) {
326 - $links = array(
327 - 'AdRecord' => 'http://www.datafeedr.com/docs/item/252',
328 - 'Adtraction' => 'http://www.datafeedr.com/docs/item/261',
329 - 'Affiliate4You' => 'http://www.datafeedr.com/docs/item/265',
330 - 'AffiliateWindow' => 'http://www.datafeedr.com/docs/item/101',
331 - 'Affiliator' => 'http://www.datafeedr.com/docs/item/270',
332 - 'Affilinet' => 'http://www.datafeedr.com/docs/item/104',
333 - 'Amazon Local' => 'http://www.datafeedr.com/docs/item/275',
334 - 'Avangate' => 'http://www.datafeedr.com/docs/item/188',
335 - 'AvantLink' => 'http://www.datafeedr.com/docs/item/190',
336 - 'Belboon' => 'http://www.datafeedr.com/docs/item/201',
337 - 'BettyMills' => 'http://www.datafeedr.com/docs/item/264',
338 - 'bol.com' => 'http://www.datafeedr.com/docs/item/253',
339 - 'ClickBank' => 'http://www.datafeedr.com/docs/item/106',
340 - 'ClixGalore' => 'http://www.datafeedr.com/docs/item/200',
341 - 'Commission Factory' => 'http://www.datafeedr.com/docs/item/193',
342 - 'Commission Junction' => 'http://www.datafeedr.com/docs/item/65',
343 - 'Commission Monster' => 'http://www.datafeedr.com/docs/item/109',
344 - 'Daisycon' => 'http://www.datafeedr.com/docs/item/196',
345 - 'DGM' => 'http://www.datafeedr.com/docs/item/263',
346 - 'Double.net' => 'http://www.datafeedr.com/docs/item/271',
347 - 'FlipKart' => 'http://www.datafeedr.com/docs/item/273',
348 - 'Impact Radius' => 'http://www.datafeedr.com/docs/item/268',
349 - 'LinkConnector' => 'http://www.datafeedr.com/docs/item/105',
350 - 'LinkShare' => 'http://www.datafeedr.com/docs/item/60',
351 - 'M4N' => 'http://www.datafeedr.com/docs/item/198',
352 - 'MyCommerce' => 'http://www.datafeedr.com/docs/item/111',
353 - 'OneNetworkDirect' => 'http://www.datafeedr.com/docs/item/112',
354 - 'Paid on Results' => 'http://www.datafeedr.com/docs/item/189',
355 - 'Partner-ads' => 'http://www.datafeedr.com/docs/item/262',
356 - 'PepperJam' => 'http://www.datafeedr.com/docs/item/103',
357 - 'RegNow' => 'http://www.datafeedr.com/docs/item/111',
358 - 'RevResponse' => 'http://www.datafeedr.com/docs/item/197',
359 - 'ShareASale' => 'http://www.datafeedr.com/docs/item/108',
360 - 'SuperClix' => 'http://www.datafeedr.com/docs/item/256',
361 - 'TradeDoubler' => 'http://www.datafeedr.com/docs/item/113',
362 - 'TradeTracker' => 'http://www.datafeedr.com/docs/item/195',
363 - 'Webgains' => 'http://www.datafeedr.com/docs/item/114',
364 - 'Zanox' => 'http://www.datafeedr.com/docs/item/269',
365 - );
366 - return $links[$name];
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 ) );
367 394 }
368 -
395 +
369 396 function validate( $input ) {
370 - $new_input['ids'] = array();
371 - if ( isset( $input['ids'] ) ) {
372 - foreach ( $input['ids'] as $k => $v ) {
373 - if ( isset( $v['nid'] ) ) {
374 - $new_input['ids'][$k] = $v;
375 - }
376 - }
377 - }
378 - return $new_input;
397 + return dfrapi_sanitize_networks_option( $input );
379 398 }
380 -
399 +
381 400 } // class Dfrapi_Networks
382 401
383 402 } // class_exists check