405 lines
13 KiB
PHP
405 lines
13 KiB
PHP
<?php
|
||
/**
|
||
* ادغام bbPress با Hesabix2
|
||
*
|
||
* @package Hesabix2
|
||
*/
|
||
|
||
if ( ! defined( 'ABSPATH' ) ) {
|
||
exit;
|
||
}
|
||
|
||
if ( ! hesabix2_bbpress_is_active() ) {
|
||
return;
|
||
}
|
||
|
||
/**
|
||
* اعلام پشتیبانی قالب از bbPress
|
||
*/
|
||
function hesabix2_bbpress_theme_support() {
|
||
add_theme_support( 'bbpress' );
|
||
}
|
||
add_action( 'after_setup_theme', 'hesabix2_bbpress_theme_support', 20 );
|
||
|
||
/**
|
||
* حذف لفاف و breadcrumb پیشفرض bbPress
|
||
*/
|
||
function hesabix2_bbpress_setup_integrations() {
|
||
if ( ! function_exists( 'bbpress' ) ) {
|
||
return;
|
||
}
|
||
|
||
$theme = bbpress()->theme_compat->theme;
|
||
if ( is_object( $theme ) ) {
|
||
remove_action( 'bbp_before_main_content', array( $theme, 'before_main_content' ) );
|
||
remove_action( 'bbp_after_main_content', array( $theme, 'after_main_content' ) );
|
||
}
|
||
|
||
add_filter( 'bbp_no_breadcrumb', '__return_true' );
|
||
}
|
||
add_action( 'bbp_init', 'hesabix2_bbpress_setup_integrations', 20 );
|
||
|
||
/**
|
||
* کلاس body
|
||
*
|
||
* @param array $classes
|
||
* @return array
|
||
*/
|
||
function hesabix2_bbpress_body_class( $classes ) {
|
||
if ( hesabix2_is_bbpress_page() ) {
|
||
$classes[] = 'is-bbpress';
|
||
$classes[] = 'hesabix2-bbpress';
|
||
}
|
||
return $classes;
|
||
}
|
||
add_filter( 'body_class', 'hesabix2_bbpress_body_class' );
|
||
|
||
/**
|
||
* حذف پیشوند «بایگانیها» در عنوان آرشیو وردپرس روی صفحات انجمن
|
||
*
|
||
* @param string $title
|
||
* @return string
|
||
*/
|
||
function hesabix2_bbpress_archive_title( $title ) {
|
||
if ( ! hesabix2_is_bbpress_page() ) {
|
||
return $title;
|
||
}
|
||
$heading = hesabix2_bbpress_page_heading();
|
||
return $heading ? $heading : wp_strip_all_tags( $title );
|
||
}
|
||
add_filter( 'get_the_archive_title', 'hesabix2_bbpress_archive_title' );
|
||
|
||
/**
|
||
* عنوان تب مرورگر برای انجمن
|
||
*
|
||
* @param array $parts
|
||
* @return array
|
||
*/
|
||
function hesabix2_bbpress_document_title( $parts ) {
|
||
if ( ! hesabix2_is_bbpress_page() ) {
|
||
return $parts;
|
||
}
|
||
$heading = hesabix2_bbpress_page_heading();
|
||
if ( $heading ) {
|
||
$parts['title'] = $heading;
|
||
}
|
||
return $parts;
|
||
}
|
||
add_filter( 'document_title_parts', 'hesabix2_bbpress_document_title' );
|
||
|
||
/**
|
||
* هدایت برگههای ورود/ثبتنام bbPress به قالب hesabix2
|
||
*/
|
||
function hesabix2_bbpress_auth_page_redirect() {
|
||
if ( ! is_page() ) {
|
||
return;
|
||
}
|
||
|
||
$page_id = (int) get_queried_object_id();
|
||
if ( $page_id < 1 ) {
|
||
return;
|
||
}
|
||
|
||
$login_id = (int) get_option( '_bbp_page_for_login' );
|
||
$register_id = (int) get_option( '_bbp_page_for_register' );
|
||
|
||
if ( $login_id && $page_id === $login_id ) {
|
||
$url = hesabix2_bbpress_login_url();
|
||
if ( $url && untrailingslashit( $url ) !== untrailingslashit( get_permalink( $page_id ) ) ) {
|
||
wp_safe_redirect( $url );
|
||
exit;
|
||
}
|
||
}
|
||
|
||
if ( $register_id && $page_id === $register_id ) {
|
||
$url = hesabix2_bbpress_register_url();
|
||
if ( $url && untrailingslashit( $url ) !== untrailingslashit( get_permalink( $page_id ) ) ) {
|
||
wp_safe_redirect( $url );
|
||
exit;
|
||
}
|
||
}
|
||
}
|
||
add_action( 'template_redirect', 'hesabix2_bbpress_auth_page_redirect' );
|
||
|
||
/**
|
||
* بازگشت پس از ورود به انجمن
|
||
*
|
||
* @param string $redirect_to
|
||
* @return string
|
||
*/
|
||
function hesabix2_bbpress_login_redirect( $redirect_to ) {
|
||
if ( $redirect_to ) {
|
||
return $redirect_to;
|
||
}
|
||
$root = hesabix2_bbpress_root_url();
|
||
return $root ? $root : home_url( '/' );
|
||
}
|
||
add_filter( 'bbp_user_login_redirect_to', 'hesabix2_bbpress_login_redirect' );
|
||
|
||
/**
|
||
* جلوگیری از ثبت CSS پیشفرض بستهٔ bbPress
|
||
*/
|
||
function hesabix2_bbpress_disable_default_pack_styles() {
|
||
if ( ! hesabix2_is_bbpress_page() || ! function_exists( 'bbpress' ) ) {
|
||
return;
|
||
}
|
||
|
||
$theme = bbpress()->theme_compat->theme;
|
||
if ( is_object( $theme ) && is_callable( array( $theme, 'enqueue_styles' ) ) ) {
|
||
remove_action( 'bbp_enqueue_scripts', array( $theme, 'enqueue_styles' ) );
|
||
}
|
||
}
|
||
add_action( 'bbp_enqueue_scripts', 'hesabix2_bbpress_disable_default_pack_styles', 1 );
|
||
|
||
/**
|
||
* حذف CSS پیشفرض bbPress (پشتیبان)
|
||
*/
|
||
function hesabix2_bbpress_dequeue_default_styles() {
|
||
if ( ! hesabix2_is_bbpress_page() ) {
|
||
return;
|
||
}
|
||
wp_dequeue_style( 'bbp-default' );
|
||
wp_deregister_style( 'bbp-default' );
|
||
wp_dequeue_style( 'bbp-default-rtl' );
|
||
wp_deregister_style( 'bbp-default-rtl' );
|
||
}
|
||
add_action( 'wp_enqueue_scripts', 'hesabix2_bbpress_dequeue_default_styles', 999 );
|
||
|
||
/**
|
||
* استایل اختصاصی انجمن
|
||
*/
|
||
function hesabix2_bbpress_enqueue_styles() {
|
||
if ( ! hesabix2_is_bbpress_page() ) {
|
||
return;
|
||
}
|
||
|
||
$css_path = get_template_directory() . '/assets/css/bbpress.css';
|
||
if ( ! is_readable( $css_path ) ) {
|
||
return;
|
||
}
|
||
|
||
$deps = array( 'hesabix2-style' );
|
||
wp_enqueue_style(
|
||
'hesabix2-bbpress',
|
||
get_template_directory_uri() . '/assets/css/bbpress.css',
|
||
$deps,
|
||
(string) filemtime( $css_path )
|
||
);
|
||
}
|
||
add_action( 'wp_enqueue_scripts', 'hesabix2_bbpress_enqueue_styles', 110 );
|
||
|
||
/**
|
||
* برچسبهای فارسی رایج bbPress در قالب (بدون ویرایش فایلهای افزونه)
|
||
*
|
||
* @param string $translation
|
||
* @param string $text
|
||
* @param string $domain
|
||
* @return string
|
||
*/
|
||
function hesabix2_bbpress_gettext( $translation, $text, $domain ) {
|
||
if ( 'bbpress' !== $domain || ! hesabix2_is_bbpress_page() ) {
|
||
return $translation;
|
||
}
|
||
|
||
static $map = null;
|
||
if ( null === $map ) {
|
||
$map = array(
|
||
'Author' => 'نویسنده',
|
||
'Creator' => 'نویسنده',
|
||
'Replies' => 'پاسخها',
|
||
'Posts' => 'نوشتهها',
|
||
'Topic' => 'موضوع',
|
||
'Topics' => 'موضوعات',
|
||
'Forum' => 'انجمن',
|
||
'Forums' => 'انجمنها',
|
||
'Search Results' => 'نتایج جستجو',
|
||
'Search' => 'جستجو',
|
||
'Started by: %1$s' => 'شروعشده توسط: %1$s',
|
||
'in: %1$s' => 'در: %1$s',
|
||
'Profile' => 'پروفایل',
|
||
'Topics Started' => 'موضوعات ایجادشده',
|
||
'Forum Topics Started' => 'موضوعات ایجادشده',
|
||
'Replies Created' => 'پاسخهای ایجادشده',
|
||
'Forum Replies Created' => 'پاسخهای ایجادشده',
|
||
'Favorites' => 'علاقهمندیها',
|
||
'Subscriptions' => 'اشتراکها',
|
||
'Engagements' => 'تعاملات',
|
||
'Edit' => 'ویرایش',
|
||
'Reply' => 'پاسخ',
|
||
'Submit' => 'ارسال',
|
||
'Cancel' => 'انصراف',
|
||
'Register' => 'ثبتنام',
|
||
'Log In' => 'ورود',
|
||
'Log Out' => 'خروج',
|
||
'Create New Topic' => 'موضوع جدید',
|
||
'Reply To: %s' => 'پاسخ به: %s',
|
||
'Oh, bother! No topics were found here.' => 'هنوز موضوعی در این بخش ثبت نشده است.',
|
||
'Oh, bother! No forums were found here.' => 'هنوز انجمنی ایجاد نشده است.',
|
||
'Oh, bother! No replies were found here.' => 'هنوز پاسخی ثبت نشده است.',
|
||
'Last Activity: %s' => 'آخرین فعالیت: %s',
|
||
'Registered: %s' => 'عضویت: %s',
|
||
'Website: %s' => 'وبسایت: %s',
|
||
'Voices' => 'نویسندگان',
|
||
'Last Post' => 'آخرین نوشته',
|
||
'Subscribe' => 'اشتراک',
|
||
'Unsubscribe' => 'لغو اشتراک',
|
||
'Favorite' => 'علاقهمندی',
|
||
'Unfavorite' => 'حذف علاقهمندی',
|
||
'Tagged:' => 'برچسبها:',
|
||
'Viewing %1$s post' => '%1$s نوشته',
|
||
'Viewing %1$s posts' => '%1$s نوشته',
|
||
'Viewing %2$s post (of %4$s total)' => 'نمایش %2$s از %4$s نوشته',
|
||
'Viewing %1$s posts - %2$s through %3$s (of %4$s total)' => 'نمایش %2$s تا %3$s از %4$s نوشته',
|
||
'Viewing %1$s reply' => '%1$s پاسخ',
|
||
'Viewing %1$s replies' => '%1$s پاسخ',
|
||
'Viewing %2$s replies (of %4$s total)' => 'نمایش %2$s از %4$s پاسخ',
|
||
'Viewing %1$s replies - %2$s through %3$s (of %4$s total)' => 'نمایش %2$s تا %3$s از %4$s پاسخ',
|
||
);
|
||
}
|
||
|
||
return isset( $map[ $text ] ) ? $map[ $text ] : $translation;
|
||
}
|
||
add_filter( 'gettext', 'hesabix2_bbpress_gettext', 20, 3 );
|
||
|
||
/**
|
||
* توضیح انجمن/موضوع بهصورت خط متا فشرده (بدون باکس اعلان بزرگ)
|
||
*
|
||
* @param string $html
|
||
* @return string
|
||
*/
|
||
function hesabix2_bbpress_compact_description_html( $html ) {
|
||
$text = trim( wp_strip_all_tags( $html ) );
|
||
if ( '' === $text ) {
|
||
return '';
|
||
}
|
||
return '<p class="hesabix2-bbp-meta">' . esc_html( $text ) . '</p>';
|
||
}
|
||
add_filter( 'bbp_get_single_forum_description', 'hesabix2_bbpress_compact_description_html', 20 );
|
||
|
||
/**
|
||
* آمار موضوع بهصورت یک خط فشرده
|
||
*
|
||
* @param string $html
|
||
* @param array $r
|
||
* @param array $args
|
||
* @return string
|
||
*/
|
||
function hesabix2_bbpress_compact_topic_description( $html, $r = array(), $args = array() ) {
|
||
if ( ! function_exists( 'bbp_get_topic_id' ) ) {
|
||
return hesabix2_bbpress_compact_description_html( $html );
|
||
}
|
||
|
||
$topic_id = bbp_get_topic_id( isset( $r['topic_id'] ) ? (int) $r['topic_id'] : 0 );
|
||
if ( ! $topic_id ) {
|
||
return hesabix2_bbpress_compact_description_html( $html );
|
||
}
|
||
|
||
$reply_count = function_exists( 'bbp_get_topic_reply_count' )
|
||
? (int) bbp_get_topic_reply_count( $topic_id, true, false )
|
||
: 0;
|
||
$voice_count = function_exists( 'bbp_get_topic_voice_count' )
|
||
? (int) bbp_get_topic_voice_count( $topic_id, true, false )
|
||
: 0;
|
||
|
||
$parts = array();
|
||
|
||
if ( $reply_count > 0 ) {
|
||
$parts[] = sprintf(
|
||
/* translators: %s: reply count */
|
||
_n( '%s پاسخ', '%s پاسخ', $reply_count, 'hesabix2' ),
|
||
bbp_number_format( $reply_count )
|
||
);
|
||
}
|
||
|
||
if ( $voice_count > 0 ) {
|
||
$parts[] = sprintf(
|
||
/* translators: %s: participant count */
|
||
_n( '%s کاربر', '%s کاربر', $voice_count, 'hesabix2' ),
|
||
bbp_number_format( $voice_count )
|
||
);
|
||
}
|
||
|
||
$last_active = function_exists( 'bbp_get_topic_last_active_id' ) ? bbp_get_topic_last_active_id( $topic_id ) : 0;
|
||
if ( $last_active && function_exists( 'bbp_get_topic_freshness_link' ) ) {
|
||
$freshness = bbp_get_topic_freshness_link( $topic_id );
|
||
$author = function_exists( 'bbp_get_author_link' )
|
||
? bbp_get_author_link(
|
||
array(
|
||
'post_id' => $last_active,
|
||
'size' => 14,
|
||
'type' => 'name',
|
||
)
|
||
)
|
||
: '';
|
||
if ( $freshness && $author ) {
|
||
$parts[] = sprintf(
|
||
/* translators: 1: time link, 2: author link */
|
||
__( 'آخرین: %1$s — %2$s', 'hesabix2' ),
|
||
$freshness,
|
||
$author
|
||
);
|
||
} elseif ( $freshness ) {
|
||
$parts[] = sprintf(
|
||
/* translators: %s: time link */
|
||
__( 'آخرین: %s', 'hesabix2' ),
|
||
$freshness
|
||
);
|
||
}
|
||
}
|
||
|
||
if ( empty( $parts ) ) {
|
||
return '';
|
||
}
|
||
|
||
return '<p class="hesabix2-bbp-meta hesabix2-bbp-meta--topic">' . implode( ' · ', $parts ) . '</p>';
|
||
}
|
||
add_filter( 'bbp_get_single_topic_description', 'hesabix2_bbpress_compact_topic_description', 20, 3 );
|
||
|
||
/**
|
||
* شمارنده صفحهبندی پاسخها — متن کوتاه
|
||
*
|
||
* @param string $retstr
|
||
* @return string
|
||
*/
|
||
function hesabix2_bbpress_compact_topic_pagination_count( $retstr ) {
|
||
if ( ! function_exists( 'bbpress' ) ) {
|
||
return $retstr;
|
||
}
|
||
|
||
$bbp = bbpress();
|
||
if ( ! isset( $bbp->reply_query ) || ! is_object( $bbp->reply_query ) ) {
|
||
return $retstr;
|
||
}
|
||
|
||
$total_int = (int) $bbp->reply_query->found_posts;
|
||
if ( $total_int < 1 ) {
|
||
return '';
|
||
}
|
||
|
||
$ppp_int = max( 1, (int) $bbp->reply_query->posts_per_page );
|
||
$paged = max( 1, (int) $bbp->reply_query->paged );
|
||
$start_int = (int) ( ( $paged - 1 ) * $ppp_int ) + 1;
|
||
$to_int = (int) min( $start_int + $ppp_int - 1, $total_int );
|
||
|
||
$total_num = bbp_number_format( $total_int );
|
||
|
||
if ( $total_int <= $ppp_int ) {
|
||
return sprintf(
|
||
/* translators: %s: post count */
|
||
_n( '%s نوشته', '%s نوشته', $total_int, 'hesabix2' ),
|
||
$total_num
|
||
);
|
||
}
|
||
|
||
$from_num = bbp_number_format( $start_int );
|
||
$to_num = bbp_number_format( $to_int );
|
||
|
||
return sprintf(
|
||
/* translators: 1: from, 2: to, 3: total */
|
||
__( 'نمایش %1$s–%2$s از %3$s نوشته', 'hesabix2' ),
|
||
$from_num,
|
||
$to_num,
|
||
$total_num
|
||
);
|
||
}
|
||
add_filter( 'bbp_get_topic_pagination_count', 'hesabix2_bbpress_compact_topic_pagination_count' );
|