1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - News |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Alessandro Cosentino <[email protected]> |
9
|
|
|
* @author Bernhard Posselt <[email protected]> |
10
|
|
|
* @copyright Alessandro Cosentino 2012 |
11
|
|
|
* @copyright Bernhard Posselt 2012, 2014 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OCA\News\Fetcher; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class Fetcher { |
18
|
|
|
|
19
|
|
|
private $fetchers; |
20
|
|
|
|
21
|
|
|
public function __construct(){ |
22
|
|
|
$this->fetchers = []; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Add an additional fetcher |
28
|
|
|
* @param IFeedFetcher $fetcher the fetcher |
29
|
|
|
*/ |
30
|
|
|
public function registerFetcher(IFeedFetcher $fetcher){ |
31
|
|
|
$this->fetchers[] = $fetcher; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Fetch a feed from remote |
36
|
|
|
* @param string $url remote url of the feed |
37
|
|
|
* @param boolean $getFavicon if the favicon should also be fetched, |
38
|
|
|
* defaults to true |
39
|
|
|
* @param string $lastModified a last modified value from an http header |
40
|
|
|
* defaults to false. If lastModified matches the http header from the feed |
41
|
|
|
* no results are fetched |
42
|
|
|
* @param string $etag an etag from an http header. |
43
|
|
|
* If lastModified matches the http header from the feed |
44
|
|
|
* no results are fetched |
45
|
|
|
* @param bool fullTextEnabled if true tells the fetcher to enhance the |
46
|
|
|
* articles by fetching custom enhanced content |
47
|
|
|
* @param string $basicAuthUser if given, basic auth is set for this feed |
48
|
|
|
* @param string $basicAuthPassword if given, basic auth is set for this |
49
|
|
|
* feed. Ignored if user is null or an empty string |
50
|
|
|
* @throws FetcherException if simple pie fails |
51
|
|
|
* @return array an array containing the new feed and its items, first |
52
|
|
|
* element being the Feed and second element being an array of Items |
53
|
|
|
*/ |
54
|
|
|
public function fetch($url, $getFavicon=true, $lastModified=null, |
55
|
|
|
$etag=null, $fullTextEnabled=false, |
56
|
|
|
$basicAuthUser=null, $basicAuthPassword=null) { |
57
|
|
|
foreach($this->fetchers as $fetcher){ |
58
|
|
|
if($fetcher->canHandle($url)){ |
59
|
|
|
return $fetcher->fetch($url, $getFavicon, $lastModified, $etag, |
60
|
|
|
$fullTextEnabled, $basicAuthUser, |
61
|
|
|
$basicAuthPassword); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return [null, []]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|