@@ -1216,15 +1216,26 @@ function blc_register_settings_sections() {
12161216 add_settings_section (
12171217 'blc_surveillance_section ' ,
12181218 __ ('Surveillance proactive ' , 'liens-morts-detector-jlg ' ),
1219- 'blc_render_surveillance_section_intro ' ,
1219+ '__return_false ' ,
12201220 $ page
12211221 );
12221222
12231223 add_settings_field (
12241224 'blc_surveillance_thresholds ' ,
1225- __ ('Seuils personnalisés ' , 'liens-morts-detector-jlg ' ),
1225+ __ ('Seuils et métriques surveillés ' , 'liens-morts-detector-jlg ' ),
12261226 'blc_render_surveillance_thresholds_field ' ,
12271227 $ page ,
1228+ 'blc_surveillance_section ' ,
1229+ array (
1230+ 'label_for ' => 'blc-surveillance-thresholds ' ,
1231+ )
1232+ );
1233+
1234+ add_settings_field (
1235+ 'blc_surveillance_escalation ' ,
1236+ __ ('Escalade & notifications ' , 'liens-morts-detector-jlg ' ),
1237+ 'blc_render_surveillance_escalation_field ' ,
1238+ $ page ,
12281239 'blc_surveillance_section '
12291240 );
12301241
@@ -4606,6 +4617,7 @@ function blc_sanitize_notification_recipients_option($value) {
46064617 *
46074618 * @return array<string, string>
46084619 */
4620+ if (!function_exists ('blc_get_notification_webhook_channel_choices ' )) {
46094621function blc_get_notification_webhook_channel_choices () {
46104622 return array (
46114623 'disabled ' => __ ('Désactivé ' , 'liens-morts-detector-jlg ' ),
@@ -4615,16 +4627,17 @@ function blc_get_notification_webhook_channel_choices() {
46154627 'mattermost ' => __ ('Mattermost ' , 'liens-morts-detector-jlg ' ),
46164628 );
46174629}
4630+ }
46184631
4632+ /**
4633+ * Retourne la liste des catégories de statuts HTTP disponibles pour les notifications.
4634+ *
4635+ * @return array<string, string>
4636+ */
46194637if (!function_exists ('blc_get_notification_status_filter_choices ' )) {
4620- /**
4621- * Retourne la liste des catégories de statuts HTTP disponibles pour les notifications.
4622- *
4623- * @return array<string, string>
4624- */
4625- function blc_get_notification_status_filter_choices () {
4626- $ definitions = blc_get_notification_status_filter_definitions ();
4627- $ choices = array ();
4638+ function blc_get_notification_status_filter_choices () {
4639+ $ definitions = blc_get_notification_status_filter_definitions ();
4640+ $ choices = array ();
46284641
46294642 foreach ($ definitions as $ key => $ definition ) {
46304643 if (!isset ($ definition ['label ' ])) {
@@ -4637,15 +4650,18 @@ function blc_get_notification_status_filter_choices() {
46374650 return $ choices ;
46384651 }
46394652}
4653+ }
46404654
46414655/**
46424656 * Retourne la liste par défaut des catégories retenues dans les résumés.
46434657 *
46444658 * @return string[]
46454659 */
4660+ if (!function_exists ('blc_get_default_notification_status_filters ' )) {
46464661function blc_get_default_notification_status_filters () {
46474662 return array_keys (blc_get_notification_status_filter_choices ());
46484663}
4664+ }
46494665
46504666/**
46514667 * Normalise une liste de catégories de statuts HTTP.
@@ -4654,6 +4670,7 @@ function blc_get_default_notification_status_filters() {
46544670 *
46554671 * @return string[]
46564672 */
4673+ if (!function_exists ('blc_normalize_notification_status_filters ' )) {
46574674function blc_normalize_notification_status_filters ($ value ) {
46584675 $ choices = blc_get_notification_status_filter_choices ();
46594676
@@ -4695,25 +4712,27 @@ function blc_normalize_notification_status_filters($value) {
46954712
46964713 return array_values ($ selected );
46974714}
4715+ }
46984716
4717+ /**
4718+ * Récupère la liste des statuts HTTP retenus pour les notifications.
4719+ *
4720+ * @param mixed $override Liste optionnelle à utiliser à la place du réglage stocké.
4721+ *
4722+ * @return string[]
4723+ */
46994724if (!function_exists ('blc_get_notification_status_filters ' )) {
4700- /**
4701- * Récupère la liste des statuts HTTP retenus pour les notifications.
4702- *
4703- * @param mixed $override Liste optionnelle à utiliser à la place du réglage stocké.
4704- *
4705- * @return string[]
4706- */
4707- function blc_get_notification_status_filters ($ override = null ) {
4708- if (is_array ($ override )) {
4709- return blc_normalize_notification_status_filters ($ override );
4710- }
4725+ function blc_get_notification_status_filters ($ override = null ) {
4726+ if (is_array ($ override )) {
4727+ return blc_normalize_notification_status_filters ($ override );
4728+ }
47114729
47124730 $ stored = get_option ('blc_notification_status_filters ' , blc_get_default_notification_status_filters ());
47134731
47144732 return blc_normalize_notification_status_filters ($ stored );
47154733 }
47164734}
4735+ }
47174736
47184737/**
47194738 * Sanitize la liste des statuts HTTP retenus pour les notifications.
@@ -4722,9 +4741,11 @@ function blc_get_notification_status_filters($override = null) {
47224741 *
47234742 * @return string[]
47244743 */
4744+ if (!function_exists ('blc_sanitize_notification_status_filters_option ' )) {
47254745function blc_sanitize_notification_status_filters_option ($ value ) {
47264746 return blc_normalize_notification_status_filters ($ value );
47274747}
4748+ }
47284749
47294750/**
47304751 * Sanitize surveillance thresholds option payload and persist via helper.
@@ -4821,6 +4842,7 @@ function blc_sanitize_surveillance_thresholds_option($value) {
48214842 *
48224843 * @return string
48234844 */
4845+ if (!function_exists ('blc_normalize_notification_webhook_channel ' )) {
48244846function blc_normalize_notification_webhook_channel ($ value ) {
48254847 if (!is_scalar ($ value )) {
48264848 $ value = 'disabled ' ;
@@ -4835,6 +4857,7 @@ function blc_normalize_notification_webhook_channel($value) {
48354857
48364858 return $ value ;
48374859}
4860+ }
48384861
48394862/**
48404863 * Sanitize a severity threshold option (info, warning, critical).
@@ -4887,6 +4910,7 @@ function blc_sanitize_notification_escalation_mode_option($value) {
48874910 *
48884911 * @return string
48894912 */
4913+ if (!function_exists ('blc_normalize_notification_webhook_url ' )) {
48904914function blc_normalize_notification_webhook_url ($ value ) {
48914915 if (!is_scalar ($ value )) {
48924916 return '' ;
@@ -4901,6 +4925,7 @@ function blc_normalize_notification_webhook_url($value) {
49014925
49024926 return (string ) $ value ;
49034927}
4928+ }
49044929
49054930/**
49064931 * Normalise le modèle de message des webhooks.
@@ -4909,6 +4934,7 @@ function blc_normalize_notification_webhook_url($value) {
49094934 *
49104935 * @return string
49114936 */
4937+ if (!function_exists ('blc_normalize_notification_message_template ' )) {
49124938function blc_normalize_notification_message_template ($ value ) {
49134939 if (!is_scalar ($ value )) {
49144940 $ value = '' ;
@@ -4926,7 +4952,9 @@ function blc_normalize_notification_message_template($value) {
49264952
49274953 return $ value ;
49284954}
4955+ }
49294956
4957+ if (!function_exists ('blc_normalize_notification_slack_channel_override ' )) {
49304958function blc_normalize_notification_slack_channel_override ($ value ) {
49314959 if (!is_scalar ($ value )) {
49324960 return '' ;
@@ -4966,7 +4994,9 @@ function blc_normalize_notification_slack_channel_override($value) {
49664994
49674995 return substr ($ normalized , 0 , 80 );
49684996}
4997+ }
49694998
4999+ if (!function_exists ('blc_normalize_notification_slack_username ' )) {
49705000function blc_normalize_notification_slack_username ($ value ) {
49715001 if (!is_scalar ($ value )) {
49725002 return '' ;
@@ -4987,7 +5017,9 @@ function blc_normalize_notification_slack_username($value) {
49875017
49885018 return $ value ;
49895019}
5020+ }
49905021
5022+ if (!function_exists ('blc_normalize_notification_slack_icon ' )) {
49915023function blc_normalize_notification_slack_icon ($ value ) {
49925024 if (!is_scalar ($ value )) {
49935025 return '' ;
@@ -5009,7 +5041,9 @@ function blc_normalize_notification_slack_icon($value) {
50095041
50105042 return $ url ;
50115043}
5044+ }
50125045
5046+ if (!function_exists ('blc_normalize_notification_slack_title_template ' )) {
50135047function blc_normalize_notification_slack_title_template ($ value ) {
50145048 if (!is_scalar ($ value )) {
50155049 $ value = '' ;
@@ -5034,10 +5068,138 @@ function blc_normalize_notification_slack_title_template($value) {
50345068
50355069 return $ value ;
50365070}
5071+ }
50375072
5073+ if (!function_exists ('blc_normalize_notification_slack_toggle ' )) {
50385074function blc_normalize_notification_slack_toggle ($ value ) {
50395075 return (bool ) $ value ;
50405076}
5077+ }
5078+
5079+ /**
5080+ * Retrieve the available taxonomy choices for surveillance thresholds.
5081+ *
5082+ * @return array<string,string>
5083+ */
5084+ if (!function_exists ('blc_get_surveillance_taxonomy_choices ' )) {
5085+ function blc_get_surveillance_taxonomy_choices () {
5086+ $ choices = array ();
5087+
5088+ if (function_exists ('get_taxonomies ' )) {
5089+ $ taxonomies = get_taxonomies (array ('public ' => true ), 'objects ' );
5090+
5091+ if (is_array ($ taxonomies )) {
5092+ foreach ($ taxonomies as $ taxonomy => $ object ) {
5093+ $ label = isset ($ object ->labels ->singular_name ) ? (string ) $ object ->labels ->singular_name : $ taxonomy ;
5094+ $ choices [$ taxonomy ] = $ label ;
5095+ }
5096+ }
5097+ }
5098+
5099+ if ($ choices === array ()) {
5100+ $ choices ['category ' ] = __ ('Catégories ' , 'liens-morts-detector-jlg ' );
5101+ $ choices ['post_tag ' ] = __ ('Étiquettes ' , 'liens-morts-detector-jlg ' );
5102+ }
5103+
5104+ return $ choices ;
5105+ }
5106+ }
5107+
5108+ /**
5109+ * Return the available comparison operators for surveillance thresholds.
5110+ *
5111+ * @return array<string,string>
5112+ */
5113+ if (!function_exists ('blc_get_surveillance_comparison_options ' )) {
5114+ function blc_get_surveillance_comparison_options () {
5115+ return array (
5116+ 'gte ' => __ ('≥ (supérieur ou égal) ' , 'liens-morts-detector-jlg ' ),
5117+ 'gt ' => __ ('> (strictement supérieur) ' , 'liens-morts-detector-jlg ' ),
5118+ 'lte ' => __ ('≤ (inférieur ou égal) ' , 'liens-morts-detector-jlg ' ),
5119+ 'lt ' => __ ('< (strictement inférieur) ' , 'liens-morts-detector-jlg ' ),
5120+ 'eq ' => __ ('= (égal à) ' , 'liens-morts-detector-jlg ' ),
5121+ 'neq ' => __ ('≠ (différent de) ' , 'liens-morts-detector-jlg ' ),
5122+ );
5123+ }
5124+ }
5125+
5126+ /**
5127+ * Return the severity labels for surveillance alerts.
5128+ *
5129+ * @return array<string,string>
5130+ */
5131+ if (!function_exists ('blc_get_surveillance_severity_options ' )) {
5132+ function blc_get_surveillance_severity_options () {
5133+ return array (
5134+ 'warning ' => __ ('Avertissement ' , 'liens-morts-detector-jlg ' ),
5135+ 'critical ' => __ ('Critique ' , 'liens-morts-detector-jlg ' ),
5136+ );
5137+ }
5138+ }
5139+
5140+ /**
5141+ * Sanitize the surveillance thresholds option payload.
5142+ *
5143+ * @param mixed $value Raw value.
5144+ *
5145+ * @return array<string,mixed>
5146+ */
5147+ function blc_sanitize_surveillance_thresholds_option ($ value ) {
5148+ return blc_normalize_surveillance_thresholds ($ value );
5149+ }
5150+
5151+ /**
5152+ * Sanitize the list of severity levels enabled for a channel.
5153+ *
5154+ * @param mixed $value Raw value.
5155+ *
5156+ * @return array<int,string>
5157+ */
5158+ function blc_sanitize_surveillance_escalation_levels_option ($ value ) {
5159+ $ options = blc_get_surveillance_severity_options ();
5160+
5161+ if (is_string ($ value )) {
5162+ $ value = array ($ value );
5163+ }
5164+
5165+ if (!is_array ($ value )) {
5166+ $ value = array ();
5167+ }
5168+
5169+ $ normalized = array ();
5170+
5171+ foreach ($ value as $ candidate ) {
5172+ if (!is_scalar ($ candidate )) {
5173+ continue ;
5174+ }
5175+
5176+ $ slug = sanitize_key ((string ) $ candidate );
5177+ if ($ slug === '' || !isset ($ options [$ slug ])) {
5178+ continue ;
5179+ }
5180+
5181+ $ normalized [$ slug ] = $ slug ;
5182+ }
5183+
5184+ return array_values ($ normalized );
5185+ }
5186+
5187+ /**
5188+ * Sanitize the cooldown (seconds) configured for a severity.
5189+ *
5190+ * @param mixed $value Raw value.
5191+ *
5192+ * @return int
5193+ */
5194+ function blc_sanitize_surveillance_cooldown_option ($ value ) {
5195+ $ value = is_numeric ($ value ) ? (int ) $ value : 0 ;
5196+
5197+ if ($ value < 60 ) {
5198+ $ value = 60 ;
5199+ }
5200+
5201+ return $ value ;
5202+ }
50415203
50425204/**
50435205 * Retrieve the available taxonomy choices for surveillance thresholds.
0 commit comments