summaryrefslogtreecommitdiff
path: root/includes/pages/user_atom.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/pages/user_atom.php')
-rw-r--r--includes/pages/user_atom.php37
1 files changed, 18 insertions, 19 deletions
diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php
index a491fea7..9a4d65a5 100644
--- a/includes/pages/user_atom.php
+++ b/includes/pages/user_atom.php
@@ -1,7 +1,8 @@
<?php
-use Engelsystem\Database\DB;
use Engelsystem\Http\Exceptions\HttpForbidden;
+use Engelsystem\Models\News;
+use Illuminate\Database\Eloquent\Collection;
/**
* Publically available page to feed the news to feed readers
@@ -23,15 +24,11 @@ function user_atom()
throw new HttpForbidden('Not allowed', ['content-type' => 'text/text']);
}
- $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);
+ $news = $request->has('meetings') ? News::whereIsMeeting((bool)$request->get('meetings', false)) : News::query();
+ $news
+ ->limit((int)config('display_news'))
+ ->orderByDesc('updated_at');
+ $output = make_atom_entries_from_news($news->get());
header('Content-Type: application/atom+xml; charset=utf-8');
header('Content-Length: ' . strlen($output));
@@ -39,12 +36,14 @@ function user_atom()
}
/**
- * @param array[] $news_entries
+ * @param News[]|Collection $news_entries
* @return string
*/
function make_atom_entries_from_news($news_entries)
{
$request = app('request');
+ $updatedAt = isset($news_entries[0]) ? $news_entries[0]->updated_at->format('Y-m-d\TH:i:sP') : '0000:00:00T00:00:00+00:00';
+
$html = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>' . config('app_name') . '</title>
@@ -55,7 +54,7 @@ function make_atom_entries_from_news($news_entries)
$request->getRequestUri()
))
. '</id>
- <updated>' . date('Y-m-d\TH:i:sP', $news_entries[0]['Datum']) . '</updated>' . "\n";
+ <updated>' . $updatedAt . '</updated>' . "\n";
foreach ($news_entries as $news_entry) {
$html .= make_atom_entry_from_news($news_entry);
}
@@ -64,21 +63,21 @@ function make_atom_entries_from_news($news_entries)
}
/**
- * @param array $news_entry
+ * @param News $news
* @return string
*/
-function make_atom_entry_from_news($news_entry)
+function make_atom_entry_from_news(News $news)
{
return '
<entry>
- <title>' . htmlspecialchars($news_entry['Betreff']) . '</title>
- <link href="' . page_link_to('news_comments', ['nid' => $news_entry['ID']]) . '"/>
+ <title>' . htmlspecialchars($news->title) . '</title>
+ <link href="' . page_link_to('news_comments', ['nid' => $news->id]) . '"/>
<id>' . preg_replace(
'#^https?://#',
'',
- page_link_to('news_comments', ['nid' => $news_entry['ID']])
+ page_link_to('news_comments', ['nid' => $news->id])
) . '</id>
- <updated>' . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . '</updated>
- <summary type="html">' . htmlspecialchars($news_entry['Text']) . '</summary>
+ <updated>' . $news->updated_at->format('Y-m-d\TH:i:sP') . '</updated>
+ <summary type="html">' . htmlspecialchars($news->text) . '</summary>
</entry>' . "\n";
}