options = $options; $this->values = $values; } /* * Generate options fields * @return string */ public function generate_fields() { if ( empty( $this->options ) ) { return; } $html = ''; $html .= ''; $html .= ''; foreach ( $this->options as $section => $section_options ) { foreach( $section_options as $field) { $this->field_name = $this->get_field_name( $field ); $html .= 'get_field_classes( $field ) . '>'; $html .= ''; $html .= ''; $html .= ''; } } $html .= ''; $html .= '
'; $html .= $this->get_field( $field ); if ( isset( $field['tip'] ) && $field['tip'] ) { $html .= ''; } if ( isset( $field['spoiler'] ) && $field['spoiler'] ) { $html .= '
'; $html .= ''; $html .= '' . $field['spoiler']['title'] . ''; $html .= '' . stripslashes( $field['spoiler']['text'] ) . ''; $html .= ''; } $html .= '
'; return $html; } /* * Get field name * @return string */ private function get_field_name( $field ) { return "awl_label_params[settings][" . $field['id'] . "]"; } /* * Get field value * @return string */ private function get_field_value( $field ) { $value = isset( $field['value'] ) ? $field['value'] : ''; $field_value = false; if ( $this->values && ! empty( $this->values ) && isset( $this->values['settings'] ) ) { $field_id = $field['id']; if ( isset( $this->values['settings'][$field_id] ) ) { $field_value = $this->values['settings'][$field_id]; $suboption = isset( $field['suboption'] ) ? $field['suboption'] : ''; if ( $suboption && isset( $field_value[$suboption] ) ) { $field_value = $field_value[$suboption]; } } } if ( $field_value && is_string( $field_value ) ) { $value = $field_value; } return $value; } /* * Get field class names * @return string */ private function get_field_classes( $field ) { $classes = isset( $field['class'] ) && is_string( $field['class'] ) ? 'class="' . $field['class'] . '"' : ''; return $classes; } /* * Get extra table class names * @return string */ private function extra_classes() { $classes = ''; $classes .= ( $this->get_field_value( array( 'id' => 'position_type' ) ) === 'on_image' ) ? ' awl-position-on-image' : ' awl-position-on-line'; $classes .= ( $this->get_field_value( array( 'id' => 'custom_styles' ) ) === 'true' ) ? ' awl-show-styles' : ''; return $classes; } /* * Get field html markup * @param field array Field params * @return string */ private function get_field( $field ) { $field_html = ''; if ( isset( $field['params'] ) && is_array( $field['params'] ) ) { $field_html .= '
'; foreach( $field['params'] as $name => $val ) { $this->field_name = $this->get_field_name( $field ) . '[' . $name . ']'; $field['suboption'] = $name; $field['value'] = $val; $field_html .= '
' . $this->call_field( $field ) . '
'; } $field_html .= '
'; } else { $field_html .= $this->call_field( $field ); } return $field_html; } /* * Call field type method * @param field array Field params * @return string */ private function call_field( $field ) { $this->field_value = $this->get_field_value( $field ); return call_user_func_array( array( $this, 'get_field_' . $field['type'] ), array( $field ) ); } /* * Select field html markup * @return string */ private function get_field_select( $field ) { $html = ''; $html .= ''; return $html; } /* * Text field html markup * @return string */ private function get_field_text( $field ) { $html = ''; return $html; } /* * Number field html markup * @return string */ private function get_field_number( $field ) { $params = ''; $params .= isset( $field['step'] ) ? ' step="' . $field['step'] . '"' : ''; $params .= isset( $field['min'] ) ? ' min="' . $field['min'] . '"' : ''; $params .= isset( $field['max'] ) ? ' max="' . $field['max'] . '"' : ''; $html = ''; return $html; } /* * Textarea field html markup * @return string */ private function get_field_textarea( $field ) { $html = ''; return $html; } /* * Color field html markup * @return string */ private function get_field_color( $field ) { $params = isset( $field['alpha'] ) && $field['alpha'] ? 'data-alpha="true"' : ''; $html = ''; return $html; } /* * Checkbox field html markup * @return string */ private function get_field_checkbox2( $field ) { $html = ''; $html .= ''; return $html; } /* * Upload button field html markup * @return string */ private function get_field_upload( $field ) { $html = ''; return $html; } /* * Template field html markup * @return string */ private function get_field_template( $field ) { $template_type = $this->get_field_value( array( 'id' => 'type', 'value' => 'text' ) ); $image_url = $field['choices'][$template_type][$this->field_value]; // custom uploaded image if ( ! $image_url ) { $image_url = $this->field_value; $field['choices']['image'] = array( $this->field_value => $this->field_value ) + $field['choices']['image']; } $html = ''; $html .= '
'; $html .= ''; $html .= ''; $html .= '
'; foreach ( $field['choices'] as $template_group => $template_group_items ) { $html .= ''; } $html .= '
'; $html .= '
'; return $html; } } endif;