split user atom into different functions

main
msquare 8 years ago
parent d4bba0d468
commit 79588ff2cf

@ -4,29 +4,47 @@
function user_atom() { function user_atom() {
global $user, $DISPLAY_NEWS; global $user, $DISPLAY_NEWS;
if (isset ($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) if (isset($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
$key = $_REQUEST['key']; $key = $_REQUEST['key'];
else } else {
die("Missing key."); engelsystem_error("Missing key.");
}
$user = User_by_api_key($key); $user = User_by_api_key($key);
if($user === false) if ($user === false) {
die("Unable to find user."); engelsystem_error("Unable to find user.");
if($user == null) }
die("Key invalid."); if ($user == null) {
if(!in_array('atom', privileges_for_user($user['UID']))) engelsystem_error("Key invalid.");
die("No privilege for atom."); }
if (! in_array('atom', privileges_for_user($user['UID']))) {
engelsystem_error("No privilege for atom.");
}
$news = sql_select("SELECT * FROM `News` " . (empty($_REQUEST['meetings']) ? '' : 'WHERE `Treffen` = 1 ') . "ORDER BY `ID` DESC LIMIT " . sql_escape($DISPLAY_NEWS)); $news = sql_select("SELECT * FROM `News` " . (empty($_REQUEST['meetings']) ? '' : 'WHERE `Treffen` = 1 ') . "ORDER BY `ID` DESC LIMIT " . sql_escape($DISPLAY_NEWS));
$output = make_atom_entries_from_news($news);
header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Type: application/atom+xml; charset=utf-8');
header("Content-Length: " . strlen($output));
raw_output($html);
}
function make_atom_entries_from_news($news_entries) {
$html = '<?xml version="1.0" encoding="utf-8"?> $html = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"> <feed xmlns="http://www.w3.org/2005/Atom">
<title>Engelsystem</title> <title>Engelsystem</title>
<id>' . $_SERVER['HTTP_HOST'] . htmlspecialchars(preg_replace('#[&?]key=[a-f0-9]{32}#', '', $_SERVER['REQUEST_URI'])) . '</id> <id>' . $_SERVER['HTTP_HOST'] . htmlspecialchars(preg_replace('#[&?]key=[a-f0-9]{32}#', '', $_SERVER['REQUEST_URI'])) . '</id>
<updated>' . date('Y-m-d\TH:i:sP', $news[0]['Datum']) . "</updated>\n"; <updated>' . date('Y-m-d\TH:i:sP', $news[0]['Datum']) . "</updated>\n";
foreach ($news as $news_entry) { foreach ($news_entries as $news_entry) {
$html .= " <entry> $html .= make_atom_entry_from_news($news_entry);
}
$html .= "</feed>";
return $html;
}
function make_atom_entry_from_news($news_entry) {
return " <entry>
<title>" . htmlspecialchars($news_entry['Betreff']) . "</title> <title>" . htmlspecialchars($news_entry['Betreff']) . "</title>
<link href=\"" . page_link_to_absolute("news_comments&amp;nid=") . "${news_entry['ID']}\"/> <link href=\"" . page_link_to_absolute("news_comments&amp;nid=") . "${news_entry['ID']}\"/>
<id>" . preg_replace('#^https?://#', '', page_link_to_absolute("news")) . "-${news_entry['ID']}</id> <id>" . preg_replace('#^https?://#', '', page_link_to_absolute("news")) . "-${news_entry['ID']}</id>
@ -34,9 +52,4 @@ function user_atom() {
<summary type=\"html\">" . htmlspecialchars($news_entry['Text']) . "</summary> <summary type=\"html\">" . htmlspecialchars($news_entry['Text']) . "</summary>
</entry>\n"; </entry>\n";
} }
$html .= "</feed>";
header("Content-Length: " . strlen($html));
echo $html;
die();
}
?> ?>

Loading…
Cancel
Save