refactor: flatten src/AKSRT → src (drop theme-identifier dir)
Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
This commit is contained in:
1 parent
56f1a8175f
commit
8c5b1555c9
285 files changed
+26
-3600
No files matched your search
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Messages;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class SiteNotice {
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
private function __construct() {}
|
||||
|
||||
public static function get_instance(): self {
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
add_action('wp_footer', [$this, 'render_notice']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if site notice is enabled, has content, not expired,
|
||||
* and current user matches the target audience (policy).
|
||||
*/
|
||||
private function is_active(): bool {
|
||||
if (!class_exists('\AKSRT\Settings\Settings')) return false;
|
||||
|
||||
$cfg = \AKSRT\Settings\Settings::get_system_notice_config();
|
||||
if (!$cfg['enabled'] || $cfg['content'] === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 身份策略检查
|
||||
$policy = $cfg['policy'];
|
||||
if ($policy !== '') {
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
switch ($policy) {
|
||||
case 'signin':
|
||||
if ($user_id <= 0) return false;
|
||||
break;
|
||||
|
||||
case 'vip':
|
||||
if (!function_exists('aksrt_is_vip') || !aksrt_is_vip($user_id)) return false;
|
||||
break;
|
||||
|
||||
case 'free':
|
||||
if (function_exists('aksrt_is_vip') && aksrt_is_vip($user_id)) return false;
|
||||
break;
|
||||
|
||||
case 'auth':
|
||||
if ($user_id <= 0) return false;
|
||||
$verified = get_user_meta($user_id, 'email_verified', true);
|
||||
if (!$verified) {
|
||||
$verified = get_user_meta($user_id, 'phone_verified', true);
|
||||
}
|
||||
if (!$verified) return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 过期检查:expires 为小时数,0=永不过期
|
||||
$expires_hours = (int) $cfg['expires'];
|
||||
if ($expires_hours > 0 && isset($_COOKIE['aksrt_notice_seen'])) {
|
||||
$seen_ts = absint($_COOKIE['aksrt_notice_seen']);
|
||||
if ($seen_ts > 0 && (time() - $seen_ts) < ($expires_hours * 3600)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the notice popup in footer
|
||||
*/
|
||||
public function render_notice(): void {
|
||||
if (!$this->is_active()) return;
|
||||
|
||||
$cfg = \AKSRT\Settings\Settings::get_system_notice_config();
|
||||
$content = wp_kses_post($cfg['content']);
|
||||
$title = esc_html($cfg['title'] ?: __('站点公告', 'aksrt'));
|
||||
$extra_cls = $cfg['class'] ? ' ' . esc_attr($cfg['class']) : '';
|
||||
$radius = absint($cfg['radius']);
|
||||
$size_cls = $cfg['size'];
|
||||
|
||||
// 标题图标 / 样式
|
||||
$title_icon = $cfg['title_icon'];
|
||||
$title_cls = $cfg['title_class'] ? ' ' . esc_attr($cfg['title_class']) : '';
|
||||
$title_style = $cfg['title_style'] ? ' style="' . esc_attr($cfg['title_style']) . '"' : '';
|
||||
|
||||
// 弹窗尺寸 class
|
||||
$dialog_cls = 'aksrt-site-notice__dialog';
|
||||
if ($size_cls !== '') {
|
||||
$dialog_cls .= ' ' . esc_attr($size_cls);
|
||||
}
|
||||
|
||||
// 内联样式:圆角
|
||||
$dialog_style = 'display:none;';
|
||||
if ($radius > 0) {
|
||||
$dialog_style .= 'border-radius:' . $radius . 'px;';
|
||||
}
|
||||
|
||||
$buttons = $cfg['buttons'];
|
||||
?>
|
||||
<div id="aksrt-site-notice"
|
||||
class="aksrt-site-notice<?php echo $extra_cls; ?>"
|
||||
data-expires="<?php echo esc_attr($cfg['expires']); ?>"
|
||||
style="<?php echo esc_attr($dialog_style); ?>">
|
||||
<div class="aksrt-site-notice__overlay"></div>
|
||||
<div class="<?php echo $dialog_cls; ?>">
|
||||
<div class="aksrt-site-notice__head">
|
||||
<h3 class="aksrt-site-notice__title<?php echo $title_cls; ?>"<?php echo $title_style; ?>>
|
||||
<?php if ($title_icon): ?><i class="<?php echo esc_attr($title_icon); ?>"></i> <?php endif; ?>
|
||||
<?php echo $title; ?>
|
||||
</h3>
|
||||
<button type="button" class="aksrt-site-notice__close" aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>">
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="aksrt-site-notice__body">
|
||||
<?php echo $content; ?>
|
||||
</div>
|
||||
<?php if (!empty($buttons)): ?>
|
||||
<div class="aksrt-site-notice__foot">
|
||||
<?php foreach ($buttons as $btn): ?>
|
||||
<?php
|
||||
$btn_cls = 'aksrt-site-notice__btn aksrt-site-notice__btn--' . esc_attr($btn['color']);
|
||||
if ($btn['link']):
|
||||
?>
|
||||
<a href="<?php echo esc_url($btn['link']); ?>" class="<?php echo $btn_cls; ?>"><?php echo esc_html($btn['text']); ?></a>
|
||||
<?php else: ?>
|
||||
<button type="button" class="<?php echo $btn_cls; ?>" data-dismiss="notice"><?php echo esc_html($btn['text']); ?></button>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user