PluginProbe
Datafeedr API / 1.0.32
Datafeedr API v1.0.32
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.32, at classes/class-dfrapi-configuration.php

258 lines 11.4 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
16 public function __construct() {
17 $this->key = 'dfrapi_configuration';
18 $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' ) );
22 add_action( 'admin_notices', array( $this, 'admin_notice' ) );
23 }
24
25 function admin_menu() {
26 add_submenu_page(
27 'dfrapi',
28 __( 'Configuration &#8212; Datafeedr API', DFRAPI_DOMAIN ),
29 __( 'Configuration', DFRAPI_DOMAIN ),
30 'manage_options',
31 'dfrapi',
32 array( $this, 'output' )
33 );
34 }
35
36 function admin_notice() {
37 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>';
41 }
42 }
43
44 function output() {
45 echo '<div class="wrap" id="' . $this->key . '">';
46 echo '<h2>' . dfrapi_setting_pages( $this->page ) . ' &#8212; Datafeedr API</h2>';
47 echo '<form method="post" action="options.php">';
48 wp_nonce_field( 'update-options' );
49 settings_fields( $this->page );
50 do_settings_sections( $this->page);
51 submit_button();
52 echo '</form>';
53 echo '</div>';
54 }
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 'amazon_access_key_id' => '',
66 'amazon_secret_access_key' => '',
67 'amazon_tracking_id' => '',
68 'amazon_locale' => 'us',
69 ),
70 $this->options
71 );
72 }
73
74 function register_settings() {
75 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' );
84
85 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' );
91 }
92 }
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 );
98 echo '</a>.';
99 }
100
101 function field_access_id() {
102 ?>
103 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[access_id]" value="<?php echo esc_attr( $this->options['access_id'] ); ?>" />
104 <?php
105 }
106
107 function field_secret_key() {
108 ?>
109 <input type="text" class="regular-text" name="<?php echo $this->key; ?>[secret_key]" value="<?php echo esc_attr( $this->options['secret_key'] ); ?>" />
110 <?php
111 }
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 );
117 echo '</a>.';
118 }
119
120 function field_zanox_connection_key() {
121 ?>
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'] ); ?>" />
123 <?php
124 }
125
126 function field_zanox_secret_key() {
127 ?>
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'] ); ?>" />
129 <?php
130 }
131
132 function field_transport_method() {
133 ?>
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>
140 <?php
141 }
142
143 function section_amazon_api_settings_desc() {
144 echo __( 'Add your ', DFRAPI_DOMAIN );
145 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 );
147 echo '</a>.';
148 echo '<br /><span style="color:red">';
149 echo __( 'These are ONLY compatible with the Datafeedr Comparison Sets plugin.', DFRAPI_DOMAIN );
150 echo '</span>';
151 }
152
153 function field_amazon_access_key_id() {
154 ?>
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'] ); ?>" />
156 <?php
157 }
158
159 function field_amazon_secret_access_key() {
160 ?>
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'] ); ?>" />
162 <?php
163 }
164
165 function field_amazon_tracking_id() {
166 ?>
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>
172 <?php
173 }
174
175 function field_amazon_locale() {
176 ?>
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>
194 <?php
195 }
196
197 function validate( $input ) {
198
199 if ( !isset( $input ) || !is_array( $input ) || empty( $input ) ) { return $input; }
200
201 $new_input = array();
202
203 foreach( $input as $key => $value ) {
204
205 // Validate "access_id"
206 if ( $key == 'access_id' ) {
207 $new_input['access_id'] = trim( $value );
208 }
209
210 // Validate "secret_key"
211 if ( $key == 'secret_key' ) {
212 $new_input['secret_key'] = trim( $value );
213 }
214
215 // Validate "transport_method"
216 if ( $key == 'transport_method' ) {
217 $new_input['transport_method'] = trim( $value );
218 }
219
220 // Validate "zanox_connection_key"
221 if ( $key == 'zanox_connection_key' ) {
222 $new_input['zanox_connection_key'] = trim( $value );
223 }
224
225 // Validate "zanox_secret_key"
226 if ( $key == 'zanox_secret_key' ) {
227 $new_input['zanox_secret_key'] = trim( $value );
228 }
229
230 // Validate Amazon Access Key ID
231 if ( $key == 'amazon_access_key_id' ) {
232 $new_input['amazon_access_key_id'] = trim( $value );
233 }
234
235 // Validate Amazon Secret Access Key
236 if ( $key == 'amazon_secret_access_key' ) {
237 $new_input['amazon_secret_access_key'] = trim( $value );
238 }
239
240 // Validate Amazon Tracking ID
241 if ( $key == 'amazon_tracking_id' ) {
242 $new_input['amazon_tracking_id'] = trim( $value );
243 }
244
245 // Validate Amazon Locale
246 if ( $key == 'amazon_locale' ) {
247 $new_input['amazon_locale'] = trim( $value );
248 }
249
250 } // foreach
251
252 return $new_input;
253 }
254
255 } // class Dfrapi_Configuration
256
257 } // class_exists check
258