$fields * @param list $keys */ function adv_click_ingest_first_filled(array $fields, array $keys): ?string { foreach ($keys as $key) { if (!array_key_exists($key, $fields)) { continue; } $value = trim((string) $fields[$key]); if ($value !== '' && !adv_click_ingest_is_placeholder($value)) { return $value; } } return null; } function adv_click_ingest_is_placeholder(string $value): bool { $raw = strtolower(trim($value)); return in_array($raw, [ '', '-', '--', '---', '.', 'n/a', 'na', 'n.a.', 'n.a', 'sconosciuto', 'unknown', 'none', 'null', 'undefined', 'anonimo', 'anonymous', ], true); } /** * @param array $fields * @return array */ function adv_click_ingest_map_contact_fields(array $fields): array { $nome = adv_click_ingest_first_filled($fields, [ 'your-name', 'nome', 'first_name', 'firstname', 'first-name', 'name', 'nome-cognome', 'nome_cognome', 'full_name', 'fullname', 'nome_completo', ]); $cognome = adv_click_ingest_first_filled($fields, [ 'your-cognome', 'cognome', 'last_name', 'lastname', 'last-name', 'surname', 'family_name', ]); $email = adv_click_ingest_first_filled($fields, [ 'your-email', 'email', 'e-mail', 'e_mail', 'email_address', 'mail', 'indirizzo_email', ]); $telefono = adv_click_ingest_first_filled($fields, [ 'your-tel', 'your-telephone', 'your-phone', 'telefono', 'phone', 'telephone', 'tel', 'cellulare', 'mobile', 'cell', 'phone_number', ]); $messaggio = adv_click_ingest_first_filled($fields, [ 'your-message', 'messaggio', 'message', 'note', 'notes', 'comment', 'comments', ]); $azienda = adv_click_ingest_first_filled($fields, [ 'azienda', 'company', 'company_name', 'ragione_sociale', 'business_name', 'organization', ]); $fullNameKeys = ['nome-cognome', 'nome_cognome', 'full_name', 'fullname', 'nome_completo', 'name']; $fromFullName = $nome !== null && $cognome === null && adv_click_ingest_first_filled($fields, $fullNameKeys) === $nome; if ($fromFullName && str_contains($nome, ' ')) { $parts = preg_split('/\s+/', $nome, 2) ?: []; if (count($parts) === 2) { $nome = $parts[0]; $cognome = $parts[1]; } } $mapped = array_filter([ 'nome' => $nome, 'cognome' => $cognome, 'email' => $email, 'telefono' => $telefono, 'messaggio' => $messaggio, 'azienda' => $azienda, ], static fn ($v) => $v !== null && $v !== ''); return adv_click_ingest_infer_missing_contact_fields($fields, $mapped); } /** * @param array $fields * @param array $mapped * @return array */ function adv_click_ingest_infer_missing_contact_fields(array $fields, array $mapped): array { $skip = [ 'honeypot_field_name', 'acceptance_privacy', 'tipo_form', 'tipo_richiesta', 'richiesta', 'richiesta_url', 'adv_crm_conversion_url', 'landing_url', 'last_page_url', 'funnel_url', 'visited_pages', 'session_guid', 'visitor_ip', 'slug_crm', 'form_plugin', 'site_host', 'web', 'social', 'google', 'cf7_honeypot_timestamp', ]; foreach ($fields as $key => $value) { $value = trim((string) $value); if ($value === '' || adv_click_ingest_is_placeholder($value)) { continue; } $lookup = strtolower((string) $key); if ( in_array($lookup, $skip, true) || str_starts_with($lookup, 'honeypot') || str_contains($lookup, 'timestamp') || str_contains($lookup, 'url') || str_starts_with($lookup, '_') ) { continue; } if (!isset($mapped['email']) && filter_var($value, FILTER_VALIDATE_EMAIL)) { $mapped['email'] = $value; continue; } if (!isset($mapped['telefono'])) { $digits = preg_replace('/\D+/', '', $value) ?? ''; $len = strlen($digits); if ($len >= 6 && $len <= 15 && !($len === 10 && str_starts_with($digits, '1'))) { $mapped['telefono'] = $value; } } } return $mapped; }