1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Http\Controllers; |
13
|
|
|
|
14
|
|
|
use Gitamin\Facades\Setting; |
15
|
|
|
use Gitamin\Models\Issue; |
16
|
|
|
use Gitamin\Models\ProjectTeam; |
17
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown; |
18
|
|
|
use Illuminate\Routing\Controller; |
19
|
|
|
use Illuminate\Support\Str; |
20
|
|
|
use Roumen\Feed\Facades\Feed; |
21
|
|
|
|
22
|
|
|
class FeedController extends Controller |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Instance of Feed. |
26
|
|
|
* |
27
|
|
|
* @var Roumen\Feed\Facades\Feed |
28
|
|
|
*/ |
29
|
|
|
private $feed; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Whether it is a RSS Feed. |
33
|
|
|
* |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
private $isRss; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a new feed controller instance. |
40
|
|
|
* |
41
|
|
|
* @return void |
|
|
|
|
42
|
|
|
*/ |
43
|
|
|
public function __construct() |
44
|
|
|
{ |
45
|
|
|
$this->feed = Feed::make(); |
46
|
|
|
$this->feed->title = Setting::get('app_name'); |
47
|
|
|
$this->feed->description = trans('gitamin.feed'); |
48
|
|
|
$this->feed->link = Str::canonicalize(Setting::get('app_domain')); |
49
|
|
|
$this->feed->setDateFormat('datetime'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Generates an Atom feed of all issues. |
54
|
|
|
* |
55
|
|
|
* @param \Gitamin\Models\ProjectTeam|null $group |
56
|
|
|
* |
57
|
|
|
* @return \Illuminate\Http\Response |
58
|
|
|
*/ |
59
|
|
|
public function atomAction(ProjectTeam $group = null) |
60
|
|
|
{ |
61
|
|
|
$this->isRss = false; |
62
|
|
|
|
63
|
|
|
return $this->feedAction($group); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Generates an Rss feed of all issues. |
68
|
|
|
* |
69
|
|
|
* @param \Gitamin\Models\ProjectTeam|null $group |
70
|
|
|
* |
71
|
|
|
* @return \Illuminate\Http\Response |
72
|
|
|
*/ |
73
|
|
|
public function rssAction(ProjectTeam $group = null) |
74
|
|
|
{ |
75
|
|
|
$this->isRss = true; |
76
|
|
|
$this->feed->lang = Setting::get('app_locale'); |
77
|
|
|
|
78
|
|
|
return $this->feedAction($group); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Generates an Atom feed of all issues. |
83
|
|
|
* |
84
|
|
|
* @param \Gitamin\Models\ProjectTeam|null $group |
85
|
|
|
* |
86
|
|
|
* @return \Illuminate\Http\Response |
87
|
|
|
*/ |
88
|
|
|
public function feedAction(ProjectTeam $group = null) |
89
|
|
|
{ |
90
|
|
|
if ($group->exists) { |
91
|
|
|
$group->projects->map(function ($project) { |
|
|
|
|
92
|
|
|
$project->issues()->visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) { |
93
|
|
|
$this->feedAddItem($issue); |
94
|
|
|
}); |
95
|
|
|
}); |
96
|
|
|
} else { |
97
|
|
|
Issue::visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) { |
|
|
|
|
98
|
|
|
$this->feedAddItem($issue); |
99
|
|
|
}); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $this->feed->render($this->isRss ? 'rss' : 'atom'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Adds an item to the feed. |
107
|
|
|
* |
108
|
|
|
* @param \Gitamin\Models\Issue $issue |
109
|
|
|
*/ |
110
|
|
|
private function feedAddItem($issue) |
111
|
|
|
{ |
112
|
|
|
$this->feed->add( |
113
|
|
|
$issue->name, |
|
|
|
|
114
|
|
|
Setting::get('app_name'), |
115
|
|
|
Str::canonicalize(route('issue', ['id' => $issue->id])), |
|
|
|
|
116
|
|
|
$this->isRss ? $issue->created_at->toRssString() : $issue->created_at->toAtomString(), |
|
|
|
|
117
|
|
|
$this->isRss ? $issue->message : Markdown::convertToHtml($issue->message) |
|
|
|
|
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.