Add flash messaging for newsletter actions in index.php and wiki.php. Implemented session handling for success and error messages, and added redirection after form submissions to enhance user experience.
This commit is contained in:
32
wiki.php
32
wiki.php
@@ -170,6 +170,10 @@ function fetchLatestArticles(string $wikiUrl, int $limit = 150): array
|
||||
$nodes = $xpath->query('//li');
|
||||
|
||||
foreach ($nodes as $li) {
|
||||
if (!$li instanceof DOMElement) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$text = trim(preg_replace('/\s+/', ' ', $li->textContent ?? ''));
|
||||
|
||||
if (!preg_match('/\((\d{2}\.\d{2}\.\d{4})\)/', $text, $dateMatch)) {
|
||||
@@ -722,6 +726,15 @@ $error = '';
|
||||
$previewHtml = '';
|
||||
$previewClipboardHtml = '';
|
||||
|
||||
$flash = $_SESSION['wiki_newsletter_flash'] ?? null;
|
||||
if (is_array($flash)) {
|
||||
$message = (string)($flash['message'] ?? '');
|
||||
$error = (string)($flash['error'] ?? '');
|
||||
$previewHtml = (string)($flash['preview_html'] ?? '');
|
||||
$previewClipboardHtml = (string)($flash['preview_clipboard_html'] ?? '');
|
||||
unset($_SESSION['wiki_newsletter_flash']);
|
||||
}
|
||||
|
||||
$isCron = (PHP_SAPI === 'cli' && cliArg('cron') !== null) || isset($_GET['cron']);
|
||||
|
||||
if ($isCron) {
|
||||
@@ -751,6 +764,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'login
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') !== 'login') {
|
||||
$redirectUrl = strtok($_SERVER['REQUEST_URI'], '?');
|
||||
|
||||
try {
|
||||
requireAdmin();
|
||||
$config = configFromPost($config);
|
||||
@@ -770,9 +785,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') !== 'login
|
||||
} elseif ($action === 'monthly_send') {
|
||||
$message = sendMonthlyIfDue($config);
|
||||
}
|
||||
|
||||
$_SESSION['wiki_newsletter_flash'] = [
|
||||
'message' => $message,
|
||||
'error' => '',
|
||||
'preview_html' => $previewHtml,
|
||||
'preview_clipboard_html' => $previewClipboardHtml,
|
||||
];
|
||||
} catch (Throwable $e) {
|
||||
$error = $e->getMessage();
|
||||
$_SESSION['wiki_newsletter_flash'] = [
|
||||
'message' => '',
|
||||
'error' => $e->getMessage(),
|
||||
'preview_html' => '',
|
||||
'preview_clipboard_html' => '',
|
||||
];
|
||||
}
|
||||
|
||||
header('Location: ' . $redirectUrl);
|
||||
exit;
|
||||
}
|
||||
|
||||
$isLoggedIn = isAdminLoggedIn();
|
||||
|
||||
Reference in New Issue
Block a user