/
atom.php
72 lines (62 loc) · 2.56 KB
/
atom.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
61
62
63
64
65
66
67
68
69
70
71
72
<?php
require('system.php');
$user = user_load('id', intval($_GET['u']));
if(!$user) {
header('HTTP/1.1 404 Not found');
header('Content-Type: text/html; charset=utf-8');
echo('<div id="error">Ungültige Benutzer-ID</div>');
return;
}
$atom_token = substr(sha1($user->id . $user->salt . $user->name), 0, 4);
if($user->atom_feed === false || !isset($_GET['t']) || $_GET['t'] != $atom_token) {
header('HTTP/1.1 403 Access denied');
header('Content-Type: text/html; charset=utf-8');
echo('<div id="error">Entweder wurde dieser Feed deaktiviert oder der Link ist inkorrekt.</div>');
return;
}
ob_end_clean();
header('Content-type: application/atom+xml; charset=utf-8');
echo('<?xml version="1.0"?>');
$base_url = htmlspecialchars('http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'/');
?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
<id><?=$base_url?>uebungszettel-<?=$user->id?></id>
<title>Aktuelle Übungszettel für <?=htmlspecialchars($user->name)?></title>
<updated><?=date('c')?></updated>
<link rel="self" href="http://<?=$_SERVER['SERVER_NAME']?>/atom.php?u=<?=$user->id?>" />
<link rel="alternate" href="/" />
<author><name>Übungszettelagregator</name></author>
<?php
$descs = array();
foreach($database->query('SELECT id, short FROM feeds') as $feed) $descs[$feed['id']] = $feed['short'];
$exercises = $database->query('
SELECT
id, data, feed_id, timestamp,
(SELECT comment FROM user_data WHERE user_id = '.$user->id.' AND data_id = id) AS comment,
(SELECT invisible FROM user_data WHERE user_id = '.$user->id.' AND data_id = id) AS invisible
FROM
data
WHERE feed_id IN (SELECT feed_id FROM user_feeds WHERE user_id = '.$user->id.')
AND timestamp IS NOT NULL');
foreach($exercises as $exercise):
if($exercise['invisible'] && $hide_invisible) continue;
?>
<entry>
<updated><?=date('c', $exercise['timestamp'])?></updated>
<id><?=$base_url?>uebungszettel-<?=$user->id?>uebung-<?=$exercise['id']?></id>
<title><?=htmlspecialchars($descs[$exercise['feed_id']])?> - <?=strip_tags(format_data($exercise['data'], $exercise['id']))?></title>
<summary type="html">
<?=htmlspecialchars(format_data($exercise['data'], $exercise['id']))?>
</summary>
<?php
list($url, $text) = split_data($exercise['data']);
if($url):
?>
<link title="<?=htmlspecialchars(trim($text))?>" href="<?=htmlspecialchars($url)?>" rel="alternate" />
<?php else: ?>
<content type="text"><?=htmlspecialchars($text)?></content>
<?php endif; ?>
</entry>
<?php endforeach; ?>
</feed>
<?php die(); ?>