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 +460 -128 1.0.32 → 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,210 +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 54
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 - 'amazon_access_key_id' => '',
66 - 'amazon_secret_access_key' => '',
67 - 'amazon_tracking_id' => '',
68 - 'amazon_locale' => 'us',
69 - ),
70 - $this->options
71 - );
72 - }
73 -
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 +
74 89 function register_settings() {
75 90 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
76 - add_settings_section( 'api_settings', __( 'Datafeedr API Settings', DFRAPI_DOMAIN ), array( &$this, 'section_api_settings_desc' ), $this->page );
77 - add_settings_field( 'access_id', __( 'API Access ID', DFRAPI_DOMAIN ), array( &$this, 'field_access_id' ), $this->page, 'api_settings' );
78 - add_settings_field( 'secret_key', __( 'API Secret Key', DFRAPI_DOMAIN ), array( &$this, 'field_secret_key' ), $this->page, 'api_settings' );
79 - add_settings_field( 'transport_method', __( 'Transport Method', DFRAPI_DOMAIN ), array( &$this, 'field_transport_method' ), $this->page, 'api_settings' );
80 -
81 - add_settings_section( 'zanox_api_settings', __( 'Zanox Settings', DFRAPI_DOMAIN ), array( &$this, 'section_zanox_api_settings_desc' ), $this->page );
82 - add_settings_field( 'zanox_connection_key', __( 'Connection Key', DFRAPI_DOMAIN ), array( &$this, 'field_zanox_connection_key' ), $this->page, 'zanox_api_settings' );
83 - 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' );
84 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 +
85 119 if ( defined( 'DFRCS_VERSION' ) ) {
86 - add_settings_section( 'amazon_api_settings', __( 'Amazon Settings', DFRAPI_DOMAIN ), array( &$this, 'section_amazon_api_settings_desc' ), $this->page );
87 - add_settings_field( 'amazon_access_key_id', __( 'Amazon Access Key ID', DFRAPI_DOMAIN ), array( &$this, 'field_amazon_access_key_id' ), $this->page, 'amazon_api_settings' );
88 - add_settings_field( 'amazon_secret_access_key', __( 'Amazon Secret Access Key', DFRAPI_DOMAIN ), array( &$this, 'field_amazon_secret_access_key' ), $this->page, 'amazon_api_settings' );
89 - add_settings_field( 'amazon_tracking_id', __( 'Amazon Tracking ID', DFRAPI_DOMAIN ), array( &$this, 'field_amazon_tracking_id' ), $this->page, 'amazon_api_settings' );
90 - add_settings_field( 'amazon_locale', __( 'Amazon Locale', DFRAPI_DOMAIN ), array( &$this, 'field_amazon_locale' ), $this->page, 'amazon_api_settings' );
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' ] );
91 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' );
92 142 }
93 -
94 - function section_api_settings_desc() {
95 - echo __( 'Add your ', DFRAPI_DOMAIN );
96 - 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 ) . '">';
97 - 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' );
98 148 echo '</a>.';
99 149 }
100 150
101 151 function field_access_id() {
102 152 ?>
103 - <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'] ); ?>" />
104 154 <?php
105 155 }
106 156
107 157 function field_secret_key() {
108 158 ?>
109 - <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'] ); ?>" />
110 160 <?php
111 161 }
112 -
113 - function section_zanox_api_settings_desc() {
114 - echo __( 'If you want to use the Zanox affiliate network, add your ', DFRAPI_DOMAIN );
115 - echo ' <a href="http://publisher.zanox.com/ws_gettingstarted/ws.gettingstarted.html" target="_blank" title="' . __( 'Get your Zanox Keys', DFRAPI_DOMAIN ) . '">';
116 - 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' );
117 181 echo '</a>.';
118 182 }
119 183
120 - function field_zanox_connection_key() {
184 + function field_ph_application_key() {
121 185 ?>
122 - <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'] ); ?>" />
123 187 <?php
124 188 }
125 189
126 - function field_zanox_secret_key() {
190 + function field_ph_user_api_key() {
127 191 ?>
128 - <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'] ); ?>" />
129 193 <?php
130 194 }
131 -
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 +
132 267 function field_transport_method() {
133 268 ?>
134 - <select id="transport_method" name="<?php echo $this->key; ?>[transport_method]">
135 - <option value="curl" <?php selected( $this->options['transport_method'], 'curl', true ); ?>><?php _e( 'CURL', DFRAPI_DOMAIN ); ?></option>
136 - <option value="file" <?php selected( $this->options['transport_method'], 'file', true ); ?>><?php _e( 'File', DFRAPI_DOMAIN ); ?></option>
137 - <option value="socket" <?php selected( $this->options['transport_method'], 'socket', true ); ?>><?php _e( 'Socket', DFRAPI_DOMAIN ); ?></option>
138 - </select>
139 - <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>
140 275 <?php
141 276 }
142 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 +
143 324 function section_amazon_api_settings_desc() {
144 - echo __( 'Add your ', DFRAPI_DOMAIN );
325 + echo __( 'Add your ', 'datafeedr-api' );
145 326 echo '<a href="https://affiliate-program.amazon.com/gp/advertising/api/detail/your-account.html" target="_blank">';
146 - echo __( 'Amazon Product Advertising API keys', DFRAPI_DOMAIN );
327 + echo __( 'Amazon Product Advertising API keys', 'datafeedr-api' );
147 328 echo '</a>.';
148 329 echo '<br /><span style="color:red">';
149 - echo __( 'These are ONLY compatible with the Datafeedr Comparison Sets plugin.', DFRAPI_DOMAIN );
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' );
150 335 echo '</span>';
151 336 }
152 337
153 338 function field_amazon_access_key_id() {
154 339 ?>
155 - <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'] ); ?>" />
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'] ); ?>" />
156 341 <?php
157 342 }
158 343
159 344 function field_amazon_secret_access_key() {
160 345 ?>
161 - <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'] ); ?>" />
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'] ); ?>" />
162 347 <?php
163 348 }
164 349
165 350 function field_amazon_tracking_id() {
166 351 ?>
167 - <input type="text" class="regular-text" name="<?php echo $this->key; ?>[amazon_tracking_id]" value="<?php echo esc_attr( $this->options['amazon_tracking_id'] ); ?>" />
168 - <p class="description">
169 - <?php _e( 'This is the same as your Associates Tag usually ending in "-20" or "-21". Can be found ', DFRAPI_DOMAIN ); ?>
170 - <a href="https://affiliate-program.amazon.com/gp/associates/network/main.html" target="_blank"><?php _e( 'here', DFRAPI_DOMAIN ); ?></a>.
171 - </p>
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>
172 357 <?php
173 358 }
174 359
175 360 function field_amazon_locale() {
176 361 ?>
177 - <select id="amazon_locale" name="<?php echo $this->key; ?>[amazon_locale]">
178 - <option value="br" <?php selected( $this->options['amazon_locale'], 'br', true ); ?>><?php _e( 'Brazil', DFRAPI_DOMAIN ); ?></option>
179 - <option value="ca" <?php selected( $this->options['amazon_locale'], 'ca', true ); ?>><?php _e( 'Canada', DFRAPI_DOMAIN ); ?></option>
180 - <option value="cn" <?php selected( $this->options['amazon_locale'], 'cn', true ); ?>><?php _e( 'China', DFRAPI_DOMAIN ); ?></option>
181 - <option value="fr" <?php selected( $this->options['amazon_locale'], 'fr', true ); ?>><?php _e( 'France', DFRAPI_DOMAIN ); ?></option>
182 - <option value="de" <?php selected( $this->options['amazon_locale'], 'de', true ); ?>><?php _e( 'Germany', DFRAPI_DOMAIN ); ?></option>
183 - <option value="in" <?php selected( $this->options['amazon_locale'], 'in', true ); ?>><?php _e( 'India', DFRAPI_DOMAIN ); ?></option>
184 - <option value="it" <?php selected( $this->options['amazon_locale'], 'it', true ); ?>><?php _e( 'Italy', DFRAPI_DOMAIN ); ?></option>
185 - <option value="jp" <?php selected( $this->options['amazon_locale'], 'jp', true ); ?>><?php _e( 'Japan', DFRAPI_DOMAIN ); ?></option>
186 - <option value="mx" <?php selected( $this->options['amazon_locale'], 'mx', true ); ?>><?php _e( 'Mexico', DFRAPI_DOMAIN ); ?></option>
187 - <option value="es" <?php selected( $this->options['amazon_locale'], 'es', true ); ?>><?php _e( 'Spain', DFRAPI_DOMAIN ); ?></option>
188 - <option value="uk" <?php selected( $this->options['amazon_locale'], 'uk', true ); ?>><?php _e( 'United Kingdom', DFRAPI_DOMAIN ); ?></option>
189 - <option value="us" <?php selected( $this->options['amazon_locale'], 'us', true ); ?>><?php _e( 'United States', DFRAPI_DOMAIN ); ?></option>
190 - </select>
191 - <p class="description">
192 - <a href="http://docs.aws.amazon.com/AWSECommerceService/latest/DG/AssociateIDs.html" target="_blank"><?php _e( 'More information', DFRAPI_DOMAIN ); ?></a> <?php _e( 'regarding Amazon Locales.', DFRAPI_DOMAIN ); ?>
193 - </p>
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>
194 385 <?php
195 386 }
196 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 +
197 437 function validate( $input ) {
198 -
438 +
199 439 if ( !isset( $input ) || !is_array( $input ) || empty( $input ) ) { return $input; }
200 -
440 +
201 441 $new_input = array();
202 -
203 - foreach( $input as $key => $value ) {
204 -
442 +
443 + foreach ( $input as $key => $value ) {
444 +
205 445 // Validate "access_id"
206 - if ( $key == 'access_id' ) {
207 - $new_input['access_id'] = trim( $value );
446 + if ( $key === 'access_id' ) {
447 + $new_input['access_id'] = dfrapi_sanitize_setting_text( $value );
208 448 }
209 -
449 +
210 450 // Validate "secret_key"
211 - if ( $key == 'secret_key' ) {
212 - $new_input['secret_key'] = trim( $value );
451 + if ( $key === 'secret_key' ) {
452 + $new_input['secret_key'] = dfrapi_sanitize_setting_text( $value );
213 453 }
214 -
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 +
215 464 // Validate "transport_method"
216 - if ( $key == 'transport_method' ) {
217 - $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';
218 470 }
219 -
220 - // Validate "zanox_connection_key"
221 - if ( $key == 'zanox_connection_key' ) {
222 - $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 );
223 475 }
224 -
225 - // Validate "zanox_secret_key"
226 - if ( $key == 'zanox_secret_key' ) {
227 - $new_input['zanox_secret_key'] = trim( $value );
228 - }
229 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 +
230 485 // Validate Amazon Access Key ID
231 - if ( $key == 'amazon_access_key_id' ) {
232 - $new_input['amazon_access_key_id'] = trim( $value );
486 + if ( $key === 'amazon_access_key_id' ) {
487 + $new_input['amazon_access_key_id'] = dfrapi_sanitize_setting_text( $value );
233 488 }
234 489
235 490 // Validate Amazon Secret Access Key
236 - if ( $key == 'amazon_secret_access_key' ) {
237 - $new_input['amazon_secret_access_key'] = trim( $value );
491 + if ( $key === 'amazon_secret_access_key' ) {
492 + $new_input['amazon_secret_access_key'] = dfrapi_sanitize_setting_text( $value );
238 493 }
239 494
240 495 // Validate Amazon Tracking ID
241 - if ( $key == 'amazon_tracking_id' ) {
242 - $new_input['amazon_tracking_id'] = trim( $value );
496 + if ( $key === 'amazon_tracking_id' ) {
497 + $new_input['amazon_tracking_id'] = dfrapi_sanitize_setting_text( $value );
243 498 }
244 499
245 500 // Validate Amazon Locale
246 - if ( $key == 'amazon_locale' ) {
247 - $new_input['amazon_locale'] = trim( $value );
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';
248 507 }
249 -
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 + }
250 579 } // foreach
251 -
580 +
581 + // Override setting so it's always enabled.
582 + $new_input['disable_api'] = trim( 'no' );
583 +
252 584 return $new_input;
253 585 }
254 -
586 +
255 587 } // class Dfrapi_Configuration
256 588
257 589 } // class_exists check