summaryrefslogtreecommitdiff
path: root/http/index.php
blob: ca9b6baaf0be5d8cd825c3efb2f7411ecd033e9f (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
66
67
<?php

$format = $_REQUEST['format'];

if (!in_array($format, ['atom', 'rss'])) {
    header('HTTP/1.1 400');
    die('Invalid feed format.');
}

$pathinfo = trim($_REQUEST['pathinfo'], '/');

if (strlen($pathinfo)) {
    header('Location: ' . $pathinfo, TRUE, 302);
    die();
}

$params = explode('/', $_REQUEST['query']);

if (count($params) < 2) {
    header('HTTP/1.1 400');
    die('Not enough parameters.');
}

$provider = ucfirst(array_shift($params));
$feed = array_shift($params);
$parsedParams = [];
foreach ($params as $param) {
    $splitParam = explode(':', $param, 2);
    $parsedParams[$splitParam[0]] = count($splitParam) > 1 ? $plitParam[1] : TRUE;
}

try {
    require_once('../providers/' . $provider . '.php');
    $provider = '\\Providers\\' . $provider;
    $provider = new $provider($feed, $parsedParams);
    $content = $provider->get();
} catch (Exception $e) {
    print $e->getMessage();
    die();
}

require_once('../lib/smarty3/Smarty.class.php');

$smarty = new Smarty();
$smarty->setCacheDir('../cache/smarty');
$smarty->setCompileDir('../cache/smarty/compile');
$smarty->setTemplateDir('../templates');

$smarty->assign('feedID', 'http://rss.emkael.info'.$_SERVER['REQUEST_URI']);
$smarty->assign('feedTitle', $provider->title());
$smarty->assign('cacheTime', $provider->cacheTime());
$smarty->assign('user', $feed);
$smarty->assign('content', $provider->get());

switch ($format) {
case 'rss':
    header('Content-Type: application/rss+xml');
    $smarty->display('rss.tpl');
    break;
case 'atom':
default:
    header('Content-Type: application/atom+xml');
    $smarty->display('atom.tpl');
    break;
}

?>