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-configuration.php +502 -84 1.0.13 → 1.4.3 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2
3 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 +defined( 'ABSPATH' ) || exit;
4 4
5 5 if ( ! class_exists( 'Dfrapi_Configuration' ) ) {
6 6
7 7 /**
@@ -11,34 +11,33 @@
11 11
12 12 private $page = 'dfrapi-configuration';
13 13 private $key;
14 14 private $account;
15 + public $options;
15 16
16 17 public function __construct() {
17 18 $this->key = 'dfrapi_configuration';
18 19 $this->account = (array) get_option( 'dfrapi_account', array( 'max_length' => 50 ) );
19 - add_action( 'init', array( &$this, 'load_settings' ) );
20 - add_action( 'admin_init', array( &$this, 'register_settings' ) );
21 - add_action( 'admin_menu', array( $this, 'admin_menu' ) );
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' ), 10 );
22 23 add_action( 'admin_notices', array( $this, 'admin_notice' ) );
23 24 }
24 -
25 +
25 26 function admin_menu() {
26 27 add_submenu_page(
27 28 'dfrapi',
28 - __( 'Configuration &#8212; Datafeedr API', DFRAPI_DOMAIN ),
29 - __( 'Configuration', DFRAPI_DOMAIN ),
30 - 'manage_options',
29 + __( 'Configuration &#8212; Datafeedr API', 'datafeedr-api' ),
30 + __( 'Configuration', 'datafeedr-api' ),
31 + 'manage_options',
31 32 'dfrapi',
32 - array( $this, 'output' )
33 + array( $this, 'output' )
33 34 );
34 35 }
35 -
36 +
36 37 function admin_notice() {
37 38 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && 'dfrapi' == $_GET['page'] ) {
38 - echo '<div class="updated"><p>';
39 - _e( 'Configuration successfully updated!', DFRAPI_DOMAIN );
40 - echo '</p></div>';
39 + dfrapi_admin_notice( __( 'Configuration successfully updated!', 'datafeedr-api' ), 'success' );
41 40 }
42 41 }
43 42
44 43 function output() {
@@ -48,124 +47,543 @@
48 47 wp_nonce_field( 'update-options' );
49 48 settings_fields( $this->page );
50 49 do_settings_sections( $this->page);
51 50 submit_button();
52 - echo '</form>';
51 + echo '</form>';
53 52 echo '</div>';
54 53 }
55 -
56 - function load_settings() {
57 - $this->options = (array) get_option( $this->key );
58 - $this->options = array_merge(
59 - array(
60 - 'access_id' => '',
61 - 'secret_key' => '',
62 - 'transport_method' => 'curl',
63 - 'zanox_connection_key' => '',
64 - 'zanox_secret_key' => '',
65 - ),
66 - $this->options
67 - );
68 - }
69 -
54 +
55 + function load_settings() {
56 +
57 + $this->options = (array) get_option( $this->key );
58 +
59 + $this->options = array_merge( array(
60 + 'access_id' => '',
61 + 'secret_key' => '',
62 + 'api_version' => 'stable',
63 + 'transport_method' => 'curl',
64 + 'disable_api' => 'no',
65 + 'zanox_connection_key' => '',
66 + 'zanox_secret_key' => '',
67 + 'amazon_access_key_id' => '',
68 + 'amazon_secret_access_key' => '',
69 + 'amazon_tracking_id' => '',
70 + 'amazon_locale' => 'us',
71 + 'ph_application_key' => '',
72 + 'ph_user_api_key' => '',
73 + 'ph_publisher_id' => '',
74 + 'effiliation_key' => '',
75 + 'awin_access_token' => '',
76 + 'affiliate_gateway_sid' => '',
77 + 'belboon_aid' => '',
78 + 'adservice_mid' => '',
79 + 'hs_beacon' => 'on',
80 + 'amazon_api' => 'paapi', // 'capi' or 'paapi'
81 + 'capi_credential_id' => '',
82 + 'capi_credential_secret' => '',
83 + 'capi_partner_tag' => '',
84 + 'capi_marketplace' => 'US',
85 + ), $this->options );
86 +
87 + }
88 +
70 89 function register_settings() {
71 90 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
72 - add_settings_section( 'api_settings', __( 'Datafeedr API Settings', DFRAPI_DOMAIN ), array( &$this, 'section_api_settings_desc' ), $this->page );
73 - add_settings_field( 'access_id', __( 'API Access ID', DFRAPI_DOMAIN ), array( &$this, 'field_access_id' ), $this->page, 'api_settings' );
74 - add_settings_field( 'secret_key', __( 'API Secret Key', DFRAPI_DOMAIN ), array( &$this, 'field_secret_key' ), $this->page, 'api_settings' );
75 - add_settings_field( 'transport_method', __( 'Transport Method', DFRAPI_DOMAIN ), array( &$this, 'field_transport_method' ), $this->page, 'api_settings' );
76 -
77 - add_settings_section( 'zanox_api_settings', __( 'Zanox Settings', DFRAPI_DOMAIN ), array( &$this, 'section_zanox_api_settings_desc' ), $this->page );
78 - add_settings_field( 'zanox_connection_key', __( 'Connection Key', DFRAPI_DOMAIN ), array( &$this, 'field_zanox_connection_key' ), $this->page, 'zanox_api_settings' );
79 - add_settings_field( 'zanox_secret_key', __( 'Secret Key', DFRAPI_DOMAIN ), array( &$this, 'field_zanox_secret_key' ), $this->page, 'zanox_api_settings' );
91 + add_settings_section( 'api_settings', __( 'Datafeedr API Settings', 'datafeedr-api' ), array( &$this, 'section_api_settings_desc' ), $this->page );
92 + add_settings_field( 'access_id', __( 'API Access ID', 'datafeedr-api' ), array( &$this, 'field_access_id' ), $this->page, 'api_settings' );
93 + add_settings_field( 'secret_key', __( 'API Secret Key', 'datafeedr-api' ), array( &$this, 'field_secret_key' ), $this->page, 'api_settings' );
94 + add_settings_field( 'api_version', __( 'API Version', 'datafeedr-api' ), array( &$this, 'field_api_version' ), $this->page, 'api_settings' );
95 + // add_settings_field( 'transport_method', __( 'Transport Method', 'datafeedr-api' ), array( &$this, 'field_transport_method' ), $this->page, 'api_settings' );
96 +
97 + /*
98 + add_settings_field(
99 + 'disable_api',
100 + __( 'Disable API', 'datafeedr-api' ),
101 + array( &$this, 'field_disable_api' ),
102 + $this->page,
103 + 'api_settings'
104 + );
105 + */
106 +
107 + add_settings_section( 'awin_settings', __( 'Awin Settings', 'datafeedr-api' ), array( &$this, 'section_awin_settings_desc' ), $this->page );
108 + add_settings_field( 'awin_access_token', __( 'Awin API Token', 'datafeedr-api' ), array( &$this, 'field_awin_access_token' ), $this->page, 'awin_settings' );
109 +
110 + add_settings_section( 'affiliate_gateway_settings', __( 'Affiliate Gateway Settings', 'datafeedr-api' ), array( &$this, 'section_affiliate_gateway_settings_desc' ), $this->page );
111 + add_settings_field( 'affiliate_gateway_sid', __( 'Affiliate Gateway SID', 'datafeedr-api' ), array( &$this, 'field_affiliate_gateway_sid' ), $this->page, 'affiliate_gateway_settings' );
112 +
113 + add_settings_section( 'adservice_settings', __( 'Adservice Settings', 'datafeedr-api' ), array( &$this, 'section_adservice_settings_desc' ), $this->page );
114 + add_settings_field( 'adservice_mid', __( 'Adservice Media ID', 'datafeedr-api' ), array( &$this, 'field_adservice_mid' ), $this->page, 'adservice_settings' );
115 +
116 + add_settings_section( 'belboon_settings', __( 'Belboon Settings', 'datafeedr-api' ), array( &$this, 'section_belboon_settings_desc' ), $this->page );
117 + add_settings_field( 'belboon_aid', __( 'Adspace ID', 'datafeedr-api' ), array( &$this, 'field_belboon_aid' ), $this->page, 'belboon_settings' );
118 +
119 + if ( defined( 'DFRCS_VERSION' ) ) {
120 + add_settings_section( 'amazon_api_settings', __( 'Amazon Settings', 'datafeedr-api' ), array( &$this, 'section_amazon_api_settings_desc' ), $this->page );
121 + add_settings_field( 'amazon_api', __( 'Amazon API', 'datafeedr-api' ), array( &$this, 'field_amazon_api' ), $this->page, 'amazon_api_settings' );
122 + add_settings_field( 'amazon_access_key_id', __( 'Access Key ID', 'datafeedr-api' ), array( &$this, 'field_amazon_access_key_id' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] );
123 + add_settings_field( 'amazon_secret_access_key', __( 'Secret Access Key', 'datafeedr-api' ), array( &$this, 'field_amazon_secret_access_key' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] );
124 + add_settings_field( 'amazon_tracking_id', __( 'Tracking ID', 'datafeedr-api' ), array( &$this, 'field_amazon_tracking_id' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] );
125 + add_settings_field( 'amazon_locale', __( 'Locale', 'datafeedr-api' ), array( &$this, 'field_amazon_locale' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] );
126 + add_settings_field( 'capi_credential_id', __( 'Credential ID', 'datafeedr-api' ), array( &$this, 'field_capi_credential_id' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] );
127 + add_settings_field( 'capi_credential_secret', __( 'Credential Secret', 'datafeedr-api' ), array( &$this, 'field_capi_credential_secret' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] );
128 + add_settings_field( 'capi_partner_tag', __( 'Partner Tag', 'datafeedr-api' ), array( &$this, 'field_capi_partner_tag' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] );
129 + add_settings_field( 'capi_marketplace', __( 'Marketplace', 'datafeedr-api' ), array( &$this, 'field_capi_marketplace' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] );
130 + }
131 +
132 + add_settings_section( 'ph_api_settings', __( 'Partnerize Settings', 'datafeedr-api' ), array( &$this, 'section_ph_api_settings_desc' ), $this->page );
133 + add_settings_field( 'ph_application_key', __( 'Application Key', 'datafeedr-api' ), array( &$this, 'field_ph_application_key' ), $this->page, 'ph_api_settings' );
134 + add_settings_field( 'ph_user_api_key', __( 'User API Key', 'datafeedr-api' ), array( &$this, 'field_ph_user_api_key' ), $this->page, 'ph_api_settings' );
135 + add_settings_field( 'ph_publisher_id', __( 'Publisher ID', 'datafeedr-api' ), array( &$this, 'field_ph_publisher_id' ), $this->page, 'ph_api_settings' );
136 +
137 + add_settings_section( 'effiliation_api_settings', __( 'Effiliation Settings', 'datafeedr-api' ), array( &$this, 'section_effiliation_api_settings_desc' ), $this->page );
138 + add_settings_field( 'effiliation_key', __( 'Effiliation Key', 'datafeedr-api' ), array( &$this, 'field_effiliation_key' ), $this->page, 'effiliation_api_settings' );
139 +
140 + add_settings_section( 'hs_beacon_settings', __( 'Datafeedr Documentation & Support Link', 'datafeedr-api' ), array( &$this, 'section_hs_beacon_settings_desc' ), $this->page );
141 + add_settings_field( 'hs_beacon_status', __( 'Enabled', 'datafeedr-api' ), array( &$this, 'field_hs_beacon_status' ), $this->page, 'hs_beacon_settings' );
80 142 }
81 -
82 - function section_api_settings_desc() {
83 - echo __( 'Add your ', DFRAPI_DOMAIN );
84 - echo ' <a href="'.DFRAPI_KEYS_URL.'?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiconfigpage" target="_blank" title="' . __( 'Get your Datafeedr API Keys', DFRAPI_DOMAIN ) . '">';
85 - echo __( 'Datafeedr API Keys', DFRAPI_DOMAIN );
143 +
144 + function section_api_settings_desc() {
145 + echo __( 'Add your ', 'datafeedr-api' );
146 + echo ' <a href="'.DFRAPI_KEYS_URL.'?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiconfigpage" target="_blank" title="' . __( 'Get your Datafeedr API Keys', 'datafeedr-api' ) . '">';
147 + echo __( 'Datafeedr API Keys', 'datafeedr-api' );
86 148 echo '</a>.';
87 149 }
88 150
89 151 function field_access_id() {
90 152 ?>
91 - <input type="text" class="regular-text" name="<?php echo $this->key; ?>[access_id]" value="<?php echo esc_attr( $this->options['access_id'] ); ?>" />
153 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[access_id]" value="<?php echo esc_attr( $this->options['access_id'] ); ?>" />
92 154 <?php
93 155 }
94 156
95 157 function field_secret_key() {
96 158 ?>
97 - <input type="text" class="regular-text" name="<?php echo $this->key; ?>[secret_key]" value="<?php echo esc_attr( $this->options['secret_key'] ); ?>" />
159 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[secret_key]" value="<?php echo esc_attr( $this->options['secret_key'] ); ?>" />
98 160 <?php
99 161 }
100 -
101 - function section_zanox_api_settings_desc() {
102 - echo __( 'If you want to use the Zanox affiliate network, add your ', DFRAPI_DOMAIN );
103 - echo ' <a href="http://publisher.zanox.com/ws_gettingstarted/ws.gettingstarted.html" target="_blank" title="' . __( 'Get your Zanox Keys', DFRAPI_DOMAIN ) . '">';
104 - echo __( 'Zanox Keys', DFRAPI_DOMAIN );
162 +
163 + function field_api_version() {
164 + ?>
165 + <p>
166 + <input type="radio" value="stable" name="<?php echo $this->key; ?>[api_version]" <?php checked( $this->options['api_version'], 'stable', true ); ?> /> <?php _e( 'stable', 'datafeedr-api' ); ?>
167 + </p>
168 + <p>
169 + <input type="radio" value="beta" disabled name="<?php echo $this->key; ?>[api_version]" <?php checked( $this->options['api_version'], 'beta', true ); ?> /> <?php _e( 'beta', 'datafeedr-api' ); ?>
170 + </p>
171 + <p class="description">
172 + <?php _e( 'The only available version of the API at this time is the "stable" version.', 'datafeedr-api' ); ?>
173 + </p>
174 + <?php
175 + }
176 +
177 + function section_ph_api_settings_desc() {
178 + echo __( 'If you want to use the Partnerize affiliate network, add your ', 'datafeedr-api' );
179 + echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/195-how-to-find-your-partnerize-publisher-id-and-api-keys" target="_blank" title="' . __( 'Learn how to find your Partnerize Keys', 'datafeedr-api' ) . '">';
180 + echo __( 'Partnerize Keys', 'datafeedr-api' );
105 181 echo '</a>.';
106 182 }
107 183
108 - function field_zanox_connection_key() {
184 + function field_ph_application_key() {
109 185 ?>
110 - <input type="text" class="regular-text" name="<?php echo $this->key; ?>[zanox_connection_key]" value="<?php echo esc_attr( $this->options['zanox_connection_key'] ); ?>" />
186 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[ph_application_key]" value="<?php echo esc_attr( $this->options['ph_application_key'] ); ?>" />
111 187 <?php
112 188 }
113 189
114 - function field_zanox_secret_key() {
190 + function field_ph_user_api_key() {
115 191 ?>
116 - <input type="text" class="regular-text" name="<?php echo $this->key; ?>[zanox_secret_key]" value="<?php echo esc_attr( $this->options['zanox_secret_key'] ); ?>" />
192 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[ph_user_api_key]" value="<?php echo esc_attr( $this->options['ph_user_api_key'] ); ?>" />
117 193 <?php
118 194 }
119 -
195 +
196 + function field_ph_publisher_id() {
197 + ?>
198 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[ph_publisher_id]" value="<?php echo esc_attr( $this->options['ph_publisher_id'] ); ?>" />
199 + <?php
200 + }
201 +
202 + function section_effiliation_api_settings_desc() {
203 + echo __( 'If you want to use the Effiliation affiliate network, add your ', 'datafeedr-api' );
204 + echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/211-how-to-find-your-effiliation-api-key" target="_blank" title="' . __( 'Get your Effiliation Key', 'datafeedr-api' ) . '">';
205 + echo __( 'Effiliation Key', 'datafeedr-api' );
206 + echo '</a>.';
207 + }
208 +
209 + function field_effiliation_key() {
210 + ?>
211 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[effiliation_key]" value="<?php echo esc_attr( $this->options['effiliation_key'] ); ?>" />
212 + <?php
213 + }
214 +
215 + function section_awin_settings_desc() {
216 + echo __( 'If you want to use the Awin affiliate network, enter your Awin API Token to view the Awin programs you have joined.', 'datafeedr-api' );
217 + echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/120-how-to-find-your-awin-affiliate-id-and-api-key" target="_blank" title="' . __( 'Learn how to get your Awin API Token', 'datafeedr-api' ) . '">';
218 + echo __( 'Learn how to find your Awin API Token', 'datafeedr-api' );
219 + echo '</a>.';
220 + }
221 +
222 + function field_awin_access_token() {
223 + ?>
224 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[awin_access_token]" value="<?php echo esc_attr( $this->options['awin_access_token'] ); ?>" />
225 + <?php
226 + }
227 +
228 + function section_affiliate_gateway_settings_desc() {
229 + echo __( 'If you want to use The Affiliate Gateway affiliate network, enter your Affiliate Gateway SID.', 'datafeedr-api' );
230 + echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/225-how-to-find-your-affiliate-gateway-affiliate-id" target="_blank" title="' . __( 'Learn how to get your Affiliate Gateway SID', 'datafeedr-api' ) . '">';
231 + echo __( 'Learn how to get your Affiliate Gateway SID', 'datafeedr-api' );
232 + echo '</a>.';
233 + }
234 +
235 + function field_affiliate_gateway_sid() {
236 + ?>
237 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[affiliate_gateway_sid]" value="<?php echo esc_attr( $this->options['affiliate_gateway_sid'] ); ?>" />
238 + <?php
239 + }
240 +
241 + function section_adservice_settings_desc() {
242 + echo __( 'If you want to use the Adservice affiliate network, enter your Adservice Media ID.', 'datafeedr-api' );
243 + echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/251-how-to-find-your-adservice-affiliate-id-and-media-id" target="_blank" title="' . __( 'Learn how to get your Adservice Media ID', 'datafeedr-api' ) . '">';
244 + echo __( 'Learn how to get your Adservice Media ID', 'datafeedr-api' );
245 + echo '</a>.';
246 + }
247 +
248 + function field_adservice_mid() {
249 + ?>
250 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[adservice_mid]" value="<?php echo esc_attr( $this->options['adservice_mid'] ); ?>" />
251 + <?php
252 + }
253 +
254 + function section_belboon_settings_desc() {
255 + echo __( 'If you want to use the Belboon affiliate network, enter your Belboon Adspace ID.', 'datafeedr-api' );
256 + echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/125-how-to-find-your-belboon-affiliate-id" target="_blank" title="' . __( 'Learn how to get your Belboon Adspace ID', 'datafeedr-api' ) . '">';
257 + echo __( 'Learn how to get your Belboon Adspace ID', 'datafeedr-api' );
258 + echo '</a>.';
259 + }
260 +
261 + function field_belboon_aid() {
262 + ?>
263 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[belboon_aid]" value="<?php echo esc_attr( $this->options['belboon_aid'] ); ?>" />
264 + <?php
265 + }
266 +
120 267 function field_transport_method() {
121 268 ?>
122 - <select id="transport_method" name="<?php echo $this->key; ?>[transport_method]">
123 - <option value="curl" <?php selected( $this->options['transport_method'], 'curl', true ); ?>><?php _e( 'CURL', DFRAPI_DOMAIN ); ?></option>
124 - <option value="file" <?php selected( $this->options['transport_method'], 'file', true ); ?>><?php _e( 'File', DFRAPI_DOMAIN ); ?></option>
125 - <option value="socket" <?php selected( $this->options['transport_method'], 'socket', true ); ?>><?php _e( 'Socket', DFRAPI_DOMAIN ); ?></option>
126 - </select>
127 - <p class="description"><?php _e( 'If you\'re not sure, use CURL.', DFRAPI_DOMAIN ); ?></p>
269 + <select id="transport_method" name="<?php echo $this->key; ?>[transport_method]">
270 + <option value="curl" <?php selected( $this->options['transport_method'], 'curl', true ); ?>><?php _e( 'CURL', 'datafeedr-api' ); ?></option>
271 + <option value="file" <?php selected( $this->options['transport_method'], 'file', true ); ?>><?php _e( 'File', 'datafeedr-api' ); ?></option>
272 + <option value="socket" <?php selected( $this->options['transport_method'], 'socket', true ); ?>><?php _e( 'Socket', 'datafeedr-api' ); ?></option>
273 + </select>
274 + <p class="description"><?php _e( 'If you\'re not sure, use CURL.', 'datafeedr-api' ); ?></p>
128 275 <?php
129 276 }
130 277
278 + function field_disable_api() {
279 + ?>
280 + <p>
281 + <input type="radio" value="yes" name="<?php echo $this->key; ?>[disable_api]" <?php checked( $this->options['disable_api'], 'yes', true ); ?> /> <?php _e( 'Yes', 'datafeedr-api' ); ?>
282 + </p>
283 + <p>
284 + <input type="radio" value="no" name="<?php echo $this->key; ?>[disable_api]" <?php checked( $this->options['disable_api'], 'no', true ); ?> /> <?php _e( 'No', 'datafeedr-api' ); ?>
285 + </p>
286 + <p class="description"><?php _e( 'Prevent your site from attempting to make a request to the Datafeedr API.', 'datafeedr-api' ); ?></p>
287 + <?php
288 + }
289 +
290 + function field_amazon_api() {
291 + ?>
292 + <p>
293 + <label>
294 + <input type="radio"
295 + value="paapi"
296 + name="<?php echo $this->key; ?>[amazon_api]"
297 + <?php checked( $this->options['amazon_api'], 'paapi' ); ?>
298 + />
299 + <?php _e( 'Product Advertising API', 'datafeedr-api' ); ?>
300 + <strong>
301 + <?php _e( '(deprecated)', 'datafeedr-api' ); ?>
302 + </strong>
303 + </label>
304 + </p>
305 + <p>
306 + <label>
307 + <input type="radio"
308 + value="capi"
309 + name="<?php echo $this->key; ?>[amazon_api]"
310 + <?php checked( $this->options['amazon_api'], 'capi' ); ?>
311 + />
312 + <?php _e( 'Creators API', 'datafeedr-api' ); ?>
313 + <strong>
314 + <?php _e( '(recommended)', 'datafeedr-api' ); ?>
315 + </strong>
316 + </label>
317 + </p>
318 + <p class="description">
319 + <?php _e( 'Which Amazon API would you like to connect to?', 'datafeedr-api' ); ?>
320 + </p>
321 + <?php
322 + }
323 +
324 + function section_amazon_api_settings_desc() {
325 + echo __( 'Add your ', 'datafeedr-api' );
326 + echo '<a href="https://affiliate-program.amazon.com/gp/advertising/api/detail/your-account.html" target="_blank">';
327 + echo __( 'Amazon Product Advertising API keys', 'datafeedr-api' );
328 + echo '</a>.';
329 + echo '<br /><span style="color:red">';
330 + echo __( 'These are ONLY compatible with the ', 'datafeedr-api' );
331 + echo '<a href="https://datafeedr.me/dfrcs" target="_blank">';
332 + echo __( 'Datafeedr Comparison Sets', 'datafeedr-api' );
333 + echo '</a>';
334 + echo __( ' plugin.', 'datafeedr-api' );
335 + echo '</span>';
336 + }
337 +
338 + function field_amazon_access_key_id() {
339 + ?>
340 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[amazon_access_key_id]" value="<?php echo esc_attr( $this->options['amazon_access_key_id'] ); ?>" />
341 + <?php
342 + }
343 +
344 + function field_amazon_secret_access_key() {
345 + ?>
346 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[amazon_secret_access_key]" value="<?php echo esc_attr( $this->options['amazon_secret_access_key'] ); ?>" />
347 + <?php
348 + }
349 +
350 + function field_amazon_tracking_id() {
351 + ?>
352 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[amazon_tracking_id]" value="<?php echo esc_attr( $this->options['amazon_tracking_id'] ); ?>" />
353 + <p class="description">
354 + <?php _e( 'This is the same as your Associates Tag usually ending in "-20" or "-21". Can be found ', 'datafeedr-api' ); ?>
355 + <a href="https://affiliate-program.amazon.com/gp/associates/network/main.html" target="_blank"><?php _e( 'here', 'datafeedr-api' ); ?></a>.
356 + </p>
357 + <?php
358 + }
359 +
360 + function field_amazon_locale() {
361 + ?>
362 + <select id="amazon_locale" name="<?php echo $this->key; ?>[amazon_locale]">
363 + <option value="au" <?php selected( $this->options['amazon_locale'], 'au', true ); ?>><?php _e( 'Australia', 'datafeedr-api' ); ?></option>
364 + <option value="br" <?php selected( $this->options['amazon_locale'], 'br', true ); ?>><?php _e( 'Brazil', 'datafeedr-api' ); ?></option>
365 + <option value="ca" <?php selected( $this->options['amazon_locale'], 'ca', true ); ?>><?php _e( 'Canada', 'datafeedr-api' ); ?></option>
366 + <option value="fr" <?php selected( $this->options['amazon_locale'], 'fr', true ); ?>><?php _e( 'France', 'datafeedr-api' ); ?></option>
367 + <option value="de" <?php selected( $this->options['amazon_locale'], 'de', true ); ?>><?php _e( 'Germany', 'datafeedr-api' ); ?></option>
368 + <option value="in" <?php selected( $this->options['amazon_locale'], 'in', true ); ?>><?php _e( 'India', 'datafeedr-api' ); ?></option>
369 + <option value="it" <?php selected( $this->options['amazon_locale'], 'it', true ); ?>><?php _e( 'Italy', 'datafeedr-api' ); ?></option>
370 + <option value="jp" <?php selected( $this->options['amazon_locale'], 'jp', true ); ?>><?php _e( 'Japan', 'datafeedr-api' ); ?></option>
371 + <option value="mx" <?php selected( $this->options['amazon_locale'], 'mx', true ); ?>><?php _e( 'Mexico', 'datafeedr-api' ); ?></option>
372 + <option value="nl" <?php selected( $this->options['amazon_locale'], 'nl', true ); ?>><?php _e( 'Netherlands', 'datafeedr-api' ); ?></option>
373 + <option value="sg" <?php selected( $this->options['amazon_locale'], 'sg', true ); ?>><?php _e( 'Singapore', 'datafeedr-api' ); ?></option>
374 + <option value="sa" <?php selected( $this->options['amazon_locale'], 'sa', true ); ?>><?php _e( 'Saudi Arabia', 'datafeedr-api' ); ?></option>
375 + <option value="es" <?php selected( $this->options['amazon_locale'], 'es', true ); ?>><?php _e( 'Spain', 'datafeedr-api' ); ?></option>
376 + <option value="se" <?php selected( $this->options['amazon_locale'], 'se', true ); ?>><?php _e( 'Sweden', 'datafeedr-api' ); ?></option>
377 + <option value="tr" <?php selected( $this->options['amazon_locale'], 'tr', true ); ?>><?php _e( 'Turkey', 'datafeedr-api' ); ?></option>
378 + <option value="ae" <?php selected( $this->options['amazon_locale'], 'ae', true ); ?>><?php _e( 'United Arab Emirates', 'datafeedr-api' ); ?></option>
379 + <option value="uk" <?php selected( $this->options['amazon_locale'], 'uk', true ); ?>><?php _e( 'United Kingdom', 'datafeedr-api' ); ?></option>
380 + <option value="us" <?php selected( $this->options['amazon_locale'], 'us', true ); ?>><?php _e( 'United States', 'datafeedr-api' ); ?></option>
381 + </select>
382 + <p class="description">
383 + <a href="http://docs.aws.amazon.com/AWSECommerceService/latest/DG/AssociateIDs.html" target="_blank"><?php _e( 'More information', 'datafeedr-api' ); ?></a> <?php _e( 'regarding Amazon Locales.', 'datafeedr-api' ); ?>
384 + </p>
385 + <?php
386 + }
387 +
388 + function field_capi_credential_id() {
389 + ?>
390 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[capi_credential_id]" value="<?php echo esc_attr( $this->options['capi_credential_id'] ); ?>" />
391 + <?php
392 + }
393 +
394 + function field_capi_credential_secret() {
395 + ?>
396 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[capi_credential_secret]" value="<?php echo esc_attr( $this->options['capi_credential_secret'] ); ?>" />
397 + <?php
398 + }
399 +
400 + function field_capi_partner_tag() {
401 + ?>
402 + <input type="text" class="regular-text" name="<?php echo $this->key; ?>[capi_partner_tag]" value="<?php echo esc_attr( $this->options['capi_partner_tag'] ); ?>" />
403 + <?php
404 + }
405 +
406 + function field_capi_marketplace() {
407 +
408 + ?>
409 + <select name="<?php echo $this->key; ?>[capi_marketplace]">
410 + <?php foreach ( dfrapi_get_capi_marketplaces() as $code => $marketplace ) : ?>
411 + <option value="<?php esc_attr_e( $code ); ?>" <?php selected( $this->options['capi_marketplace'], $code ); ?>>
412 + <?php esc_html_e( $marketplace['locale'] ); ?>
413 + </option>
414 + <?php endforeach; ?>
415 + </select>
416 + <?php
417 + }
418 +
419 + function section_hs_beacon_settings_desc() {
420 + echo __( 'Display the link to Datafeedr documentation and support on every Datafeedr-specific page in your WordPress Admin Area. ',
421 + 'datafeedr-api' );
422 + echo __( 'This provides the full Datafeedr documentation and access to a support contact form right inside your WordPress site.',
423 + 'datafeedr-api' );
424 + }
425 +
426 + function field_hs_beacon_status() {
427 + ?>
428 + <p>
429 + <input type="radio" value="on" name="<?php echo $this->key; ?>[hs_beacon]" <?php checked( $this->options['hs_beacon'], 'on', true ); ?> /> <?php _e( 'Yes', 'datafeedr-api' ); ?>
430 + </p>
431 + <p>
432 + <input type="radio" value="off" name="<?php echo $this->key; ?>[hs_beacon]" <?php checked( $this->options['hs_beacon'], 'off', true ); ?> /> <?php _e( 'No', 'datafeedr-api' ); ?>
433 + </p>
434 + <?php
435 + }
436 +
131 437 function validate( $input ) {
132 -
438 +
133 439 if ( !isset( $input ) || !is_array( $input ) || empty( $input ) ) { return $input; }
134 -
440 +
135 441 $new_input = array();
136 -
137 - foreach( $input as $key => $value ) {
138 -
442 +
443 + foreach ( $input as $key => $value ) {
444 +
139 445 // Validate "access_id"
140 - if ( $key == 'access_id' ) {
141 - $new_input['access_id'] = trim( $value );
446 + if ( $key === 'access_id' ) {
447 + $new_input['access_id'] = dfrapi_sanitize_setting_text( $value );
142 448 }
143 -
449 +
144 450 // Validate "secret_key"
145 - if ( $key == 'secret_key' ) {
146 - $new_input['secret_key'] = trim( $value );
451 + if ( $key === 'secret_key' ) {
452 + $new_input['secret_key'] = dfrapi_sanitize_setting_text( $value );
147 453 }
148 -
454 +
455 + // Validate "api_version"
456 + if ( $key === 'api_version' ) {
457 + $api_version = dfrapi_sanitize_setting_text( $value );
458 +
459 + $new_input['api_version'] = in_array( $api_version, dfrapi_get_valid_api_versions(), true )
460 + ? $api_version
461 + : dfrapi_get_default_api_version();
462 + }
463 +
149 464 // Validate "transport_method"
150 - if ( $key == 'transport_method' ) {
151 - $new_input['transport_method'] = trim( $value );
465 + if ( $key === 'transport_method' ) {
466 + $transport_method = dfrapi_sanitize_setting_text( $value );
467 + $new_input['transport_method'] = in_array( $transport_method, [ 'curl', 'file', 'socket' ], true )
468 + ? $transport_method
469 + : 'curl';
152 470 }
153 -
154 - // Validate "zanox_connection_key"
155 - if ( $key == 'zanox_connection_key' ) {
156 - $new_input['zanox_connection_key'] = trim( $value );
471 +
472 + // Validate "disable_api"
473 + if ( $key === 'disable_api' ) {
474 + $new_input['disable_api'] = dfrapi_sanitize_setting_text( $value );
157 475 }
158 -
159 - // Validate "zanox_secret_key"
160 - if ( $key == 'zanox_secret_key' ) {
161 - $new_input['zanox_secret_key'] = trim( $value );
476 +
477 + // Validate Amazon API
478 + if ( $key === 'amazon_api' ) {
479 + $amazon_api = strtolower( dfrapi_sanitize_setting_text( $value ) );
480 + $new_input['amazon_api'] = in_array( $amazon_api, [ 'paapi', 'capi' ], true )
481 + ? $amazon_api
482 + : 'paapi';
483 + }
484 +
485 + // Validate Amazon Access Key ID
486 + if ( $key === 'amazon_access_key_id' ) {
487 + $new_input['amazon_access_key_id'] = dfrapi_sanitize_setting_text( $value );
162 488 }
163 -
489 +
490 + // Validate Amazon Secret Access Key
491 + if ( $key === 'amazon_secret_access_key' ) {
492 + $new_input['amazon_secret_access_key'] = dfrapi_sanitize_setting_text( $value );
493 + }
494 +
495 + // Validate Amazon Tracking ID
496 + if ( $key === 'amazon_tracking_id' ) {
497 + $new_input['amazon_tracking_id'] = dfrapi_sanitize_setting_text( $value );
498 + }
499 +
500 + // Validate Amazon Locale
501 + if ( $key === 'amazon_locale' ) {
502 + $amazon_locale = strtolower( dfrapi_sanitize_setting_text( $value ) );
503 + $valid_amazon_locales = [ 'au', 'br', 'ca', 'fr', 'de', 'in', 'it', 'jp', 'mx', 'nl', 'sg', 'sa', 'es', 'se', 'tr', 'ae', 'uk', 'us' ];
504 + $new_input['amazon_locale'] = in_array( $amazon_locale, $valid_amazon_locales, true )
505 + ? $amazon_locale
506 + : 'us';
507 + }
508 +
509 + // Validate CAPI Credential ID
510 + if ( $key === 'capi_credential_id' ) {
511 + $new_input['capi_credential_id'] = dfrapi_sanitize_setting_text( $value );
512 + }
513 +
514 + // Validate CAPI Credential Secret
515 + if ( $key === 'capi_credential_secret' ) {
516 + $new_input['capi_credential_secret'] = dfrapi_sanitize_setting_text( $value );
517 + }
518 +
519 + // Validate CAPI Partner Tag
520 + if ( $key === 'capi_partner_tag' ) {
521 + $new_input['capi_partner_tag'] = dfrapi_sanitize_setting_text( $value );
522 + }
523 +
524 + // Validate CAPI Marketplace
525 + if ( $key === 'capi_marketplace' ) {
526 +
527 + $marketplace = strtoupper( dfrapi_sanitize_setting_text( $value ) );
528 + $valid_marketplaces = array_keys( dfrapi_get_capi_marketplaces() );
529 +
530 + $new_input['capi_marketplace'] = in_array( $marketplace, $valid_marketplaces, true )
531 + ? $marketplace
532 + : 'US';
533 + }
534 +
535 + // Validate PH Application Key
536 + if ( $key === 'ph_application_key' ) {
537 + $new_input['ph_application_key'] = dfrapi_sanitize_setting_text( $value );
538 + }
539 +
540 + // Validate PH User API Key
541 + if ( $key === 'ph_user_api_key' ) {
542 + $new_input['ph_user_api_key'] = dfrapi_sanitize_setting_text( $value );
543 + }
544 +
545 + // Validate PH Publisher Key
546 + if ( $key === 'ph_publisher_id' ) {
547 + $new_input['ph_publisher_id'] = dfrapi_sanitize_setting_text( $value );
548 + }
549 +
550 + // Validate Effiliation Key
551 + if ( $key === 'effiliation_key' ) {
552 + $new_input['effiliation_key'] = dfrapi_sanitize_setting_text( $value );
553 + }
554 +
555 + // Validate Awin Acceess Token
556 + if ( $key === 'awin_access_token' ) {
557 + $new_input['awin_access_token'] = dfrapi_sanitize_setting_text( $value );
558 + }
559 +
560 + // Validate The Affiliate Gateway SID
561 + if ( $key === 'affiliate_gateway_sid' ) {
562 + $new_input['affiliate_gateway_sid'] = dfrapi_sanitize_setting_text( $value );
563 + }
564 +
565 + // Validate Adservice MID
566 + if ( $key === 'adservice_mid' ) {
567 + $new_input['adservice_mid'] = dfrapi_sanitize_setting_text( $value );
568 + }
569 +
570 + // Validate Belboon AID
571 + if ( $key === 'belboon_aid' ) {
572 + $new_input['belboon_aid'] = dfrapi_sanitize_setting_text( $value );
573 + }
574 +
575 + // Enable HelpScout Beacon
576 + if ( $key === 'hs_beacon' ) {
577 + $new_input['hs_beacon'] = ( 'on' === $value ) ? 'on' : 'off';
578 + }
164 579 } // foreach
165 -
580 +
581 + // Override setting so it's always enabled.
582 + $new_input['disable_api'] = trim( 'no' );
583 +
166 584 return $new_input;
167 585 }
168 -
586 +
169 587 } // class Dfrapi_Configuration
170 588
171 589 } // class_exists check