engelsystem/includes/pages/user_atom.php

60 lines
2.0 KiB
PHP
Raw Normal View History

2012-12-26 20:39:54 +01:00
<?php
// publically available page to feed the news to feedreaders
2017-01-02 03:57:23 +01:00
function user_atom()
{
global $user, $DISPLAY_NEWS;
2017-01-02 15:43:36 +01:00
if (!isset($_REQUEST['key']) || !preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
2017-01-02 03:57:23 +01:00
engelsystem_error("Missing key.");
}
$key = $_REQUEST['key'];
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
$user = User_by_api_key($key);
if ($user == null) {
engelsystem_error("Key invalid.");
}
2017-01-02 15:43:36 +01:00
if (!in_array('atom', privileges_for_user($user['UID']))) {
2017-01-02 03:57:23 +01:00
engelsystem_error("No privilege for atom.");
}
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
$news = sql_select("SELECT * FROM `News` " . (empty($_REQUEST['meetings']) ? '' : 'WHERE `Treffen` = 1 ') . "ORDER BY `ID` DESC LIMIT " . sql_escape($DISPLAY_NEWS));
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
$output = make_atom_entries_from_news($news);
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
header('Content-Type: application/atom+xml; charset=utf-8');
header("Content-Length: " . strlen($output));
raw_output($output);
}
2017-01-02 03:57:23 +01:00
function make_atom_entries_from_news($news_entries)
{
$html = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
2012-12-26 20:39:54 +01:00
<title>Engelsystem</title>
2017-01-02 15:43:36 +01:00
<id>' . $_SERVER['HTTP_HOST']
. htmlspecialchars(preg_replace(
'#[&?]key=[a-f0-9]{32}#',
'',
$_SERVER['REQUEST_URI']
))
. '</id>
2016-08-22 19:32:54 +02:00
<updated>' . date('Y-m-d\TH:i:sP', $news_entries[0]['Datum']) . "</updated>\n";
2017-01-02 03:57:23 +01:00
foreach ($news_entries as $news_entry) {
$html .= make_atom_entry_from_news($news_entry);
}
$html .= "</feed>";
return $html;
}
2017-01-02 03:57:23 +01:00
function make_atom_entry_from_news($news_entry)
{
return " <entry>
2012-12-26 20:39:54 +01:00
<title>" . htmlspecialchars($news_entry['Betreff']) . "</title>
<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>
<updated>" . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . "</updated>
2012-12-26 20:39:54 +01:00
<summary type=\"html\">" . htmlspecialchars($news_entry['Text']) . "</summary>
</entry>\n";
}