ソースを参照

RSS

pull/18/head
コミット
5d2bb989e1
  1. 23
      app/Http/Controllers/RssFeedController.php
  2. 22
      resources/views/rss/feed.blade.php
  3. 1
      resources/views/theme/techsuwa/component/navbar.blade.php
  4. 1
      routes/view/site.php

23
app/Http/Controllers/RssFeedController.php

@ -0,0 +1,23 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class RssFeedController extends Controller {
public function feed () {
$select = ['id', 'user_id', 'title', 'slug', 'publish_date', 'message'];
$posts = DB::table('blg_content')->select($select)->where('isPost', true)->where('public_status', 0)->orderBy('id', 'desc')->limit(50)->get();
foreach ($posts as $k => $v) {
$userd = DB::table('users')->where('id', $v->user_id)->first();
$userd = DB::table('usr_profile')->where('user_id', $v->user_id)->first();
$v->user = $userd->display_name;
unset($posts[$k]->user_id);
}
return response()->view('rss.feed', ['posts' => $posts])->header('Content-Type', 'application/xml');
}
}

22
resources/views/rss/feed.blade.php

@ -0,0 +1,22 @@
<?=
'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
?>
<rss version="2.0">
<channel>
<title><![CDATA[{{ env('APP_NAME') }}]]></title>
<link><![CDATA[{{ env('APP_URL') }}/feed ]]></link>
<description><![CDATA[ テクニカル諏訪子のホームページです。ゲーム及びテクノロジー関係ブログですわ♡ ]]></description>
<language>ja</language>
<pubDate>{{ now() }}</pubDate>
@foreach($posts as $post)
<item>
<title><![CDATA[{{ $post->title }}]]></title>
<link>{{ env('APP_URL') }}/blog/{{ $post->slug }}</link>
<description><![CDATA[{!! $post->message !!}]]></description>
<author><![CDATA[{{ $post->user }}]]></author>
<pubDate>{{ date('Y-m-d H:i:s', $post->publish_date) }}</pubDate>
</item>
@endforeach
</channel>
</rss>

1
resources/views/theme/techsuwa/component/navbar.blade.php

@ -4,6 +4,7 @@
<ul class="navbar-nav mr-auto">
<li class="nav-item"><a class="nav-link{{ (str_contains($_SERVER['REQUEST_URI'], '/blog') || $_SERVER['REQUEST_URI'] == '/' ? ' active' : '') }}" href="/">{{ __('site.top') }}</a></li>
<li class="nav-item"><a class="nav-link" href="http://{{ env('ONION_HOST') }}">Tor</a></li>
<li class="nav-item"><a class="nav-link" href="/feed">RSS</a></li>
</ul>
<ul class="navbar-nav ml-auto">
@if ($user)

1
routes/view/site.php

@ -34,5 +34,6 @@ Route::get('/memberlist', 'User\MemberList@index');
Route::get('/commentlist', 'Home\CommentList@index');
Route::get('/contact/seiko', 'Home\Contact@seiko');
Route::any('/contact', 'Home\Contact@index');
Route::get('/feed', 'RssFeedController@feed');
Route::get('/{slug}', 'Home\Index@page');

読み込み中…
キャンセル
保存