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.
+