'页头( 前)', 'header' => '页头下方', 'sidebar_top' => '侧边栏顶部', 'sidebar_bottom' => '侧边栏底部', 'content_top' => '内容区顶部', 'content_bottom' => '内容区底部', 'post_content_top' => '文章正文前', 'post_content_bottom' => '文章正文后', 'footer' => '页脚前', 'body_end' => '页面末尾( 前)', ]; /** * 读取某一注入点的所有注入块(多条,已排序、已过滤停用), * 并把插件追加的 HTML 合并进来。 */ public static function blocksFor(string $point): array { $raw = Setting::get('inject.blocks', []); $raw = is_array($raw) ? $raw : (json_decode((string) $raw, true) ?: []); $blocks = collect($raw) ->filter(fn (array $b) => ($b['point'] ?? null) === $point && ($b['enabled'] ?? true)) ->sortBy(fn (array $b) => (int) ($b['sort'] ?? 0)) ->pluck('html') ->filter() ->values() ->all(); $extra = (string) app(PluginManager::class)->applyFilters("theme.inject.{$point}", ''); if ($extra !== '') { $blocks[] = $extra; } return $blocks; } /** * 注册 View Composer:渲染前台视图前把各注入点内容 push 到对应 @stack。 */ public static function registerComposer(): void { $views = ['index', 'show', 'list', 'archives', 'tags', 'tag', 'search', 'links', 'comments', 'login', 'register', 'profile', 'membership.*', 'payments.*']; \Illuminate\Support\Facades\View::composer($views, function (\Illuminate\View\View $view) { foreach (array_keys(self::POINTS) as $point) { foreach (self::blocksFor($point) as $html) { $view->getFactory()->startPush("theme:{$point}", $html); } } }); } }