Merge pull request 'Worktree ux depth batch12' (#230) from worktree-ux-depth-batch12 into main
Reviewed-on: CYL/wordpress-theme-aksrt#230
This commit is contained in:
@@ -1303,3 +1303,132 @@
|
||||
.aksrt-faq__main { grid-template-columns: 1fr; }
|
||||
.aksrt-faq__a { padding-left: 14px; }
|
||||
}
|
||||
|
||||
/* ---- batch12: video shell + bookmark links styles + product oneline swiper ---- */
|
||||
.aksrt-video-widget {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
border-radius: 10px;
|
||||
background: #000;
|
||||
}
|
||||
.aksrt-video-widget.radius8 { border-radius: 10px; }
|
||||
.aksrt-video-widget__frame,
|
||||
.aksrt-video-widget__player,
|
||||
.aksrt-video-widget .aksrt-video {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.aksrt-video-widget__frame {
|
||||
border: 0;
|
||||
display: block;
|
||||
}
|
||||
.aksrt-video-widget.controller-hide .aksrt-video video::-webkit-media-controls {
|
||||
opacity: 0;
|
||||
transition: opacity .2s ease;
|
||||
}
|
||||
.aksrt-video-widget.controller-hide:hover .aksrt-video video::-webkit-media-controls {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.aksrt-bookmark-links.links-box {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
.aksrt-bookmark-links.style-card .author-minicard,
|
||||
.aksrt-bookmark-links.style-bigcard .author-minicard {
|
||||
flex: 1 1 calc(50% - 12px);
|
||||
min-width: 140px;
|
||||
background: var(--surface-2, #f8fafc);
|
||||
border: 1px solid var(--color-line, #e5e7eb);
|
||||
padding: 12px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.aksrt-bookmark-links.style-bigcard .author-minicard {
|
||||
flex: 1 1 100%;
|
||||
text-align: center;
|
||||
}
|
||||
.aksrt-bookmark-links .avatar-img img,
|
||||
.aksrt-bookmark-links .link-img img {
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.aksrt-bookmark-links.style-bigcard .avatar-img img {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
}
|
||||
.aksrt-bookmark-links.style-image {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.aksrt-bookmark-links.style-image .link-only-img img {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 10px;
|
||||
object-fit: cover;
|
||||
}
|
||||
.aksrt-bookmark-links.style-simple {
|
||||
display: block;
|
||||
line-height: 1.9;
|
||||
font-size: 13px;
|
||||
}
|
||||
.aksrt-bookmark-links.style-simple a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
margin-right: 8px;
|
||||
}
|
||||
.aksrt-bookmark-links.style-simple a:hover {
|
||||
color: var(--color-primary, #3b82f6);
|
||||
}
|
||||
.aksrt-bookmark-links.has-box {
|
||||
padding: 12px;
|
||||
border: 1px solid var(--color-line, #e5e7eb);
|
||||
border-radius: 12px;
|
||||
background: var(--surface-1, #fff);
|
||||
}
|
||||
|
||||
.aksrt-product-oneline-swiper {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
padding: 0 28px 4px;
|
||||
}
|
||||
.aksrt-product-oneline-swiper .swiper-wrapper {
|
||||
display: flex;
|
||||
}
|
||||
.aksrt-product-oneline-swiper .swiper-slide {
|
||||
width: auto;
|
||||
max-width: 46%;
|
||||
min-width: 150px;
|
||||
height: auto;
|
||||
}
|
||||
.aksrt-product-oneline-swiper .aksrt-product-card {
|
||||
height: 100%;
|
||||
}
|
||||
.aksrt-product-oneline-swiper .swiper-button-prev,
|
||||
.aksrt-product-oneline-swiper .swiper-button-next {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
margin-top: 0;
|
||||
top: 42%;
|
||||
border-radius: 50%;
|
||||
background: var(--surface-1, #fff);
|
||||
border: 1px solid var(--color-line, #e5e7eb);
|
||||
color: var(--color-ink, #111);
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,.06);
|
||||
}
|
||||
.aksrt-product-oneline-swiper .swiper-button-prev:after,
|
||||
.aksrt-product-oneline-swiper .swiper-button-next:after {
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.aksrt-product-oneline-swiper .swiper-button-prev { left: 0; }
|
||||
.aksrt-product-oneline-swiper .swiper-button-next { right: 0; }
|
||||
.aksrt-product-widget--oneline .aksrt-product-widget__grid {
|
||||
/* legacy flex fallback if swiper unavailable */
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@
|
||||
this.poster = this.el.dataset.poster || '';
|
||||
this.type = this.el.dataset.type || detectType(this.src);
|
||||
this.autoplay = this.el.dataset.autoplay === 'true';
|
||||
this.loop = this.el.dataset.loop === 'true';
|
||||
this.muted = this.el.dataset.muted === 'true' || this.autoplay;
|
||||
this.init();
|
||||
}
|
||||
|
||||
@@ -76,8 +78,10 @@
|
||||
this.video.controls = true;
|
||||
this.video.playsInline = true;
|
||||
this.video.preload = this.autoplay ? 'auto' : 'metadata';
|
||||
if (this.loop) this.video.loop = true;
|
||||
if (this.muted) this.video.muted = true;
|
||||
if (this.poster) this.video.poster = this.poster;
|
||||
this.video.style.cssText = 'display:block;width:100%;height:auto;max-height:70vh;';
|
||||
this.video.style.cssText = 'display:block;width:100%;height:100%;object-fit:contain;max-height:none;';
|
||||
|
||||
// Play overlay
|
||||
this.overlay = document.createElement('div');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* WordPress bookmark / links list (zibll widget_ui_links_lists_2).
|
||||
* WordPress bookmark / links list (zibll widget_ui_links_lists via aksrt_links_box).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -16,7 +16,7 @@ class WidgetBookmarkLinks extends \WP_Widget {
|
||||
'aksrt_bookmark_links',
|
||||
esc_html__('AKSRT 链接列表', 'aksrt'),
|
||||
[
|
||||
'description' => esc_html__('WordPress 链接(书签)列表,适合友链/导航。', 'aksrt'),
|
||||
'description' => esc_html__('WordPress 链接(书签)列表:card / bigcard / image / simple。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_bookmark_links',
|
||||
]
|
||||
);
|
||||
@@ -30,12 +30,12 @@ class WidgetBookmarkLinks extends \WP_Widget {
|
||||
}
|
||||
$order = strtoupper((string) ($instance['links_order'] ?? 'ASC')) === 'DESC' ? 'DESC' : 'ASC';
|
||||
$type = sanitize_key((string) ($instance['type'] ?? 'card'));
|
||||
if (!in_array($type, ['card', 'image', 'simple'], true)) {
|
||||
if (!in_array($type, ['card', 'bigcard', 'image', 'simple'], true)) {
|
||||
$type = 'card';
|
||||
}
|
||||
$go_link = !empty($instance['go_link']);
|
||||
$blank = !isset($instance['blank']) || !empty($instance['blank']);
|
||||
$nofollow = !empty($instance['nofollow']);
|
||||
$nofollow = !isset($instance['nofollow']) || !empty($instance['nofollow']);
|
||||
$show_box = !empty($instance['show_box']);
|
||||
|
||||
$bm_args = [
|
||||
@@ -49,6 +49,13 @@ class WidgetBookmarkLinks extends \WP_Widget {
|
||||
}
|
||||
$bookmarks = get_bookmarks($bm_args);
|
||||
if (!$bookmarks) {
|
||||
if (current_user_can('manage_options')) {
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo function_exists('aksrt_get_widget_null')
|
||||
? aksrt_get_widget_null(__('暂无链接,请在「链接」中添加', 'aksrt')) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
: '<p class="widget-empty">' . esc_html__('暂无链接', 'aksrt') . '</p>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,37 +65,22 @@ class WidgetBookmarkLinks extends \WP_Widget {
|
||||
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
$wrap = 'aksrt-bookmark-links style-' . $type . ($show_box ? ' has-box' : '');
|
||||
$wrap = 'aksrt-bookmark-links links-box style-' . $type . ($show_box ? ' has-box' : '');
|
||||
echo '<div class="' . esc_attr($wrap) . '">';
|
||||
foreach ($bookmarks as $b) {
|
||||
$url = (string) $b->link_url;
|
||||
if ($url !== '' && $go_link && function_exists('aksrt_go_link')) {
|
||||
$url = aksrt_go_link($url, true);
|
||||
if (function_exists('aksrt_links_box')) {
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo aksrt_links_box($bookmarks, $type, $nofollow, $go_link, $blank);
|
||||
} else {
|
||||
// Minimal fallback.
|
||||
foreach ($bookmarks as $b) {
|
||||
$url = (string) $b->link_url;
|
||||
if ($url !== '' && $go_link && function_exists('aksrt_go_link')) {
|
||||
$url = aksrt_go_link($url, true);
|
||||
}
|
||||
echo '<a class="aksrt-bookmark-links__item" href="' . esc_url($url) . '"' . ($blank ? ' target="_blank" rel="noopener noreferrer"' : '') . '>';
|
||||
echo esc_html((string) $b->link_name);
|
||||
echo '</a>';
|
||||
}
|
||||
$rel = [];
|
||||
if ($nofollow) {
|
||||
$rel[] = 'nofollow';
|
||||
}
|
||||
if ($blank) {
|
||||
$rel[] = 'noopener';
|
||||
$rel[] = 'noreferrer';
|
||||
}
|
||||
$rel_attr = $rel ? ' rel="' . esc_attr(implode(' ', $rel)) . '"' : '';
|
||||
$tgt = $blank ? ' target="_blank"' : '';
|
||||
$img = (string) $b->link_image;
|
||||
$name = (string) $b->link_name;
|
||||
$desc = (string) $b->link_description;
|
||||
|
||||
echo '<a class="aksrt-bookmark-links__item" href="' . esc_url($url) . '"' . $tgt . $rel_attr . '>';
|
||||
if ($type !== 'simple' && $img !== '') {
|
||||
echo '<img class="aksrt-bookmark-links__img" src="' . esc_url($img) . '" alt="" loading="lazy" />';
|
||||
}
|
||||
echo '<span class="aksrt-bookmark-links__text">';
|
||||
echo '<span class="aksrt-bookmark-links__name">' . esc_html($name) . '</span>';
|
||||
if ($type === 'card' && $desc !== '') {
|
||||
echo '<span class="aksrt-bookmark-links__desc">' . esc_html($desc) . '</span>';
|
||||
}
|
||||
echo '</span></a>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
@@ -116,6 +108,7 @@ class WidgetBookmarkLinks extends \WP_Widget {
|
||||
<label><?php esc_html_e('样式', 'aksrt'); ?>
|
||||
<select name="<?php echo esc_attr($this->get_field_name('type')); ?>">
|
||||
<option value="card" <?php selected(($instance['type'] ?? 'card'), 'card'); ?>><?php esc_html_e('图文卡片', 'aksrt'); ?></option>
|
||||
<option value="bigcard" <?php selected(($instance['type'] ?? ''), 'bigcard'); ?>><?php esc_html_e('大卡片', 'aksrt'); ?></option>
|
||||
<option value="image" <?php selected(($instance['type'] ?? ''), 'image'); ?>><?php esc_html_e('图片', 'aksrt'); ?></option>
|
||||
<option value="simple" <?php selected(($instance['type'] ?? ''), 'simple'); ?>><?php esc_html_e('纯文字', 'aksrt'); ?></option>
|
||||
</select>
|
||||
@@ -137,7 +130,7 @@ class WidgetBookmarkLinks extends \WP_Widget {
|
||||
</p>
|
||||
<p>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('blank')); ?>" value="1" <?php checked(!isset($instance['blank']) || !empty($instance['blank'])); ?>> <?php esc_html_e('新窗口', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('nofollow')); ?>" value="1" <?php checked(!empty($instance['nofollow'])); ?>> <?php esc_html_e('nofollow', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('nofollow')); ?>" value="1" <?php checked(!isset($instance['nofollow']) || !empty($instance['nofollow'])); ?>> <?php esc_html_e('nofollow', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('go_link')); ?>" value="1" <?php checked(!empty($instance['go_link'])); ?>> <?php esc_html_e('外链跳转页', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_box')); ?>" value="1" <?php checked(!empty($instance['show_box'])); ?>> <?php esc_html_e('外框盒子', 'aksrt'); ?></label>
|
||||
</p>
|
||||
@@ -145,13 +138,17 @@ class WidgetBookmarkLinks extends \WP_Widget {
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$type = sanitize_key((string) ($new_instance['type'] ?? 'card'));
|
||||
if (!in_array($type, ['card', 'bigcard', 'image', 'simple'], true)) {
|
||||
$type = 'card';
|
||||
}
|
||||
return [
|
||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||
'links_cats' => sanitize_text_field((string) ($new_instance['links_cats'] ?? '')),
|
||||
'links_limit' => max(0, min(100, (int) ($new_instance['links_limit'] ?? 12))),
|
||||
'links_orderby' => sanitize_key((string) ($new_instance['links_orderby'] ?? 'name')),
|
||||
'links_order' => strtoupper((string) ($new_instance['links_order'] ?? 'ASC')) === 'DESC' ? 'DESC' : 'ASC',
|
||||
'type' => in_array(($new_instance['type'] ?? ''), ['card', 'image', 'simple'], true) ? $new_instance['type'] : 'card',
|
||||
'type' => $type,
|
||||
'blank' => !empty($new_instance['blank']) ? 1 : 0,
|
||||
'nofollow' => !empty($new_instance['nofollow']) ? 1 : 0,
|
||||
'go_link' => !empty($new_instance['go_link']) ? 1 : 0,
|
||||
|
||||
@@ -93,6 +93,7 @@ class WidgetProductList extends \WP_Widget {
|
||||
if (!$products->have_posts()) {
|
||||
return '';
|
||||
}
|
||||
$oneline = $style === 'oneline';
|
||||
ob_start();
|
||||
while ($products->have_posts()) {
|
||||
$products->the_post();
|
||||
@@ -100,30 +101,36 @@ class WidgetProductList extends \WP_Widget {
|
||||
$card = class_exists('\AKSRT\Shop\Shop')
|
||||
? \AKSRT\Shop\Shop::get_instance()->build_product_card_view($pid)
|
||||
: [];
|
||||
if ($oneline) {
|
||||
echo '<div class="swiper-slide ajax-item">';
|
||||
}
|
||||
if (function_exists('get_template_part') && !empty($card['id'])) {
|
||||
get_template_part('templates/parts/shop/product', 'card', [
|
||||
'product' => $card,
|
||||
'show_sales' => true,
|
||||
]);
|
||||
continue;
|
||||
} else {
|
||||
// Fallback mini card.
|
||||
$price = (float) ($card['price'] ?? 0);
|
||||
$image = (string) ($card['image'] ?? '');
|
||||
echo '<div class="aksrt-product-widget__item ajax-item">';
|
||||
if ($image !== '') {
|
||||
echo '<a href="' . esc_url(get_permalink($pid)) . '" class="aksrt-product-widget__thumb">';
|
||||
echo '<img src="' . esc_url($image) . '" alt="' . esc_attr(get_the_title($pid)) . '" loading="lazy">';
|
||||
echo '</a>';
|
||||
}
|
||||
echo '<div class="aksrt-product-widget__info">';
|
||||
echo '<a href="' . esc_url(get_permalink($pid)) . '" class="aksrt-product-widget__title">' . esc_html(get_the_title($pid)) . '</a>';
|
||||
echo '<div class="aksrt-product-widget__meta">';
|
||||
echo '<span class="aksrt-product-widget__price">¥' . esc_html(number_format_i18n($price, 2)) . '</span>';
|
||||
if (!empty($card['sales'])) {
|
||||
echo '<span class="aksrt-product-widget__sales">' . esc_html((string) $card['sales']) . esc_html__(' 已售', 'aksrt') . '</span>';
|
||||
}
|
||||
echo '</div></div></div>';
|
||||
}
|
||||
// Fallback mini card.
|
||||
$price = (float) ($card['price'] ?? 0);
|
||||
$image = (string) ($card['image'] ?? '');
|
||||
echo '<div class="aksrt-product-widget__item ajax-item">';
|
||||
if ($image !== '') {
|
||||
echo '<a href="' . esc_url(get_permalink($pid)) . '" class="aksrt-product-widget__thumb">';
|
||||
echo '<img src="' . esc_url($image) . '" alt="' . esc_attr(get_the_title($pid)) . '" loading="lazy">';
|
||||
echo '</a>';
|
||||
if ($oneline) {
|
||||
echo '</div>';
|
||||
}
|
||||
echo '<div class="aksrt-product-widget__info">';
|
||||
echo '<a href="' . esc_url(get_permalink($pid)) . '" class="aksrt-product-widget__title">' . esc_html(get_the_title($pid)) . '</a>';
|
||||
echo '<div class="aksrt-product-widget__meta">';
|
||||
echo '<span class="aksrt-product-widget__price">¥' . esc_html(number_format_i18n($price, 2)) . '</span>';
|
||||
if (!empty($card['sales'])) {
|
||||
echo '<span class="aksrt-product-widget__sales">' . esc_html((string) $card['sales']) . esc_html__(' 已售', 'aksrt') . '</span>';
|
||||
}
|
||||
echo '</div></div></div>';
|
||||
}
|
||||
wp_reset_postdata();
|
||||
return (string) ob_get_clean();
|
||||
@@ -231,12 +238,25 @@ class WidgetProductList extends \WP_Widget {
|
||||
|
||||
$style_class = 'aksrt-product-widget--' . $style;
|
||||
echo '<div class="aksrt-product-widget ' . esc_attr($style_class) . '" data-aksrt-product-widget data-aksrt-product-config="' . esc_attr(wp_json_encode($cfg)) . '">';
|
||||
// Items sit directly under .ajaxpager so ajax-list inject/append works (zibll product-lists-row).
|
||||
echo '<div class="ajaxpager aksrt-product-widget__grid product-lists-row" data-aksrt-ajaxpager data-aksrt-ajax-url="' . esc_url($ajax_url) . '">';
|
||||
echo $payload['html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped — cards escaped upstream
|
||||
echo $payload['paginate_html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<div class="post_ajax_loader" data-aksrt-ajax-loader data-aksrt-ajax-loader-hide hidden></div>';
|
||||
echo '</div></div>';
|
||||
|
||||
if ($style === 'oneline') {
|
||||
// zibll-style horizontal swiper-scroll (shared slider.js Type A).
|
||||
echo '<div class="swiper-container swiper-scroll aksrt-product-oneline-swiper">';
|
||||
echo '<div class="swiper-wrapper product-lists-row">';
|
||||
echo $payload['html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '</div>';
|
||||
echo '<div class="swiper-button-prev" aria-label="' . esc_attr__('上一页', 'aksrt') . '"></div>';
|
||||
echo '<div class="swiper-button-next" aria-label="' . esc_attr__('下一页', 'aksrt') . '"></div>';
|
||||
echo '</div>';
|
||||
} else {
|
||||
// Items sit directly under .ajaxpager so ajax-list inject/append works (zibll product-lists-row).
|
||||
echo '<div class="ajaxpager aksrt-product-widget__grid product-lists-row" data-aksrt-ajaxpager data-aksrt-ajax-url="' . esc_url($ajax_url) . '">';
|
||||
echo $payload['html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped — cards escaped upstream
|
||||
echo $payload['paginate_html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<div class="post_ajax_loader" data-aksrt-ajax-loader data-aksrt-ajax-loader-hide hidden></div>';
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
@@ -67,7 +67,22 @@ class WidgetStats extends \WP_Widget {
|
||||
if ($s['prefix'] !== '') {
|
||||
echo '<span class="aksrt-stats__prefix">' . esc_html($s['prefix']) . '</span>';
|
||||
}
|
||||
echo '<span class="aksrt-stats__number" data-target="' . esc_attr($s['number']) . '">' . esc_html($s['number']) . '</span>';
|
||||
// Wire effects.js count-up when number is numeric.
|
||||
$raw_num = preg_replace('/[^\d.]/', '', (string) $s['number']);
|
||||
$is_numeric = $raw_num !== '' && is_numeric($raw_num);
|
||||
if ($is_numeric) {
|
||||
$dec = 0;
|
||||
if (str_contains((string) $raw_num, '.')) {
|
||||
$dec = strlen(substr(strrchr((string) $raw_num, '.'), 1));
|
||||
}
|
||||
printf(
|
||||
'<span class="aksrt-stats__number" data-aksrt-countup data-target="%s" data-duration="1600" data-decimals="%d">0</span>',
|
||||
esc_attr((string) $raw_num),
|
||||
(int) $dec
|
||||
);
|
||||
} else {
|
||||
echo '<span class="aksrt-stats__number" data-target="' . esc_attr($s['number']) . '">' . esc_html($s['number']) . '</span>';
|
||||
}
|
||||
if ($s['unit'] !== '') {
|
||||
echo '<span class="aksrt-stats__unit">' . esc_html($s['unit']) . '</span>';
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Video player widget (zibll dplayer lite via native video / oEmbed).
|
||||
* Video player widget (zibll dplayer lite via data-aksrt-video + embed).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -15,7 +15,10 @@ class WidgetVideoPlayer extends \WP_Widget {
|
||||
parent::__construct(
|
||||
'aksrt_video_player',
|
||||
__('视频播放器', 'aksrt'),
|
||||
['description' => __('侧栏/流体区嵌入视频播放器。', 'aksrt')]
|
||||
[
|
||||
'description' => __('侧栏/流体区嵌入视频(共享 aksrt-video 播放器)。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_video_player',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,6 +34,12 @@ class WidgetVideoPlayer extends \WP_Widget {
|
||||
$aspect = (string) ($instance['aspect_ratio'] ?? '');
|
||||
|
||||
if ($video_url === '') {
|
||||
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__('请配置视频 URL 或移出该模块', 'aksrt') . '</div>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,29 +56,32 @@ class WidgetVideoPlayer extends \WP_Widget {
|
||||
}
|
||||
|
||||
$embed = $this->get_embed_url($video_url);
|
||||
$cls = 'aksrt-video-widget' . ($hide_controller ? ' controller-hide' : '');
|
||||
$cls = 'aksrt-video-widget relative-h radius8' . ($hide_controller ? ' controller-hide' : '');
|
||||
echo '<div class="' . esc_attr($cls) . '" style="padding-bottom:' . esc_attr((string) $scale) . '%">';
|
||||
|
||||
if ($embed !== '') {
|
||||
$src = $embed;
|
||||
if ($autoplay) {
|
||||
$src = add_query_arg(['autoplay' => '1', 'mute' => '1'], $src);
|
||||
}
|
||||
echo '<iframe src="' . esc_url($src) . '" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen loading="lazy"></iframe>';
|
||||
echo '<iframe class="aksrt-video-widget__frame" src="' . esc_url($src) . '" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen loading="lazy"></iframe>';
|
||||
} else {
|
||||
$attrs = ' controls playsinline';
|
||||
if ($autoplay) {
|
||||
$attrs .= ' autoplay';
|
||||
// Shared player stack (assets/js/video-player.js).
|
||||
$type = 'mp4';
|
||||
if (preg_match('/\.m3u8(\?|$)/i', $video_url)) {
|
||||
$type = 'hls';
|
||||
} elseif (preg_match('/\.flv(\?|$)/i', $video_url)) {
|
||||
$type = 'flv';
|
||||
}
|
||||
if ($loop) {
|
||||
$attrs .= ' loop';
|
||||
}
|
||||
if ($muted) {
|
||||
$attrs .= ' muted';
|
||||
}
|
||||
if ($poster !== '') {
|
||||
$attrs .= ' poster="' . esc_url($poster) . '"';
|
||||
}
|
||||
echo '<video' . $attrs . '><source src="' . esc_url($video_url) . '"></video>';
|
||||
printf(
|
||||
'<div class="aksrt-video aksrt-video-widget__player" data-aksrt-video data-src="%s" data-type="%s"%s%s%s%s></div>',
|
||||
esc_url($video_url),
|
||||
esc_attr($type),
|
||||
$poster !== '' ? ' data-poster="' . esc_url($poster) . '"' : '',
|
||||
$autoplay ? ' data-autoplay="true"' : '',
|
||||
$loop ? ' data-loop="true"' : '',
|
||||
$muted ? ' data-muted="true"' : ''
|
||||
);
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
@@ -97,7 +109,7 @@ class WidgetVideoPlayer extends \WP_Widget {
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('视频 URL', 'aksrt'); ?>
|
||||
<label><?php esc_html_e('视频 URL(mp4/m3u8/flv 或 YouTube/B站/腾讯)', 'aksrt'); ?>
|
||||
<input class="widefat" type="url" name="<?php echo esc_attr($this->get_field_name('video_url')); ?>" value="<?php echo esc_attr((string) ($instance['video_url'] ?? '')); ?>">
|
||||
</label>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user