1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\Post; |
6
|
|
|
use App\Models\Tag; |
7
|
|
|
use App\Services\PostProcesses; |
8
|
|
|
use Illuminate\Http\Request; |
9
|
|
|
|
10
|
|
|
class BlogController extends Controller |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Display a listing of the published blog posts. |
14
|
|
|
* |
15
|
|
|
* @return \Illuminate\Http\Response |
16
|
|
|
*/ |
17
|
|
|
public function index(Request $request) |
18
|
|
|
{ |
19
|
|
|
$tag = $request->get('tag'); |
20
|
|
|
$service = new PostProcesses($tag); |
21
|
|
|
$data = $service->getResponse(); |
22
|
|
|
|
23
|
|
|
$layout = $tag ? Tag::layout($tag) : 'blog.roll-layouts.home'; |
24
|
|
|
|
25
|
|
|
return view($layout, $data); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Display the specified resource. |
30
|
|
|
* |
31
|
|
|
* @param string $slug |
32
|
|
|
* @param Request $request |
33
|
|
|
* |
34
|
|
|
* @return \Illuminate\Http\Response |
35
|
|
|
*/ |
36
|
|
|
public function showPost(Request $request, $slug) |
37
|
|
|
{ |
38
|
|
|
$user = \Auth::user(); |
39
|
|
|
|
40
|
|
|
// Allow writers to view posts in draft mode and future dates |
41
|
|
|
if ($user && $user->level() > 2) { |
|
|
|
|
42
|
|
|
$post = Post::with('tags') |
43
|
|
|
->bySlug($slug) |
44
|
|
|
->firstOrFail(); |
45
|
|
|
} else { |
46
|
|
|
$post = Post::with('tags') |
47
|
|
|
->bySlug($slug) |
48
|
|
|
->publishedTimePast() |
49
|
|
|
->isNotDraft() |
50
|
|
|
->firstOrFail(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$tag = $request->get('tag'); |
54
|
|
|
|
55
|
|
|
if ($tag) { |
56
|
|
|
$tag = Tag::whereTag($tag)->firstOrFail(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$data = compact('post', 'tag', 'slug'); |
60
|
|
|
|
61
|
|
|
return view($post->layout, $data); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Display a listing of the authors with published content. |
66
|
|
|
* |
67
|
|
|
* @return \Illuminate\Http\Response |
68
|
|
|
*/ |
69
|
|
|
public function authors(Request $request) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$authors = Post::activeAuthors()->get(); |
72
|
|
|
|
73
|
|
|
if (!$authors) { |
|
|
|
|
74
|
|
|
$authors = []; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$data = [ |
78
|
|
|
'authors' => $authors, |
79
|
|
|
'image' => config('blog.authors_page_image'), |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
return view('blog.pages.authors', $data); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Display a listing of an authors published posts. |
87
|
|
|
* |
88
|
|
|
* @return \Illuminate\Http\Response |
89
|
|
|
*/ |
90
|
|
|
public function author(Request $request, $author) |
91
|
|
|
{ |
92
|
|
|
$tag = $request->get('tag'); |
93
|
|
|
$posts = Post::postsByAuthors($author)->get(); |
94
|
|
|
|
95
|
|
|
$data = [ |
96
|
|
|
'author' => $author, |
97
|
|
|
'image' => config('blog.author_page_image'), |
98
|
|
|
'posts' => $posts, |
99
|
|
|
'tag' => $tag, |
100
|
|
|
]; |
101
|
|
|
|
102
|
|
|
return view('blog.pages.author', $data); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get the RSS feed. |
107
|
|
|
* |
108
|
|
|
* @param RssFeed $feed |
109
|
|
|
* |
110
|
|
|
* @return \Illuminate\Http\Response |
111
|
|
|
*/ |
112
|
|
|
public function rss(RssFeed $feed) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
$rss = $feed->getRSS(); |
115
|
|
|
|
116
|
|
|
return response($rss)->header('Content-type', 'application/rss+xml'); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|