refactor: flatten src/AKSRT → src (drop theme-identifier dir)

Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
This commit is contained in:
2026-08-02 22:06:06 +08:00
parent 56f1a8175f
commit 8c5b1555c9
285 changed files with 26 additions and 3600 deletions
+58
View File
@@ -0,0 +1,58 @@
<?php
/**
* @package AKSRT
*/
namespace AKSRT\Frontend;
defined('ABSPATH') || exit;
class CustomCodeRenderer {
public function output_header(): void {
$custom_css = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::custom_css()
: aksrt_get_setting('custom_css', '');
$head_code = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::custom_head_code()
: aksrt_get_setting('custom_head_code', get_option('aksrt_custom_head_code', ''));
$trackcode = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::trackcode()
: '';
echo $this->format((string) $custom_css, 'css', 'aksrt-custom-css');
if ($head_code) {
echo $this->format((string) $head_code, 'js', 'aksrt-custom-js-header');
}
if ($trackcode) {
echo $this->format((string) $trackcode, 'js', 'aksrt-trackcode');
}
}
public function output_footer(): void {
$footer_code = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::custom_footer_code()
: aksrt_get_setting('custom_footer_code', get_option('aksrt_custom_footer_code', ''));
if ($footer_code) {
echo $this->format((string) $footer_code, 'js', 'aksrt-custom-js-footer');
}
}
private function format(string $code, string $type, string $id): string {
$code = trim($code);
if ($code === '') {
return '';
}
if (preg_match('/<\s*(script|style|meta|link|noscript)\b/i', $code)) {
return $code . "\n";
}
if ($type === 'css') {
return '<style id="' . esc_attr($id) . '">' . "\n" . $code . "\n</style>\n";
}
return '<script id="' . esc_attr($id) . '">' . "\n" . $code . "\n</script>\n";
}
}
+192
View File
@@ -0,0 +1,192 @@
<?php
/**
* @package AKSRT
*/
namespace AKSRT\Frontend;
defined('ABSPATH') || exit;
class InlineStyleBuilder {
public function output(): void {
$logo_url = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::logo_url() : (string) aksrt_get_setting('logo_url', '');
$dark_logo_url = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::logo_dark_url() : (string) aksrt_get_setting('site_logo_dark', '');
$favicon = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::favicon_url() : (string) aksrt_get_setting('favicon_url', '');
$primary_color = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::resolved_primary_color() : '#f04494';
$dark_primary = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::dark_primary_color() : '#f04494';
$border_radius = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::border_radius() : 8;
$card_radius = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::card_radius() : ($border_radius + 4);
$container_max = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::container_max_width() : 1200;
$font_family = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::font_family() : 'system';
$logo_width = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::logo_width() : 150;
$sidebar_cfg = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_sidebar_config() : ['width' => 311, 'enabled' => true, 'position' => 'right'];
$content_width = $container_max === 0 ? '100%' : $container_max . 'px';
$content_no_sidebar_max = $container_max === 0 ? '100%' : max(860, $container_max - 220) . 'px';
$container_wide = $container_max === 0 ? '100%' : max(1280, $container_max + 160) . 'px';
$radius_sm = max(0, $border_radius - 2);
$radius_lg = $border_radius + 4;
$radius_xl = $border_radius + 10;
$rgb = $this->hex_to_rgb($primary_color);
$primary_hover = $this->adjust_hex_color($primary_color, -0.12);
$primary_active = $this->adjust_hex_color($primary_color, -0.22);
$font_stacks = $this->resolve_font_stacks($font_family);
$dark_rgb = $this->hex_to_rgb($dark_primary);
$dark_hover = $this->adjust_hex_color($dark_primary, -0.12);
$dark_active = $this->adjust_hex_color($dark_primary, -0.22);
// Zibll hard-codes 311px dual-column math; keep runtime width aligned to that
// baseline when settings still hold the old 300 default (or empty).
$sidebar_width = (int) ($sidebar_cfg['width'] ?? 311);
if ($sidebar_width <= 0 || $sidebar_width === 300) {
$sidebar_width = 311;
}
$sidebar_width = max(200, min(400, $sidebar_width));
$layout_vars = [
'--content-max' => $content_width,
'--content-no-sidebar-max' => $content_no_sidebar_max,
'--container' => $content_width,
'--container-wide' => $container_wide,
'--mian-max-width' => $content_width, // zibll typo token
'--sidebar-width' => $sidebar_width . 'px',
'--color-primary' => $primary_color,
'--color-primary-hover' => $primary_hover,
'--color-primary-active' => $primary_active,
'--color-primary-soft' => sprintf('rgba(%d, %d, %d, 0.12)', $rgb[0], $rgb[1], $rgb[2]),
'--color-primary-softer' => sprintf('rgba(%d, %d, %d, 0.06)', $rgb[0], $rgb[1], $rgb[2]),
'--color-primary-rgb' => implode(', ', $rgb),
'--focus-color' => $primary_color,
'--radius-sm' => $radius_sm . 'px',
'--radius' => $border_radius . 'px',
'--radius-card' => $card_radius . 'px',
// Zibll --main-radius tracks the base radius (8), not the larger card radius.
'--main-radius' => $border_radius . 'px',
'--radius-btn' => $border_radius . 'px',
'--radius-code' => $border_radius . 'px',
'--radius-lg' => $radius_lg . 'px',
'--radius-xl' => $radius_xl . 'px',
'--shadow-md' => '0 8px 24px rgba(20, 28, 48, 0.10)',
'--main-shadow' => 'rgba(116, 116, 116, 0.08)',
'--font-body' => $font_stacks['body'],
'--font-display' => $font_stacks['display'],
'--font-ui' => $font_stacks['ui'],
'--font-heading' => $font_stacks['ui'],
'--aksrt-logo-width' => $logo_width . 'px',
'--nav-height' => '60px',
'--single-cover-scale' => '35%',
'--posts-list-scale' => (class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['list_scale'] ?? 70 : 70) . '%',
'--posts-card-scale' => (class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['card_scale'] ?? 70 : 70) . '%',
];
echo '<style id="aksrt-runtime-vars">:root{';
foreach ($layout_vars as $name => $value) {
echo esc_html($name) . ':' . esc_attr($value) . ';';
}
if ($logo_url) {
echo '--aksrt-logo-url:"' . esc_url($logo_url) . '";';
}
if ($dark_logo_url) {
echo '--aksrt-logo-dark-url:"' . esc_url($dark_logo_url) . '";';
}
if ($favicon) {
echo '--aksrt-favicon:"' . esc_url($favicon) . '";';
}
if ($dark_primary !== $primary_color) {
echo '}html.dark{';
echo '--color-primary:' . esc_attr($dark_primary) . ';';
echo '--color-primary-hover:' . esc_attr($dark_hover) . ';';
echo '--color-primary-active:' . esc_attr($dark_active) . ';';
echo '--color-primary-soft:' . sprintf('rgba(%d,%d,%d,0.12)', $dark_rgb[0], $dark_rgb[1], $dark_rgb[2]) . ';';
echo '--color-primary-softer:' . sprintf('rgba(%d,%d,%d,0.06)', $dark_rgb[0], $dark_rgb[1], $dark_rgb[2]) . ';';
echo '--color-primary-rgb:' . esc_attr(implode(', ', $dark_rgb)) . ';';
echo '--focus-color:' . esc_attr($dark_primary) . ';';
}
echo '}</style>' . "\n";
// Zibll header_theme_custom → --header-bg / --header-color on .header.
if (class_exists('\AKSRT\Settings\Settings')) {
$ht = \AKSRT\Settings\Settings::get_header_theme_config();
if (!empty($ht['custom'])) {
$h_bg = $ht['bg_custom'] !== '' ? $ht['bg_custom'] : ($ht['bg'] ?? '');
$h_fg = $ht['color_custom'] ?? '';
if ($h_bg !== '' || $h_fg !== '') {
echo '<style id="aksrt-header-theme">.header{';
if ($h_bg !== '') {
echo '--header-bg:' . esc_attr($h_bg) . ';background:' . esc_attr($h_bg) . ';';
}
if ($h_fg !== '') {
echo '--header-color:' . esc_attr($h_fg) . ';color:' . esc_attr($h_fg) . ';';
}
echo '}</style>' . "\n";
}
}
}
if (class_exists('\AKSRT\Settings\Settings') && !empty(\AKSRT\Settings\Settings::get_value('close_backdrop', false))) {
echo '<style id="aksrt-no-backdrop">.aksrt-header,.header-inner,.site-header,.header,.mobile-nav-overlay,.modal-backdrop,.aksrt-drawer-overlay,.aksrt-float-btn,.sidebar-inner{backdrop-filter:none!important;-webkit-backdrop-filter:none!important;background-color:var(--bg-card,#fff)!important}</style>' . "\n";
}
echo '<style id="aksrt-runtime-components">'
. '.aksrt-search-hot-keywords{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:12px;font-family:var(--font-ui);}'
. '.aksrt-search-hot-keywords__label{font-size:12px;color:var(--color-ink-3);}'
. '.aksrt-search-hot-keywords__list{display:flex;gap:8px;flex-wrap:wrap;}'
. '.aksrt-search-hot-keywords__item{display:inline-flex;align-items:center;padding:4px 10px;border-radius:999px;background:var(--surface-2,#f3f4f6);color:var(--color-ink-2,#374151);font-size:12px;line-height:1.4;text-decoration:none;}'
. '.aksrt-search-hot-keywords__item:hover{background:var(--color-primary,#2563eb);color:#fff;}'
. '.site-footer__copyright--extra{margin-top:8px;opacity:.78;}'
. '</style>' . "\n";
}
private function resolve_font_stacks(string $family): array {
switch ($family) {
case 'noto-sans-sc':
return [
'body' => '"Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif',
'display' => '"Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif',
'ui' => 'Inter, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif',
];
case 'noto-serif-sc':
return [
'body' => '"Noto Serif SC", Georgia, "Songti SC", serif',
'display' => '"Noto Serif SC", Georgia, "Songti SC", serif',
'ui' => 'Inter, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif',
];
default:
return [
'body' => '"Source Serif 4", "Noto Serif SC", Georgia, "Songti SC", "STSong", serif',
'display' => '"Source Serif 4", "Noto Serif SC", Georgia, "Songti SC", "STSong", serif',
'ui' => 'Inter, Manrope, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',
];
}
}
private function hex_to_rgb(string $hex): array {
$hex = ltrim($hex, '#');
if (strlen($hex) === 3) {
$hex = preg_replace('/(.)/', '$1$1', $hex);
}
if (!is_string($hex) || strlen($hex) !== 6) {
return [136, 171, 218];
}
return [
hexdec(substr($hex, 0, 2)),
hexdec(substr($hex, 2, 2)),
hexdec(substr($hex, 4, 2)),
];
}
private function adjust_hex_color(string $hex, float $amount): string {
$rgb = $this->hex_to_rgb($hex);
$adjusted = array_map(
static function (int $channel) use ($amount): int {
$base = $amount >= 0
? $channel + ((255 - $channel) * $amount)
: $channel * (1 + $amount);
return max(0, min(255, (int) round($base)));
},
$rgb
);
return sprintf('#%02X%02X%02X', $adjusted[0], $adjusted[1], $adjusted[2]);
}
}
+66
View File
@@ -0,0 +1,66 @@
<?php
/**
* @package AKSRT
*/
namespace AKSRT\Frontend;
defined('ABSPATH') || exit;
class LoadingOverlayRenderer {
public function output(): void {
if (!class_exists('\AKSRT\Settings\Settings') || !\AKSRT\Settings\Settings::is_qj_loading_enabled()) {
return;
}
$style = \AKSRT\Settings\Settings::get_qj_loading_style();
?>
<style id="aksrt-loading-css">
.aksrt-loading-overlay{position:fixed;inset:0;z-index:99999;display:flex;align-items:center;justify-content:center;background:var(--bg-card,#fff);transition:opacity .4s ease,visibility .4s ease}
.aksrt-loading-overlay .loader{width:48px;height:48px;position:relative}
[data-loading-style="no1"] .loader{border:4px solid var(--color-primary-soft,rgba(240,68,148,.15));border-top-color:var(--color-primary,#f04494);border-radius:50%;animation:aksrt-load-spin .8s linear infinite}
[data-loading-style="no2"] .loader{border:4px solid var(--color-primary-soft,rgba(240,68,148,.15));border-radius:50%;animation:aksrt-load-pulse 1.2s ease-in-out infinite}
[data-loading-style="no3"] .loader::before,[data-loading-style="no3"] .loader::after{content:'';position:absolute;border-radius:50%;animation:aksrt-load-ripple 1.6s linear infinite;border:3px solid var(--color-primary,#f04494);inset:0}
[data-loading-style="no3"] .loader::after{animation-delay:-.8s}
[data-loading-style="no4"] .loader{display:flex;gap:6px;align-items:center;justify-content:center}
[data-loading-style="no4"] .loader::before,[data-loading-style="no4"] .loader::after,[data-loading-style="no4"] .loader i{width:12px;height:12px;border-radius:50%;background:var(--color-primary,#f04494);display:block;animation:aksrt-load-bounce .6s ease-in-out infinite alternate}
[data-loading-style="no4"] .loader::after{animation-delay:.2s}
[data-loading-style="no4"] .loader i{animation-delay:.4s}
[data-loading-style="no5"] .loader{background:var(--color-primary,#f04494);animation:aksrt-load-rotate-square 1.2s ease-in-out infinite}
[data-loading-style="no6"] .loader{width:60px;height:6px;border-radius:3px;background:var(--color-primary-soft,rgba(240,68,148,.15));overflow:hidden;position:relative}
[data-loading-style="no6"] .loader::after{content:'';position:absolute;left:-40%;top:0;width:40%;height:100%;background:var(--color-primary,#f04494);border-radius:3px;animation:aksrt-load-bar 1.2s ease-in-out infinite}
[data-loading-style="no7"] .loader{display:grid;grid-template-columns:repeat(3,1fr);gap:4px}
[data-loading-style="no7"] .loader i{width:12px;height:12px;background:var(--color-primary,#f04494);border-radius:2px;animation:aksrt-load-grid-fade 1s ease-in-out infinite}
[data-loading-style="no7"] .loader i:nth-child(1){animation-delay:0s}[data-loading-style="no7"] .loader i:nth-child(2){animation-delay:.1s}[data-loading-style="no7"] .loader i:nth-child(3){animation-delay:.2s}
[data-loading-style="no7"] .loader i:nth-child(4){animation-delay:.3s}[data-loading-style="no7"] .loader i:nth-child(5){animation-delay:.4s}[data-loading-style="no7"] .loader i:nth-child(6){animation-delay:.5s}
[data-loading-style="no7"] .loader i:nth-child(7){animation-delay:.6s}[data-loading-style="no7"] .loader i:nth-child(8){animation-delay:.7s}[data-loading-style="no7"] .loader i:nth-child(9){animation-delay:.8s}
[data-loading-style="no8"] .loader{display:flex;gap:5px;align-items:flex-end;height:40px}
[data-loading-style="no8"] .loader i{width:6px;background:var(--color-primary,#f04494);border-radius:2px;animation:aksrt-load-wave 1s ease-in-out infinite}
[data-loading-style="no8"] .loader i:nth-child(1){animation-delay:0s}[data-loading-style="no8"] .loader i:nth-child(2){animation-delay:.1s}[data-loading-style="no8"] .loader i:nth-child(3){animation-delay:.2s}
[data-loading-style="no8"] .loader i:nth-child(4){animation-delay:.3s}[data-loading-style="no8"] .loader i:nth-child(5){animation-delay:.4s}
[data-loading-style="no9"] .loader{display:flex;gap:8px;align-items:center;justify-content:center}
[data-loading-style="no9"] .loader i{width:10px;height:10px;background:var(--color-primary,#f04494);border-radius:50%;animation:aksrt-load-dot-scale .8s ease-in-out infinite alternate}
[data-loading-style="no9"] .loader i:nth-child(2){animation-delay:.15s}[data-loading-style="no9"] .loader i:nth-child(3){animation-delay:.3s}
[data-loading-style="no10"] .loader{border:4px solid transparent;border-top-color:var(--color-primary,#f04494);border-bottom-color:var(--color-primary,#f04494);border-radius:50%;animation:aksrt-load-spin 1s linear infinite}
[data-loading-style="no10"] .loader::after{content:'';position:absolute;inset:4px;border:4px solid transparent;border-left-color:var(--color-primary-soft,rgba(240,68,148,.35));border-right-color:var(--color-primary-soft,rgba(240,68,148,.35));border-radius:50%;animation:aksrt-load-spin .6s linear infinite reverse}
@keyframes aksrt-load-spin{to{transform:rotate(360deg)}}
@keyframes aksrt-load-pulse{0%,100%{transform:scale(1);opacity:1}50%{transform:scale(1.15);opacity:.5}}
@keyframes aksrt-load-ripple{0%{transform:scale(.5);opacity:1}100%{transform:scale(1.2);opacity:0}}
@keyframes aksrt-load-bounce{to{transform:translateY(-12px);opacity:.5}}
@keyframes aksrt-load-rotate-square{0%{transform:rotate(0) scale(1)}50%{transform:rotate(180deg) scale(.6)}100%{transform:rotate(360deg) scale(1)}}
@keyframes aksrt-load-bar{0%{left:-40%}100%{left:100%}}
@keyframes aksrt-load-grid-fade{0%,100%{opacity:.3;transform:scale(.8)}50%{opacity:1;transform:scale(1)}}
@keyframes aksrt-load-wave{0%,100%{height:10px}50%{height:36px}}
@keyframes aksrt-load-dot-scale{from{transform:scale(1)}to{transform:scale(1.8);opacity:.4}}
body.aksrt-loading-done .aksrt-loading-overlay{opacity:0;visibility:hidden;pointer-events:none}
[data-theme="dark"] .aksrt-loading-overlay{background:var(--bg-card,#1a1a2e)}
</style>
<div class="aksrt-loading-overlay" data-loading-style="<?php echo esc_attr($style); ?>">
<div class="loader"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></div>
</div>
<script>
(function(){function d(){document.body.classList.add('aksrt-loading-done')}if(document.readyState==='complete'){d()}else{window.addEventListener('load',d)}})();
</script>
<?php
}
}
+215
View File
@@ -0,0 +1,215 @@
<?php
/**
* Nav walker — zibll senior submenu + meta decorations.
*
* @package AKSRT
*/
namespace AKSRT\Frontend;
defined('ABSPATH') || exit;
class NavWalker extends \Walker_Nav_Menu {
/** @var array<string,mixed> */
private $settings;
/** @var int[] */
public static $submenu_ids = [];
/**
* @param array<string,mixed> $settings
*/
public function __construct(array $settings = []) {
$this->settings = $settings ?: (
function_exists('aksrt_get_menu_decoration_settings')
? aksrt_get_menu_decoration_settings()
: ['icon_enabled' => true, 'badge_enabled' => true]
);
}
/**
* Skip WP children when parent uses senior submenu.
*/
public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) {
if (!empty($element->menu_item_parent) && in_array((int) $element->menu_item_parent, self::$submenu_ids, true)) {
return;
}
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
public function start_el(&$output, $item, $depth = 0, $args = null, $id = 0): void {
$title = '<span class="menu-item-title">' . $item->title . '</span>';
$icon_enabled = !empty($this->settings['icon_enabled']);
$badge_enabled = !empty($this->settings['badge_enabled']);
$icon = function_exists('aksrt_menu_pz') ? (string) aksrt_menu_pz((int) $item->ID, 'icon', '') : '';
$badge = function_exists('aksrt_menu_pz') ? (string) aksrt_menu_pz((int) $item->ID, 'badge', '') : '';
$badge_class = function_exists('aksrt_menu_pz') ? (string) aksrt_menu_pz((int) $item->ID, 'badge_class', '') : '';
if ($icon && function_exists('aksrt_render_menu_icon')) {
$title = aksrt_render_menu_icon($icon, $icon_enabled) . $title;
}
if ($badge && function_exists('aksrt_render_menu_badge')) {
$title .= aksrt_render_menu_badge($badge, $badge_class, $badge_enabled);
}
$item->title = $title;
$submenu = '';
if (function_exists('aksrt_menu_pz') && aksrt_menu_pz((int) $item->ID, 'submenu_s') && (int) $depth === 0) {
$submenu = $this->submenu((int) $item->ID);
}
if ($submenu) {
$item->classes = is_array($item->classes) ? $item->classes : [];
$item->classes[] = 'menu-item-has-children';
self::$submenu_ids[] = (int) $item->ID;
}
parent::start_el($output, $item, $depth, $args, $id);
$output .= $submenu;
}
/**
* @param int $item_id
*/
public function submenu(int $item_id): string {
$type = function_exists('aksrt_menu_pz') ? sanitize_key((string) aksrt_menu_pz($item_id, 'submenu_type', '')) : '';
$method = 'submenu_' . $type;
if ($type !== '' && method_exists($this, $method)) {
return (string) $this->$method($item_id);
}
return '';
}
/**
* Graphic card mega menu.
*/
public function submenu_graphic_card(int $item_id): string {
$opts = function_exists('aksrt_menu_pz') ? aksrt_menu_pz($item_id, 'graphic_card_opts', []) : [];
$opts = is_array($opts) ? $opts : [];
$items = is_array($opts['items'] ?? null) ? $opts['items'] : [];
if (!$items) {
return '';
}
$arrangement = (string) ($opts['arrangement'] ?? '');
$lists = '';
$i = 0;
foreach ($items as $item) {
$item_html = $this->submenu_graphic_card_item(is_array($item) ? $item : []);
if ($item_html === '') {
continue;
}
$ani = 'style="--ani-delay:' . ($i * 0.05) . 's;"';
$cls = $arrangement === 'swiper' ? 'swiper-slide' : '';
$lists .= '<div class="' . esc_attr($cls) . '" ' . $ani . '>' . $item_html . '</div>';
$i++;
}
if ($lists === '') {
return '';
}
$align = (string) ($opts['align'] ?? '');
$lists_box = '<div class="graphic-card-items-box flex hh' . ($align ? ' ' . esc_attr($align) : '') . '">' . $lists . '</div>';
if ($arrangement === 'swiper') {
$lists_box = '<div class="swiper-container swiper-scroll"><div class="swiper-wrapper">'
. $lists . '</div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div>';
}
$size = !empty($opts['size']) ? ' size-' . sanitize_key((string) $opts['size']) : '';
$img_scale = isset($opts['img_scale']) ? (int) $opts['img_scale'] : 0;
$scale_attr = '';
if ($img_scale && $img_scale !== 100) {
$scale_attr = ' style="--img-scale:' . esc_attr((string) round($img_scale / 100, 2)) . ';"';
}
return '<div class="sub-menu senior-submenu submenu-graphic-card' . esc_attr($size) . '"' . $scale_attr . '><div class="container">'
. $lists_box . '</div></div>';
}
/**
* @param array<string,mixed> $args
*/
public function submenu_graphic_card_item(array $args): string {
if (empty($args['img'])) {
return '';
}
$link_url = !empty($args['link']['url']) ? esc_url((string) $args['link']['url']) : 'javascript:;';
$link_title = (string) ($args['link']['text'] ?? '');
$link_target = !empty($args['link']['target']) ? ' target="' . esc_attr((string) $args['link']['target']) . '"' : '';
$title = (string) ($args['title'] ?? '');
if ($title === '' && $link_title !== '') {
$title = $link_title;
}
$badge = !empty($args['badge'])
? '<div class="img-badg-box"><span class="badg badg-sm ' . esc_attr((string) ($args['badge_class'] ?? '')) . '">'
. esc_html((string) $args['badge']) . '</span></div>'
: '';
$img_html = '<div class="img-box hover-zoom-img"><img src="' . esc_url((string) $args['img']) . '" alt="" loading="lazy">' . $badge . '</div>';
$title_html = $title !== '' ? '<div class="title mt10 text-ellipsis">' . esc_html($title) . '</div>' : '';
return '<div class="menu-graphic-card-item"><a href="' . $link_url . '"' . $link_target . '>'
. $img_html . $title_html . '</a></div>';
}
/**
* Multi-column links mega menu.
*/
public function submenu_multi_column_links(int $item_id): string {
$opts = function_exists('aksrt_menu_pz') ? aksrt_menu_pz($item_id, 'multi_column_links_opts', []) : [];
$opts = is_array($opts) ? $opts : [];
$columns = is_array($opts['columns'] ?? null) ? $opts['columns'] : [];
if (!$columns) {
return '';
}
$lists = '';
$i = 1;
foreach ($columns as $column) {
if (!is_array($column)) {
continue;
}
$ani = 'style="--ani-delay:' . ($i * 0.08) . 's;"';
$lists .= '<div class="links-column flex-auto" ' . $ani . '>';
$lists .= $this->submenu_multi_column_links_item($column, 'column-title');
$lists .= '<div class="links-items">';
if (!empty($column['items']) && is_array($column['items'])) {
foreach ($column['items'] as $item) {
if (is_array($item)) {
$lists .= $this->submenu_multi_column_links_item($item, '');
}
}
}
$lists .= '</div></div>';
$i++;
}
return '<div class="sub-menu senior-submenu submenu-multi-column-links"><div class="container"><div class="links-columns-box flex jsa hh">'
. $lists . '</div></div></div>';
}
/**
* @param array<string,mixed> $args
*/
public function submenu_multi_column_links_item(array $args, string $class = ''): string {
$title = (string) ($args['title'] ?? '');
$link_url = (string) ($args['link']['url'] ?? '');
$link_title = (string) ($args['link']['text'] ?? '');
if ($title === '' && $link_title !== '') {
$title = $link_title;
}
if ($title === '') {
return '';
}
$icon = '';
if (!empty($args['icon']) && function_exists('aksrt_render_menu_icon')) {
$icon = aksrt_render_menu_icon((string) $args['icon'], true);
}
if (!empty($args['img_icon'])) {
$icon = '<img class="menu-item-icon mr3 fa-fw" src="' . esc_url((string) $args['img_icon']) . '" alt="" loading="lazy">';
}
$title_html = $icon . $title;
$class = trim(($class ? $class . ' ' : '') . 'link-item');
if ($link_url !== '') {
$target = !empty($args['link']['target']) ? ' target="' . esc_attr((string) $args['link']['target']) . '"' : '';
return '<div class="' . esc_attr($class) . '"><a href="' . esc_url($link_url) . '"' . $target . '>'
. $title_html . '<i class="fa fa-angle-double-right icon-hover-show" aria-hidden="true"></i></a></div>';
}
return '<div class="' . esc_attr($class) . '"><a href="javascript:;">' . $title_html . '</a></div>';
}
}
+260
View File
@@ -0,0 +1,260 @@
<?php
/**
* WeChat JS-SDK share signature (zibll ZibWeChatShare parity).
*
* @package AKSRT
*/
namespace AKSRT\Frontend;
defined('ABSPATH') || exit;
class WeChatShare {
private static $instance = null;
/** @var array{wechat_enabled:bool,wechat_appid:string,wechat_app_secret:string,only_logo:bool} */
private $config = [];
public static function get_instance(): self {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
public function init(): void {
$this->config = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_share_settings()
: [];
if (empty($this->config['wechat_enabled'])) {
return;
}
if (empty($this->config['wechat_appid']) || empty($this->config['wechat_app_secret'])) {
return;
}
add_action('wp_enqueue_scripts', [$this, 'enqueue_sdk'], 20);
add_action('wp_footer', [$this, 'print_share_date'], 99);
}
public function enqueue_sdk(): void {
// Only needed in WeChat browser, but enqueue lightly for all (script is external CDN).
wp_enqueue_script(
'aksrt-jweixin',
'https://res.wx.qq.com/open/js/jweixin-1.6.0.js',
[],
'1.6.0',
true
);
// Ensure our bridge runs after jweixin.
if (wp_script_is('aksrt-weixin-share', 'registered') || wp_script_is('aksrt-weixin-share', 'enqueued')) {
wp_script_add_data('aksrt-weixin-share', 'group', 1);
}
}
public function print_share_date(): void {
$url = $this->current_url();
$sign = $this->get_sign($url);
if (!$sign) {
return;
}
$img = $this->resolve_image();
$title = wp_get_document_title();
$desc = '';
if (is_singular()) {
$post = get_post();
if ($post) {
$desc = wp_strip_all_tags(get_the_excerpt($post));
}
}
if ($desc === '') {
$desc = (string) get_bloginfo('description');
}
$payload = [
'appId' => $sign['appId'],
'timestamp' => (string) $sign['timestamp'],
'nonceStr' => $sign['nonceStr'],
'signature' => $sign['signature'],
'url' => $url,
'title' => $title,
'img' => $img,
'desc' => $desc,
];
?>
<script type="text/javascript">
window.WeChatShareDate = <?php echo wp_json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>;
(function () {
function applyConfig() {
if (!window.wx || typeof window.wx.config !== 'function' || !window.WeChatShareDate) return;
var e = window.WeChatShareDate;
try {
window.wx.config({
debug: false,
appId: e.appId,
timestamp: e.timestamp,
nonceStr: e.nonceStr,
signature: e.signature,
jsApiList: ['updateTimelineShareData', 'updateAppMessageShareData']
});
window.wx.ready(function () {
var title = e.title || document.title;
var link = e.url || window.location.href;
var desc = e.desc || ((document.querySelector('meta[name="description"]') || {}).content || '');
var img = e.img || '';
if (typeof window.wx.updateTimelineShareData === 'function') {
window.wx.updateTimelineShareData({ title: title, link: link, imgUrl: img });
}
if (typeof window.wx.updateAppMessageShareData === 'function') {
window.wx.updateAppMessageShareData({ title: title, desc: desc, link: link, imgUrl: img });
}
});
} catch (err) {}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function () { setTimeout(applyConfig, 50); });
} else {
setTimeout(applyConfig, 50);
}
})();
</script>
<?php
}
/**
* @return array{appId:string,nonceStr:string,timestamp:int,signature:string}|null
*/
public function get_sign(string $url): ?array {
$ticket = $this->get_jsapi_ticket();
if ($ticket === '') {
return null;
}
$timestamp = time();
$nonce = $this->nonce_string();
$raw = "jsapi_ticket={$ticket}&noncestr={$nonce}&timestamp={$timestamp}&url={$url}";
return [
'appId' => (string) $this->config['wechat_appid'],
'nonceStr' => $nonce,
'timestamp' => $timestamp,
'signature' => sha1($raw),
];
}
private function current_url(): string {
$https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|| (isset($_SERVER['SERVER_PORT']) && (int) $_SERVER['SERVER_PORT'] === 443)
|| (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https');
$protocol = $https ? 'https://' : 'http://';
$host = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash((string) $_SERVER['HTTP_HOST'])) : wp_parse_url(home_url('/'), PHP_URL_HOST);
$uri = isset($_SERVER['REQUEST_URI']) ? (string) wp_unslash($_SERVER['REQUEST_URI']) : '/';
// Drop hash fragment if any (should not be present in REQUEST_URI).
return $protocol . $host . $uri;
}
private function resolve_image(): string {
$only_logo = !empty($this->config['only_logo']);
$default = '';
if (!empty($this->config['share_img'])) {
$default = (string) $this->config['share_img'];
} elseif (class_exists('\AKSRT\Settings\Settings')) {
$default = (string) (\AKSRT\Settings\Settings::get_value('favicon', '') ?: \AKSRT\Settings\Settings::get_value('iconpng', ''));
}
if ($only_logo) {
return $default;
}
$pic = '';
if (is_singular()) {
$post_id = get_queried_object_id();
if ($post_id && has_post_thumbnail($post_id)) {
$pic = (string) get_the_post_thumbnail_url($post_id, 'full');
}
} elseif (is_author()) {
$author = get_queried_object();
if ($author && !empty($author->ID)) {
$pic = (string) get_user_meta((int) $author->ID, 'custom_avatar', true);
if ($pic === '') {
$pic = get_avatar_url((int) $author->ID, ['size' => 300]);
}
}
} elseif (is_category() || is_tag() || is_tax()) {
$term = get_queried_object();
if ($term && !empty($term->term_id)) {
$img_id = (int) get_term_meta((int) $term->term_id, 'thumbnail_id', true);
if ($img_id) {
$pic = (string) (wp_get_attachment_image_url($img_id, 'full') ?: '');
}
}
}
return $pic !== '' ? $pic : $default;
}
private function get_jsapi_ticket(): string {
$opt = get_option('aksrt_wechatshare_ticket', []);
$now = time() + 300;
if (is_array($opt) && !empty($opt['ticket']) && !empty($opt['expiration_time']) && (int) $opt['expiration_time'] > $now) {
return (string) $opt['ticket'];
}
$token = $this->get_access_token();
if ($token === '') {
return '';
}
$url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . rawurlencode($token) . '&type=jsapi';
$res = $this->http_json($url);
if (empty($res['ticket'])) {
return '';
}
$res['expiration_time'] = time() + max(60, (int) ($res['expires_in'] ?? 7200));
update_option('aksrt_wechatshare_ticket', $res, false);
return (string) $res['ticket'];
}
private function get_access_token(): string {
// Prefer shared GZH token cache when present.
$opt = get_option('aksrt_weixingzh_access_token', []);
$now = time() + 300;
if (is_array($opt) && !empty($opt['access_token']) && !empty($opt['expiration_time']) && (int) $opt['expiration_time'] > $now) {
return (string) $opt['access_token'];
}
$appid = (string) $this->config['wechat_appid'];
$secret = (string) $this->config['wechat_app_secret'];
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . rawurlencode($appid) . '&secret=' . rawurlencode($secret);
$res = $this->http_json($url);
if (empty($res['access_token'])) {
return '';
}
$res['expiration_time'] = time() + max(60, (int) ($res['expires_in'] ?? 7200));
update_option('aksrt_weixingzh_access_token', $res, false);
return (string) $res['access_token'];
}
/**
* @return array<string,mixed>
*/
private function http_json(string $url): array {
$response = wp_remote_get($url, [
'timeout' => 8,
'headers' => ['Accept' => 'application/json'],
]);
if (is_wp_error($response)) {
return [];
}
$body = (string) wp_remote_retrieve_body($response);
$data = json_decode($body, true);
return is_array($data) ? $data : [];
}
private function nonce_string(int $length = 16): string {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$str = '';
$max = strlen($chars) - 1;
for ($i = 0; $i < $length; $i++) {
$str .= $chars[random_int(0, $max)];
}
return $str;
}
}