PluginProbe
Spoki – Chat Buttons and WooCommerce Notifications / trunk
Spoki – Chat Buttons and WooCommerce Notifications vtrunk
2.17.4 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.10.0 2.11.0 2.11.1 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.14.0 All 69 releases
spoki / views / html-settings.php

html-settings.php in Spoki – Chat Buttons and WooCommerce Notifications trunk, at views/html-settings.php

350 lines 19.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 $has_wc = spoki_has_woocommerce();
3 $is_current_tab = $GLOBALS['current_tab'] == 'settings';
4 $has_key = (isset($this->options['secret']) && trim($this->options['secret']) != '') || (isset($this->options['delivery_url']) && trim($this->options['delivery_url']) != '');
5 $has_spoki_keys = (isset($this->options['secret']) && trim($this->options['secret']) != '') && (isset($this->options['delivery_url']) && trim($this->options['delivery_url']) != '');
6 $account_info = $this->options['account_info'] ?? ['plan' => []];
7
8 if ($is_current_tab) {
9 if ($has_wc && $has_spoki_keys && !isset($account_info['plan']['name'])) {
10 $account_info = Spoki()->fetch_account_info();
11 }
12
13 $response_status = Spoki()->fetch_secret_status(true);
14 if (is_wp_error($response_status)) { ?>
15 <div class="notice notice-error">
16 <p>
17 <b><?php _e('Unable to reach the Spoki server. Your website is blocking the requests.', "spoki"); ?></b><br/>
18 <span><?php _e('Most common motivations are:', "spoki"); ?></span>
19 <ul style="list-style-type: initial;">
20 <li><?php _e('A Firewall is blocking the Spoki requests => disable the Firewall or add "https://api.spoki.com" to the whitelist', "spoki"); ?></li>
21 <li><?php _e('A plugin is caching the Spoki requests => clear cache and try again or disable caching', "spoki"); ?></li>
22 <li><?php _e('The website is too slow and can\'t perform all requests in time => Increase the max_execution_time in your php.ini', "spoki"); ?></li>
23 </ul>
24 <span>Error: <?php echo $response_status->get_error_message() ?>. </span>
25 <a
26 target="_blank"
27 href="https://www.google.com/search?q=Wordpress <?php echo $response_status->get_error_message() ?>"
28 ><?php _e('How to fix', "spoki"); ?></a>
29 </p>
30 </div>
31 <?php }
32 }
33 $is_pro = isset($account_info['plan']['is_pro']) && $account_info['plan']['is_pro'] == true;
34 $has_valid_secret = isset($this->options['secret_status']['code']) && $this->options['secret_status']['code'] == 200;
35
36 if ($has_wc && $has_key && !$has_valid_secret) { ?>
37 <div class="notice notice-error">
38 <p>
39 <b><?php _e('Your Spoki keys are not valid!', "spoki"); ?></b>
40 <a href="?page=<?php echo urlencode(SPOKI_PLUGIN_NAME) ?>&tab=settings">
41 <?php _e('Settings', "spoki") ?>
42 </a>
43 </p>
44 </div>
45 <?php } ?>
46
47 <div <?php if (!$is_current_tab) echo 'style="display:none"' ?>>
48 <h2><?php _e('Account info', "spoki") ?></h2>
49 <p><?php _e('This account info will be used to let WhatsApp buttons work.', "spoki") ?></p>
50 <table class="form-table">
51 <tr>
52 <th scope="row">
53 <label for="<?php echo SPOKI_OPTIONS ?>[telephone]">
54 <?php _e('Your WhatsApp Telephone', "spoki") ?> *
55 </label>
56 </th>
57 <td>
58 <div class="spoki-phone-container">
59 <input type="text" class="regular-text spoki-phone-prefix"
60 name="<?php echo SPOKI_OPTIONS ?>[prefix]"
61 <?php if ($is_current_tab) echo 'required' ?>
62 value="<?php if (isset($this->options['prefix']) && trim($this->options['prefix']) != '') echo $this->options['prefix'] ?>"
63 placeholder="+39"
64 />
65 <input type="tel" class="regular-text"
66 name="<?php echo SPOKI_OPTIONS ?>[telephone]"
67 <?php if ($is_current_tab) echo 'required' ?>
68 placeholder="3331234567"
69 value="<?php if (isset($this->options['telephone']) && trim($this->options['telephone']) != '') echo $this->options['telephone'] ?>"
70 />
71 </div>
72 <p class="description">
73 <b><?php _e("Note", "spoki") ?></b>: <?php _e("Your customers will send messages to this WhatsApp number", "spoki") ?>
74 </p>
75 </td>
76 </tr>
77 <tr>
78 <th scope="row">
79 <label for="<?php echo SPOKI_OPTIONS ?>[shop_name]">
80 <?php _e('Shop Name', "spoki") ?> *
81 </label>
82 </th>
83 <td>
84 <input type="text" class="regular-text" <?php if ($is_current_tab) echo 'required' ?>
85 name="<?php echo SPOKI_OPTIONS ?>[shop_name]"
86 placeholder="<?php echo Spoki()->shop['name'] ?>"
87 value="<?php if (isset($this->options['shop_name']) && trim($this->options['shop_name']) != '') echo $this->options['shop_name'] ?>"
88 />
89 </td>
90 </tr>
91 <tr>
92 <th scope="row">
93 <label for="<?php echo SPOKI_OPTIONS ?>[email]">
94 <?php _e('Your best email', "spoki") ?> *
95 </label>
96 </th>
97 <td>
98 <input type="email" class="regular-text" <?php if ($is_current_tab) echo 'required' ?>
99 name="<?php echo SPOKI_OPTIONS ?>[email]"
100 placeholder="<?php echo Spoki()->shop['email'] ?>"
101 value="<?php if (isset($this->options['email']) && trim($this->options['email']) != '') echo $this->options['email'] ?>"
102 />
103 </td>
104 </tr>
105 <tr>
106 <th scope="row">
107 <label for="<?php echo SPOKI_OPTIONS ?>[default_prefix]">
108 <?php _e('Default prefix', "spoki") ?>
109 </label>
110 </th>
111 <td>
112 <input type="text" class="regular-text spoki-phone-prefix"
113 name="<?php echo SPOKI_OPTIONS ?>[default_prefix]"
114 value="<?php if (isset($this->options['default_prefix']) && trim($this->options['default_prefix']) != '') echo $this->options['default_prefix'] ?>"
115 placeholder="+39"
116 />
117 <p class="description">
118 <b><?php _e("Note", "spoki") ?></b>: <?php _e('Set the default prefix to set if the customer don\'t specify it in the phone number field in the checkout.<br/>If empty Spoki will try to guess it. ', "spoki"); ?>
119 </p>
120 </td>
121 </tr>
122 <?php if ($is_current_tab): ?>
123 <tr>
124 <th>
125 <label for="single_product_button_position">
126 <b><?php _e('Language', "spoki") ?></b>
127 </label>
128 </th>
129 <td>
130 <?php
131 $language = Spoki()->shop['language'];
132 $is_spanish = spoki_starts_with($language, 'es');
133 $is_italian = spoki_starts_with($language, 'it');
134 $is_portoguese = spoki_starts_with($language, 'pt');
135 $is_french = spoki_starts_with($language, 'fr');
136 $is_english = !$is_italian && !$is_spanish && !$is_portoguese && !$is_french;
137 ?>
138 <select name="<?php echo SPOKI_OPTIONS ?>[language]" id="language" class="regular-text">
139 <option value="en-EN" <?php echo $is_english ? 'selected' : '' ?>><?php echo __('English', "spoki") ?></option>
140 <option value="it-IT" <?php echo $is_italian ? 'selected' : '' ?>><?php echo __('Italian', "spoki") ?></option>
141 <option value="es-ES" <?php echo $is_spanish ? 'selected' : '' ?>><?php echo __('Spanish', "spoki") ?></option>
142 <option value="pt-PT" <?php echo $is_portoguese ? 'selected' : '' ?>><?php echo __('Portuguese', "spoki") ?></option>
143 <option value="fr-FR" <?php echo $is_french ? 'selected' : '' ?>><?php echo __('French', "spoki") ?></option>
144 </select>
145 <p class="description">
146 <?php _e('Your language is not in list?', "spoki") ?> <a target="_blank" href="<?php echo SPOKI_SUGGEST_TEMPLATES_URL ?>"><?php _e('Suggest messages', "spoki") ?></a>
147 </p>
148 <p class="description">
149 <b><?php _e("Note", "spoki") ?></b>: <?php _e('Choose the language of the WooCommerce messages to send to customers', "spoki"); ?>
150 </p>
151 </td>
152 </tr>
153 <?php endif; ?>
154 <tr>
155 <th scope="row">
156 <label for="<?php echo SPOKI_OPTIONS ?>[contact_link]">
157 <?php _e('Contact link', "spoki") ?>
158 </label>
159 </th>
160 <td>
161 <input type="text" class="regular-text"
162 name="<?php echo SPOKI_OPTIONS ?>[contact_link]"
163 placeholder="<?php _e('Reply to the WhatsApp telephone', 'spoki') ?>"
164 value="<?php if (isset($this->options['contact_link']) && trim($this->options['contact_link']) != '') echo $this->options['contact_link'] ?>"
165 />
166 <p class="description">
167 <b><?php _e("Note", "spoki") ?></b>: <?php _e("Enter the link where your customers can contact you after receiving the notification message.<br/>This link will come at the end of each WooCommerce notification message.<br/>If you leave empty the customers will reply to your WhatsApp telephone.", "spoki") ?>
168 <small>(<?php echo Spoki()->shop['telephone'] ?>)</small>
169 </p>
170 </td>
171 </tr>
172 <tr>
173 <th scope="row">
174 <label><?php _e('Working Days and Times', "spoki") ?></label>
175 </th>
176 <td>
177 <label>
178 <input id="working-days-times-toggle" type="checkbox" name="<?php echo SPOKI_OPTIONS ?>[working_days_times][enabled]" value="1" <?php if (isset($this->options['working_days_times']['enabled'])) echo checked(1, $this->options['working_days_times']['enabled'], false) ?>>
179 <?php _e('Enable working days and times', "spoki") ?>
180 </label>
181 <br/>
182 <br/>
183 <label>
184 <input class="working-field" disabled type="checkbox" name="<?php echo SPOKI_OPTIONS ?>[working_days_times][day_1]" value="1" <?php if (isset($this->options['working_days_times']['day_1'])) echo checked(1, $this->options['working_days_times']['day_1'], false) ?>>
185 <?php _e('Monday', "spoki") ?>
186 </label>
187 <br/>
188 <label>
189 <input class="working-field" disabled type="checkbox" name="<?php echo SPOKI_OPTIONS ?>[working_days_times][day_2]" value="1" <?php if (isset($this->options['working_days_times']['day_2'])) echo checked(1, $this->options['working_days_times']['day_2'], false) ?>>
190 <?php _e('Tuesday', "spoki") ?>
191 </label>
192 <br/>
193 <label>
194 <input class="working-field" disabled type="checkbox" name="<?php echo SPOKI_OPTIONS ?>[working_days_times][day_3]" value="1" <?php if (isset($this->options['working_days_times']['day_3'])) echo checked(1, $this->options['working_days_times']['day_3'], false) ?>>
195 <?php _e('Wednesday', "spoki") ?>
196 </label>
197 <br/>
198 <label>
199 <input class="working-field" disabled type="checkbox" name="<?php echo SPOKI_OPTIONS ?>[working_days_times][day_4]" value="1" <?php if (isset($this->options['working_days_times']['day_4'])) echo checked(1, $this->options['working_days_times']['day_4'], false) ?>>
200 <?php _e('Thursday', "spoki") ?>
201 </label>
202 <br/>
203 <label>
204 <input class="working-field" disabled type="checkbox" name="<?php echo SPOKI_OPTIONS ?>[working_days_times][day_5]" value="1" <?php if (isset($this->options['working_days_times']['day_5'])) echo checked(1, $this->options['working_days_times']['day_5'], false) ?>>
205 <?php _e('Friday', "spoki") ?>
206 </label>
207 <br/>
208 <label>
209 <input class="working-field" disabled type="checkbox" name="<?php echo SPOKI_OPTIONS ?>[working_days_times][day_6]" value="1" <?php if (isset($this->options['working_days_times']['day_6'])) echo checked(1, $this->options['working_days_times']['day_6'], false) ?>>
210 <?php _e('Saturday', "spoki") ?>
211 </label>
212 <br/>
213 <label>
214 <input class="working-field" disabled type="checkbox" name="<?php echo SPOKI_OPTIONS ?>[working_days_times][day_0]" value="1" <?php if (isset($this->options['working_days_times']['day_0'])) echo checked(1, $this->options['working_days_times']['day_0'], false) ?>>
215 <?php _e('Sunday', "spoki") ?>
216 </label>
217 <br/>
218 <br/>
219 <label>
220 <?php _e('Opening Time', "spoki") ?>:
221 <input class="working-field" disabled type="time"
222 name="<?php echo SPOKI_OPTIONS ?>[working_days_times][opening_time]"
223 value="<?php if (isset($this->options['working_days_times']['opening_time']) && trim($this->options['working_days_times']['opening_time']) != '') echo $this->options['working_days_times']['opening_time'] ?>"
224 >
225 </label>
226 <br/>
227 <br/>
228 <label>
229 <?php _e('Closing Time', "spoki") ?>:
230 <input class="working-field" disabled type="time"
231 name="<?php echo SPOKI_OPTIONS ?>[working_days_times][closing_time]"
232 value="<?php if (isset($this->options['working_days_times']['closing_time']) && trim($this->options['working_days_times']['closing_time']) != '') echo $this->options['working_days_times']['closing_time'] ?>"
233 >
234 </label>
235 <script>
236 (function () {
237 function toggleWorkingFields(enable) {
238 Array.from(document.getElementsByClassName('working-field')).forEach(el => enable ? el.removeAttribute('disabled') : el.setAttribute('disabled', true))
239 }
240
241 const workingDaysTimeToggleEl = document.getElementById('working-days-times-toggle');
242 toggleWorkingFields(workingDaysTimeToggleEl.getAttribute('checked'))
243 workingDaysTimeToggleEl.addEventListener('click', e => toggleWorkingFields(e.target.checked));
244 })();
245 </script>
246 </td>
247 </tr>
248 </table>
249 <!-- <script src="--><?php //echo plugins_url() . '/' . SPOKI_PLUGIN_NAME . '/assets/js/prefixes.js' ?><!--"></script>-->
250 <!-- <script>-->
251 <!-- Array.from(document.getElementsByClassName('spoki-phone-prefixes')).forEach(el => el.append(...prefixes.map(p => {-->
252 <!-- var option = document.createElement('option');-->
253 <!-- option.value = p.code;-->
254 <!-- option.text = `${p.code} (${p.name})`;-->
255 <!-- return option;-->
256 <!-- })))-->
257 <!-- </script>-->
258 <br/>
259 <hr/>
260 <h2><?php _e('Spoki keys', "spoki") ?></h2>
261 <p class="description"><?php _e('Enter here the keys we emailed you to send automatic notifications with WooCommerce.', "spoki") ?></p>
262 <table class="form-table">
263 <tr>
264 <th scope="row"><?php _e('Current Spoki Plan', "spoki") ?></th>
265 <td>
266 <p>
267 <?php
268 if ($has_spoki_keys && isset($account_info['plan']['name'])) {
269 echo "<b>" . $account_info['plan']['name'] . "</b> ";
270 if (!$is_pro) {
271 echo "<a href='" . Spoki()->get_pro_plan_link() . "' target='_blank'><button type='button' class='button button-primary bg-spoki' style='border: none;'>" . __('Change plan', "spoki") . "</button></a>";
272 }
273 } else {
274 _e('There is no associated Spoki plan.<br/>If you already have a Spoki account insert your Spoki keys below.', "spoki");
275 }
276 ?>
277 </p>
278 </td>
279 </tr>
280 <tr>
281 <th scope="row"><?php _e('Spoki Delivery URL', "spoki") ?></th>
282 <td>
283 <input type="text" class="regular-text" name="<?php echo SPOKI_OPTIONS ?>[delivery_url]" value="<?php if (isset($this->options['delivery_url']) && trim($this->options['delivery_url']) != '') echo $this->options['delivery_url'] ?>">
284 </td>
285 </tr>
286 <tr>
287 <th scope="row"><?php _e('Spoki Secret', "spoki") ?></th>
288 <td>
289 <input type="text" class="regular-text" name="<?php echo SPOKI_OPTIONS ?>[secret]" value="<?php if (isset($this->options['secret']) && trim($this->options['secret']) != '') echo $this->options['secret'] ?>">
290 <?php if ($has_valid_secret):
291 echo "<p class='text-success'>" . __('Valid keys!', "spoki") . "</p>";
292 else:
293 echo "<p class='text-danger'>" . __('Invalid keys', "spoki") . "</p>";
294 endif; ?>
295 </td>
296 </tr>
297 </table>
298 <br/>
299 <hr/>
300 <h2><?php _e('Plugin settings', "spoki") ?></h2>
301 <table class="form-table">
302 <tr>
303 <th scope="row">
304 <label for="<?php echo SPOKI_OPTIONS ?>[disable_auto_update]">
305 <?php _e('Disable plugin updates', "spoki") ?>
306 </label>
307 </th>
308 <td>
309 <div>
310 <input type="checkbox" id="disable_auto_update"
311 name="<?php echo SPOKI_OPTIONS ?>[disable_auto_update]"
312 value="1" <?php if (isset($this->options['disable_auto_update'])) echo checked(1, $this->options['disable_auto_update'], false) ?>>
313 <label for="disable_auto_update">
314 <?php _e('Disable automatic updates', "spoki") ?>
315 </label>
316 </div>
317 <p class="description">
318 <?php _e("If checked the plugin will not update automatically after a new release.", "spoki") ?>
319 </p>
320 </td>
321 </tr>
322 </table>
323 <br/><br/><br/>
324 <div>
325 <input type="checkbox" id="terms_check" <?php if ($is_current_tab) echo 'required' ?>
326 name="<?php echo SPOKI_OPTIONS ?>[terms_check]"
327 value="1" <?php if (isset($this->options['terms_check'])) echo checked(1, $this->options['terms_check'], false) ?>>
328 <label for="terms_check">
329 <?php _e("I accept", "spoki") ?>
330 <a href="https://api.spoki.com/static/terms_conditions_spoki_flex.pdf" target="_blank"><?php _e('general terms and conditions', "spoki") ?></a>
331 <?php _e("for using the Spoki service and the", "spoki") ?>
332 <a href="https://api.spoki.com/static/privacy.pdf" target="_blank"><?php _e('privacy policy', "spoki") ?></a>.
333 </label>
334 </div>
335
336 <input type="hidden" name="<?php echo SPOKI_OPTIONS ?>[secret_status][code]" value="<?php echo $this->options['secret_status']['code'] ?>">
337 <input type="hidden" name="<?php echo SPOKI_OPTIONS ?>[secret_status][secret]" value="<?php echo $this->options['secret_status']['secret'] ?>">
338 <input type="hidden" name="<?php echo SPOKI_OPTIONS ?>[secret_status][delivery_url]" value="<?php echo $this->options['secret_status']['delivery_url'] ?>">
339 <input type="hidden" name="<?php echo SPOKI_OPTIONS ?>[secret_status][message]" value="<?php echo $this->options['secret_status']['message'] ?>">
340
341 <?php if ($is_current_tab) : ?>
342 <input type="hidden" name="<?php echo SPOKI_OPTIONS ?>[is_settings]" value="1">
343 <input type="hidden" name="<?php echo SPOKI_OPTIONS ?>[account_info][response_json]" value="">
344 <input type="hidden" name="spoki_account_url" value="<?php echo Spoki()->api_account ?>">
345 <input type="hidden" name="spoki_plan_url" value="<?php echo Spoki()->api_plan ?>">
346 <?php
347 endif;
348 submit_button(null, 'primary', 'submit', true, 'settings-btn="1"'); ?>
349 </div>
350