diff --git a/database/schema.sql b/database/schema.sql index 3d67f63..f2c7501 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -180,6 +180,8 @@ CREATE TABLE `tbl_scwebhooks` ( `cl_scwebhook_id` int(11) NOT NULL AUTO_INCREMENT, `cl_scwebhook_name` varchar(255) NOT NULL, `cl_scwebhook_url` text NOT NULL, + `cl_scwebhook_image_url` text NOT NULL, + `cl_scwebhook_border_color` varchar(20) NOT NULL DEFAULT '#ffae00', `cl_scwebhook_is_forum` tinyint(1) DEFAULT 0, PRIMARY KEY (`cl_scwebhook_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; diff --git a/db/scdiscord.php b/db/scdiscord.php index b0943af..ba2da65 100644 --- a/db/scdiscord.php +++ b/db/scdiscord.php @@ -17,11 +17,25 @@ function scdiscord_bootstrap(): void cl_scwebhook_id INT(11) NOT NULL AUTO_INCREMENT, cl_scwebhook_name VARCHAR(255) NOT NULL, cl_scwebhook_url TEXT NOT NULL, + cl_scwebhook_image_url TEXT NOT NULL, + cl_scwebhook_border_color VARCHAR(20) NOT NULL DEFAULT '#ffae00', cl_scwebhook_is_forum TINYINT(1) NOT NULL DEFAULT 0, PRIMARY KEY (cl_scwebhook_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" ); + $columns_stmt = $db->query("SHOW COLUMNS FROM tbl_scwebhooks LIKE 'cl_scwebhook_image_url'"); + $has_webhook_image = (bool) $columns_stmt->fetch(); + if (!$has_webhook_image) { + $db->exec("ALTER TABLE tbl_scwebhooks ADD COLUMN cl_scwebhook_image_url TEXT NOT NULL AFTER cl_scwebhook_url"); + } + + $columns_stmt = $db->query("SHOW COLUMNS FROM tbl_scwebhooks LIKE 'cl_scwebhook_border_color'"); + $has_webhook_border_color = (bool) $columns_stmt->fetch(); + if (!$has_webhook_border_color) { + $db->exec("ALTER TABLE tbl_scwebhooks ADD COLUMN cl_scwebhook_border_color VARCHAR(20) NOT NULL DEFAULT '#ffae00' AFTER cl_scwebhook_image_url"); + } + $db->exec( "CREATE TABLE IF NOT EXISTS tbl_scbanners ( cl_scbanner_id INT(11) NOT NULL AUTO_INCREMENT, @@ -38,6 +52,20 @@ function scdiscord_bootstrap(): void $db->exec("ALTER TABLE tbl_scbanners ADD COLUMN cl_scbanner_border_color VARCHAR(20) NOT NULL DEFAULT '#ffae00' AFTER cl_scbanner_url"); } + $db->exec( + "UPDATE tbl_scwebhooks w + LEFT JOIN tbl_scbanners b ON b.cl_scbanner_name = w.cl_scwebhook_name + SET + w.cl_scwebhook_image_url = CASE + WHEN (w.cl_scwebhook_image_url IS NULL OR w.cl_scwebhook_image_url = '') AND b.cl_scbanner_url IS NOT NULL THEN b.cl_scbanner_url + ELSE w.cl_scwebhook_image_url + END, + w.cl_scwebhook_border_color = CASE + WHEN (w.cl_scwebhook_border_color IS NULL OR w.cl_scwebhook_border_color = '' OR w.cl_scwebhook_border_color = '#ffae00') AND b.cl_scbanner_border_color IS NOT NULL THEN b.cl_scbanner_border_color + ELSE w.cl_scwebhook_border_color + END" + ); + $db->exec( "CREATE TABLE IF NOT EXISTS tbl_scnotifications ( cl_scnotification_id INT(11) NOT NULL AUTO_INCREMENT, diff --git a/scnotification.php b/scnotification.php index 8b19fec..66a6809 100644 --- a/scnotification.php +++ b/scnotification.php @@ -37,9 +37,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $cl_scnotification_webhook_id = (int) $matches[1]; } - $cl_scnotification_banner_id = (int) ($_POST['cl_scnotification_banner_id'] ?? 0); - $use_custom_banner = isset($_POST['cl_scnotification_use_custom_banner']) || isset($_POST['use_custom_banner']); - $cl_scnotification_custom_banner_url = trim((string) ($_POST['cl_scnotification_custom_banner_url'] ?? ($_POST['custom_banner'] ?? ''))); $notify_here = isset($_POST['cl_scnotification_notify_here']) || isset($_POST['ping_here']); $notify_everyone = isset($_POST['cl_scnotification_notify_everyone']) || isset($_POST['ping_everyone']); $cl_scnotification_title = trim((string) ($_POST['cl_scnotification_title'] ?? ($_POST['title'] ?? ''))); @@ -92,18 +89,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit; } - $banner = null; - if ($cl_scnotification_banner_id > 0) { - $stmt_banner = $db->prepare('SELECT * FROM tbl_scbanners WHERE cl_scbanner_id = :id LIMIT 1'); - $stmt_banner->execute(['id' => $cl_scnotification_banner_id]); - $banner = $stmt_banner->fetch(); - } - - if ($use_custom_banner && $cl_scnotification_custom_banner_url !== '' && !filter_var($cl_scnotification_custom_banner_url, FILTER_VALIDATE_URL)) { - auth_flash_set('error', 'L’URL de bannière personnalisée est invalide.'); - header('Location: scnotification.php'); - exit; - } foreach ([ 'URL canal Discord' => [$show_channel_url, $cl_scnotification_channel_url], @@ -119,10 +104,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } $mentions = scdiscord_build_mentions($notify_here, $notify_everyone); - $banner_image_url = $use_custom_banner && $cl_scnotification_custom_banner_url !== '' - ? $cl_scnotification_custom_banner_url - : (string) ($banner['cl_scbanner_url'] ?? ''); - $border_color = (string) ($banner['cl_scbanner_border_color'] ?? '#ffae00'); + $banner_image_url = (string) ($webhook['cl_scwebhook_image_url'] ?? ''); + $border_color = (string) ($webhook['cl_scwebhook_border_color'] ?? '#ffae00'); $fields = []; @@ -249,7 +232,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $stmt_log = $db->prepare( 'INSERT INTO tbl_scnotifications ( cl_scnotification_webhook_id, - cl_scnotification_banner_id, cl_scnotification_title, cl_scnotification_message, cl_scnotification_payload, @@ -258,7 +240,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { cl_scnotification_created_by ) VALUES ( :webhook_id, - :banner_id, :title, :message, :payload, @@ -269,7 +250,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { ); $stmt_log->execute([ 'webhook_id' => $cl_scnotification_webhook_id, - 'banner_id' => $cl_scnotification_banner_id > 0 ? $cl_scnotification_banner_id : null, 'title' => $cl_scnotification_title, 'message' => $cl_scnotification_message, 'payload' => json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), @@ -298,8 +278,6 @@ unset($_SESSION['scnotification_old']); $stmt_webhooks = $db->query('SELECT * FROM tbl_scwebhooks ORDER BY cl_scwebhook_name ASC'); $webhooks = $stmt_webhooks->fetchAll(); -$stmt_banners = $db->query('SELECT * FROM tbl_scbanners ORDER BY cl_scbanner_name ASC'); -$banners = $stmt_banners->fetchAll(); function scnotification_old_value(array $old, string $key, string $default = ''): string { $value = $old[$key] ?? $default; @@ -737,25 +715,11 @@ function scnotification_old_checked(array $old, string $key, bool $default = fal
-

Bannière et Couleur de bordure

-
- -
- -
- -
+

Prévisualisation et Couleur

+

+ L’image de prévisualisation et la couleur de bordure sont maintenant prises automatiquement depuis le canal Discord sélectionné. + Pour les modifier, va dans la page de configuration Discord du webhook correspondant. +

@@ -939,7 +903,6 @@ function scnotification_old_checked(array $old, string $key, bool $default = fal } function syncStates() { - toggleByCheckbox('cl_scnotification_use_custom_banner', '#cl_scnotification_custom_banner_url'); toggleByCheckbox('cl_scnotification_show_footer', '.footer-toggle'); toggleByCheckbox('cl_scnotification_show_org', '.org-toggle'); toggleByCheckbox('cl_scnotification_show_pvp', '.pvp-toggle'); @@ -963,7 +926,6 @@ function scnotification_old_checked(array $old, string $key, bool $default = fal messageField.addEventListener('input', updateCounter); [ - 'cl_scnotification_use_custom_banner', 'cl_scnotification_show_footer', 'cl_scnotification_show_org', 'cl_scnotification_show_pvp', diff --git a/scwebhook.php b/scwebhook.php index 447277e..ed84a5f 100644 --- a/scwebhook.php +++ b/scwebhook.php @@ -30,10 +30,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $webhook_id = (int) ($_POST['webhook_id'] ?? 0); $cl_scwebhook_name = trim((string) ($_POST['cl_scwebhook_name'] ?? '')); $cl_scwebhook_url = trim((string) ($_POST['cl_scwebhook_url'] ?? '')); + $cl_scwebhook_image_url = trim((string) ($_POST['cl_scwebhook_image_url'] ?? '')); + $cl_scwebhook_border_color = scdiscord_normalize_hex_color((string) ($_POST['cl_scwebhook_border_color'] ?? '')); $cl_scwebhook_is_forum = 0; - if ($cl_scwebhook_name === '' || $cl_scwebhook_url === '') { - auth_flash_set('error', 'Le nom et l’URL du webhook sont obligatoires.'); + if ($cl_scwebhook_name === '' || $cl_scwebhook_url === '' || $cl_scwebhook_image_url === '') { + auth_flash_set('error', 'Le nom, l’URL du webhook et l’image sont obligatoires.'); header('Location: scwebhook.php'); exit; } @@ -44,28 +46,38 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit; } + if (!filter_var($cl_scwebhook_image_url, FILTER_VALIDATE_URL)) { + auth_flash_set('error', 'L’URL de l’image Discord est invalide.'); + header('Location: scwebhook.php'); + exit; + } + try { if ($action === 'add_webhook') { - $stmt = $db->prepare('INSERT INTO tbl_scwebhooks (cl_scwebhook_name, cl_scwebhook_url, cl_scwebhook_is_forum) VALUES (:name, :url, :is_forum)'); + $stmt = $db->prepare('INSERT INTO tbl_scwebhooks (cl_scwebhook_name, cl_scwebhook_url, cl_scwebhook_image_url, cl_scwebhook_border_color, cl_scwebhook_is_forum) VALUES (:name, :url, :image_url, :border_color, :is_forum)'); $stmt->execute([ 'name' => $cl_scwebhook_name, 'url' => $cl_scwebhook_url, + 'image_url' => $cl_scwebhook_image_url, + 'border_color' => $cl_scwebhook_border_color, 'is_forum' => $cl_scwebhook_is_forum, ]); - auth_flash_set('success', 'Webhook Discord ajouté avec succès.'); + auth_flash_set('success', 'Canal Discord ajouté avec succès.'); } else { if ($webhook_id <= 0) { throw new RuntimeException('ID de webhook invalide.'); } - $stmt = $db->prepare('UPDATE tbl_scwebhooks SET cl_scwebhook_name = :name, cl_scwebhook_url = :url, cl_scwebhook_is_forum = :is_forum WHERE cl_scwebhook_id = :id'); + $stmt = $db->prepare('UPDATE tbl_scwebhooks SET cl_scwebhook_name = :name, cl_scwebhook_url = :url, cl_scwebhook_image_url = :image_url, cl_scwebhook_border_color = :border_color, cl_scwebhook_is_forum = :is_forum WHERE cl_scwebhook_id = :id'); $stmt->execute([ 'name' => $cl_scwebhook_name, 'url' => $cl_scwebhook_url, + 'image_url' => $cl_scwebhook_image_url, + 'border_color' => $cl_scwebhook_border_color, 'is_forum' => $cl_scwebhook_is_forum, 'id' => $webhook_id, ]); - auth_flash_set('success', 'Webhook Discord mis à jour.'); + auth_flash_set('success', 'Canal Discord mis à jour.'); } } catch (Throwable $e) { auth_flash_set('error', 'Erreur webhook : ' . $e->getMessage()); @@ -89,7 +101,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } else { $stmt = $db->prepare('DELETE FROM tbl_scwebhooks WHERE cl_scwebhook_id = :id'); $stmt->execute(['id' => $webhook_id]); - auth_flash_set('success', 'Webhook Discord supprimé.'); + auth_flash_set('success', 'Canal Discord supprimé.'); } } catch (Throwable $e) { auth_flash_set('error', 'Erreur suppression webhook : ' . $e->getMessage()); @@ -99,86 +111,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { header('Location: scwebhook.php'); exit; } - - if ($action === 'add_banner' || $action === 'update_banner') { - $banner_id = (int) ($_POST['banner_id'] ?? 0); - $cl_scbanner_name = trim((string) ($_POST['cl_scbanner_name'] ?? '')); - $cl_scbanner_url = trim((string) ($_POST['cl_scbanner_url'] ?? '')); - $cl_scbanner_border_color = scdiscord_normalize_hex_color((string) ($_POST['cl_scbanner_border_color'] ?? '')); - - if ($cl_scbanner_name === '' || $cl_scbanner_url === '') { - auth_flash_set('error', 'Le nom et le lien d’image de la bannière sont obligatoires.'); - header('Location: scwebhook.php'); - exit; - } - - if (!filter_var($cl_scbanner_url, FILTER_VALIDATE_URL)) { - auth_flash_set('error', 'L’URL de la bannière est invalide.'); - header('Location: scwebhook.php'); - exit; - } - - try { - if ($action === 'add_banner') { - $stmt = $db->prepare('INSERT INTO tbl_scbanners (cl_scbanner_name, cl_scbanner_url, cl_scbanner_border_color) VALUES (:name, :url, :border_color)'); - $stmt->execute([ - 'name' => $cl_scbanner_name, - 'url' => $cl_scbanner_url, - 'border_color' => $cl_scbanner_border_color, - ]); - auth_flash_set('success', 'Bannière Discord ajoutée avec succès.'); - } else { - if ($banner_id <= 0) { - throw new RuntimeException('ID de bannière invalide.'); - } - - $stmt = $db->prepare('UPDATE tbl_scbanners SET cl_scbanner_name = :name, cl_scbanner_url = :url, cl_scbanner_border_color = :border_color WHERE cl_scbanner_id = :id'); - $stmt->execute([ - 'name' => $cl_scbanner_name, - 'url' => $cl_scbanner_url, - 'border_color' => $cl_scbanner_border_color, - 'id' => $banner_id, - ]); - auth_flash_set('success', 'Bannière Discord mise à jour.'); - } - } catch (Throwable $e) { - auth_flash_set('error', 'Erreur bannière : ' . $e->getMessage()); - } - - header('Location: scwebhook.php'); - exit; - } - - if ($action === 'delete_banner') { - $banner_id = (int) ($_POST['banner_id'] ?? 0); - - if ($banner_id > 0) { - try { - $stmt = $db->prepare('DELETE FROM tbl_scbanners WHERE cl_scbanner_id = :id'); - $stmt->execute(['id' => $banner_id]); - auth_flash_set('success', 'Bannière Discord supprimée.'); - } catch (Throwable $e) { - auth_flash_set('error', 'Erreur suppression bannière : ' . $e->getMessage()); - } - } - - header('Location: scwebhook.php'); - exit; - } } $stmt_webhooks = $db->query('SELECT * FROM tbl_scwebhooks ORDER BY cl_scwebhook_name ASC'); $webhooks = $stmt_webhooks->fetchAll(); -$stmt_banners = $db->query('SELECT * FROM tbl_scbanners ORDER BY cl_scbanner_name ASC'); -$banners = $stmt_banners->fetchAll(); ?> - SC Webhook | R.E.A.C.T. Admin + SC Discord | R.E.A.C.T. Admin