' . '
';
return $html;
}
/**
* Renders the text content of a news entry
*
* @param News $news
* @return string HTML
*/
function news_text(News $news): string
{
$text = preg_replace("/\r\n\r\n/m", '';
$html .= '
';
$html .= '
' . ($news->is_meeting ? '[Meeting] ' : '') . $news->title . '
';
$html .= '';
$html .= '
' . news_text($news) . '
';
$html .= '';
$html .= '
';
return $html;
}
/**
* @return string
*/
function user_news_comments()
{
$user = auth()->user();
$request = request();
$html = '';
$html .= '
' . user_news_comments_title() . '
';
$nid = $request->input('nid');
if (
$request->has('nid')
&& preg_match('/^\d{1,}$/', $nid)
&& $news = News::find($nid)
) {
if ($request->hasPostData('submit') && $request->has('text')) {
$text = $request->input('text');
$news->comments()->create([
'text' => $text,
'user_id' => $user->id,
]);
engelsystem_log('Created news_comment: ' . $text);
$html .= success(__('Entry saved.'), true);
}
$html .= display_news($news);
foreach ($news->comments as $comment) {
$html .= '
';
$html .= '
' . nl2br(htmlspecialchars($comment->text)) . '
';
$html .= '';
$html .= '
';
}
$html .= '
' . __('New Comment:') . '
';
$html .= form([
form_textarea('text', __('Message'), ''),
form_submit('submit', __('Save'))
], page_link_to('news_comments', ['nid' => $news->id]));
} else {
$html .= __('Invalid request.');
}
return $html . '
';
}
/**
* @return string
*/
function user_news()
{
$user = auth()->user();
$display_news = config('display_news');
$request = request();
$html = '';
$html .= '
' . news_title() . '
' . msg();
$isMeeting = $request->postData('treffen', false);
if ($request->has('text') && $request->has('betreff') && auth()->can('admin_news')) {
$text = $request->postData('text');
if (!auth()->can('admin_news_html')) {
$text = strip_tags($text);
}
$news = News::create([
'title' => strip_tags($request->postData('betreff')),
'text' => $text,
'user_id' => $user->id,
'is_meeting' => (bool)$isMeeting,
]);
engelsystem_log('Created news: ' . $news->title . ', is meeting: ' . ($news->is_meeting ? 'yes' : 'no'));
success(__('Entry saved.'));
throw_redirect(page_link_to('news'));
}
if (preg_match('/^\d{1,}$/', $request->input('page', 0))) {
$page = $request->input('page', 0);
} else {
$page = 0;
}
$news = News::query()
->orderBy('created_at', 'DESC')
->limit($display_news)
->offset($page * $display_news)
->get();
foreach ($news as $entry) {
$html .= display_news($entry);
}
$dis_rows = ceil(News::query()->count() / $display_news);
$html .= '
' . '
';
if (auth()->can('admin_news')) {
$html .= '
';
$html .= '
' . __('Create news:') . '
';
$html .= form([
form_text('betreff', __('Subject'), ''),
form_textarea('text', __('Message'), ''),
form_checkbox('treffen', __('Meeting'), false, 1),
form_submit('submit', __('Save'))
]);
}
return $html . '
';
}