' . meetings_title() . '
' . msg();
$request = request();
if (preg_match('/^\d{1,}$/', $request->input('page', 0))) {
$page = $request->input('page', 0);
} else {
$page = 0;
}
$news = News::where('is_meeting', true)
->orderBy('created_at', 'DESC')
->limit($display_news)
->offset($page * $display_news)
->get();
foreach ($news as $entry) {
$html .= display_news($entry);
}
$dis_rows = ceil(News::where('is_meeting', true)->count() / $display_news);
$html .= '' . '
';
return $html;
}
/**
* Renders the text content of a news entry
*
* @param News $news
* @return string HTML
*/
function news_text(News $news): string
{
$text = ReplaceSmilies($news->text);
$text = preg_replace("/\r\n\r\n/m", '
', $text);
return $text;
}
/**
* @param News $news
* @return string
*/
function display_news(News $news): string
{
global $page;
$html = '';
$html .= '';
$html .= '
';
$html .= '
' . ($news->is_meeting ? '[Meeting] ' : '') . ReplaceSmilies($news->title) . '
';
$html .= '';
$html .= '
' . news_text($news) . '
';
$html .= '';
$html .= '
';
return $html;
}
/**
* @return string
*/
function user_news_comments()
{
$user = auth()->user();
$request = request();
$html = '' . user_news_comments_title() . '
';
$nid = $request->input('nid');
if (
$request->has('nid')
&& preg_match('/^\d{1,}$/', $nid)
&& News::where('id', $request->input('nid'))->count() > 0
) {
$news = News::find('id');
if ($request->hasPostData('submit') && $request->has('text')) {
$text = $request->input('text');
DB::insert('
INSERT INTO `NewsComments` (`Refid`, `Datum`, `Text`, `UID`)
VALUES (?, ?, ?, ?)
',
[
$nid,
date('Y-m-d H:i:s'),
$text,
$user->id,
]
);
engelsystem_log('Created news_comment: ' . $text);
$html .= success(__('Entry saved.'), true);
}
$html .= display_news($news);
$comments = DB::select(
'SELECT * FROM `NewsComments` WHERE `Refid`=? ORDER BY \'ID\'',
[$nid]
);
foreach ($comments as $comment) {
$user_source = User::find($comment['UID']);
$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 = '' . news_title() . '
' . msg();
$isMeeting = $request->postData('treffen');
if ($request->has('text') && $request->has('betreff') && auth()->can('admin_news')) {
if (!$request->has('treffen')) {
$isMeeting = 0;
}
$text = $request->postData('text');
if (!auth()->can('admin_news_html')) {
$text = strip_tags($text);
}
News::create([
'title' => strip_tags($request->postData('betreff')),
'text' => $text,
'user_id' => $user->id,
'is_meeting' => !!$isMeeting,
]);
engelsystem_log('Created news: ' . $request->postData('betreff') . ', treffen: ' . $isMeeting);
success(__('Entry saved.'));
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 . '
';
}