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\Owner; |
17
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown; |
18
|
|
|
use Illuminate\Support\Str; |
19
|
|
|
use Roumen\Feed\Facades\Feed; |
20
|
|
|
|
21
|
|
|
class FeedController extends Controller |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Feed facade. |
25
|
|
|
* |
26
|
|
|
* @var \Roumen\Feed\Facades\Feed |
27
|
|
|
*/ |
28
|
|
|
protected $feed; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Create a new feed controller instance. |
32
|
|
|
*/ |
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
$this->feed = Feed::make(); |
36
|
|
|
$this->feed->title = Setting::get('app_name'); |
37
|
|
|
$this->feed->description = trans('gitamin.feed'); |
38
|
|
|
$this->feed->link = Str::canonicalize(Setting::get('app_domain')); |
39
|
|
|
$this->feed->setDateFormat('datetime'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Generates an Atom feed of all issues. |
44
|
|
|
* |
45
|
|
|
* @param \Gitamin\Models\Owner|null $owner |
46
|
|
|
* |
47
|
|
|
* @return \Illuminate\Http\Response |
48
|
|
|
*/ |
49
|
|
|
public function atomAction(Owner $owner = null) |
50
|
|
|
{ |
51
|
|
|
return $this->feedAction($owner, false); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Generates a Rss feed of all issues. |
56
|
|
|
* |
57
|
|
|
* @param \Gitamin\Models\Owner|null $owner |
58
|
|
|
* |
59
|
|
|
* @return \Illuminate\Http\Response |
60
|
|
|
*/ |
61
|
|
|
public function rssAction(Owner $owner = null) |
62
|
|
|
{ |
63
|
|
|
$this->feed->lang = Setting::get('app_locale'); |
|
|
|
|
64
|
|
|
|
65
|
|
|
return $this->feedAction($owner, true); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Generates a feed of all issues. |
70
|
|
|
* |
71
|
|
|
* @param \Gitamin\Models\Owner|null $owner |
72
|
|
|
* @param bool $isRss |
73
|
|
|
* |
74
|
|
|
* @return \Illuminate\Http\Response |
75
|
|
|
*/ |
76
|
|
|
private function feedAction(Owner &$owner, $isRss) |
77
|
|
|
{ |
78
|
|
|
if ($owner->exists) { |
79
|
|
|
$owner->projects->map(function ($project) { |
|
|
|
|
80
|
|
|
$project->issues()->visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) use ($isRss) { |
|
|
|
|
81
|
|
|
$this->feedAddItem($issue, $isRss); |
82
|
|
|
}); |
83
|
|
|
}); |
84
|
|
|
} else { |
85
|
|
|
Issue::visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) use ($isRss) { |
|
|
|
|
86
|
|
|
$this->feedAddItem($issue, $isRss); |
87
|
|
|
}); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $this->feed->render($isRss ? 'rss' : 'atom'); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Adds an item to the feed. |
95
|
|
|
* |
96
|
|
|
* @param \Gitamin\Models\Issue $issue |
97
|
|
|
* @param bool $isRss |
98
|
|
|
*/ |
99
|
|
|
private function feedAddItem($issue, $isRss) |
100
|
|
|
{ |
101
|
|
|
$this->feed->add( |
|
|
|
|
102
|
|
|
$issue->name, |
|
|
|
|
103
|
|
|
Setting::get('app_name'), |
104
|
|
|
Str::canonicalize($issue->url), |
|
|
|
|
105
|
|
|
$isRss ? $issue->created_at->toRssString() : $issue->created_at->toAtomString(), |
|
|
|
|
106
|
|
|
$isRss ? $issue->message : Markdown::convertToHtml($issue->message) |
|
|
|
|
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):