PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / trunk
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent vtrunk
3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / frontend / class-wpsc-frontend.php

class-wpsc-frontend.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent trunk, at includes/frontend/class-wpsc-frontend.php

683 lines 24.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Frontend' ) ) :
7
8 final class WPSC_Frontend {
9
10 /**
11 * Initialize this class
12 */
13 public static function init() {
14
15 // Load scripts.
16 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) );
17
18 // ticket url redirect.
19 add_action( 'init', array( __CLASS__, 'ticket_url_redirect' ) );
20 }
21
22 /**
23 * Ticket url support for old versions
24 *
25 * @return void
26 */
27 public static function ticket_url_redirect() {
28
29 if ( isset( $_REQUEST['ticket_id'] ) && isset( $_REQUEST['auth_code'] ) ) { // phpcs:ignore
30
31 $id = isset( $_REQUEST['ticket_id'] ) ? intval( $_REQUEST['ticket_id'] ) : 0; // phpcs:ignore
32 if ( ! $id ) {
33 return;
34 }
35
36 $ticket = new WPSC_Ticket( $id );
37 if ( ! $ticket->id ) {
38 return;
39 }
40
41 // Validate the submitted auth code against the stored one before
42 // doing anything with the ticket. Never redirect to (and thereby
43 // disclose) the real ticket URL/auth code for an invalid guess.
44 $submitted_auth_code = sanitize_text_field( wp_unslash( $_REQUEST['auth_code'] ) ); // phpcs:ignore
45 if ( ! $ticket->auth_code || ! $submitted_auth_code || ! hash_equals( (string) $ticket->auth_code, $submitted_auth_code ) ) {
46 return;
47 }
48
49 wp_safe_redirect( $ticket->get_url() );
50 exit;
51 }
52 }
53
54 /**
55 * Load JS and CSS scripts
56 *
57 * @return void
58 */
59 public static function load_scripts() {
60
61 // Check load scripts setting to load script on perticular page.
62 if ( ! WPSC_Functions::is_load_scripts_page() ) {
63 return;
64 }
65
66 // jquery.
67 wp_enqueue_script( 'jquery' );
68 wp_enqueue_script( 'jquery-ui-core' );
69
70 // TinyMCE.
71 wp_enqueue_editor();
72
73 // jQuery UI Effects.
74 wp_enqueue_script( 'jquery-effects-core' );
75 wp_enqueue_script( 'jquery-effects-slide' );
76
77 // Sortable.
78 wp_enqueue_script( 'jquery-ui-sortable' );
79
80 // WPSC Framework.
81 wp_enqueue_script( 'wpsc-framework', WPSC_PLUGIN_URL . 'framework/scripts.js', array( 'jquery' ), WPSC_VERSION, true );
82
83 if ( is_rtl() ) {
84 wp_enqueue_style( 'wpsc-framework', WPSC_PLUGIN_URL . 'framework/style-rtl.css', array(), WPSC_VERSION );
85 } else {
86 wp_enqueue_style( 'wpsc-framework', WPSC_PLUGIN_URL . 'framework/style.css', array(), WPSC_VERSION );
87 }
88
89 wp_localize_script( 'wpsc-framework', 'supportcandy', self::get_localization_data() );
90
91 // selectWoo.
92 wp_enqueue_script( 'wpsc-selectWoo', WPSC_PLUGIN_URL . 'asset/js/selectWoo/selectWoo.full.min.js', array( 'jquery' ), WPSC_VERSION, true );
93 if ( file_exists( WPSC_ABSPATH . 'asset/js/selectWoo/i18n/' . get_locale() . '.js' ) ) {
94 wp_enqueue_script( 'selectWoo-lang', WPSC_PLUGIN_URL . 'asset/js/selectWoo/i18n/' . get_locale() . '.js', array( 'jquery' ), WPSC_VERSION, true );
95 }
96 wp_enqueue_style( 'wpsc-select2', WPSC_PLUGIN_URL . 'asset/css/select2.css', array(), WPSC_VERSION );
97
98 // gpopover.
99 wp_enqueue_script( 'gpopover', WPSC_PLUGIN_URL . 'asset/libs/gpopover/jquery.gpopover.js', array( 'jquery' ), WPSC_VERSION, true );
100 wp_enqueue_style( 'gpopover', WPSC_PLUGIN_URL . 'asset/libs/gpopover/jquery.gpopover.css', array(), WPSC_VERSION );
101
102 // jquery circle progress.
103 wp_enqueue_script( 'jquery-circle-progress', WPSC_PLUGIN_URL . 'asset/libs/jquery-circle-progress/circle-progress.min.js', array( 'jquery' ), WPSC_VERSION, true );
104
105 // flatpickr.
106 wp_enqueue_script( 'flatpickr-js', WPSC_PLUGIN_URL . 'asset/libs/flatpickr/flatpickr.js', array( 'jquery' ), WPSC_VERSION, true );
107 wp_enqueue_style( 'flatpickr-css', WPSC_PLUGIN_URL . 'asset/libs/flatpickr/flatpickr.min.css', array(), WPSC_VERSION );
108
109 if ( file_exists( WPSC_ABSPATH . 'asset/libs/flatpickr/l10n/' . WPSC_Functions::get_locale_iso() . '.js' ) ) {
110 wp_enqueue_script( 'flatpickr-lang', WPSC_PLUGIN_URL . 'asset/libs/flatpickr/l10n/' . WPSC_Functions::get_locale_iso() . '.js', array( 'jquery' ), WPSC_VERSION, true );
111 }
112
113 // fullcalendar.
114 wp_enqueue_script( 'fullcalendar', WPSC_PLUGIN_URL . 'asset/libs/fullcalendar/lib/main.min.js', array( 'jquery' ), WPSC_VERSION, true );
115 wp_enqueue_script( 'fullcalendar-locales', WPSC_PLUGIN_URL . 'asset/libs/fullcalendar/lib/locales-all.min.js', array( 'jquery' ), WPSC_VERSION, true );
116 wp_enqueue_style( 'fullcalendar', WPSC_PLUGIN_URL . 'asset/libs/fullcalendar/lib/main.min.css', array(), WPSC_VERSION );
117
118 // DataTables.
119 wp_enqueue_script( 'datatables', WPSC_PLUGIN_URL . 'asset/libs/DataTables/datatables.min.js', array( 'jquery' ), WPSC_VERSION, true );
120 wp_enqueue_style( 'datatables', WPSC_PLUGIN_URL . 'asset/libs/DataTables/datatables.min.css', array(), WPSC_VERSION );
121
122 // ChartJs.
123 wp_enqueue_script( 'chartjs', WPSC_PLUGIN_URL . 'asset/libs/chartjs/dist/chart.min.js', array( 'jquery' ), WPSC_VERSION, true );
124 }
125
126 /**
127 * Get localization data for the admin scripts
128 *
129 * @return array
130 */
131 private static function get_localization_data() {
132
133 $gs = get_option( 'wpsc-gs-general' );
134 $page_settings = get_option( 'wpsc-gs-page-settings' );
135 $file_settings = get_option( 'wpsc-gs-file-attachments' );
136
137 $localizations = array(
138 'ajax_url' => admin_url( 'admin-ajax.php' ),
139 'urls' => array(
140 'support' => $page_settings['support-page'] ? get_permalink( $page_settings['support-page'] ) : '',
141 'open_ticket' => $page_settings['open-ticket-page'] ? get_permalink( $page_settings['open-ticket-page'] ) : '',
142 ),
143 'plugin_url' => WPSC_PLUGIN_URL,
144 'version' => WPSC_VERSION,
145 'loader_html' => WPSC_Framework::loader_html(),
146 'inline_loader' => WPSC_Framework::inline_loader(),
147 'is_frontend' => 1,
148 'is_reload' => 1,
149 'reply_form_position' => $gs['reply-form-position'],
150 'allowed_file_extensions' => array_map( 'trim', array_map( 'strtolower', explode( ',', $file_settings['allowed-file-extensions'] ) ) ),
151 'nonce' => wp_create_nonce( 'general' ),
152 'translations' => array(
153 'req_fields_error' => esc_attr__( 'Required fields can not be empty!', 'supportcandy' ),
154 'datatables' => array(
155 'emptyTable' => esc_attr__( 'No Records', 'supportcandy' ),
156 'zeroRecords' => esc_attr__( 'No Records', 'supportcandy' ),
157 'info' => sprintf(
158 /* translators: e.g. Showing 1 to 20 of 300 records */
159 esc_attr__( 'Showing %1$s to %2$s of %3$s records', 'supportcandy' ),
160 '_START_',
161 '_END_',
162 '_TOTAL_'
163 ),
164 'infoEmpty' => '',
165 'loadingRecords' => '',
166 'processing' => '',
167 'infoFiltered' => '',
168 'search' => esc_attr__( 'Search:', 'supportcandy' ),
169 'paginate' => array(
170 'first' => esc_attr__( 'First', 'supportcandy' ),
171 'previous' => esc_attr__( 'Previous', 'supportcandy' ),
172 'next' => esc_attr__( 'Next', 'supportcandy' ),
173 'last' => esc_attr__( 'Last', 'supportcandy' ),
174 ),
175 ),
176 ),
177 'temp' => array(),
178 'home_url' => home_url(),
179 );
180
181 return apply_filters( 'wpsc_frontend_localizations', $localizations );
182 }
183
184 /**
185 * Authentication screen
186 *
187 * @param boolean $otp_login - otp login option.
188 * @param boolean $additional_links - additional links.
189 * @return void
190 */
191 public static function load_authentication_screen( $otp_login = true, $additional_links = true ) {
192
193 $gs = get_option( 'wpsc-gs-general' );
194 $page_settings = get_option( 'wpsc-gs-page-settings' );
195 $recaptcha = get_option( 'wpsc-recaptcha-settings' );
196 $tc = get_option( 'wpsc-term-and-conditions' );
197 $gdpr = get_option( 'wpsc-gdpr-settings' );
198 ?>
199 <div class="wpsc-auth-container">
200 <div class="auth-inner-container">
201 <h2><?php esc_attr_e( 'Please sign in', 'supportcandy' ); ?></h2>
202 <form onsubmit="return false;" class="wpsc-login wpsc-default-login">
203 <?php
204 if ( $page_settings['user-login'] === 'default' ) {
205 ?>
206
207 <input type="text" name="username" placeholder="<?php esc_attr_e( 'Username / Email address', 'supportcandy' ); ?>" autocomplete="off"/>
208 <input type="password" name="password" placeholder="<?php esc_attr_e( 'Password', 'supportcandy' ); ?>"/>
209 <div class="checkbox-container remember-me">
210 <input id="wpsc-remember-me" type="checkbox" name="remember_me" value="1"/>
211 <label for="wpsc-remember-me"><?php esc_attr_e( 'Remember me', 'supportcandy' ); ?></label>
212 </div>
213 <?php
214
215 // recaptcha.
216 if ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 2 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) :
217 $unique_id = uniqid( 'wpsc_' );
218 ?>
219 <script src="https://www.google.com/recaptcha/api.js?onload=recaptchaCallback&render=explicit" async defer></script> <?php // phpcs:ignore ?>
220 <div id="<?php echo esc_attr( $unique_id ); ?>" style="margin-bottom: 5px;"></div>
221 <script>
222 var recaptchaCallback = function() {
223 var obj = jQuery('#<?php echo esc_attr( $unique_id ); ?>');
224 grecaptcha.render(obj.attr("id"), {
225 "sitekey" : "<?php echo esc_attr( $recaptcha['recaptcha-site-key'] ); ?>",
226 "callback" : function(token) {
227 obj.closest('form').find(".g-recaptcha-response").val(token);
228 }
229 });
230 }
231 </script>
232 <?php
233 endif;
234 if ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 3 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) :
235 ?>
236 <script src="https://www.google.com/recaptcha/api.js?render=<?php echo esc_attr( $recaptcha['recaptcha-site-key'] ); ?>"></script> <?php // phpcs:ignore ?>
237 <?php
238 endif;
239 if ( $recaptcha['captcha-provider'] === 'cloudflare-turnstile' && $recaptcha['cloudflare-site-key'] && $recaptcha['cloudflare-secret-key'] ) :
240 ?>
241 <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script> <?php // phpcs:ignore ?>
242 <div class="wpsc-tff turnstile wpsc-xs-12 wpsc-sm-12 wpsc-md-12 wpsc-lg-12 required wpsc-visible" data-cft="turnstile">
243 <div class="cf-turnstile" data-sitekey="<?php echo esc_attr( $recaptcha['cloudflare-site-key'] ); ?>"></div>
244 </div>
245 <?php
246 endif;
247 ?>
248
249 <button class="wpsc-button normal primary" onclick="wpsc_submit_login_form(this)"><?php esc_attr_e( 'Sign In', 'supportcandy' ); ?></button>
250 <input type="hidden" name="action" value="wpsc_default_login"/>
251 <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_default_login' ) ); ?>"/>
252 <?php
253
254 } else {
255 $host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
256 $uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
257
258 $redirect_url = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http' ) . '://' . $host . $uri;
259 $login_url = $page_settings['user-login'] == 'custom' ? $page_settings['custom-login-url'] : wp_login_url( $redirect_url );
260 ?>
261 <button class="wpsc-button normal primary" onclick="wpsc_custom_login( this, '<?php echo esc_url( $login_url ); ?>' )"><?php esc_attr_e( 'Sign In', 'supportcandy' ); ?></button>
262 <?php
263
264 }
265 ?>
266 </form>
267
268 <div class="auth-links">
269 <?php
270
271 if ( $page_settings['user-login'] === 'default' ) :
272 ?>
273 <a class="wpsc-link wpsc-forgot-password" href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php esc_attr_e( 'Forgot your password?', 'supportcandy' ); ?></a>
274 <?php
275 endif;
276
277 if ( $page_settings['user-registration'] == 'default' ) {
278
279 $registration_url = 'javascript:wpsc_get_default_registration();';
280
281 } elseif ( $page_settings['user-registration'] == 'wp-default' ) {
282
283 $registration_url = wp_registration_url();
284
285 } elseif ( $page_settings['user-registration'] == 'custom' ) {
286
287 $registration_url = $page_settings['custom-registration-url'];
288 }
289 if ( $page_settings['user-registration'] !== 'disable' ) {
290 ?>
291 <a class="wpsc-link wpsc-register" href="<?php echo esc_attr( $registration_url ); ?>"><?php esc_attr_e( 'Register now', 'supportcandy' ); ?></a>
292 <?php
293 }
294 if ( $otp_login && $page_settings['otp-login'] && in_array( 'guest', $gs['allow-create-ticket'] ) ) :
295 ?>
296 <span class="wpsc-link wpsc-otp-signin" onclick="wpsc_get_guest_sign_in();"><?php esc_attr_e( 'Sign-in using one time password', 'supportcandy' ); ?></span>
297 <?php
298 endif;
299
300 if ( $additional_links && in_array( 'guest', $gs['allow-create-ticket'] ) ) :
301 ?>
302 <span class="wpsc-link wpsc-guest-create-ticket" onclick="wpsc_get_guest_ticket_form();"><?php esc_attr_e( 'Create new ticket as guest', 'supportcandy' ); ?></span>
303 <?php
304 endif;
305
306 if ( $additional_links && $page_settings['open-ticket-page'] ) :
307 ?>
308 <a class="wpsc-link wpsc-otp-open-ticket" href="<?php echo esc_url( get_permalink( $page_settings['open-ticket-page'] ) ); ?>"><?php esc_attr_e( 'Open existing ticket using one time password', 'supportcandy' ); ?></a>
309 <?php
310 endif;
311 ?>
312 </div>
313 </div>
314 <script>
315 /**
316 * Submit default login form
317 */
318 function wpsc_submit_login_form(el) {
319
320 var dataform = new FormData(jQuery(el).closest('form')[0]);
321 var username = dataform.get('username').trim();
322 var password = dataform.get('password').trim();
323 if (!username || !password) {
324 alert(supportcandy.translations.req_fields_missing);
325 return;
326 }
327 <?php
328 if ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 3 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) {
329 ?>
330 grecaptcha.ready(function() {
331 grecaptcha.execute('<?php echo esc_attr( $recaptcha['recaptcha-site-key'] ); ?>', {action: 'submit_login'}).then(function(token) {
332 dataform.append('g-recaptcha-response', token);
333 wpsc_post_login_form(el, dataform);
334 });
335 });
336 <?php
337 } elseif ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 2 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) {
338 ?>
339 var token = dataform.get('g-recaptcha-response');
340 if (!token) {
341 alert("<?php esc_attr_e( 'Security verification failed. Please refresh the page and try again.', 'supportcandy' ); ?>");
342 return;
343 }
344 wpsc_post_login_form(el, dataform);
345 <?php
346 } else {
347 ?>
348
349 wpsc_post_login_form(el, dataform);
350 <?php
351 }
352 ?>
353 }
354
355 /**
356 * Submit login form
357 */
358 function wpsc_post_login_form(el, dataform) {
359
360 jQuery(el).text(supportcandy.translations.please_wait);
361 jQuery.ajax({
362 url: supportcandy.ajax_url,
363 type: 'POST',
364 data: dataform,
365 processData: false,
366 contentType: false
367 }).done(function (response) {
368 if (response.success) {
369 window.location.reload();
370 return;
371 }
372
373 if (response.data) {
374 if (typeof response.data === 'string') {
375 message = response.data;
376 } else if (response.data.message) {
377 message = response.data.message;
378 }
379 }
380 alert(message);
381 }).fail(function (xhr, status, error) {
382 let message = supportcandy.translations.something_wrong;
383
384 // Handle WP JSON errors (401, 403, 400)
385 if (xhr.responseJSON && xhr.responseJSON.data) {
386 if (typeof xhr.responseJSON.data === 'string') {
387 message = xhr.responseJSON.data;
388 } else if (xhr.responseJSON.data.message) {
389 message = xhr.responseJSON.data.message;
390 }
391 }
392
393 alert(message);
394 }).always(function () {
395 window.location.reload();
396 });
397 }
398
399 /**
400 * Custom login
401 */
402 function wpsc_custom_login(el, url) {
403
404 jQuery(el).text(supportcandy.translations.please_wait);
405 window.location.href = url;
406 }
407
408 /**
409 * Get default registration page
410 */
411 function wpsc_get_default_registration() {
412
413 jQuery('.auth-inner-container').html(supportcandy.loader_html);
414 var data = { action: 'wpsc_get_default_registration' };
415 jQuery.post(supportcandy.ajax_url, data, function (response) {
416 jQuery('.auth-inner-container').html(response);
417 });
418 }
419
420 /**
421 * Set default registration form
422 */
423 function wpsc_set_default_registration(el) {
424
425 var dataform = new FormData(jQuery(el).closest('form')[0]);
426 var firstname = dataform.get('firstname').trim();
427 var lastname = dataform.get('lastname').trim();
428 var username = dataform.get('username').trim();
429 var email_address = dataform.get('email_address').trim();
430 var password = dataform.get('password').trim();
431 var confirm_password = dataform.get('confirm_password').trim();
432 var isUsername = dataform.get('is_username').trim();
433 var isEmail = dataform.get('is_email').trim();
434
435 <?php
436 if ( $tc['allow-term-and-conditions-reg-user'] ) {
437 ?>
438 var tandcCheckbox = dataform.get('wpsc-tandc-reg-user');
439 if ( ! tandcCheckbox ){
440 alert(supportcandy.translations.req_term_cond);
441 return;
442 }
443 <?php
444 }
445 if ( $gdpr['allow-gdpr-reg-user'] ) {
446 ?>
447 var gdprCheckbox = dataform.get('wpsc-gdpr-reg-user');
448 if ( gdprCheckbox != 1 ){
449 alert(supportcandy.translations.req_gdpr);
450 return;
451 }
452 <?php
453 }
454 ?>
455
456 if (!firstname || !lastname || !username || !email_address || !password || !confirm_password) {
457 alert(supportcandy.translations.req_fields_missing);
458 return;
459 }
460
461 if (!validateEmail(email_address)) {
462 alert(supportcandy.translations.incorrect_email);
463 return;
464 }
465
466 if (isUsername != 1) {
467 alert(supportcandy.translations.unsername_unavailable);
468 return;
469 }
470
471 if (isEmail != 1) {
472 alert(supportcandy.translations.email_unavailable);
473 return;
474 }
475
476 if (password !== confirm_password) {
477 alert(supportcandy.translations.incorrect_password);
478 return;
479 }
480
481 <?php
482 if ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 3 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) {
483 ?>
484 grecaptcha.ready(function() {
485 grecaptcha.execute('<?php echo esc_attr( $recaptcha['recaptcha-site-key'] ); ?>', {action: 'submit_registration'}).then(function(token) {
486 dataform.append('g-recaptcha-response', token);
487 wpsc_authenticate_registration(el, dataform);
488 });
489 });
490 <?php
491 } elseif ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 2 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) {
492 ?>
493 var token = dataform.get('g-recaptcha-response');
494 if (!token) {
495 alert("<?php esc_attr_e( 'Captcha not set!', 'supportcandy' ); ?>");
496 return;
497 }
498 wpsc_authenticate_registration(el, dataform);
499 <?php
500 } elseif ( $recaptcha['captcha-provider'] === 'cloudflare-turnstile' && $recaptcha['cloudflare-site-key'] && $recaptcha['cloudflare-secret-key'] ) {
501 ?>
502 var token = dataform.get('cf-turnstile-response');
503 if (!token) {
504 alert("<?php esc_attr_e( 'Security verification failed. Please refresh the page and try again.', 'supportcandy' ); ?>");
505 return;
506 }
507
508 dataform.set(
509 'cf-turnstile-response',
510 token
511 );
512 wpsc_authenticate_registration(el, dataform);
513 <?php
514
515 } else {
516 ?>
517
518 wpsc_authenticate_registration(el, dataform);
519 <?php
520 }
521 ?>
522 }
523
524 /**
525 * Post registration form
526 */
527 function wpsc_authenticate_registration(el, dataform) {
528
529 jQuery('.auth-inner-container').html(supportcandy.loader_html);
530 jQuery.ajax({
531 url: supportcandy.ajax_url,
532 type: 'POST',
533 data: dataform,
534 processData: false,
535 contentType: false
536 }).done(function (res) {
537 if (typeof(res) == "object") {
538 alert(supportcandy.translations.something_wrong);
539 wpsc_get_default_registration();
540 } else {
541 jQuery('.auth-inner-container').html(res);
542 }
543 }).fail(function (res) {
544 alert(supportcandy.translations.something_wrong);
545 window.location.reload();
546 });
547 }
548
549 /**
550 * Register user
551 */
552 function wpsc_confirm_registration(el) {
553
554 jQuery('.auth-inner-container').html(supportcandy.loader_html);
555 var dataform = new FormData(jQuery(el).closest('form')[0]);
556 jQuery.ajax({
557 url: supportcandy.ajax_url,
558 type: 'POST',
559 data: dataform,
560 processData: false,
561 contentType: false
562 }).done(function (res) {
563 if (res.isSuccess == 1) {
564 window.location.reload();
565 } else {
566 alert(supportcandy.translations.something_wrong);
567 wpsc_get_default_registration();
568 }
569 });
570 }
571
572 /**
573 * Get guest otp login screen
574 *
575 * @return void
576 */
577 function wpsc_get_guest_sign_in() {
578
579 jQuery('.auth-inner-container').html(supportcandy.loader_html);
580 var data = { action: 'wpsc_get_guest_sign_in' };
581 jQuery.post(supportcandy.ajax_url, data, function (res) {
582 if (typeof(res) == "object") {
583 alert(supportcandy.translations.something_wrong);
584 window.location.reload();
585 } else {
586 jQuery('.auth-inner-container').html(res);
587 }
588 });
589 }
590
591 /**
592 * Send login OTP
593 *
594 * @return void
595 */
596 function wpsc_authenticate_guest_login(el) {
597
598 var dataform = new FormData(jQuery(el).closest('form')[0]);
599
600 var email_address = dataform.get('email_address').trim();
601 if ( ! email_address ) {
602 alert(supportcandy.translations.req_fields_missing);
603 return;
604 }
605
606 if (!validateEmail(email_address)) {
607 alert(supportcandy.translations.incorrect_email);
608 return;
609 }
610
611 jQuery(el).text(supportcandy.translations.please_wait);
612 jQuery.ajax({
613 url: supportcandy.ajax_url,
614 type: 'POST',
615 data: dataform,
616 processData: false,
617 contentType: false
618 }).done(function (res) {
619 if (typeof(res) == "object") {
620 alert(supportcandy.translations.something_wrong);
621 wpsc_get_guest_sign_in();
622 } else {
623 jQuery('.auth-inner-container').html(res);
624 }
625 }).fail(function (res) {
626 alert(supportcandy.translations.something_wrong);
627 window.location.reload();
628 });
629 }
630
631 /**
632 * Confirm guest login auth
633 *
634 * @return void
635 */
636 function wpsc_confirm_guest_login(el) {
637
638 jQuery('.auth-inner-container').html(supportcandy.loader_html);
639 var dataform = new FormData(jQuery(el).closest('form')[0]);
640 jQuery.ajax({
641 url: supportcandy.ajax_url,
642 type: 'POST',
643 data: dataform,
644 processData: false,
645 contentType: false
646 }).done(function (res) {
647 if (res.isSuccess == 1) {
648 window.location.reload();
649 } else {
650 alert(supportcandy.translations.something_wrong);
651 wpsc_get_guest_sign_in();
652 }
653 });
654 }
655 </script>
656 </div>
657 <?php
658 }
659
660 /**
661 * Load HTML snippets that can be used by js to load dynamically
662 *
663 * @return void
664 */
665 public static function load_html_snippets() {
666 ?>
667
668 <div class="wpsc-page-snippets" style="display: none;">
669 <div class="wpsc-editor-attachment upload-waiting">
670 <div class="attachment-label"></div>
671 <div class="attachment-remove" onclick="wpsc_remove_attachment(this)">
672 <?php WPSC_Icons::get( 'times' ); ?>
673 </div>
674 <div class="attachment-waiting"></div>
675 </div>
676 </div>
677 <?php
678 }
679 }
680 endif;
681
682 WPSC_Frontend::init();
683