cgt-wp-theme/inc/theme-options.php
2026-11-12 22:07:17 +01:00

772 lines
35 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Panneau d'administration WordPress : Apparence > Réglages UL CGT
*
* Toutes les options sont pré-remplies par défaut via wp_parse_args()
* afin que le thème soit immédiatement fonctionnel dès son activation.
*
* @package CGT_FHA
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
const CGT_FHA_OPTION_KEY = 'cgt_fha_options';
const CGT_FHA_SCHEMA_VERSION = '1.2.1';
/**
* Valeurs par défaut complètes de toutes les options du thème.
*
* @return array<string, mixed>
*/
function cgt_fha_get_defaults(): array {
return array(
// Onglet 1 : Identité & Coordonnées.
'phone' => '07 60 49 64 69',
'email' => 'union-locale@cgt-fha.fr',
'address' => "Espace Sabart, 10 Av. de l'Ayroule, 09400 Tarascon-sur-Ariège",
'hours' => "Permanences d'accueil et juridiques : Mardi et Jeudi de 9h30 à 12h30, et sur rendez-vous.",
'facebook_url' => 'https://www.facebook.com/profile.php?id=61552410568856',
'instagram_url' => '',
'youtube_url' => '',
'header_logo_url' => CGT_FHA_URI . '/assets/img/banniere-ul-noir.png',
'footer_logo_url' => CGT_FHA_URI . '/assets/img/banniere-ul-blanc.png',
'footer_desc' => "L'Union Locale CGT de Foix et de la Haute-Ariège rassemble tous les syndicats CGT de son périmètre et rattache directement les salarié·e·s isolé·e·s au sein de son syndicat multiprofessionnel (Multipros).",
'footer_call' => "Une lutte dans votre entreprise, une info à partager ? Contactez l'UL",
'news_url' => home_url( '/actualites/' ),
'calendar_url' => home_url( '/calendrier/' ),
'contact_url' => home_url( '/contact/' ),
'join_url' => home_url( '/syndiquez-vous/' ),
'legal_url' => home_url( '/mentions-legales/' ),
// Onglet 2 : Bandeau Mobilisation auto-expirant.
'banner_enabled' => 0,
'banner_text' => 'MOBILISATION : Grève et manifestation à Foix - Allées de Villote',
'banner_url' => '',
'banner_expires' => wp_date( 'Y-m-d\TH:i', time() + 7 * DAY_IN_SECONDS ),
// Onglet 3 : Page d'accueil — Hero.
'hero_bg_url' => CGT_FHA_URI . '/assets/img/hero-ariege.jpg',
'hero_title_line1' => 'Union Locale CGT Foix Haute-Ariège',
'hero_title_line2' => 'Votre syndicat de proximité !',
'hero_quote' => '« La régression sociale ne se négocie pas, elle se combat ! » — Henri Krasucki, Secrétaire Général de la CGT de 1982 à 1992',
'hero_btn1_label' => "J'ai besoin d'aide",
'hero_btn1_url' => home_url( '/contact/' ),
'hero_btn2_label' => 'Rejoindre la CGT',
'hero_btn2_url' => home_url( '/syndiquez-vous/' ),
// Onglet 3 : Section 2 — À quoi nous servons ?
'missions_title' => 'À QUOI NOUS SERVONS ?',
'missions_subtitle' => "L'Union Locale fédère l'ensemble des syndicats CGT du bassin de Foix et de la Haute-Ariège, et accueille directement les salarié·e·s sans syndicat d'entreprise grâce à son syndicat multiprofessionnel (Multipros).",
'mission_1_icon' => 'fist',
'mission_1_title' => "S'ORGANISER",
'mission_1_text' => "Unir tous les syndicats CGT de Foix et de la Haute-Ariège, créer une section dans votre entreprise ou vous syndiquer directement via le syndicat Multipros de l'Union Locale.",
'mission_2_icon' => 'shield',
'mission_2_title' => 'SE DÉFENDRE',
'mission_2_text' => "Faire respecter vos droits, vos salaires et vos conditions de travail à Foix comme en Haute-Ariège, avec l'appui solidaire de nos syndicats, conseillers du salarié et défenseurs.",
'mission_3_icon' => 'chat',
'mission_3_title' => "S'INFORMER & SE FORMER",
'mission_3_text' => "Partager l'actualité des luttes à Foix et en Haute-Ariège et exercer votre droit légal à la formation syndicale (CFESES) pour agir collectivement.",
// Onglet 3 : Titres Actualités locales & confédérales.
'local_news_title' => 'SUR LE TERRAIN À FOIX ET EN HAUTE-ARIÈGE',
'local_news_more' => 'Voir toutes les actualités locales →',
'confederal_title' => 'ACTUALITÉ CONFÉDÉRALE',
// Onglet 3 : Section 5 — Salariés isolés & TPE (Multipros).
'tpe_enabled' => 1,
'tpe_badge' => "Syndicat Multipros de l'UL · TPE, PME & Isolé·e·s",
'tpe_title' => "SALARIÉS ISOLÉS & TPE : VOUS N'ÊTES PAS SEULS",
'tpe_text' => "À Foix comme en Haute-Ariège, même sans section syndicale ni CSE dans votre entreprise (TPE, commerce, artisanat, chantier, association…), l'Union Locale est votre maison commune : vous êtes rattaché·e directement au syndicat multiprofessionnel (Multipros) de l'UL.",
'tpe_point_1' => "Rattachement au syndicat Multipros de l'UL : ne restez plus isolé·e et rejoignez la solidarité de tous les syndicats CGT de Foix et de la Haute-Ariège.",
'tpe_point_2' => "Confidentialité absolue : aucune prise de contact ni adhésion n'est portée à la connaissance de votre employeur sans votre accord.",
'tpe_point_3' => "Conseillers du Salarié : accompagnement gratuit et défense à vos côtés lors d'un entretien préalable à licenciement ou d'un litige.",
'tpe_btn_label' => "Contacter l'UL en toute confidentialité",
'tpe_btn_url' => home_url( '/contact/' ),
// Onglet 3 : Section 6 — Formation Syndicale (CFESES) & Appli Mobile (désactivée par défaut).
'cfeses_enabled' => 1,
'cfeses_eyebrow' => 'Droit individuel & vie militante',
'cfeses_title' => 'Formation Syndicale (CFESES)',
'cfeses_text' => "Tout·e salarié·e a droit au Congé de Formation Économique, Sociale, Environnementale et Syndicale : jusqu'à 12 jours par an avec maintien intégral de salaire. Remettez votre demande à l'employeur au moins 30 jours avant le stage.",
'cfeses_btn_label' => 'Demander une formation syndicale',
'cfeses_btn_url' => home_url( '/contact/' ),
'app_enabled' => 0,
'app_eyebrow' => 'Outil militant 100 % hors-ligne',
'app_title' => "L'Application Mobile UL CGT Foix Haute-Ariège",
'app_text' => 'Suivez les actualités locales, recevez les alertes mobilisation en temps réel et gardez votre carte de syndiqué virtuelle & vos 13 timbres toujours sur vous (Android / KMP).',
'app_btn_label' => "Télécharger l'application (.apk / Store)",
'app_download_url' => 'https://cgt-fha.fr/',
'app_qr_url' => CGT_FHA_URI . '/assets/img/qr-placeholder.svg',
// Onglet 3 : Section 7 — Réseau syndical CGT (5 cartes verticales).
'network_enabled' => 1,
'network_title' => 'RÉSEAU SYNDICAL CGT',
'network_1_enabled' => 1,
'network_1_logo' => CGT_FHA_URI . '/assets/img/logo-cgt-09.jpg',
'network_1_label' => 'UD CGT 09',
'network_1_desc' => "Union Départementale des syndicats CGT de l'Ariège : coordination départementale des luttes et solidarité interprofessionnelle.",
'network_1_btn' => 'Visiter le site ↗',
'network_1_url' => 'https://ariege.cgt.fr/',
'network_2_enabled' => 1,
'network_2_logo' => CGT_FHA_URI . '/assets/img/logo-cgt.png',
'network_2_label' => 'Confédération CGT',
'network_2_desc' => 'Site national de la CGT : actualités confédérales, campagnes interprofessionnelles, analyses et repères revendicatifs.',
'network_2_btn' => 'Visiter le site ↗',
'network_2_url' => 'https://www.cgt.fr/',
'network_3_enabled' => 1,
'network_3_logo' => CGT_FHA_URI . '/assets/img/logo-nvo.png',
'network_3_label' => 'La NVO',
'network_3_desc' => "La Nouvelle Vie Ouvrière : le média d'information sociale et syndicale de la CGT au service du monde du travail.",
'network_3_btn' => 'Visiter le site ↗',
'network_3_url' => 'https://www.nvo.fr/',
'network_4_enabled' => 1,
'network_4_logo' => CGT_FHA_URI . '/assets/img/logo-ihs.jpg',
'network_4_label' => 'IHS CGT',
'network_4_desc' => "Institut CGT d'Histoire Sociale : mémoire vivante des luttes sociales, archives et recherches sur le mouvement ouvrier.",
'network_4_btn' => 'Visiter le site ↗',
'network_4_url' => 'https://www.ihs.cgt.fr/',
'network_5_enabled' => 1,
'network_5_logo' => CGT_FHA_URI . '/assets/img/logo-indecosa.png',
'network_5_label' => 'INDECOSA-CGT',
'network_5_desc' => 'Association de la CGT pour l\'information et la défense des consommateurs salarié·e·s (logement, énergie, consommation).',
'network_5_btn' => 'Visiter le site ↗',
'network_5_url' => 'https://www.indecosa-cgt.fr/',
);
}
/**
* Retourne les options fusionnées avec les valeurs par défaut (mise en cache mémoire par requête).
*
* @param bool $fresh Force la relecture depuis la base de données.
* @return array<string, mixed>
*/
function cgt_fha_get_options( bool $fresh = false ): array {
static $cached = null;
if ( null !== $cached && ! $fresh ) {
return $cached;
}
$saved = get_option( CGT_FHA_OPTION_KEY, array() );
$saved = is_array( $saved ) ? $saved : array();
$merged = wp_parse_args( $saved, cgt_fha_get_defaults() );
$media_keys = array(
'hero_bg_url',
'header_logo_url',
'footer_logo_url',
'app_qr_url',
'network_1_logo',
'network_2_logo',
'network_3_logo',
'network_4_logo',
'network_5_logo',
);
// Garantit que les visuels critiques vidés par erreur retombent sur le défaut.
$defaults = cgt_fha_get_defaults();
foreach ( $media_keys as $media_key ) {
if ( empty( $merged[ $media_key ] ) ) {
$merged[ $media_key ] = $defaults[ $media_key ];
}
}
$cached = $merged;
return $cached;
}
/**
* Migration structurelle versionnée et non destructive des options du thème.
*
* Aucun hook (init, after_switch_theme, upgrader_process_complete) ne doit jamais
* écraser les personnalisations existantes enregistrées dans cgt_fha_options.
* Toutes les valeurs manquantes sont fournies dynamiquement via wp_parse_args()
* dans cgt_fha_get_options().
*/
add_action( 'init', 'cgt_fha_maybe_migrate_options', 5 );
function cgt_fha_maybe_migrate_options(): void {
$installed_version = (string) get_option( 'cgt_fha_schema_version', '' );
if ( CGT_FHA_SCHEMA_VERSION === $installed_version ) {
return;
}
$saved = get_option( CGT_FHA_OPTION_KEY, false );
if ( is_array( $saved ) && ! empty( $saved ) && '' !== $installed_version ) {
/**
* Table de correspondance réservée aux futures migrations structurelles
* (ex. 'ancienne_cle' => 'nouvelle_cle'). Ne modifie jamais une clé
* cible déjà personnalisée par l'utilisateur.
*
* @var array<string, string> $renamed_keys
*/
$renamed_keys = array();
$migrated = false;
foreach ( $renamed_keys as $old_key => $new_key ) {
if ( array_key_exists( $old_key, $saved ) && ! array_key_exists( $new_key, $saved ) ) {
$saved[ $new_key ] = $saved[ $old_key ];
$migrated = true;
}
}
if ( $migrated ) {
update_option( CGT_FHA_OPTION_KEY, $saved );
cgt_fha_get_options( true );
}
}
update_option( 'cgt_fha_schema_version', CGT_FHA_SCHEMA_VERSION, true );
}
/**
* Vérifie si le bandeau d'alerte mobilisation doit être affiché.
*/
function cgt_fha_is_banner_active(): bool {
$opts = cgt_fha_get_options();
if ( empty( $opts['banner_enabled'] ) || empty( $opts['banner_text'] ) || empty( $opts['banner_expires'] ) ) {
return false;
}
$tz = wp_timezone();
$expire_dt = DateTimeImmutable::createFromFormat( 'Y-m-d\TH:i', (string) $opts['banner_expires'], $tz );
if ( ! $expire_dt ) {
return false;
}
$now_ts = (int) current_time( 'timestamp' );
return $now_ts < $expire_dt->getTimestamp();
}
/**
* Enregistrement du réglage et de la page d'administration.
*/
add_action( 'admin_menu', 'cgt_fha_register_admin_page' );
function cgt_fha_register_admin_page(): void {
add_theme_page(
'Réglages UL CGT Foix Haute-Ariège',
'Réglages UL CGT',
'manage_options',
'cgt-fha-settings',
'cgt_fha_render_admin_page'
);
}
add_action( 'admin_init', 'cgt_fha_register_settings' );
function cgt_fha_register_settings(): void {
register_setting(
'cgt_fha_settings_group',
CGT_FHA_OPTION_KEY,
array(
'type' => 'array',
'sanitize_callback' => 'cgt_fha_sanitize_options',
'default' => cgt_fha_get_defaults(),
)
);
}
/**
* Remarque : aucun hook after_switch_theme n'écrit dans cgt_fha_options.
* Toutes les valeurs par défaut sont appliquées dynamiquement à la lecture
* via wp_parse_args() dans cgt_fha_get_options(), préservant 100 % des
* réglages enregistrés en base lors d'une réactivation ou mise à jour.
*/
/**
* Nettoyage et validation de toutes les options soumises dans l'admin.
*
* @param mixed $input Données brutes du formulaire.
* @return array<string, mixed>
*/
function cgt_fha_sanitize_options( $input ): array {
$input = is_array( $input ) ? $input : array();
$defaults = cgt_fha_get_defaults();
$existing = cgt_fha_get_options( true );
$is_form_submit = ! empty( $input['_form_submit'] );
$clean = array();
$text_fields = array(
'phone',
'address',
'footer_call',
'banner_text',
'hero_title_line1',
'hero_title_line2',
'hero_btn1_label',
'hero_btn2_label',
'missions_title',
'mission_1_title',
'mission_2_title',
'mission_3_title',
'local_news_title',
'local_news_more',
'confederal_title',
'tpe_badge',
'tpe_title',
'tpe_btn_label',
'cfeses_eyebrow',
'cfeses_title',
'cfeses_btn_label',
'app_eyebrow',
'app_title',
'app_btn_label',
'network_title',
'network_1_label',
'network_1_btn',
'network_2_label',
'network_2_btn',
'network_3_label',
'network_3_btn',
'network_4_label',
'network_4_btn',
'network_5_label',
'network_5_btn',
);
foreach ( $text_fields as $field ) {
$val = isset( $input[ $field ] ) ? sanitize_text_field( wp_unslash( (string) $input[ $field ] ) ) : ( $existing[ $field ] ?? $defaults[ $field ] );
$clean[ $field ] = $val;
}
$textarea_fields = array(
'hours',
'footer_desc',
'hero_quote',
'missions_subtitle',
'mission_1_text',
'mission_2_text',
'mission_3_text',
'tpe_text',
'tpe_point_1',
'tpe_point_2',
'tpe_point_3',
'cfeses_text',
'app_text',
'network_1_desc',
'network_2_desc',
'network_3_desc',
'network_4_desc',
'network_5_desc',
);
foreach ( $textarea_fields as $field ) {
$val = isset( $input[ $field ] ) ? sanitize_textarea_field( wp_unslash( (string) $input[ $field ] ) ) : ( $existing[ $field ] ?? $defaults[ $field ] );
$clean[ $field ] = $val;
}
$clean['email'] = isset( $input['email'] )
? sanitize_email( wp_unslash( (string) $input['email'] ) )
: (string) ( $existing['email'] ?? $defaults['email'] );
$url_fields = array(
'facebook_url',
'instagram_url',
'youtube_url',
'header_logo_url',
'footer_logo_url',
'news_url',
'calendar_url',
'contact_url',
'join_url',
'legal_url',
'banner_url',
'hero_bg_url',
'hero_btn1_url',
'hero_btn2_url',
'tpe_btn_url',
'cfeses_btn_url',
'app_download_url',
'app_qr_url',
'network_1_logo',
'network_1_url',
'network_2_logo',
'network_2_url',
'network_3_logo',
'network_3_url',
'network_4_logo',
'network_4_url',
'network_5_logo',
'network_5_url',
);
foreach ( $url_fields as $field ) {
$raw = isset( $input[ $field ] ) ? trim( (string) wp_unslash( $input[ $field ] ) ) : ( $existing[ $field ] ?? $defaults[ $field ] );
$clean[ $field ] = '' === $raw ? '' : esc_url_raw( $raw );
}
$checkbox_fields = array(
'banner_enabled',
'tpe_enabled',
'cfeses_enabled',
'app_enabled',
'network_enabled',
'network_1_enabled',
'network_2_enabled',
'network_3_enabled',
'network_4_enabled',
'network_5_enabled',
);
foreach ( $checkbox_fields as $field ) {
if ( $is_form_submit ) {
$clean[ $field ] = ! empty( $input[ $field ] ) ? 1 : 0;
} else {
$clean[ $field ] = array_key_exists( $field, $input )
? ( ! empty( $input[ $field ] ) ? 1 : 0 )
: (int) ( $existing[ $field ] ?? $defaults[ $field ] );
}
}
// Validation datetime-local (YYYY-MM-DDTHH:MM).
if ( isset( $input['banner_expires'] ) ) {
$raw_expires = sanitize_text_field( wp_unslash( (string) $input['banner_expires'] ) );
$clean['banner_expires'] = preg_match( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/', $raw_expires )
? $raw_expires
: (string) ( $existing['banner_expires'] ?? $defaults['banner_expires'] );
} else {
$clean['banner_expires'] = (string) ( $existing['banner_expires'] ?? $defaults['banner_expires'] );
}
// Validation des icônes de mission.
$valid_icons = array_keys( cgt_fha_get_mission_icon_choices() );
foreach ( array( 'mission_1_icon', 'mission_2_icon', 'mission_3_icon' ) as $icon_key ) {
if ( isset( $input[ $icon_key ] ) ) {
$chosen = sanitize_key( (string) $input[ $icon_key ] );
$clean[ $icon_key ] = in_array( $chosen, $valid_icons, true )
? $chosen
: (string) ( $existing[ $icon_key ] ?? $defaults[ $icon_key ] );
} else {
$clean[ $icon_key ] = (string) ( $existing[ $icon_key ] ?? $defaults[ $icon_key ] );
}
}
return $clean;
}
/**
* Liste des icônes disponibles dans le sélecteur admin des 3 cartes de mission.
*
* @return array<string, string>
*/
function cgt_fha_get_mission_icon_choices(): array {
return array(
'fist' => 'Poing levé / Collectif',
'shield' => 'Bouclier / Défense des droits',
'chat' => 'Bulles d\'échange / Information & Formation',
'megaphone' => 'Mégaphone / Mobilisation',
'scale' => 'Balance / Prud\'hommes & Juridique',
'users' => 'Collectif salarié·e·s',
'book' => 'Livre / Formation CFESES',
);
}
/**
* Helper d'affichage d'un champ texte/URL/textarea dans l'admin.
*/
function cgt_fha_admin_field_row( string $key, string $label, string $type = 'text', string $desc = '' ): void {
$opts = cgt_fha_get_options();
$val = $opts[ $key ] ?? '';
$id = 'cgt_fha_' . $key;
$name = CGT_FHA_OPTION_KEY . '[' . $key . ']';
?>
<tr>
<th scope="row"><label for="<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $label ); ?></label></th>
<td>
<?php if ( 'textarea' === $type ) : ?>
<textarea id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" rows="3" class="large-text"><?php echo esc_textarea( (string) $val ); ?></textarea>
<?php elseif ( 'checkbox' === $type ) : ?>
<label>
<input type="checkbox" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" value="1" <?php checked( ! empty( $val ) ); ?> />
<span><?php echo esc_html( $desc ); ?></span>
</label>
<?php else : ?>
<input type="<?php echo esc_attr( $type ); ?>" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( (string) $val ); ?>" class="<?php echo 'datetime-local' === $type ? 'regular-text' : 'large-text'; ?>" />
<?php endif; ?>
<?php if ( '' !== $desc && 'checkbox' !== $type ) : ?>
<p class="description"><?php echo esc_html( $desc ); ?></p>
<?php endif; ?>
</td>
</tr>
<?php
}
/**
* Helper d'affichage d'un sélecteur d'image via la Médiathèque WordPress.
*/
function cgt_fha_admin_media_row( string $key, string $label, string $default_url, string $desc = '', bool $dark_preview = false ): void {
$opts = cgt_fha_get_options();
$val = ! empty( $opts[ $key ] ) ? (string) $opts[ $key ] : $default_url;
$id = 'cgt_fha_' . $key;
$name = CGT_FHA_OPTION_KEY . '[' . $key . ']';
$preview_bg = $dark_preview ? '#1c1e21' : '#f8fafc';
?>
<tr>
<th scope="row"><label for="<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $label ); ?></label></th>
<td>
<div style="display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-bottom:10px;">
<input type="url" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_url( $val ); ?>" class="regular-text" />
<button type="button" class="button button-secondary" data-cgt-media-select="<?php echo esc_attr( $id ); ?>">Choisir dans la Médiathèque</button>
<button type="button" class="button" data-cgt-media-clear="<?php echo esc_attr( $id ); ?>" data-cgt-default-url="<?php echo esc_url( $default_url ); ?>">Rétablir par défaut</button>
</div>
<img id="<?php echo esc_attr( $id . '_preview' ); ?>" src="<?php echo esc_url( $val ); ?>" alt="" style="max-width:260px; max-height:110px; border:1px solid #cbd5e1; border-radius:6px; background:<?php echo esc_attr( $preview_bg ); ?>; padding:6px;" />
<?php if ( '' !== $desc ) : ?>
<p class="description"><?php echo esc_html( $desc ); ?></p>
<?php endif; ?>
</td>
</tr>
<?php
}
/**
* Rendu de la page d'administration Apparence > Réglages UL CGT.
*/
function cgt_fha_render_admin_page(): void {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$defaults = cgt_fha_get_defaults();
$opts = cgt_fha_get_options( true );
$active_tab = isset( $_GET['tab'] ) ? sanitize_key( (string) $_GET['tab'] ) : 'identity';
if ( ! in_array( $active_tab, array( 'identity', 'banner', 'homepage', 'confederal' ), true ) ) {
$active_tab = 'identity';
}
$feed_status = class_exists( 'CGT_FHA_Confederal_Feed' ) ? CGT_FHA_Confederal_Feed::get_cache_status() : array();
?>
<div class="wrap cgt-admin-wrap">
<h1 style="display:flex; align-items:center; gap:10px;">
<span style="display:inline-block; width:14px; height:14px; background:#d20012; border-radius:3px;"></span>
Réglages de l'Union Locale CGT Foix Haute-Ariège
</h1>
<p>Tous les textes, images, icônes, coordonnées et liens du thème sont modifiables ici sans toucher au code.</p>
<?php if ( isset( $_GET['cgt_feed_refreshed'] ) ) : ?>
<div class="notice notice-success is-dismissible">
<p><strong>Actualités confédérales (`cgt.fr`) synchronisées avec succès.</strong></p>
</div>
<?php endif; ?>
<?php settings_errors(); ?>
<nav class="nav-tab-wrapper" role="tablist" aria-label="Onglets de réglages UL CGT">
<a href="#identity" class="nav-tab <?php echo 'identity' === $active_tab ? 'nav-tab-active' : ''; ?>" data-cgt-tab="identity" role="tab" aria-selected="<?php echo 'identity' === $active_tab ? 'true' : 'false'; ?>">1. Identité &amp; Coordonnées</a>
<a href="#banner" class="nav-tab <?php echo 'banner' === $active_tab ? 'nav-tab-active' : ''; ?>" data-cgt-tab="banner" role="tab" aria-selected="<?php echo 'banner' === $active_tab ? 'true' : 'false'; ?>">2. Bandeau Mobilisation</a>
<a href="#homepage" class="nav-tab <?php echo 'homepage' === $active_tab ? 'nav-tab-active' : ''; ?>" data-cgt-tab="homepage" role="tab" aria-selected="<?php echo 'homepage' === $active_tab ? 'true' : 'false'; ?>">3. Page d'accueil &amp; Blocs</a>
<a href="#confederal" class="nav-tab <?php echo 'confederal' === $active_tab ? 'nav-tab-active' : ''; ?>" data-cgt-tab="confederal" role="tab" aria-selected="<?php echo 'confederal' === $active_tab ? 'true' : 'false'; ?>">4. Flux Confédéral (cgt.fr)</a>
</nav>
<form method="post" action="options.php" style="margin-top:20px;">
<?php settings_fields( 'cgt_fha_settings_group' ); ?>
<input type="hidden" name="<?php echo esc_attr( CGT_FHA_OPTION_KEY ); ?>[_form_submit]" value="1" />
<input type="hidden" name="cgt_fha_active_tab" value="<?php echo esc_attr( $active_tab ); ?>" />
<!-- ONGLET 1 : IDENTITÉ & COORDONNÉES -->
<div data-cgt-panel="identity" <?php echo 'identity' !== $active_tab ? 'hidden' : ''; ?>>
<h2>Coordonnées &amp; Identité visuelle</h2>
<table class="form-table" role="presentation">
<?php
cgt_fha_admin_media_row( 'header_logo_url', 'Logo En-tête', $defaults['header_logo_url'], 'Par défaut : bannière officielle Union Locale CGT Foix Haute-Ariège (assets/img/banniere-ul-noir.png).' );
cgt_fha_admin_media_row( 'footer_logo_url', 'Logo Pied de page (version blanche)', $defaults['footer_logo_url'], 'Affiché sur le fond sombre du pied de page (assets/img/banniere-ul-blanc.png par défaut).', true );
cgt_fha_admin_field_row( 'phone', 'Téléphone', 'text', 'Affiché dans la barre supérieure et le pied de page.' );
cgt_fha_admin_field_row( 'email', 'Adresse e-mail', 'email' );
cgt_fha_admin_field_row( 'address', 'Adresse des locaux', 'text' );
cgt_fha_admin_field_row( 'hours', 'Horaires des permanences', 'textarea' );
cgt_fha_admin_field_row( 'facebook_url', 'URL Page Facebook', 'url' );
cgt_fha_admin_field_row( 'instagram_url', 'URL Instagram (optionnel)', 'url' );
cgt_fha_admin_field_row( 'youtube_url', 'URL YouTube (optionnel)', 'url' );
cgt_fha_admin_field_row( 'footer_desc', 'Présentation pied de page', 'textarea' );
cgt_fha_admin_field_row( 'footer_call', 'Appel militant pied de page', 'text' );
?>
</table>
<h2>Pages clés de l'Union Locale</h2>
<table class="form-table" role="presentation">
<?php
cgt_fha_admin_field_row( 'news_url', 'URL page Actualités', 'url' );
cgt_fha_admin_field_row( 'calendar_url', 'URL page Calendrier', 'url' );
cgt_fha_admin_field_row( 'contact_url', "URL page Besoin d'aide / Contact", 'url' );
cgt_fha_admin_field_row( 'join_url', 'URL page Syndiquez-vous', 'url' );
cgt_fha_admin_field_row( 'legal_url', 'URL Mentions légales & Confidentialité', 'url' );
?>
</table>
<?php submit_button( 'Enregistrer les réglages' ); ?>
</div>
<!-- ONGLET 2 : BANDEAU MOBILISATION -->
<div data-cgt-panel="banner" <?php echo 'banner' !== $active_tab ? 'hidden' : ''; ?>>
<h2>Bandeau d'Alerte Mobilisation Auto-Expirant</h2>
<p class="description">
Le bandeau rouge CGT s'affiche uniquement si la case <strong>Activer le bandeau</strong> est cochée <strong>ET</strong> que l'heure actuelle du site
(<code><?php echo esc_html( current_time( 'd/m/Y H:i' ) ); ?></code>) est antérieure à la date d'expiration.
</p>
<table class="form-table" role="presentation">
<?php
cgt_fha_admin_field_row( 'banner_enabled', 'Activer le bandeau', 'checkbox', 'Afficher le bandeau rouge de mobilisation sous la barre supérieure.' );
cgt_fha_admin_field_row( 'banner_text', 'Mot d\'ordre & lieu', 'text', 'Exemple : MOBILISATION : Grève et manifestation à Foix - Allées de Villote' );
cgt_fha_admin_field_row( 'banner_url', 'Lien URL au clic (optionnel)', 'url', 'Laissez vide si le bandeau ne doit pas être cliquable.' );
cgt_fha_admin_field_row( 'banner_expires', 'Date et heure d\'expiration automatique', 'datetime-local', 'Passé cet horaire, le bandeau disparaît automatiquement.' );
?>
</table>
<?php submit_button( 'Enregistrer les réglages' ); ?>
</div>
<!-- ONGLET 3 : PAGE D'ACCUEIL -->
<div data-cgt-panel="homepage" <?php echo 'homepage' !== $active_tab ? 'hidden' : ''; ?>>
<h2>Section 1 — Bannière Hero Plein Écran</h2>
<table class="form-table" role="presentation">
<?php
cgt_fha_admin_media_row( 'hero_bg_url', 'Image panoramique de fond', $defaults['hero_bg_url'], 'Image sombre de montagne/Ariège recommandée (1600×720 px).' );
cgt_fha_admin_field_row( 'hero_title_line1', 'Titre H1 — Ligne 1', 'text' );
cgt_fha_admin_field_row( 'hero_title_line2', 'Titre H1 — Ligne 2', 'text' );
cgt_fha_admin_field_row( 'hero_quote', 'Citation sous le titre', 'textarea' );
cgt_fha_admin_field_row( 'hero_btn1_label', 'Bouton gauche — Libellé', 'text' );
cgt_fha_admin_field_row( 'hero_btn1_url', 'Bouton gauche — Lien URL', 'url' );
cgt_fha_admin_field_row( 'hero_btn2_label', 'Bouton droit — Libellé', 'text' );
cgt_fha_admin_field_row( 'hero_btn2_url', 'Bouton droit — Lien URL', 'url' );
?>
</table>
<hr />
<h2>Section 2 — « À QUOI NOUS SERVONS ? » (3 Cartes)</h2>
<table class="form-table" role="presentation">
<?php
cgt_fha_admin_field_row( 'missions_title', 'Titre de la section', 'text' );
cgt_fha_admin_field_row( 'missions_subtitle', 'Chapeau de présentation (Union des syndicats & Multipros)', 'textarea' );
$icon_choices = cgt_fha_get_mission_icon_choices();
for ( $i = 1; $i <= 3; $i++ ) :
$icon_key = 'mission_' . $i . '_icon';
$title_key = 'mission_' . $i . '_title';
$text_key = 'mission_' . $i . '_text';
?>
<tr>
<th scope="row"><label for="<?php echo esc_attr( 'cgt_fha_' . $icon_key ); ?>">Carte <?php echo (int) $i; ?> — Icône SVG</label></th>
<td>
<select id="<?php echo esc_attr( 'cgt_fha_' . $icon_key ); ?>" name="<?php echo esc_attr( CGT_FHA_OPTION_KEY . '[' . $icon_key . ']' ); ?>">
<?php foreach ( $icon_choices as $slug => $label ) : ?>
<option value="<?php echo esc_attr( $slug ); ?>" <?php selected( $opts[ $icon_key ], $slug ); ?>><?php echo esc_html( $label ); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php
cgt_fha_admin_field_row( $title_key, 'Carte ' . $i . ' — Titre', 'text' );
cgt_fha_admin_field_row( $text_key, 'Carte ' . $i . ' — Description', 'textarea' );
endfor;
?>
</table>
<hr />
<h2>Sections 3 &amp; 4 — Titres Actualités</h2>
<table class="form-table" role="presentation">
<?php
cgt_fha_admin_field_row( 'local_news_title', 'Titre Actualités locales', 'text' );
cgt_fha_admin_field_row( 'local_news_more', 'Libellé lien « Voir toutes... »', 'text' );
cgt_fha_admin_field_row( 'confederal_title', 'Titre Actualité confédérale', 'text' );
?>
</table>
<hr />
<h2>Section 5 — Salariés isolés &amp; TPE (Syndicat Multipros)</h2>
<table class="form-table" role="presentation">
<?php
cgt_fha_admin_field_row( 'tpe_enabled', 'Afficher ce bloc', 'checkbox', 'Afficher la section Salariés isolés & TPE sur la page d\'accueil.' );
cgt_fha_admin_field_row( 'tpe_badge', 'Surtitre / Badge', 'text' );
cgt_fha_admin_field_row( 'tpe_title', 'Titre du bloc', 'text' );
cgt_fha_admin_field_row( 'tpe_text', 'Paragraphe explicatif', 'textarea' );
cgt_fha_admin_field_row( 'tpe_point_1', 'Point clé 1 (Rattachement Multipros)', 'textarea' );
cgt_fha_admin_field_row( 'tpe_point_2', 'Point clé 2 (Confidentialité)', 'textarea' );
cgt_fha_admin_field_row( 'tpe_point_3', 'Point clé 3 (Conseillers du Salarié)', 'textarea' );
cgt_fha_admin_field_row( 'tpe_btn_label', 'Libellé du bouton', 'text' );
cgt_fha_admin_field_row( 'tpe_btn_url', 'Lien URL du bouton', 'url' );
?>
</table>
<hr />
<h2>Section 6 — Formation Syndicale (CFESES) &amp; Application Mobile</h2>
<table class="form-table" role="presentation">
<?php
cgt_fha_admin_field_row( 'cfeses_enabled', 'Afficher le bloc CFESES', 'checkbox', 'Afficher la colonne Formation Syndicale (CFESES).' );
cgt_fha_admin_field_row( 'cfeses_eyebrow', 'CFESES — Surtitre', 'text' );
cgt_fha_admin_field_row( 'cfeses_title', 'CFESES — Titre', 'text' );
cgt_fha_admin_field_row( 'cfeses_text', 'CFESES — Texte explicatif', 'textarea' );
cgt_fha_admin_field_row( 'cfeses_btn_label', 'CFESES — Libellé bouton', 'text' );
cgt_fha_admin_field_row( 'cfeses_btn_url', 'CFESES — Lien URL', 'url' );
cgt_fha_admin_field_row(
'app_enabled',
'Afficher le bloc Appli Mobile',
'checkbox',
'Désactivé par défaut tant que le contenu / fichier de téléchargement n\'est pas prêt. Cochez pour afficher ce bloc sur la page d\'accueil.'
);
cgt_fha_admin_field_row( 'app_eyebrow', 'Appli — Surtitre', 'text' );
cgt_fha_admin_field_row( 'app_title', 'Appli — Titre', 'text' );
cgt_fha_admin_field_row( 'app_text', 'Appli — Présentation', 'textarea' );
cgt_fha_admin_field_row( 'app_btn_label', 'Appli — Libellé bouton téléchargement', 'text' );
cgt_fha_admin_field_row( 'app_download_url', 'Appli — Lien direct (.apk / Play Store)', 'url' );
cgt_fha_admin_media_row( 'app_qr_url', 'Appli — Image QR Code', $defaults['app_qr_url'], 'Téléversez le QR Code pointant vers votre fichier .apk ou fiche Store.' );
?>
</table>
<hr />
<h2>Section 7 — Réseau Syndical CGT (Cartes avec logo, description et bouton)</h2>
<table class="form-table" role="presentation">
<?php
cgt_fha_admin_field_row( 'network_enabled', 'Afficher la section Réseau CGT', 'checkbox', 'Afficher la grille de cartes du réseau syndical CGT en bas de page d\'accueil.' );
cgt_fha_admin_field_row( 'network_title', 'Titre de la section', 'text' );
for ( $i = 1; $i <= 5; $i++ ) {
cgt_fha_admin_field_row( 'network_' . $i . '_enabled', 'Carte ' . $i . ' — Afficher', 'checkbox', 'Afficher cette carte dans le Réseau Syndical CGT.' );
cgt_fha_admin_media_row( 'network_' . $i . '_logo', 'Carte ' . $i . ' — Logo', $defaults[ 'network_' . $i . '_logo' ] );
cgt_fha_admin_field_row( 'network_' . $i . '_label', 'Carte ' . $i . ' — Titre', 'text' );
cgt_fha_admin_field_row( 'network_' . $i . '_desc', 'Carte ' . $i . ' — Description courte', 'textarea' );
cgt_fha_admin_field_row( 'network_' . $i . '_btn', 'Carte ' . $i . ' — Libellé bouton', 'text' );
cgt_fha_admin_field_row( 'network_' . $i . '_url', 'Carte ' . $i . ' — URL du site', 'url' );
}
?>
</table>
<?php submit_button( 'Enregistrer les réglages' ); ?>
</div>
</form>
<!-- ONGLET 4 : FLUX CONFÉDÉRAL (hors formulaire options.php pour le bouton POST dédié) -->
<div data-cgt-panel="confederal" <?php echo 'confederal' !== $active_tab ? 'hidden' : ''; ?> style="margin-top:20px;">
<h2>État du flux automatique « Actualité Confédérale » (`cgt.fr`)</h2>
<div class="card" style="max-width:760px; padding:16px 20px;">
<p>
<strong>Statut du cache :</strong>
<?php echo ! empty( $feed_status['has_transient'] ) ? '<span style="color:#0a7d2b;font-weight:700;">Actif (Transient valide)</span>' : '<span style="color:#b45309;font-weight:700;">Expiré ou en attente de synchronisation</span>'; ?>
</p>
<p>
<strong>Dernière synchronisation :</strong>
<?php echo ! empty( $feed_status['fetched_at'] ) ? esc_html( wp_date( 'd/m/Y à H:i:s', (int) $feed_status['fetched_at'] ) ) : 'Pas encore effectuée'; ?>
</p>
<p>
<strong>Source utilisée :</strong>
<?php echo esc_html( (string) ( $feed_status['source'] ?? 'Non définie' ) ); ?>
</p>
<?php if ( ! empty( $feed_status['featured']['title'] ) ) : ?>
<div style="margin:14px 0; padding:12px 14px; background:#f8fafc; border:1px solid #cbd5e1; border-radius:8px;">
<p style="margin:0 0 4px;"><strong>Article « À la une » en cache :</strong></p>
<p style="margin:0 0 4px; font-size:15px;"><strong><?php echo esc_html( $feed_status['featured']['title'] ); ?></strong></p>
<p style="margin:0; color:#4a5568;"><?php echo esc_html( $feed_status['featured']['summary'] ?? '' ); ?></p>
</div>
<?php endif; ?>
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
<input type="hidden" name="action" value="cgt_fha_refresh_feed" />
<?php wp_nonce_field( 'cgt_fha_refresh_feed_action', 'cgt_fha_refresh_feed_nonce' ); ?>
<button type="submit" class="button button-primary">Actualiser les actus confédérales maintenant</button>
</form>
</div>
</div>
</div>
<?php
}