2012-12-26 20:39:54 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\DB;
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
2017-07-18 21:38:53 +02:00
|
|
|
* Publically available page to feed the news to feed readers
|
2017-01-03 03:22:48 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function user_atom()
|
|
|
|
{
|
2017-01-21 23:07:20 +01:00
|
|
|
global $user;
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
if (!$request->has('key') || !preg_match('/^[\da-f]{32}$/', $request->input('key'))) {
|
2017-01-03 14:12:17 +01:00
|
|
|
engelsystem_error('Missing key.');
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-07-18 21:38:53 +02:00
|
|
|
$key = $request->input('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) {
|
2017-01-03 14:12:17 +01:00
|
|
|
engelsystem_error('Key invalid.');
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
if (!in_array('atom', privileges_for_user($user['UID']))) {
|
2017-01-03 14:12:17 +01:00
|
|
|
engelsystem_error('No privilege for atom.');
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
$news = DB::select('
|
2017-01-03 03:22:48 +01:00
|
|
|
SELECT *
|
2017-01-22 01:02:52 +01:00
|
|
|
FROM `News`
|
2017-07-18 21:38:53 +02:00
|
|
|
' . (!$request->has('meetings') ? '' : 'WHERE `Treffen` = 1 ') . '
|
2017-01-03 03:22:48 +01:00
|
|
|
ORDER BY `ID`
|
2017-01-21 23:07:20 +01:00
|
|
|
DESC LIMIT ' . (int)config('display_news')
|
2017-01-03 03:22:48 +01:00
|
|
|
);
|
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');
|
2017-01-03 14:12:17 +01:00
|
|
|
header('Content-Length: ' . strlen($output));
|
2017-01-02 03:57:23 +01:00
|
|
|
raw_output($output);
|
2016-08-22 19:08:10 +02:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param array[] $news_entries
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function make_atom_entries_from_news($news_entries)
|
|
|
|
{
|
|
|
|
$html = '<?xml version="1.0" encoding="utf-8"?>
|
2013-09-10 14:27:31 +02:00
|
|
|
<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(
|
2017-01-21 19:47:44 +01:00
|
|
|
'#[&?]key=[a-f\d]{32}#',
|
2017-01-02 15:43:36 +01:00
|
|
|
'',
|
|
|
|
$_SERVER['REQUEST_URI']
|
|
|
|
))
|
|
|
|
. '</id>
|
2017-01-03 14:12:17 +01: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);
|
|
|
|
}
|
2017-01-03 14:12:17 +01:00
|
|
|
$html .= '</feed>';
|
2017-01-02 03:57:23 +01:00
|
|
|
return $html;
|
2016-08-22 19:08:10 +02:00
|
|
|
}
|
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
function make_atom_entry_from_news($news_entry)
|
|
|
|
{
|
2017-01-03 14:12:17 +01:00
|
|
|
return ' <entry>
|
|
|
|
<title>' . htmlspecialchars($news_entry['Betreff']) . '</title>
|
2017-08-28 16:21:10 +02:00
|
|
|
<link href="' . page_link_to_absolute('news_comments', ['nid' => $news_entry['ID']]) . '"/>
|
2017-01-03 14:12:17 +01:00
|
|
|
<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>
|
2017-08-28 16:21:10 +02:00
|
|
|
<summary>' . htmlspecialchars($news_entry['Text']) . '</summary>
|
2017-01-03 14:12:17 +01:00
|
|
|
</entry>' . "\n";
|
2013-09-10 14:27:31 +02:00
|
|
|
}
|