215 lines
7.8 KiB
PHP
215 lines
7.8 KiB
PHP
<?php
|
|
/**
|
|
* Header multi-function cluster (zibll zib_menu_button publish/VIP subset).
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
if (!function_exists('aksrt_get_new_add_actions')) :
|
|
/**
|
|
* Build multi-type publish actions.
|
|
*
|
|
* @param string[] $types Currently only post is supported.
|
|
* @return list<array{type:string,url:string,label:string,icon:string}>
|
|
*/
|
|
function aksrt_get_new_add_actions(array $types = ['post']): array {
|
|
$out = [];
|
|
foreach ($types as $type) {
|
|
$type = sanitize_key((string) $type);
|
|
if ($type === 'post') {
|
|
// Front submit page may be unset → aksrt_get_new_post_url() returns ''.
|
|
// Never drop the publish chip for that: fall back to WP post-new.
|
|
$url = function_exists('aksrt_get_new_post_url') ? (string) aksrt_get_new_post_url() : '';
|
|
if ($url === '') {
|
|
$url = admin_url('post-new.php');
|
|
}
|
|
$out[] = [
|
|
'type' => 'post',
|
|
'url' => $url,
|
|
'label' => __('写文章', 'aksrt'),
|
|
'icon' => 'fa fas fa-file-alt',
|
|
];
|
|
}
|
|
}
|
|
return $out;
|
|
}
|
|
endif;
|
|
|
|
if (!function_exists('aksrt_normalize_header_cta_label')) :
|
|
/**
|
|
* Normalize CTA label HTML: map FA5 classes and keep a single leading icon.
|
|
*/
|
|
function aksrt_normalize_header_cta_label(string $label, string $fallback_icon = 'fa fas fa-pen'): string {
|
|
$label = trim($label);
|
|
if ($label === '') {
|
|
return '<i class="' . esc_attr($fallback_icon) . '" aria-hidden="true"></i> ' . esc_html__('发布', 'aksrt');
|
|
}
|
|
|
|
if (stripos($label, '<i') === false) {
|
|
// No space between icon and label — spacing via CSS margin (zibll .but > .fa).
|
|
$label = '<i class="' . esc_attr($fallback_icon) . '" aria-hidden="true"></i><span class="navbar-cta-text">' . esc_html(wp_strip_all_tags($label)) . '</span>';
|
|
} else {
|
|
$label = preg_replace(
|
|
'/(<\/i>)\s*([^<].*)$/u',
|
|
'$1<span class="navbar-cta-text">$2</span>',
|
|
$label
|
|
) ?? $label;
|
|
}
|
|
|
|
return $label;
|
|
}
|
|
endif;
|
|
|
|
if (!function_exists('aksrt_render_new_add_btns')) :
|
|
/**
|
|
* Multi-type publish button (zibll newadd-btns).
|
|
*
|
|
* @param string[] $types
|
|
*/
|
|
function aksrt_render_new_add_btns(array $types, string $class = '', string $label = ''): string {
|
|
$actions = aksrt_get_new_add_actions($types);
|
|
if (!$actions) {
|
|
// Last resort: keep a write-post entry so the top-nav chip is never blank.
|
|
$fallback = function_exists('aksrt_get_new_post_url') ? (string) aksrt_get_new_post_url() : '';
|
|
if ($fallback === '') {
|
|
$fallback = admin_url('post-new.php');
|
|
}
|
|
$actions = [[
|
|
'type' => 'post',
|
|
'url' => $fallback,
|
|
'label' => __('写文章', 'aksrt'),
|
|
'icon' => 'fa fas fa-file-alt',
|
|
]];
|
|
}
|
|
if ($label === '') {
|
|
$label = __('发布', 'aksrt');
|
|
}
|
|
$label_html = aksrt_normalize_header_cta_label((string) $label, 'fa fas fa-pen');
|
|
|
|
// Split paint classes vs wrapper tokens.
|
|
$class_tokens = preg_split('/\s+/', trim($class), -1, PREG_SPLIT_NO_EMPTY) ?: [];
|
|
$cta_tokens = [];
|
|
$wrap_tokens = ['newadd-btns'];
|
|
foreach ($class_tokens as $token) {
|
|
if ($token === 'newadd-btns') {
|
|
continue;
|
|
}
|
|
if ($token === 'btn-primary' || $token === 'but' || $token === 'navbar-cta' || $token === 'radius' || $token === 'main-radius' || $token === 'mini-radius' || str_starts_with($token, 'jb-') || str_starts_with($token, 'b-')) {
|
|
$cta_tokens[] = $token;
|
|
continue;
|
|
}
|
|
$wrap_tokens[] = $token;
|
|
}
|
|
if (!$cta_tokens) {
|
|
$cta_tokens[] = 'jb-blue';
|
|
}
|
|
if (!in_array('but', $cta_tokens, true)) {
|
|
$cta_tokens[] = 'but';
|
|
}
|
|
$cta_class = trim(implode(' ', array_unique($cta_tokens)));
|
|
|
|
if (count($actions) === 1) {
|
|
$a = $actions[0];
|
|
return '<a rel="nofollow" class="' . esc_attr(trim(implode(' ', $wrap_tokens) . ' ' . $cta_class . ' navbar-cta')) . '" href="' . esc_url($a['url']) . '">'
|
|
. $label_html
|
|
. '</a>';
|
|
}
|
|
|
|
// zibll: span.newadd-btns.hover-show > toggle chip + .hover-show-con.drop-newadd
|
|
// Paint classes (jb-*, but, radius) MUST live on the toggle — wrapper is layout-only
|
|
// (background forced transparent). Bare navbar-but has no .navbar-but-cluster shell.
|
|
// data-aksrt-newadd: JS may portal menu to body so chip width cannot track menu.
|
|
$html = '<span class="' . esc_attr(trim(implode(' ', $wrap_tokens) . ' hover-show')) . '" data-aksrt-newadd="1">';
|
|
$html .= '<span class="newadd-btns__toggle navbar-cta ' . esc_attr($cta_class) . '">' . $label_html
|
|
. '<i class="fa fas fa-caret-down" aria-hidden="true"></i></span>';
|
|
$html .= '<div class="hover-show-con dropdown-menu drop-newadd" role="menu">';
|
|
foreach ($actions as $a) {
|
|
$html .= '<a rel="nofollow" class="btn-newadd newadd-btns__item" role="menuitem" href="' . esc_url($a['url']) . '">';
|
|
$html .= '<i class="' . esc_attr($a['icon']) . '" aria-hidden="true"></i> '
|
|
. '<text>' . esc_html($a['label']) . '</text>';
|
|
$html .= '</a>';
|
|
}
|
|
$html .= '</div></span>';
|
|
return $html;
|
|
}
|
|
endif;
|
|
|
|
if (!function_exists('aksrt_render_header_menu_buttons')) :
|
|
/**
|
|
* Publish + optional VIP open button for header CTA.
|
|
*/
|
|
function aksrt_render_header_menu_buttons(): string {
|
|
$settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::read_domain('page_display', 'header-nav') : [];
|
|
$types = is_array($settings['nav_newposts_btns'] ?? null)
|
|
? array_values(array_intersect(array_map('sanitize_key', $settings['nav_newposts_btns']), ['post']))
|
|
: ['post'];
|
|
if (!$types) {
|
|
$types = ['post'];
|
|
}
|
|
$cfg = [
|
|
'enabled' => !isset($settings['nav_newposts']) || !empty($settings['nav_newposts']),
|
|
'text' => trim((string) ($settings['nav_newposts_text'] ?? __('发布', 'aksrt'))),
|
|
'radius_pill' => !isset($settings['nav_newposts_radius']) || !empty($settings['nav_newposts_radius']),
|
|
'class' => sanitize_html_class((string) (($settings['nav_newposts_class'] ?? '') ?: 'jb-blue')),
|
|
'types' => $types,
|
|
];
|
|
$html = '';
|
|
if (!empty($cfg['enabled'])) {
|
|
// zibll default: but nowave jb-blue (+ radius).
|
|
$class = 'but nowave navbar-newposts';
|
|
$skin = trim((string) ($cfg['class'] ?? ''));
|
|
if ($skin === '') {
|
|
$skin = 'jb-blue';
|
|
}
|
|
$class .= ' ' . $skin;
|
|
$pill = !empty($cfg['radius_pill']);
|
|
if ($pill && !str_contains($class, 'radius')) {
|
|
$class .= ' radius';
|
|
}
|
|
$label = (string) ($cfg['text'] ?? __('发布', 'aksrt'));
|
|
$btn = aksrt_render_new_add_btns($cfg['types'] ?? ['post'], $class, $label);
|
|
if ($btn !== '') {
|
|
$html .= $btn;
|
|
}
|
|
}
|
|
|
|
// VIP open CTA for guests / non-VIP (zibll: .pay-vip modal).
|
|
$user_id = get_current_user_id();
|
|
$show_vip = false;
|
|
if (class_exists('\AKSRT\Settings\Settings')) {
|
|
$vs = \AKSRT\Settings\Settings::get_payment_vip_settings();
|
|
$show_vip = !empty($vs['enabled']);
|
|
}
|
|
if ($show_vip) {
|
|
$is_vip = false;
|
|
if ($user_id > 0 && function_exists('aksrt_get_user_vip_level')) {
|
|
$is_vip = (int) aksrt_get_user_vip_level($user_id) > 0;
|
|
}
|
|
if (!$is_vip) {
|
|
$cls = $user_id > 0 ? 'pay-vip' : 'signin-loader';
|
|
$hover = '';
|
|
if (class_exists('\AKSRT\Content\VipService')) {
|
|
$svc = \AKSRT\Content\VipService::get_instance();
|
|
if (method_exists($svc, 'render_vip_card')) {
|
|
$cards = $svc->render_vip_card(1, $user_id) . $svc->render_vip_card(2, $user_id);
|
|
if ($cards !== '') {
|
|
$hover = '<div class="hover-show-con sub-menu sub-vip-card">' . $cards . '</div>';
|
|
}
|
|
}
|
|
}
|
|
// zibll: span.hover-show wraps button + .hover-show-con.sub-vip-card
|
|
$html .= '<span class="hover-show inline-block navbar-vip-hover">';
|
|
$html .= '<a class="but jb-red radius payvip-icon ml10 navbar-cta ' . esc_attr($cls) . '" href="javascript:;"'
|
|
. ($user_id > 0 ? ' vip-level="1"' : '') . '>';
|
|
$html .= '<svg class="icon em12 mr3" aria-hidden="true"><use xlink:href="#icon-vip_1"></use></svg>'
|
|
. '<span class="navbar-cta-text">' . esc_html__('开通会员', 'aksrt') . '</span>';
|
|
$html .= '</a>' . $hover . '</span>';
|
|
}
|
|
}
|
|
|
|
return $html;
|
|
}
|
|
endif;
|