From b878740f80ce7cfe2a0bc53956e3f7e4e0aa2f78 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 10 Nov 2019 21:30:26 +0100 Subject: News: Bug fixes, cleanup, comments & formatting Use more magically available methods and properties Fixed atom feed and stats not using the new model --- includes/pages/user_atom.php | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'includes/pages/user_atom.php') 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 @@ '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 = ' ' . config('app_name') . ' @@ -55,7 +54,7 @@ function make_atom_entries_from_news($news_entries) $request->getRequestUri() )) . ' - ' . date('Y-m-d\TH:i:sP', $news_entries[0]['Datum']) . '' . "\n"; + ' . $updatedAt . '' . "\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 ' - ' . htmlspecialchars($news_entry['Betreff']) . ' - + ' . htmlspecialchars($news->title) . ' + ' . preg_replace( '#^https?://#', '', - page_link_to('news_comments', ['nid' => $news_entry['ID']]) + page_link_to('news_comments', ['nid' => $news->id]) ) . ' - ' . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . ' - ' . htmlspecialchars($news_entry['Text']) . ' + ' . $news->updated_at->format('Y-m-d\TH:i:sP') . ' + ' . htmlspecialchars($news->text) . ' ' . "\n"; } -- cgit v1.3.1