|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * Copyright (c) 2017-2018 Tobias Reich |
| 6 | + * Copyright (c) 2018-2026 LycheeOrg. |
| 7 | + */ |
| 8 | + |
| 9 | +namespace App\Http\Middleware; |
| 10 | + |
| 11 | +use Illuminate\Http\Request; |
| 12 | + |
| 13 | +/** |
| 14 | + * Injects the admin-configured RSS feed title/description into the |
| 15 | + * spatie/laravel-feed config at request time. |
| 16 | + * |
| 17 | + * The spatie FeedController reads the feed config before it invokes our |
| 18 | + * RSSController, so the override cannot happen inside the controller and must |
| 19 | + * run here, before the feed is built. A blank setting is ignored so that the |
| 20 | + * static defaults in config/feed.php remain in effect. |
| 21 | + */ |
| 22 | +class SetRssFeedMeta |
| 23 | +{ |
| 24 | + /** |
| 25 | + * Handle an incoming request. |
| 26 | + * |
| 27 | + * @param \Illuminate\Http\Request $request |
| 28 | + * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next |
| 29 | + * |
| 30 | + * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse |
| 31 | + */ |
| 32 | + public function handle(Request $request, \Closure $next) |
| 33 | + { |
| 34 | + $configs = $request->configs(); |
| 35 | + |
| 36 | + if ($configs->hasKey('rss_title')) { |
| 37 | + $title = $configs->getValueAsString('rss_title'); |
| 38 | + if ($title !== '') { |
| 39 | + config(['feed.feeds.main.title' => $title]); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + if ($configs->hasKey('rss_description')) { |
| 44 | + $description = $configs->getValueAsString('rss_description'); |
| 45 | + if ($description !== '') { |
| 46 | + config(['feed.feeds.main.description' => $description]); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + return $next($request); |
| 51 | + } |
| 52 | +} |
0 commit comments