hesabixWpTheme/page-development.php

373 lines
24 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Template Name: وضعیت توسعه
*
* @package Hesabix2
*/
get_header();
$wrap = 'max-w-6xl mx-auto px-4 sm:px-6 lg:px-8';
$data = function_exists('hesabix2_forgejo_development_data') ? hesabix2_forgejo_development_data() : array();
$projects = isset($data['projects']) ? $data['projects'] : array();
$timeline = isset($data['timeline']) ? $data['timeline'] : array();
$global_label = isset($data['global_updated_label']) ? $data['global_updated_label'] : '';
$cache_mins = isset($data['cache_ttl_minutes']) ? (int) $data['cache_ttl_minutes'] : 30;
$stale_mode = !empty($data['stale_mode']);
$api_down = !empty($data['api_down']);
$refreshed = function_exists('hesabix2_forgejo_should_refresh') && hesabix2_forgejo_should_refresh();
$dev_url = function_exists('hesabix2_development_page_url') ? hesabix2_development_page_url() : get_permalink();
$source_home = 'https://source.hesabix.ir';
$feed_json = isset($data['feeds']['json']) ? $data['feeds']['json'] : (function_exists('hesabix2_forgejo_feed_json_url') ? hesabix2_forgejo_feed_json_url() : '');
$feed_rss = isset($data['feeds']['rss']) ? $data['feeds']['rss'] : (function_exists('hesabix2_forgejo_feed_rss_url') ? hesabix2_forgejo_feed_rss_url() : '');
$hero_summary = function_exists('hesabix2_forgejo_hero_summary')
? hesabix2_forgejo_hero_summary($projects)
: array('project_count' => 0, 'active_count' => 0, 'latest_activity_label' => '');
?>
<section class="vc-hero dev-hero bg-gradient-to-l from-brand-600 to-brand-500 text-white py-14 sm:py-16 relative overflow-hidden">
<div class="<?php echo esc_attr($wrap); ?> relative z-10 text-center lg:text-right">
<p class="text-white/80 text-sm font-medium mb-3"><?php esc_html_e('شفافیت توسعه', 'hesabix2'); ?></p>
<h1 class="text-2xl sm:text-3xl lg:text-4xl font-bold mb-6 leading-tight"><?php esc_html_e('وضعیت توسعهٔ پروژه‌ها', 'hesabix2'); ?></h1>
<?php if (!empty($projects)) : ?>
<ul class="dev-hero-stats list-none p-0 m-0 mb-6 flex flex-wrap justify-center lg:justify-start gap-3" aria-label="<?php esc_attr_e('خلاصه وضعیت', 'hesabix2'); ?>">
<li class="dev-hero-stat">
<span class="dev-hero-stat__value"><?php echo (int) $hero_summary['project_count']; ?></span>
<span class="dev-hero-stat__label"><?php esc_html_e('پروژه', 'hesabix2'); ?></span>
</li>
<li class="dev-hero-stat dev-hero-stat--active">
<span class="dev-hero-stat__value"><?php echo (int) $hero_summary['active_count']; ?></span>
<span class="dev-hero-stat__label"><?php esc_html_e('در حال توسعه', 'hesabix2'); ?></span>
</li>
<?php if (!empty($hero_summary['latest_activity_label'])) : ?>
<li class="dev-hero-stat">
<span class="dev-hero-stat__value dev-hero-stat__value--text"><?php echo esc_html($hero_summary['latest_activity_label']); ?></span>
<span class="dev-hero-stat__label"><?php esc_html_e('آخرین فعالیت', 'hesabix2'); ?></span>
</li>
<?php endif; ?>
<?php if ($global_label) : ?>
<li class="dev-hero-stat dev-hero-stat--muted hidden sm:flex">
<span class="dev-hero-stat__value dev-hero-stat__value--text text-sm"><?php echo esc_html($global_label); ?></span>
<span class="dev-hero-stat__label"><?php esc_html_e('به‌روزرسانی مخزن', 'hesabix2'); ?></span>
</li>
<?php endif; ?>
</ul>
<nav class="dev-hero-nav flex flex-wrap justify-center lg:justify-start gap-2" aria-label="<?php esc_attr_e('پرش به بخش', 'hesabix2'); ?>">
<?php foreach ($projects as $proj) :
if (!empty($proj['error']) && empty($proj['commits'])) {
continue;
}
?>
<a href="#dev-<?php echo esc_attr($proj['slug']); ?>" class="dev-hero-nav__link"><?php echo esc_html($proj['label']); ?></a>
<?php endforeach; ?>
<?php if (!empty($timeline)) : ?>
<a href="#dev-timeline" class="dev-hero-nav__link"><?php esc_html_e('فعالیت اخیر', 'hesabix2'); ?></a>
<?php endif; ?>
</nav>
<?php endif; ?>
</div>
</section>
<section class="py-5 bg-slate-50 border-b border-slate-100">
<div class="<?php echo esc_attr($wrap); ?>">
<?php if ($stale_mode || $api_down) : ?>
<div class="dev-alert dev-alert--warning mb-4" role="alert">
<p class="mb-0 text-sm">
<?php if ($api_down) : ?>
<?php esc_html_e('اتصال به مخزن کد برقرار نیست. آخرین دادهٔ ذخیره‌شده نمایش داده می‌شود.', 'hesabix2'); ?>
<?php else : ?>
<?php esc_html_e('برخی داده‌ها از کش قبلی هستند؛ مخزن کد موقتاً در دسترس نبود.', 'hesabix2'); ?>
<?php endif; ?>
</p>
</div>
<?php endif; ?>
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 text-sm text-slate-600">
<p class="mb-0">
<?php
printf(
esc_html__('به‌روزرسانی خودکار هر %d دقیقه', 'hesabix2'),
$cache_mins
);
?>
</p>
<div class="flex flex-wrap items-center gap-3">
<a href="<?php echo esc_url($source_home); ?>" target="_blank" rel="noopener noreferrer" class="text-brand-600 font-medium hover:underline">
<?php esc_html_e('مخازن کد', 'hesabix2'); ?>
</a>
<?php if ($feed_json) : ?>
<a href="<?php echo esc_url($feed_json); ?>" class="text-slate-500 hover:text-brand-600" target="_blank" rel="noopener">JSON</a>
<?php endif; ?>
<?php if ($feed_rss) : ?>
<a href="<?php echo esc_url($feed_rss); ?>" class="text-slate-500 hover:text-brand-600" target="_blank" rel="noopener">RSS</a>
<?php endif; ?>
<?php if (current_user_can('manage_options')) : ?>
<a href="<?php echo esc_url(add_query_arg('hesabix2_refresh_forgejo', '1', $dev_url)); ?>" class="text-slate-500 hover:text-brand-600">
<?php esc_html_e('به‌روزرسانی دستی', 'hesabix2'); ?>
</a>
<?php endif; ?>
</div>
</div>
<?php if ($refreshed) : ?>
<p class="mt-3 mb-0 text-sm text-brand-700 bg-brand-50 border border-brand-200 rounded-lg px-4 py-2" role="status">
<?php esc_html_e('کش پاک شد؛ داده‌های تازه بارگذاری شد.', 'hesabix2'); ?>
</p>
<?php endif; ?>
<?php if (current_user_can('manage_options') && function_exists('hesabix2_forgejo_webhook_url')) : ?>
<details class="dev-webhook-details mt-4 text-xs text-slate-500">
<summary class="cursor-pointer font-medium text-slate-600"><?php esc_html_e('تنظیم webhook (مدیر)', 'hesabix2'); ?></summary>
<p class="mt-2 mb-1"><?php esc_html_e('در Forgejo → تنظیمات مخزن → Webhooks، URL زیر را با رویداد Push و Release اضافه کنید و کلید را در Header بفرستید:', 'hesabix2'); ?></p>
<code class="dev-webhook-url block p-2 bg-white border border-slate-200 rounded-lg break-all" dir="ltr"><?php echo esc_html(hesabix2_forgejo_webhook_url()); ?></code>
<p class="mt-2 mb-1"><?php esc_html_e('Header امنیتی:', 'hesabix2'); ?></p>
<code class="dev-webhook-url block p-2 bg-white border border-slate-200 rounded-lg break-all" dir="ltr"><?php echo esc_html(hesabix2_forgejo_webhook_secret_header() . ': ' . hesabix2_forgejo_webhook_secret()); ?></code>
</details>
<?php endif; ?>
</div>
</section>
<section class="py-12 sm:py-14 bg-white border-b border-slate-100">
<div class="<?php echo esc_attr($wrap); ?>">
<h2 class="text-xl sm:text-2xl font-bold text-slate-800 mb-8 text-center lg:text-right"><?php esc_html_e('پروژه‌ها', 'hesabix2'); ?></h2>
<?php if (empty($projects)) : ?>
<p class="text-slate-600 text-center"><?php esc_html_e('در حال حاضر داده‌ای در دسترس نیست.', 'hesabix2'); ?></p>
<?php else : ?>
<div class="grid lg:grid-cols-3 gap-6">
<?php foreach ($projects as $proj) :
$status = isset($proj['status']) ? $proj['status'] : 'quiet';
$status_lbl = function_exists('hesabix2_forgejo_status_label')
? hesabix2_forgejo_status_label($status)
: $status;
$theme = !empty($proj['repo_theme']) ? $proj['repo_theme'] : 'default';
$badge_class = ('active' === $status)
? 'bg-emerald-100 text-emerald-800'
: (('error' === $status) ? 'bg-amber-100 text-amber-800' : 'bg-slate-100 text-slate-600');
$issues_url = !empty($proj['issues_url']) ? $proj['issues_url'] : '';
?>
<article id="dev-<?php echo esc_attr($proj['slug']); ?>" class="dev-repo-card dev-repo-card--<?php echo esc_attr($theme); ?> rounded-2xl border border-slate-200 bg-white shadow-sm overflow-hidden flex flex-col scroll-mt-24">
<header class="p-5 sm:p-6 border-b border-slate-100">
<div class="flex items-start gap-3 mb-2">
<span class="dev-repo-icon dev-repo-icon--<?php echo esc_attr($theme); ?>" aria-hidden="true">
<?php
if (function_exists('hesabix2_forgejo_repo_icon_svg')) {
echo hesabix2_forgejo_repo_icon_svg($theme); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- SVG from theme
}
?>
</span>
<div class="flex-1 min-w-0">
<div class="flex items-start justify-between gap-2">
<h3 class="text-lg font-bold text-slate-800 m-0"><?php echo esc_html($proj['label']); ?></h3>
<span class="shrink-0 text-xs font-semibold px-2.5 py-1 rounded-lg <?php echo esc_attr($badge_class); ?>">
<?php echo esc_html($status_lbl); ?>
</span>
</div>
<?php if (!empty($proj['stale'])) : ?>
<span class="inline-block mt-1 text-[11px] font-medium text-amber-700 bg-amber-50 px-2 py-0.5 rounded"><?php esc_html_e('دادهٔ ذخیره‌شده', 'hesabix2'); ?></span>
<?php endif; ?>
</div>
</div>
<?php if (!empty($proj['description'])) : ?>
<p class="text-slate-500 text-sm mb-2"><?php echo esc_html($proj['description']); ?></p>
<?php endif; ?>
<?php
$last_rel = !empty($proj['last_commit_at']) && function_exists('hesabix2_forgejo_relative_label')
? hesabix2_forgejo_relative_label($proj['last_commit_at'])
: '';
if ($last_rel && (empty($proj['error']) || !empty($proj['commits']))) :
?>
<p class="text-xs text-slate-400 mb-0">
<?php
printf(
esc_html__('آخرین commit: %s', 'hesabix2'),
esc_html($last_rel)
);
?>
</p>
<?php endif; ?>
<?php if (!empty($proj['error']) && empty($proj['commits'])) : ?>
<p class="text-amber-700 text-sm mt-3 mb-0"><?php echo esc_html($proj['error']); ?></p>
<?php endif; ?>
</header>
<div class="p-5 sm:p-6 flex-1 flex flex-col gap-5">
<?php if (!empty($proj['latest_release'])) :
$rel = $proj['latest_release'];
?>
<div>
<h4 class="text-xs font-bold text-slate-500 uppercase tracking-wide mb-2"><?php esc_html_e('آخرین نسخه', 'hesabix2'); ?></h4>
<p class="mb-1">
<a href="<?php echo esc_url($rel['html_url']); ?>" target="_blank" rel="noopener noreferrer" class="font-semibold text-brand-600 hover:underline">
<?php echo esc_html($rel['tag_name'] ?: $rel['name']); ?>
</a>
<?php if (!empty($rel['prerelease'])) : ?>
<span class="text-xs text-slate-500">(<?php esc_html_e('پیش‌انتشار', 'hesabix2'); ?>)</span>
<?php endif; ?>
</p>
<?php if (!empty($rel['date_label'])) : ?>
<p class="text-xs text-slate-500 mb-2"><?php echo esc_html($rel['date_label']); ?></p>
<?php endif; ?>
<?php if (!empty($rel['body_html'])) : ?>
<div class="dev-release-body page-prose text-sm text-slate-600"><?php echo $rel['body_html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_kses in feed ?></div>
<?php elseif (!empty($rel['body'])) : ?>
<p class="text-sm text-slate-600 mt-0 mb-0"><?php echo esc_html($rel['body']); ?></p>
<?php endif; ?>
</div>
<?php elseif (empty($proj['error']) || !empty($proj['commits'])) : ?>
<p class="text-sm text-slate-500 mb-0"><?php esc_html_e('نسخهٔ رسمی منتشر نشده؛ تغییرات در commitها قابل مشاهده است.', 'hesabix2'); ?></p>
<?php endif; ?>
<?php if (!empty($proj['commits'])) : ?>
<div>
<h4 class="text-xs font-bold text-slate-500 uppercase tracking-wide mb-2"><?php esc_html_e('آخرین تغییرات', 'hesabix2'); ?></h4>
<ul class="dev-commit-list list-none p-0 m-0 space-y-3">
<?php foreach (array_slice($proj['commits'], 0, 5) as $commit) : ?>
<li class="text-sm dev-commit-item dev-commit-item--<?php echo esc_attr($theme); ?> pr-3">
<a href="<?php echo esc_url($commit['html_url']); ?>" target="_blank" rel="noopener noreferrer" class="font-medium text-slate-800 hover:text-brand-600">
<?php echo esc_html($commit['summary']); ?>
</a>
<p class="text-xs text-slate-500 mt-1 mb-0">
<?php if (!empty($commit['author'])) : ?>
<span><?php echo esc_html($commit['author']); ?></span>
<span aria-hidden="true"> · </span>
<?php endif; ?>
<?php
$commit_when = !empty($commit['created']) && function_exists('hesabix2_forgejo_relative_label')
? hesabix2_forgejo_relative_label($commit['created'])
: ($commit['date_label'] ?? '');
if ($commit_when) :
?>
<time datetime="<?php echo esc_attr($commit['created']); ?>" title="<?php echo esc_attr($commit['date_label'] ?? ''); ?>"><?php echo esc_html($commit_when); ?></time>
<?php endif; ?>
<?php if (!empty($commit['stats'])) : ?>
<span aria-hidden="true"> · </span>
<span dir="ltr" class="font-mono text-[11px]">+<?php echo (int) $commit['stats']['additions']; ?> / -<?php echo (int) $commit['stats']['deletions']; ?></span>
<?php endif; ?>
</p>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php if (!empty($proj['open_issues']) && $issues_url) : ?>
<a href="<?php echo esc_url($issues_url); ?>" target="_blank" rel="noopener noreferrer" class="inline-flex items-center gap-1.5 text-sm font-medium text-brand-600 hover:underline">
<?php
printf(
esc_html(_n('%d issue باز', '%d issue باز', (int) $proj['open_issues'], 'hesabix2')),
(int) $proj['open_issues']
);
?>
<span aria-hidden="true">←</span>
</a>
<?php endif; ?>
</div>
<footer class="p-5 sm:p-6 pt-0 mt-auto flex flex-col gap-2">
<a href="<?php echo esc_url($proj['html_url']); ?>" target="_blank" rel="noopener noreferrer" class="inline-flex items-center justify-center w-full min-h-[44px] px-4 py-2.5 rounded-xl font-semibold text-brand-600 border-2 border-brand-200 hover:bg-brand-50 transition text-sm">
<?php esc_html_e('مشاهده در مخزن کد', 'hesabix2'); ?>
</a>
</footer>
</article>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</section>
<?php if (!empty($timeline)) : ?>
<section id="dev-timeline" class="py-12 sm:py-14 bg-slate-50 border-b border-slate-100 scroll-mt-24">
<div class="<?php echo esc_attr($wrap); ?>">
<h2 class="text-xl sm:text-2xl font-bold text-slate-800 mb-4 text-center lg:text-right"><?php esc_html_e('فعالیت اخیر', 'hesabix2'); ?></h2>
<div class="dev-timeline-tabs flex flex-wrap justify-center lg:justify-start gap-2 mb-6" role="tablist" aria-label="<?php esc_attr_e('فیلتر پروژه', 'hesabix2'); ?>">
<button type="button" class="dev-timeline-tab dev-timeline-tab--active" data-dev-filter="all" role="tab" aria-selected="true">
<?php esc_html_e('همه', 'hesabix2'); ?>
</button>
<?php foreach ($projects as $proj) :
if (empty($proj['commits'])) {
continue;
}
$theme = !empty($proj['repo_theme']) ? $proj['repo_theme'] : 'default';
?>
<button type="button" class="dev-timeline-tab dev-timeline-tab--<?php echo esc_attr($theme); ?>" data-dev-filter="<?php echo esc_attr($proj['slug']); ?>" role="tab" aria-selected="false">
<?php echo esc_html(!empty($proj['repo_label_short']) ? $proj['repo_label_short'] : $proj['label']); ?>
</button>
<?php endforeach; ?>
</div>
<div class="rounded-2xl border border-slate-200 bg-white shadow-sm overflow-hidden">
<p class="dev-timeline-empty hidden p-6 text-center text-slate-500 text-sm mb-0" data-dev-timeline-empty>
<?php esc_html_e('برای این پروژه commit اخیری در فهرست نیست.', 'hesabix2'); ?>
</p>
<ul class="dev-timeline list-none p-0 m-0 divide-y divide-slate-100">
<?php foreach ($timeline as $item) :
$t_theme = !empty($item['repo_theme']) ? $item['repo_theme'] : 'default';
?>
<li class="dev-timeline-item p-4 sm:p-5 flex flex-col sm:flex-row sm:items-start gap-2 sm:gap-4" data-dev-timeline-item data-repo-slug="<?php echo esc_attr($item['repo_slug']); ?>">
<span class="dev-timeline-badge dev-timeline-badge--<?php echo esc_attr($t_theme); ?> shrink-0 inline-flex items-center gap-1.5 self-start text-xs font-bold px-2.5 py-1 rounded-lg">
<?php
if (function_exists('hesabix2_forgejo_repo_icon_svg')) {
echo hesabix2_forgejo_repo_icon_svg($t_theme); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
<?php echo esc_html($item['repo_label']); ?>
</span>
<div class="flex-1 min-w-0">
<a href="<?php echo esc_url($item['html_url']); ?>" target="_blank" rel="noopener noreferrer" class="font-medium text-slate-800 hover:text-brand-600">
<?php echo esc_html($item['summary']); ?>
</a>
<p class="text-xs text-slate-500 mt-1 mb-0">
<?php if (!empty($item['author'])) : ?>
<span><?php echo esc_html($item['author']); ?></span>
<span aria-hidden="true"> · </span>
<?php endif; ?>
<?php
$item_when = !empty($item['created']) && function_exists('hesabix2_forgejo_relative_label')
? hesabix2_forgejo_relative_label($item['created'])
: ($item['date_label'] ?? '');
if ($item_when) :
?>
<time datetime="<?php echo esc_attr($item['created']); ?>" title="<?php echo esc_attr($item['date_label'] ?? ''); ?>"><?php echo esc_html($item_when); ?></time>
<?php endif; ?>
<?php if (!empty($item['sha_short'])) : ?>
<span aria-hidden="true"> · </span>
<code class="text-[11px] bg-slate-100 px-1 rounded" dir="ltr"><?php echo esc_html($item['sha_short']); ?></code>
<?php endif; ?>
</p>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
</section>
<?php endif; ?>
<section class="py-10 sm:py-12 bg-white">
<div class="<?php echo esc_attr($wrap); ?> text-center lg:text-right">
<p class="text-slate-600 text-sm leading-relaxed max-w-2xl lg:mr-0 mx-auto mb-4">
<?php esc_html_e('حسابیکس متن‌باز است؛ می‌توانید کد را در مخزن بررسی، گزارش issue ثبت کنید یا در توسعه مشارکت داشته باشید.', 'hesabix2'); ?>
</p>
<?php if ($feed_json || $feed_rss) : ?>
<p class="text-slate-500 text-xs mb-6">
<?php esc_html_e('فیدها:', 'hesabix2'); ?>
<?php if ($feed_json) : ?>
<a href="<?php echo esc_url($feed_json); ?>" class="text-brand-600 hover:underline" target="_blank" rel="noopener">JSON</a>
<?php endif; ?>
<?php if ($feed_json && $feed_rss) : ?> · <?php endif; ?>
<?php if ($feed_rss) : ?>
<a href="<?php echo esc_url($feed_rss); ?>" class="text-brand-600 hover:underline" target="_blank" rel="noopener">RSS</a>
<?php endif; ?>
</p>
<?php endif; ?>
<a href="<?php echo esc_url($source_home); ?>" target="_blank" rel="noopener noreferrer" class="inline-flex items-center justify-center gap-2 bg-brand-500 hover:bg-brand-600 text-white font-semibold px-6 py-3 rounded-xl transition shadow-lg shadow-brand-500/20">
<?php esc_html_e('رفتن به source.hesabix.ir', 'hesabix2'); ?>
</a>
</div>
</section>
<?php get_footer(); ?>