245 lines
9.2 KiB
PHP
245 lines
9.2 KiB
PHP
<?php
|
||
/**
|
||
* کمککنندههای صفحهٔ مجتمع پورتال مشتریان
|
||
*
|
||
* @package Hesabix2
|
||
*/
|
||
|
||
if ( ! defined( 'ABSPATH' ) ) {
|
||
exit;
|
||
}
|
||
|
||
/**
|
||
* آدرس صفحهٔ مجتمع احراز هویت.
|
||
*
|
||
* @param string $action login|register|forgot.
|
||
* @param string $redirect_to بازگشت پس از ورود.
|
||
* @return string
|
||
*/
|
||
function hesabix2_portal_auth_url( $action = 'login', $redirect_to = '' ) {
|
||
if ( function_exists( 'hpauth_portal_url' ) ) {
|
||
return hpauth_portal_url( $action, $redirect_to );
|
||
}
|
||
$pages = get_pages(
|
||
array(
|
||
'meta_key' => '_wp_page_template',
|
||
'meta_value' => 'page-portal-auth.php',
|
||
'number' => 1,
|
||
)
|
||
);
|
||
if ( empty( $pages ) ) {
|
||
return wp_login_url( $redirect_to );
|
||
}
|
||
$url = get_permalink( $pages[0]->ID );
|
||
$url = add_query_arg( 'hpauth', $action, $url );
|
||
if ( $redirect_to ) {
|
||
$url = add_query_arg( 'redirect_to', rawurlencode( esc_url_raw( $redirect_to ) ), $url );
|
||
}
|
||
return $url;
|
||
}
|
||
|
||
/**
|
||
* جایگزین hesabix2_auth_page_url — همیشه پورتال مجتمع.
|
||
*
|
||
* @param string $template_slug نادیده (سازگاری).
|
||
* @param string $redirect_after بازگشت.
|
||
* @return string
|
||
*/
|
||
/**
|
||
* آدرس بازگشت به سایت (همان redirect_to امن، یا صفحهٔ اصلی).
|
||
*
|
||
* @param string $redirect_to مقصد امن از query.
|
||
* @return string
|
||
*/
|
||
function hesabix2_portal_auth_back_url( $redirect_to = '' ) {
|
||
$home = home_url( '/' );
|
||
$target = $redirect_to ? $redirect_to : $home;
|
||
|
||
$portal_pages = get_pages(
|
||
array(
|
||
'meta_key' => '_wp_page_template',
|
||
'meta_value' => 'page-portal-auth.php',
|
||
'number' => 1,
|
||
)
|
||
);
|
||
if ( ! empty( $portal_pages ) ) {
|
||
$portal_permalink = untrailingslashit( get_permalink( $portal_pages[0]->ID ) );
|
||
if ( untrailingslashit( $target ) === $portal_permalink ) {
|
||
return $home;
|
||
}
|
||
}
|
||
|
||
return apply_filters( 'hesabix2_portal_auth_back_url', $target, $redirect_to );
|
||
}
|
||
|
||
/**
|
||
* آدرس صفحهٔ شرایط استفاده / قوانین.
|
||
*
|
||
* @return string
|
||
*/
|
||
function hesabix2_portal_auth_terms_url() {
|
||
$filtered = apply_filters( 'hesabix2_portal_auth_terms_url', '' );
|
||
if ( is_string( $filtered ) && '' !== $filtered ) {
|
||
return esc_url( $filtered );
|
||
}
|
||
|
||
if ( function_exists( 'wc_terms_and_conditions_page_id' ) ) {
|
||
$page_id = wc_terms_and_conditions_page_id();
|
||
if ( $page_id ) {
|
||
return get_permalink( $page_id );
|
||
}
|
||
}
|
||
|
||
foreach ( array( 'terms', 'terms-of-use', 'privacy-policy', 'privacy' ) as $slug ) {
|
||
$page = get_page_by_path( $slug );
|
||
if ( $page instanceof WP_Post ) {
|
||
return get_permalink( $page );
|
||
}
|
||
}
|
||
|
||
return home_url( '/' );
|
||
}
|
||
|
||
/**
|
||
* برچسب لینک بازگشت بر اساس مقصد.
|
||
*
|
||
* @param string $back_url آدرس بازگشت.
|
||
* @return string
|
||
*/
|
||
function hesabix2_portal_auth_back_label( $back_url ) {
|
||
$home = untrailingslashit( home_url( '/' ) );
|
||
if ( untrailingslashit( $back_url ) === $home ) {
|
||
return __( 'بازگشت به صفحهٔ اصلی', 'hesabix2' );
|
||
}
|
||
return __( 'بازگشت به سایت', 'hesabix2' );
|
||
}
|
||
|
||
/**
|
||
* آیکون SVG فلش بازگشت (RTL).
|
||
*/
|
||
function hesabix2_portal_auth_icon_back() {
|
||
echo '<svg class="hpauth-icon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M14 5l7 7m0 0l-7 7m7-7H3"/></svg>';
|
||
}
|
||
|
||
function hesabix2_portal_auth_page_url( $template_slug = '', $redirect_after = '' ) {
|
||
$action = 'login';
|
||
if ( 'page-register.php' === $template_slug ) {
|
||
$action = 'register';
|
||
} elseif ( 'page-lostpassword.php' === $template_slug ) {
|
||
$action = 'forgot';
|
||
}
|
||
return hesabix2_portal_auth_url( $action, $redirect_after );
|
||
}
|
||
|
||
/**
|
||
* فیلدهای کپچا مشترک در فرمهای پورتال.
|
||
*
|
||
* @param string $prefix پیشوند یکتا برای چند کپچا در یک صفحه.
|
||
*/
|
||
/**
|
||
* فیلد رمز عبور با دکمهٔ نمایش/مخفی.
|
||
*
|
||
* @param string $id شناسه input.
|
||
* @param string $name نام فیلد.
|
||
* @param array $attrs ویژگیهای اضافی HTML.
|
||
* @param bool $required الزامی بودن.
|
||
*/
|
||
function hesabix2_portal_auth_password_field( $id, $name, $attrs = array(), $required = true ) {
|
||
$defaults = array(
|
||
'autocomplete' => 'current-password',
|
||
'minlength' => '8',
|
||
'placeholder' => '••••••••',
|
||
);
|
||
$attrs = array_merge( $defaults, $attrs );
|
||
$attr_html = '';
|
||
foreach ( $attrs as $key => $val ) {
|
||
if ( null === $val || false === $val ) {
|
||
continue;
|
||
}
|
||
$attr_html .= sprintf( ' %s="%s"', esc_attr( $key ), esc_attr( (string) $val ) );
|
||
}
|
||
$req = $required ? ' required' : '';
|
||
?>
|
||
<div class="hpauth-input-wrap hpauth-input-wrap--password">
|
||
<input type="password" class="hpauth-input" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>"<?php echo $attr_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above. ?><?php echo $req; ?> />
|
||
<button type="button" class="hpauth-input-toggle" data-password-toggle aria-label="<?php esc_attr_e( 'نمایش رمز عبور', 'hesabix2' ); ?>" aria-pressed="false">
|
||
<svg class="hpauth-input-toggle__show" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
||
<svg class="hpauth-input-toggle__hide" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>
|
||
</button>
|
||
</div>
|
||
<?php
|
||
}
|
||
|
||
/**
|
||
* دکمهٔ ارسال با اسپینر loading.
|
||
*
|
||
* @param string $text متن دکمه.
|
||
* @param string $extra_classes کلاسهای اضافی.
|
||
* @param string $type نوع دکمه: submit|button.
|
||
* @param array $attrs data-* و سایر attributeها.
|
||
*/
|
||
function hesabix2_portal_auth_submit_button( $text, $extra_classes = '', $type = 'submit', $attrs = array() ) {
|
||
$classes = trim( 'hpauth-submit ' . $extra_classes );
|
||
$attr_html = '';
|
||
foreach ( $attrs as $key => $val ) {
|
||
if ( null === $val || false === $val ) {
|
||
continue;
|
||
}
|
||
$attr_html .= sprintf( ' %s="%s"', esc_attr( $key ), esc_attr( (string) $val ) );
|
||
}
|
||
?>
|
||
<button type="<?php echo esc_attr( $type ); ?>" class="<?php echo esc_attr( $classes ); ?>"<?php echo $attr_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above. ?>>
|
||
<span class="hpauth-submit__spinner" aria-hidden="true"></span>
|
||
<span class="hpauth-submit__text"><?php echo esc_html( $text ); ?></span>
|
||
</button>
|
||
<?php
|
||
}
|
||
|
||
/**
|
||
* فیلد شناسهٔ ورود (موبایل یا ایمیل).
|
||
*
|
||
* @param string $id شناسه input.
|
||
* @param string $name نام فیلد (پیشفرض identifier).
|
||
* @param bool $required الزامی.
|
||
*/
|
||
function hesabix2_portal_auth_identifier_field( $id, $name = 'identifier', $required = true ) {
|
||
$email_on = class_exists( 'Hpauth_Identifier' ) && Hpauth_Identifier::email_login_allowed();
|
||
$label = $email_on
|
||
? __( 'موبایل یا ایمیل', 'hesabix2' )
|
||
: __( 'شماره موبایل', 'hesabix2' );
|
||
$placeholder = $email_on ? '09123456789 یا name@example.com' : '09123456789';
|
||
$req = $required ? ' required' : '';
|
||
?>
|
||
<div class="hpauth-field" data-identifier-field>
|
||
<label class="hpauth-label" for="<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $label ); ?></label>
|
||
<input
|
||
type="text"
|
||
class="hpauth-input"
|
||
id="<?php echo esc_attr( $id ); ?>"
|
||
name="<?php echo esc_attr( $name ); ?>"
|
||
autocomplete="username"
|
||
placeholder="<?php echo esc_attr( $placeholder ); ?>"
|
||
dir="ltr"
|
||
data-identifier-input
|
||
<?php echo $email_on ? 'data-email-login="1"' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
<?php echo $req; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
/>
|
||
</div>
|
||
<?php
|
||
}
|
||
|
||
function hesabix2_portal_auth_captcha_fields( $prefix ) {
|
||
?>
|
||
<div class="hpauth-captcha" data-captcha-wrap data-captcha-prefix="<?php echo esc_attr( $prefix ); ?>">
|
||
<label class="hpauth-label"><?php esc_html_e( 'کد امنیتی', 'hesabix2' ); ?></label>
|
||
<div class="hpauth-captcha__row">
|
||
<img class="hpauth-captcha__img" alt="<?php esc_attr_e( 'کد امنیتی', 'hesabix2' ); ?>" data-captcha-img width="140" height="48" />
|
||
<button type="button" class="hpauth-captcha__refresh" data-captcha-refresh aria-label="<?php esc_attr_e( 'تصویر جدید', 'hesabix2' ); ?>">
|
||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M23 4v6h-6M1 20v-6h6"/><path d="M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"/></svg>
|
||
</button>
|
||
</div>
|
||
<input type="text" class="hpauth-input hpauth-captcha__code" name="captcha_code" autocomplete="off" maxlength="8" required dir="ltr" data-captcha-code placeholder="<?php esc_attr_e( 'اعداد تصویر', 'hesabix2' ); ?>" />
|
||
<input type="hidden" name="captcha_id" data-captcha-id value="" />
|
||
</div>
|
||
<?php
|
||
}
|