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