@@ -73,9 +73,25 @@ public function discoverFeeds(string $url): array
73
73
// Fetch the URL
74
74
$ response = $ this ->fetchUrl ($ url );
75
75
76
- $ responseType = $ response ->getHeaderLine ('Content-Type ' );
77
- // Must claim to be HTML.
78
- if (!str_contains ($ responseType , 'html ' )) {
76
+ /** @var array<\App\Model\Entity\Feed> $feeds */
77
+ $ feeds = [];
78
+
79
+ $ contentType = $ this ->getContentType ($ response );
80
+ $ feedTypes = ['application/atom+xml ' , 'application/xml ' , 'text/xml ' , 'application/rss ' , 'application/rss+xml ' ];
81
+
82
+ // Feed URL provided
83
+ if (in_array ($ contentType , $ feedTypes )) {
84
+ $ feeds [] = new Feed ([
85
+ 'default_alias ' => $ url ,
86
+ 'url ' => $ url ,
87
+ 'favicon_url ' => '' ,
88
+ ]);
89
+
90
+ return $ feeds ;
91
+ }
92
+
93
+ // If we didn't get a feed URL, or an HTML page abort.
94
+ if ($ contentType != 'text/html ' ) {
79
95
throw new RuntimeException ('That URL is not an HTML page. No feed could be found. ' );
80
96
}
81
97
try {
@@ -93,9 +109,6 @@ public function discoverFeeds(string $url): array
93
109
// No user/pass support yet.
94
110
$ uri = new Uri ($ url );
95
111
96
- /** @var array<\App\Model\Entity\Feed> $feeds */
97
- $ feeds = [];
98
-
99
112
// parse the HTML page looking for link elements
100
113
$ xpath = new DOMXPath ($ dom );
101
114
@@ -172,6 +185,17 @@ protected function findFavicon(DOMXPath $xpath): ?string
172
185
return null ;
173
186
}
174
187
188
+ protected function getContentType (Response $ res ): string
189
+ {
190
+ $ contentType = $ res ->getHeaderLine ('Content-Type ' );
191
+ $ colonPos = strpos ($ contentType , '; ' );
192
+ if ($ colonPos !== false ) {
193
+ $ contentType = substr ($ contentType , 0 , $ colonPos );
194
+ }
195
+
196
+ return $ contentType ;
197
+ }
198
+
175
199
/**
176
200
* Import new FeedItems for all the unique items in a feed's current response
177
201
*/
@@ -196,11 +220,7 @@ public function refreshFeed(Feed $feed): void
196
220
197
221
protected function parseResponse (Response $ res , Feed $ feed ): array
198
222
{
199
- $ contentType = $ res ->getHeaderLine ('Content-Type ' );
200
- $ colonPos = strpos ($ contentType , '; ' );
201
- if ($ colonPos !== false ) {
202
- $ contentType = substr ($ contentType , 0 , $ colonPos );
203
- }
223
+ $ contentType = $ this ->getContentType ($ res );
204
224
$ body = (string )$ res ->getBody ();
205
225
// No items in an empty response.
206
226
if (!$ body ) {
0 commit comments