';
}
/**
* Genere les sections de donnees HTML.
*
* @param array $user_data Les donnees utilisateur.
*/
private function build_data_sections( array $user_data ): string {
$sections = $this->classify_user_data_sections( $user_data );
$content = '';
foreach ( $sections as $section_title => $section_data ) {
if ( ! empty( $section_data ) ) {
$content .= '
' . esc_html( $section_title ) . '
' . $this->format_data_items( $section_data ) . '
';
}
}
return $content;
}
/**
* Classe les donnees utilisateur en sections.
*
* @param array $user_data Les donnees brutes utilisateur.
*/
private function classify_user_data_sections( array $user_data ): array {
$sections = array(
/* translators: Section title in GDPR export */ __( 'Informations de base', 'advanced-pdf-invoice-builder' ) => array(),
/* translators: Section title in GDPR export */ __( 'Métadonnées utilisateur', 'advanced-pdf-invoice-builder' ) => array(),
/* translators: Section title in GDPR export */ __( 'Préférences et paramètres', 'advanced-pdf-invoice-builder' ) => array(),
/* translators: Section title in GDPR export */ __( 'Historique et activité', 'advanced-pdf-invoice-builder' ) => array(),
/* translators: Section title in GDPR export */ __( 'Données RGPD', 'advanced-pdf-invoice-builder' ) => array(),
/* translators: Section title in GDPR export */ __( 'Autre', 'advanced-pdf-invoice-builder' ) => array(),
);
foreach ( $user_data as $key => $value ) {
if ( strpos( $key, 'user_' ) === 0 || in_array( $key, array( 'ID', 'user_login', 'user_email', 'display_name' ), true ) ) {
$sections['Informations de base'][ $key ] = $value;
} elseif ( strpos( $key, 'meta_' ) === 0 || strpos( $key, 'wp_' ) === 0 ) {
$sections['Métadonnées utilisateur'][ $key ] = $value;
} elseif ( strpos( $key, 'pref' ) === 0 || strpos( $key, 'setting' ) === 0 || strpos( $key, 'option' ) === 0 ) {
$sections['Préférences et paramètres'][ $key ] = $value;
} elseif ( strpos( $key, 'consent' ) !== false || strpos( $key, 'gdpr' ) !== false ) {
$sections['Données RGPD'][ $key ] = $value;
} elseif ( strpos( $key, 'last_' ) === 0 || strpos( $key, 'date' ) !== false || strpos( $key, 'time' ) !== false ) {
$sections['Historique et activité'][ $key ] = $value;
} else {
$sections['Autre'][ $key ] = $value;
}
}
return $sections;
}
/**
* Génère les éléments HTML data-item pour un tableau de données.
* Extracted complex items to format_complex_item() to keep cognitive complexity ≤ 15.
*
* @param array $data Les donnees a formater.
*/
private function format_data_items( array $data ): string {
$result = '';
foreach ( $data as $key => $value ) {
$display_key = ucfirst( str_replace( array( '_', '-' ), ' ', $key ) );
if ( is_array( $value ) || is_object( $value ) ) {
$result .= $this->format_complex_item( $display_key, $value );
} else {
$result .= '
' . esc_html( $display_key ) . '
' . esc_html( $value ) . '
';
}
}
return $result;
}
/**
* Formate un element de donnee complexe (tableau/objet) en HTML.
*
* @param string $display_key Cle affichee.
* @param mixed $value Valeur complexe.
*/
private function format_complex_item( string $display_key, mixed $value ): string {
if ( empty( $value ) ) {
return '
' . esc_html( $display_key ) . '
' . esc_html__( '(Aucune donnée)', 'advanced-pdf-invoice-builder' ) . '
';
}
if ( is_object( $value ) ) {
$value = (array) $value;
}
$sub = '';
foreach ( $value as $sub_key => $sub_value ) {
$sub_display = ucfirst( str_replace( array( '_', '-' ), ' ', $sub_key ) );
$sub_val = ( is_array( $sub_value ) || is_object( $sub_value ) ) ? esc_html__( '(Données complexes)', 'advanced-pdf-invoice-builder' ) : esc_html( $sub_value );
$sub .= '
' . esc_html( $sub_display ) . '' . $sub_val . '
';
}
return '
' . esc_html( $display_key ) . '
' . $sub . '
';
}
/**
* Genere le pied de page HTML du document d export.
*/
private function build_footer(): string {
return '