{$name}" ); } /** * @param array $data * @return bool|array */ public static function sanitize_data( &$data ) { $_method = __METHOD__; $_data = print_r( $data, true ); wp_die( "Method {$_method} is not implemented. Data:\n
{$_data}
" ); return true; } public static function get_fields() { $_method = __METHOD__; wp_die( "Method {$_method} is not implemented." ); return []; } public static function get_filter_fields() { return static::get_fields(); } public static function filter_data( &$data ) { $fields = static::get_filter_fields(); $filtered = []; foreach ( array_keys( $fields ) as $field ) { $filtered[$field] = fqp_array_get( $data, $field ); } $data = $filtered; } public static function render_element( $name, array $specs ) { if ( ! array_key_exists( 'type', $specs ) ) { wp_die( "Element type is not defined!"); } $method = "render_{$specs['type']}"; if ( ! method_exists( __CLASS__, $method ) ) { wp_die( "Unknown element type '{$specs['type']}'!" ); } if ( empty( $specs['name'] ) ) { $specs['name'] = $name; } if ( empty( $specs['attribs']['name'] ) ) { $specs['attribs']['name'] = $name; } if ( empty( $specs['attribs']['id'] ) ) { $specs['attribs']['id'] = static::get_html_id( $name ); } return static::{$method}( $specs ); } protected static function render_input( array $specs ) { $label = static::render_label( $specs ); $description = static::render_info_button( @$specs['description'] ); $specs['attribs']['type'] = $specs['type']; $specs['attribs']['value'] = @$specs['value']; if ( empty( $specs['attribs']['maxlength'] ) ) { $specs['attribs']['maxlength'] = 255; } else { $specs['attribs']['maxlength'] = intval( $specs['attribs']['maxlength'] ); if ( !$specs['attribs']['maxlength'] || $specs['attribs']['maxlength'] > 255 ) { $specs['attribs']['maxlength'] = 255; } } if ( ! empty( $specs['attribs']['value'] ) ) { if ( ! array_key_exists( 'class', $specs['attribs'] ) ) { $specs['attribs']['class'] = ''; } $specs['attribs']['class'] = trim( $specs['attribs']['class'] . ' filled' ); } $attribs = static::render_attribs( $specs['attribs'] ); $data_placeholder = ''; if ( @$specs['attribs']['data-placeholder'] ) { $data_placeholder = esc_html( $specs['attribs']['data-placeholder'] ); $placeholder_attribs = ''; if ($specs['attribs']['value']) { $placeholder_attribs = static::render_attribs( [ 'style' => 'display:none;' ] ); } $data_placeholder = "{$data_placeholder}"; } return "{$label}{$data_placeholder}{$description}"; } protected static function render_hidden( array $specs ) { return self::render_input( $specs ); } protected static function render_text( array $specs ) { return self::render_input( $specs ); } protected static function render_number( array $specs ) { return self::render_input( $specs ); } protected static function render_email( array $specs ) { return self::render_input( $specs ); } protected static function render_date( array $specs ) { $specs['type'] = 'text'; $specs['attribs']['class'] = trim( @$specs['attribs']['class'] . ' datepicker' ); return str_replace( '', '', self::render_input( $specs ) ); } protected static function render_phone( array $specs ) { return self::render_input( $specs ); } protected static function render_textarea( array $specs ) { $label = static::render_label( $specs ); $value = fqp_esc_html__( @$specs['value'] ); if ( $value ) { if ( ! array_key_exists( 'class', $specs['attribs'] ) ) { $specs['attribs']['class'] = ''; } $specs['attribs']['class'] = trim( $specs['attribs']['class'] . ' filled' ); } $attribs = static::render_attribs( $specs['attribs'] ); $description = static::render_info_button( @$specs['description'] ); return "{$label}{$description}"; } protected static function render_radio( array $specs ) { $html = ''; $attribs = $specs['attribs']; $id_prefix = "{$attribs['id']}-"; foreach ( $specs['multi_options'] as $value => $label ) { $_attribs = $attribs; $_attribs['value'] = $value; $_attribs['checked'] = ( $value == @$specs['value'] ); $_attribs['id'] = $id_prefix . static::get_html_id( $value ); if ( ! empty( $specs['input_attribs'] ) && ! empty( $specs['input_attribs'][$value] ) ) { $_attribs = array_merge( $_attribs, $specs['input_attribs'][$value] ); } $id = esc_attr( $_attribs['id'] ); if ( ! array_key_exists( 'escape_options', $specs ) || $specs['escape_options'] ) { $label = fqp_esc_html__( $label ); } $rendered_attribs = static::render_attribs( $_attribs ); $html .= ""; } return $html; } protected static function render_checkbox( array $specs ) { if ( ! array_key_exists( 'value' , $specs['attribs'] ) ) { $specs['attribs']['value'] = 'y'; } if ( $specs['attribs']['value'] == @$specs['value'] ) { $specs['attribs']['checked'] = true; } $id = fqp_esc_attr__( $specs['attribs']['id'] ); if ( array_key_exists( 'escape_label', $specs ) && false === $specs['escape_label'] ) { $label = @$specs['label']; } else { $label = fqp_esc_html__( @$specs['label'] ); } $rendered_attribs = static::render_attribs( $specs['attribs'] ); $description = static::render_info_button( @$specs['description'] ); return ""; } protected static function render_select( array $specs ) { $label = static::render_label( $specs ); $attribs = static::render_attribs( $specs['attribs'] ); $options = static::render_options( $specs ); $description = static::render_info_button( @$specs['description'] ); return "{$label}{$description}"; } protected static function render_button( array $specs ) { $attribs = static::render_attribs( $specs['attribs'] ); if ( array_key_exists('escape_label', $specs) && false === $specs['escape_label'] ) { $label = $specs['label']; } else { $label = fqp_esc_html__( $specs['label'] ); } return ""; } protected static function prepare_attribs( array &$attribs ) { array_walk( $attribs, function ( &$value ) { $value = esc_attr( $value ); } ); } public static function get_html_id( $element_name ) { return sanitize_html_id( $element_name ); } protected static function render_attribs( array $attribs ) { static::prepare_attribs( $attribs ); if ( static::$add_tab_index && ! array_key_exists( 'tabindex', $attribs ) ) { $attribs['tabindex'] = static::$tab_index++; } $_attribs = []; foreach ( $attribs as $name => $value ) { $name = trim( $name ); $value = trim( $value ); if ( in_array( $name, [ 'required', 'checked' ] ) ) { if ( $value ) { $_attribs[] = esc_attr( $name ); } } else { $name = esc_attr( $name ); $value = fqp_esc_attr__( $value); $_attribs[] = "{$name}=\"{$value}\""; } } return implode( ' ', $_attribs ); } protected static function render_info_button( $msg ) { $html = ''; if ( $msg ) { $html = 'i'; } return $html; } protected static function render_label( array $specs ) { $html = ''; if ( ! empty( $specs['label'] ) ) { if ( array_key_exists('escape_label', $specs) && false === $specs['escape_label'] ) { $label = $specs['label']; } else { $label = fqp_esc_html__( $specs['label'] ); } $id = fqp_esc_attr__( @$specs['attribs']['id'] ); $html = ""; } return $html; } protected static function render_options( array $specs ) { $options = ''; if ( !empty( $specs['multi_options'] ) && is_array( $specs['multi_options'] ) ) { $_value = @$specs['attribs']['value']; foreach ( $specs['multi_options'] as $value => $title ) { if ( is_array( $title ) ) { $options .= static::render_optgroup( $value, $title, $_value ); } else { $options .= static::render_option( $value, $title, $_value ); } } } return $options; } protected static function render_optgroup( $title, $values, $current) { $attribs = [ 'label' => $title ]; $attribs = static::render_attribs( $attribs ); $optgroup = ""; foreach ( $values as $value => $title ) { $optgroup .= static::render_option( $value, $title, $_value ); } $optgroup .= ''; return $optgroup; } protected static function render_option( $value, $title, $current = null ) { $attribs = ['value' => $value]; if ( $value == $current ) { $attribs['selected'] = 'selected'; } $attribs = static::render_attribs( $attribs ); $title = fqp_esc_html__( $title ); return ""; } public static function get_function_in_company_description() { if ( FQP::ENTRY_TYPE_AG == static::$entry_type ) { return 'EN In der AG müssen Sie nicht zwingend jemanden als Geschäftsführerin bzw. Geschäftsführer im Handelsregister eintragen lassen. Wenn ein Unternehmen ausschliesslich Verwaltungsratsmitglieder eingetragen hat, so gelten diese Personen automatisch auch als Geschäftsführer. Ist aber eine Person nur für die Geschäftsführung tätig, so ist es durchaus sinnvoll, dies auch im Handelsregister eintragen zu lassen.'; } elseif ( FQP::ENTRY_TYPE_LTD == static::$entry_type ) { if ( FQP::BACKING_TYPE_CASH == static::$backing_type ) { return 'EN Die GmbH benötigt zwingend einen Geschäftsführer. Soll die Geschäftsführung mehrere Personen übertragen werden, so muss zwingend eine Person den «Vorsitz der Geschäftsführung» übernehmen.'; } elseif ( FQP::BACKING_TYPE_GOODS == static::$backing_type ) { return 'EN Die GmbH benötigt zwingend eine Geschäftsführerin bzw. einen Geschäftsführer. Soll die Geschäftsführung mehrere Personen übertragen werden, so muss zwingend eine Person den «Vorsitz der Geschäftsführung» übernehmen.'; } } return ''; } }