{$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['value'] = $value; $attribs['checked'] = ( $value == @$specs['value'] ); $attribs['id'] = $id_prefix . static::get_html_id( $value ); $id = esc_attr( $attribs['id'] ); $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 ) { $attribs = ['value' => $value]; if ( $value == $_value ) { $attribs['selected'] = 'selected'; } $attribs = static::render_attribs( $attribs ); $title = fqp_esc_html__( $title ); $options .= ""; } } return $options; } 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 ( in_array( static::$entry_type, [ FQP::ENTRY_TYPE_LTD, FQP::ENTRY_TYPE_COLLECTIVE_COMPANY ] ) ) { return 'EN Die GmbH benötigt zwingend einen Geschäftsführer.'; } return ''; } }