forked from KomodoPlatform/WooCommerce-KMD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspace-render-settings.php
More file actions
executable file
·304 lines (268 loc) · 16.6 KB
/
Copy pathspace-render-settings.php
File metadata and controls
executable file
·304 lines (268 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
/**
Spacecoin for WooCommerce
https://github.com/SpaceWorksCo/WooCommerce-SPACE
*/
// Include everything
include (dirname(__FILE__) . '/space-include-all.php');
//===========================================================================
function SPACE__render_general_settings_page () { SPACE__render_settings_page ('general'); }
function SPACE__render_advanced_settings_page () { SPACE__render_settings_page ('advanced'); }
//===========================================================================
//===========================================================================
function SPACE__render_settings_page ($menu_page_name)
{
if (isset ($_POST['button_update_space_settings']))
{
check_admin_referer( 'space-settings' ); // CSRF protection
if ( !current_user_can( 'manage_options' ) ) // Access control
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
SPACE__update_settings ("", false);
echo <<<HHHH
<div align="center" style="background-color:#FFFFE0;padding:5px;font-size:120%;border: 1px solid #E6DB55;margin:5px;border-radius:3px;">
Settings updated!
</div>
HHHH;
}
else if (isset($_POST['button_reset_space_settings']))
{
check_admin_referer( 'space-settings' ); // CSRF protection
if ( !current_user_can( 'manage_options' ) ) // Access control
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
SPACE__reset_all_settings (false);
echo <<<HHHH
<div align="center" style="background-color:#FFFFE0;padding:5px;font-size:120%;border: 1px solid #E6DB55;margin:5px;border-radius:3px;">
All settings reverted to all defaults
</div>
HHHH;
}
else if (isset($_POST['button_reset_partial_SPACE_settings']))
{
check_admin_referer( 'space-settings' ); // CSRF protection
if ( !current_user_can( 'manage_options' ) ) // Access control
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
SPACE__reset_partial_settings (false);
echo <<<HHHH
<div align="center" style="background-color:#FFFFE0;padding:5px;font-size:120%;border: 1px solid #E6DB55;margin:5px;border-radius:3px;">
Settings on this page reverted to defaults
</div>
HHHH;
}
else if (isset($_POST['validate_space-license']))
{
check_admin_referer( 'space-settings' ); // CSRF protection
if ( !current_user_can( 'manage_options' ) ) // Access control
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
SPACE__update_settings ("", false);
}
// Output full admin settings HTML
$gateway_status_message = "";
$gateway_valid_for_use = SPACE__is_gateway_valid_for_use($gateway_status_message);
if (!$gateway_valid_for_use)
{
$gateway_status_message =
'<p style="border:1px solid #DDD;padding:5px 10px;font-weight:bold;color:#EE0000;background-color:#FFFFAA;">' .
"Spacecoin Payment Gateway is NOT operational (try to re-enter and save settings): " . $gateway_status_message .
'</p>';
}
else
{
$gateway_status_message =
'<p style="border:1px solid #DDD;padding:5px 10px;font-weight:bold;color:#004400;background-color:#CCFFCC;">' .
"Spacecoin Payment Gateway is operational" .
'</p>';
}
$currency_code = false;
if (function_exists('get_woocommerce_currency'))
$currency_code = @get_woocommerce_currency();
if (!$currency_code)
$currency_code = 'USD';
$exchange_rate_message =
'<p style="border:1px solid #DDD;padding:5px 10px;background-color:#cceeff;">' .
SPACE__get_exchange_rate_per_spacecoin ($currency_code, 'getfirst', true) .
'</p>';
echo '<div class="wrap">';
switch ($menu_page_name)
{
case 'general' :
echo SPACE__GetPluginNameVersionEdition(true);
echo $gateway_status_message . $exchange_rate_message;
SPACE__render_general_settings_page_html();
break;
case 'advanced' :
echo SPACE__GetPluginNameVersionEdition(false);
echo $gateway_status_message . $exchange_rate_message;
SPACE__render_advanced_settings_page_html();
break;
default :
break;
}
echo '</div>'; // wrap
}
//===========================================================================
//===========================================================================
function SPACE__render_general_settings_page_html ()
{
$space_settings = SPACE__get_settings ();
global $g_SPACE__cron_script_url;
?>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<?php wp_nonce_field( 'space-settings' ); ?>
<p class="submit">
<input type="submit" class="button-primary" name="button_update_space_settings" value="<?php _e('Save Changes') ?>" />
<input type="submit" class="button-secondary" style="color:red;" name="button_reset_partial_space_settings" value="<?php _e('Reset settings') ?>" onClick="return confirm('Are you sure you want to reset settings on this page?');" />
</p>
<table class="form-table">
<tr valign="top">
<th scope="row">Delete all plugin-specific settings, database tables and data on uninstall:</th>
<td>
<input type="hidden" name="delete_db_tables_on_uninstall" value="0" /><input type="checkbox" name="delete_db_tables_on_uninstall" value="1" <?php if ($space_settings['delete_db_tables_on_uninstall']) echo 'checked="checked"'; ?> />
<p class="description">If checked - all plugin-specific settings, database tables and data will be removed from Wordpress database upon plugin uninstall (but not upon deactivation or upgrade).</p>
</td>
</tr>
<tr valign="top" style="display:none">
<th scope="row">Spacecoin Service Provider:</th>
<td>
<select name="service_provider" class="select " >
<option <?php if ($space_settings['service_provider'] == 'electrum_wallet') echo 'selected="selected"'; ?> value="electrum_wallet">Your own Spacecoin Electro wallet</option>
</select>
<p class="description">
Please select your Spacecoin service provider and press [Save changes]. Then fill-in necessary details and press [Save changes] again.
<br />Recommended setting: <b>Your own Spacecoin wallet</b>.
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Spacecoin Master Public Key (MPK):</th>
<td>
<textarea style="width:75%;" name="electrum_mpk_saved"><?php echo $space_settings['electrum_mpk_saved']; ?></textarea>
<p class="description">
<ol class="description">
<li>
Launch Spacecoin Electrum wallet.
</li>
<li>
Select: Wallet -> Information to see the Master Public Key.
</li>
<li>
Copy the xpub string and paste it in this field.
</li>
<li>
Save changes.
</li>
</ol>
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Number of confirmations required before accepting payment:</th>
<td>
<input type="text" name="confs_num" value="<?php echo $space_settings['confs_num']; ?>" size="4" />
<p class="description">
After a transaction is broadcast to the Spacecoin network, it may be included in a block that is published
to the network. When that happens it is said that one <a href="https://en.bitcoin.it/wiki/Confirmation"><b>confirmation</b></a> has occurred for the transaction.
With each subsequent block that is found, the number of confirmations is increased by one. To protect against double spending, a transaction should not be considered as confirmed until a certain number of blocks confirm, or verify that transaction.
6 is considered very safe number of confirmations, although it takes longer to confirm.
</p>
</td>
</tr>
<tr valign="top" style="display:none">
<th scope="row">Spacecoin Exchange rate calculation type:</th>
<td>
<select name="exchange_rate_type" class="select ">
<option <?php if ($space_settings['exchange_rate_type'] == 'vwap') echo 'selected="selected"'; ?> value="vwap">Weighted Average</option>
<option <?php if ($space_settings['exchange_rate_type'] == 'realtime') echo 'selected="selected"'; ?> value="realtime">Real Time</option>
<option <?php if ($space_settings['exchange_rate_type'] == 'bestrate') echo 'selected="selected"'; ?> value="bestrate">Most profitable</option>
</select>
<p class="description">
Weighted Average (recommended): <a href="http://en.wikipedia.org/wiki/Volume-weighted_average_price">weighted average</a> rates polled from a number of exchange services
<br />Real time: the most recent transaction rates polled from a number of exchange services.
<br />Most profitable: pick better exchange rate of all indicators (most favorable for merchant). Calculated as: MIN (Weighted Average, Real time)
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Exchange rate multiplier:</th>
<td>
<input type="text" name="exchange_multiplier" value="<?php echo $space_settings['exchange_multiplier']; ?>" size="4" />
<p class="description">
Extra multiplier to apply to convert store default currency to spacecoin price.
<br />Example: 1.05 - will add extra 5% to the total price in spacecoin.
May be useful to compensate for market volatility or for merchant's loss to fees when converting spacecoin to local currency,
or to encourage customer to use spacecoin for purchases (by setting multiplier to < 1.00 values).
</p>
</td>
</tr>
<tr valign="top" style="display:none">
<th scope="row">Extreme privacy mode enabled?</th>
<td>
<select name="PRO_EDITION_ONLY" class="select">
<option selected="selected" disabled="disabled" value="0">No (default)</option>
</select> <?php echo SPACE__GetProLabel(); ?>
<p class="description">
<b>No</b> (default, recommended) - will allow to recycle spacecoin addresses that been generated for each placed order but never received any payments. The drawback of this approach is that potential snoop can generate many fake (never paid for) orders to discover sequence of spacecoin addresses that belongs to the wallet of this store and then track down sales through blockchain analysis. The advantage of this option is that it very efficiently reuses empty (zero-balance) spacecoin addresses within the wallet, allowing only 1 sale per address without growing the wallet size (Eletrum "gap" value).
<br />
<b>Yes</b> - COMMING SOON. This will guarantee to generate unique spacecoin address for every order (real, accidental or fake). This option will provide the most anonymity and privacy to the store owner's wallet. The drawback is that it will likely leave a number of addresses within the wallet never used (and hence will require setting very high 'gap limit' within the Electrum wallet much sooner).
<br />It is recommended to regenerate new wallet after number of used spacecoin addresses reaches 1000. Wallets with very high gap limits (>1000) are very slow to sync with blockchain and they put an extra load on the network. <br />
Extreme privacy mode offers the best anonymity and privacy to the store albeit with the drawbacks of potentially flooding your Electrum wallet with expired and zero-balance addresses. Hence, for vast majority of cases (where you just need a secure way to operate spacecoin based store) it is suggested to set this option to 'No').<br />
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Auto-complete paid orders:</th>
<td>
<input type="hidden" name="autocomplete_paid_orders" value="0" /><input type="checkbox" name="autocomplete_paid_orders" value="1" <?php if ($space_settings['autocomplete_paid_orders']) echo 'checked="checked"'; ?> />
<p class="description">If checked - fully paid order will be marked as 'completed' and '<i>Your order is complete</i>' email will be immediately delivered to customer.
<br />If unchecked: store admin will need to mark order as completed manually - assuming extra time needed to ship physical product after payment is received.
<br />Note: virtual/downloadable products will automatically complete upon receiving full payment (so this setting does not have effect in this case).
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Cron job type:</th>
<td>
<select name="enable_soft_cron_job" class="select ">
<option <?php if ($space_settings['enable_soft_cron_job'] == '1') echo 'selected="selected"'; ?> value="1">Soft Cron (Wordpress-driven)</option>
<option <?php if ($space_settings['enable_soft_cron_job'] != '1') echo 'selected="selected"'; ?> value="0">Hard Cron (Cpanel-driven)</option>
</select>
<p class="description">
<?php if ($space_settings['enable_soft_cron_job'] != '1') echo '<p style="background-color:#FFC;color:#2A2;"><b>NOTE</b>: Hard Cron job is enabled: make sure to follow instructions below to enable hard cron job at your hosting panel.</p>'; ?>
Cron job will take care of all regular spacecoin payment processing tasks, like checking if payments are made and automatically completing the orders.<br />
<b>Soft Cron</b>: - Wordpress-driven (runs on behalf of a random site visitor).
<br />
<b>Hard Cron</b>: - Cron job driven by the website hosting system/server (usually via CPanel). <br />
When enabling Hard Cron job - make this script to run every 5 minutes at your hosting panel cron job scheduler:<br />
<?php echo '<tt style="background-color:#FFA;color:#B00;padding:0px 6px;">wget -O /dev/null ' . $g_SPACE__cron_script_url . '?hardcron=1</tt>'; ?>
<br /><b style="color:red;">NOTE:</b> Cron jobs <b>might not work</b> if your site is password protected with HTTP Basic auth or other methods. This will result in WooCommerce store not seeing received payments (even though funds will arrive correctly to your spacecoin addresses).
<br /><u>Note:</u> You will need to deactivate/reactivate plugin after changing this setting for it to have effect.<br />
"Hard" cron jobs may not be properly supported by all hosting plans (many shared hosting plans has restrictions in place).
</p>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" name="button_update_space_settings" value="<?php _e('Save Changes') ?>" />
<input type="submit" class="button-secondary" style="color:red;" name="button_reset_partial_space_settings" value="<?php _e('Reset settings') ?>" onClick="return confirm('Are you sure you want to reset settings on this page?');" />
</p>
</form>
<?php
}
//===========================================================================
//===========================================================================
function SPACE__render_advanced_settings_page_html ()
{
$space_settings = SPACE__get_settings ();
?>
</table>
<?php wp_nonce_field( 'space-settings' ); ?>
<p class="submit">
<input type="submit" class="button-primary" name="button_update_space_settings" value="{$value_save_changes}" />
<input type="submit" class="button-secondary" style="color:red;" name="button_reset_partial_space_settings" value="{$value_reset_settings}" onClick="return confirm('Are you sure you want to reset settings on this page?');" />
</p>
</form>
TTT;
echo $html_out;
//{{{/PLACEHOLDER}}} ?> ///+{EDITION==Pro}///
<?php
}
//===========================================================================