fix: restyle pager chips and restore theme ad slots
Build and Deploy / verify (push) Successful in 37s
Build and Deploy / deploy (push) Successful in 38s

Replace the loose page-count label with a SaBlog-style 6 / 316 chip, wire inject/stylevar HTML into list and post views, and flush page cache when ads are saved.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
gouki
2026-09-18 21:48:24 +00:00
co-authored by Cursor
parent ae47447062
commit 36c4ffc5b4
41 changed files with 936 additions and 81 deletions
+63
View File
@@ -34,6 +34,24 @@ class ThemeInjector
'body_end' => '页面末尾(</body> 前)',
];
/**
* Old SaBlog stylevar names → inject points. Unmapped HTML vars go to footer.
*
* @var array<string, list<string>>
*/
public const STYLEVAR_POINTS = [
'head' => ['ad_head', 'headad'],
'header' => ['headerad', 'header_ad', 'ad_header', 'topad', 'ad_top', 'sitead', 'site_ad'],
'sidebar_top' => ['sidebarad', 'sidebar_ad', 'ad_sidebar', 'leftad', 'ad_left'],
'sidebar_bottom' => ['ad_sidebar_bottom'],
'content_top' => ['indexad', 'ad_index', 'contentad', 'ad_content'],
'content_bottom' => ['ad_content_bottom'],
'post_content_top' => ['ad_post_top', 'insad'],
'post_content_bottom' => ['ad_post_bottom'],
'footer' => ['footerad', 'footer_ad', 'ad_footer', 'huangjinlian', 'huangjinlian2', 'huangjinlian3'],
'body_end' => ['ad_body_end'],
];
/**
* 读取某一注入点的所有注入块(多条,已排序、已过滤停用),
* 并把插件追加的 HTML 合并进来。
@@ -51,6 +69,10 @@ class ThemeInjector
->values()
->all();
foreach (self::stylevarBlocks($point) as $html) {
$blocks[] = $html;
}
$extra = (string) app(PluginManager::class)->applyFilters("theme.inject.{$point}", '');
if ($extra !== '') {
@@ -75,4 +97,45 @@ class ThemeInjector
}
});
}
/**
* @return list<string>
*/
private static function stylevarBlocks(string $point): array
{
$vars = app(ThemeManager::class)->variables();
if ($vars === []) {
return [];
}
$html = [];
foreach (self::STYLEVAR_POINTS[$point] ?? [] as $key) {
$value = trim((string) ($vars[$key] ?? ''));
if ($value !== '') {
$html[] = $value;
}
}
if ($point !== 'footer') {
return $html;
}
$mapped = [];
foreach (self::STYLEVAR_POINTS as $keys) {
foreach ($keys as $key) {
$mapped[$key] = true;
}
}
foreach ($vars as $key => $value) {
$value = trim((string) $value);
if ($value === '' || isset($mapped[$key]) || ! str_contains($value, '<')) {
continue;
}
$html[] = $value;
}
return $html;
}
}
+30 -1
View File
@@ -59,6 +59,7 @@ class SablogImport extends Command
}
$this->importSettings();
$this->importStylevars();
$this->importCategories();
$this->importUsers();
$this->importPosts();
@@ -144,7 +145,7 @@ class SablogImport extends Command
* searchindex —— 搜索缓存,现代 SQL 全文检索足够
* sessions —— Laravel 原生会话
* statistics —— 实时统计
* stylevars —— 老式广告位变量
* stylevars —— 导入为当前主题的 theme_vars(广告位)
* seccode / 验证码 —— 由 AI 审核 + 蜜罐 + 频控取代
*/
private function importSettings(): void
@@ -182,6 +183,34 @@ class SablogImport extends Command
$this->report['settings'] = $count;
}
private function importStylevars(): void
{
if (! $this->hasTable('stylevars')) {
return;
}
$vars = [];
foreach ($this->rows('stylevars') as $row) {
$name = (string) ($row['title'] ?? $row['variable'] ?? $row['name'] ?? '');
$value = (string) ($row['value'] ?? $row['content'] ?? '');
if ($name === '' || $value === '') {
continue;
}
$vars[$name] = $value;
}
if ($vars === []) {
return;
}
$theme = (string) Setting::get('active_theme', 'sablog');
$existing = Setting::get('theme_vars_'.$theme, []);
$existing = is_array($existing) ? $existing : (json_decode((string) $existing, true) ?: []);
Setting::set('theme_vars_'.$theme, array_merge($existing, $vars));
$this->report['stylevars'] = count($vars);
}
private function importCategories(): void
{
$count = 0;
+1
View File
@@ -119,6 +119,7 @@ class ThemeInject extends Page
Setting::set('inject.blocks', $blocks);
Setting::set('theme_vars_'.app(ThemeManager::class)->active(), $data['theme_vars'] ?? []);
\App\Blog\Support\PageCacheMiddleware::flush();
Notification::make()->title('注入内容已保存')->success()->send();
}