436 lines
21 KiB
PHP
436 lines
21 KiB
PHP
<?php
|
||
/**
|
||
* دیالوگ ورود آرک / شادمان + حمایت اختیاری (سراسر سایت)
|
||
*
|
||
* @package Hesabix2
|
||
*/
|
||
|
||
if (!defined('ABSPATH')) {
|
||
exit;
|
||
}
|
||
|
||
/**
|
||
* سطوح gamification نوار حمایت
|
||
*
|
||
* @return array<int, array<string, mixed>>
|
||
*/
|
||
function hesabix2_entry_dialog_tiers() {
|
||
$tiers = array(
|
||
array(
|
||
'min' => 10000,
|
||
'slug' => 'cigarette-sultan',
|
||
'emoji' => '🚬',
|
||
'sticker' => '😂',
|
||
'title' => __('یه نخ سیگار برای جناب سلطانی', 'hesabix2'),
|
||
'impact' => __('استیکر خنده هم همراهش — لطف کوچک، دلگرمی بزرگ', 'hesabix2'),
|
||
'theme' => 'tier-cigarette',
|
||
'tagline' => __('حداقل حمایت — با حس شوخی و مهربونی', 'hesabix2'),
|
||
),
|
||
array(
|
||
'min' => 25000,
|
||
'emoji' => '🍫',
|
||
'sticker' => '💝',
|
||
'title' => __('شکلات برای یکی از اعضای تیم', 'hesabix2'),
|
||
'impact' => __('وقتی دیباگ سنگینه، شیرینی کمک میکنه', 'hesabix2'),
|
||
'theme' => 'tier-chocolate',
|
||
),
|
||
array(
|
||
'min' => 40000,
|
||
'emoji' => '🍪',
|
||
'sticker' => '🌙',
|
||
'title' => __('بیسکویت شبکاری', 'hesabix2'),
|
||
'impact' => __('برای کسی که شبا درگیر مانیتورینگه', 'hesabix2'),
|
||
'theme' => 'tier-cookie',
|
||
),
|
||
array(
|
||
'min' => 50000,
|
||
'emoji' => '☕',
|
||
'sticker' => '⚡',
|
||
'title' => __('یک قهوه دمی', 'hesabix2'),
|
||
'impact' => __('انرژی برای یک باگ و یک فیچر دیگر', 'hesabix2'),
|
||
'theme' => 'tier-coffee',
|
||
'tagline' => __('همون قیمت یه قهوه واقعی', 'hesabix2'),
|
||
),
|
||
array(
|
||
'min' => 80000,
|
||
'emoji' => '🧃',
|
||
'sticker' => '🎉',
|
||
'title' => __('نوشابه بعد از دیپلوی', 'hesabix2'),
|
||
'impact' => __('جشن ریلیز بدون نوشابه کامل نمیشه', 'hesabix2'),
|
||
'theme' => 'tier-drink',
|
||
),
|
||
array(
|
||
'min' => 120000,
|
||
'emoji' => '🥐',
|
||
'sticker' => '☀️',
|
||
'title' => __('صبحانه تیم', 'hesabix2'),
|
||
'impact' => __('یک صبح کاری گرمتر برای رفع باگها', 'hesabix2'),
|
||
'theme' => 'tier-breakfast',
|
||
),
|
||
array(
|
||
'min' => 200000,
|
||
'emoji' => '🍕',
|
||
'sticker' => '🔥',
|
||
'title' => __('ناهار پیتزایی', 'hesabix2'),
|
||
'impact' => __('ناهار جمعی = چند ساعت تمرکز بیشتر', 'hesabix2'),
|
||
'theme' => 'tier-lunch',
|
||
),
|
||
array(
|
||
'min' => 350000,
|
||
'emoji' => '🎮',
|
||
'sticker' => '🎯',
|
||
'title' => __('یک راند بازی برای استراحت', 'hesabix2'),
|
||
'impact' => __('ریست ذهن تیم بعد از اسپرینت سنگین', 'hesabix2'),
|
||
'theme' => 'tier-game',
|
||
),
|
||
array(
|
||
'min' => 500000,
|
||
'emoji' => '☁️',
|
||
'sticker' => '💪',
|
||
'title' => __('شارژ سرور', 'hesabix2'),
|
||
'impact' => __('کمک به پایداری سرویس برای هزاران کسبوکار', 'hesabix2'),
|
||
'theme' => 'tier-cloud',
|
||
),
|
||
array(
|
||
'min' => 1000000,
|
||
'emoji' => '🥉',
|
||
'sticker' => '✨',
|
||
'title' => __('حامی برنزی', 'hesabix2'),
|
||
'impact' => __('نام شما (با اجازه) در دیوار حامیان', 'hesabix2'),
|
||
'theme' => 'tier-bronze',
|
||
),
|
||
array(
|
||
'min' => 2500000,
|
||
'emoji' => '🥈',
|
||
'sticker' => '🌟',
|
||
'title' => __('حامی نقرهای', 'hesabix2'),
|
||
'impact' => __('جایگاه ویژه در لیست حامیان جامعه', 'hesabix2'),
|
||
'theme' => 'tier-silver',
|
||
),
|
||
array(
|
||
'min' => 4000000,
|
||
'slug' => 'vip-lunch',
|
||
'emoji' => '🍽️',
|
||
'sticker' => '⭐',
|
||
'title' => __('مهمان ویژه — ناهار با تیم حسابیکس', 'hesabix2'),
|
||
'impact' => __('یک ناهار صمیمی با اعضای تیم؛ گپ، تجربهٔ محصول و قدردانی حضوری (با هماهنگی)', 'hesabix2'),
|
||
'theme' => 'tier-vip-lunch',
|
||
'tagline' => __('بالای ۴ میلیون — شما مهمان ویژهٔ تیم هستید', 'hesabix2'),
|
||
),
|
||
array(
|
||
'min' => 5000000,
|
||
'emoji' => '🥇',
|
||
'sticker' => '👑',
|
||
'title' => __('قهرمان حسابیکس', 'hesabix2'),
|
||
'impact' => __('حمایت جدی برای نقشه راه و زیرساخت', 'hesabix2'),
|
||
'theme' => 'tier-gold',
|
||
),
|
||
array(
|
||
'min' => 10000000,
|
||
'emoji' => '🚀',
|
||
'sticker' => '💫',
|
||
'title' => __('اسپانسر ستاره', 'hesabix2'),
|
||
'impact' => __('همسطح شرکای صفحه حامیان — برای همکاری تماس بگیرید', 'hesabix2'),
|
||
'theme' => 'tier-star',
|
||
),
|
||
array(
|
||
'min' => 50000000,
|
||
'slug' => 'wrestling',
|
||
'emoji' => '🤼',
|
||
'sticker' => '😂',
|
||
'title' => __('مسابقه کشتی با جناب سلطانی', 'hesabix2'),
|
||
'impact' => __('در آوردگاه کشتی ایران — کرمانشاه؛ یک تجربهٔ افسانهای برای حامیان فوقالعاده (با هماهنگی و شوخی)', 'hesabix2'),
|
||
'theme' => 'tier-wrestling',
|
||
'tagline' => __('بالای ۵۰ میلیون — رینگ کرمانشاه منتظره!', 'hesabix2'),
|
||
),
|
||
);
|
||
|
||
$tiers = apply_filters('hesabix2_entry_dialog_tiers', $tiers);
|
||
|
||
usort(
|
||
$tiers,
|
||
static function ($a, $b) {
|
||
return ((int) ($a['min'] ?? 0)) <=> ((int) ($b['min'] ?? 0));
|
||
}
|
||
);
|
||
|
||
return $tiers;
|
||
}
|
||
|
||
/**
|
||
* آدرس صفحه حامیان
|
||
*/
|
||
function hesabix2_entry_dialog_sponsors_url() {
|
||
if (function_exists('hesabix2_sponsors_page_url')) {
|
||
return hesabix2_sponsors_page_url();
|
||
}
|
||
return home_url('/sponsors/');
|
||
}
|
||
|
||
/**
|
||
* حداقل / حداکثر مبلغ دیالوگ
|
||
*
|
||
* @return array{min: int, max: int}
|
||
*/
|
||
function hesabix2_entry_dialog_amount_limits() {
|
||
$min = 10000;
|
||
$max = 100000000;
|
||
|
||
if (class_exists('Hesabix_Donations_Settings')) {
|
||
$plugin_min = (int) Hesabix_Donations_Settings::get('min_amount_toman', 1000);
|
||
$plugin_max = (int) Hesabix_Donations_Settings::get('max_amount_toman', 200000000);
|
||
$min = max($min, $plugin_min);
|
||
$max = min($max, $plugin_max);
|
||
}
|
||
|
||
return apply_filters(
|
||
'hesabix2_entry_dialog_amount_limits',
|
||
array(
|
||
'min' => $min,
|
||
'max' => $max,
|
||
)
|
||
);
|
||
}
|
||
|
||
/**
|
||
* آیا دیالوگ فعال است؟
|
||
*/
|
||
function hesabix2_entry_dialog_enabled() {
|
||
return (bool) apply_filters('hesabix2_entry_dialog_enabled', true);
|
||
}
|
||
|
||
/**
|
||
* صفحاتی که دیالوگ ورود روی آنها فعال است (فرانتاند عمومی — برای CTAهای هدر/فوتر و محتوا)
|
||
*/
|
||
function hesabix2_entry_dialog_is_active_page() {
|
||
if (is_admin() || wp_doing_ajax() || wp_doing_cron()) {
|
||
return false;
|
||
}
|
||
|
||
return (bool) apply_filters('hesabix2_entry_dialog_is_active_page', true);
|
||
}
|
||
|
||
/**
|
||
* ویژگیهای لینک ورود (جلوگیری از پرش مستقیم)
|
||
*
|
||
* @param string $entry arc|shad
|
||
* @param string $href URL پنل
|
||
* @return string HTML attributes
|
||
*/
|
||
function hesabix2_entry_link_attrs($entry, $href = '') {
|
||
if (!hesabix2_entry_dialog_enabled() || !hesabix2_entry_dialog_is_active_page()) {
|
||
return '';
|
||
}
|
||
|
||
$entry = ('shad' === $entry) ? 'shad' : 'arc';
|
||
$href = $href ? $href : ('shad' === $entry && function_exists('hesabix2_fp_shad_url') ? hesabix2_fp_shad_url() : (function_exists('hesabix2_fp_arc_url') ? hesabix2_fp_arc_url() : ''));
|
||
|
||
return sprintf(
|
||
' data-hesabix-entry="%1$s" data-hesabix-href="%2$s" role="button" tabindex="0" aria-haspopup="dialog"',
|
||
esc_attr($entry),
|
||
esc_attr($href)
|
||
);
|
||
}
|
||
|
||
/**
|
||
* بارگذاری داراییها
|
||
*/
|
||
function hesabix2_entry_dialog_assets() {
|
||
if (!hesabix2_entry_dialog_is_active_page() || !hesabix2_entry_dialog_enabled()) {
|
||
return;
|
||
}
|
||
|
||
$theme_dir = get_template_directory();
|
||
$theme_uri = get_template_directory_uri();
|
||
$css = $theme_dir . '/assets/css/support-entry-dialog.css';
|
||
$js = $theme_dir . '/assets/js/support-entry-dialog.js';
|
||
|
||
wp_enqueue_style(
|
||
'hesabix2-entry-dialog',
|
||
$theme_uri . '/assets/css/support-entry-dialog.css',
|
||
array('hesabix2-style'),
|
||
file_exists($css) ? (string) filemtime($css) : '1.0'
|
||
);
|
||
|
||
$limits = hesabix2_entry_dialog_amount_limits();
|
||
$copy = array(
|
||
'arc' => array(
|
||
'title' => __('آرک رایگانه — از ۱۰ هزار تومان هم میتونی به تیم لطف کنی ☕', 'hesabix2'),
|
||
'subtitle' => __('حسابیکس متنبازه و استفادهٔ اصلی آرک برای شما رایگان میمونه. هزینهٔ سرور و توسعه با حمایت جامعه جمع میشه — نه با قفل کردن دادهات.', 'hesabix2'),
|
||
'enter' => __('ورود رایگان به آرک', 'hesabix2'),
|
||
'support' => __('حمایت و ورود به آرک', 'hesabix2'),
|
||
),
|
||
'shad' => array(
|
||
'title' => __('ورود به شادمان — نسخهٔ قدیمی حسابداری', 'hesabix2'),
|
||
'subtitle' => __('تا پایان سال فقط بهروزرسانی امنیتی داره. برای شروع تازه، آرک پیشنهاد میشه؛ ورود شادمان همچنان بازه.', 'hesabix2'),
|
||
'enter' => __('ورود رایگان به شادمان', 'hesabix2'),
|
||
'support' => __('حمایت و ورود به شادمان', 'hesabix2'),
|
||
'hint' => function_exists('hesabix2_fp_migration_notice') ? hesabix2_fp_migration_notice() : '',
|
||
),
|
||
);
|
||
|
||
$stats_line = '';
|
||
if (class_exists('Hesabix_Donations_Repository')) {
|
||
$stats = Hesabix_Donations_Repository::get_stats(false);
|
||
if (!empty($stats['count'])) {
|
||
$stats_line = sprintf(
|
||
/* translators: %s: formatted count */
|
||
__('بیش از %s حمایت مالی از جامعهٔ حسابیکس ثبت شده — ممنون که کنار ما هستید.', 'hesabix2'),
|
||
number_format_i18n((int) $stats['count'])
|
||
);
|
||
}
|
||
}
|
||
|
||
wp_enqueue_script(
|
||
'hesabix2-entry-dialog',
|
||
$theme_uri . '/assets/js/support-entry-dialog.js',
|
||
array(),
|
||
file_exists($js) ? (string) filemtime($js) : '1.0',
|
||
true
|
||
);
|
||
|
||
wp_localize_script(
|
||
'hesabix2-entry-dialog',
|
||
'hesabixEntryDialog',
|
||
array(
|
||
'ajaxUrl' => admin_url('admin-ajax.php'),
|
||
'homeUrl' => home_url('/'),
|
||
'sponsorsUrl' => hesabix2_entry_dialog_sponsors_url(),
|
||
'compareUrl' => function_exists('hesabix2_versions_compare_url') ? hesabix2_versions_compare_url() : home_url('/arc-shadoman/'),
|
||
'nonce' => wp_create_nonce('hesabix_donation_start'),
|
||
'donationsOn' => class_exists('Hesabix_Donations_Payment_Handler'),
|
||
'guarantee' => function_exists('hesabix2_fp_data_guarantee') ? hesabix2_fp_data_guarantee() : '',
|
||
'openSource' => __('متنباز یعنی آزادی استفاده و دسترسی به کد — نه بیهزینه بودن زیرساخت.', 'hesabix2'),
|
||
'statsLine' => $stats_line,
|
||
'dismissDays' => 30,
|
||
'minAmount' => $limits['min'],
|
||
'maxAmount' => $limits['max'],
|
||
'defaultAmount' => 50000,
|
||
'tiers' => hesabix2_entry_dialog_tiers(),
|
||
'copy' => $copy,
|
||
'i18n' => array(
|
||
'close' => __('بستن', 'hesabix2'),
|
||
'whySupport' => __('چرا حمایت مالی؟', 'hesabix2'),
|
||
'amountLabel' => __('مبلغ حمایت', 'hesabix2'),
|
||
'toman' => __('تومان', 'hesabix2'),
|
||
'showOnWall' => __('نامم در دیوار حامیان نمایش داده شود', 'hesabix2'),
|
||
'donorName' => __('نام شما (اختیاری)', 'hesabix2'),
|
||
'dismiss' => __('۳۰ روز دیگر نشان نده', 'hesabix2'),
|
||
'freeNote' => __('ورود همیشه رایگان است — حمایت اختیاری است.', 'hesabix2'),
|
||
'payProcessing' => __('در حال انتقال به درگاه…', 'hesabix2'),
|
||
'donationsOff' => __('درگاه حمایت موقتاً در دسترس نیست؛ میتوانید رایگان وارد شوید.', 'hesabix2'),
|
||
'compareArc' => __('مقایسهٔ آرک و شادمان', 'hesabix2'),
|
||
'tryArc' => __('ثبتنام رایگان در آرک', 'hesabix2'),
|
||
),
|
||
)
|
||
);
|
||
}
|
||
add_action('wp_enqueue_scripts', 'hesabix2_entry_dialog_assets', 25);
|
||
|
||
/**
|
||
* HTML دیالوگ در فوتر
|
||
*/
|
||
function hesabix2_render_entry_dialog_markup() {
|
||
if (!hesabix2_entry_dialog_is_active_page() || !hesabix2_entry_dialog_enabled()) {
|
||
return;
|
||
}
|
||
|
||
$limits = hesabix2_entry_dialog_amount_limits();
|
||
$slider_min = (int) $limits['min'];
|
||
$slider_max = (int) $limits['max'];
|
||
?>
|
||
<div id="hesabix-entry-dialog" class="hx-entry-dialog" aria-hidden="true" role="dialog" aria-modal="true" aria-labelledby="hx-entry-dialog-title">
|
||
<div class="hx-entry-dialog__backdrop" data-hx-entry-close tabindex="-1" aria-hidden="true"></div>
|
||
<div class="hx-entry-dialog__panel">
|
||
<button type="button" class="hx-entry-dialog__close" data-hx-entry-close aria-label="<?php esc_attr_e('بستن', 'hesabix2'); ?>">
|
||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg>
|
||
</button>
|
||
|
||
<div class="hx-entry-dialog__layout">
|
||
<header class="hx-entry-dialog__header">
|
||
<p class="hx-entry-dialog__badge">
|
||
<span class="hx-entry-dialog__badge-dot" aria-hidden="true"></span>
|
||
<?php esc_html_e('رایگان · متنباز · دادهٔ شما مال شماست', 'hesabix2'); ?>
|
||
</p>
|
||
<h2 id="hx-entry-dialog-title" class="hx-entry-dialog__title"></h2>
|
||
<p class="hx-entry-dialog__subtitle"></p>
|
||
<p class="hx-entry-dialog__guarantee"></p>
|
||
<p class="hx-entry-dialog__stats"></p>
|
||
<p class="hx-entry-dialog__shad-hint"></p>
|
||
</header>
|
||
|
||
<div class="hx-entry-dialog__main">
|
||
<div class="hx-entry-tier" id="hx-entry-tier-card" aria-live="polite" aria-atomic="true" aria-describedby="hx-entry-tier-impact">
|
||
<div class="hx-entry-tier__glow" aria-hidden="true"></div>
|
||
<div class="hx-entry-tier__visual">
|
||
<span class="hx-entry-tier__emoji" id="hx-entry-tier-emoji" aria-hidden="true">☕</span>
|
||
<span class="hx-entry-tier__sticker" id="hx-entry-tier-sticker" aria-hidden="true"></span>
|
||
</div>
|
||
<div class="hx-entry-tier__body">
|
||
<h3 class="hx-entry-tier__title" id="hx-entry-tier-title"></h3>
|
||
<p class="hx-entry-tier__impact" id="hx-entry-tier-impact"></p>
|
||
<p class="hx-entry-tier__tagline" id="hx-entry-tier-tagline"></p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="hx-entry-slider-wrap">
|
||
<label for="hx-entry-amount-input" class="hx-entry-slider__label"><?php esc_html_e('مبلغ حمایت', 'hesabix2'); ?></label>
|
||
<div class="hx-entry-amount-field">
|
||
<input
|
||
type="text"
|
||
id="hx-entry-amount-input"
|
||
class="hx-entry-amount-input"
|
||
inputmode="numeric"
|
||
autocomplete="off"
|
||
dir="ltr"
|
||
aria-describedby="hx-entry-amount-hint"
|
||
value="<?php echo esc_attr(number_format_i18n(50000)); ?>"
|
||
>
|
||
<span class="hx-entry-amount-field__unit"><?php esc_html_e('تومان', 'hesabix2'); ?></span>
|
||
</div>
|
||
<input type="range" id="hx-entry-amount-slider" class="hx-entry-slider" min="0" max="100" value="25" step="1" aria-label="<?php esc_attr_e('تنظیم مبلغ با نوار', 'hesabix2'); ?>" aria-valuemin="<?php echo esc_attr((string) $slider_min); ?>" aria-valuemax="<?php echo esc_attr((string) $slider_max); ?>">
|
||
<p class="hx-entry-slider__range-hint" id="hx-entry-amount-hint">
|
||
<span><?php echo esc_html(sprintf(__('از %s', 'hesabix2'), number_format_i18n($slider_min))); ?></span>
|
||
<span><?php echo esc_html(sprintf(__('تا %s تومان', 'hesabix2'), number_format_i18n($slider_max))); ?></span>
|
||
</p>
|
||
</div>
|
||
|
||
<details class="hx-entry-extra">
|
||
<summary><?php esc_html_e('نام در دیوار حامیان (اختیاری)', 'hesabix2'); ?></summary>
|
||
<div class="hx-entry-extra__inner">
|
||
<label class="sr-only" for="hx-entry-donor-name"><?php esc_html_e('نام', 'hesabix2'); ?></label>
|
||
<input type="text" id="hx-entry-donor-name" class="hx-entry-input" maxlength="120" placeholder="<?php esc_attr_e('نام شما', 'hesabix2'); ?>" autocomplete="name">
|
||
<label class="hx-entry-check">
|
||
<input type="checkbox" id="hx-entry-show-wall" value="1">
|
||
<span><?php esc_html_e('نامم در دیوار حامیان نمایش داده شود', 'hesabix2'); ?></span>
|
||
</label>
|
||
</div>
|
||
</details>
|
||
</div>
|
||
|
||
<footer class="hx-entry-dialog__footer">
|
||
<button type="button" class="hx-entry-btn hx-entry-btn--support" id="hx-entry-btn-support"></button>
|
||
<button type="button" class="hx-entry-btn hx-entry-btn--free" id="hx-entry-btn-free"></button>
|
||
<a href="<?php echo esc_url(hesabix2_entry_dialog_sponsors_url()); ?>" class="hx-entry-link" id="hx-entry-link-why" target="_blank" rel="noopener noreferrer"><?php esc_html_e('چرا حمایت مالی؟', 'hesabix2'); ?></a>
|
||
<a href="<?php echo esc_url(function_exists('hesabix2_versions_compare_url') ? hesabix2_versions_compare_url() : home_url('/arc-shadoman/')); ?>" class="hx-entry-link hx-entry-link--compare is-hidden" id="hx-entry-link-compare"><?php esc_html_e('مقایسهٔ آرک و شادمان', 'hesabix2'); ?></a>
|
||
<label class="hx-entry-dismiss">
|
||
<input type="checkbox" id="hx-entry-dismiss">
|
||
<span><?php esc_html_e('۳۰ روز دیگر نشان نده', 'hesabix2'); ?></span>
|
||
</label>
|
||
<p class="hx-entry-free-note"><?php esc_html_e('ورود همیشه رایگان است — حمایت اختیاری است.', 'hesabix2'); ?></p>
|
||
</footer>
|
||
</div>
|
||
|
||
<form id="hx-entry-donate-form" class="is-hidden" method="post" action="<?php echo esc_url(home_url('/')); ?>">
|
||
<input type="hidden" name="hesabix_donation_nonce" id="hx-entry-donation-nonce" value="">
|
||
<input type="hidden" name="amount_toman" id="hx-entry-amount-hidden" value="">
|
||
<input type="hidden" name="hesabix_return_url" id="hx-entry-return-url" value="">
|
||
<input type="hidden" name="donor_name" id="hx-entry-donor-hidden" value="">
|
||
<input type="hidden" name="message" id="hx-entry-message-hidden" value="">
|
||
<input type="checkbox" name="show_on_wall" id="hx-entry-wall-hidden" value="1" class="is-hidden" disabled>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<?php
|
||
}
|
||
add_action('wp_footer', 'hesabix2_render_entry_dialog_markup', 15);
|