PluginProbe
Datafeedr API / 1.0.125
Datafeedr API v1.0.125
1.4.3 1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 All 182 releases
datafeedr-api / classes / class-dfrapi-configuration.php

class-dfrapi-configuration.php in Datafeedr API 1.0.125, at classes/class-dfrapi-configuration.php

426 lines 20.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 if ( ! class_exists( 'Dfrapi_Configuration' ) ) {
6
7 /**
8 * Configuration page.
9 */
10 class Dfrapi_Configuration {
11
12 private $page = 'dfrapi-configuration';
13 private $key;
14 private $account;
15 public $options;
16
17 public function __construct() {
18 $this->key = 'dfrapi_configuration';
19 $this->account = (array) get_option( 'dfrapi_account', array( 'max_length' => 50 ) );
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 );
23 add_action( 'admin_notices', array( $this, 'admin_notice' ) );
24 }
25
26 function admin_menu() {
27 add_submenu_page(
28 'dfrapi',
29 __( 'Configuration &#8212; Datafeedr API', 'datafeedr-api' ),
30 __( 'Configuration', 'datafeedr-api' ),
31 'manage_options',
32 'dfrapi',
33 array( $this, 'output' )
34 );
35 }
36
37 function admin_notice() {
38 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && 'dfrapi' == $_GET['page'] ) {
39 echo '<div class="updated"><p>';
40 _e( 'Configuration successfully updated!', 'datafeedr-api' );
41 echo '</p></div>';
42 }
43 }
44
45 function output() {
46 echo '<div class="wrap" id="' . $this->key . '">';
47 echo '<h2>' . dfrapi_setting_pages( $this->page ) . ' &#8212; Datafeedr API</h2>';
48 echo '<form method="post" action="options.php">';
49 wp_nonce_field( 'update-options' );
50 settings_fields( $this->page );
51 do_settings_sections( $this->page);
52 submit_button();
53 echo '</form>';
54 echo '</div>';
55 }
56
57 function load_settings() {
58 $this->options = (array) get_option( $this->key );
59 $this->options = array_merge(
60 array(
61 'access_id' => '',
62 'secret_key' => '',
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 'hs_beacon' => 'on',
79 ),
80 $this->options
81 );
82 }
83
84 function register_settings() {
85 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
86 add_settings_section( 'api_settings', __( 'Datafeedr API Settings', 'datafeedr-api' ), array( &$this, 'section_api_settings_desc' ), $this->page );
87 add_settings_field( 'access_id', __( 'API Access ID', 'datafeedr-api' ), array( &$this, 'field_access_id' ), $this->page, 'api_settings' );
88 add_settings_field( 'secret_key', __( 'API Secret Key', 'datafeedr-api' ), array( &$this, 'field_secret_key' ), $this->page, 'api_settings' );
89 // add_settings_field( 'transport_method', __( 'Transport Method', 'datafeedr-api' ), array( &$this, 'field_transport_method' ), $this->page, 'api_settings' );
90
91 /*
92 add_settings_field(
93 'disable_api',
94 __( 'Disable API', 'datafeedr-api' ),
95 array( &$this, 'field_disable_api' ),
96 $this->page,
97 'api_settings'
98 );
99 */
100
101 add_settings_section( 'awin_settings', __( 'Awin Settings', 'datafeedr-api' ), array( &$this, 'section_awin_settings_desc' ), $this->page );
102 add_settings_field( 'awin_access_token', __( 'Awin API Token', 'datafeedr-api' ), array( &$this, 'field_awin_access_token' ), $this->page, 'awin_settings' );
103
104 add_settings_section( 'affiliate_gateway_settings', __( 'The Affiliate Gateway Settings', 'datafeedr-api' ), array( &$this, 'section_affiliate_gateway_settings_desc' ), $this->page );
105 add_settings_field( 'affiliate_gateway_sid', __( 'The Affiliate Gateway SID', 'datafeedr-api' ), array( &$this, 'field_affiliate_gateway_sid' ), $this->page, 'affiliate_gateway_settings' );
106
107 add_settings_section( 'belboon_settings', __( 'Belboon Settings', 'datafeedr-api' ), array( &$this, 'section_belboon_settings_desc' ), $this->page );
108 add_settings_field( 'belboon_aid', __( 'Adspace ID', 'datafeedr-api' ), array( &$this, 'field_belboon_aid' ), $this->page, 'belboon_settings' );
109
110 if ( defined( 'DFRCS_VERSION' ) ) {
111 add_settings_section( 'amazon_api_settings', __( 'Amazon Settings', 'datafeedr-api' ), array( &$this, 'section_amazon_api_settings_desc' ), $this->page );
112 add_settings_field( 'amazon_access_key_id', __( 'Amazon Access Key ID', 'datafeedr-api' ), array( &$this, 'field_amazon_access_key_id' ), $this->page, 'amazon_api_settings' );
113 add_settings_field( 'amazon_secret_access_key', __( 'Amazon Secret Access Key', 'datafeedr-api' ), array( &$this, 'field_amazon_secret_access_key' ), $this->page, 'amazon_api_settings' );
114 add_settings_field( 'amazon_tracking_id', __( 'Amazon Tracking ID', 'datafeedr-api' ), array( &$this, 'field_amazon_tracking_id' ), $this->page, 'amazon_api_settings' );
115 add_settings_field( 'amazon_locale', __( 'Amazon Locale', 'datafeedr-api' ), array( &$this, 'field_amazon_locale' ), $this->page, 'amazon_api_settings' );
116 }
117
118 add_settings_section( 'ph_api_settings', __( 'Partnerize Settings', 'datafeedr-api' ), array( &$this, 'section_ph_api_settings_desc' ), $this->page );
119 add_settings_field( 'ph_application_key', __( 'Application Key', 'datafeedr-api' ), array( &$this, 'field_ph_application_key' ), $this->page, 'ph_api_settings' );
120 add_settings_field( 'ph_user_api_key', __( 'User API Key', 'datafeedr-api' ), array( &$this, 'field_ph_user_api_key' ), $this->page, 'ph_api_settings' );
121 add_settings_field( 'ph_publisher_id', __( 'Publisher ID', 'datafeedr-api' ), array( &$this, 'field_ph_publisher_id' ), $this->page, 'ph_api_settings' );
122
123 add_settings_section( 'effiliation_api_settings', __( 'Effiliation Settings', 'datafeedr-api' ), array( &$this, 'section_effiliation_api_settings_desc' ), $this->page );
124 add_settings_field( 'effiliation_key', __( 'Effiliation Key', 'datafeedr-api' ), array( &$this, 'field_effiliation_key' ), $this->page, 'effiliation_api_settings' );
125
126 add_settings_section( 'hs_beacon_settings', __( 'Datafeedr Documentation & Support Link', 'datafeedr-api' ), array( &$this, 'section_hs_beacon_settings_desc' ), $this->page );
127 add_settings_field( 'hs_beacon_status', __( 'Enabled', 'datafeedr-api' ), array( &$this, 'field_hs_beacon_status' ), $this->page, 'hs_beacon_settings' );
128 }
129
130 function section_api_settings_desc() {
131 echo __( 'Add your ', 'datafeedr-api' );
132 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' ) . '">';
133 echo __( 'Datafeedr API Keys', 'datafeedr-api' );
134 echo '</a>.';
135 }
136
137 function field_access_id() {
138 ?>
139 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[access_id]" value="<?php echo esc_attr( $this->options['access_id'] ); ?>" />
140 <?php
141 }
142
143 function field_secret_key() {
144 ?>
145 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[secret_key]" value="<?php echo esc_attr( $this->options['secret_key'] ); ?>" />
146 <?php
147 }
148
149 function section_ph_api_settings_desc() {
150 echo __( 'If you want to use the Partnerize affiliate network, add your ', 'datafeedr-api' );
151 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' ) . '">';
152 echo __( 'Partnerize Keys', 'datafeedr-api' );
153 echo '</a>.';
154 }
155
156 function field_ph_application_key() {
157 ?>
158 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[ph_application_key]" value="<?php echo esc_attr( $this->options['ph_application_key'] ); ?>" />
159 <?php
160 }
161
162 function field_ph_user_api_key() {
163 ?>
164 <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'] ); ?>" />
165 <?php
166 }
167
168 function field_ph_publisher_id() {
169 ?>
170 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[ph_publisher_id]" value="<?php echo esc_attr( $this->options['ph_publisher_id'] ); ?>" />
171 <?php
172 }
173
174 function section_effiliation_api_settings_desc() {
175 echo __( 'If you want to use the Effiliation affiliate network, add your ', 'datafeedr-api' );
176 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' ) . '">';
177 echo __( 'Effiliation Key', 'datafeedr-api' );
178 echo '</a>.';
179 }
180
181 function field_effiliation_key() {
182 ?>
183 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[effiliation_key]" value="<?php echo esc_attr( $this->options['effiliation_key'] ); ?>" />
184 <?php
185 }
186
187 function section_awin_settings_desc() {
188 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' );
189 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' ) . '">';
190 echo __( 'Learn how to find your Awin API Token', 'datafeedr-api' );
191 echo '</a>.';
192 }
193
194 function field_awin_access_token() {
195 ?>
196 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[awin_access_token]" value="<?php echo esc_attr( $this->options['awin_access_token'] ); ?>" />
197 <?php
198 }
199
200 function section_affiliate_gateway_settings_desc() {
201 echo __( 'If you want to use The Affiliate Gateway affiliate network, enter your Affiliate Gateway SID.', 'datafeedr-api' );
202 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' ) . '">';
203 echo __( 'Learn how to get your Affiliate Gateway SID', 'datafeedr-api' );
204 echo '</a>.';
205 }
206
207 function field_affiliate_gateway_sid() {
208 ?>
209 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[affiliate_gateway_sid]" value="<?php echo esc_attr( $this->options['affiliate_gateway_sid'] ); ?>" />
210 <?php
211 }
212
213 function section_belboon_settings_desc() {
214 echo __( 'If you want to use the Belboon affiliate network, enter your Belboon Adspace ID.', 'datafeedr-api' );
215 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' ) . '">';
216 echo __( 'Learn how to get your Belboon Adspace ID', 'datafeedr-api' );
217 echo '</a>.';
218 }
219
220 function field_belboon_aid() {
221 ?>
222 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[belboon_aid]" value="<?php echo esc_attr( $this->options['belboon_aid'] ); ?>" />
223 <?php
224 }
225
226 function field_transport_method() {
227 ?>
228 <select id="transport_method" name="<?php echo $this->key; ?>[transport_method]">
229 <option value="curl" <?php selected( $this->options['transport_method'], 'curl', true ); ?>><?php _e( 'CURL', 'datafeedr-api' ); ?></option>
230 <option value="file" <?php selected( $this->options['transport_method'], 'file', true ); ?>><?php _e( 'File', 'datafeedr-api' ); ?></option>
231 <option value="socket" <?php selected( $this->options['transport_method'], 'socket', true ); ?>><?php _e( 'Socket', 'datafeedr-api' ); ?></option>
232 </select>
233 <p class="description"><?php _e( 'If you\'re not sure, use CURL.', 'datafeedr-api' ); ?></p>
234 <?php
235 }
236
237 function field_disable_api() {
238 ?>
239 <p>
240 <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' ); ?>
241 </p>
242 <p>
243 <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' ); ?>
244 </p>
245 <p class="description"><?php _e( 'Prevent your site from attempting to make a request to the Datafeedr API.', 'datafeedr-api' ); ?></p>
246 <?php
247 }
248
249 function section_amazon_api_settings_desc() {
250 echo __( 'Add your ', 'datafeedr-api' );
251 echo '<a href="https://affiliate-program.amazon.com/gp/advertising/api/detail/your-account.html" target="_blank">';
252 echo __( 'Amazon Product Advertising API keys', 'datafeedr-api' );
253 echo '</a>.';
254 echo '<br /><span style="color:red">';
255 echo __( 'These are ONLY compatible with the Datafeedr Comparison Sets plugin.', 'datafeedr-api' );
256 echo '</span>';
257 }
258
259 function field_amazon_access_key_id() {
260 ?>
261 <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'] ); ?>" />
262 <?php
263 }
264
265 function field_amazon_secret_access_key() {
266 ?>
267 <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'] ); ?>" />
268 <?php
269 }
270
271 function field_amazon_tracking_id() {
272 ?>
273 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[amazon_tracking_id]" value="<?php echo esc_attr( $this->options['amazon_tracking_id'] ); ?>" />
274 <p class="description">
275 <?php _e( 'This is the same as your Associates Tag usually ending in "-20" or "-21". Can be found ', 'datafeedr-api' ); ?>
276 <a href="https://affiliate-program.amazon.com/gp/associates/network/main.html" target="_blank"><?php _e( 'here', 'datafeedr-api' ); ?></a>.
277 </p>
278 <?php
279 }
280
281 function field_amazon_locale() {
282 ?>
283 <select id="amazon_locale" name="<?php echo $this->key; ?>[amazon_locale]">
284 <option value="au" <?php selected( $this->options['amazon_locale'], 'au', true ); ?>><?php _e( 'Australia', 'datafeedr-api' ); ?></option>
285 <option value="br" <?php selected( $this->options['amazon_locale'], 'br', true ); ?>><?php _e( 'Brazil', 'datafeedr-api' ); ?></option>
286 <option value="ca" <?php selected( $this->options['amazon_locale'], 'ca', true ); ?>><?php _e( 'Canada', 'datafeedr-api' ); ?></option>
287 <option value="fr" <?php selected( $this->options['amazon_locale'], 'fr', true ); ?>><?php _e( 'France', 'datafeedr-api' ); ?></option>
288 <option value="de" <?php selected( $this->options['amazon_locale'], 'de', true ); ?>><?php _e( 'Germany', 'datafeedr-api' ); ?></option>
289 <option value="in" <?php selected( $this->options['amazon_locale'], 'in', true ); ?>><?php _e( 'India', 'datafeedr-api' ); ?></option>
290 <option value="it" <?php selected( $this->options['amazon_locale'], 'it', true ); ?>><?php _e( 'Italy', 'datafeedr-api' ); ?></option>
291 <option value="jp" <?php selected( $this->options['amazon_locale'], 'jp', true ); ?>><?php _e( 'Japan', 'datafeedr-api' ); ?></option>
292 <option value="mx" <?php selected( $this->options['amazon_locale'], 'mx', true ); ?>><?php _e( 'Mexico', 'datafeedr-api' ); ?></option>
293 <option value="nl" <?php selected( $this->options['amazon_locale'], 'nl', true ); ?>><?php _e( 'Netherlands', 'datafeedr-api' ); ?></option>
294 <option value="sg" <?php selected( $this->options['amazon_locale'], 'sg', true ); ?>><?php _e( 'Singapore', 'datafeedr-api' ); ?></option>
295 <option value="sa" <?php selected( $this->options['amazon_locale'], 'sa', true ); ?>><?php _e( 'Saudi Arabia', 'datafeedr-api' ); ?></option>
296 <option value="es" <?php selected( $this->options['amazon_locale'], 'es', true ); ?>><?php _e( 'Spain', 'datafeedr-api' ); ?></option>
297 <option value="se" <?php selected( $this->options['amazon_locale'], 'se', true ); ?>><?php _e( 'Sweden', 'datafeedr-api' ); ?></option>
298 <option value="tr" <?php selected( $this->options['amazon_locale'], 'tr', true ); ?>><?php _e( 'Turkey', 'datafeedr-api' ); ?></option>
299 <option value="ae" <?php selected( $this->options['amazon_locale'], 'ae', true ); ?>><?php _e( 'United Arab Emirates', 'datafeedr-api' ); ?></option>
300 <option value="uk" <?php selected( $this->options['amazon_locale'], 'uk', true ); ?>><?php _e( 'United Kingdom', 'datafeedr-api' ); ?></option>
301 <option value="us" <?php selected( $this->options['amazon_locale'], 'us', true ); ?>><?php _e( 'United States', 'datafeedr-api' ); ?></option>
302 </select>
303 <p class="description">
304 <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' ); ?>
305 </p>
306 <?php
307 }
308
309 function section_hs_beacon_settings_desc() {
310 echo __( 'Display the link to Datafeedr documentation and support on every Datafeedr-specific page in your WordPress Admin Area. ',
311 'datafeedr-api' );
312 echo __( 'This provides the full Datafeedr documentation and access to a support contact form right inside your WordPress site.',
313 'datafeedr-api' );
314 }
315
316 function field_hs_beacon_status() {
317 ?>
318 <p>
319 <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' ); ?>
320 </p>
321 <p>
322 <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' ); ?>
323 </p>
324 <?php
325 }
326
327 function validate( $input ) {
328
329 if ( !isset( $input ) || !is_array( $input ) || empty( $input ) ) { return $input; }
330
331 $new_input = array();
332
333 foreach( $input as $key => $value ) {
334
335 // Validate "access_id"
336 if ( $key == 'access_id' ) {
337 $new_input['access_id'] = trim( $value );
338 }
339
340 // Validate "secret_key"
341 if ( $key == 'secret_key' ) {
342 $new_input['secret_key'] = trim( $value );
343 }
344
345 // Validate "transport_method"
346 if ( $key == 'transport_method' ) {
347 $new_input['transport_method'] = trim( $value );
348 }
349
350 // Validate "disable_api"
351 if ( $key == 'disable_api' ) {
352 $new_input['disable_api'] = trim( $value );
353 }
354
355 // Validate Amazon Access Key ID
356 if ( $key == 'amazon_access_key_id' ) {
357 $new_input['amazon_access_key_id'] = trim( $value );
358 }
359
360 // Validate Amazon Secret Access Key
361 if ( $key == 'amazon_secret_access_key' ) {
362 $new_input['amazon_secret_access_key'] = trim( $value );
363 }
364
365 // Validate Amazon Tracking ID
366 if ( $key == 'amazon_tracking_id' ) {
367 $new_input['amazon_tracking_id'] = trim( $value );
368 }
369
370 // Validate Amazon Locale
371 if ( $key == 'amazon_locale' ) {
372 $new_input['amazon_locale'] = trim( $value );
373 }
374
375 // Validate PH Application Key
376 if ( $key == 'ph_application_key' ) {
377 $new_input['ph_application_key'] = trim( $value );
378 }
379
380 // Validate PH User API Key
381 if ( $key == 'ph_user_api_key' ) {
382 $new_input['ph_user_api_key'] = trim( $value );
383 }
384
385 // Validate PH Publisher Key
386 if ( $key == 'ph_publisher_id' ) {
387 $new_input['ph_publisher_id'] = trim( $value );
388 }
389
390 // Validate Effiliation Key
391 if ( $key == 'effiliation_key' ) {
392 $new_input['effiliation_key'] = trim( $value );
393 }
394
395 // Validate Awin Acceess Token
396 if ( $key == 'awin_access_token' ) {
397 $new_input['awin_access_token'] = trim( $value );
398 }
399
400 // Validate The Affiliate Gateway SID
401 if ( $key == 'affiliate_gateway_sid' ) {
402 $new_input['affiliate_gateway_sid'] = trim( $value );
403 }
404
405 // Validate Belboon AID
406 if ( $key == 'belboon_aid' ) {
407 $new_input['belboon_aid'] = trim( $value );
408 }
409
410 // Enable HelpScout Beacon
411 if ( $key == 'hs_beacon' ) {
412 $new_input['hs_beacon'] = ( 'on' == $value ) ? 'on' : 'off';
413 }
414
415 } // foreach
416
417 // Override setting so it's always enabled.
418 $new_input['disable_api'] = trim( 'no' );
419
420 return $new_input;
421 }
422
423 } // class Dfrapi_Configuration
424
425 } // class_exists check
426