Merge pull request 'Worktree ux depth batch10' (#228) from worktree-ux-depth-batch10 into main
Reviewed-on: CYL/wordpress-theme-aksrt#228
This commit is contained in:
commit
9fd7257d94
10 files changed
+666
-149
No files matched your search
@@ -364,6 +364,10 @@ html.dark .article-end-separator span {
|
|||||||
color: var(--color-primary);
|
color: var(--color-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toc-list .toc-h1 a {
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
.toc-list .toc-h3 a {
|
.toc-list .toc-h3 a {
|
||||||
padding-left: 12px;
|
padding-left: 12px;
|
||||||
}
|
}
|
||||||
@@ -372,6 +376,30 @@ html.dark .article-end-separator span {
|
|||||||
padding-left: 24px;
|
padding-left: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* WidgetPostsNavs + built-in shell share .posts-nav-box.toc-widget */
|
||||||
|
.widget .posts-nav-box.toc-widget,
|
||||||
|
.widget_aksrt_posts_navs .posts-nav-box.toc-widget {
|
||||||
|
margin: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget .posts-nav-box.toc-widget > h3,
|
||||||
|
.widget .posts-nav-box.toc-widget .toc-widget__title,
|
||||||
|
.widget_aksrt_posts_navs .posts-nav-box.toc-widget > h3 {
|
||||||
|
margin: 0 0 10px;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.single .sidebar .posts-nav-box.toc-widget.is-affix,
|
||||||
|
body.single .sidebar .posts-nav-box.toc-widget[data-affix="true"] {
|
||||||
|
position: sticky;
|
||||||
|
top: calc(var(--nav-height, 60px) + 16px);
|
||||||
|
}
|
||||||
|
|
||||||
.toc-float-btn {
|
.toc-float-btn {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
right: 18px;
|
right: 18px;
|
||||||
|
|||||||
@@ -883,3 +883,123 @@
|
|||||||
.aksrt-tag-cloud .c-red-2 { background: #fecaca; color: #991b1b; }
|
.aksrt-tag-cloud .c-red-2 { background: #fecaca; color: #991b1b; }
|
||||||
|
|
||||||
.aksrt-home-widget__ajax .ajax-pag { margin-top: 12px; text-align: center; }
|
.aksrt-home-widget__ajax .ajax-pag { margin-top: 12px; text-align: center; }
|
||||||
|
|
||||||
|
/* ---- batch10: user-card more-posts + slider wrap + ranking top badge ---- */
|
||||||
|
.user-card-posts .more-posts-mini .item {
|
||||||
|
padding: 6px 0;
|
||||||
|
border-bottom: 1px dashed var(--color-line, rgba(0, 0, 0, 0.06));
|
||||||
|
}
|
||||||
|
.user-card-posts .more-posts-mini .item:last-child { border-bottom: 0; }
|
||||||
|
.user-card-posts .more-posts-mini .item a {
|
||||||
|
display: block;
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.user-card-posts .more-posts-mini .item a:hover {
|
||||||
|
color: var(--color-primary, #3b82f6);
|
||||||
|
}
|
||||||
|
.user-card-posts .more-posts.swiper-container {
|
||||||
|
margin: 8px 0 0;
|
||||||
|
padding: 0 2px 4px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.user-card-posts .more-posts .swiper-slide {
|
||||||
|
width: auto;
|
||||||
|
max-width: 46%;
|
||||||
|
}
|
||||||
|
.aksrt-more-post-card {
|
||||||
|
display: block;
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--surface-2, #f8fafc);
|
||||||
|
}
|
||||||
|
.aksrt-more-post-card__thumb {
|
||||||
|
display: block;
|
||||||
|
aspect-ratio: 16 / 10;
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--surface-3, #eef2f7);
|
||||||
|
}
|
||||||
|
.aksrt-more-post-card__thumb img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.aksrt-more-post-card__body {
|
||||||
|
display: block;
|
||||||
|
padding: 6px 8px 8px;
|
||||||
|
}
|
||||||
|
.aksrt-more-post-card__title {
|
||||||
|
display: block;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.35;
|
||||||
|
}
|
||||||
|
.aksrt-more-post-card__meta {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 6px;
|
||||||
|
margin-top: 4px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.aksrt-widget-slider-wrap {
|
||||||
|
border-radius: 10px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.aksrt-widget-slider-wrap .new-swiper {
|
||||||
|
--pc-height: 220px;
|
||||||
|
--m-height: 180px;
|
||||||
|
height: var(--pc-height);
|
||||||
|
}
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.aksrt-widget-slider-wrap .new-swiper {
|
||||||
|
height: var(--m-height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.aksrt-widget-slider-wrap .swiper-slide img.fit-cover {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.aksrt-widget-slider-wrap .aksrt-slide-text {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
padding: 18px 14px 12px;
|
||||||
|
background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
|
||||||
|
color: #fff;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.aksrt-widget-slider-wrap .aksrt-slide-text__title {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.aksrt-widget-slider-wrap .aksrt-slide-text__desc {
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: 0.9;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.muted-box.c-red,
|
||||||
|
.c-red.muted-box {
|
||||||
|
color: #b91c1c;
|
||||||
|
background: #fef2f2;
|
||||||
|
border: 1px solid #fecaca;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 12px 14px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ranking empty state */
|
||||||
|
.aksrt-user-ranking__empty {
|
||||||
|
margin: 8px 0 0;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--muted-2-color, #999);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
+59
-17
@@ -19,9 +19,31 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initPostToc() {
|
function initPostToc() {
|
||||||
var content = document.querySelector('.wp-posts-content[data-nav="posts"][data-aksrt-toc="1"]');
|
// Accept either explicit data-aksrt-toc="1" or any [data-nav] article body.
|
||||||
var tocWidget = document.querySelector('.posts-nav-box.toc-widget');
|
var content =
|
||||||
var tocList = tocWidget ? tocWidget.querySelector('.toc-list') : null;
|
document.querySelector('.wp-posts-content[data-nav="posts"][data-aksrt-toc="1"]') ||
|
||||||
|
document.querySelector('.wp-posts-content[data-nav]') ||
|
||||||
|
document.querySelector('[data-nav="posts"]') ||
|
||||||
|
document.querySelector('[data-nav]');
|
||||||
|
|
||||||
|
// Support multiple TOC shells (built-in single sidebar + WidgetPostsNavs).
|
||||||
|
var tocWidgets = Array.prototype.slice.call(
|
||||||
|
document.querySelectorAll('.posts-nav-box.toc-widget, .posts-nav-box[data-title]')
|
||||||
|
);
|
||||||
|
var tocLists = [];
|
||||||
|
tocWidgets.forEach(function (box) {
|
||||||
|
if (!box.classList.contains('toc-widget')) {
|
||||||
|
box.classList.add('toc-widget');
|
||||||
|
}
|
||||||
|
var list = box.querySelector('.toc-list');
|
||||||
|
if (!list) {
|
||||||
|
list = document.createElement('ol');
|
||||||
|
list.className = 'toc-list';
|
||||||
|
box.appendChild(list);
|
||||||
|
}
|
||||||
|
tocLists.push(list);
|
||||||
|
});
|
||||||
|
|
||||||
var mobileToggle = document.querySelector('.toc-float-btn');
|
var mobileToggle = document.querySelector('.toc-float-btn');
|
||||||
var drawer = document.querySelector('.toc-drawer');
|
var drawer = document.querySelector('.toc-drawer');
|
||||||
var overlay = document.querySelector('.toc-drawer-overlay');
|
var overlay = document.querySelector('.toc-drawer-overlay');
|
||||||
@@ -29,16 +51,25 @@
|
|||||||
var closeBtn = drawer ? drawer.querySelector('.toc-drawer__close') : null;
|
var closeBtn = drawer ? drawer.querySelector('.toc-drawer__close') : null;
|
||||||
|
|
||||||
if (!content || content.dataset.aksrtTocBound === '1') return;
|
if (!content || content.dataset.aksrtTocBound === '1') return;
|
||||||
if (!tocList && !drawerList && !mobileToggle) return;
|
if (!tocLists.length && !drawerList && !mobileToggle) return;
|
||||||
|
|
||||||
content.dataset.aksrtTocBound = '1';
|
content.dataset.aksrtTocBound = '1';
|
||||||
|
|
||||||
var maxDepth = parseInt(content.dataset.aksrtTocDepth || '3', 10) || 3;
|
var maxDepth = parseInt(content.dataset.aksrtTocDepth || '3', 10) || 3;
|
||||||
|
// zibll section-navs: only fill when heading count > 2 (≥3).
|
||||||
|
var MIN_HEADINGS = 3;
|
||||||
|
|
||||||
function getHeadings() {
|
function getHeadings() {
|
||||||
return Array.prototype.slice.call(content.querySelectorAll('h2, h3, h4')).filter(function (heading) {
|
// zibll scans h1–h4 inside [data-nav]; depth setting still caps lower levels.
|
||||||
|
return Array.prototype.slice.call(content.querySelectorAll('h1, h2, h3, h4')).filter(function (heading) {
|
||||||
|
if (heading.closest('.no-nav') || heading.classList.contains('item-heading')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var level = parseInt((heading.tagName || 'H2').replace('H', ''), 10) || 2;
|
var level = parseInt((heading.tagName || 'H2').replace('H', ''), 10) || 2;
|
||||||
return level <= maxDepth;
|
// toc_depth is typically 2–4 meaning deepest heading level from h2 baseline;
|
||||||
|
// allow h1 always, then h2..h(1+maxDepth) capped at h4.
|
||||||
|
if (level === 1) return true;
|
||||||
|
return level <= Math.min(4, maxDepth + 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +77,7 @@
|
|||||||
if (!container) return false;
|
if (!container) return false;
|
||||||
|
|
||||||
var headings = getHeadings();
|
var headings = getHeadings();
|
||||||
if (!headings.length) return false;
|
if (headings.length < MIN_HEADINGS) return false;
|
||||||
|
|
||||||
var html = '';
|
var html = '';
|
||||||
headings.forEach(function (heading) {
|
headings.forEach(function (heading) {
|
||||||
@@ -55,7 +86,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var levelClass = '';
|
var levelClass = '';
|
||||||
if (heading.tagName === 'H3') {
|
if (heading.tagName === 'H1') {
|
||||||
|
levelClass = 'toc-h1';
|
||||||
|
} else if (heading.tagName === 'H3') {
|
||||||
levelClass = 'toc-h3';
|
levelClass = 'toc-h3';
|
||||||
} else if (heading.tagName === 'H4') {
|
} else if (heading.tagName === 'H4') {
|
||||||
levelClass = 'toc-h4';
|
levelClass = 'toc-h4';
|
||||||
@@ -68,13 +101,24 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasToc = buildToc(tocList);
|
var hasToc = false;
|
||||||
if (drawerList && drawerList !== tocList) {
|
tocLists.forEach(function (list) {
|
||||||
buildToc(drawerList);
|
if (buildToc(list)) hasToc = true;
|
||||||
|
});
|
||||||
|
if (drawerList && tocLists.indexOf(drawerList) === -1) {
|
||||||
|
if (buildToc(drawerList)) hasToc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasToc) {
|
if (!hasToc) {
|
||||||
if (tocWidget) tocWidget.remove();
|
tocWidgets.forEach(function (box) {
|
||||||
|
var host = box.closest('.widget') || box.parentElement;
|
||||||
|
// Prefer removing the whole widget chrome when empty.
|
||||||
|
if (host && host !== document.body && host.querySelectorAll('.posts-nav-box').length <= 1) {
|
||||||
|
host.remove();
|
||||||
|
} else {
|
||||||
|
box.remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
if (mobileToggle) mobileToggle.remove();
|
if (mobileToggle) mobileToggle.remove();
|
||||||
if (drawer) drawer.remove();
|
if (drawer) drawer.remove();
|
||||||
if (overlay) overlay.remove();
|
if (overlay) overlay.remove();
|
||||||
@@ -94,7 +138,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function trackActiveHeading() {
|
function trackActiveHeading() {
|
||||||
var headings = content.querySelectorAll('h2[id], h3[id], h4[id]');
|
var headings = content.querySelectorAll('h1[id], h2[id], h3[id], h4[id]');
|
||||||
if (!headings.length) return;
|
if (!headings.length) return;
|
||||||
|
|
||||||
var activeId = '';
|
var activeId = '';
|
||||||
@@ -117,10 +161,8 @@
|
|||||||
if (!target) return;
|
if (!target) return;
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
target.scrollIntoView({
|
var top = target.getBoundingClientRect().top + window.pageYOffset - 105;
|
||||||
behavior: 'smooth',
|
window.scrollTo({ top: Math.max(0, top), behavior: 'smooth' });
|
||||||
block: 'start'
|
|
||||||
});
|
|
||||||
closeDrawer();
|
closeDrawer();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ require_once AKSRT_DIR . '/inc/helpers/aksrt-header-userbox.php';
|
|||||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-header-menu-buttons.php';
|
require_once AKSRT_DIR . '/inc/helpers/aksrt-header-menu-buttons.php';
|
||||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-runtime-win.php';
|
require_once AKSRT_DIR . '/inc/helpers/aksrt-runtime-win.php';
|
||||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-identity.php';
|
require_once AKSRT_DIR . '/inc/helpers/aksrt-identity.php';
|
||||||
|
require_once AKSRT_DIR . '/inc/helpers/aksrt-user-card.php';
|
||||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-rewards.php';
|
require_once AKSRT_DIR . '/inc/helpers/aksrt-rewards.php';
|
||||||
require_once AKSRT_DIR . '/inc/helpers/menu-decoration.php';
|
require_once AKSRT_DIR . '/inc/helpers/menu-decoration.php';
|
||||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-transactions.php';
|
require_once AKSRT_DIR . '/inc/helpers/aksrt-transactions.php';
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Shared user-card / author-card render helpers (zibll zib_get_user_card_box parity).
|
||||||
|
*
|
||||||
|
* @package AKSRT
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('ABSPATH') || exit;
|
||||||
|
|
||||||
|
if (!function_exists('aksrt_user_card_query_posts')) :
|
||||||
|
/**
|
||||||
|
* Author posts for card strip.
|
||||||
|
*
|
||||||
|
* @param array<string,mixed> $args
|
||||||
|
* @return list<\WP_Post>
|
||||||
|
*/
|
||||||
|
function aksrt_user_card_query_posts(array $args): array {
|
||||||
|
$user_id = (int) ($args['user_id'] ?? 0);
|
||||||
|
$limit = max(0, min(20, (int) ($args['limit'] ?? 6)));
|
||||||
|
if ($user_id <= 0 || $limit <= 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderby = sanitize_key((string) ($args['orderby'] ?? 'date'));
|
||||||
|
$post_type = sanitize_key((string) ($args['post_type'] ?? 'post'));
|
||||||
|
if (!post_type_exists($post_type)) {
|
||||||
|
$post_type = 'post';
|
||||||
|
}
|
||||||
|
|
||||||
|
$query_args = [
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'post_type' => $post_type,
|
||||||
|
'author' => $user_id,
|
||||||
|
'posts_per_page' => $limit,
|
||||||
|
'ignore_sticky_posts' => true,
|
||||||
|
'no_found_rows' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$exclude = (int) ($args['exclude'] ?? 0);
|
||||||
|
if ($exclude <= 0) {
|
||||||
|
$exclude = (int) get_the_ID();
|
||||||
|
}
|
||||||
|
if ($exclude > 0) {
|
||||||
|
$query_args['post__not_in'] = [$exclude];
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($orderby) {
|
||||||
|
case 'views':
|
||||||
|
case 'view':
|
||||||
|
$query_args['meta_key'] = 'aksrt_post_views';
|
||||||
|
$query_args['orderby'] = 'meta_value_num';
|
||||||
|
$query_args['order'] = 'DESC';
|
||||||
|
break;
|
||||||
|
case 'comment_count':
|
||||||
|
case 'comments':
|
||||||
|
$query_args['orderby'] = 'comment_count';
|
||||||
|
$query_args['order'] = 'DESC';
|
||||||
|
break;
|
||||||
|
case 'modified':
|
||||||
|
$query_args['orderby'] = 'modified';
|
||||||
|
$query_args['order'] = 'DESC';
|
||||||
|
break;
|
||||||
|
case 'rand':
|
||||||
|
case 'random':
|
||||||
|
$query_args['orderby'] = 'rand';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$query_args['orderby'] = 'date';
|
||||||
|
$query_args['order'] = 'DESC';
|
||||||
|
}
|
||||||
|
|
||||||
|
$q = new WP_Query($query_args);
|
||||||
|
$posts = $q->posts;
|
||||||
|
wp_reset_postdata();
|
||||||
|
return is_array($posts) ? array_values(array_filter($posts, static fn($p) => $p instanceof WP_Post)) : [];
|
||||||
|
}
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if (!function_exists('aksrt_render_user_card_posts')) :
|
||||||
|
/**
|
||||||
|
* Render more-posts strip (card swiper-scroll or mini list).
|
||||||
|
*
|
||||||
|
* @param array<string,mixed> $args
|
||||||
|
*/
|
||||||
|
function aksrt_render_user_card_posts(array $args): string {
|
||||||
|
$style = sanitize_key((string) ($args['post_style'] ?? $args['style'] ?? 'mini'));
|
||||||
|
if (!in_array($style, ['card', 'mini'], true)) {
|
||||||
|
$style = 'mini';
|
||||||
|
}
|
||||||
|
$posts = aksrt_user_card_query_posts($args);
|
||||||
|
$show_empty = !empty($args['show_empty']);
|
||||||
|
|
||||||
|
if (!$posts) {
|
||||||
|
if (!$show_empty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return '<div class="user-card-posts mt10 muted-2-color em09 text-center">' .
|
||||||
|
esc_html__('暂无更多文章', 'aksrt') .
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
echo '<div class="user-card-posts mt10">';
|
||||||
|
if ($style === 'card') {
|
||||||
|
echo '<div class="swiper-container more-posts swiper-scroll"><div class="swiper-wrapper">';
|
||||||
|
foreach ($posts as $rp) {
|
||||||
|
$thumb = get_the_post_thumbnail_url($rp, 'medium');
|
||||||
|
$title = get_the_title($rp);
|
||||||
|
$time = function_exists('aksrt_time_ago')
|
||||||
|
? aksrt_time_ago((string) $rp->post_date)
|
||||||
|
: human_time_diff((int) get_the_time('U', $rp), (int) current_time('timestamp')) . __('前', 'aksrt');
|
||||||
|
$views = function_exists('aksrt_get_post_views') ? (int) aksrt_get_post_views($rp->ID) : 0;
|
||||||
|
echo '<div class="swiper-slide mr10">';
|
||||||
|
echo '<a class="aksrt-more-post-card" href="' . esc_url(get_permalink($rp)) . '">';
|
||||||
|
if ($thumb) {
|
||||||
|
echo '<span class="aksrt-more-post-card__thumb"><img class="fit-cover" src="' . esc_url($thumb) . '" alt="" loading="lazy" decoding="async" /></span>';
|
||||||
|
}
|
||||||
|
echo '<span class="aksrt-more-post-card__body">';
|
||||||
|
echo '<span class="aksrt-more-post-card__title text-ellipsis">' . esc_html($title) . '</span>';
|
||||||
|
echo '<span class="aksrt-more-post-card__meta muted-2-color em09">';
|
||||||
|
echo '<item>' . esc_html($time) . '</item>';
|
||||||
|
if ($views > 0) {
|
||||||
|
echo '<item class="pull-right"><i class="fa fa-eye" aria-hidden="true"></i> ' . esc_html((string) $views) . '</item>';
|
||||||
|
}
|
||||||
|
echo '</span></span></a></div>';
|
||||||
|
}
|
||||||
|
echo '</div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div>';
|
||||||
|
} else {
|
||||||
|
echo '<div class="more-posts-mini">';
|
||||||
|
foreach ($posts as $rp) {
|
||||||
|
echo '<div class="item"><a class="icon-circle text-ellipsis" href="' . esc_url(get_permalink($rp)) . '">' .
|
||||||
|
esc_html(get_the_title($rp)) .
|
||||||
|
'</a></div>';
|
||||||
|
}
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
echo '</div>';
|
||||||
|
return (string) ob_get_clean();
|
||||||
|
}
|
||||||
|
endif;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Post author card (zibll widget_ui_avatar).
|
* Post author card (zibll widget_ui_avatar + zib_get_user_card_box depth).
|
||||||
*
|
*
|
||||||
* @package AKSRT
|
* @package AKSRT
|
||||||
*/
|
*/
|
||||||
@@ -16,7 +16,7 @@ class WidgetAuthorCard extends \WP_Widget {
|
|||||||
'aksrt_author_card',
|
'aksrt_author_card',
|
||||||
esc_html__('AKSRT 文章作者卡片', 'aksrt'),
|
esc_html__('AKSRT 文章作者卡片', 'aksrt'),
|
||||||
[
|
[
|
||||||
'description' => esc_html__('在文章/帖子侧栏显示当前内容作者信息。', 'aksrt'),
|
'description' => esc_html__('在文章/帖子侧栏显示当前内容作者信息与更多文章。', 'aksrt'),
|
||||||
'classname' => 'widget_aksrt_author_card',
|
'classname' => 'widget_aksrt_author_card',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@@ -41,8 +41,20 @@ class WidgetAuthorCard extends \WP_Widget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$show_bg = !isset($instance['show_img_bg']) || !empty($instance['show_img_bg']);
|
$show_bg = !isset($instance['show_img_bg']) || !empty($instance['show_img_bg']);
|
||||||
$show_stats = !isset($instance['show_stats']) || !empty($instance['show_stats']);
|
$show_stats = !isset($instance['show_stats']) || !empty($instance['show_stats']);
|
||||||
|
$show_posts = !isset($instance['show_posts']) || !empty($instance['show_posts']);
|
||||||
|
$post_style = sanitize_key((string) ($instance['post_style'] ?? 'mini'));
|
||||||
|
if (!in_array($post_style, ['card', 'mini'], true)) {
|
||||||
|
// Legacy show_img checkbox from zibll.
|
||||||
|
if (isset($instance['show_img'])) {
|
||||||
|
$post_style = !empty($instance['show_img']) ? 'card' : 'mini';
|
||||||
|
} else {
|
||||||
|
$post_style = 'mini';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$limit = max(0, min(12, (int) ($instance['limit'] ?? 6)));
|
||||||
|
$orderby = sanitize_key((string) ($instance['orderby'] ?? 'date'));
|
||||||
|
|
||||||
$avatar = function_exists('aksrt_get_avatar_url')
|
$avatar = function_exists('aksrt_get_avatar_url')
|
||||||
? aksrt_get_avatar_url($author_id, ['size' => 120])
|
? aksrt_get_avatar_url($author_id, ['size' => 120])
|
||||||
@@ -68,35 +80,39 @@ class WidgetAuthorCard extends \WP_Widget {
|
|||||||
$followers = \AKSRT\User\Follow::get_instance()->get_follower_count($author_id);
|
$followers = \AKSRT\User\Follow::get_instance()->get_follower_count($author_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$name_html = function_exists('aksrt_get_user_name')
|
||||||
|
? aksrt_get_user_name(['id' => $author_id, 'follow' => false, 'class' => 'flex ac jc'])
|
||||||
|
: '<a href="' . esc_url($home) . '">' . esc_html($user->display_name) . '</a>';
|
||||||
|
|
||||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
$title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base);
|
$title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base);
|
||||||
if ($title !== '') {
|
if ($title !== '') {
|
||||||
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '<div class="aksrt-author-card' . ($show_bg ? ' has-cover' : '') . '">';
|
echo '<div class="aksrt-author-card user-card author zib-widget' . ($show_bg ? ' has-cover' : '') . '">';
|
||||||
if ($show_bg) {
|
if ($show_bg) {
|
||||||
$bg = $cover !== '' ? ' style="background-image:url(' . esc_url($cover) . ')"' : '';
|
$bg = $cover !== '' ? ' style="background-image:url(' . esc_url($cover) . ')"' : '';
|
||||||
echo '<div class="aksrt-author-card__cover"' . $bg . '></div>';
|
echo '<div class="aksrt-author-card__cover user-cover graphic"' . $bg . '></div>';
|
||||||
}
|
}
|
||||||
echo '<div class="aksrt-author-card__body">';
|
echo '<div class="aksrt-author-card__body card-content">';
|
||||||
echo '<a class="aksrt-author-card__avatar" href="' . esc_url($home) . '"><img src="' . esc_url($avatar) . '" alt="" width="72" height="72" loading="lazy" /></a>';
|
echo '<div class="user-content">';
|
||||||
echo '<a class="aksrt-author-card__name" href="' . esc_url($home) . '">' . esc_html($user->display_name) . '</a>';
|
echo '<a class="aksrt-author-card__avatar user-avatar" href="' . esc_url($home) . '"><img class="avatar" src="' . esc_url($avatar) . '" alt="" width="72" height="72" loading="lazy" /></a>';
|
||||||
|
echo '<div class="aksrt-author-card__name user-name">' . $name_html . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
if ($bio !== '') {
|
if ($bio !== '') {
|
||||||
echo '<div class="aksrt-author-card__bio">' . esc_html(wp_trim_words($bio, 28)) . '</div>';
|
echo '<div class="aksrt-author-card__bio user-desc muted-2-color em09">' . esc_html(wp_trim_words($bio, 28)) . '</div>';
|
||||||
}
|
}
|
||||||
$show_badge = !isset($instance['show_badge']) || !empty($instance['show_badge']);
|
$show_badge = !isset($instance['show_badge']) || !empty($instance['show_badge']);
|
||||||
if ($show_badge && class_exists('\AKSRT\User\Badges') && \AKSRT\User\Badges::public_display()) {
|
if ($show_badge && class_exists('\AKSRT\User\Badges') && \AKSRT\User\Badges::public_display()) {
|
||||||
$wear = \AKSRT\User\Badges::get_wear($author_id);
|
$wear = \AKSRT\User\Badges::get_wear($author_id);
|
||||||
if ($wear === '') {
|
if ($wear === '') {
|
||||||
// zibll alias fallback
|
|
||||||
$wear = sanitize_key((string) get_user_meta($author_id, 'wear_medal', true));
|
$wear = sanitize_key((string) get_user_meta($author_id, 'wear_medal', true));
|
||||||
}
|
}
|
||||||
if ($wear !== '') {
|
if ($wear !== '') {
|
||||||
$map = \AKSRT\User\Badges::get_dictionary_map();
|
$map = \AKSRT\User\Badges::get_dictionary_map();
|
||||||
if (isset($map[$wear])) {
|
if (isset($map[$wear])) {
|
||||||
$badge = $map[$wear];
|
$badge = $map[$wear];
|
||||||
echo '<div class="aksrt-author-card__badge tone-' . esc_attr((string) ($badge['tone'] ?? 'neutral')) . '">';
|
echo '<div class="aksrt-author-card__badge author-tag tone-' . esc_attr((string) ($badge['tone'] ?? 'neutral')) . '">';
|
||||||
if (!empty($badge['icon_url'])) {
|
if (!empty($badge['icon_url'])) {
|
||||||
echo '<img src="' . esc_url((string) $badge['icon_url']) . '" alt="" width="16" height="16" loading="lazy" /> ';
|
echo '<img src="' . esc_url((string) $badge['icon_url']) . '" alt="" width="16" height="16" loading="lazy" /> ';
|
||||||
} else {
|
} else {
|
||||||
@@ -118,18 +134,37 @@ class WidgetAuthorCard extends \WP_Widget {
|
|||||||
}
|
}
|
||||||
$cuid = get_current_user_id();
|
$cuid = get_current_user_id();
|
||||||
$show_follow = !isset($instance['show_follow']) || !empty($instance['show_follow']);
|
$show_follow = !isset($instance['show_follow']) || !empty($instance['show_follow']);
|
||||||
|
echo '<div class="aksrt-author-card__actions user-btns">';
|
||||||
if ($show_follow && $cuid > 0 && $cuid !== $author_id && class_exists('\AKSRT\User\Follow')) {
|
if ($show_follow && $cuid > 0 && $cuid !== $author_id && class_exists('\AKSRT\User\Follow')) {
|
||||||
$following = \AKSRT\User\Follow::get_instance()->is_following($cuid, $author_id);
|
$following = \AKSRT\User\Follow::get_instance()->is_following($cuid, $author_id);
|
||||||
$label = $following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
|
$label = $following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
|
||||||
echo '<button type="button" class="aksrt-author-card__btn aksrt-author-card__follow' . ($following ? ' is-following' : '') . '" data-aksrt-follow="' . (int) $author_id . '">' . esc_html($label) . '</button>';
|
echo '<button type="button" class="aksrt-author-card__btn aksrt-author-card__follow but' . ($following ? ' is-following' : '') . '" data-aksrt-follow="' . (int) $author_id . '">' . esc_html($label) . '</button>';
|
||||||
}
|
}
|
||||||
echo '<a class="aksrt-author-card__btn" href="' . esc_url($home) . '">' . esc_html__('查看主页', 'aksrt') . '</a>';
|
echo '<a class="aksrt-author-card__btn but" href="' . esc_url($home) . '">' . esc_html__('查看主页', 'aksrt') . '</a>';
|
||||||
|
echo '</div>';
|
||||||
|
echo '</div>'; // .user-content
|
||||||
|
|
||||||
|
if ($show_posts && $limit > 0 && function_exists('aksrt_render_user_card_posts')) {
|
||||||
|
echo aksrt_render_user_card_posts([ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
|
'user_id' => $author_id,
|
||||||
|
'limit' => $limit,
|
||||||
|
'orderby' => $orderby,
|
||||||
|
'post_style' => $post_style,
|
||||||
|
'post_type' => 'post',
|
||||||
|
'show_empty' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
echo '</div></div>';
|
echo '</div></div>';
|
||||||
|
|
||||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
}
|
}
|
||||||
|
|
||||||
public function form($instance): void {
|
public function form($instance): void {
|
||||||
|
$post_style = sanitize_key((string) ($instance['post_style'] ?? 'mini'));
|
||||||
|
if (!in_array($post_style, ['card', 'mini'], true)) {
|
||||||
|
$post_style = !empty($instance['show_img']) ? 'card' : 'mini';
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<p class="description"><?php esc_html_e('自动读取当前文章/帖子作者;也可固定用户 ID。', 'aksrt'); ?></p>
|
<p class="description"><?php esc_html_e('自动读取当前文章/帖子作者;也可固定用户 ID。', 'aksrt'); ?></p>
|
||||||
<p>
|
<p>
|
||||||
@@ -146,12 +181,44 @@ class WidgetAuthorCard extends \WP_Widget {
|
|||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_img_bg')); ?>" value="1" <?php checked(!isset($instance['show_img_bg']) || !empty($instance['show_img_bg'])); ?>> <?php esc_html_e('显示封面', 'aksrt'); ?></label><br>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_img_bg')); ?>" value="1" <?php checked(!isset($instance['show_img_bg']) || !empty($instance['show_img_bg'])); ?>> <?php esc_html_e('显示封面', 'aksrt'); ?></label><br>
|
||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_stats')); ?>" value="1" <?php checked(!isset($instance['show_stats']) || !empty($instance['show_stats'])); ?>> <?php esc_html_e('显示统计', 'aksrt'); ?></label><br>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_stats')); ?>" value="1" <?php checked(!isset($instance['show_stats']) || !empty($instance['show_stats'])); ?>> <?php esc_html_e('显示统计', 'aksrt'); ?></label><br>
|
||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_follow')); ?>" value="1" <?php checked(!isset($instance['show_follow']) || !empty($instance['show_follow'])); ?>> <?php esc_html_e('显示关注按钮', 'aksrt'); ?></label><br>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_follow')); ?>" value="1" <?php checked(!isset($instance['show_follow']) || !empty($instance['show_follow'])); ?>> <?php esc_html_e('显示关注按钮', 'aksrt'); ?></label><br>
|
||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_badge')); ?>" value="1" <?php checked(!isset($instance['show_badge']) || !empty($instance['show_badge'])); ?>> <?php esc_html_e('显示佩戴徽章', 'aksrt'); ?></label>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_badge')); ?>" value="1" <?php checked(!isset($instance['show_badge']) || !empty($instance['show_badge'])); ?>> <?php esc_html_e('显示佩戴徽章', 'aksrt'); ?></label><br>
|
||||||
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_posts')); ?>" value="1" <?php checked(!isset($instance['show_posts']) || !empty($instance['show_posts'])); ?>> <?php esc_html_e('显示更多文章', 'aksrt'); ?></label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label><?php esc_html_e('文章数量', 'aksrt'); ?>
|
||||||
|
<input class="tiny-text" type="number" min="0" max="12" name="<?php echo esc_attr($this->get_field_name('limit')); ?>" value="<?php echo esc_attr((string) ((int) ($instance['limit'] ?? 6))); ?>">
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label><?php esc_html_e('文章样式', 'aksrt'); ?>
|
||||||
|
<select name="<?php echo esc_attr($this->get_field_name('post_style')); ?>">
|
||||||
|
<option value="mini" <?php selected($post_style, 'mini'); ?>><?php esc_html_e('迷你列表', 'aksrt'); ?></option>
|
||||||
|
<option value="card" <?php selected($post_style, 'card'); ?>><?php esc_html_e('卡片横滑', 'aksrt'); ?></option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label><?php esc_html_e('排序', 'aksrt'); ?>
|
||||||
|
<select name="<?php echo esc_attr($this->get_field_name('orderby')); ?>">
|
||||||
|
<option value="date" <?php selected(($instance['orderby'] ?? 'date'), 'date'); ?>><?php esc_html_e('最新', 'aksrt'); ?></option>
|
||||||
|
<option value="views" <?php selected(($instance['orderby'] ?? ''), 'views'); ?>><?php esc_html_e('阅读量', 'aksrt'); ?></option>
|
||||||
|
<option value="comment_count" <?php selected(($instance['orderby'] ?? ''), 'comment_count'); ?>><?php esc_html_e('评论数', 'aksrt'); ?></option>
|
||||||
|
<option value="rand" <?php selected(($instance['orderby'] ?? ''), 'rand'); ?>><?php esc_html_e('随机', 'aksrt'); ?></option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update($new_instance, $old_instance): array {
|
public function update($new_instance, $old_instance): array {
|
||||||
|
$post_style = sanitize_key((string) ($new_instance['post_style'] ?? 'mini'));
|
||||||
|
if (!in_array($post_style, ['card', 'mini'], true)) {
|
||||||
|
$post_style = 'mini';
|
||||||
|
}
|
||||||
|
$orderby = sanitize_key((string) ($new_instance['orderby'] ?? 'date'));
|
||||||
|
if (!in_array($orderby, ['date', 'views', 'comment_count', 'modified', 'rand'], true)) {
|
||||||
|
$orderby = 'date';
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||||
'user_id' => max(0, (int) ($new_instance['user_id'] ?? 0)),
|
'user_id' => max(0, (int) ($new_instance['user_id'] ?? 0)),
|
||||||
@@ -159,6 +226,10 @@ class WidgetAuthorCard extends \WP_Widget {
|
|||||||
'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0,
|
'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0,
|
||||||
'show_follow' => !empty($new_instance['show_follow']) ? 1 : 0,
|
'show_follow' => !empty($new_instance['show_follow']) ? 1 : 0,
|
||||||
'show_badge' => !empty($new_instance['show_badge']) ? 1 : 0,
|
'show_badge' => !empty($new_instance['show_badge']) ? 1 : 0,
|
||||||
|
'show_posts' => !empty($new_instance['show_posts']) ? 1 : 0,
|
||||||
|
'limit' => max(0, min(12, (int) ($new_instance['limit'] ?? 6))),
|
||||||
|
'post_style' => $post_style,
|
||||||
|
'orderby' => $orderby,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
/**
|
/**
|
||||||
* In-article / topic TOC shell (zibll widget_ui_posts_navs parity).
|
* In-article / topic TOC shell (zibll widget_ui_posts_navs parity).
|
||||||
*
|
*
|
||||||
* Frontend JS fills `.posts-nav-box` from heading outline when present.
|
* Shell matches the built-in single sidebar TOC so page-template.js can fill
|
||||||
|
* `.posts-nav-box.toc-widget > .toc-list` from `[data-nav]` headings.
|
||||||
*
|
*
|
||||||
* @package AKSRT
|
* @package AKSRT
|
||||||
*/
|
*/
|
||||||
@@ -18,8 +19,8 @@ class WidgetPostsNavs extends \WP_Widget {
|
|||||||
'aksrt_posts_navs',
|
'aksrt_posts_navs',
|
||||||
esc_html__('AKSRT 文章目录树', 'aksrt'),
|
esc_html__('AKSRT 文章目录树', 'aksrt'),
|
||||||
[
|
[
|
||||||
'description' => esc_html__('显示当前文章/帖子标题目录,非详情页不输出。标题超过 3 个才显示。', 'aksrt'),
|
'description' => esc_html__('显示当前文章/帖子标题目录,非详情页不输出。标题超过 2 个才填充。', 'aksrt'),
|
||||||
'classname' => 'widget_aksrt_posts_navs',
|
'classname' => 'widget_aksrt_posts_navs',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -35,16 +36,28 @@ class WidgetPostsNavs extends \WP_Widget {
|
|||||||
|
|
||||||
$data_title = $title;
|
$data_title = $title;
|
||||||
if ($mini_title !== '') {
|
if ($mini_title !== '') {
|
||||||
$data_title .= ' · ' . $mini_title;
|
$data_title .= ($data_title !== '' ? ' · ' : '') . $mini_title;
|
||||||
|
}
|
||||||
|
if ($data_title === '') {
|
||||||
|
$data_title = __('文章目录', 'aksrt');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mirror aksrt-single-render built-in TOC shell so page-template.js binds.
|
||||||
|
$classes = 'zib-widget toc-widget posts-nav-box';
|
||||||
|
if ($in_affix) {
|
||||||
|
$classes .= ' is-affix';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
echo '<div class="widget-container">';
|
|
||||||
printf(
|
printf(
|
||||||
'<div class="posts-nav-box"%s%s></div>',
|
'<div class="%s"%s data-title="%s" aria-label="%s">',
|
||||||
|
esc_attr($classes),
|
||||||
$in_affix ? ' data-affix="true"' : '',
|
$in_affix ? ' data-affix="true"' : '',
|
||||||
$data_title !== '' ? ' data-title="' . esc_attr($data_title) . '"' : ''
|
esc_attr($data_title),
|
||||||
|
esc_attr($data_title)
|
||||||
);
|
);
|
||||||
|
echo '<h3 class="widget-title toc-widget__title">' . esc_html($data_title) . '</h3>';
|
||||||
|
echo '<ol class="toc-list"></ol>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
}
|
}
|
||||||
@@ -68,7 +81,7 @@ class WidgetPostsNavs extends \WP_Widget {
|
|||||||
<?php esc_html_e('侧栏随动(仅侧边栏)', 'aksrt'); ?>
|
<?php esc_html_e('侧栏随动(仅侧边栏)', 'aksrt'); ?>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<p class="description"><?php esc_html_e('请添加到文章/帖子侧栏。正文 H2–H4 超过 3 个时前端才会填充目录。', 'aksrt'); ?></p>
|
<p class="description"><?php esc_html_e('请添加到文章/帖子侧栏。正文标题 ≥3 个时由前端填充目录;无标题则自动移除。', 'aksrt'); ?></p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Simple image slider widget (zibll widget_ui_slider lite).
|
* Simple image slider widget (zibll widget_ui_slider → aksrt_render_slider / new-swiper).
|
||||||
*
|
*
|
||||||
* @package AKSRT
|
* @package AKSRT
|
||||||
*/
|
*/
|
||||||
@@ -16,8 +16,8 @@ class WidgetSlider extends \WP_Widget {
|
|||||||
'aksrt_slider',
|
'aksrt_slider',
|
||||||
esc_html__('AKSRT 幻灯片', 'aksrt'),
|
esc_html__('AKSRT 幻灯片', 'aksrt'),
|
||||||
[
|
[
|
||||||
'description' => esc_html__('多图轮播,支持链接与标题。', 'aksrt'),
|
'description' => esc_html__('多图轮播(共享 new-swiper / Swiper 栈),支持链接与标题。', 'aksrt'),
|
||||||
'classname' => 'widget_aksrt_slider',
|
'classname' => 'widget_aksrt_slider slide-widget',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -25,14 +25,38 @@ class WidgetSlider extends \WP_Widget {
|
|||||||
public function widget($args, $instance): void {
|
public function widget($args, $instance): void {
|
||||||
$slides = $this->normalize_slides($instance['slides'] ?? []);
|
$slides = $this->normalize_slides($instance['slides'] ?? []);
|
||||||
if (!$slides) {
|
if (!$slides) {
|
||||||
|
if (current_user_can('manage_options')) {
|
||||||
|
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
|
echo '<div class="c-red muted-box mb20"><b>' . esc_html__('幻灯片模块:', 'aksrt') . '</b>' .
|
||||||
|
esc_html__('当前配置下没有可显示的内容,请正确配置或移出该模块', 'aksrt') . '</div>';
|
||||||
|
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$interval = max(2, min(20, (int) ($instance['interval'] ?? 4)));
|
$interval = max(2, min(20, (int) ($instance['interval'] ?? 4)));
|
||||||
$loop = !empty($instance['loop']);
|
$loop = !isset($instance['loop']) || !empty($instance['loop']);
|
||||||
$dots = !empty($instance['pagination']);
|
$dots = !isset($instance['pagination']) || !empty($instance['pagination']);
|
||||||
$nav = !empty($instance['button']);
|
$nav = !isset($instance['button']) || !empty($instance['button']);
|
||||||
$blank = !empty($instance['blank']);
|
$blank = !empty($instance['blank']);
|
||||||
$height = max(80, min(800, (int) ($instance['height'] ?? 220)));
|
$height = max(80, min(800, (int) ($instance['height'] ?? 220)));
|
||||||
|
$m_height = max(60, min(800, (int) ($instance['m_height'] ?? $height)));
|
||||||
|
$effect = sanitize_key((string) ($instance['effect'] ?? 'slide'));
|
||||||
|
if (!in_array($effect, ['slide', 'fade', 'cube', 'coverflow', 'flip'], true)) {
|
||||||
|
$effect = 'slide';
|
||||||
|
}
|
||||||
|
|
||||||
|
$slide_payload = [];
|
||||||
|
foreach ($slides as $slide) {
|
||||||
|
$slide_payload[] = [
|
||||||
|
'image' => $slide['image'],
|
||||||
|
'link' => $slide['href'],
|
||||||
|
'title' => $slide['title'],
|
||||||
|
'desc' => $slide['desc'],
|
||||||
|
'alt' => $slide['title'],
|
||||||
|
'target' => $blank ? '_blank' : '_self',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
$title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base);
|
$title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base);
|
||||||
@@ -40,97 +64,47 @@ class WidgetSlider extends \WP_Widget {
|
|||||||
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = 'aksrt-slider-' . esc_attr($this->id);
|
if (function_exists('aksrt_render_slider')) {
|
||||||
printf(
|
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
'<div class="aksrt-widget-slider" id="%s" data-interval="%d" data-loop="%s" style="--aksrt-slider-h:%dpx">',
|
echo aksrt_render_slider([
|
||||||
$uid,
|
'slides' => $slide_payload,
|
||||||
$interval * 1000,
|
'effect' => $effect,
|
||||||
$loop ? '1' : '0',
|
'loop' => $loop,
|
||||||
$height
|
'autoplay' => true,
|
||||||
);
|
'interval' => $interval * 1000,
|
||||||
echo '<div class="aksrt-widget-slider__track">';
|
'pc_height' => $height . 'px',
|
||||||
foreach ($slides as $i => $slide) {
|
'm_height' => $m_height . 'px',
|
||||||
$active = $i === 0 ? ' is-active' : '';
|
'show_nav' => $nav,
|
||||||
echo '<div class="aksrt-widget-slider__slide' . esc_attr($active) . '">';
|
'show_pagination' => $dots,
|
||||||
$img = '<img src="' . esc_url($slide['image']) . '" alt="' . esc_attr($slide['title']) . '" loading="lazy" />';
|
'slider_class' => 'slide-widget',
|
||||||
if ($slide['href'] !== '') {
|
'wrapper_class' => 'aksrt-widget-slider-wrap',
|
||||||
printf(
|
]);
|
||||||
'<a href="%s"%s class="aksrt-widget-slider__link">%s</a>',
|
} else {
|
||||||
esc_url($slide['href']),
|
// Minimal fallback without helper.
|
||||||
$blank ? ' target="_blank" rel="noopener noreferrer"' : '',
|
echo '<div class="aksrt-widget-slider" style="--aksrt-slider-h:' . (int) $height . 'px">';
|
||||||
$img // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
foreach ($slide_payload as $i => $slide) {
|
||||||
);
|
$active = $i === 0 ? ' is-active' : '';
|
||||||
} else {
|
echo '<div class="aksrt-widget-slider__slide' . esc_attr($active) . '">';
|
||||||
echo $img; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
$img = '<img src="' . esc_url($slide['image']) . '" alt="' . esc_attr($slide['title']) . '" loading="lazy" />';
|
||||||
}
|
if ($slide['link'] !== '') {
|
||||||
if ($slide['title'] !== '' || $slide['desc'] !== '') {
|
echo '<a href="' . esc_url($slide['link']) . '"' . ($blank ? ' target="_blank" rel="noopener noreferrer"' : '') . '>' . $img . '</a>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
echo '<div class="aksrt-widget-slider__caption">';
|
} else {
|
||||||
if ($slide['title'] !== '') {
|
echo $img; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
echo '<strong>' . esc_html($slide['title']) . '</strong>';
|
|
||||||
}
|
|
||||||
if ($slide['desc'] !== '') {
|
|
||||||
echo '<span>' . esc_html($slide['desc']) . '</span>';
|
|
||||||
}
|
}
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
echo '</div>';
|
|
||||||
if ($nav) {
|
|
||||||
echo '<button type="button" class="aksrt-widget-slider__prev" aria-label="' . esc_attr__('上一张', 'aksrt') . '">‹</button>';
|
|
||||||
echo '<button type="button" class="aksrt-widget-slider__next" aria-label="' . esc_attr__('下一张', 'aksrt') . '">›</button>';
|
|
||||||
}
|
|
||||||
if ($dots) {
|
|
||||||
echo '<div class="aksrt-widget-slider__dots" role="tablist">';
|
|
||||||
foreach ($slides as $i => $slide) {
|
|
||||||
printf(
|
|
||||||
'<button type="button" class="aksrt-widget-slider__dot%s" data-index="%d" aria-label="%s"></button>',
|
|
||||||
$i === 0 ? ' is-active' : '',
|
|
||||||
(int) $i,
|
|
||||||
esc_attr(sprintf(__('第 %d 张', 'aksrt'), $i + 1))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
echo '</div>';
|
|
||||||
}
|
|
||||||
echo '</div>';
|
|
||||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
||||||
|
|
||||||
// Inline init once per widget (no extra enqueue dependency).
|
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
?>
|
|
||||||
<script>
|
|
||||||
(function(){
|
|
||||||
var root=document.getElementById(<?php echo wp_json_encode($uid); ?>);
|
|
||||||
if(!root||root._aksrtSlider)return; root._aksrtSlider=1;
|
|
||||||
var slides=[].slice.call(root.querySelectorAll('.aksrt-widget-slider__slide'));
|
|
||||||
var dots=[].slice.call(root.querySelectorAll('.aksrt-widget-slider__dot'));
|
|
||||||
var i=0, timer=null, ms=parseInt(root.getAttribute('data-interval')||'4000',10)||4000;
|
|
||||||
var loop=root.getAttribute('data-loop')==='1';
|
|
||||||
function go(n){
|
|
||||||
if(!slides.length)return;
|
|
||||||
i=(n+slides.length)%slides.length;
|
|
||||||
slides.forEach(function(s,idx){s.classList.toggle('is-active',idx===i);});
|
|
||||||
dots.forEach(function(d,idx){d.classList.toggle('is-active',idx===i);});
|
|
||||||
}
|
|
||||||
function next(){ if(!loop && i>=slides.length-1){go(0);return;} go(i+1); }
|
|
||||||
function start(){ stop(); if(slides.length>1) timer=setInterval(next, ms); }
|
|
||||||
function stop(){ if(timer){clearInterval(timer);timer=null;} }
|
|
||||||
var prev=root.querySelector('.aksrt-widget-slider__prev');
|
|
||||||
var nxt=root.querySelector('.aksrt-widget-slider__next');
|
|
||||||
if(prev) prev.addEventListener('click', function(){ go(i-1); start(); });
|
|
||||||
if(nxt) nxt.addEventListener('click', function(){ go(i+1); start(); });
|
|
||||||
dots.forEach(function(d){ d.addEventListener('click', function(){ go(parseInt(d.getAttribute('data-index')||'0',10)); start(); }); });
|
|
||||||
root.addEventListener('mouseenter', stop);
|
|
||||||
root.addEventListener('mouseleave', start);
|
|
||||||
start();
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
<?php
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function form($instance): void {
|
public function form($instance): void {
|
||||||
$title = (string) ($instance['title'] ?? '');
|
$title = (string) ($instance['title'] ?? '');
|
||||||
$interval = (int) ($instance['interval'] ?? 4);
|
$interval = (int) ($instance['interval'] ?? 4);
|
||||||
$height = (int) ($instance['height'] ?? 220);
|
$height = (int) ($instance['height'] ?? 220);
|
||||||
|
$m_height = (int) ($instance['m_height'] ?? $height);
|
||||||
|
$effect = sanitize_key((string) ($instance['effect'] ?? 'slide'));
|
||||||
$slides = $this->normalize_slides($instance['slides'] ?? []);
|
$slides = $this->normalize_slides($instance['slides'] ?? []);
|
||||||
if (!$slides) {
|
if (!$slides) {
|
||||||
$slides = [
|
$slides = [
|
||||||
@@ -150,10 +124,26 @@ class WidgetSlider extends \WP_Widget {
|
|||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label><?php esc_html_e('高度(px)', 'aksrt'); ?>
|
<label><?php esc_html_e('PC 高度(px)', 'aksrt'); ?>
|
||||||
<input class="tiny-text" type="number" min="80" max="800" name="<?php echo esc_attr($this->get_field_name('height')); ?>" value="<?php echo esc_attr((string) $height); ?>">
|
<input class="tiny-text" type="number" min="80" max="800" name="<?php echo esc_attr($this->get_field_name('height')); ?>" value="<?php echo esc_attr((string) $height); ?>">
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<label><?php esc_html_e('移动端高度(px)', 'aksrt'); ?>
|
||||||
|
<input class="tiny-text" type="number" min="60" max="800" name="<?php echo esc_attr($this->get_field_name('m_height')); ?>" value="<?php echo esc_attr((string) $m_height); ?>">
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label><?php esc_html_e('切换效果', 'aksrt'); ?>
|
||||||
|
<select name="<?php echo esc_attr($this->get_field_name('effect')); ?>">
|
||||||
|
<option value="slide" <?php selected($effect, 'slide'); ?>><?php esc_html_e('滑动', 'aksrt'); ?></option>
|
||||||
|
<option value="fade" <?php selected($effect, 'fade'); ?>><?php esc_html_e('淡入', 'aksrt'); ?></option>
|
||||||
|
<option value="coverflow" <?php selected($effect, 'coverflow'); ?>><?php esc_html_e('Coverflow', 'aksrt'); ?></option>
|
||||||
|
<option value="cube" <?php selected($effect, 'cube'); ?>><?php esc_html_e('Cube', 'aksrt'); ?></option>
|
||||||
|
<option value="flip" <?php selected($effect, 'flip'); ?>><?php esc_html_e('Flip', 'aksrt'); ?></option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('loop')); ?>" value="1" <?php checked(!empty($instance['loop']) || !isset($instance['loop'])); ?>> <?php esc_html_e('循环播放', 'aksrt'); ?></label><br>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('loop')); ?>" value="1" <?php checked(!empty($instance['loop']) || !isset($instance['loop'])); ?>> <?php esc_html_e('循环播放', 'aksrt'); ?></label><br>
|
||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('button')); ?>" value="1" <?php checked(!empty($instance['button']) || !isset($instance['button'])); ?>> <?php esc_html_e('翻页按钮', 'aksrt'); ?></label><br>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('button')); ?>" value="1" <?php checked(!empty($instance['button']) || !isset($instance['button'])); ?>> <?php esc_html_e('翻页按钮', 'aksrt'); ?></label><br>
|
||||||
@@ -177,9 +167,7 @@ class WidgetSlider extends \WP_Widget {
|
|||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<p class="description"><?php esc_html_e('保存后可继续编辑;需要更多张可先填满再在下次编辑时追加(当前表单固定 2–6 槽)。', 'aksrt'); ?></p>
|
|
||||||
<?php
|
<?php
|
||||||
// Ensure at least 4 slots for editing convenience.
|
|
||||||
$extra = max(0, 4 - count($slides));
|
$extra = max(0, 4 - count($slides));
|
||||||
for ($j = 0; $j < $extra; $j++) {
|
for ($j = 0; $j < $extra; $j++) {
|
||||||
$i = count($slides) + $j;
|
$i = count($slides) + $j;
|
||||||
@@ -193,14 +181,23 @@ class WidgetSlider extends \WP_Widget {
|
|||||||
</p>
|
</p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
|
<p class="description"><?php esc_html_e('使用主题共享 Swiper(.new-swiper)。图片 URL 必填;仅 1 张时不滑动。', 'aksrt'); ?></p>
|
||||||
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update($new_instance, $old_instance): array {
|
public function update($new_instance, $old_instance): array {
|
||||||
$slides = $this->normalize_slides($new_instance['slides'] ?? []);
|
$slides = $this->normalize_slides($new_instance['slides'] ?? []);
|
||||||
|
$effect = sanitize_key((string) ($new_instance['effect'] ?? 'slide'));
|
||||||
|
if (!in_array($effect, ['slide', 'fade', 'cube', 'coverflow', 'flip'], true)) {
|
||||||
|
$effect = 'slide';
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||||
'interval' => max(2, min(20, (int) ($new_instance['interval'] ?? 4))),
|
'interval' => max(2, min(20, (int) ($new_instance['interval'] ?? 4))),
|
||||||
'height' => max(80, min(800, (int) ($new_instance['height'] ?? 220))),
|
'height' => max(80, min(800, (int) ($new_instance['height'] ?? 220))),
|
||||||
|
'm_height' => max(60, min(800, (int) ($new_instance['m_height'] ?? ($new_instance['height'] ?? 220)))),
|
||||||
|
'effect' => $effect,
|
||||||
'loop' => !empty($new_instance['loop']) ? 1 : 0,
|
'loop' => !empty($new_instance['loop']) ? 1 : 0,
|
||||||
'button' => !empty($new_instance['button']) ? 1 : 0,
|
'button' => !empty($new_instance['button']) ? 1 : 0,
|
||||||
'pagination' => !empty($new_instance['pagination']) ? 1 : 0,
|
'pagination' => !empty($new_instance['pagination']) ? 1 : 0,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class WidgetUserCard extends \WP_Widget {
|
|||||||
parent::__construct(
|
parent::__construct(
|
||||||
'aksrt_user_card',
|
'aksrt_user_card',
|
||||||
__('用户卡片', 'aksrt'),
|
__('用户卡片', 'aksrt'),
|
||||||
['description' => __('未登录显示登录入口;登录后显示当前用户卡片、签到与快捷按钮。', 'aksrt')]
|
['description' => __('未登录显示登录入口;登录后显示当前用户卡片、签到、快捷按钮与更多文章。', 'aksrt')]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,9 +24,18 @@ class WidgetUserCard extends \WP_Widget {
|
|||||||
$show_stats = !empty($instance['show_stats']) || !isset($instance['show_stats']);
|
$show_stats = !empty($instance['show_stats']) || !isset($instance['show_stats']);
|
||||||
$show_actions = !empty($instance['show_button']) || !isset($instance['show_button']);
|
$show_actions = !empty($instance['show_button']) || !isset($instance['show_button']);
|
||||||
$show_checkin = !empty($instance['show_checkin']) || !isset($instance['show_checkin']);
|
$show_checkin = !empty($instance['show_checkin']) || !isset($instance['show_checkin']);
|
||||||
|
// zibll user widget forces show_posts=false; author widget enables it.
|
||||||
|
// AKSRT keeps optional show_posts for current-user card (default off).
|
||||||
|
$show_posts = !empty($instance['show_posts']);
|
||||||
$loged_title = (string) ($instance['loged_title'] ?? __('Hi!请登录', 'aksrt'));
|
$loged_title = (string) ($instance['loged_title'] ?? __('Hi!请登录', 'aksrt'));
|
||||||
$btn1_text = (string) ($instance['button_1_text'] ?? __('发布文章', 'aksrt'));
|
$btn1_text = (string) ($instance['button_1_text'] ?? __('发布文章', 'aksrt'));
|
||||||
$btn2_text = (string) ($instance['button_2_text'] ?? __('用户中心', 'aksrt'));
|
$btn2_text = (string) ($instance['button_2_text'] ?? __('用户中心', 'aksrt'));
|
||||||
|
$post_style = sanitize_key((string) ($instance['post_style'] ?? 'mini'));
|
||||||
|
if (!in_array($post_style, ['card', 'mini'], true)) {
|
||||||
|
$post_style = 'mini';
|
||||||
|
}
|
||||||
|
$limit = max(0, min(12, (int) ($instance['limit'] ?? 6)));
|
||||||
|
$orderby = sanitize_key((string) ($instance['orderby'] ?? 'date'));
|
||||||
|
|
||||||
// Fixed user id wins; else current user.
|
// Fixed user id wins; else current user.
|
||||||
$user_id = !empty($instance['user_id']) ? (int) $instance['user_id'] : 0;
|
$user_id = !empty($instance['user_id']) ? (int) $instance['user_id'] : 0;
|
||||||
@@ -63,7 +72,6 @@ class WidgetUserCard extends \WP_Widget {
|
|||||||
? aksrt_get_user_center_url()
|
? aksrt_get_user_center_url()
|
||||||
: $profile_url;
|
: $profile_url;
|
||||||
$compose_url = home_url('/');
|
$compose_url = home_url('/');
|
||||||
// Prefer front submit / write page when available.
|
|
||||||
if (function_exists('get_pages')) {
|
if (function_exists('get_pages')) {
|
||||||
$pages = get_pages(['meta_key' => '_wp_page_template', 'meta_value' => 'templates/pages/page-submit.php', 'number' => 1]);
|
$pages = get_pages(['meta_key' => '_wp_page_template', 'meta_value' => 'templates/pages/page-submit.php', 'number' => 1]);
|
||||||
if (!empty($pages[0])) {
|
if (!empty($pages[0])) {
|
||||||
@@ -90,14 +98,32 @@ class WidgetUserCard extends \WP_Widget {
|
|||||||
$following_count = \AKSRT\User\Follow::get_instance()->get_following_count($user_id);
|
$following_count = \AKSRT\User\Follow::get_instance()->get_following_count($user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$name_html = function_exists('aksrt_get_user_name')
|
||||||
|
? aksrt_get_user_name(['id' => $user_id, 'follow' => !$is_self, 'class' => 'flex ac jc'])
|
||||||
|
: '<a href="' . esc_url($profile_url) . '">' . esc_html($user->display_name) . '</a>';
|
||||||
|
|
||||||
echo '<div class="aksrt-user-card user-card zib-widget widget">';
|
echo '<div class="aksrt-user-card user-card zib-widget widget">';
|
||||||
if ($show_cover) {
|
if ($show_cover) {
|
||||||
$bg = $cover !== '' ? ' style="background-image:url(' . esc_url($cover) . ')"' : '';
|
if ($cover !== '') {
|
||||||
echo '<div class="aksrt-user-card__cover user-cover graphic"' . $bg . '></div>';
|
echo '<div class="aksrt-user-card__cover user-cover graphic" style="background-image:url(' . esc_url($cover) . ')"></div>';
|
||||||
|
} else {
|
||||||
|
// Prefer site default cover image when available.
|
||||||
|
$default_cover = '';
|
||||||
|
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_user_cover_default')) {
|
||||||
|
$default_cover = (string) \AKSRT\Settings\Settings::get_user_cover_default();
|
||||||
|
}
|
||||||
|
if ($default_cover === '' && function_exists('get_theme_mod')) {
|
||||||
|
$default_cover = (string) get_theme_mod('aksrt_user_cover', '');
|
||||||
|
}
|
||||||
|
if ($default_cover !== '') {
|
||||||
|
echo '<div class="aksrt-user-card__cover user-cover graphic" style="background-image:url(' . esc_url($default_cover) . ')"></div>';
|
||||||
|
} else {
|
||||||
|
echo '<div class="aksrt-user-card__cover user-cover graphic is-empty"></div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
echo '<div class="aksrt-user-card__body card-content">';
|
echo '<div class="aksrt-user-card__body card-content">';
|
||||||
if ($show_checkin && $is_self && function_exists('aksrt_header_user_checkin_btn')) {
|
if ($show_checkin && $is_self && function_exists('aksrt_header_user_checkin_btn')) {
|
||||||
// Reuse compact check-in button markup (without details if already long).
|
|
||||||
$btn = aksrt_header_user_checkin_btn($user_id);
|
$btn = aksrt_header_user_checkin_btn($user_id);
|
||||||
if ($btn !== '') {
|
if ($btn !== '') {
|
||||||
echo '<div class="aksrt-user-card__checkin">' . $btn . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
echo '<div class="aksrt-user-card__checkin">' . $btn . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
@@ -106,7 +132,7 @@ class WidgetUserCard extends \WP_Widget {
|
|||||||
echo '<div class="aksrt-user-card__avatar user-avatar">';
|
echo '<div class="aksrt-user-card__avatar user-avatar">';
|
||||||
echo '<a href="' . esc_url($profile_url) . '"><img src="' . esc_url($avatar_url) . '" alt="' . esc_attr($user->display_name) . '" loading="lazy" width="72" height="72" /></a>';
|
echo '<a href="' . esc_url($profile_url) . '"><img src="' . esc_url($avatar_url) . '" alt="' . esc_attr($user->display_name) . '" loading="lazy" width="72" height="72" /></a>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo '<h4 class="aksrt-user-card__name user-name"><a href="' . esc_url($profile_url) . '">' . esc_html($user->display_name) . '</a></h4>';
|
echo '<h4 class="aksrt-user-card__name user-name">' . $name_html . '</h4>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
if ($bio !== '') {
|
if ($bio !== '') {
|
||||||
echo '<p class="aksrt-user-card__bio user-desc">' . esc_html(wp_trim_words($bio, 24)) . '</p>';
|
echo '<p class="aksrt-user-card__bio user-desc">' . esc_html(wp_trim_words($bio, 24)) . '</p>';
|
||||||
}
|
}
|
||||||
@@ -125,6 +151,18 @@ class WidgetUserCard extends \WP_Widget {
|
|||||||
} elseif ($show_actions) {
|
} elseif ($show_actions) {
|
||||||
echo '<div class="aksrt-user-card__actions"><a class="aksrt-user-card__btn aksrt-user-card__btn--primary" href="' . esc_url($profile_url) . '">' . esc_html__('查看主页', 'aksrt') . '</a></div>';
|
echo '<div class="aksrt-user-card__actions"><a class="aksrt-user-card__btn aksrt-user-card__btn--primary" href="' . esc_url($profile_url) . '">' . esc_html__('查看主页', 'aksrt') . '</a></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($show_posts && $limit > 0 && function_exists('aksrt_render_user_card_posts')) {
|
||||||
|
echo aksrt_render_user_card_posts([ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
|
'user_id' => $user_id,
|
||||||
|
'limit' => $limit,
|
||||||
|
'orderby' => $orderby,
|
||||||
|
'post_style' => $post_style,
|
||||||
|
'post_type' => 'post',
|
||||||
|
'show_empty' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
echo '</div></div>';
|
echo '</div></div>';
|
||||||
|
|
||||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
@@ -149,7 +187,15 @@ class WidgetUserCard extends \WP_Widget {
|
|||||||
|
|
||||||
echo '<div class="aksrt-user-card user-card zib-widget widget is-guest">';
|
echo '<div class="aksrt-user-card user-card zib-widget widget is-guest">';
|
||||||
if ($show_cover) {
|
if ($show_cover) {
|
||||||
echo '<div class="aksrt-user-card__cover user-cover graphic is-empty"></div>';
|
$default_cover = '';
|
||||||
|
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_user_cover_default')) {
|
||||||
|
$default_cover = (string) \AKSRT\Settings\Settings::get_user_cover_default();
|
||||||
|
}
|
||||||
|
if ($default_cover !== '') {
|
||||||
|
echo '<div class="aksrt-user-card__cover user-cover graphic" style="background-image:url(' . esc_url($default_cover) . ')"></div>';
|
||||||
|
} else {
|
||||||
|
echo '<div class="aksrt-user-card__cover user-cover graphic is-empty"></div>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
echo '<div class="aksrt-user-card__body card-content">';
|
echo '<div class="aksrt-user-card__body card-content">';
|
||||||
echo '<div class="aksrt-user-card__avatar user-avatar"><img src="' . esc_url($default_avatar) . '" alt="" width="72" height="72" loading="lazy" /></div>';
|
echo '<div class="aksrt-user-card__avatar user-avatar"><img src="' . esc_url($default_avatar) . '" alt="" width="72" height="72" loading="lazy" /></div>';
|
||||||
@@ -167,6 +213,10 @@ class WidgetUserCard extends \WP_Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function form($instance): void {
|
public function form($instance): void {
|
||||||
|
$post_style = sanitize_key((string) ($instance['post_style'] ?? 'mini'));
|
||||||
|
if (!in_array($post_style, ['card', 'mini'], true)) {
|
||||||
|
$post_style = 'mini';
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<p>
|
<p>
|
||||||
<label><?php esc_html_e('标题(可选)', 'aksrt'); ?>
|
<label><?php esc_html_e('标题(可选)', 'aksrt'); ?>
|
||||||
@@ -197,22 +247,58 @@ class WidgetUserCard extends \WP_Widget {
|
|||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_img_bg')); ?>" value="1" <?php checked(!isset($instance['show_img_bg']) || !empty($instance['show_img_bg'])); ?>> <?php esc_html_e('显示封面', 'aksrt'); ?></label><br>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_img_bg')); ?>" value="1" <?php checked(!isset($instance['show_img_bg']) || !empty($instance['show_img_bg'])); ?>> <?php esc_html_e('显示封面', 'aksrt'); ?></label><br>
|
||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_stats')); ?>" value="1" <?php checked(!isset($instance['show_stats']) || !empty($instance['show_stats'])); ?>> <?php esc_html_e('显示统计', 'aksrt'); ?></label><br>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_stats')); ?>" value="1" <?php checked(!isset($instance['show_stats']) || !empty($instance['show_stats'])); ?>> <?php esc_html_e('显示统计', 'aksrt'); ?></label><br>
|
||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_button')); ?>" value="1" <?php checked(!isset($instance['show_button']) || !empty($instance['show_button'])); ?>> <?php esc_html_e('显示操作按钮', 'aksrt'); ?></label><br>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_button')); ?>" value="1" <?php checked(!isset($instance['show_button']) || !empty($instance['show_button'])); ?>> <?php esc_html_e('显示操作按钮', 'aksrt'); ?></label><br>
|
||||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_checkin')); ?>" value="1" <?php checked(!isset($instance['show_checkin']) || !empty($instance['show_checkin'])); ?>> <?php esc_html_e('显示签到(本人)', 'aksrt'); ?></label>
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_checkin')); ?>" value="1" <?php checked(!isset($instance['show_checkin']) || !empty($instance['show_checkin'])); ?>> <?php esc_html_e('显示签到(本人)', 'aksrt'); ?></label><br>
|
||||||
|
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_posts')); ?>" value="1" <?php checked(!empty($instance['show_posts'])); ?>> <?php esc_html_e('显示更多文章', 'aksrt'); ?></label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label><?php esc_html_e('文章数量', 'aksrt'); ?>
|
||||||
|
<input class="tiny-text" type="number" min="0" max="12" name="<?php echo esc_attr($this->get_field_name('limit')); ?>" value="<?php echo esc_attr((string) ((int) ($instance['limit'] ?? 6))); ?>">
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label><?php esc_html_e('文章样式', 'aksrt'); ?>
|
||||||
|
<select name="<?php echo esc_attr($this->get_field_name('post_style')); ?>">
|
||||||
|
<option value="mini" <?php selected($post_style, 'mini'); ?>><?php esc_html_e('迷你列表', 'aksrt'); ?></option>
|
||||||
|
<option value="card" <?php selected($post_style, 'card'); ?>><?php esc_html_e('卡片横滑', 'aksrt'); ?></option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label><?php esc_html_e('排序', 'aksrt'); ?>
|
||||||
|
<select name="<?php echo esc_attr($this->get_field_name('orderby')); ?>">
|
||||||
|
<option value="date" <?php selected(($instance['orderby'] ?? 'date'), 'date'); ?>><?php esc_html_e('最新', 'aksrt'); ?></option>
|
||||||
|
<option value="views" <?php selected(($instance['orderby'] ?? ''), 'views'); ?>><?php esc_html_e('阅读量', 'aksrt'); ?></option>
|
||||||
|
<option value="comment_count" <?php selected(($instance['orderby'] ?? ''), 'comment_count'); ?>><?php esc_html_e('评论数', 'aksrt'); ?></option>
|
||||||
|
<option value="rand" <?php selected(($instance['orderby'] ?? ''), 'rand'); ?>><?php esc_html_e('随机', 'aksrt'); ?></option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update($new_instance, $old_instance): array {
|
public function update($new_instance, $old_instance): array {
|
||||||
|
$post_style = sanitize_key((string) ($new_instance['post_style'] ?? 'mini'));
|
||||||
|
if (!in_array($post_style, ['card', 'mini'], true)) {
|
||||||
|
$post_style = 'mini';
|
||||||
|
}
|
||||||
|
$orderby = sanitize_key((string) ($new_instance['orderby'] ?? 'date'));
|
||||||
|
if (!in_array($orderby, ['date', 'views', 'comment_count', 'modified', 'rand'], true)) {
|
||||||
|
$orderby = 'date';
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||||
'user_id' => max(0, (int) ($new_instance['user_id'] ?? 0)),
|
'user_id' => max(0, (int) ($new_instance['user_id'] ?? 0)),
|
||||||
'loged_title' => sanitize_text_field((string) ($new_instance['loged_title'] ?? '')),
|
'loged_title' => sanitize_text_field((string) ($new_instance['loged_title'] ?? '')),
|
||||||
'button_1_text' => sanitize_text_field((string) ($new_instance['button_1_text'] ?? '')),
|
'button_1_text' => sanitize_text_field((string) ($new_instance['button_1_text'] ?? '')),
|
||||||
'button_2_text' => sanitize_text_field((string) ($new_instance['button_2_text'] ?? '')),
|
'button_2_text' => sanitize_text_field((string) ($new_instance['button_2_text'] ?? '')),
|
||||||
'show_img_bg' => !empty($new_instance['show_img_bg']) ? 1 : 0,
|
'show_img_bg' => !empty($new_instance['show_img_bg']) ? 1 : 0,
|
||||||
'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0,
|
'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0,
|
||||||
'show_button' => !empty($new_instance['show_button']) ? 1 : 0,
|
'show_button' => !empty($new_instance['show_button']) ? 1 : 0,
|
||||||
'show_checkin' => !empty($new_instance['show_checkin']) ? 1 : 0,
|
'show_checkin' => !empty($new_instance['show_checkin']) ? 1 : 0,
|
||||||
|
'show_posts' => !empty($new_instance['show_posts']) ? 1 : 0,
|
||||||
|
'limit' => max(0, min(12, (int) ($new_instance['limit'] ?? 6))),
|
||||||
|
'post_style' => $post_style,
|
||||||
|
'orderby' => $orderby,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,10 +25,9 @@ class WidgetUserRanking extends \WP_Widget {
|
|||||||
|
|
||||||
$desc_mode = sanitize_key((string) ($instance['desc'] ?? 'desc'));
|
$desc_mode = sanitize_key((string) ($instance['desc'] ?? 'desc'));
|
||||||
$users = $this->get_ranking($rank_by, $count, $desc_mode);
|
$users = $this->get_ranking($rank_by, $count, $desc_mode);
|
||||||
if (empty($users)) return;
|
|
||||||
|
|
||||||
echo $args['before_widget'];
|
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
echo $args['before_title'] . esc_html($title) . $args['after_title'];
|
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
|
|
||||||
if (!empty($instance['checkin_btn']) && is_user_logged_in() && function_exists('aksrt_header_user_checkin_btn')) {
|
if (!empty($instance['checkin_btn']) && is_user_logged_in() && function_exists('aksrt_header_user_checkin_btn')) {
|
||||||
$cbtn = aksrt_header_user_checkin_btn(get_current_user_id());
|
$cbtn = aksrt_header_user_checkin_btn(get_current_user_id());
|
||||||
@@ -37,6 +36,14 @@ class WidgetUserRanking extends \WP_Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($users)) {
|
||||||
|
echo '<p class="aksrt-user-ranking__empty muted-2-color">' . esc_html__('暂无排行数据', 'aksrt') . '</p>';
|
||||||
|
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$top_badge = !empty($instance['top_badge']);
|
||||||
|
|
||||||
echo '<ul class="aksrt-user-ranking">';
|
echo '<ul class="aksrt-user-ranking">';
|
||||||
$rank = 0;
|
$rank = 0;
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
@@ -46,7 +53,12 @@ class WidgetUserRanking extends \WP_Widget {
|
|||||||
? aksrt_get_user_home_url($user['id'])
|
? aksrt_get_user_home_url($user['id'])
|
||||||
: get_author_posts_url($user['id']);
|
: get_author_posts_url($user['id']);
|
||||||
|
|
||||||
echo '<li class="aksrt-user-ranking__item' . esc_attr($rank_class) . '">';
|
echo '<li class="aksrt-user-ranking__item relative' . esc_attr($rank_class) . '">';
|
||||||
|
|
||||||
|
if ($top_badge && $rank <= 3) {
|
||||||
|
$tone = $rank === 1 ? 'jb-red' : ($rank === 2 ? 'jb-yellow' : 'b-gray');
|
||||||
|
echo '<badge class="img-badge left hot ' . esc_attr($tone) . '"><i>TOP' . (int) $rank . '</i></badge>';
|
||||||
|
}
|
||||||
|
|
||||||
// 排名
|
// 排名
|
||||||
echo '<span class="aksrt-user-ranking__rank">' . esc_html((string) $rank) . '</span>';
|
echo '<span class="aksrt-user-ranking__rank">' . esc_html((string) $rank) . '</span>';
|
||||||
@@ -76,7 +88,7 @@ class WidgetUserRanking extends \WP_Widget {
|
|||||||
}
|
}
|
||||||
echo '</ul>';
|
echo '</ul>';
|
||||||
|
|
||||||
echo $args['after_widget'];
|
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_ranking(string $rank_by, int $count, string $desc_mode = 'desc'): array {
|
private function get_ranking(string $rank_by, int $count, string $desc_mode = 'desc'): array {
|
||||||
@@ -287,6 +299,12 @@ class WidgetUserRanking extends \WP_Widget {
|
|||||||
<?php esc_html_e('顶部显示签到按钮', 'aksrt'); ?>
|
<?php esc_html_e('顶部显示签到按钮', 'aksrt'); ?>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="<?php echo esc_attr($this->get_field_name('top_badge')); ?>" value="1" <?php checked(!empty($instance['top_badge'])); ?>>
|
||||||
|
<?php esc_html_e('前三名 TOP 角标', 'aksrt'); ?>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,6 +315,7 @@ class WidgetUserRanking extends \WP_Widget {
|
|||||||
$instance['count'] = max(1, min(20, (int) ($new_instance['count'] ?? 5)));
|
$instance['count'] = max(1, min(20, (int) ($new_instance['count'] ?? 5)));
|
||||||
$instance['show_avatar'] = !empty($new_instance['show_avatar']);
|
$instance['show_avatar'] = !empty($new_instance['show_avatar']);
|
||||||
$instance['checkin_btn'] = !empty($new_instance['checkin_btn']);
|
$instance['checkin_btn'] = !empty($new_instance['checkin_btn']);
|
||||||
|
$instance['top_badge'] = !empty($new_instance['top_badge']);
|
||||||
$instance['desc'] = in_array($new_instance['desc'] ?? '', ['desc', 'user_registered', 'last_login', 'last_checkin'], true) ? $new_instance['desc'] : 'desc';
|
$instance['desc'] = in_array($new_instance['desc'] ?? '', ['desc', 'user_registered', 'last_login', 'last_checkin'], true) ? $new_instance['desc'] : 'desc';
|
||||||
return $instance;
|
return $instance;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user