*/ function aksrt_get_user_home_page_context(WP_User $user): array { $user_id = (int) $user->ID; $dashboard = function_exists('aksrt_get_user_dashboard_view') ? aksrt_get_user_dashboard_view($user_id, ['viewer_id' => get_current_user_id()]) : []; $is_own_profile = !empty($dashboard['is_own_profile']); $user_home_settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_user_home_settings() : [ 'tabs' => ['posts', 'favorites', 'comments', 'follow'], 'sidebar' => false, 'cover' => true, 'follow' => true, 'posts_per_page' => 10, ]; $user_center_settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_user_center_settings() : ['social_links' => true]; $post_count = (int) ($dashboard['post_count'] ?? 0); $comment_count = (int) ($dashboard['comment_count'] ?? 0); $favorite_post_ids = $dashboard['favorite_post_ids'] ?? []; $favorite_count = (int) ($dashboard['favorite_count'] ?? 0); $user_contacts = $dashboard['user_contacts'] ?? []; $per_page = max(1, (int) ($user_home_settings['posts_per_page'] ?? 10)); $credits_enabled = !empty($dashboard['credits_enabled']); $credit_balance = $dashboard['credit_balance'] ?? 0.0; $currency_name = $dashboard['currency_name'] ?? __('积分', 'aksrt'); $user_home_manager = class_exists('\AKSRT\User\Home') ? \AKSRT\User\Home::get_instance() : null; $visible_tabs = $user_home_manager ? $user_home_manager->get_visible_tabs($is_own_profile) : []; $enabled_tabs = array_keys($visible_tabs); if (empty($enabled_tabs)) { $enabled_tabs = ['posts', 'comments', 'favorites']; } // Apply admin-configured display order. $order = $user_home_settings['tabs_order'] ?? []; $ordered = []; foreach ((array) $order as $tab_key) { if (in_array($tab_key, $enabled_tabs, true)) { $ordered[] = $tab_key; } } foreach ($enabled_tabs as $tab_key) { if (!in_array($tab_key, $ordered, true)) { $ordered[] = $tab_key; } } $enabled_tabs = $ordered; $pc_hide = $user_home_settings['tabs_pc_hide'] ?? []; $mobile_hide = $user_home_settings['tabs_mobile_hide'] ?? []; $enabled_tabs_pc = array_values(array_diff($enabled_tabs, (array) $pc_hide)); $enabled_tabs_mobile = array_values(array_diff($enabled_tabs, (array) $mobile_hide)); $is_mobile = function_exists('wp_is_mobile') && wp_is_mobile(); $display_tabs = $is_mobile ? $enabled_tabs_mobile : $enabled_tabs_pc; $default_tab = !empty($display_tabs) ? $display_tabs[0] : $enabled_tabs[0]; $forum_instance = class_exists('\AKSRT\Forum\Forum') ? \AKSRT\Forum\Forum::get_instance() : null; $forum_stats = $forum_instance ? $forum_instance->get_user_forum_stats($user_id) : []; $forum_topic_count = (int) ($forum_stats['topic_count'] ?? 0); $product_count = 0; if (class_exists('\AKSRT\Shop\Shop')) { $product_count = (int) \AKSRT\Shop\Shop::get_instance()->count_author_products($user_id); } $follow_count = 0; if (class_exists('\AKSRT\User\Follow')) { $follow_count = (int) \AKSRT\User\Follow::get_instance()->get_follower_count($user_id); } $plate_count = 0; if ($forum_instance) { $seen_plates = []; if (method_exists($forum_instance, 'get_user_followed_plates')) { foreach ((array) $forum_instance->get_user_followed_plates($user_id) as $plate) { $pid = (int) ($plate['id'] ?? 0); if ($pid > 0) { $seen_plates[$pid] = true; } } } if (method_exists($forum_instance, 'get_user_managed_plates')) { $managed = (array) $forum_instance->get_user_managed_plates($user_id); foreach (['owned', 'moderating'] as $bucket) { foreach ((array) ($managed[$bucket] ?? []) as $plate) { $pid = (int) ($plate['id'] ?? 0); if ($pid > 0) { $seen_plates[$pid] = true; } } } } $plate_count = count($seen_plates); } $tab_counts = [ 'posts' => $post_count, 'comments' => $comment_count, 'favorites' => $favorite_count, 'credits' => $credits_enabled && $is_own_profile ? (int) round((float) $credit_balance) : 0, 'product' => $product_count, 'plate' => $plate_count, 'forum' => $forum_topic_count, 'follow' => $follow_count, ]; $tab_labels = [ 'posts' => __('文章', 'aksrt'), 'comments' => __('评论', 'aksrt'), 'favorites' => __('收藏', 'aksrt'), 'credits' => sprintf(__('我的%s', 'aksrt'), $currency_name), 'product' => __('商品', 'aksrt'), 'plate' => __('圈子', 'aksrt'), 'forum' => __('论坛', 'aksrt'), 'follow' => __('粉丝', 'aksrt'), // Zibll: 粉丝 ]; foreach ($visible_tabs as $tab_key => $tab_config) { if (!empty($tab_config['label'])) { $tab_labels[$tab_key] = (string) $tab_config['label']; } } $active_tab = isset($_GET['tab']) ? sanitize_key(wp_unslash($_GET['tab'])) : $default_tab; if (!in_array($active_tab, $enabled_tabs, true)) { $active_tab = $default_tab; } $home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : home_url('/'); return [ 'user' => $user, 'user_id' => $user_id, 'dashboard' => $dashboard, 'is_own_profile' => $is_own_profile, 'user_home_settings' => $user_home_settings, 'user_center_settings' => $user_center_settings, 'user_contacts' => $user_contacts, 'post_count' => $post_count, 'comment_count' => $comment_count, 'favorite_post_ids' => $favorite_post_ids, 'favorite_count' => $favorite_count, 'per_page' => $per_page, 'credits_enabled' => $credits_enabled, 'credit_balance' => $credit_balance, 'currency_name' => $currency_name, 'enabled_tabs' => $enabled_tabs, 'tabs_pc_hide' => (array) $pc_hide, 'tabs_mobile_hide' => (array) $mobile_hide, 'default_tab' => $default_tab, 'active_tab' => $active_tab, 'tab_counts' => $tab_counts, 'tab_labels' => $tab_labels, 'forum_instance' => $forum_instance, 'forum_stats' => $forum_stats, 'forum_topic_count' => $forum_topic_count, 'home_url' => $home_url, 'posts_page' => max(1, isset($_GET['posts_page']) ? (int) $_GET['posts_page'] : 1), 'comments_page' => max(1, isset($_GET['comments_page']) ? (int) $_GET['comments_page'] : 1), 'favorites_page' => max(1, isset($_GET['favorites_page']) ? (int) $_GET['favorites_page'] : 1), 'svg_empty_post' => '', 'svg_empty_comment' => '', 'svg_empty_favorite' => '', ]; } }