hesabixWpTheme/inc/bbpress-shell.php

259 lines
8.6 KiB
PHP

<?php
/**
* هدر فشرده انجمن bbPress — breadcrumb، عنوان، ابزارها، جستجو
*
* @package Hesabix2
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* آیا فرم جستجوی سراسری در هدر نمایش داده شود؟
*
* @return bool
*/
function hesabix2_bbpress_shell_show_search() {
if ( ! function_exists( 'bbp_allow_search' ) || ! bbp_allow_search() ) {
return false;
}
if ( function_exists( 'bbp_is_single_user_edit' ) && bbp_is_single_user_edit() ) {
return false;
}
if ( function_exists( 'bbp_is_topic_edit' ) && bbp_is_topic_edit() ) {
return false;
}
if ( function_exists( 'bbp_is_reply_edit' ) && bbp_is_reply_edit() ) {
return false;
}
if ( function_exists( 'bbp_is_forum_edit' ) && bbp_is_forum_edit() ) {
return false;
}
return true;
}
/**
* زیرعنوان کوتاه (فقط صفحهٔ اصلی انجمن)
*
* @return string
*/
function hesabix2_bbpress_shell_subtitle() {
if ( function_exists( 'bbp_is_forum_archive' ) && bbp_is_forum_archive() ) {
return __( 'بحث و تبادل نظر با سایر کاربران حسابیکس', 'hesabix2' );
}
return '';
}
/**
* دکمهٔ اصلی (موضوع جدید / پاسخ / ورود)
*
* @return array{href: string, label: string, primary?: bool}|null
*/
function hesabix2_bbpress_primary_action() {
if ( function_exists( 'bbp_is_single_forum' ) && bbp_is_single_forum() ) {
if ( function_exists( 'bbp_is_forum_closed' ) && bbp_is_forum_closed() ) {
return null;
}
if ( is_user_logged_in()
&& function_exists( 'bbp_current_user_can_access_create_topic_form' )
&& bbp_current_user_can_access_create_topic_form() ) {
return array(
'href' => '#new-post',
'label' => __( 'موضوع جدید', 'hesabix2' ),
'primary' => true,
);
}
if ( ! is_user_logged_in() ) {
$login = function_exists( 'hesabix2_bbpress_login_url' )
? hesabix2_bbpress_login_url( get_permalink() )
: ( function_exists( 'hesabix2_portal_auth_url' ) ? hesabix2_portal_auth_url( 'login', get_permalink() ) : wp_login_url( get_permalink() ) );
return array(
'href' => $login,
'label' => __( 'ورود برای موضوع جدید', 'hesabix2' ),
'primary' => true,
);
}
}
if ( function_exists( 'bbp_is_single_topic' ) && bbp_is_single_topic() ) {
if ( is_user_logged_in()
&& function_exists( 'bbp_current_user_can_access_create_reply_form' )
&& bbp_current_user_can_access_create_reply_form() ) {
return array(
'href' => '#new-post',
'label' => __( 'پاسخ دهید', 'hesabix2' ),
'primary' => true,
);
}
if ( ! is_user_logged_in() ) {
$login = function_exists( 'hesabix2_bbpress_login_url' )
? hesabix2_bbpress_login_url( get_permalink() )
: ( function_exists( 'hesabix2_portal_auth_url' ) ? hesabix2_portal_auth_url( 'login', get_permalink() ) : wp_login_url( get_permalink() ) );
return array(
'href' => $login,
'label' => __( 'ورود برای پاسخ', 'hesabix2' ),
'primary' => true,
);
}
}
return null;
}
/**
* لینک‌های نوار ابزار انجمن
*
* @return array<int, array{href: string, label: string, primary?: bool}>
*/
function hesabix2_bbpress_toolbar_links() {
$links = array();
$root = function_exists( 'hesabix2_bbpress_root_url' ) ? hesabix2_bbpress_root_url() : '';
if ( $root && function_exists( 'bbp_is_forum_archive' ) && ! bbp_is_forum_archive() ) {
$links[] = array(
'href' => $root,
'label' => __( 'فهرست انجمن', 'hesabix2' ),
'primary' => true,
);
}
if ( function_exists( 'bbp_allow_search' ) && bbp_allow_search()
&& function_exists( 'bbp_get_search_url' )
&& function_exists( 'bbp_is_search' ) && ! bbp_is_search()
&& ! hesabix2_bbpress_shell_show_search() ) {
$links[] = array(
'href' => bbp_get_search_url(),
'label' => __( 'جستجو', 'hesabix2' ),
);
}
if ( function_exists( 'bbp_get_view_url' )
&& function_exists( 'bbp_is_single_view' ) && ! bbp_is_single_view() ) {
$links[] = array(
'href' => bbp_get_view_url( 'popular' ),
'label' => __( 'پربحث‌ترین', 'hesabix2' ),
);
$links[] = array(
'href' => bbp_get_view_url( 'no-replies' ),
'label' => __( 'بدون پاسخ', 'hesabix2' ),
);
}
$stats_url = function_exists( 'hesabix2_bbpress_statistics_url' ) ? hesabix2_bbpress_statistics_url() : '';
if ( $stats_url
&& function_exists( 'hesabix2_is_bbpress_statistics_page' )
&& ! hesabix2_is_bbpress_statistics_page() ) {
$links[] = array(
'href' => $stats_url,
'label' => __( 'آمار', 'hesabix2' ),
);
}
return apply_filters( 'hesabix2_bbpress_toolbar_links', $links );
}
/**
* رندر breadcrumb
*/
function hesabix2_bbpress_render_breadcrumb() {
$items = function_exists( 'hesabix2_bbpress_breadcrumb_items' ) ? hesabix2_bbpress_breadcrumb_items() : array();
if ( count( $items ) < 2 ) {
return;
}
?>
<nav class="hesabix2-bbp-breadcrumb" aria-label="<?php esc_attr_e( 'مسیر انجمن', 'hesabix2' ); ?>">
<ol class="hesabix2-bbp-breadcrumb__list">
<?php
$last = count( $items ) - 1;
foreach ( $items as $i => $item ) :
$label = isset( $item['label'] ) ? $item['label'] : '';
if ( '' === $label ) {
continue;
}
$is_last = ( $i === $last );
$url = ( ! $is_last && ! empty( $item['url'] ) ) ? $item['url'] : '';
?>
<li class="hesabix2-bbp-breadcrumb__item">
<?php if ( $url ) : ?>
<a href="<?php echo esc_url( $url ); ?>"><?php echo esc_html( $label ); ?></a>
<?php else : ?>
<span<?php echo $is_last ? ' aria-current="page"' : ''; ?>><?php echo esc_html( $label ); ?></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ol>
</nav>
<?php
}
/**
* رندر هدر فشرده انجمن
*/
function hesabix2_bbpress_render_shell() {
$heading = function_exists( 'hesabix2_bbpress_page_heading' ) ? hesabix2_bbpress_page_heading() : '';
if ( ! $heading ) {
return;
}
$subtitle = hesabix2_bbpress_shell_subtitle();
$toolbar_links = hesabix2_bbpress_toolbar_links();
$primary = hesabix2_bbpress_primary_action();
$show_search = hesabix2_bbpress_shell_show_search();
$is_root = function_exists( 'bbp_is_forum_archive' ) && bbp_is_forum_archive();
$has_toolbar = ! empty( $toolbar_links );
$has_bar = $has_toolbar || $show_search;
$GLOBALS['hesabix2_bbp_search_compact'] = true;
?>
<section class="hesabix2-bbp-shell ap-hero-qa" aria-label="<?php esc_attr_e( 'سرصفحه انجمن', 'hesabix2' ); ?>">
<div class="hesabix2-bbp-shell__inner">
<?php hesabix2_bbpress_render_breadcrumb(); ?>
<div class="hesabix2-bbp-shell__head">
<div class="hesabix2-bbp-shell__title-block">
<?php if ( $is_root ) : ?>
<span class="ap-hero-badge hesabix2-bbp-shell__badge">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M17 8h2a2 2 0 012 2v10a2 2 0 01-2 2H5a2 2 0 01-2-2V10a2 2 0 012-2h2"/><path stroke-linecap="round" stroke-linejoin="round" d="M12 12h.01M8 12h.01M16 12h.01M7 8V6a2 2 0 012-2h6a2 2 0 012 2v2"/></svg>
<?php esc_html_e( 'انجمن کاربران', 'hesabix2' ); ?>
</span>
<?php endif; ?>
<h1 class="hesabix2-bbp-shell__title"><?php echo esc_html( $heading ); ?></h1>
<?php if ( $subtitle ) : ?>
<p class="hesabix2-bbp-shell__subtitle"><?php echo esc_html( $subtitle ); ?></p>
<?php endif; ?>
</div>
<?php if ( $primary ) : ?>
<div class="hesabix2-bbp-shell__cta">
<a
class="hesabix2-bbp-shell__cta-btn<?php echo ! empty( $primary['primary'] ) ? ' hesabix2-bbp-shell__cta-btn--primary' : ''; ?>"
href="<?php echo esc_url( $primary['href'] ); ?>"
><?php echo esc_html( $primary['label'] ); ?></a>
</div>
<?php endif; ?>
</div>
<?php if ( $has_bar ) : ?>
<div class="hesabix2-bbp-shell__bar">
<?php if ( $has_toolbar ) : ?>
<nav class="hesabix2-bbp-shell__nav" aria-label="<?php esc_attr_e( 'ابزار انجمن', 'hesabix2' ); ?>">
<?php foreach ( $toolbar_links as $link ) : ?>
<a
class="hesabix2-bbp-shell__chip<?php echo ! empty( $link['primary'] ) ? ' hesabix2-bbp-shell__chip--active' : ''; ?>"
href="<?php echo esc_url( $link['href'] ); ?>"
><?php echo esc_html( $link['label'] ); ?></a>
<?php endforeach; ?>
</nav>
<?php endif; ?>
<?php
if ( $show_search && function_exists( 'bbp_get_template_part' ) ) {
bbp_get_template_part( 'form', 'search' );
}
?>
</div>
<?php endif; ?>
</div>
</section>
<?php
unset( $GLOBALS['hesabix2_bbp_search_compact'] );
}