-
Notifications
You must be signed in to change notification settings - Fork 6
/
feed.php
60 lines (53 loc) · 2.03 KB
/
feed.php
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
<?php
include_once("mergedrss.php");
include_once("JsonpHelper.php");
if ( ! empty($_GET["category"]) ) {
$category = $_GET["category"];
} else {
$category = "blog";
}
if ( ! empty($_GET["format"]) && $_GET["format"] === "json" ) {
$format = $_GET["format"];
} else {
$format = "xml";
}
$configs = file_get_contents("config.json");
$configs = json_decode($configs, true);
$communities = $configs['directoryUrl'];
$limit = $configs['defaultLimit'];
if ( ! empty($_GET["items"]) ) {
$limit = $_GET["items"];
}
$feeds = array();
//load combined api file
$api = file_get_contents($communities);
$communities = json_decode($api, true);
// get additional feeds from config
foreach($configs['additionalFeeds'] as $additionalFeed) {
if ($additionalFeed['category'] == $category) {
$feeds[$additionalFeed['name']] = array($additionalFeed['url'], $additionalFeed['name'], $additionalFeed['homepage'], array($additionalFeed['name']));
}
}
// get feeds from API
foreach($communities as $indexName => $community)
{
if ( ! empty($community['feeds'] ) ) {
foreach($community['feeds'] as $feed )
{
if ( ! empty($feed['category']) && $feed['category'] == $category && !empty($feed['type']) && (strtolower($feed['type']) == "rss" || strtolower($feed['type']) == "atom" ) ) {
if ( array_key_exists($feed['url'], $feeds) ) {
array_push($feeds[$feed['url']][3], $indexName);
} else {
$feeds[$feed['url']] = array($feed['url'],$community['name'], $community['url'], array($indexName));
}
}
}
}
}
// set an arbitrary feed date
$feed_date = date("r", mktime(10,0,0,9,8,2010));
// Create new MergedRSS object with desired parameters
$MergedRSS = new MergedRSS($feeds, "Freifunk Community Feeds", "https://freifunk.net/", "This the merged RSS feed of RSS feeds of our communities", "http://wiki.freifunk.net/images/7/78/175x170_freifunknet.png", $feed_date);
//Export the first 10 items to screen
$result = $MergedRSS->export(true, false, $limit, (array_key_exists('source', $_GET) ? $_GET['source'] : 'all'));
JsonpHelper::output($result, $format);