summaryrefslogtreecommitdiff
path: root/includes/pages/user_atom.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-11-28 15:43:51 +0100
committerGitHub <noreply@github.com>2017-11-28 15:43:51 +0100
commit599f2fd264bfc7b1b6826fe206442806e317340f (patch)
tree50cf84d7d07d11bd65b45c2c17f37632f6cd8eff /includes/pages/user_atom.php
parenta5fc5bd0979e8de1fce8a8addd351a6e7bd6aeb8 (diff)
parenteda7f7788ea8012bd8be46405c56a666c11f3fa5 (diff)
Merge pull request #365 from engelsystem/feature-igel-rewrite
Feature igel rewrite
Diffstat (limited to 'includes/pages/user_atom.php')
-rw-r--r--includes/pages/user_atom.php109
1 files changed, 67 insertions, 42 deletions
diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php
index 9a765634..c9d9398e 100644
--- a/includes/pages/user_atom.php
+++ b/includes/pages/user_atom.php
@@ -1,51 +1,76 @@
<?php
-// publically available page to feed the news to feedreaders
-function user_atom() {
- global $user, $DISPLAY_NEWS;
-
- if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
- engelsystem_error("Missing key.");
- }
- $key = $_REQUEST['key'];
-
- $user = User_by_api_key($key);
- if ($user == null) {
- engelsystem_error("Key invalid.");
- }
- 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));
-
- $output = make_atom_entries_from_news($news);
-
- header('Content-Type: application/atom+xml; charset=utf-8');
- header("Content-Length: " . strlen($output));
- raw_output($output);
+use Engelsystem\Database\DB;
+
+/**
+ * Publically available page to feed the news to feed readers
+ */
+function user_atom()
+{
+ global $user;
+ $request = request();
+
+ if (!$request->has('key') || !preg_match('/^[\da-f]{32}$/', $request->input('key'))) {
+ engelsystem_error('Missing key.');
+ }
+ $key = $request->input('key');
+
+ $user = User_by_api_key($key);
+ if ($user == null) {
+ engelsystem_error('Key invalid.');
+ }
+ if (!in_array('atom', privileges_for_user($user['UID']))) {
+ engelsystem_error('No privilege for atom.');
+ }
+
+ $news = DB::select('
+ SELECT *
+ FROM `News`
+ ' . (!$request->has('meetings') ? '' : 'WHERE `Treffen` = 1 ') . '
+ ORDER BY `ID`
+ DESC LIMIT ' . (int)config('display_news')
+ );
+
+ $output = make_atom_entries_from_news($news);
+
+ header('Content-Type: application/atom+xml; charset=utf-8');
+ header('Content-Length: ' . strlen($output));
+ raw_output($output);
}
-function make_atom_entries_from_news($news_entries) {
- $html = '<?xml version="1.0" encoding="utf-8"?>
+/**
+ * @param array[] $news_entries
+ * @return string
+ */
+function make_atom_entries_from_news($news_entries)
+{
+ $request = app('request');
+ $html = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Engelsystem</title>
- <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_entries[0]['Datum']) . "</updated>\n";
- foreach ($news_entries as $news_entry) {
- $html .= make_atom_entry_from_news($news_entry);
- }
- $html .= "</feed>";
- return $html;
+ <id>' . $request->getHttpHost()
+ . htmlspecialchars(preg_replace(
+ '#[&?]key=[a-f\d]{32}#',
+ '',
+ $request->getRequestUri()
+ ))
+ . '</id>
+ <updated>' . date('Y-m-d\TH:i:sP', $news_entries[0]['Datum']) . '</updated>' . "\n";
+ foreach ($news_entries as $news_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>
- <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>
- <summary type=\"html\">" . htmlspecialchars($news_entry['Text']) . "</summary>
- </entry>\n";
+function make_atom_entry_from_news($news_entry)
+{
+ return '
+ <entry>
+ <title>' . htmlspecialchars($news_entry['Betreff']) . '</title>
+ <link href="' . page_link_to('news_comments', ['nid' => $news_entry['ID']]) . '"/>
+ <id>' . preg_replace('#^https?://#', '', page_link_to('news_comments', ['nid' => $news_entry['ID']])) . '</id>
+ <updated>' . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . '</updated>
+ <summary>' . htmlspecialchars($news_entry['Text']) . '</summary>
+ </entry>' . "\n";
}
-?>