$w ) { if ( '' === trim( $w ) || '-' === $w ) { continue; } $lower = mb_strtolower( $w, 'UTF-8' ); if ( $i > 0 && in_array( $lower, $particles, true ) ) { $words[ $i ] = $lower; } elseif ( mb_strlen( $w, 'UTF-8' ) <= 2 && ! in_array( $lower, $particles, true ) ) { $words[ $i ] = $w; // Initials and acronyms. } else { $words[ $i ] = mb_convert_case( $lower, MB_CASE_TITLE, 'UTF-8' ); } } return implode( '', $words ); } public static function statuses() { /** * Filter contact statuses. * * @param array $statuses slug => label. */ return apply_filters( 'nodebook_statuses', array( 'subscriber' => __( 'Subscriber', 'nodebook' ), 'lead' => __( 'Lead', 'nodebook' ), 'prospect' => __( 'Prospect', 'nodebook' ), 'customer' => __( 'Customer', 'nodebook' ), 'inactive' => __( 'Inactive', 'nodebook' ), ) ); } /** * Contact properties. type: text|email|tel|url|select|textarea|number|money|date. * readonly fields are calculated by the plugin. */ public static function contact() { $f = array( 'email' => array( 'label' => __( 'Email', 'nodebook' ), 'type' => 'email' ), 'first_name' => array( 'label' => __( 'First name', 'nodebook' ), 'type' => 'text' ), 'last_name' => array( 'label' => __( 'Last name', 'nodebook' ), 'type' => 'text' ), 'phone' => array( 'label' => __( 'Phone', 'nodebook' ), 'type' => 'tel' ), 'company' => array( 'label' => __( 'Company', 'nodebook' ), 'type' => 'company' ), 'job_title' => array( 'label' => __( 'Job title', 'nodebook' ), 'type' => 'text' ), 'status' => array( 'label' => __( 'Status', 'nodebook' ), 'type' => 'select', 'options' => self::statuses() ), 'source' => array( 'label' => __( 'Captured via', 'nodebook' ), 'type' => 'text' ), 'website' => array( 'label' => __( 'Website', 'nodebook' ), 'type' => 'url' ), 'address' => array( 'label' => __( 'Address', 'nodebook' ), 'type' => 'text' ), 'city' => array( 'label' => __( 'City', 'nodebook' ), 'type' => 'text' ), 'state' => array( 'label' => __( 'State / region', 'nodebook' ), 'type' => 'text' ), 'postcode' => array( 'label' => __( 'Postcode', 'nodebook' ), 'type' => 'text' ), 'country' => array( 'label' => __( 'Country', 'nodebook' ), 'type' => 'text' ), 'description' => array( 'label' => __( 'Description', 'nodebook' ), 'type' => 'textarea' ), 'first_source' => array( 'label' => __( 'First-touch source', 'nodebook' ), 'type' => 'text', 'group' => 'journey' ), 'first_medium' => array( 'label' => __( 'First-touch medium', 'nodebook' ), 'type' => 'text', 'group' => 'journey' ), 'first_campaign' => array( 'label' => __( 'First-touch campaign', 'nodebook' ), 'type' => 'text', 'group' => 'journey' ), 'first_referrer' => array( 'label' => __( 'Referring page', 'nodebook' ), 'type' => 'text', 'group' => 'journey' ), 'landing_page' => array( 'label' => __( 'Landing page', 'nodebook' ), 'type' => 'text', 'group' => 'journey' ), 'first_touch_at' => array( 'label' => __( 'First touch', 'nodebook' ), 'type' => 'date', 'readonly' => true ), 'last_intent_at' => array( 'label' => __( 'Last high-intent view', 'nodebook' ), 'type' => 'date', 'readonly' => true ), 'orders_count' => array( 'label' => __( 'Orders', 'nodebook' ), 'type' => 'number', 'readonly' => true ), 'total_spent' => array( 'label' => __( 'Total spent', 'nodebook' ), 'type' => 'money', 'readonly' => true ), 'visits_count' => array( 'label' => __( 'Visits', 'nodebook' ), 'type' => 'number', 'readonly' => true ), 'first_seen' => array( 'label' => __( 'First seen', 'nodebook' ), 'type' => 'date', 'readonly' => true ), 'last_seen' => array( 'label' => __( 'Last seen', 'nodebook' ), 'type' => 'date', 'readonly' => true ), 'created_at' => array( 'label' => __( 'Created', 'nodebook' ), 'type' => 'date', 'readonly' => true ), ); /** * Filter contact fields (labels/types). Built-in columns only; your own fields are in Nodebook_Props. */ return apply_filters( 'nodebook_contact_fields', Nodebook_Props::apply_builtin( 'contact', $f ) ); } public static function company() { return apply_filters( 'nodebook_company_fields', Nodebook_Props::apply_builtin( 'company', array( 'name' => array( 'label' => __( 'Name', 'nodebook' ), 'type' => 'text' ), 'domain' => array( 'label' => __( 'Domain', 'nodebook' ), 'type' => 'text' ), 'website' => array( 'label' => __( 'Website', 'nodebook' ), 'type' => 'url' ), 'phone' => array( 'label' => __( 'Phone', 'nodebook' ), 'type' => 'tel' ), 'industry' => array( 'label' => __( 'Industry', 'nodebook' ), 'type' => 'text' ), 'size' => array( 'label' => __( 'Company size', 'nodebook' ), 'type' => 'text' ), 'address' => array( 'label' => __( 'Address', 'nodebook' ), 'type' => 'text' ), 'city' => array( 'label' => __( 'City', 'nodebook' ), 'type' => 'text' ), 'state' => array( 'label' => __( 'State / region', 'nodebook' ), 'type' => 'text' ), 'postcode' => array( 'label' => __( 'Postcode', 'nodebook' ), 'type' => 'text' ), 'country' => array( 'label' => __( 'Country', 'nodebook' ), 'type' => 'text' ), 'description' => array( 'label' => __( 'Description', 'nodebook' ), 'type' => 'textarea' ), 'created_at' => array( 'label' => __( 'Created', 'nodebook' ), 'type' => 'date', 'readonly' => true ), ) ) ); } /** Column length limits (match the schema). */ public static function max_length( $key ) { $map = array( 'email' => 190, 'first_name' => 100, 'last_name' => 100, 'phone' => 50, 'job_title' => 150, 'source' => 150, 'website' => 255, 'first_source' => 100, 'first_medium' => 100, 'first_campaign' => 150, 'first_referrer' => 255, 'landing_page' => 255, 'address' => 255, 'city' => 100, 'state' => 100, 'postcode' => 20, 'country' => 100, 'name' => 190, 'domain' => 190, 'industry' => 100, 'size' => 50, ); return isset( $map[ $key ] ) ? $map[ $key ] : 0; } /** * Sanitize one value for a field definition. */ public static function clean( $key, $value, array $def ) { if ( is_array( $value ) ) { $value = implode( ', ', array_map( 'strval', array_filter( $value, 'is_scalar' ) ) ); } $value = (string) $value; switch ( $def['type'] ) { case 'email': $value = strtolower( sanitize_email( $value ) ); break; case 'url': $value = trim( $value ); if ( $value && ! preg_match( '#^https?://#i', $value ) ) { $value = 'https://' . $value; } $value = esc_url_raw( $value ); break; case 'textarea': $value = sanitize_textarea_field( $value ); break; case 'select': $value = sanitize_key( $value ); if ( ! isset( $def['options'][ $value ] ) ) { $value = ''; } break; case 'number': $value = (string) absint( $value ); break; case 'money': $value = (string) (float) preg_replace( '/[^0-9.\-]/', '', str_replace( ',', '.', $value ) ); break; default: $value = sanitize_text_field( $value ); } $max = self::max_length( $key ); if ( $max && function_exists( 'mb_substr' ) ) { $value = mb_substr( $value, 0, $max ); } elseif ( $max ) { $value = substr( $value, 0, $max ); } return $value; } /** * Guess which contact field a form label/key/type belongs to. Returns '' for "custom field", * 'message' for free text, 'name' for full name, 'skip' for things never stored. */ public static function guess( $label, $key = '', $type = '' ) { $type = strtolower( (string) $type ); $s = strtolower( trim( $label . ' ' . $key ) ); $s = str_replace( array( '_', '-', '[', ']' ), ' ', $s ); if ( in_array( $type, array( 'password', 'file', 'fileupload', 'file-upload', 'upload', 'captcha', 'recaptcha', 'hcaptcha', 'turnstile', 'html', 'divider', 'section', 'pagebreak', 'page', 'submit', 'signature', 'honeypot' ), true ) ) { return 'skip'; } if ( preg_match( '/pass(word)?|captcha|token|nonce|honeypot|credit|card number|cvc|cvv|iban/', $s ) ) { return 'skip'; } if ( 'email' === $type || preg_match( '/e ?mail|correo/', $s ) ) { return 'email'; } if ( preg_match( '/first ?name|fname|given|voornaam|vorname|pr[eé]nom/', $s ) ) { return 'first_name'; } if ( preg_match( '/last ?name|lname|surname|family|achternaam|nachname|apellido|nom de famille/', $s ) ) { return 'last_name'; } if ( in_array( $type, array( 'tel', 'phone' ), true ) || preg_match( '/phone|\btel\b|mobile|cell|whats ?app|telefoon|tel[eé]fono|handy/', $s ) ) { return 'phone'; } if ( preg_match( '/company|organi[sz]ation|business|bedrijf|empresa|firma|soci[eé]t[eé]/', $s ) ) { return 'company'; } if ( preg_match( '/job ?title|position|functie|cargo|\brole\b/', $s ) ) { return 'job_title'; } if ( 'url' === $type || preg_match( '/website|\burl\b|web ?site|webpagina/', $s ) ) { return 'website'; } if ( preg_match( '/\bcity\b|town|\bstad\b|ciudad|\bort\b|ville/', $s ) ) { return 'city'; } if ( preg_match( '/zip|postal|post ?code|plz/', $s ) ) { return 'postcode'; } if ( preg_match( '/country|\bland\b|pa[ií]s|pays/', $s ) ) { return 'country'; } if ( preg_match( '/\bstate\b|province|region|provincie/', $s ) ) { return 'state'; } if ( preg_match( '/address|street|adres|direcci[oó]n|stra(ss|ß)e/', $s ) ) { return 'address'; } $is_name = static function ( $v ) { return (bool) preg_match( '/^(your |full |je |uw |tu )?(name|naam|nombre|nom)$|full ?name|your ?name/', trim( str_replace( array( '_', '-', '[', ']', '*', ':' ), ' ', strtolower( (string) $v ) ) ) ); }; if ( 'name' === $type || $is_name( $s ) || $is_name( $label ) || ( '' === trim( (string) $label ) && $is_name( $key ) ) ) { return 'name'; } if ( 'textarea' === $type || preg_match( '/message|comment|bericht|mensaje|enquiry|inquiry|question|vraag|nachricht/', $s ) ) { return 'message'; } return ''; } }