blob: 9fe1f4bbd2b8e7f04166bb215cbebf24c999c804 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<?php
/**
* ownCloud - News
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2016
*/
/**
* This is used for generating a JSON config section for a feed by executing:
* php -f generate_authors.php www.feed.com
*/
require_once __DIR__ . '/../../vendor/autoload.php';
if (count($argv) < 2 || count($argv) > 3) {
print('Usage: php -f generate_explore http://path.com/feed [vote_count]');
print("\n");
exit();
} elseif (count($argv) === 3) {
$votes = $argv[2];
} else {
$votes = 100;
}
$url = $argv[1];
try {
$config = new PicoFeed\Config\Config();
$reader = new PicoFeed\Reader\Reader($config);
$resource = $reader->discover($url);
$location = $resource->getUrl();
$content = $resource->getContent();
$encoding = $resource->getEncoding();
$parser = $reader->getParser($location, $content, $encoding);
$feed = $parser->execute();
$favicon = new PicoFeed\Reader\Favicon($config);
$result = [
"title" => $feed->getTitle(),
"favicon" => $favicon->find($url),
"url" => $feed->getSiteUrl(),
"feed" => $feed->getFeedUrl(),
"description" => $feed->getDescription(),
"votes" => $votes
];
if ($feed->getLogo()) {
$result["image"] = $feed->getLogo();
}
print(json_encode($result, JSON_PRETTY_PRINT));
} catch (\Exception $ex) {
print($ex->getMessage());
}
print("\n");
|