forked from fossasia/feed.api.fossasia.net
/
feed.php
57 lines (49 loc) · 1.93 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
<?php
include_once("mergedrss.php");
include_once("JsonpHelper.php");
if ( ! empty($_GET["category"]) ) {
$category = $_GET["category"];
} else {
$category = "blog";
}
$configs = file_get_contents("config.json");
$configs = json_decode($configs, true);
$communities = $configs['ffGeoJsonUrl'];
$limit = $configs['defaultLimit'];
if ( ! empty($_GET["items"]) ) {
$limit = $_GET["items"];
}
$feeds = array();
$urls = array();
//load combined api file
$api = file_get_contents($communities);
$json = json_decode($api, true);
$geofeatures = $json['features'];
// get additional feeds from config
foreach($configs['additionalFeeds'] as $additionalFeed) {
if ($additionalFeed['category'] == $category) {
$feeds[$additionalFeed['name']] = array($additionalFeed['url'], $additionalFeed['name'], $additionalFeed['homepage']);
}
}
// get feeds from API
foreach($geofeatures as $feature)
{
if ( ! empty($feature['properties']['feeds'] ) ) {
foreach($feature['properties']['feeds'] as $feed )
{
if ( ! array_key_exists($feature['properties']['url'], $urls) && ! empty($feed['category']) && $feed['category'] == $category && !empty($feed['type']) && $feed['type'] == "rss" ) {
$feeds[$feature['properties']['shortname']] = array($feed['url'],$feature['properties']['name'], $feature['properties']['url']);
$urls[$feature['properties']['url']] = "1";
}
}
}
}
// set the header type
header("Content-type: text/xml");
// 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, "Fossasia Community Feeds", "http://www.fossasia.net/", "This the merged RSS feed of RSS feeds of our community", $feed_date);
//Export the first 10 items to screen
$result = $MergedRSS->export(true, false, (array_key_exists('limit', $_GET) ? $_GET['limit'] : $limit), (array_key_exists('source', $_GET) ? $_GET['source'] : 'all'));
JsonpHelper::outputXML($result);