is_registered( 'aieo/contact-form' ) ) { return; } $dir = AIEO_DIR . self::BLOCK_DIR; if ( is_readable( $dir . '/block.json' ) ) { register_block_type( $dir ); } } public static function register_elementor_widget( $widgets_manager ) { if ( ! is_object( $widgets_manager ) || ! method_exists( $widgets_manager, 'register' ) ) { return; } if ( ! class_exists( '\Elementor\Widget_Base' ) ) { return; } if ( ! class_exists( 'AIEO_Contact_Form_Elementor_Widget', false ) ) { $file = __DIR__ . '/class-aieo-contact-form-elementor-widget.php'; if ( ! is_readable( $file ) ) { return; } require_once $file; } if ( class_exists( 'AIEO_Contact_Form_Elementor_Widget', false ) ) { $widgets_manager->register( new AIEO_Contact_Form_Elementor_Widget() ); } } public static function shortcode( $atts = array() ) { $a = shortcode_atts( array( 'title' => '', 'intro' => '', 'company_label' => '', 'button' => '', 'fields' => '', 'required' => '', 'hide' => '', 'names' => '', 'rows' => '', 'class' => '', ), $atts, self::SHORTCODE ); return self::render( $a ); } public static function enqueue_assets() { if ( self::$enqueued ) { return; } self::$enqueued = true; $base = defined( 'AIEO_FILE' ) ? AIEO_FILE : __FILE__; $dir = defined( 'AIEO_DIR' ) ? AIEO_DIR : trailingslashit( dirname( __FILE__ ) ); $css_rel = 'assets/css/aieo-contact-form.css'; $js_rel = 'assets/js/aieo-contact-form.js'; $ver = defined( 'AIEO_VERSION' ) ? AIEO_VERSION : '1'; $css_ver = file_exists( $dir . $css_rel ) ? (string) filemtime( $dir . $css_rel ) : $ver; $js_ver = file_exists( $dir . $js_rel ) ? (string) filemtime( $dir . $js_rel ) : $ver; $deps = array( array(), array() ); if ( class_exists( 'AIEO_Form_Fields' ) ) { AIEO_Form_Fields::register_assets(); $deps = array( array( AIEO_Form_Fields::STYLE ), array( AIEO_Form_Fields::SCRIPT ) ); } wp_register_style( self::HANDLE, plugins_url( $css_rel, $base ), $deps[0], $css_ver ); self::$sheet = method_exists( 'AIEO_Form_Fields', 'style_here' ) ? AIEO_Form_Fields::style_here( self::HANDLE ) : ''; if ( ! method_exists( 'AIEO_Form_Fields', 'style_here' ) ) { wp_enqueue_style( self::HANDLE ); } wp_enqueue_script( self::HANDLE, plugins_url( $js_rel, $base ), $deps[1], $js_ver, true ); wp_localize_script( self::HANDLE, 'aieoContactForm', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'action' => AIEO_Contact_Form_Ajax::ACTION, 'minTime' => AIEO_Contact_Form_Ajax::MIN_SECONDS, 'i18n' => array( 'required' => self::refusal_words( 'first_name', 'missing' ), 'invalidEmail' => self::refusal_words( 'email', 'invalid' ), 'invalidPhone' => self::refusal_words( 'phone', 'invalid' ), 'consent' => self::refusal_words( 'consent', 'missing' ), 'sending' => __( 'Sending…', 'ai-eshop-optimizer' ), 'genericError' => __( 'Something went wrong. Please try again.', 'ai-eshop-optimizer' ), ), ) ); } public static function render( $args = array() ) { $args = wp_parse_args( $args, array( 'title' => '', 'intro' => '', 'company_label' => '', 'button' => '', 'fields' => '', 'required' => '', 'hide' => '', 'names' => '', 'rows' => 0, 'class' => '', ) ); if ( ! AIEO_Contact_Form_Settings::is_enabled() ) { return ''; } if ( ! AIEO_Contact_Form_Store::ready() ) { return ''; } $s = AIEO_Contact_Form_Settings::get(); $cfg = AIEO_Contact_Form_Settings::placement( $s, $args ); $fields = AIEO_Contact_Form_Settings::fields_from_config( $cfg ); $signed = AIEO_Contact_Form_Settings::sign( $cfg ); self::enqueue_assets(); self::$uid++; $uid = self::$uid; $id = 'aieo-cf-' . $uid; $title = '' !== trim( (string) $args['title'] ) ? (string) $args['title'] : (string) $s['form_title']; $intro = '' !== trim( (string) $args['intro'] ) ? (string) $args['intro'] : (string) $s['form_intro']; $button = '' !== trim( (string) $args['button'] ) ? (string) $args['button'] : (string) $s['button_text']; $labels = self::labels( $s, (string) $args['company_label'] ); $result = self::posted_result( $uid ); self::$errors = $result && 'error' === $result['state'] ? self::posted_errors( $fields, $s ) : array(); $box = array(); foreach ( self::$errors as $key => $message ) { $box[] = array( 'id' => $id . '-' . $key, 'text' => class_exists( 'AIEO_Form_Fields' ) ? AIEO_Form_Fields::box_text( 'consent' === $key ? '' : (string) ( $labels[ $key ] ?? '' ), $message ) : $message, ); } $extra_class = trim( preg_replace( '/[^A-Za-z0-9_\- ]+/', '', (string) $args['class'] ) ); ob_start(); echo self::$sheet; self::$sheet = ''; ?>

role="status" aria-live="polite" tabindex="-1" data-aieo-cf-status>
>
__( 'First name', 'ai-eshop-optimizer' ), 'last_name' => __( 'Last name', 'ai-eshop-optimizer' ), 'email' => __( 'Email', 'ai-eshop-optimizer' ), 'phone' => __( 'Phone', 'ai-eshop-optimizer' ), 'city' => __( 'City', 'ai-eshop-optimizer' ), 'country' => __( 'Country', 'ai-eshop-optimizer' ), 'company' => '' !== trim( (string) $company_override ) ? (string) $company_override : (string) $s['company_label'], 'message' => __( 'Message', 'ai-eshop-optimizer' ), ); } private static function consent_html( array $s ) { return class_exists( 'AIEO_Form_Fields' ) ? AIEO_Form_Fields::linked( (string) $s['consent_text'], (string) $s['consent_link_text'], self::privacy_url( $s ) ) : esc_html( (string) $s['consent_text'] ); } private static function privacy_html( array $s ) { $url = self::privacy_url( $s ); if ( ! class_exists( 'AIEO_Form_Fields' ) || '' === trim( $url ) ) { return ''; } return AIEO_Form_Fields::linked( (string) $s['privacy_text'], (string) $s['privacy_link_text'], $url ); } private static function privacy_url( array $s ) { return '' !== trim( (string) $s['consent_url'] ) ? (string) $s['consent_url'] : ( function_exists( 'get_privacy_policy_url' ) ? (string) get_privacy_policy_url() : '' ); } private static function posted_errors( array $fields, array $s ) { if ( ! class_exists( 'AIEO_Form_Fields' ) ) { return array(); } $bad = AIEO_Form_Fields::bad_from_query( 'aieo_cf_bad' ); $out = array(); foreach ( AIEO_Contact_Form_Settings::FIELDS as $key ) { if ( isset( $bad[ $key ] ) && ! empty( $fields[ $key ]['show'] ) ) { $out[ $key ] = self::refusal_words( $key, $bad[ $key ] ); } } if ( isset( $bad['consent'] ) && 'yes' === (string) $s['consent_enabled'] ) { $out['consent'] = self::refusal_words( 'consent', 'missing' ); } return $out; } private static function refusal_words( $key, $reason ) { if ( method_exists( 'AIEO_Contact_Form_Ajax', 'message' ) ) { return AIEO_Contact_Form_Ajax::message( $key, $reason ); } if ( 'consent' === $key ) { return __( 'Please accept the privacy policy to continue.', 'ai-eshop-optimizer' ); } if ( 'invalid' === $reason && 'email' === $key ) { return __( 'Please enter a valid email address.', 'ai-eshop-optimizer' ); } if ( 'invalid' === $reason && 'phone' === $key ) { return __( 'Please enter a phone number we can reach you on.', 'ai-eshop-optimizer' ); } return __( 'This field is required.', 'ai-eshop-optimizer' ); } private static function posted_result( $uid ) { if ( empty( $_GET['aieo_cf'] ) ) { return null; } $for = isset( $_GET['aieo_cf_form'] ) ? (int) $_GET['aieo_cf_form'] : 1; if ( $for !== (int) $uid ) { return null; } $code = sanitize_key( wp_unslash( (string) $_GET['aieo_cf'] ) ); if ( 'sent' === $code ) { $s = AIEO_Contact_Form_Settings::get(); return array( 'state' => 'success', 'message' => (string) $s['success_message'] ); } return array( 'state' => 'error', 'message' => AIEO_Contact_Form_Ajax::error_message( $code ) ); } public static function countries( $locale = '' ) { if ( ! function_exists( 'WC' ) ) { return array(); } $current = function_exists( 'determine_locale' ) ? determine_locale() : get_locale(); $locale = '' !== (string) $locale ? (string) $locale : $current; if ( isset( self::$countries[ $locale ] ) ) { return self::$countries[ $locale ]; } $switched = $locale !== $current && function_exists( 'switch_to_locale' ) && switch_to_locale( $locale ); try { $list = self::build_countries( $locale ); } finally { if ( $switched ) { restore_previous_locale(); } } self::$countries[ $locale ] = $list; return $list; } private static function build_countries( $locale ) { $list = array(); $file = method_exists( WC(), 'plugin_path' ) ? WC()->plugin_path() . '/i18n/countries.php' : ''; if ( '' !== $file && is_readable( $file ) ) { $list = (array) apply_filters( 'woocommerce_countries', include $file ); } elseif ( isset( WC()->countries ) && is_object( WC()->countries ) ) { $list = (array) WC()->countries->get_countries(); } $list = array_map( 'html_entity_decode', array_map( 'strval', $list ) ); if ( class_exists( 'Collator' ) ) { $coll = new Collator( $locale ); uasort( $list, static function ( $a, $b ) use ( $coll ) { return (int) $coll->compare( $a, $b ); } ); } else { uasort( $list, static function ( $a, $b ) { $a = function_exists( 'remove_accents' ) ? remove_accents( $a ) : $a; $b = function_exists( 'remove_accents' ) ? remove_accents( $b ) : $b; return strcasecmp( $a, $b ); } ); } return $list; } public static function default_country( array $s ) { $code = strtoupper( trim( (string) $s['default_country'] ) ); if ( '' === $code && function_exists( 'WC' ) && isset( WC()->countries ) && is_object( WC()->countries ) ) { $code = (string) WC()->countries->get_base_country(); } return $code; } public static function country_name( $code, $locale = '' ) { $code = (string) $code; if ( '' === $code ) { return ''; } $list = self::countries( $locale ); return isset( $list[ strtoupper( $code ) ] ) ? $list[ strtoupper( $code ) ] : $code; } private static function captcha_gate() { if ( ! class_exists( 'AIEO_Form_Captcha' ) ) { return ''; } $cls = AIEO_Form_Captcha::captcha_class(); if ( '' === $cls ) { return ''; } if ( class_exists( 'AIEO_Captcha_Keys' ) && method_exists( 'AIEO_Captcha_Keys', 'verified_for_enforcement' ) && ! AIEO_Captcha_Keys::verified_for_enforcement() ) { return ''; } return $cls; } private static function captcha_field() { $cls = self::captcha_gate(); if ( '' === $cls || ! method_exists( $cls, 'field' ) ) { return; } call_user_func( array( $cls, 'field' ), self::CAPTCHA_SURFACE ); } public static function captcha_check() { $cls = self::captcha_gate(); if ( '' === $cls || ! method_exists( $cls, 'verify' ) ) { return true; } return call_user_func( array( $cls, 'verify' ), self::CAPTCHA_SURFACE ); } } }