options = $options; $this->values = $values; } /* * Generate label settings tabs * @return string */ public function generate_nav_tabs() { if ( empty( $this->options ) ) { return; } $tabs = AWL_Admin_Options::include_label_settings_tabs(); $html = ''; $html .= '
'; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; return $html; } /* * 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) { /** * Filter label settings field before render * @since 1.56 * @param array $field Array of options for current field * @param array $this->values Array of current label options */ $field = apply_filters( 'awl_settings_field_' . $field['id'], $field, $this->values ); $this->field_name = $this->get_field_name( $field ); $html .= 'get_field_classes( $field ) . '>'; $html .= ''; $html .= ''; $html .= ''; } } $html .= ''; $html .= '
'; $html .= ''; if ( isset( $field['multi_device'] ) && $field['multi_device'] ) { $html .= AWL_Admin_Helpers::add_device_switcher(); } $html .= ''; if ( isset( $field['multi_device'] ) && $field['multi_device'] ) { $html .= '
'; $html .= $this->get_field( $field ); $html .= '
'; foreach ( array( 'tablet', 'phone' ) as $device ) { $device_field = $this->get_device_field( $field, $device ); $html .= '
'; $html .= $this->get_field( $device_field ); $html .= '
'; } } else { $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]; } } // get parent value for multi device options if child value is missing if ( ! is_string( $field_value ) && ! $field_value && ( strpos( $field_id, '_tablet' ) !== false || strpos( $field_id, '_phone' ) !== false ) ) { $field_id = str_replace( array( '_tablet', '_phone' ), '', $field_id ); if ( isset( $this->values['settings'][$field_id] ) ) { $field_value = $this->values['settings'][$field_id]; } } } if ( 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-disabled-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 ); } // Add subfields if exists if ( isset( $field['suboptions'] ) && is_array( $field['suboptions'] ) ) { $new_field_html = ''; $new_field_html .= '
'; $new_field_html .= '
'; $new_field_html .= $field_html; $new_field_html .= '
'; foreach( $field['suboptions'] as $suboption_id => $suboption_params ) { $this->field_name = $this->get_field_name( $suboption_params ); $suboptions_width = isset( $suboption_params['width'] ) ? ' style="width:' . esc_attr( $suboption_params['width'] ) . ';flex: 0 0 ' . esc_attr( $suboption_params['width'] ) . ';"' : ''; $new_field_html .= '
'; $new_field_html .= $this->call_field( $suboption_params ); $new_field_html .= '
'; } $new_field_html .= '
'; $field_html = $new_field_html; } 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 ) ); } /* * Get specific device subfield * @param $parent_field array Main field * @param $device string Device name * @return array */ private function get_device_field( $parent_field, $device ) { $device_field = $parent_field; $device_field['id'] = $parent_field['id'] . '_' . $device; if ( isset( $device_field['suboptions'] ) ) { foreach ( $device_field['suboptions'] as $suboption_key => $suboption ) { $device_field['suboptions'][$suboption_key]['id'] = $suboption['id'] . '_' . $device; } } $this->field_name = $this->get_field_name( $device_field ); return $device_field; } /* * Select field html markup * @return string */ private function get_field_select( $field ) { $disabled = isset( $field['disabled'] ) && $field['disabled'] ? ' disabled' : ''; $html = ''; $html .= ''; return $html; } /* * Text field html markup * @return string */ private function get_field_text( $field ) { $disabled = isset( $field['disabled'] ) && $field['disabled'] ? ' disabled' : ''; $html = ''; return $html; } /* * Number field html markup * @return string */ private function get_field_number( $field ) { $disabled = isset( $field['disabled'] ) && $field['disabled'] ? ' disabled' : ''; $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 ) { $disabled = isset( $field['disabled'] ) && $field['disabled'] ? ' disabled' : ''; $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_checkbox( $field ) { $disabled = isset( $field['disabled'] ) && $field['disabled'] ? ' disabled' : ''; $html = ''; $html .= 'field_value, '1', false ) . $disabled . '>'; 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 = isset( $field['choices'][$template_type] ) && isset( $field['choices'][$template_type][$this->field_value] ) ? $field['choices'][$template_type][$this->field_value] : $field['choices']['text']['standard']; // 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 .= '
'; $html .= '
'; foreach ( $field['choices'] as $template_group => $template_group_items ) { $html .= '
    '; foreach( $template_group_items as $template_val => $template_img ) { $is_active = ( $this->field_value === $template_val ) ? ' awl-active' : ''; $pro_only = strpos( $template_val, '-pro' ) !== false ? ' awl-pro-template' : ''; $html .= '
  • '; $html .= ''; $html .= '
  • '; } $html .= '
'; } $html .= '
'; $html .= '
'; $html .= '
'; return $html; } } endif;