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 -227 1.0.32 → 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,237 +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 - $use_cache = wp_using_ext_object_cache( false );
220 - $adspaces = get_transient( $option_name );
221 - wp_using_ext_object_cache( $use_cache );
222 - if ( false === $adspaces || empty ( $adspaces ) ) {
223 - $zanox_keys = dfrapi_get_zanox_keys();
224 - if ( !$zanox_keys ) {
225 - return array( 'zanox_error' => 'missing_keys' );
226 - } else {
227 - $client = new Dfr_ZanoxAPIClient( $zanox_keys['connection_key'], $zanox_keys['secret_key'] );
228 - $adspaces = $client->adspaces();
229 - if ( $client->error() ) {
230 - return array( 'zanox_error' => $client->error() );
231 - } else {
232 - $use_cache = wp_using_ext_object_cache( false );
233 - set_transient( $option_name, $adspaces, HOUR_IN_SECONDS );
234 - wp_using_ext_object_cache( $use_cache );
235 - }
236 - }
237 - }
238 - dfrapi_update_transient_whitelist( $option_name );
239 - return $adspaces;
240 - }
241 -
226 +
242 227 function num_missing_affiliate_ids_in_group( $group_name ) {
243 228 $count = 0;
244 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 +
245 239 if ( $network['group'] == $group_name ) {
246 240 if ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) {
247 - if ( trim( $this->options['ids'][$network['_id']]['aid'] ) == '' ) {
248 - $count++;
241 + if ( dfrapi_get_affiliate_id_by_network_id( (int) $network['_id'] ) === false ) {
242 + $count ++;
249 243 }
250 244 }
251 245 }
252 246 }
253 -
247 +
254 248 if ( $count > 0 ) {
255 249 $messages = $this->messages();
256 - 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> ';
257 253 }
254 +
255 + return '';
258 256 }
259 -
257 +
260 258 function num_networks_checked_in_group( $group_name ) {
261 259 $count = 0;
262 260 foreach ( $this->all_networks as $network ) {
263 261 if ( $network['group'] == $group_name ) {
264 262 if ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) {
265 - $count++;
263 + $count ++;
266 264 }
267 265 }
268 266 }
269 -
267 +
270 268 if ( $count > 0 ) {
271 269 $messages = $this->messages();
272 - 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> ';
273 272 }
274 273 }
275 -
274 +
276 275 function num_networks_in_group( $group_name ) {
277 276 $count = 0;
278 277 foreach ( $this->all_networks as $network ) {
279 278 if ( $network['group'] == $group_name ) {
280 - $count++;
281 - }
279 + $count ++;
280 + }
282 281 }
283 -
282 +
284 283 if ( $count > 0 ) {
285 284 $messages = $this->messages();
286 - 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> ';
287 287 }
288 288 }
289 -
289 +
290 290 function num_merchants_in_group( $group_name ) {
291 291 $count = 0;
292 292 foreach ( $this->all_networks as $network ) {
293 293 if ( $network['group'] == $group_name ) {
294 294 $count += $network['merchant_count'];
295 - }
295 + }
296 296 }
297 -
297 +
298 298 if ( $count > 0 ) {
299 299 $messages = $this->messages();
300 - return '<span class="num_merchants">' . sprintf( translate_nooped_plural( $messages['num_merchants'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . '</span> <span class="sep">/</span> ';
301 - }
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 + }
302 303 }
303 -
304 +
304 305 function num_products_in_group( $group_name ) {
305 306 $count = 0;
306 307 foreach ( $this->all_networks as $network ) {
307 308 if ( $network['group'] == $group_name ) {
308 309 $count += $network['product_count'];
309 - }
310 + }
310 311 }
311 -
312 +
312 313 if ( $count > 0 ) {
313 314 $messages = $this->messages();
314 - 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>';
315 317 }
316 -
318 +
317 319 }
318 -
320 +
319 321 function messages() {
320 322 return array(
321 - 'num_missing' => _n_noop( '%s missing affiliate ID', '%s missing affiliate IDs' ),
322 - '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' ),
323 325 'num_networks' => _n_noop( '%s network', '%s networks' ),
324 326 'num_merchants' => _n_noop( '%s merchant', '%s merchants' ),
325 327 'num_products' => _n_noop( '%s product', '%s products' ),
326 328 );
327 329 }
328 -
329 - function map_link( $name ) {
330 - $links = array(
331 - 'AdRecord' => 'http://www.datafeedr.com/docs/item/252',
332 - 'Adtraction' => 'http://www.datafeedr.com/docs/item/261',
333 - 'Affiliate4You' => 'http://www.datafeedr.com/docs/item/265',
334 - 'AffiliateWindow' => 'http://www.datafeedr.com/docs/item/101',
335 - 'Affiliator' => 'http://www.datafeedr.com/docs/item/270',
336 - 'Affilinet' => 'http://www.datafeedr.com/docs/item/104',
337 - 'Amazon Local' => 'http://www.datafeedr.com/docs/item/275',
338 - 'APD' => 'http://www.datafeedr.com/docs/item/263',
339 - 'Avangate' => 'http://www.datafeedr.com/docs/item/188',
340 - 'AvantLink' => 'http://www.datafeedr.com/docs/item/190',
341 - 'Belboon' => 'http://www.datafeedr.com/docs/item/201',
342 - 'BettyMills' => 'http://www.datafeedr.com/docs/item/264',
343 - 'bol.com' => 'http://www.datafeedr.com/docs/item/253',
344 - 'ClickBank' => 'http://www.datafeedr.com/docs/item/106',
345 - 'ClixGalore' => 'http://www.datafeedr.com/docs/item/200',
346 - 'Commission Factory' => 'http://www.datafeedr.com/docs/item/193',
347 - 'Commission Junction' => 'http://www.datafeedr.com/docs/item/65',
348 - 'Commission Monster' => 'http://www.datafeedr.com/docs/item/109',
349 - 'Daisycon' => 'http://www.datafeedr.com/docs/item/196',
350 - 'DGM' => 'http://www.datafeedr.com/docs/item/263',
351 - 'Double.net' => 'http://www.datafeedr.com/docs/item/271',
352 - 'FamilyBlend' => 'http://www.datafeedr.com/docs/item/265',
353 - 'FlipKart' => 'http://www.datafeedr.com/docs/item/273',
354 - 'Impact Radius' => 'http://www.datafeedr.com/docs/item/268',
355 - 'LinkConnector' => 'http://www.datafeedr.com/docs/item/105',
356 - 'LinkShare' => 'http://www.datafeedr.com/docs/item/60',
357 - 'M4N' => 'http://www.datafeedr.com/docs/item/198',
358 - 'MyCommerce' => 'http://www.datafeedr.com/docs/item/111',
359 - 'OneNetworkDirect' => 'http://www.datafeedr.com/docs/item/112',
360 - 'Optimise' => 'http://www.datafeedr.com/docs/item/276',
361 - 'Paid on Results' => 'http://www.datafeedr.com/docs/item/189',
362 - 'Partner-ads' => 'http://www.datafeedr.com/docs/item/262',
363 - 'PepperJam' => 'http://www.datafeedr.com/docs/item/103',
364 - 'RegNow' => 'http://www.datafeedr.com/docs/item/111',
365 - 'RevResponse' => 'http://www.datafeedr.com/docs/item/197',
366 - 'ShareASale' => 'http://www.datafeedr.com/docs/item/108',
367 - 'SuperClix' => 'http://www.datafeedr.com/docs/item/256',
368 - 'TradeDoubler' => 'http://www.datafeedr.com/docs/item/113',
369 - 'TradeTracker' => 'http://www.datafeedr.com/docs/item/195',
370 - 'Webgains' => 'http://www.datafeedr.com/docs/item/114',
371 - 'Zanox' => 'http://www.datafeedr.com/docs/item/269',
372 - );
373 - 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 ) );
374 394 }
375 -
395 +
376 396 function validate( $input ) {
377 - $new_input['ids'] = array();
378 - if ( isset( $input['ids'] ) ) {
379 - foreach ( $input['ids'] as $k => $v ) {
380 - if ( isset( $v['nid'] ) ) {
381 - $new_input['ids'][$k] = $v;
382 - }
383 - }
384 - }
385 - return $new_input;
397 + return dfrapi_sanitize_networks_option( $input );
386 398 }
387 -
399 +
388 400 } // class Dfrapi_Networks
389 401
390 402 } // class_exists check